From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Wei-Lin Chang <weilin.chang@arm.com>
Cc: Usama Arif <usama.arif@linux.dev>,
Leonardo Bras <leo.bras@arm.com>,
maz@kernel.org, oupton@kernel.org, fuad.tabba@linux.dev,
joey.gouly@arm.com, seiden@linux.ibm.com,
suzuki.poulose@arm.com, yuzenghui@huawei.com,
catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, riel@surriel.com,
shakeel.butt@linux.dev, kernel-team@meta.com, rkeilty@meta.com,
atish.patra@linux.dev, dgreid@meta.com
Subject: Re: [PATCH] KVM: arm64: Reduce the stage-2 page cache on 64 KiB hosts
Date: Thu, 26 Nov 2026 16:53:38 +0000 [thread overview]
Message-ID: <awhj98o6vqTqXX7D@gremlin> (raw)
In-Reply-To: <awhH1Dpu0uIwP6ea@gremlin>
On Thu, Nov 26, 2026 at 04:30:24PM +0000, Lorenzo Stoakes (ARM) wrote:
> I also think actually there's an existing problem with the top-up right now in
> user_mem_abort() that needs addressing too, actually, that this change exposes
> and will cause bugs if done as above.
>
> So right now top-up is conditional there:
>
> if (!perm_fault || memslot_is_logging(s2fd->memslot) ||
> is_protected_kvm_enabled()) {
> ret = topup_mmu_memcache(s2fd->mmu, memcache);
> if (ret)
> return ret;
> }
>
> Inverted is 'permission fault && !dirty-logging && !pKVM'. So the question is
> whether a permission fault not needing a new page table is correct.
>
> So working through, the actual decision about a page table allocation is done
> in:
>
> user_mem_abort()
> -> kvm_s2_fault_map()
> -> kvm_pgtable_stage2_map()
> -> ... -> stage2_map_walk_leaf()
> -> stage2_map_walker_try_leaf()
> -> stage2_leaf_mapping_allowed()
> -> kvm_block_mapping_supported() [ if false, allocate a page table ]
>
> static bool kvm_block_mapping_supported(const struct kvm_pgtable_visit_ctx *ctx, u64 phys)
> {
> u64 granule = kvm_granule_size(ctx->level);
>
> ...
>
> if (granule > (ctx->end - ctx->addr))
> return false;
>
> ...
> }
>
> But page table size can vary in NV between host and guest (guest must be >=
> host) and it gets clamped to the smaller of the two in kvm_s2_resolve_vma_size():
>
> static short kvm_s2_resolve_vma_size(const struct kvm_s2_fault_desc *s2fd,
> struct kvm_s2_fault_vma_info *s2vi,
> struct vm_area_struct *vma)
> {
> ...
> if (s2fd->nested) {
> ...
> /*
> * If we're about to create a shadow stage 2 entry, then we
> * can only create a block mapping if the guest stage 2 page
> * table uses at least as big a mapping.
> */
> max_map_size = min(kvm_s2_trans_size(s2fd->nested), max_map_size);
> ...
> }
> }
>
> This sets s2vi->vma_pagesize based on this value:
>
> static int kvm_s2_fault_get_vma_info(const struct kvm_s2_fault_desc *s2fd,
> struct kvm_s2_fault_vma_info *s2vi)
> {
> ...
> s2vi->vma_pagesize = BIT(kvm_s2_resolve_vma_size(s2fd, s2vi, vma));
> ...
> }
>
> And the fault map uses this in the mapping size, which defines ctx->addr, end
> above in kvm_block_mapping_supported():
>
> static int kvm_s2_fault_map(const struct kvm_s2_fault_desc *s2fd,
> const struct kvm_s2_fault_vma_info *s2vi,
> enum kvm_pgtable_prot prot,
> void *memcache,
> struct kvm_s2_fault_result *result)
> {
> ...
> mapping_size = s2vi->vma_pagesize;
> ...
> ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, gfn_to_gpa(gfn), mapping_size,
> __pfn_to_phys(pfn), prot,
> memcache, flags);
> ...
> }
>
> So basically, if the host has smaller page table size than the guest, you need
> an extra page table level.
>
> So simple solution is to add nested to the check:
>
> if (!perm_fault || memslot_is_logging(s2fd->memslot) ||
> is_protected_kvm_enabled() || s2fd->nested) {
> ret = topup_mmu_memcache(s2fd->mmu, memcache);
> if (ret)
> return ret;
> }
>
> But honestly I wonder at this point if it's truly worth doing all these checks?
> Maybe safer to just topup unconditionally.
>
> It'll only top up once before the cache is full anyway, so it's low cost. And
> would make more consistent with other fault paths too.
Given this is pre-existing, let me send a patch to fix this separately.
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-11-26 16:53 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 15:28 [PATCH] KVM: arm64: Reduce the stage-2 page cache on 64 KiB hosts Usama Arif
2026-11-25 17:14 ` Leonardo Bras
2026-11-25 17:55 ` Usama Arif
2026-11-25 18:25 ` Leonardo Bras
2026-11-25 21:42 ` Usama Arif
2026-11-25 21:53 ` sashiko-bot
2026-11-26 8:06 ` Wei-Lin Chang
2026-11-26 15:19 ` Leonardo Bras
2026-11-26 15:34 ` Wei-Lin Chang
2026-11-26 15:55 ` Leonardo Bras
2026-11-26 16:45 ` Lorenzo Stoakes (ARM)
2026-11-26 17:07 ` Leonardo Bras
2026-11-26 17:18 ` Lorenzo Stoakes (ARM)
2026-11-26 17:44 ` Leonardo Bras
2026-11-26 16:30 ` Lorenzo Stoakes (ARM)
2026-11-26 16:53 ` Lorenzo Stoakes (ARM) [this message]
2026-11-26 18:25 ` Leonardo Bras
2026-11-27 13:29 ` Lorenzo Stoakes (ARM)
2026-11-27 14:38 ` Usama Arif
2026-11-26 12:56 ` Marc Zyngier
2026-11-26 14:32 ` Usama Arif
2026-11-26 15:58 ` Marc Zyngier
2026-11-26 16:52 ` Lorenzo Stoakes (ARM)
2026-11-27 14:28 ` Usama Arif
2026-11-27 14:45 ` sashiko-bot
2026-11-30 14:21 ` Usama Arif
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awhj98o6vqTqXX7D@gremlin \
--to=ljs@kernel.org \
--cc=atish.patra@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=dgreid@meta.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kernel-team@meta.com \
--cc=kvmarm@lists.linux.dev \
--cc=leo.bras@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=riel@surriel.com \
--cc=rkeilty@meta.com \
--cc=seiden@linux.ibm.com \
--cc=shakeel.butt@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=usama.arif@linux.dev \
--cc=weilin.chang@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.