Re: [PATCH 5/8] KVM: selftests: Add basic stress test for save+restore and #PF handling

From: Yosry Ahmed

Date: Thu May 28 2026 - 18:15:41 EST


> diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testing/selftests/kvm/lib/x86/processor.c
> index caefcd12df8d2..6708fa8b6a304 100644
> --- a/tools/testing/selftests/kvm/lib/x86/processor.c
> +++ b/tools/testing/selftests/kvm/lib/x86/processor.c
> @@ -343,6 +343,17 @@ void virt_map_level(struct kvm_vm *vm, gva_t gva, gpa_t gpa,
> }
> }
>
> +void virt_map_page_tables(struct kvm_vm *vm)
> +{
> + gpa_t gpa = KVM_GUEST_PAGE_TABLE_MIN_PADDR;
> + struct userspace_mem_region *region;
> + u64 pt_size;
> +
> + region = memslot2region(vm, vm->memslots[MEM_REGION_PT]);
> + pt_size = region->region.guest_phys_addr + region->region.memory_size - gpa;
> + virt_map(vm, gpa, gpa, pt_size / getpagesize());
> +}

This is wrong. It tries to map the entire memslot for MEM_REGION_PT,
starting at KVM_GUEST_PAGE_TABLE_MIN_PADDR. The problem is, the
memslot is shared with other things like ELF. So this tries to map
everything from KVM_GUEST_PAGE_TABLE_MIN_PADDR (0x180000) to the end
of the memslot (0x291000 in this case) using identity GVA->GPA
mappings.

When using clang's LLD, ELF starts at GVA 0x20000, so this tries to
remap the ELF GVAs to a different GPAs, and an assertion fires in
__virt_pg_map().

Without LLD (when I did my initial testing), ELF starts at GVA
0x40000, so it's outside the range mapped by virt_map_page_tables().

We can fix this by creating a separate memslot for page tables like
other archs do, but I think for this case, it's probably simpler if
the test just walks the page tables and maps them. It should be one
page at each level.