[PATCH 1/2] KVM: arm64: Fix THP block mapping when the PMD level is folded
From: Fuad Tabba
Date: Mon Nov 23 2026 - 05:35:21 EST
When a THP backs guest memory, transparent_hugepage_adjust() rounds the
faulting gfn and pfn down to the THP's first page, and KVM maps the
whole THP with a PMD_SIZE block. However, the rounding uses a mask of
PTRS_PER_PMD - 1, and PTRS_PER_PMD is 1 when the PMD level is folded
(64K pages with a 42-bit VA, or 16K pages with a 36-bit VA). KVM then
maps PMD_SIZE worth of pages starting at the faulting page, and the
guest gets the host memory that follows the THP. With pKVM, the
hypervisor rejects the unaligned block, so the guest doesn't get that
memory.
Before the conversion to the generic page-table API, the unrounded pfn
went into a block descriptor, where the address bits below the block
size aren't part of the output address, so only the THP was mapped.
Round to PMD_SIZE >> PAGE_SHIFT pages instead.
Fixes: 6f745f1bb5bf2 ("KVM: arm64: Convert user_mem_abort() to generic page-table API")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
---
arch/arm64/kvm/mmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 1db10d8d6db73..bab44021654a0 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1573,9 +1573,9 @@ transparent_hugepage_adjust(const struct kvm_s2_fault_desc *s2fd, kvm_pfn_t *pfn
if (sz < PMD_SIZE)
return PAGE_SIZE;
- gfn &= ~(PTRS_PER_PMD - 1);
+ gfn = ALIGN_DOWN(gfn, PMD_SIZE >> PAGE_SHIFT);
*gfnp = gfn;
- pfn &= ~(PTRS_PER_PMD - 1);
+ pfn = ALIGN_DOWN(pfn, PMD_SIZE >> PAGE_SHIFT);
*pfnp = pfn;
return PMD_SIZE;
--
2.47.3