From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795549532; b=qSC+4zomEBZ5q4upnFbrVghiE5A6Ai3HNcIBrWBFjAROsa8gJtsoy0K5KNMESiQRqgoU waBRm7xd9iNkBEI1Eu9p6+i80dwWCtn4+mxFZ4uTguCANYEKlI/IfxKNPFpJ9K99lnQtK f5L+Z9auwHwnIxVytrIdzpKlY/bju9xxleOvOUuMAtFw3sWL6809MC6RyKNPCm48TX02S dZ1WLOq39vE6gwc3JYHimwwrjlvRgDMk88rdHbnPP4nFsRgxTLEYKQmRAiF2UnIQksax7 ErT4rbUFWTTHHu7Wa9RiEOETipulcrTmq9KdZ+9DoTmENs6TR4t8zDWU4zaxep1iCqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795549532; h=Received:DKIM-Signature:Received:Date:Message-ID:From:To:Cc:Subject: In-Reply-To:References:User-Agent:MIME-Version:Content-Type: X-SA-Exim-Connect-IP:X-SA-Exim-Rcpt-To:X-SA-Exim-Mail-From: X-SA-Exim-Scanned; bh=YxnkC+H0WyqL4UcCcv5HjKqJ5O4y9emPPKJptv760hc=; b=Kgf4zl7G/ZoVtEdgFiqf40gf8YMp5ZuqWxYqCFFg8x30GC1jiwCIv1GUPULJld0qwNSm IdVrg0QoEEABUe7+de+wMkD6DWsS1OOd97ZE/RkmNpjAeda6QSPaeex41HpDq8FIueTrx wQo8GnLm/McWn6fnwvNGOrP/34GWyqNYftIR6VqVFAQ/UPmnM/LnygeBE7jU0NRpVOAcs Wf8AppL8k82dhvP2s16D27nEHszJMlz0UuRaRXH3NOH5ncbyykxiy+7NgcecJTzHZan+U LFKLwGmEeAuOouKtfB6P1qc4/eE64oItP7qCmtJi9nqZSsApn+3DLA11vQCJKmYIwyw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Yn/l+G+X"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2C77606A31E; Tue, 24 Nov 2026 19:45:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Yn/l+G+X Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D9C81F000C0; Tue, 24 Nov 2026 19:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795549532; bh=YxnkC+H0WyqL4UcCcv5HjKqJ5O4y9emPPKJptv760hc=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=Yn/l+G+XwG6rnIr7gMg63Q/wt9fpkcsxai1AKo/AIZ6U5qrXSvVBszTWQi/D1nkr6 mKmw+HUszIT+CHB/DuzwKgYNByZNvK+BMQzUgDz+0/dyvYt/aaP7yJD45tZLR5xdZz 2MKVFBKpf1EteIKmBf7wAI36O98sFgf3Oj/SyXI0quMfea7ruoC51FEJZiA1mfooLo 9eTLMfj/d8XbP4dbRoyKVQXqAWCUp/QWpy6XqjpPTTI+ey1P37+bmYoZ1beZ8wTdpK dOComrq2+g9ZhWhVmHaWbVjLrmbXkUtdJefn/0kogerOoJk2we8cmm2+w3+q9V608q RGxmHDzjeexRQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xVwSI-00000002l5B-0U4K; Tue, 24 Nov 2026 19:45:30 +0000 Date: Tue, 24 Nov 2026 19:45:29 +0000 Message-ID: <861p8aypwm.wl-maz@kernel.org> From: Marc Zyngier To: Leonardo Bras Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Steffen Eiden , Joey Gouly , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Fuad Tabba , Dan Carpenter , stable@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size In-Reply-To: References: <20261123182312.4842-1-maz@kernel.org> <864id6yyjy.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: leo.bras@arm.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, seiden@linux.ibm.com, joey.gouly@arm.com, suzuki.poulose@arm.com, oupton@kernel.org, yuzenghui@huawei.com, fuad.tabba@linux.dev, dan@pereq.eu, stable@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Tue, 24 Nov 2026 18:06:02 +0000, Leonardo Bras wrote: > > On Tue, Nov 24, 2026 at 04:38:41PM +0000, Marc Zyngier wrote: > > On Tue, 24 Nov 2026 16:20:16 +0000, > > Leonardo Bras wrote: > > > > > > On Mon, Nov 23, 2026 at 06:23:12PM +0000, Marc Zyngier wrote: > > > > Should a guest be slightly foolish and submit a S2 TLBI with a TTL hint > > > > that describe a base granule size smaller than the host's page size, > > > > we take the resulting size at face value and feed it to the S2 unmapping > > > > code. Which legitimately screams about something not being page-aligned. > > > > > > > > The architecture allows us to drop the TLBI on the floor, as we don't > > > > support a S2 granule size smaller than the host's page size. But it turns > > > > out that doing so is proving pretty hard (we call compute_tlb_inval_range > > > > from a number of places, none of which is amenable to an early out). > > > > > > > > Instead, detect the annoying case, and pretend that we don't have a TTL > > > > hint at all, leaving the size upgrade mechanism to take place and use > > > > the largest possible size for the guest's S2 granule size. > > > > > > > > This will still allow nonsensical stuff to get through, such as a 4kB > > > > level 2 (aka 2MB) from a guest with a 64kB S2 base granule size running > > > > on a 16kB page size host, but that's not worse than doing nothing, and > > > > the host code won't get shouty. > > > > > > > > Reported-by: Dan Carpenter > > > > Link: https://lore.kernel.org/r/20261123-inval_range-v1-1-815e15797089@pereq.eu > > > > Fixes: d1de1576dc21 ("KVM: arm64: nv: Handle FEAT_TTL hinted TLB operations") > > > > Signed-off-by: Marc Zyngier > > > > Cc: stable@vger.kernel.org > > > > --- > > > > > > > > Notes: > > > > Reposting this as a first class patch, as I'd like to plug that one > > > > as early as possible (and Dan has plenty of other patches in flight...) > > > > > > > > arch/arm64/kvm/nested.c | 7 +++++++ > > > > 1 file changed, 7 insertions(+) > > > > > > > > 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)) { > > > > -- > > > > 2.47.3 > > > > > > > > > > Hey Marc, > > > > > > I think the changes make sense, although rounding up to PAGE_SIZE also > > > looks a valid solution in my unexperienced viewpoint. > > > > No, it isn't the same thing. Taker the example I have given, where the > > host is 16k, the guest 64k, and the invalidation 4k. If you round > > things up to 16k, you're still not invalidating anything that is > > consistent with the *minimum page size* for the guest. Anything larger > > is a multiple of both the host and guest page sizes, and therefore > > always correct. > > Ah, right! > In this case, could we not invalidate the largest page size supported > (64k)? Because that's not what the absence of TTL means. > > IIUC: > - To have max_size between 0 and PAGE_SIZE means it's either 4k or 16k, > so invalidating the 64k should be enough? No. > > - max_size=0 from __ttl_to_size() means largest blocksize supported by > stage2 in current TG. Yes. > > The two above are opposite ends, no? Like, the first is "this is too small > for us to invalidate, let's pick something bigger", and the other one is > "we want to invalidate the largest supported block". > > Is it really ok to put them in the same bucket? That's the *only* thing you can do, short of not invalidating anything at all. The commit message alreayd explains the IMPDEF choice that is made, and why it is made. Let me explain it again: - An invalid TTL allows us to ignore the TLBI altogether. No ifs, no buts. This is definitely an invalid TTL. - However, by the time we reach this code, we are committed to perform an invalidation, and we can't backtrack (doing so would be really ugly). - Our next port of call is to still perform an invalidation with something reasonable. Since the TTL is invalid, only the IPA tells us anything. And for any IPA without any range information, the only sane thing to do is to invalidate the largest possible size. You could refine this a bit more, but frankly this is not worth it. We are already allowing a broken guest to do some invalidations, but there is no need to go out of our way to do anything more. The end. M. -- Without deviation from the norm, progress is not possible.