[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1536233456-12173-4-git-send-email-wei.w.wang@intel.com>
Date: Thu, 6 Sep 2018 19:30:51 +0800
From: Wei Wang <wei.w.wang@...el.com>
To: linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
pbonzini@...hat.com, ak@...ux.intel.com
Cc: kan.liang@...el.com, peterz@...radead.org, mingo@...hat.com,
rkrcmar@...hat.com, like.xu@...el.com, wei.w.wang@...el.com
Subject: [PATCH v2 3/8] KVM/vmx: Pass through the lbr stack to a guest
Pass through the LBR stack to the guest when the guest lbr feature is
enabled. This makes the guest have direct accesses to the lbr stack.
Signed-off-by: Like Xu <like.xu@...el.com>
Signed-off-by: Wei Wang <wei.w.wang@...el.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>
Cc: Andi Kleen <ak@...ux.intel.com>
---
arch/x86/kvm/vmx.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 1d26f3c..7a62c1c 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -7847,6 +7847,38 @@ static void vmx_enable_tdp(void)
kvm_enable_tdp();
}
+static int vmx_passthrough_lbr_msrs(struct kvm *kvm,
+ unsigned long *msr_bitmap)
+{
+ int i;
+ struct perf_lbr_stack lbr_stack;
+
+ if (perf_get_lbr_stack(&lbr_stack) < 0) {
+ pr_err("Failed to pass through the lbr stack\n");
+ return -ENOENT;
+ }
+
+ vmx_disable_intercept_for_msr(msr_bitmap, MSR_LBR_SELECT,
+ MSR_TYPE_RW);
+ vmx_disable_intercept_for_msr(msr_bitmap, lbr_stack.lbr_tos,
+ MSR_TYPE_RW);
+
+ for (i = 0; i < lbr_stack.lbr_nr; i++) {
+ vmx_disable_intercept_for_msr(msr_bitmap,
+ lbr_stack.lbr_from + i,
+ MSR_TYPE_RW);
+ vmx_disable_intercept_for_msr(msr_bitmap,
+ lbr_stack.lbr_to + i,
+ MSR_TYPE_RW);
+ if (lbr_stack.lbr_info)
+ vmx_disable_intercept_for_msr(msr_bitmap,
+ lbr_stack.lbr_info + i,
+ MSR_TYPE_RW);
+ }
+
+ return 0;
+}
+
static __init int hardware_setup(void)
{
unsigned long host_bndcfgs;
@@ -10998,6 +11030,12 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_SYSENTER_EIP, MSR_TYPE_RW);
vmx->msr_bitmap_mode = 0;
+ if (kvm->arch.guest_lbr) {
+ err = vmx_passthrough_lbr_msrs(kvm, msr_bitmap);
+ if (err < 0)
+ goto free_vmcs;
+ }
+
vmx->loaded_vmcs = &vmx->vmcs01;
cpu = get_cpu();
vmx_vcpu_load(&vmx->vcpu, cpu);
--
2.7.4
Powered by blists - more mailing lists