Re: [PATCH v2 18/23] KVM: selftests: Generalize nested mapping functions
From: Yosry Ahmed
Date: Thu Nov 20 2025 - 19:20:19 EST
On Thu, Nov 20, 2025 at 04:10:51PM -0800, Sean Christopherson wrote:
> On Tue, Oct 21, 2025, Yosry Ahmed wrote:
> > Instead of passing in a pointer to struct vmx_pages, pass in the GPA of
> > the root of the EPTs, as that's the only member being used. Furthermore,
> > only use ept_pte_masks for VMX, and use x86_pte_masks otherwise (which
> > is what NPT uses).
> >
> > This is in preparation of supporting NPTs as well.
> >
> > No functional change intended.
> >
> > Signed-off-by: Yosry Ahmed <yosry.ahmed@xxxxxxxxx>
> > ---
> > tools/testing/selftests/kvm/include/x86/vmx.h | 6 +++---
> > .../testing/selftests/kvm/lib/x86/memstress.c | 4 ++--
> > tools/testing/selftests/kvm/lib/x86/vmx.c | 20 ++++++++++---------
> > .../selftests/kvm/x86/vmx_dirty_log_test.c | 6 +++---
> > 4 files changed, 19 insertions(+), 17 deletions(-)
> >
> > diff --git a/tools/testing/selftests/kvm/include/x86/vmx.h b/tools/testing/selftests/kvm/include/x86/vmx.h
> > index 5aa14ceed050a..4429e83e1f52c 100644
> > --- a/tools/testing/selftests/kvm/include/x86/vmx.h
> > +++ b/tools/testing/selftests/kvm/include/x86/vmx.h
> > @@ -561,11 +561,11 @@ bool load_vmcs(struct vmx_pages *vmx);
> >
> > bool ept_1g_pages_supported(void);
> >
> > -void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
> > +void nested_map(struct kvm_vm *vm, vm_paddr_t root_gpa,
> > uint64_t nested_paddr, uint64_t paddr, uint64_t size);
> > -void nested_map_memslot(struct vmx_pages *vmx, struct kvm_vm *vm,
> > +void nested_map_memslot(struct kvm_vm *vm, vm_paddr_t root_gpa,
> > uint32_t memslot);
> > -void nested_identity_map_1g(struct vmx_pages *vmx, struct kvm_vm *vm,
> > +void nested_identity_map_1g(struct kvm_vm *vm, vm_paddr_t root_gpa,
> > uint64_t addr, uint64_t size);
>
> Ugh, "nested" is a bad namespace. Running L2 doesn't strictly require nested
> TDP, and the operations themselves are non-nested, in the sense that we're
> modifying stage-2 / TDP page tables.
>
> My vote would be to do a rename to either stage2_pg_map() or tdp_pg_map()
It is 'nested' in the since that we are creating mappings in nested TDP
(i.e. not L0's TDP), but I guess that doesn't make much sense given that
most selftests library functions are already referring to the guest
anyway.
I will use tdp_pg_map() only because that's the common x86 terminology
(although I do like stage2 better in general).