From: Marc Zyngier <maz@kernel.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Steffen Eiden <seiden@linux.ibm.com>,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oupton@kernel.org>,
Zenghui Yu <yuzenghui@huawei.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
Hyunwoo Kim <imv4bel@gmail.com>,
Yao Yuan <yaoyuan@linux.alibaba.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v2 2/8] KVM: arm64: Handle negative S1 walk levels in VNCR TLB size evaluation
Date: Sat, 08 Aug 2026 10:06:31 +0100 [thread overview]
Message-ID: <87bjbdouaw.wl-maz@kernel.org> (raw)
In-Reply-To: <anYL8J1ejjujgp-A@lucifer>
On Fri, 07 Aug 2026 18:12:18 +0100,
"Lorenzo Stoakes (ARM)" <ljs@kernel.org> wrote:
[...]
> So actually if granularity is TLBI_TTL_TG_4K this will return SZ_1G and 0 in the
> other cases unless I'm getting something wrong here?
>
> This is really more a 'maybe worth mentioning in the commit log to be pedantic'
> kind of thing :)
>
> IOW you could luck out before with SZ_1G for TLBI_TTL_TG_4K.
Yes, and that's what happens in most cases. But as Huynwoo Kim's
reports, 16k and 64k lead to something really bad. And even 4k works
by pure luck, so this is all fsck'd in my book.
>
> >
> > Tidy-up pgshift_level_to_ttl() to handle these negative levels, and
> > ttl_to_size() to always return SZ_1G when no valid TTL is present.
> > This allows the removal of open-coded checks for similar situations.
>
> I guess SZ_1G is a reasonable default here?
It is more than a reasonable default. It is the maximum block size
that can architecturally be mapped in the absence of FEAT_LPA*. In
this situation, 16k pages imply a 32M max block mapping, and 64k
implies 512M. 4K pages, by virtue of allowing a level-1 block mapping
result in a 1G size.
>
> >
> > Note that the check for a negative value not explicitely checking for
>
> NIT: explicitely -> explicitly
>
> > S1_MMU_DISABLED is deliberate, so that actual negative levels introduced
> > with LVA2 and D128 can take the same path if we ever support them.
> >
> > Fixes: 7270cc9157f47 ("KVM: arm64: nv: Handle VNCR_EL2 invalidation from MMU notifiers")
> > Reported-by: Hyunwoo Kim <imv4bel@gmail.com>
> > Link: https://lore.kernel.org/r/ameGoxbn2wzBq2kL@v4bel
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > Cc: stable@vger.kernel.org
> > ---
> > arch/arm64/kvm/nested.c | 26 +++++++++++++++++++-------
> > 1 file changed, 19 insertions(+), 7 deletions(-)
> >
> > diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
> > index f3c75954cf36c..035cda256e2a5 100644
> > --- a/arch/arm64/kvm/nested.c
> > +++ b/arch/arm64/kvm/nested.c
> > @@ -505,7 +505,7 @@ int kvm_walk_nested_s2(struct kvm_vcpu *vcpu, phys_addr_t gipa,
> > return ret;
> > }
> >
> > -static unsigned int ttl_to_size(u8 ttl)
> > +static unsigned int __ttl_to_size(u8 ttl)
> > {
> > int level = ttl & 3;
> > int gran = (ttl >> 2) & 3;
> > @@ -561,10 +561,22 @@ static unsigned int ttl_to_size(u8 ttl)
> > return max_size;
> > }
> >
> > -static u8 pgshift_level_to_ttl(u16 shift, u8 level)
> > +static unsigned int ttl_to_size(u8 ttl)
> > +{
> > + return __ttl_to_size(ttl) ?: SZ_1G;
> > +}
>
> Might be worth a comment about the default?
It's the architecture. I'm trying hard not to make KVM a running
commentary of the ARM ARM ;-).
>
> > +
> > +static u8 pgshift_level_to_ttl(u16 shift, s8 level)
> > {
> > u8 ttl;
> >
> > + /*
> > + * If we don't have a proper level, fallback to the maximum
> > + * size.
> > + */
> > + if (level < 0)
> > + return 0;
> > +
> > switch(shift) {
> > case 12:
> > ttl = TLBI_TTL_TG_4K;
> > @@ -675,7 +687,11 @@ unsigned long compute_tlb_inval_range(struct kvm_s2_mmu *mmu, u64 val)
> > ttl = get_guest_mapping_ttl(mmu, addr);
> > }
> >
> > - max_size = ttl_to_size(ttl);
> > + /*
> > + * Don't use the default 1GB fallback, as we can adapt to the
> > + * max mapping size we allow at S2.
> > + */
>
> Being a bit pedantic here but I wonder if simply just to say 'Adapt to the max
> mapping size allowed at S2' as the fallback is inferred?
Sure.
Thanks,
M.
--
Jazz isn't dead. It just smells funny.
next prev parent reply other threads:[~2026-08-08 9:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 9:10 [PATCH v2 0/8] KVM: arm64: VNCR TLB invalidation fixes Marc Zyngier
2026-08-06 9:10 ` [PATCH v2 1/8] KVM: arm64: Remove VM-wide VNCR mapping counter Marc Zyngier
2026-08-07 16:45 ` Lorenzo Stoakes (ARM)
2026-08-08 8:43 ` Marc Zyngier
2026-08-06 9:10 ` [PATCH v2 2/8] KVM: arm64: Handle negative S1 walk levels in VNCR TLB size evaluation Marc Zyngier
2026-08-07 17:12 ` Lorenzo Stoakes (ARM)
2026-08-08 9:06 ` Marc Zyngier [this message]
2026-08-06 9:10 ` [PATCH v2 3/8] KVM: arm64: Consider SCTLR_EL2.M when mapping the L1 VNCR page Marc Zyngier
2026-08-06 9:10 ` [PATCH v2 4/8] KVM: arm64: Correctly handle end of VA space TLBI invalidation Marc Zyngier
2026-08-08 21:41 ` Wei-Lin Chang
2026-08-09 18:13 ` Marc Zyngier
2026-08-09 21:10 ` Wei-Lin Chang
2026-08-06 9:10 ` [PATCH v2 5/8] KVM: arm64: Handle VNCR TLB invalidation race with vcpu_put() VNCR unmapping Marc Zyngier
2026-08-07 6:03 ` Yao Yuan
2026-08-06 9:10 ` [PATCH v2 6/8] KVM: arm64: Sign-extend VA for range-based TLBI invalidation Marc Zyngier
2026-08-06 9:10 ` [PATCH v2 7/8] KVM: arm64: Make VNCR invalidation participate in MMU invalidation retry Marc Zyngier
2026-08-06 9:10 ` [PATCH v2 8/8] KVM: arm64: Add VNCR TLB tracking again Marc Zyngier
2026-08-08 18:35 ` [PATCH v2 0/8] KVM: arm64: VNCR TLB invalidation fixes Oliver Upton
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=87bjbdouaw.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=fuad.tabba@linux.dev \
--cc=imv4bel@gmail.com \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=ljs@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=yaoyuan@linux.alibaba.com \
--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;
as well as URLs for NNTP newsgroup(s).