]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: selftests: Allow kvm_cpu_has_ept() to be called on AMD CPUs
authorYosry Ahmed <yosry.ahmed@linux.dev>
Tue, 30 Dec 2025 23:01:44 +0000 (15:01 -0800)
committerSean Christopherson <seanjc@google.com>
Thu, 8 Jan 2026 20:02:14 +0000 (12:02 -0800)
In preparation for generalizing the nested dirty logging test, checking
if either EPT or NPT is enabled will be needed. To avoid needing to gate
the kvm_cpu_has_ept() call by the CPU type, make sure the function
returns false if VMX is not available instead of trying to read VMX-only
MSRs.

No functional change intended.

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Link: https://patch.msgid.link/20251230230150.4150236-16-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/lib/x86/vmx.c

index 448a6345746782aaf668111aa7d7bda12ee043e3..c87b340362a900da8bc427f4d1d4780501443f2d 100644 (file)
@@ -377,6 +377,9 @@ bool kvm_cpu_has_ept(void)
 {
        uint64_t ctrl;
 
+       if (!kvm_cpu_has(X86_FEATURE_VMX))
+               return false;
+
        ctrl = kvm_get_feature_msr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS) >> 32;
        if (!(ctrl & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS))
                return false;