Skip to content

Commit b333b8e

Browse files
sean-jcbonzini
authored andcommitted
KVM: VMX: Ignore guest CPUID for host userspace writes to DEBUGCTL
Ignore guest CPUID for host userspace writes to the DEBUGCTL MSR, KVM's ABI is that setting CPUID vs. state can be done in any order, i.e. KVM allows userspace to stuff MSRs prior to setting the guest's CPUID that makes the new MSR "legal". Keep the vmx_get_perf_capabilities() check for guest writes, even though it's technically unnecessary since the vCPU's PERF_CAPABILITIES is consulted when refreshing LBR support. A future patch will clean up vmx_get_perf_capabilities() to avoid the RDMSR on every call, at which point the paranoia will incur no meaningful overhead. Note, prior to vmx_get_perf_capabilities() checking that the host fully supports LBRs via x86_perf_get_lbr(), KVM effectively relied on intel_pmu_lbr_is_enabled() to guard against host userspace enabling LBRs on platforms without full support. Fixes: c646236 ("KVM: vmx/pmu: Add PMU_CAP_LBR_FMT check when guest LBR is enabled") Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 18e897d commit b333b8e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,16 +2021,16 @@ static u64 nested_vmx_truncate_sysenter_addr(struct kvm_vcpu *vcpu,
20212021
return (unsigned long)data;
20222022
}
20232023

2024-
static u64 vcpu_supported_debugctl(struct kvm_vcpu *vcpu)
2024+
static u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated)
20252025
{
20262026
u64 debugctl = 0;
20272027

20282028
if (boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT) &&
2029-
guest_cpuid_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT))
2029+
(host_initiated || guest_cpuid_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT)))
20302030
debugctl |= DEBUGCTLMSR_BUS_LOCK_DETECT;
20312031

20322032
if ((vmx_get_perf_capabilities() & PMU_CAP_LBR_FMT) &&
2033-
intel_pmu_lbr_is_enabled(vcpu))
2033+
(host_initiated || intel_pmu_lbr_is_enabled(vcpu)))
20342034
debugctl |= DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI;
20352035

20362036
return debugctl;
@@ -2105,7 +2105,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
21052105
vmcs_writel(GUEST_SYSENTER_ESP, data);
21062106
break;
21072107
case MSR_IA32_DEBUGCTLMSR: {
2108-
u64 invalid = data & ~vcpu_supported_debugctl(vcpu);
2108+
u64 invalid;
2109+
2110+
invalid = data & ~vmx_get_supported_debugctl(vcpu, msr_info->host_initiated);
21092111
if (invalid & (DEBUGCTLMSR_BTF|DEBUGCTLMSR_LBR)) {
21102112
if (report_ignored_msrs)
21112113
vcpu_unimpl(vcpu, "%s: BTF|LBR in IA32_DEBUGCTLMSR 0x%llx, nop\n",

0 commit comments

Comments
 (0)