github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/sys/linux/test/arm64-syz_kvm_setup_syzos_vm-enable-pmu-msr-emul-2 (about)

     1  #
     2  # requires: arch=arm64 -threaded
     3  #
     4  # This series of tests exercise the PMU registers that are exposed in the QEMU emulation mode.
     5  # They should not be used in the corpus when running on real HW.
     6  #
     7  r0 = openat$kvm(0, &AUTO='/dev/kvm\x00', 0x0, 0x0)
     8  r1 = ioctl$KVM_CREATE_VM(r0, AUTO, 0x0)
     9  r2 = syz_kvm_setup_syzos_vm$arm64(r1, &(0x7f0000c00000/0x400000)=nil)
    10  #
    11  # 0x603000000013df60 is PMEVTYPERn_EL0(0).
    12  # 0x603000000013df61 is PMEVTYPERn_EL0(1).
    13  # 0x603000000013df62 is PMEVTYPERn_EL0(2).
    14  # 0x603000000013df63 is PMEVTYPERn_EL0(3).
    15  # 0x603000000013df64 is PMEVTYPERn_EL0(4).
    16  # 0x603000000013df65 is PMEVTYPERn_EL0(5).
    17  # 0x603000000013df7f is PMCCFILTR_EL0.
    18  # Writes to these registers will trigger kvm_handle_sys_reg in arch/arm64/kvm/sys_regs.c
    19  # This is done to illustrate that PMU is accessible.
    20  # 0x8 corresponds to the KVM_ARM_VCPU_PMU_V3 feature bit and is required to enable PMU.
    21  #
    22  r3 = syz_kvm_add_vcpu$arm64(r2, &AUTO={0x0, &AUTO=[@msr={AUTO, AUTO, {0x603000000013df60, 0x8000}}, @msr={AUTO, AUTO, {0x603000000013df61, 0x8000}}, @msr={AUTO, AUTO, {0x603000000013df62, 0x8000}}, @msr={AUTO, AUTO, {0x603000000013df63, 0x8000}}, @msr={AUTO, AUTO, {0x603000000013df64, 0x8000}}, @msr={AUTO, AUTO, {0x603000000013df65, 0x8000}}, @msr={AUTO, AUTO, {0x603000000013df7f, 0x8000}}, ], AUTO}, &AUTO=[@featur1={0x1, 0x8}], 0x1)
    23  #
    24  # Call ioctl(KVM_SET_DEVICE_ATTR) with group=KVM_ARM_VCPU_PMU_V3_CTRL and attr=KVM_ARM_VCPU_PMU_V3_INIT,
    25  # as per https://www.kernel.org/doc/Documentation/virt/kvm/devices/vcpu.rst.
    26  #
    27  ioctl$KVM_SET_DEVICE_ATTR_vcpu(r3, AUTO, &AUTO=@attr_pmu_init)
    28  
    29  r4 = ioctl$KVM_GET_VCPU_MMAP_SIZE(r0, AUTO)
    30  r5 = mmap$KVM_VCPU(&(0x7f0000009000/0x1000)=nil, r4, 0x3, 0x1, r3, 0x0)
    31  #
    32  # Run till the end of guest_main(). 0xffffffffffffffff is UEXIT_END.
    33  #
    34  ioctl$KVM_RUN(r3, AUTO, 0x0)
    35  syz_kvm_assert_syzos_uexit$arm64(r5, 0xffffffffffffffff)
    36  syz_kvm_assert_reg(r3, 0x603000000013df60, 0x8000)
    37  syz_kvm_assert_reg(r3, 0x603000000013df61, 0x8000)
    38  syz_kvm_assert_reg(r3, 0x603000000013df62, 0x8000)
    39  syz_kvm_assert_reg(r3, 0x603000000013df63, 0x8000)
    40  syz_kvm_assert_reg(r3, 0x603000000013df64, 0x8000)
    41  syz_kvm_assert_reg(r3, 0x603000000013df65, 0x8000)
    42  syz_kvm_assert_reg(r3, 0x603000000013df7f, 0x8000)