Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Leonardo Bras <leo.bras@arm.com>
Cc: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
	 Fuad Tabba <fuad.tabba@linux.dev>,
	Joey Gouly <joey.gouly@arm.com>,
	 Steffen Eiden <seiden@linux.ibm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	 Zenghui Yu <yuzenghui@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	 Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Christoffer Dall <christoffer.dall@linaro.org>,
	Jintack Lim <jintack.lim@linaro.org>,
	 Wei-Lin Chang <weilin.chang@arm.com>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	 linux-kernel@vger.kernel.org, Usama Arif <usama.arif@linux.dev>,
	stable@vger.kernel.org
Subject: Re: [PATCH] KVM: arm64: Top up the mmu memcache on user fault for NV
Date: Fri, 27 Nov 2026 13:09:11 +0000	[thread overview]
Message-ID: <awl76RV-OOU7i0xm@gremlin> (raw)
In-Reply-To: <awlwTGHVjoO72YFw@LeoBrasDK>

On Fri, Nov 27, 2026 at 11:58:04AM +0000, Leonardo Bras wrote:
> On Thu, Nov 26, 2026 at 05:28:29PM +0000, Lorenzo Stoakes (ARM) wrote:
> > The S2 user fault path tops up the MMU memcache (used for page table
> > pre-allocation as the point at which page tables are installed may not
> > allocate) except when:
> >
> > * It's a permission fault AND
> > * dirty page logging is disabled AND
> > * pKVM is disabled
> >
> > At which point it is assumed no page table will be allocated.
> >
> > However nested virtualisation adds another edge case - the mapping size of
> > a shadow S2 is clamped to that of the guest's own S2. If the guest
> > hypervisor replaces a block mapping with a table, a permission fault on the
> > shadow block has to be mapped at PAGE_SIZE, which requires a page table to
> > collapse the block into.
>
> Can you please expand on how would that happen?
>
> IIUC when a guest hypervisor replaces a block mapping with a table, it
> calls a tlbi in the range, and L0 will trap and remove the Shadow S2 entry,
> then next access shouldn't be a permission but a translation fault.
>
> What am I missing?

That's a great point, actually :)

But nothing really enforces that L1 does that for sure, even a bug could produce
that, and you really want to avoid the host getting in bother in that case.

(The host kernel has to behave properly no matter what guests do).

I was able to (get claude to) repro this easily.

But actually I think there's another case too, even assuming everything's
well-behaved:

* vCPU B: Writes to a read-only shadow block -> permission fault, exits
  to the host.

* vCPU A: Concurrently does its break/TLBI/make on the L1 S2, replacing
  the block with writable pages. The TLBI clears the shadow block.

* vCPU B: Now handles the fault. It's still a permission fault as far as
  the ESR is concerned so we skip the top-up, but the L1 S2 now says
  page rather than block, so we go to map a page and have to allocate
  page table(s) for it.

This needs the mapping size to have changed (otherwise we just try to relax
permissions, which doesn't allocate) which can happen when splitting,
replacing pages with a THP page, etc.

In general I think just topping up regardless is the better route, but for
a backport this is the least big change to fix this.

>
> Thanks!
> Leo

--
Cheers, Lorenzo

      reply	other threads:[~2026-11-27 13:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 17:28 [PATCH] KVM: arm64: Top up the mmu memcache on user fault for NV Lorenzo Stoakes (ARM)
2026-11-27 11:58 ` Leonardo Bras
2026-11-27 13:09   ` Lorenzo Stoakes (ARM) [this message]

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=awl76RV-OOU7i0xm@gremlin \
    --to=ljs@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@linaro.org \
    --cc=fuad.tabba@linux.dev \
    --cc=jintack.lim@linaro.org \
    --cc=joey.gouly@arm.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=seiden@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox