Skip to content

Commit 96d7dbf

Browse files
sean-jcgregkh
authored andcommitted
KVM: SVM: Suppress DEBUGCTL.BTF on AMD
commit d0eac42 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 29a5d95 commit 96d7dbf

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,15 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
31813181
*/
31823182
data &= ~GENMASK(5, 2);
31833183

3184+
/*
3185+
* Suppress BTF as KVM doesn't virtualize BTF, but there's no
3186+
* way to communicate lack of support to the guest.
3187+
*/
3188+
if (data & DEBUGCTLMSR_BTF) {
3189+
kvm_pr_unimpl_wrmsr(vcpu, MSR_IA32_DEBUGCTLMSR, data);
3190+
data &= ~DEBUGCTLMSR_BTF;
3191+
}
3192+
31843193
if (data & DEBUGCTL_RESERVED_BITS)
31853194
return 1;
31863195

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ static inline bool is_vnmi_enabled(struct vcpu_svm *svm)
591591
/* svm.c */
592592
#define MSR_INVALID 0xffffffffU
593593

594-
#define DEBUGCTL_RESERVED_BITS (~(DEBUGCTLMSR_BTF | DEBUGCTLMSR_LBR))
594+
#define DEBUGCTL_RESERVED_BITS (~DEBUGCTLMSR_LBR)
595595

596596
extern bool dump_invalid_vmcb;
597597

0 commit comments

Comments
 (0)