Skip to content

Commit 03a8871

Browse files
ouptonbonzini
authored andcommitted
KVM: nVMX: Expose load IA32_PERF_GLOBAL_CTRL VM-{Entry,Exit} control
The "load IA32_PERF_GLOBAL_CTRL" bit for VM-entry and VM-exit should only be exposed to the guest if IA32_PERF_GLOBAL_CTRL is a valid MSR. Create a new helper to allow pmu_refresh() to update the VM-Entry and VM-Exit controls to ensure PMU values are initialized when performing the is_valid_msr() check. Suggested-by: Jim Mattson <[email protected]> Co-developed-by: Krish Sadhukhan <[email protected]> Signed-off-by: Krish Sadhukhan <[email protected]> Signed-off-by: Oliver Upton <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Reviewed-by: Peter Shier <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 71f7347 commit 03a8871

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4359,6 +4359,27 @@ int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification,
43594359
return 0;
43604360
}
43614361

4362+
void nested_vmx_pmu_entry_exit_ctls_update(struct kvm_vcpu *vcpu)
4363+
{
4364+
struct vcpu_vmx *vmx;
4365+
4366+
if (!nested_vmx_allowed(vcpu))
4367+
return;
4368+
4369+
vmx = to_vmx(vcpu);
4370+
if (kvm_x86_ops->pmu_ops->is_valid_msr(vcpu, MSR_CORE_PERF_GLOBAL_CTRL)) {
4371+
vmx->nested.msrs.entry_ctls_high |=
4372+
VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
4373+
vmx->nested.msrs.exit_ctls_high |=
4374+
VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
4375+
} else {
4376+
vmx->nested.msrs.entry_ctls_high &=
4377+
~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
4378+
vmx->nested.msrs.exit_ctls_high &=
4379+
~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
4380+
}
4381+
}
4382+
43624383
static int nested_vmx_get_vmptr(struct kvm_vcpu *vcpu, gpa_t *vmpointer)
43634384
{
43644385
gva_t gva;

arch/x86/kvm/vmx/nested.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ int vmx_set_vmx_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
2222
int vmx_get_vmx_msr(struct nested_vmx_msrs *msrs, u32 msr_index, u64 *pdata);
2323
int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification,
2424
u32 vmx_instruction_info, bool wr, int len, gva_t *ret);
25+
void nested_vmx_pmu_entry_exit_ctls_update(struct kvm_vcpu *vcpu);
2526

2627
static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)
2728
{

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "x86.h"
1616
#include "cpuid.h"
1717
#include "lapic.h"
18+
#include "nested.h"
1819
#include "pmu.h"
1920

2021
static struct kvm_event_hw_type_mapping intel_arch_events[] = {
@@ -335,6 +336,8 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
335336
0, pmu->nr_arch_gp_counters);
336337
bitmap_set(pmu->all_valid_pmc_idx,
337338
INTEL_PMC_MAX_GENERIC, pmu->nr_arch_fixed_counters);
339+
340+
nested_vmx_pmu_entry_exit_ctls_update(vcpu);
338341
}
339342

340343
static void intel_pmu_init(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)