Skip to content

Commit 947ab90

Browse files
committed
KVM: selftests: Verify MSRs are (not) in save/restore list when (un)supported
Add a check in the MSRs test to verify that KVM's reported support for MSRs with feature bits is consistent between KVM's MSR save/restore lists and KVM's supported CPUID. To deal with Intel's wonderful decision to bundle IBT and SHSTK under CET, track the "second" feature to avoid false failures when running on a CPU with only one of IBT or SHSTK. Reviewed-by: Chao Gao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 3469fd2 commit 947ab90

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,29 @@ static void test_msrs(void)
444444
}
445445

446446
for (idx = 0; idx < ARRAY_SIZE(__msrs); idx++) {
447-
if (msrs[idx].is_kvm_defined) {
447+
struct kvm_msr *msr = &msrs[idx];
448+
449+
if (msr->is_kvm_defined) {
448450
for (i = 0; i < NR_VCPUS; i++)
449451
host_test_kvm_reg(vcpus[i]);
450452
continue;
451453
}
452454

455+
/*
456+
* Verify KVM_GET_SUPPORTED_CPUID and KVM_GET_MSR_INDEX_LIST
457+
* are consistent with respect to MSRs whose existence is
458+
* enumerated via CPUID. Skip the check for FS/GS.base MSRs,
459+
* as they aren't reported in the save/restore list since their
460+
* state is managed via SREGS.
461+
*/
462+
TEST_ASSERT(msr->index == MSR_FS_BASE || msr->index == MSR_GS_BASE ||
463+
kvm_msr_is_in_save_restore_list(msr->index) ==
464+
(kvm_cpu_has(msr->feature) || kvm_cpu_has(msr->feature2)),
465+
"%s %s in save/restore list, but %s according to CPUID", msr->name,
466+
kvm_msr_is_in_save_restore_list(msr->index) ? "is" : "isn't",
467+
(kvm_cpu_has(msr->feature) || kvm_cpu_has(msr->feature2)) ?
468+
"supported" : "unsupported");
469+
453470
sync_global_to_guest(vm, idx);
454471

455472
vcpus_run(vcpus, NR_VCPUS);

0 commit comments

Comments
 (0)