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