Skip to content

Commit 5130d45

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Seed pkvm_ownership_selftest vcpu memcache
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>
1 parent d4d215e commit 5130d45

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,16 +752,30 @@ static struct pkvm_hyp_vcpu selftest_vcpu = {
752752
struct pkvm_hyp_vcpu *init_selftest_vm(void *virt)
753753
{
754754
struct hyp_page *p = hyp_virt_to_page(virt);
755+
unsigned long min_pages, seeded = 0;
755756
int i;
756757

757758
selftest_vm.kvm.arch.mmu.vtcr = host_mmu.arch.mmu.vtcr;
758759
WARN_ON(kvm_guest_prepare_stage2(&selftest_vm, virt));
759760

761+
/*
762+
* Mirror pkvm_refill_memcache() for the share/donate pre-checks;
763+
* the selftest invokes those functions directly and would
764+
* otherwise see an empty memcache.
765+
*/
766+
min_pages = kvm_mmu_cache_min_pages(&selftest_vm.kvm.arch.mmu);
767+
760768
for (i = 0; i < pkvm_selftest_pages(); i++) {
761769
if (p[i].refcount)
762770
continue;
763771
p[i].refcount = 1;
764-
hyp_put_page(&selftest_vm.pool, hyp_page_to_virt(&p[i]));
772+
if (seeded < min_pages) {
773+
push_hyp_memcache(&selftest_vcpu.vcpu.arch.pkvm_memcache,
774+
hyp_page_to_virt(&p[i]), hyp_virt_to_phys);
775+
seeded++;
776+
} else {
777+
hyp_put_page(&selftest_vm.pool, hyp_page_to_virt(&p[i]));
778+
}
765779
}
766780

767781
selftest_vm.kvm.arch.pkvm.handle = __pkvm_reserve_vm();

0 commit comments

Comments
 (0)