Skip to content

Commit ce690e9

Browse files
dmatlackbonzini
authored andcommitted
KVM: selftests: Refactor nested_map() to specify target level
Refactor nested_map() to specify that it explicityl wants 4K mappings (the existing behavior) and push the implementation down into __nested_map(), which can be used in subsequent commits to create huge page mappings. No function change intended. Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: David Matlack <dmatlack@google.com> Message-Id: <20220520233249.3776001-5-dmatlack@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent b8ca01e commit ce690e9

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • tools/testing/selftests/kvm/lib/x86_64

tools/testing/selftests/kvm/lib/x86_64/vmx.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
486486
* nested_paddr - Nested guest physical address to map
487487
* paddr - VM Physical Address
488488
* size - The size of the range to map
489+
* level - The level at which to map the range
489490
*
490491
* Output Args: None
491492
*
@@ -494,22 +495,29 @@ void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
494495
* Within the VM given by vm, creates a nested guest translation for the
495496
* page range starting at nested_paddr to the page range starting at paddr.
496497
*/
497-
void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
498-
uint64_t nested_paddr, uint64_t paddr, uint64_t size)
498+
void __nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
499+
uint64_t nested_paddr, uint64_t paddr, uint64_t size,
500+
int level)
499501
{
500-
size_t page_size = vm->page_size;
502+
size_t page_size = PG_LEVEL_SIZE(level);
501503
size_t npages = size / page_size;
502504

503505
TEST_ASSERT(nested_paddr + size > nested_paddr, "Vaddr overflow");
504506
TEST_ASSERT(paddr + size > paddr, "Paddr overflow");
505507

506508
while (npages--) {
507-
nested_pg_map(vmx, vm, nested_paddr, paddr);
509+
__nested_pg_map(vmx, vm, nested_paddr, paddr, level);
508510
nested_paddr += page_size;
509511
paddr += page_size;
510512
}
511513
}
512514

515+
void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
516+
uint64_t nested_paddr, uint64_t paddr, uint64_t size)
517+
{
518+
__nested_map(vmx, vm, nested_paddr, paddr, size, PG_LEVEL_4K);
519+
}
520+
513521
/* Prepare an identity extended page table that maps all the
514522
* physical pages in VM.
515523
*/

0 commit comments

Comments
 (0)