]> git.ipfire.org Git - thirdparty/linux.git/commit
KVM: selftests: Make sure vm->vpages_mapped is always up-to-date
authorYosry Ahmed <yosry.ahmed@linux.dev>
Tue, 21 Oct 2025 07:47:24 +0000 (07:47 +0000)
committerSean Christopherson <seanjc@google.com>
Fri, 21 Nov 2025 18:17:05 +0000 (10:17 -0800)
commitd2e50389ab44acfa05e72604d701a70b234f9938
tree2ae4d349f601610676a23bde5cead224931e1e2c
parent1de4dc15baa1917adb3a0b369d00d818be9d9bab
KVM: selftests: Make sure vm->vpages_mapped is always up-to-date

Call paths leading to __virt_pg_map() are currently:
(a) virt_pg_map() -> virt_arch_pg_map() -> __virt_pg_map()
(b) virt_map_level() -> __virt_pg_map()

For (a), calls to virt_pg_map() from kvm_util.c make sure they update
vm->vpages_mapped, but other callers do not. Move the sparsebit_set()
call into virt_pg_map() to make sure all callers are captured.

For (b), call sparsebit_set_num() from virt_map_level().

It's tempting to have a single the call inside __virt_pg_map(), however:
- The call path in (a) is not x86-specific, while (b) is. Moving the
  call into __virt_pg_map() would require doing something similar for
  other archs implementing virt_pg_map().

- Future changes will reusue __virt_pg_map() for nested PTEs, which should
  not update vm->vpages_mapped, i.e. a triple underscore version that does
  not update vm->vpages_mapped would need to be provided.

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Link: https://patch.msgid.link/20251021074736.1324328-12-yosry.ahmed@linux.dev
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/kvm_util.h
tools/testing/selftests/kvm/lib/kvm_util.c
tools/testing/selftests/kvm/lib/x86/processor.c