Skip to content

KVM: arm64: Handle unaligned memslots in kvm_(test_)_age_gfn()

Oliver Upton kvmarm linux-arm-kernel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5KVM: arm64: Hoist S2 PTE definitions into kvm_pgtable.harch/arm64/include/asm/kvm_pgtable.h arch/arm64/kvm/hyp/pgtable.c+34 -340 replies
2/5KVM: arm64: Add a mask for all leaf PTE attributesarch/arm64/include/asm/kvm_pgtable.h arch/arm64/kvm/hyp/pgtable.c+6 -40 replies
3/5KVM: arm64: Only return attributes from stage2_update_leaf_attrs()arch/arm64/kvm/hyp/pgtable.c arch/arm64/kvm/mmu.c+18 -164 replies
4/5KVM: arm64: Correctly handle page aging notifiers for unaligned memlsotarch/arm64/include/asm/kvm_pgtable.h arch/arm64/kvm/hyp/pgtable.c arch/arm64/kvm/mmu.c+24 -181 reply
5/5KVM: arm64: Consistently use KVM's types/helpers in kvm_age_gfn()arch/arm64/include/asm/kvm_pgtable.h arch/arm64/kvm/hyp/pgtable.c arch/arm64/kvm/mmu.c+11 -80 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] KVM: arm64: Handle unaligned memslots in kvm_(test_)_age_gfn()

There is no requirement for userspace to align KVM memslots to an appropriate boundary for the backing memory source. For example, userspace could choose to use 2M THP and place the memslot at a 4K offset within the hugepage.

Under these conditions, KVM can only map at the 4K level, effectively shattering the hugepage into a table of PTEs.

kvm_(test_)_age_gfn() operate on the assumption that the GFN range is of a single page or hugepage size. Furthermore, this assumption bleeds into the table walkers, which walk until reaching the first leaf PTE.

This completely falls apart in the aforementioned example where the memslot is unalgined, as there could be many leaf PTEs that need to be visited for a single hugepage. Furthermore, this configuration can lead to the WARN in kvm_age_gfn() firing as well.

This series addresses the issue by rejigging the related page table walkers to traverse a specified range of memory. I also roped in some cleanups that I did along the way (i.e. patches 1 and 5), but can easily respin w/o them if desired.

Tested on Ampere Altra w/ kvmtool and KVM selftests. I was going to implement a reproducer for the issue in KVM selftests, but there is a significant amount of idiot-proofing around the memslots helpers that prevent an unaligned memslot. Might get back to that when I have more patience for it.

Applies to 6.2-rc3.

Oliver Upton (5):
KVM: arm64: Hoist S2 PTE definitions into kvm_pgtable.h
KVM: arm64: Add a mask for all leaf PTE attributes
KVM: arm64: Only return attributes from stage2_update_leaf_attrs()
KVM: arm64: Correctly handle page aging notifiers for unaligned
memlsot
KVM: arm64: Consistently use KVM's types/helpers in kvm_age_gfn()

 arch/arm64/include/asm/kvm_pgtable.h | 66 +++++++++++++++++++----
 arch/arm64/kvm/hyp/pgtable.c         | 79 ++++++++--------------------
 arch/arm64/kvm/mmu.c                 | 18 +++----
 3 files changed, 88 insertions(+), 75 deletions(-)

base-commit: b7bfaa761d760e72a969d116517eaa12e404c262

Signature · 7 lines
2.39.0.314.g84b9a713c41-goog


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel