Skip to content

Commit 447112d

Browse files
committed
KVM: VMX: Snapshot LBR capabilities during module initialization
Snapshot VMX's LBR capabilities once during module initialization instead of calling into perf every time a vCPU reconfigures its vPMU. This will allow massaging the LBR capabilities, e.g. if the CPU doesn't support callstacks, without having to remember to update multiple locations. Opportunistically tag vmx_get_perf_capabilities() with __init, as it's only called from vmx_set_cpu_caps(). Reviewed-by: Mingwei Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 7f2817e commit 447112d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
535535
perf_capabilities = vcpu_get_perf_capabilities(vcpu);
536536
if (cpuid_model_is_consistent(vcpu) &&
537537
(perf_capabilities & PMU_CAP_LBR_FMT))
538-
x86_perf_get_lbr(&lbr_desc->records);
538+
memcpy(&lbr_desc->records, &vmx_lbr_caps, sizeof(vmx_lbr_caps));
539539
else
540540
lbr_desc->records.nr = 0;
541541

arch/x86/kvm/vmx/vmx.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ module_param(ple_window_max, uint, 0444);
218218
int __read_mostly pt_mode = PT_MODE_SYSTEM;
219219
module_param(pt_mode, int, S_IRUGO);
220220

221+
struct x86_pmu_lbr __ro_after_init vmx_lbr_caps;
222+
221223
static DEFINE_STATIC_KEY_FALSE(vmx_l1d_should_flush);
222224
static DEFINE_STATIC_KEY_FALSE(vmx_l1d_flush_cond);
223225
static DEFINE_MUTEX(vmx_l1d_flush_mutex);
@@ -7862,10 +7864,9 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
78627864
vmx_update_exception_bitmap(vcpu);
78637865
}
78647866

7865-
static u64 vmx_get_perf_capabilities(void)
7867+
static __init u64 vmx_get_perf_capabilities(void)
78667868
{
78677869
u64 perf_cap = PMU_CAP_FW_WRITES;
7868-
struct x86_pmu_lbr lbr;
78697870
u64 host_perf_cap = 0;
78707871

78717872
if (!enable_pmu)
@@ -7875,8 +7876,8 @@ static u64 vmx_get_perf_capabilities(void)
78757876
rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap);
78767877

78777878
if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR)) {
7878-
x86_perf_get_lbr(&lbr);
7879-
if (lbr.nr)
7879+
x86_perf_get_lbr(&vmx_lbr_caps);
7880+
if (vmx_lbr_caps.nr)
78807881
perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
78817882
}
78827883

arch/x86/kvm/vmx/vmx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ struct lbr_desc {
110110
bool msr_passthrough;
111111
};
112112

113+
extern struct x86_pmu_lbr vmx_lbr_caps;
114+
113115
/*
114116
* The nested_vmx structure is part of vcpu_vmx, and holds information we need
115117
* for correct emulation of VMX (i.e., nested VMX) on this vcpu.

0 commit comments

Comments
 (0)