Skip to content

Commit 01bcd82

Browse files
committed
KVM: selftests: Verify KVM stuffs runtime CPUID OS bits on CR4 writes
Extend x86's set sregs test to verify that KVM sets/clears OSXSAVE and OSKPKE according to CR4.XSAVE and CR4.PKE respectively. For performance reasons, KVM is responsible for emulating the architectural behavior of the OS CPUID bits tracking CR4. Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Link: https://lore.kernel.org/r/20241128013424.4096668-10-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent a2a791e commit 01bcd82

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ static void test_cr_bits(struct kvm_vcpu *vcpu, uint64_t cr4)
8585
rc = _vcpu_sregs_set(vcpu, &sregs);
8686
TEST_ASSERT(!rc, "Failed to set supported CR4 bits (0x%lx)", cr4);
8787

88+
TEST_ASSERT(!!(sregs.cr4 & X86_CR4_OSXSAVE) ==
89+
(vcpu->cpuid && vcpu_cpuid_has(vcpu, X86_FEATURE_OSXSAVE)),
90+
"KVM didn't %s OSXSAVE in CPUID as expected",
91+
(sregs.cr4 & X86_CR4_OSXSAVE) ? "set" : "clear");
92+
93+
TEST_ASSERT(!!(sregs.cr4 & X86_CR4_PKE) ==
94+
(vcpu->cpuid && vcpu_cpuid_has(vcpu, X86_FEATURE_OSPKE)),
95+
"KVM didn't %s OSPKE in CPUID as expected",
96+
(sregs.cr4 & X86_CR4_PKE) ? "set" : "clear");
97+
8898
vcpu_sregs_get(vcpu, &sregs);
8999
TEST_ASSERT(sregs.cr4 == cr4, "sregs.CR4 (0x%llx) != CR4 (0x%lx)",
90100
sregs.cr4, cr4);

0 commit comments

Comments
 (0)