Skip to content

Commit 27c4135

Browse files
committed
KVM: selftests: Add support for MSR_IA32_{S,U}_CET to MSRs test
Extend the MSRs test to support {S,U}_CET, which are a bit of a pain to handled due to the MSRs existing if IBT *or* SHSTK is supported. To deal with Intel's wonderful decision to bundle IBT and SHSTK under CET, track the second feature, but skip only RDMSR #GP tests to avoid false failures when running on a CPU with only one of IBT or SHSTK (the WRMSR #GP tests are still valid since the enable bits are per-feature). Reviewed-by: Chao Gao <chao.gao@intel.com> Link: https://lore.kernel.org/r/20250919223258.1604852-47-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 9c38ddb commit 27c4135

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

tools/testing/selftests/kvm/x86/msrs_test.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,26 @@ static void guest_test_unsupported_msr(const struct kvm_msr *msr)
132132
if (ignore_unsupported_msrs)
133133
goto skip_wrmsr_gp;
134134

135-
if (this_cpu_has(msr->feature2))
136-
goto skip_wrmsr_gp;
135+
/*
136+
* {S,U}_CET exist if IBT or SHSTK is supported, but with bits that are
137+
* writable only if their associated feature is supported. Skip the
138+
* RDMSR #GP test if the secondary feature is supported, but perform
139+
* the WRMSR #GP test as the to-be-written value is tied to the primary
140+
* feature. For all other MSRs, simply do nothing.
141+
*/
142+
if (this_cpu_has(msr->feature2)) {
143+
if (msr->index != MSR_IA32_U_CET &&
144+
msr->index != MSR_IA32_S_CET)
145+
goto skip_wrmsr_gp;
146+
147+
goto skip_rdmsr_gp;
148+
}
137149

138150
vec = rdmsr_safe(msr->index, &val);
139151
__GUEST_ASSERT(vec == GP_VECTOR, "Wanted #GP on RDMSR(0x%x), got %s",
140152
msr->index, ex_str(vec));
141153

154+
skip_rdmsr_gp:
142155
vec = wrmsr_safe(msr->index, msr->write_val);
143156
__GUEST_ASSERT(vec == GP_VECTOR, "Wanted #GP on WRMSR(0x%x, 0x%lx), got %s",
144157
msr->index, msr->write_val, ex_str(vec));
@@ -276,6 +289,10 @@ static void test_msrs(void)
276289
MSR_TEST_CANONICAL(MSR_CSTAR, LM),
277290
MSR_TEST(MSR_SYSCALL_MASK, 0xffffffff, 0, LM),
278291

292+
MSR_TEST2(MSR_IA32_S_CET, CET_SHSTK_EN, CET_RESERVED, SHSTK, IBT),
293+
MSR_TEST2(MSR_IA32_S_CET, CET_ENDBR_EN, CET_RESERVED, IBT, SHSTK),
294+
MSR_TEST2(MSR_IA32_U_CET, CET_SHSTK_EN, CET_RESERVED, SHSTK, IBT),
295+
MSR_TEST2(MSR_IA32_U_CET, CET_ENDBR_EN, CET_RESERVED, IBT, SHSTK),
279296
MSR_TEST_CANONICAL(MSR_IA32_PL0_SSP, SHSTK),
280297
MSR_TEST(MSR_IA32_PL0_SSP, canonical_val, canonical_val | 1, SHSTK),
281298
MSR_TEST_CANONICAL(MSR_IA32_PL1_SSP, SHSTK),

0 commit comments

Comments
 (0)