18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci====================== 48c2ecf20Sopenharmony_ciGeneric vcpu interface 58c2ecf20Sopenharmony_ci====================== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciThe virtual cpu "device" also accepts the ioctls KVM_SET_DEVICE_ATTR, 88c2ecf20Sopenharmony_ciKVM_GET_DEVICE_ATTR, and KVM_HAS_DEVICE_ATTR. The interface uses the same struct 98c2ecf20Sopenharmony_cikvm_device_attr as other devices, but targets VCPU-wide settings and controls. 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciThe groups and attributes per virtual cpu, if any, are architecture specific. 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci1. GROUP: KVM_ARM_VCPU_PMU_V3_CTRL 148c2ecf20Sopenharmony_ci================================== 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci:Architectures: ARM64 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci1.1. ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_IRQ 198c2ecf20Sopenharmony_ci--------------------------------------- 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci:Parameters: in kvm_device_attr.addr the address for PMU overflow interrupt is a 228c2ecf20Sopenharmony_ci pointer to an int 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciReturns: 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci ======= ======================================================== 278c2ecf20Sopenharmony_ci -EBUSY The PMU overflow interrupt is already set 288c2ecf20Sopenharmony_ci -EFAULT Error reading interrupt number 298c2ecf20Sopenharmony_ci -ENXIO PMUv3 not supported or the overflow interrupt not set 308c2ecf20Sopenharmony_ci when attempting to get it 318c2ecf20Sopenharmony_ci -ENODEV KVM_ARM_VCPU_PMU_V3 feature missing from VCPU 328c2ecf20Sopenharmony_ci -EINVAL Invalid PMU overflow interrupt number supplied or 338c2ecf20Sopenharmony_ci trying to set the IRQ number without using an in-kernel 348c2ecf20Sopenharmony_ci irqchip. 358c2ecf20Sopenharmony_ci ======= ======================================================== 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ciA value describing the PMUv3 (Performance Monitor Unit v3) overflow interrupt 388c2ecf20Sopenharmony_cinumber for this vcpu. This interrupt could be a PPI or SPI, but the interrupt 398c2ecf20Sopenharmony_citype must be same for each vcpu. As a PPI, the interrupt number is the same for 408c2ecf20Sopenharmony_ciall vcpus, while as an SPI it must be a separate number per vcpu. 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci1.2 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_INIT 438c2ecf20Sopenharmony_ci--------------------------------------- 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci:Parameters: no additional parameter in kvm_device_attr.addr 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciReturns: 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci ======= ====================================================== 508c2ecf20Sopenharmony_ci -EEXIST Interrupt number already used 518c2ecf20Sopenharmony_ci -ENODEV PMUv3 not supported or GIC not initialized 528c2ecf20Sopenharmony_ci -ENXIO PMUv3 not supported, missing VCPU feature or interrupt 538c2ecf20Sopenharmony_ci number not set 548c2ecf20Sopenharmony_ci -EBUSY PMUv3 already initialized 558c2ecf20Sopenharmony_ci ======= ====================================================== 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ciRequest the initialization of the PMUv3. If using the PMUv3 with an in-kernel 588c2ecf20Sopenharmony_civirtual GIC implementation, this must be done after initializing the in-kernel 598c2ecf20Sopenharmony_ciirqchip. 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci1.3 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FILTER 628c2ecf20Sopenharmony_ci----------------------------------------- 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci:Parameters: in kvm_device_attr.addr the address for a PMU event filter is a 658c2ecf20Sopenharmony_ci pointer to a struct kvm_pmu_event_filter 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci:Returns: 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci ======= ====================================================== 708c2ecf20Sopenharmony_ci -ENODEV PMUv3 not supported or GIC not initialized 718c2ecf20Sopenharmony_ci -ENXIO PMUv3 not properly configured or in-kernel irqchip not 728c2ecf20Sopenharmony_ci configured as required prior to calling this attribute 738c2ecf20Sopenharmony_ci -EBUSY PMUv3 already initialized 748c2ecf20Sopenharmony_ci -EINVAL Invalid filter range 758c2ecf20Sopenharmony_ci ======= ====================================================== 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ciRequest the installation of a PMU event filter described as follows:: 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci struct kvm_pmu_event_filter { 808c2ecf20Sopenharmony_ci __u16 base_event; 818c2ecf20Sopenharmony_ci __u16 nevents; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci #define KVM_PMU_EVENT_ALLOW 0 848c2ecf20Sopenharmony_ci #define KVM_PMU_EVENT_DENY 1 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci __u8 action; 878c2ecf20Sopenharmony_ci __u8 pad[3]; 888c2ecf20Sopenharmony_ci }; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ciA filter range is defined as the range [@base_event, @base_event + @nevents), 918c2ecf20Sopenharmony_citogether with an @action (KVM_PMU_EVENT_ALLOW or KVM_PMU_EVENT_DENY). The 928c2ecf20Sopenharmony_cifirst registered range defines the global policy (global ALLOW if the first 938c2ecf20Sopenharmony_ci@action is DENY, global DENY if the first @action is ALLOW). Multiple ranges 948c2ecf20Sopenharmony_cican be programmed, and must fit within the event space defined by the PMU 958c2ecf20Sopenharmony_ciarchitecture (10 bits on ARMv8.0, 16 bits from ARMv8.1 onwards). 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciNote: "Cancelling" a filter by registering the opposite action for the same 988c2ecf20Sopenharmony_cirange doesn't change the default action. For example, installing an ALLOW 998c2ecf20Sopenharmony_cifilter for event range [0:10) as the first filter and then applying a DENY 1008c2ecf20Sopenharmony_ciaction for the same range will leave the whole range as disabled. 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ciRestrictions: Event 0 (SW_INCR) is never filtered, as it doesn't count a 1038c2ecf20Sopenharmony_cihardware event. Filtering event 0x1E (CHAIN) has no effect either, as it 1048c2ecf20Sopenharmony_ciisn't strictly speaking an event. Filtering the cycle counter is possible 1058c2ecf20Sopenharmony_ciusing event 0x11 (CPU_CYCLES). 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci2. GROUP: KVM_ARM_VCPU_TIMER_CTRL 1098c2ecf20Sopenharmony_ci================================= 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci:Architectures: ARM, ARM64 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci2.1. ATTRIBUTES: KVM_ARM_VCPU_TIMER_IRQ_VTIMER, KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1148c2ecf20Sopenharmony_ci----------------------------------------------------------------------------- 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci:Parameters: in kvm_device_attr.addr the address for the timer interrupt is a 1178c2ecf20Sopenharmony_ci pointer to an int 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciReturns: 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci ======= ================================= 1228c2ecf20Sopenharmony_ci -EINVAL Invalid timer interrupt number 1238c2ecf20Sopenharmony_ci -EBUSY One or more VCPUs has already run 1248c2ecf20Sopenharmony_ci ======= ================================= 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ciA value describing the architected timer interrupt number when connected to an 1278c2ecf20Sopenharmony_ciin-kernel virtual GIC. These must be a PPI (16 <= intid < 32). Setting the 1288c2ecf20Sopenharmony_ciattribute overrides the default values (see below). 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci============================= ========================================== 1318c2ecf20Sopenharmony_ciKVM_ARM_VCPU_TIMER_IRQ_VTIMER The EL1 virtual timer intid (default: 27) 1328c2ecf20Sopenharmony_ciKVM_ARM_VCPU_TIMER_IRQ_PTIMER The EL1 physical timer intid (default: 30) 1338c2ecf20Sopenharmony_ci============================= ========================================== 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ciSetting the same PPI for different timers will prevent the VCPUs from running. 1368c2ecf20Sopenharmony_ciSetting the interrupt number on a VCPU configures all VCPUs created at that 1378c2ecf20Sopenharmony_citime to use the number provided for a given timer, overwriting any previously 1388c2ecf20Sopenharmony_ciconfigured values on other VCPUs. Userspace should configure the interrupt 1398c2ecf20Sopenharmony_cinumbers on at least one VCPU after creating all VCPUs and before running any 1408c2ecf20Sopenharmony_ciVCPUs. 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci3. GROUP: KVM_ARM_VCPU_PVTIME_CTRL 1438c2ecf20Sopenharmony_ci================================== 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci:Architectures: ARM64 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci3.1 ATTRIBUTE: KVM_ARM_VCPU_PVTIME_IPA 1488c2ecf20Sopenharmony_ci-------------------------------------- 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci:Parameters: 64-bit base address 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ciReturns: 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci ======= ====================================== 1558c2ecf20Sopenharmony_ci -ENXIO Stolen time not implemented 1568c2ecf20Sopenharmony_ci -EEXIST Base address already set for this VCPU 1578c2ecf20Sopenharmony_ci -EINVAL Base address not 64 byte aligned 1588c2ecf20Sopenharmony_ci ======= ====================================== 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ciSpecifies the base address of the stolen time structure for this VCPU. The 1618c2ecf20Sopenharmony_cibase address must be 64 byte aligned and exist within a valid guest memory 1628c2ecf20Sopenharmony_ciregion. See Documentation/virt/kvm/arm/pvtime.rst for more information 1638c2ecf20Sopenharmony_ciincluding the layout of the stolen time structure. 164