]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: SVM: Suppress DEBUGCTL.BTF on AMD
authorSean Christopherson <seanjc@google.com>
Thu, 27 Feb 2025 22:24:07 +0000 (14:24 -0800)
committerSean Christopherson <seanjc@google.com>
Fri, 28 Feb 2025 17:17:45 +0000 (09:17 -0800)
Mark BTF as reserved in DEBUGCTL on AMD, as KVM doesn't actually support
BTF, and fully enabling BTF virtualization is non-trivial due to
interactions with the emulator, guest_debug, #DB interception, nested SVM,
etc.

Don't inject #GP if the guest attempts to set BTF, as there's no way to
communicate lack of support to the guest, and instead suppress the flag
and treat the WRMSR as (partially) unsupported.

In short, make KVM behave the same on AMD and Intel (VMX already squashes
BTF).

Note, due to other bugs in KVM's handling of DEBUGCTL, the only way BTF
has "worked" in any capacity is if the guest simultaneously enables LBRs.

Reported-by: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: stable@vger.kernel.org
Reviewed-and-tested-by: Ravi Bangoria <ravi.bangoria@amd.com>
Link: https://lore.kernel.org/r/20250227222411.3490595-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm.h

index bdafbde1f211abe2d33d9c86c97f54a4707de867..ed48465186961c3a494b1c6b1735ca22fc370d77 100644 (file)
@@ -3177,6 +3177,15 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
                 */
                data &= ~GENMASK(5, 2);
 
+               /*
+                * Suppress BTF as KVM doesn't virtualize BTF, but there's no
+                * way to communicate lack of support to the guest.
+                */
+               if (data & DEBUGCTLMSR_BTF) {
+                       kvm_pr_unimpl_wrmsr(vcpu, MSR_IA32_DEBUGCTLMSR, data);
+                       data &= ~DEBUGCTLMSR_BTF;
+               }
+
                if (data & DEBUGCTL_RESERVED_BITS)
                        return 1;
 
index 3a931d3885e7103cb0655133ecd494cbcd959eea..ea44c1da5a7c9131a2bb43657b2f826be1205980 100644 (file)
@@ -584,7 +584,7 @@ static inline bool is_vnmi_enabled(struct vcpu_svm *svm)
 /* svm.c */
 #define MSR_INVALID                            0xffffffffU
 
-#define DEBUGCTL_RESERVED_BITS (~(DEBUGCTLMSR_BTF | DEBUGCTLMSR_LBR))
+#define DEBUGCTL_RESERVED_BITS (~DEBUGCTLMSR_LBR)
 
 extern bool dump_invalid_vmcb;