On Thu, Sep 10, 2026, Ewan Hai-oc wrote:
> diff --git a/tools/testing/selftests/kvm/lib/x86/vmx.c 
> b/tools/testing/selftests/kvm/lib/x86/vmx.c
> index 089e1a8af..e512191f1 100644
> --- a/tools/testing/selftests/kvm/lib/x86/vmx.c
> +++ b/tools/testing/selftests/kvm/lib/x86/vmx.c
> @@ -390,6 +390,21 @@ bool kvm_cpu_has_ept(void)
>       return ctrl & SECONDARY_EXEC_ENABLE_EPT;
>  }
>  
> +bool kvm_cpu_has_vmx_apic_access_virt(void)

This should be kvm_cpu_has_vmx_virtualize_apic_accesses() to match the macro, 
and
to match what KVM itself uses.

> +{
> +     u64 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;
> +
> +     ctrl = kvm_get_feature_msr(MSR_IA32_VMX_PROCBASED_CTLS2) >> 32;
> +     return ctrl & SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;

Carve out the guts of kvm_cpu_has_ept() into a helper isntead of copy+pasting.

> +}
> +
>  void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm 
> *vm)
>  {
>       vmx->apic_access = (void *)vm_alloc_page(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 463f73aa9..a1b6da4c0 100644
> --- a/tools/testing/selftests/kvm/x86/vmx_apic_access_test.c
> +++ b/tools/testing/selftests/kvm/x86/vmx_apic_access_test.c
> @@ -78,6 +78,7 @@ int main(int argc, char *argv[])
>       struct kvm_vm *vm;
>  
>       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
> +     TEST_REQUIRE(kvm_cpu_has_vmx_apic_access_virt());

This can replace the X86_FEATURE_VMX check, since KVM shouldn't report support
for virtualizing APIC accesses without VMX.

No need for a new version, I'll fixup everything when applying.

Reply via email to