Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Dan Carpenter <dan@pereq.eu>
Cc: "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>,
	"Karthik Bhargavan" <karthik@pereq.eu>,
	"Clément Blaudeau" <clement@cryspen.com>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	stable@vger.kernel.org
Subject: Re: [PATCH] KVM: arm64: nv: Never invalidate less than a page for a TTL hint
Date: Mon, 23 Nov 2026 13:35:13 +0000	[thread overview]
Message-ID: <86h5h7zn5a.wl-maz@kernel.org> (raw)
In-Reply-To: <20261123-inval_range-v1-1-815e15797089@pereq.eu>

On Mon, 23 Nov 2026 10:30:16 +0000,
Dan Carpenter <dan@pereq.eu> wrote:
> 
> The compute_tlb_inval_range() function takes the size of a nested TLB
> invalidation from the TTL hint in the TLBI operand.  A guest hypervisor
> can give a 4K level-3 hint, which asks for a 4K invalidation.  On a host
> with 16K or 64K pages that is less than one page.  s2_mmu_unmap_ipa()
> passes the 4K size to kvm_stage2_unmap_range(), which hits
> WARN_ON(size & ~PAGE_MASK).
> 
> WARNING: arch/arm64/kvm/mmu.c:407 at kvm_stage2_unmap_range+0x38/0x60, CPU#1: ipas2e1_ttl_tes/568
> Call trace:
>  kvm_stage2_unmap_range (arch/arm64/kvm/mmu.c:410) (P)
>  s2_mmu_unmap_ipa (arch/arm64/kvm/sys_regs.c:4246)
>  kvm_s2_mmu_iterate_by_vmid (arch/arm64/kvm/nested.c:770)
>  handle_ipas2e1is (arch/arm64/kvm/sys_regs.c:4258)
>  perform_access (arch/arm64/kvm/sys_regs.c:4917)
>  kvm_handle_sys_reg (arch/arm64/kvm/sys_regs.c:5455)
>  handle_exit (arch/arm64/kvm/handle_exit.c:466)
>  kvm_arch_vcpu_ioctl_run (arch/arm64/kvm/arm.c:1583)
>  kvm_vcpu_ioctl (virt/kvm/kvm_main.c:4595)
> 
> The shadow stage-2 is built from host pages, so invalidating less than
> a page makes no sense.  Return at least PAGE_SIZE.
> 
> Fixes: d1de1576dc21 ("KVM: arm64: nv: Handle FEAT_TTL hinted TLB operations")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan@pereq.eu>
> ---
>  arch/arm64/kvm/nested.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
> index 78d5b18dbd2d..e964b122e9d0 100644
> --- a/arch/arm64/kvm/nested.c
> +++ b/arch/arm64/kvm/nested.c
> @@ -735,7 +735,7 @@ unsigned long compute_tlb_inval_range(struct kvm_s2_mmu *mmu, u64 val)
>  	}
>  
>  	WARN_ON(!max_size);
> -	return max_size;
> +	return max(max_size, PAGE_SIZE);
>  }
>  
>  /*
> 

I'm a bit on the fence about this one.

On the surface, this seems the logical thing to do. However, KVM
imposes strong limitations on the granule sizes that a guest can
use. Specifically, we don't allow guest S2 page sizes smaller than
what the host can do, and advertise so in the ID regs.

This means that a guest issued 4kB TLBI IPAS2E1 on a 16kB host is not
required to take effect at all, since the page size is not advertised
as supported at S2, as captured by the architecture:

<quote>
If an incorrect value of the TTL field is specified for the entry
being invalidated by the instruction, then no entries are required by
the architecture to be invalidated from the TLB.
</quote>

The trouble is that by the time we realise that the TTL is stupid,
we're way too deep in the bowels of the invalidation code, and we're
committed to giving a reasonable answer to this.

So given that the guest is totally buggy, I'd rather treat the TLBI as
if it didn't have a TTL field at all, as over-invalidation is always
safe.

This has the advantage of using a size that is correct for the guest:
a 64kB guest on a 16kB host using a 4kB TTL TLBI would otherwise
result in a 16kB invalidation, which doesn't make much sense either...

Untested hack follows.

Thanks,

	M.

diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
index 78d5b18dbd2d6..36e4e83badf0a 100644
--- a/arch/arm64/kvm/nested.c
+++ b/arch/arm64/kvm/nested.c
@@ -714,6 +714,13 @@ unsigned long compute_tlb_inval_range(struct kvm_s2_mmu *mmu, u64 val)
 	 */
 	max_size = __ttl_to_size(ttl);
 
+	/*
+	 * IMPDEF behaviour: treat subpage TTL-annotated TLBI as the largest
+	 * possible invalidation. Don't try this at home, kids!
+	 */
+	if (max_size < PAGE_SIZE)
+		max_size = 0;
+
 	if (!max_size) {
 		/* Compute the maximum extent of the invalidation */
 		switch (vtcr_to_tg0_pgsize(kvm, mmu->tlb_vtcr)) {

-- 
Without deviation from the norm, progress is not possible.

      reply	other threads:[~2026-11-23 13:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 10:30 [PATCH] KVM: arm64: nv: Never invalidate less than a page for a TTL hint Dan Carpenter
2026-11-23 13:35 ` Marc Zyngier [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=86h5h7zn5a.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=clement@cryspen.com \
    --cc=dan@pereq.eu \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=karthik@pereq.eu \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=oupton@kernel.org \
    --cc=seiden@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=suzuki.poulose@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