Re: [PATCH] KVM: arm64: nv: Fix guest stage-2 mapping leak on sub-block unmap
From: Colton Lewis
Date: Fri Nov 20 2026 - 18:18:02 EST
On Fri, 20 Nov 2026 06:35:12 +0000, Wei-Lin Chang <weilin.chang@xxxxxxx> wrote:
> > result, every sub-block invalidation followed by a re-fault leaks a
>
> Doesn't the block tracking node get leaked regardless of whether a
> re-fault happens?
Yes, the stale entry is left behind on the first TLBI. Re-faulting is
just what lets L1 accumulate additional entries.
> For this third paragraph can you improve it by stating how the problem
> is fixed upfront? The first two paragraphs describe the problem, then
> you started to talk about stage2_unmap_walker all of a sudden (which I'm
> not sure how much it helps), and the fix itself is not emphasised. The
> combination makes it pretty difficult to get what the patch is doing.
Agreed, the commit message was unclear. In v2 I will drop the
kvm_remove_guest_s2_mappings() approach in favor of ignoring TLBI
IPAS2E1 when the guest-supplied TTL is smaller than the mapped granule
(as Marc suggested), and rewrite the commit messages to be shorter and
clearer.
> > In addition, suppress exact-match duplicate insertions in
> > kvm_record_guest_s2_mapping() when concurrent faults or -EAGAIN retries
> > record an identical (nested, canonical) range on the same shadow MMU.
>
> I believe this is better split into its own patch, it's doing another
> thing.
Makes sense. I will split it into a separate patch in v2.
> > Fixes: 5491980c1a41 ("KVM: arm64: nv: Track guest stage-2 mapping removal")
> > Fixes: c2778d14cd2f ("KVM: arm64: nv: Track guest stage-2 mapping creation")
>
> Since there isn't a real bug in the original implementation do we need
> these tags?
Good point. I will drop the Fixes tag on the duplicate-avoidance patch
and point the TTL patch at the commit that added FEAT_TTL handling
instead.
> > + scoped_guard(spinlock, &kvm->arch.guest_s2_tracking_lock) {
> > + if (!guest_s2_mapping_exists(mmu, mapping)) {
> > + interval_tree_insert(&mapping->nested,
> > + &mmu->guest_s2_mappings);
> > + interval_tree_insert(&mapping->canonical,
> > + &kvm->arch.mmu.guest_s2_mappings);
> > + mapping = NULL;
> > + }
> > + }
> > +
> > + kfree(mapping);
>
> In my understanding kfree() can be called while holding locks, so we
> don't need the extra level of indentation.
Yes, kfree() is safe under the spinlock. I will keep guard(spinlock)
and call kfree() directly there.