@@ -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);