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

     1  #
     2  # requires: arch=arm64 -threaded
     3  #
     4  r0 = openat$kvm(0, &AUTO='/dev/kvm\x00', 0x0, 0x0)
     5  r1 = ioctl$KVM_CREATE_VM(r0, AUTO, 0x0)
     6  r2 = syz_kvm_setup_syzos_vm$arm64(r1, &(0x7f0000c00000/0x400000)=nil)
     7  #
     8  # 0x603000000013df40 is PMEVCNTR0_EL0, write to it will trigger access_pmu_evcntr() in arch/arm64/kvm/sys_regs.c
     9  # This is done to illustrate that PMU is accessible.
    10  # 0x8 corresponds to the KVM_ARM_VCPU_PMU_V3 feature bit and is required to enable PMU.
    11  #
    12  r3 = syz_kvm_add_vcpu$arm64(r2, &AUTO={0x0, &AUTO=[@msr={AUTO, AUTO, {0x603000000013df40, 0x8000}}], AUTO}, &AUTO=[@featur1={0x1, 0x8}], 0x1)
    13  #
    14  # Call ioctl(KVM_SET_DEVICE_ATTR) with group=KVM_ARM_VCPU_PMU_V3_CTRL and attr=KVM_ARM_VCPU_PMU_V3_INIT,
    15  # as per https://www.kernel.org/doc/Documentation/virt/kvm/devices/vcpu.rst.
    16  #
    17  ioctl$KVM_SET_DEVICE_ATTR_vcpu(r3, AUTO, &AUTO=@attr_pmu_init)
    18  
    19  r4 = ioctl$KVM_GET_VCPU_MMAP_SIZE(r0, AUTO)
    20  r5 = mmap$KVM_VCPU(&(0x7f0000009000/0x1000)=nil, r4, 0x3, 0x1, r3, 0x0)
    21  #
    22  # Run till the end of guest_main(). 0xffffffffffffffff is UEXIT_END.
    23  #
    24  ioctl$KVM_RUN(r3, AUTO, 0x0)
    25  syz_kvm_assert_syzos_uexit$arm64(r5, 0xffffffffffffffff)
    26  syz_kvm_assert_reg(r3, 0x603000000013df40, 0x8000)