summaryrefslogtreecommitdiff
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorFrank Zhu <frankzhu@zhaoxin.com>2026-09-10 19:54:14 +0800
committerSean Christopherson <seanjc@google.com>2026-09-11 09:37:27 -0700
commit0d5c14800de007ee45fd76008e4a115f170fa88d (patch)
tree1d5e0f526f932fca52f0f41ae0b8bc11e44313eb /tools/testing/selftests
parent1a0abfad6c8096dfb00aa5a764d92819ff749103 (diff)
downloadlinux-next-0d5c14800de007ee45fd76008e4a115f170fa88d.tar.gz
linux-next-0d5c14800de007ee45fd76008e4a115f170fa88d.zip
KVM: selftests: Check for APIC access virtualization support in said test
Not all CPUs that support VMX necessarily support the "virtualize APIC accesses" secondary processor-based VM-execution control. For example, some Zhaoxin CPUs lack this feature. Add a capability check before running the test to properly skip on unsupported hardware instead of failing. Carve out the guts of kvm_cpu_has_ept() into a generic helper and use said helper to provide kvm_cpu_has_vmx_apic_access_virt(). Signed-off-by: Frank Zhu <frankzhu@zhaoxin.com> Link: https://patch.msgid.link/20260910115414.3015260-10-ewanhai-oc@zhaoxin.com [sean: add a helper instead of copy+pasting kvm_cpu_has_ept()] Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r--tools/testing/selftests/kvm/include/x86/vmx.h13
-rw-r--r--tools/testing/selftests/kvm/lib/x86/vmx.c12
-rw-r--r--tools/testing/selftests/kvm/x86/vmx_apic_access_test.c2
3 files changed, 19 insertions, 8 deletions
diff --git a/tools/testing/selftests/kvm/include/x86/vmx.h b/tools/testing/selftests/kvm/include/x86/vmx.h
index ca67a618b68f..8fd97434eee5 100644
--- a/tools/testing/selftests/kvm/include/x86/vmx.h
+++ b/tools/testing/selftests/kvm/include/x86/vmx.h
@@ -503,7 +503,18 @@ void load_vmcs(struct vmx_pages *vmx);
bool ept_1g_pages_supported(void);
-bool kvm_cpu_has_ept(void);
+bool kvm_cpu_has_secondary_exec_control(u32 ctrl);
+
+static inline bool kvm_cpu_has_ept(void)
+{
+ return kvm_cpu_has_secondary_exec_control(SECONDARY_EXEC_ENABLE_EPT);
+}
+
+static inline bool kvm_cpu_has_vmx_virtualize_apic_accesses(void)
+{
+ return kvm_cpu_has_secondary_exec_control(SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES);
+}
+
void vm_enable_ept(struct kvm_vm *vm);
void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm);
diff --git a/tools/testing/selftests/kvm/lib/x86/vmx.c b/tools/testing/selftests/kvm/lib/x86/vmx.c
index 6a53c8ce3b3c..5a06746ebea4 100644
--- a/tools/testing/selftests/kvm/lib/x86/vmx.c
+++ b/tools/testing/selftests/kvm/lib/x86/vmx.c
@@ -422,19 +422,19 @@ void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip)
init_vmcs_guest_state(guest_rip, vmx->stack);
}
-bool kvm_cpu_has_ept(void)
+bool kvm_cpu_has_secondary_exec_control(u32 ctrl)
{
- u64 ctrl;
+ u64 ctrl_msr;
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))
+ ctrl_msr = kvm_get_feature_msr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS) >> 32;
+ if (!(ctrl_msr & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS))
return false;
- ctrl = kvm_get_feature_msr(MSR_IA32_VMX_PROCBASED_CTLS2) >> 32;
- return ctrl & SECONDARY_EXEC_ENABLE_EPT;
+ ctrl_msr = kvm_get_feature_msr(MSR_IA32_VMX_PROCBASED_CTLS2) >> 32;
+ return ctrl_msr & ctrl;
}
void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm)
diff --git a/tools/testing/selftests/kvm/x86/vmx_apic_access_test.c b/tools/testing/selftests/kvm/x86/vmx_apic_access_test.c
index d6373c414d18..1d7a529c8297 100644
--- a/tools/testing/selftests/kvm/x86/vmx_apic_access_test.c
+++ b/tools/testing/selftests/kvm/x86/vmx_apic_access_test.c
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
- TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
+ TEST_REQUIRE(kvm_cpu_has_vmx_virtualize_apic_accesses());
vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);