From: Yosry Ahmed <yosry.ahmed@linux.dev>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Yosry Ahmed <yosryahmed@google.com>,
Yosry Ahmed <yosry.ahmed@linux.dev>
Subject: [PATCH 07/12] KVM: selftests: Pass the root HVA directly to nested mapping functions
Date: Wed, 1 Oct 2025 14:58:11 +0000 [thread overview]
Message-ID: <20251001145816.1414855-8-yosry.ahmed@linux.dev> (raw)
In-Reply-To: <20251001145816.1414855-1-yosry.ahmed@linux.dev>
From: Yosry Ahmed <yosryahmed@google.com>
The nested mapping functions used to create EPT mappings currently
accept a struct vmx_pages argument, only to get the EPT root from it
later. In preparation for generalizing these functions to work for NPTs,
pass the EPT root HVA directly instead.
Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
---
tools/testing/selftests/kvm/include/x86/vmx.h | 8 +++----
.../testing/selftests/kvm/lib/x86/memstress.c | 4 ++--
tools/testing/selftests/kvm/lib/x86/vmx.c | 24 +++++++++----------
.../selftests/kvm/x86/vmx_dirty_log_test.c | 6 ++---
4 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/x86/vmx.h b/tools/testing/selftests/kvm/include/x86/vmx.h
index edb3c391b9824..06ae68cf9635c 100644
--- a/tools/testing/selftests/kvm/include/x86/vmx.h
+++ b/tools/testing/selftests/kvm/include/x86/vmx.h
@@ -559,13 +559,13 @@ bool load_vmcs(struct vmx_pages *vmx);
bool ept_1g_pages_supported(void);
-void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
+void nested_pg_map(void *root_hva, struct kvm_vm *vm,
uint64_t nested_paddr, uint64_t paddr);
-void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
+void nested_map(void *root_hva, struct kvm_vm *vm,
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(void *root_hva, struct kvm_vm *vm,
uint32_t memslot);
-void nested_identity_map_1g(struct vmx_pages *vmx, struct kvm_vm *vm,
+void nested_identity_map_1g(void *root_hva, struct kvm_vm *vm,
uint64_t addr, uint64_t size);
bool kvm_cpu_has_ept(void);
void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm,
diff --git a/tools/testing/selftests/kvm/lib/x86/memstress.c b/tools/testing/selftests/kvm/lib/x86/memstress.c
index 7f5d62a65c68a..7981e295cac70 100644
--- a/tools/testing/selftests/kvm/lib/x86/memstress.c
+++ b/tools/testing/selftests/kvm/lib/x86/memstress.c
@@ -70,11 +70,11 @@ void memstress_setup_ept(struct vmx_pages *vmx, struct kvm_vm *vm)
* KVM can shadow the EPT12 with the maximum huge page size supported
* by the backing source.
*/
- nested_identity_map_1g(vmx, vm, 0, 0x100000000ULL);
+ nested_identity_map_1g(vmx->eptp_hva, vm, 0, 0x100000000ULL);
start = align_down(memstress_args.gpa, PG_SIZE_1G);
end = align_up(memstress_args.gpa + memstress_args.size, PG_SIZE_1G);
- nested_identity_map_1g(vmx, vm, start, end - start);
+ nested_identity_map_1g(vmx->eptp_hva, vm, start, end - start);
}
void memstress_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_vcpu *vcpus[])
diff --git a/tools/testing/selftests/kvm/lib/x86/vmx.c b/tools/testing/selftests/kvm/lib/x86/vmx.c
index d4d1208dd0238..04c4b97bcd1e7 100644
--- a/tools/testing/selftests/kvm/lib/x86/vmx.c
+++ b/tools/testing/selftests/kvm/lib/x86/vmx.c
@@ -394,11 +394,11 @@ static void nested_create_pte(struct kvm_vm *vm,
}
-void __nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
+void __nested_pg_map(void *root_hva, struct kvm_vm *vm,
uint64_t nested_paddr, uint64_t paddr, int target_level)
{
const uint64_t page_size = PG_LEVEL_SIZE(target_level);
- struct eptPageTableEntry *pt = vmx->eptp_hva, *pte;
+ struct eptPageTableEntry *pt = root_hva, *pte;
uint16_t index;
TEST_ASSERT(vm->mode == VM_MODE_PXXV48_4K, "Attempt to use "
@@ -445,10 +445,10 @@ void __nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
}
-void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
+void nested_pg_map(void *root_hva, struct kvm_vm *vm,
uint64_t nested_paddr, uint64_t paddr)
{
- __nested_pg_map(vmx, vm, nested_paddr, paddr, PG_LEVEL_4K);
+ __nested_pg_map(root_hva, vm, nested_paddr, paddr, PG_LEVEL_4K);
}
/*
@@ -468,7 +468,7 @@ void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
* Within the VM given by vm, creates a nested guest translation for the
* page range starting at nested_paddr to the page range starting at paddr.
*/
-void __nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
+void __nested_map(void *root_hva, struct kvm_vm *vm,
uint64_t nested_paddr, uint64_t paddr, uint64_t size,
int level)
{
@@ -479,22 +479,22 @@ void __nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
TEST_ASSERT(paddr + size > paddr, "Paddr overflow");
while (npages--) {
- __nested_pg_map(vmx, vm, nested_paddr, paddr, level);
+ __nested_pg_map(root_hva, vm, nested_paddr, paddr, level);
nested_paddr += page_size;
paddr += page_size;
}
}
-void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
+void nested_map(void *root_hva, struct kvm_vm *vm,
uint64_t nested_paddr, uint64_t paddr, uint64_t size)
{
- __nested_map(vmx, vm, nested_paddr, paddr, size, PG_LEVEL_4K);
+ __nested_map(root_hva, vm, nested_paddr, paddr, size, PG_LEVEL_4K);
}
/* Prepare an identity extended page table that maps all the
* physical pages in VM.
*/
-void nested_map_memslot(struct vmx_pages *vmx, struct kvm_vm *vm,
+void nested_map_memslot(void *root_hva, struct kvm_vm *vm,
uint32_t memslot)
{
sparsebit_idx_t i, last;
@@ -508,7 +508,7 @@ void nested_map_memslot(struct vmx_pages *vmx, struct kvm_vm *vm,
if (i > last)
break;
- nested_map(vmx, vm,
+ nested_map(root_hva, vm,
(uint64_t)i << vm->page_shift,
(uint64_t)i << vm->page_shift,
1 << vm->page_shift);
@@ -516,10 +516,10 @@ void nested_map_memslot(struct vmx_pages *vmx, struct kvm_vm *vm,
}
/* Identity map a region with 1GiB Pages. */
-void nested_identity_map_1g(struct vmx_pages *vmx, struct kvm_vm *vm,
+void nested_identity_map_1g(void *root_hva, struct kvm_vm *vm,
uint64_t addr, uint64_t size)
{
- __nested_map(vmx, vm, addr, addr, size, PG_LEVEL_1G);
+ __nested_map(root_hva, vm, addr, addr, size, PG_LEVEL_1G);
}
bool kvm_cpu_has_ept(void)
diff --git a/tools/testing/selftests/kvm/x86/vmx_dirty_log_test.c b/tools/testing/selftests/kvm/x86/vmx_dirty_log_test.c
index fa512d033205f..21a57805e9780 100644
--- a/tools/testing/selftests/kvm/x86/vmx_dirty_log_test.c
+++ b/tools/testing/selftests/kvm/x86/vmx_dirty_log_test.c
@@ -121,9 +121,9 @@ static void test_vmx_dirty_log(bool enable_ept)
*/
if (enable_ept) {
prepare_eptp(vmx, vm, 0);
- nested_map_memslot(vmx, vm, 0);
- nested_map(vmx, vm, NESTED_TEST_MEM1, GUEST_TEST_MEM, 4096);
- nested_map(vmx, vm, NESTED_TEST_MEM2, GUEST_TEST_MEM, 4096);
+ nested_map_memslot(vmx->eptp_hva, vm, 0);
+ nested_map(vmx->eptp_hva, vm, NESTED_TEST_MEM1, GUEST_TEST_MEM, 4096);
+ nested_map(vmx->eptp_hva, vm, NESTED_TEST_MEM2, GUEST_TEST_MEM, 4096);
}
bmap = bitmap_zalloc(TEST_MEM_PAGES);
--
2.51.0.618.g983fd99d29-goog
next prev parent reply other threads:[~2025-10-01 14:58 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 14:58 [PATCH 00/12] Extend test coverage for nested SVM Yosry Ahmed
2025-10-01 14:58 ` [PATCH 01/12] KVM: selftests: Minor improvements to asserts in test_vmx_nested_state() Yosry Ahmed
2025-10-09 21:44 ` Jim Mattson
2025-10-01 14:58 ` [PATCH 02/12] KVM: selftests: Extend vmx_set_nested_state_test to cover SVM Yosry Ahmed
2025-10-09 22:40 ` Jim Mattson
2025-10-09 23:13 ` Yosry Ahmed
2025-10-01 14:58 ` [PATCH 03/12] KVM: selftests: Extend vmx_close_while_nested_test " Yosry Ahmed
2025-10-09 22:44 ` Jim Mattson
2025-10-01 14:58 ` [PATCH 04/12] KVM: selftests: Extend vmx_nested_tsc_scaling_test " Yosry Ahmed
2025-10-09 22:51 ` Jim Mattson
2025-10-09 23:19 ` Yosry Ahmed
2025-10-01 14:58 ` [PATCH 05/12] KVM: selftests: Remove invalid CR3 test from vmx_tsc_adjust_test Yosry Ahmed
2025-10-09 22:55 ` Jim Mattson
2025-10-09 23:24 ` Yosry Ahmed
2025-10-01 14:58 ` [PATCH 06/12] KVM: selftests: Extend vmx_tsc_adjust_test to cover SVM Yosry Ahmed
2025-10-09 23:27 ` Jim Mattson
2025-10-01 14:58 ` Yosry Ahmed [this message]
2025-10-09 23:30 ` [PATCH 07/12] KVM: selftests: Pass the root HVA directly to nested mapping functions Jim Mattson
2025-10-01 14:58 ` [PATCH 08/12] KVM: selftests: Use 'leaf' instead of hugepage to describe EPT entries Yosry Ahmed
2025-10-13 18:34 ` Jim Mattson
2025-10-13 21:41 ` Sean Christopherson
2025-10-13 22:25 ` Yosry Ahmed
2025-10-13 22:58 ` Sean Christopherson
2025-10-13 23:13 ` Yosry Ahmed
2025-10-15 18:20 ` Sean Christopherson
2025-10-01 14:58 ` [PATCH 09/12] KVM: selftests: Move all PTE accesses into nested_create_pte() Yosry Ahmed
2025-10-13 18:41 ` Jim Mattson
2025-10-01 14:58 ` [PATCH 10/12] KVM: selftests: Move EPT-specific init outside nested_create_pte() Yosry Ahmed
2025-10-13 18:52 ` Jim Mattson
2025-10-01 14:58 ` [PATCH 11/12] KVM: selftests: Refactor generic nested mapping outside VMX code Yosry Ahmed
2025-10-13 19:04 ` Jim Mattson
2025-10-01 14:58 ` [PATCH 12/12] KVM: selftests: Extend vmx_dirty_log_test to cover SVM Yosry Ahmed
2025-10-01 17:37 ` [PATCH 00/12] Extend test coverage for nested SVM Yosry Ahmed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251001145816.1414855-8-yosry.ahmed@linux.dev \
--to=yosry.ahmed@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox