]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Update hwcr_msr_test for CPUID faulting bit
authorJim Mattson <jmattson@google.com>
Wed, 27 May 2026 17:43:47 +0000 (10:43 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 27 May 2026 18:21:41 +0000 (11:21 -0700)
Add BIT_ULL(35) (CpuidUserDis) to the valid mask in hwcr_msr_test, now that
KVM accepts writes to this bit when the guest CPUID advertises
CpuidUserDis.

Signed-off-by: Jim Mattson <jmattson@google.com>
Link: https://patch.msgid.link/20260527174347.2356165-6-jmattson@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86/processor.h
tools/testing/selftests/kvm/x86/hwcr_msr_test.c

index 06878e7c73479074beef31032617f7d477bcbe18..513e4a1075facfa2413386bae9957bc3cc6e7fd5 100644 (file)
@@ -226,6 +226,7 @@ struct kvm_x86_cpu_feature {
 #define X86_FEATURE_SEV                        KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 1)
 #define X86_FEATURE_SEV_ES             KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 3)
 #define X86_FEATURE_SEV_SNP            KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 4)
+#define        X86_FEATURE_GP_ON_USER_CPUID    KVM_X86_CPU_FEATURE(0x80000021, 0, EAX, 17)
 #define        X86_FEATURE_PERFMON_V2          KVM_X86_CPU_FEATURE(0x80000022, 0, EAX, 0)
 #define        X86_FEATURE_LBR_PMC_FREEZE      KVM_X86_CPU_FEATURE(0x80000022, 0, EAX, 2)
 
index 8e20a03b3329876b1e008dc15aa2e5b28a07a1fe..53b7971aa072926657febbc8cbedffe31094b6d8 100644 (file)
 void test_hwcr_bit(struct kvm_vcpu *vcpu, unsigned int bit)
 {
        const u64 ignored = BIT_ULL(3) | BIT_ULL(6) | BIT_ULL(8);
-       const u64 valid = BIT_ULL(18) | BIT_ULL(24);
-       const u64 legal = ignored | valid;
+       u64 valid = BIT_ULL(18) | BIT_ULL(24);
        u64 val = BIT_ULL(bit);
        u64 actual;
+       u64 legal;
        int r;
 
+       if (kvm_cpu_has(X86_FEATURE_GP_ON_USER_CPUID))
+               valid |= BIT_ULL(35);
+
+       legal = ignored | valid;
+
        r = _vcpu_set_msr(vcpu, MSR_K7_HWCR, val);
        TEST_ASSERT(val & ~legal ? !r : r == 1,
                    "Expected KVM_SET_MSRS(MSR_K7_HWCR) = 0x%lx to %s",