Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Colton Lewis <coltonlewis@google.com>
To: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oupton@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
	 Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	 Fuad Tabba <fuad.tabba@linux.dev>,
	Steffen Eiden <seiden@linux.ibm.com>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	 Mark Rutland <mark.rutland@arm.com>,
	Wei-Lin Chang <weilin.chang@arm.com>,
	 Dan Carpenter <dan@pereq.eu>,
	kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	 kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] KVM: arm64: nv: Discard undersized TTL hints in compute_tlb_inval_range()
Date: Tue, 24 Nov 2026 22:16:16 +0000	[thread overview]
Message-ID: <20261124221616.4155034-1-coltonlewis@google.com> (raw)
In-Reply-To: <87a4my7yhg.wl-maz@kernel.org>

On Tue, 24 Nov 2026 20:42:19 +0000, Marc Zyngier <maz@kernel.org> wrote:
> On Tue, 24 Nov 2026 20:22:15 +0000,
> Colton Lewis <coltonlewis@google.com> wrote:
> > [1] only catches TTL hints smaller than host PAGE_SIZE. It does not
> > catch a hint that is >= PAGE_SIZE but smaller than the mapped block,
> > such as a 4kB L3 hint on a 2MB block on a 4kB host.
>
> Why do you think this makes *any* difference? The hint passed by the
> guest is utter bollocks, and the best thing would be to not invalidate
> anything. It's just too invasive to do elegantly.

Architecturally [1] is fine for the TLB, and before guest_s2_mappings
landed in v7.4-rc1 clearing the block was harmless. The problem with [1]
is a host memory leak in kvm_pgtable_stage2_unmap_tracked():

1. L2 faults in a 2MB block. kvm_s2_fault_map() installs a 2MB block PTE
   and kvm_record_guest_s2_mapping() inserts a 2MB
   struct kvm_guest_s2_mapping into both interval trees.
2. L1 runs TLBI IPAS2E1IS with a 4kB L3 TTL hint (4kB == PAGE_SIZE, so
   [1] returns 4kB).
3. kvm_pgtable_stage2_unmap(..., SZ_4K) clears the entire 2MB block PTE.
4. kvm_remove_guest_s2_mappings(..., SZ_4K) skips removing the 2MB entry
   because a 4kB range does not enclose it.
5. L2 touches the address again, faults because the PTE was cleared, and
   allocates another 2MB tracking entry.

Looping steps 2-5 lets an L1 guest leak one struct kvm_guest_s2_mapping
per iteration until a larger unmap or VM teardown (I measured 832kB of
slab_unreclaimable growth over 8192 iterations) and turns later TLBIs on
that range into linear walks under write_lock(&kvm->mmu_lock). Patch 2
avoids exact duplicates for the same (nested, canonical) pair, but
remapping the nested IPA to different canonical IPAs still leaves each
stale entry behind.

If you prefer not to touch compute_tlb_inval_range() beyond [1], another
option is keeping [1] as-is and dropping the cleared tracking entry in
kvm_remove_guest_s2_mappings() when a partial overlap leaves no valid
mapping beneath it (zero cost on valid hints).


  reply	other threads:[~2026-11-24 22:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 23:26 [PATCH v2 0/2] KVM: arm64: nv: Fix stale and duplicate guest S2 tracking entries Colton Lewis
2026-11-23 23:26 ` [PATCH v2 1/2] KVM: arm64: nv: Discard undersized TTL hints in compute_tlb_inval_range() Colton Lewis
2026-11-24 13:10   ` Marc Zyngier
2026-11-24 20:22     ` Colton Lewis
2026-11-24 20:42       ` Marc Zyngier
2026-11-24 22:16         ` Colton Lewis [this message]
2026-11-23 23:26 ` [PATCH v2 2/2] KVM: arm64: nv: Avoid duplicate guest stage-2 mapping entries Colton Lewis

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=20261124221616.4155034-1-coltonlewis@google.com \
    --to=coltonlewis@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=dan@pereq.eu \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --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=seiden@linux.ibm.com \
    --cc=suzuki.poulose@arm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox