]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: Seed pkvm_ownership_selftest vcpu memcache
authorFuad Tabba <tabba@google.com>
Fri, 1 May 2026 11:21:47 +0000 (12:21 +0100)
committerMarc Zyngier <maz@kernel.org>
Thu, 7 May 2026 13:12:41 +0000 (14:12 +0100)
The hypercall handlers call pkvm_refill_memcache() to top up the
hyp_vcpu memcache before invoking __pkvm_host_{share,donate}_guest().
pkvm_ownership_selftest invokes those functions directly with a
static selftest_vcpu that has an empty memcache.

Seed selftest_vcpu's memcache from the prepopulated selftest
pages, leaving the remainder for selftest_vm.pool. Required by
the memcache-sufficiency pre-check added in the following
patches.

Assisted-by: Gemini:gemini-3.1-pro review-prompts
Signed-off-by: Fuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20260501112149.2824881-5-tabba@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/nvhe/pkvm.c

index e7496eb8562897cea1f21ccb77ebcde2abaf9eba..eb1c10120f9f58e8699944be35eece9bb384d02c 100644 (file)
@@ -752,16 +752,30 @@ static struct pkvm_hyp_vcpu selftest_vcpu = {
 struct pkvm_hyp_vcpu *init_selftest_vm(void *virt)
 {
        struct hyp_page *p = hyp_virt_to_page(virt);
+       unsigned long min_pages, seeded = 0;
        int i;
 
        selftest_vm.kvm.arch.mmu.vtcr = host_mmu.arch.mmu.vtcr;
        WARN_ON(kvm_guest_prepare_stage2(&selftest_vm, virt));
 
+       /*
+        * Mirror pkvm_refill_memcache() for the share/donate pre-checks;
+        * the selftest invokes those functions directly and would
+        * otherwise see an empty memcache.
+        */
+       min_pages = kvm_mmu_cache_min_pages(&selftest_vm.kvm.arch.mmu);
+
        for (i = 0; i < pkvm_selftest_pages(); i++) {
                if (p[i].refcount)
                        continue;
                p[i].refcount = 1;
-               hyp_put_page(&selftest_vm.pool, hyp_page_to_virt(&p[i]));
+               if (seeded < min_pages) {
+                       push_hyp_memcache(&selftest_vcpu.vcpu.arch.pkvm_memcache,
+                                         hyp_page_to_virt(&p[i]), hyp_virt_to_phys);
+                       seeded++;
+               } else {
+                       hyp_put_page(&selftest_vm.pool, hyp_page_to_virt(&p[i]));
+               }
        }
 
        selftest_vm.kvm.arch.pkvm.handle = __pkvm_reserve_vm();