Oliver Upton df6556adf2 KVM: arm64: Correctly handle page aging notifiers for unaligned memslot
Userspace is allowed to select any PAGE_SIZE aligned hva to back guest
memory. This is even the case with hugepages, although it is a rather
suboptimal configuration as PTE level mappings are used at stage-2.

The arm64 page aging handlers have an assumption that the specified
range is exactly one page/block of memory, which in the aforementioned
case is not necessarily true. All together this leads to the WARN() in
kvm_age_gfn() firing.

However, the WARN is only part of the issue as the table walkers visit
at most a single leaf PTE. For hugepage-backed memory in a memslot that
isn't hugepage-aligned, page aging entirely misses accesses to the
hugepage beyond the first page in the memslot.

Add a new walker dedicated to handling page aging MMU notifiers capable
of walking a range of PTEs. Convert kvm(_test)_age_gfn() over to the new
walker and drop the WARN that caught the issue in the first place. The
implementation of this walker was inspired by the test_clear_young()
implementation by Yu Zhao [*], but repurposed to address a bug in the
existing aging implementation.

Cc: stable@vger.kernel.org # v5.15
Fixes: 056aad67f836 ("kvm: arm/arm64: Rework gpa callback handlers")
Link: https://lore.kernel.org/kvmarm/20230526234435.662652-6-yuzhao@google.com/
Co-developed-by: Yu Zhao <yuzhao@google.com>
Signed-off-by: Yu Zhao <yuzhao@google.com>
Reported-by: Reiji Watanabe <reijiw@google.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Link: https://lore.kernel.org/r/20230627235405.4069823-1-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
2023-07-12 20:10:40 +00:00
..
2023-06-28 20:35:21 -07:00
2023-07-06 10:06:04 -07:00
2023-07-06 10:06:04 -07:00
2023-07-01 21:12:32 -07:00
2023-06-28 20:35:21 -07:00
2023-07-01 09:24:31 -07:00
2023-07-06 10:06:04 -07:00
2023-07-06 10:06:04 -07:00
2023-06-29 16:34:12 -07:00
2023-07-09 10:02:49 -07:00
2023-06-29 16:34:12 -07:00
2023-06-28 20:35:21 -07:00
2023-07-07 10:00:30 -07:00
2023-07-05 21:45:32 -07:00
2023-07-06 22:42:54 -07:00
2023-07-01 09:24:31 -07:00
2023-06-30 09:20:08 -07:00