* [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size
@ 2026-11-23 18:23 Marc Zyngier
2026-11-23 19:25 ` Dan Carpenter
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Marc Zyngier @ 2026-11-23 18:23 UTC (permalink / raw)
To: kvmarm, kvm, linux-arm-kernel
Cc: Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton,
Zenghui Yu, Fuad Tabba, Dan Carpenter, stable
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 <dan@pereq.eu>
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 <maz@kernel.org>
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
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size 2026-11-23 18:23 [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size Marc Zyngier @ 2026-11-23 19:25 ` Dan Carpenter 2026-11-23 19:30 ` Marc Zyngier 2026-11-24 13:53 ` Wei-Lin Chang 2026-11-24 16:20 ` Leonardo Bras 2 siblings, 1 reply; 7+ messages in thread From: Dan Carpenter @ 2026-11-23 19:25 UTC (permalink / raw) To: Marc Zyngier Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu, Fuad Tabba, stable 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 <dan@pereq.eu> > 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 <maz@kernel.org> > 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...) Tested-by: Dan Carpenter <dan@pereq.eu> Although obviously zero is handled on the next line so there wasn't much call for testing, but I still did do the testing. regards, dan carpenter ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size 2026-11-23 19:25 ` Dan Carpenter @ 2026-11-23 19:30 ` Marc Zyngier 0 siblings, 0 replies; 7+ messages in thread From: Marc Zyngier @ 2026-11-23 19:30 UTC (permalink / raw) To: Dan Carpenter Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu, Fuad Tabba, stable On Mon, 23 Nov 2026 19:25:09 +0000, Dan Carpenter <dan@pereq.eu> 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 <dan@pereq.eu> > > 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 <maz@kernel.org> > > 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...) > > Tested-by: Dan Carpenter <dan@pereq.eu> > > Although obviously zero is handled on the next line so there wasn't > much call for testing, but I still did do the testing. And that's much appreciated. Thank you! M. -- Without deviation from the norm, progress is not possible. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size 2026-11-23 18:23 [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size Marc Zyngier 2026-11-23 19:25 ` Dan Carpenter @ 2026-11-24 13:53 ` Wei-Lin Chang 2026-11-24 16:20 ` Leonardo Bras 2 siblings, 0 replies; 7+ messages in thread From: Wei-Lin Chang @ 2026-11-24 13:53 UTC (permalink / raw) To: Marc Zyngier, kvmarm, kvm, linux-arm-kernel Cc: Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu, Fuad Tabba, Dan Carpenter, stable 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 <dan@pereq.eu> > 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 <maz@kernel.org> > Cc: stable@vger.kernel.org Reviewed-by: Wei-Lin Chang <weilin.chang@arm.com> > --- > > 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 > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size 2026-11-23 18:23 [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size Marc Zyngier 2026-11-23 19:25 ` Dan Carpenter 2026-11-24 13:53 ` Wei-Lin Chang @ 2026-11-24 16:20 ` Leonardo Bras 2026-11-24 16:38 ` Marc Zyngier 2 siblings, 1 reply; 7+ messages in thread From: Leonardo Bras @ 2026-11-24 16:20 UTC (permalink / raw) To: Marc Zyngier Cc: Leonardo Bras, kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu, Fuad Tabba, Dan Carpenter, stable 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 <dan@pereq.eu> > 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 <maz@kernel.org> > 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. I am curious if there is any particular reason not to merge that with the test below, such as: 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) { - if (!max_size) { /* Compute the maximum extent of the invalidation */ switch (vtcr_to_tg0_pgsize(kvm, mmu->tlb_vtcr)) { -- Given max_size is unsigned (>=0), and it will be changed again in the switch case below, I was not able to understand the need to make it zero first. Thanks! Leo ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size 2026-11-24 16:20 ` Leonardo Bras @ 2026-11-24 16:38 ` Marc Zyngier 2026-11-24 18:06 ` Leonardo Bras 0 siblings, 1 reply; 7+ messages in thread From: Marc Zyngier @ 2026-11-24 16:38 UTC (permalink / raw) To: Leonardo Bras Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu, Fuad Tabba, Dan Carpenter, stable On Tue, 24 Nov 2026 16:20:16 +0000, Leonardo Bras <leo.bras@arm.com> 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 <dan@pereq.eu> > > 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 <maz@kernel.org> > > 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. > > I am curious if there is any particular reason not to merge that with the > test below, such as: > > 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) { > - if (!max_size) { > /* Compute the maximum extent of the invalidation */ > switch (vtcr_to_tg0_pgsize(kvm, mmu->tlb_vtcr)) { > -- > > Given max_size is unsigned (>=0), and it will be changed again in the > switch case below, I was not able to understand the need to make it zero > first. There is more than one way to write similar things, and what I wrote made the most sense to me. I want to single out this particular corner case, which is not the much more general case if "max_size is 0 because there is no TTL information". Lumping these two things together makes it, IMO, pointlessly hard to reason about the various cases. Thanks, M. -- Without deviation from the norm, progress is not possible. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size 2026-11-24 16:38 ` Marc Zyngier @ 2026-11-24 18:06 ` Leonardo Bras 0 siblings, 0 replies; 7+ messages in thread From: Leonardo Bras @ 2026-11-24 18:06 UTC (permalink / raw) To: Marc Zyngier Cc: Leonardo Bras, kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu, Fuad Tabba, Dan Carpenter, stable On Tue, Nov 24, 2026 at 04:38:41PM +0000, Marc Zyngier wrote: > On Tue, 24 Nov 2026 16:20:16 +0000, > Leonardo Bras <leo.bras@arm.com> 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 <dan@pereq.eu> > > > 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 <maz@kernel.org> > > > 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)? IIUC: - To have max_size between 0 and PAGE_SIZE means it's either 4k or 16k, so invalidating the 64k should be enough? - max_size=0 from __ttl_to_size() means largest blocksize supported by stage2 in current TG. 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? > > > > > I am curious if there is any particular reason not to merge that with the > > test below, such as: > > > > 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) { > > - if (!max_size) { > > /* Compute the maximum extent of the invalidation */ > > switch (vtcr_to_tg0_pgsize(kvm, mmu->tlb_vtcr)) { > > -- > > > > Given max_size is unsigned (>=0), and it will be changed again in the > > switch case below, I was not able to understand the need to make it zero > > first. > > There is more than one way to write similar things, and what I wrote > made the most sense to me. > > I want to single out this particular corner case, which is not the > much more general case if "max_size is 0 because there is no TTL > information". Lumping these two things together makes it, IMO, > pointlessly hard to reason about the various cases. Ah, I see it now, makes much more sense to have it that way. Thanks! Leo ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-24 18:06 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-23 18:23 [PATCH] KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size Marc Zyngier 2026-11-23 19:25 ` Dan Carpenter 2026-11-23 19:30 ` Marc Zyngier 2026-11-24 13:53 ` Wei-Lin Chang 2026-11-24 16:20 ` Leonardo Bras 2026-11-24 16:38 ` Marc Zyngier 2026-11-24 18:06 ` Leonardo Bras
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox