KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size
Subsystems (4)
Marc Zyngier
maintainerPATCH 1/1 KVM: arm64: nv: Upgrade sub-page TTL hint to maximum size
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.
---
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(+)
arch/arm64/kvm/nested.c +7 -0
@@ -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)) {
Signature · 1 line
2.47.3
Quoted 24 lines · Marc Zyngier
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_rangefrom 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 <[email protected]>Fixes d1de1576dc21 ("KVM: arm64: nv: Handle FEAT_TTL hinted TLB operations")Signed-off-by Marc Zyngier <[email protected]>
Quoted 5 lines
---
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...)
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
Marc Zyngier
maintainerQuoted 28 lines · Dan Carpenter
Quoted 26 lines · Marc Zyngier
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_rangefrom 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 <[email protected]>Fixes d1de1576dc21 ("KVM: arm64: nv: Handle FEAT_TTL hinted TLB operations")Signed-off-by Marc Zyngier <[email protected]>---
Quoted 8 lines
Quoted 3 lines
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 <[email protected]>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.
Signature · 1 line
Without deviation from the norm, progress is not possible.