Skip to content

Commit 9a7a0e1

Browse files
yosrym93sean-jc
authored andcommitted
x86/svm: Correctly extract the IP from LBR MSRs
Currently, only bit 63 is ignored when reading LBR MSRs. However, different AMD CPUs use upper bits of the MSR differently. For example, some Zen 4 processors document bit 63 in LASTBRACNHFROMIP and bits 63:61 in LASTBRANCHTOIP to be reserved. On the other hand, some Zen 5 processors bits 63:57 to be reserved in both MSRs. Use the common denominator and always bits 63:57 when reading the LBR MSRs, which should be sufficient testing. This fixes the test flaking on some AMD processors that set bit 62 in LASTBRANCHTOIP. Reported-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev> Link: https://patch.msgid.link/20251113224639.2916783-1-yosry.ahmed@linux.dev Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 09e2c95 commit 9a7a0e1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/x86/msr.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@
8585
#define MSR_IA32_LASTINTFROMIP 0x000001dd
8686
#define MSR_IA32_LASTINTTOIP 0x000001de
8787

88-
/* Yes, AMD does indeed record mispredict info in the LBR records themselves. */
89-
#define AMD_LBR_RECORD_MISPREDICT BIT_ULL(63)
88+
/*
89+
* Different AMD CPUs use the upper bits of the IP LBRs differently. For the
90+
* purposes of tests, use the common denominator of the IP bits.
91+
*/
92+
#define AMD_LBR_RECORD_IP_BITS 57
93+
#define AMD_LBR_RECORD_IP_MASK ((1UL << AMD_LBR_RECORD_IP_BITS)-1)
9094

9195
#define LBR_INFO_MISPRED BIT_ULL(63)
9296
#define LBR_INFO_IN_TX BIT_ULL(62)

x86/svm_tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3008,7 +3008,7 @@ static void svm_no_nm_test(void)
30083008

30093009
static u64 amd_get_lbr_rip(u32 msr)
30103010
{
3011-
return rdmsr(msr) & ~AMD_LBR_RECORD_MISPREDICT;
3011+
return rdmsr(msr) & AMD_LBR_RECORD_IP_MASK;
30123012
}
30133013

30143014
#define HOST_CHECK_LBR(from_expected, to_expected) \

0 commit comments

Comments
 (0)