Skip to content

Commit a38b67d

Browse files
committed
KVM: arm64: Drop kvm_arm_pmu_available static key
With the PMUv3 cpucap, kvm_arm_pmu_available is no longer used in the hot path of guest entry/exit. On top of that, guest support for PMUv3 may not correlate with host support for the feature, e.g. on IMPDEF hardware. Throw out the static key and just inspect the list of PMUs to determine if PMUv3 is supported for KVM guests. Tested-by: Janne Grunau <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 6f34024 commit a38b67d

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

arch/arm64/kernel/image-vars.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ KVM_NVHE_ALIAS(broken_cntvoff_key);
112112
KVM_NVHE_ALIAS(__start___kvm_ex_table);
113113
KVM_NVHE_ALIAS(__stop___kvm_ex_table);
114114

115-
/* PMU available static key */
116-
#ifdef CONFIG_HW_PERF_EVENTS
117-
KVM_NVHE_ALIAS(kvm_arm_pmu_available);
118-
#endif
119-
120115
/* Position-independent library routines */
121116
KVM_NVHE_ALIAS_HYP(clear_page, __pi_clear_page);
122117
KVM_NVHE_ALIAS_HYP(copy_page, __pi_copy_page);

arch/arm64/kvm/arm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
366366
r = get_num_wrps();
367367
break;
368368
case KVM_CAP_ARM_PMU_V3:
369-
r = kvm_arm_support_pmu_v3();
369+
r = kvm_supports_guest_pmuv3();
370370
break;
371371
case KVM_CAP_ARM_INJECT_SERROR_ESR:
372372
r = cpus_have_final_cap(ARM64_HAS_RAS_EXTN);
@@ -1388,7 +1388,7 @@ static unsigned long system_supported_vcpu_features(void)
13881388
if (!cpus_have_final_cap(ARM64_HAS_32BIT_EL1))
13891389
clear_bit(KVM_ARM_VCPU_EL1_32BIT, &features);
13901390

1391-
if (!kvm_arm_support_pmu_v3())
1391+
if (!kvm_supports_guest_pmuv3())
13921392
clear_bit(KVM_ARM_VCPU_PMU_V3, &features);
13931393

13941394
if (!system_supports_sve())

arch/arm64/kvm/pmu-emul.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@
1717

1818
#define PERF_ATTR_CFG1_COUNTER_64BIT BIT(0)
1919

20-
DEFINE_STATIC_KEY_FALSE(kvm_arm_pmu_available);
21-
2220
static LIST_HEAD(arm_pmus);
2321
static DEFINE_MUTEX(arm_pmus_lock);
2422

2523
static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc);
2624
static void kvm_pmu_release_perf_event(struct kvm_pmc *pmc);
2725
static bool kvm_pmu_counter_is_enabled(struct kvm_pmc *pmc);
2826

27+
bool kvm_supports_guest_pmuv3(void)
28+
{
29+
guard(mutex)(&arm_pmus_lock);
30+
return !list_empty(&arm_pmus);
31+
}
32+
2933
static struct kvm_vcpu *kvm_pmc_to_vcpu(const struct kvm_pmc *pmc)
3034
{
3135
return container_of(pmc, struct kvm_vcpu, arch.pmu.pmc[pmc->idx]);
@@ -795,9 +799,6 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
795799
entry->arm_pmu = pmu;
796800
list_add_tail(&entry->entry, &arm_pmus);
797801

798-
if (list_is_singular(&arm_pmus))
799-
static_branch_enable(&kvm_arm_pmu_available);
800-
801802
out_unlock:
802803
mutex_unlock(&arm_pmus_lock);
803804
}

include/kvm/arm_pmu.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,7 @@ struct arm_pmu_entry {
3737
struct arm_pmu *arm_pmu;
3838
};
3939

40-
DECLARE_STATIC_KEY_FALSE(kvm_arm_pmu_available);
41-
42-
static __always_inline bool kvm_arm_support_pmu_v3(void)
43-
{
44-
return static_branch_likely(&kvm_arm_pmu_available);
45-
}
46-
40+
bool kvm_supports_guest_pmuv3(void);
4741
#define kvm_arm_pmu_irq_initialized(v) ((v)->arch.pmu.irq_num >= VGIC_NR_SGIS)
4842
u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx);
4943
void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val);
@@ -102,7 +96,7 @@ void kvm_pmu_nested_transition(struct kvm_vcpu *vcpu);
10296
struct kvm_pmu {
10397
};
10498

105-
static inline bool kvm_arm_support_pmu_v3(void)
99+
static inline bool kvm_supports_guest_pmuv3(void)
106100
{
107101
return false;
108102
}

0 commit comments

Comments
 (0)