Re: [PATCH v3 08/16] KVM: selftests: Use a nested MMU to share nested EPTs between vCPUs

From: Sean Christopherson

Date: Tue Dec 23 2025 - 18:16:25 EST


On Thu, Nov 27, 2025, Yosry Ahmed wrote:
> diff --git a/tools/testing/selftests/kvm/lib/x86/vmx.c b/tools/testing/selftests/kvm/lib/x86/vmx.c
> index a3e2eae981da..5d799ec5f7c6 100644
> --- a/tools/testing/selftests/kvm/lib/x86/vmx.c
> +++ b/tools/testing/selftests/kvm/lib/x86/vmx.c
> @@ -56,6 +56,16 @@ int vcpu_enable_evmcs(struct kvm_vcpu *vcpu)
> return evmcs_ver;
> }
>
> +void vm_enable_ept(struct kvm_vm *vm)
> +{
> + TEST_ASSERT(kvm_cpu_has_ept(), "KVM doesn't support nested EPT");
> + if (vm->arch.nested.mmu)

Make this an assert, attempting to enable EPT multiple times for a single VM is
a test bug. That way we don't have to worry about silly situations in the future,
e.g. like trying to change from 4-level to 5-level after the MMU has already been
created.

Ditto for the NPT code.

> + return;
> +
> + /* EPTP_PWL_4 is always used */
> + vm->arch.nested.mmu = mmu_create(vm, 4, NULL);