]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: SVM: Drop DEBUGCTL[5:2] from guest's effective value
authorSean Christopherson <seanjc@google.com>
Thu, 27 Feb 2025 22:24:06 +0000 (14:24 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 12:02:14 +0000 (13:02 +0100)
commit ee89e8013383d50a27ea9bf3c8a69eed6799856f upstream.

Drop bits 5:2 from the guest's effective DEBUGCTL value, as AMD changed
the architectural behavior of the bits and broke backwards compatibility.
On CPUs without BusLockTrap (or at least, in APMs from before ~2023),
bits 5:2 controlled the behavior of external pins:

  Performance-Monitoring/Breakpoint Pin-Control (PBi)—Bits 5:2, read/write.
  Software uses thesebits to control the type of information reported by
  the four external performance-monitoring/breakpoint pins on the
  processor. When a PBi bit is cleared to 0, the corresponding external pin
  (BPi) reports performance-monitor information. When a PBi bit is set to
  1, the corresponding external pin (BPi) reports breakpoint information.

With the introduction of BusLockTrap, presumably to be compatible with
Intel CPUs, AMD redefined bit 2 to be BLCKDB:

  Bus Lock #DB Trap (BLCKDB)—Bit 2, read/write. Software sets this bit to
  enable generation of a #DB trap following successful execution of a bus
  lock when CPL is > 0.

and redefined bits 5:3 (and bit 6) as "6:3 Reserved MBZ".

Ideally, KVM would treat bits 5:2 as reserved.  Defer that change to a
feature cleanup to avoid breaking existing guest in LTS kernels.  For now,
drop the bits to retain backwards compatibility (of a sort).

Note, dropping bits 5:2 is still a guest-visible change, e.g. if the guest
is enabling LBRs *and* the legacy PBi bits, then the state of the PBi bits
is visible to the guest, whereas now the guest will always see '0'.

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-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm.h

index 9998108669f1cbf2fdb10d6d9a8dc3423518afda..e7c247ca687c240cf6c93c6070551e83b87f7f9a 100644 (file)
@@ -3167,6 +3167,18 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
                        kvm_pr_unimpl_wrmsr(vcpu, ecx, data);
                        break;
                }
+
+               /*
+                * AMD changed the architectural behavior of bits 5:2.  On CPUs
+                * without BusLockTrap, bits 5:2 control "external pins", but
+                * on CPUs that support BusLockDetect, bit 2 enables BusLockTrap
+                * and bits 5:3 are reserved-to-zero.  Sadly, old KVM allowed
+                * the guest to set bits 5:2 despite not actually virtualizing
+                * Performance-Monitoring/Breakpoint external pins.  Drop bits
+                * 5:2 for backwards compatibility.
+                */
+               data &= ~GENMASK(5, 2);
+
                if (data & DEBUGCTL_RESERVED_BITS)
                        return 1;
 
index 43fa6a16eb1917821945ca8fdebf1caff1ddcb54..8c1e24ca50b589895c0c4625c3573a48b29f3f50 100644 (file)
@@ -591,7 +591,7 @@ static inline bool is_vnmi_enabled(struct vcpu_svm *svm)
 /* svm.c */
 #define MSR_INVALID                            0xffffffffU
 
-#define DEBUGCTL_RESERVED_BITS (~(0x3fULL))
+#define DEBUGCTL_RESERVED_BITS (~(DEBUGCTLMSR_BTF | DEBUGCTLMSR_LBR))
 
 extern bool dump_invalid_vmcb;