Skip to content

Commit 2e02cbb

Browse files
author
Marc Zyngier
committed
Merge branch 'kvm-arm64/pmu-5.9' into kvmarm-master/next
Signed-off-by: Marc Zyngier <maz@kernel.org>
2 parents 41fa0f5 + 51dd2eb commit 2e02cbb

7 files changed

Lines changed: 257 additions & 30 deletions

File tree

‎Documentation/virt/kvm/devices/vcpu.rst‎

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ Returns:
2525

2626
======= ========================================================
2727
-EBUSY The PMU overflow interrupt is already set
28-
-ENXIO The overflow interrupt not set when attempting to get it
29-
-ENODEV PMUv3 not supported
28+
-EFAULT Error reading interrupt number
29+
-ENXIO PMUv3 not supported or the overflow interrupt not set
30+
when attempting to get it
31+
-ENODEV KVM_ARM_VCPU_PMU_V3 feature missing from VCPU
3032
-EINVAL Invalid PMU overflow interrupt number supplied or
3133
trying to set the IRQ number without using an in-kernel
3234
irqchip.
@@ -45,16 +47,63 @@ all vcpus, while as an SPI it must be a separate number per vcpu.
4547
Returns:
4648

4749
======= ======================================================
50+
-EEXIST Interrupt number already used
4851
-ENODEV PMUv3 not supported or GIC not initialized
49-
-ENXIO PMUv3 not properly configured or in-kernel irqchip not
50-
configured as required prior to calling this attribute
52+
-ENXIO PMUv3 not supported, missing VCPU feature or interrupt
53+
number not set
5154
-EBUSY PMUv3 already initialized
5255
======= ======================================================
5356

5457
Request the initialization of the PMUv3. If using the PMUv3 with an in-kernel
5558
virtual GIC implementation, this must be done after initializing the in-kernel
5659
irqchip.
5760

61+
1.3 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FILTER
62+
-----------------------------------------
63+
64+
:Parameters: in kvm_device_attr.addr the address for a PMU event filter is a
65+
pointer to a struct kvm_pmu_event_filter
66+
67+
:Returns:
68+
69+
======= ======================================================
70+
-ENODEV: PMUv3 not supported or GIC not initialized
71+
-ENXIO: PMUv3 not properly configured or in-kernel irqchip not
72+
configured as required prior to calling this attribute
73+
-EBUSY: PMUv3 already initialized
74+
-EINVAL: Invalid filter range
75+
======= ======================================================
76+
77+
Request the installation of a PMU event filter described as follows:
78+
79+
struct kvm_pmu_event_filter {
80+
__u16 base_event;
81+
__u16 nevents;
82+
83+
#define KVM_PMU_EVENT_ALLOW 0
84+
#define KVM_PMU_EVENT_DENY 1
85+
86+
__u8 action;
87+
__u8 pad[3];
88+
};
89+
90+
A filter range is defined as the range [@base_event, @base_event + @nevents),
91+
together with an @action (KVM_PMU_EVENT_ALLOW or KVM_PMU_EVENT_DENY). The
92+
first registered range defines the global policy (global ALLOW if the first
93+
@action is DENY, global DENY if the first @action is ALLOW). Multiple ranges
94+
can be programmed, and must fit within the event space defined by the PMU
95+
architecture (10 bits on ARMv8.0, 16 bits from ARMv8.1 onwards).
96+
97+
Note: "Cancelling" a filter by registering the opposite action for the same
98+
range doesn't change the default action. For example, installing an ALLOW
99+
filter for event range [0:10) as the first filter and then applying a DENY
100+
action for the same range will leave the whole range as disabled.
101+
102+
Restrictions: Event 0 (SW_INCR) is never filtered, as it doesn't count a
103+
hardware event. Filtering event 0x1E (CHAIN) has no effect either, as it
104+
isn't strictly speaking an event. Filtering the cycle counter is possible
105+
using event 0x11 (CPU_CYCLES).
106+
58107

59108
2. GROUP: KVM_ARM_VCPU_TIMER_CTRL
60109
=================================

‎arch/arm64/include/asm/kvm_host.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ struct kvm_arch {
111111
* supported.
112112
*/
113113
bool return_nisv_io_abort_to_user;
114+
115+
/*
116+
* VM-wide PMU filter, implemented as a bitmap and big enough for
117+
* up to 2^10 events (ARMv8.0) or 2^16 events (ARMv8.1+).
118+
*/
119+
unsigned long *pmu_filter;
120+
unsigned int pmuver;
114121
};
115122

116123
struct kvm_vcpu_fault_info {

‎arch/arm64/include/uapi/asm/kvm.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ struct kvm_sync_regs {
159159
struct kvm_arch_memory_slot {
160160
};
161161

162+
/*
163+
* PMU filter structure. Describe a range of events with a particular
164+
* action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER.
165+
*/
166+
struct kvm_pmu_event_filter {
167+
__u16 base_event;
168+
__u16 nevents;
169+
170+
#define KVM_PMU_EVENT_ALLOW 0
171+
#define KVM_PMU_EVENT_DENY 1
172+
173+
__u8 action;
174+
__u8 pad[3];
175+
};
176+
162177
/* for KVM_GET/SET_VCPU_EVENTS */
163178
struct kvm_vcpu_events {
164179
struct {
@@ -329,6 +344,7 @@ struct kvm_vcpu_events {
329344
#define KVM_ARM_VCPU_PMU_V3_CTRL 0
330345
#define KVM_ARM_VCPU_PMU_V3_IRQ 0
331346
#define KVM_ARM_VCPU_PMU_V3_INIT 1
347+
#define KVM_ARM_VCPU_PMU_V3_FILTER 2
332348
#define KVM_ARM_VCPU_TIMER_CTRL 1
333349
#define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0
334350
#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1

‎arch/arm64/kvm/arm.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
147147
{
148148
int i;
149149

150+
bitmap_free(kvm->arch.pmu_filter);
151+
150152
kvm_vgic_destroy(kvm);
151153

152154
for (i = 0; i < KVM_MAX_VCPUS; ++i) {

0 commit comments

Comments
 (0)