^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) Generic vcpu interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) The virtual cpu "device" also accepts the ioctls KVM_SET_DEVICE_ATTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) KVM_GET_DEVICE_ATTR, and KVM_HAS_DEVICE_ATTR. The interface uses the same struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) kvm_device_attr as other devices, but targets VCPU-wide settings and controls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) The groups and attributes per virtual cpu, if any, are architecture specific.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 1. GROUP: KVM_ARM_VCPU_PMU_V3_CTRL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) ==================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) :Architectures: ARM64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 1.1. ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ---------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) :Parameters: in kvm_device_attr.addr the address for PMU overflow interrupt is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) pointer to an int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) ======= ========================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) -EBUSY The PMU overflow interrupt is already set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) -EFAULT Error reading interrupt number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) -ENXIO PMUv3 not supported or the overflow interrupt not set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) when attempting to get it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) -ENODEV KVM_ARM_VCPU_PMU_V3 feature missing from VCPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) -EINVAL Invalid PMU overflow interrupt number supplied or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) trying to set the IRQ number without using an in-kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) irqchip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) ======= ========================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) A value describing the PMUv3 (Performance Monitor Unit v3) overflow interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) number for this vcpu. This interrupt could be a PPI or SPI, but the interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) type must be same for each vcpu. As a PPI, the interrupt number is the same for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) all vcpus, while as an SPI it must be a separate number per vcpu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 1.2 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ---------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) :Parameters: no additional parameter in kvm_device_attr.addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ======= ======================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) -EEXIST Interrupt number already used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) -ENODEV PMUv3 not supported or GIC not initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) -ENXIO PMUv3 not supported, missing VCPU feature or interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) number not set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) -EBUSY PMUv3 already initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ======= ======================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) Request the initialization of the PMUv3. If using the PMUv3 with an in-kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) virtual GIC implementation, this must be done after initializing the in-kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) irqchip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 1.3 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FILTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) -----------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) :Parameters: in kvm_device_attr.addr the address for a PMU event filter is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) pointer to a struct kvm_pmu_event_filter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) :Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ======= ======================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) -ENODEV PMUv3 not supported or GIC not initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) -ENXIO PMUv3 not properly configured or in-kernel irqchip not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) configured as required prior to calling this attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) -EBUSY PMUv3 already initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) -EINVAL Invalid filter range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ======= ======================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) Request the installation of a PMU event filter described as follows::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct kvm_pmu_event_filter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) __u16 base_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) __u16 nevents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define KVM_PMU_EVENT_ALLOW 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define KVM_PMU_EVENT_DENY 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) __u8 action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) __u8 pad[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) A filter range is defined as the range [@base_event, @base_event + @nevents),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) together with an @action (KVM_PMU_EVENT_ALLOW or KVM_PMU_EVENT_DENY). The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) first registered range defines the global policy (global ALLOW if the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) @action is DENY, global DENY if the first @action is ALLOW). Multiple ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) can be programmed, and must fit within the event space defined by the PMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) architecture (10 bits on ARMv8.0, 16 bits from ARMv8.1 onwards).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) Note: "Cancelling" a filter by registering the opposite action for the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) range doesn't change the default action. For example, installing an ALLOW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) filter for event range [0:10) as the first filter and then applying a DENY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) action for the same range will leave the whole range as disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) Restrictions: Event 0 (SW_INCR) is never filtered, as it doesn't count a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) hardware event. Filtering event 0x1E (CHAIN) has no effect either, as it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) isn't strictly speaking an event. Filtering the cycle counter is possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) using event 0x11 (CPU_CYCLES).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 2. GROUP: KVM_ARM_VCPU_TIMER_CTRL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) :Architectures: ARM, ARM64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 2.1. ATTRIBUTES: KVM_ARM_VCPU_TIMER_IRQ_VTIMER, KVM_ARM_VCPU_TIMER_IRQ_PTIMER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) -----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) :Parameters: in kvm_device_attr.addr the address for the timer interrupt is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) pointer to an int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ======= =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) -EINVAL Invalid timer interrupt number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) -EBUSY One or more VCPUs has already run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ======= =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) A value describing the architected timer interrupt number when connected to an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) in-kernel virtual GIC. These must be a PPI (16 <= intid < 32). Setting the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) attribute overrides the default values (see below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) ============================= ==========================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) KVM_ARM_VCPU_TIMER_IRQ_VTIMER The EL1 virtual timer intid (default: 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) KVM_ARM_VCPU_TIMER_IRQ_PTIMER The EL1 physical timer intid (default: 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ============================= ==========================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) Setting the same PPI for different timers will prevent the VCPUs from running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) Setting the interrupt number on a VCPU configures all VCPUs created at that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) time to use the number provided for a given timer, overwriting any previously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) configured values on other VCPUs. Userspace should configure the interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) numbers on at least one VCPU after creating all VCPUs and before running any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) VCPUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 3. GROUP: KVM_ARM_VCPU_PVTIME_CTRL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ==================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) :Architectures: ARM64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 3.1 ATTRIBUTE: KVM_ARM_VCPU_PVTIME_IPA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) --------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) :Parameters: 64-bit base address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ======= ======================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) -ENXIO Stolen time not implemented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) -EEXIST Base address already set for this VCPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) -EINVAL Base address not 64 byte aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ======= ======================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) Specifies the base address of the stolen time structure for this VCPU. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) base address must be 64 byte aligned and exist within a valid guest memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) region. See Documentation/virt/kvm/arm/pvtime.rst for more information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) including the layout of the stolen time structure.