Skip to content

Commit 0ce61db

Browse files
sean-jcgregkh
authored andcommitted
KVM: SVM: Drop DEBUGCTL[5:2] from guest's effective value
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 <[email protected]> Cc: [email protected] Reviewed-and-tested-by: Ravi Bangoria <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4a12b6c commit 0ce61db

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,6 +3039,18 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
30393039
__func__, data);
30403040
break;
30413041
}
3042+
3043+
/*
3044+
* AMD changed the architectural behavior of bits 5:2. On CPUs
3045+
* without BusLockTrap, bits 5:2 control "external pins", but
3046+
* on CPUs that support BusLockDetect, bit 2 enables BusLockTrap
3047+
* and bits 5:3 are reserved-to-zero. Sadly, old KVM allowed
3048+
* the guest to set bits 5:2 despite not actually virtualizing
3049+
* Performance-Monitoring/Breakpoint external pins. Drop bits
3050+
* 5:2 for backwards compatibility.
3051+
*/
3052+
data &= ~GENMASK(5, 2);
3053+
30423054
if (data & DEBUGCTL_RESERVED_BITS)
30433055
return 1;
30443056

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static inline bool is_x2apic_msrpm_offset(u32 offset)
539539
/* svm.c */
540540
#define MSR_INVALID 0xffffffffU
541541

542-
#define DEBUGCTL_RESERVED_BITS (~(0x3fULL))
542+
#define DEBUGCTL_RESERVED_BITS (~(DEBUGCTLMSR_BTF | DEBUGCTLMSR_LBR))
543543

544544
extern bool dump_invalid_vmcb;
545545

0 commit comments

Comments
 (0)