[PATCH v2 1/4] KVM: arm64: Clear the whole hugetlb folio when sanitising MTE tags
From: Fuad Tabba
Date: Wed Oct 21 2026 - 07:09:53 EST
sanitise_mte_tags() clears the tags of the pages about to be mapped at
stage-2 before marking them tagged. For a hugetlb folio the flag covers
every page in the folio, but the loop only covers the mapping being
installed. Stage-2 maps a folio in pieces for the contiguous hugetlb
sizes, and for any size under dirty logging. The first fault then marks
the whole folio after clearing only its own piece, and the rest keeps
its previous owner's tags for the guest to read.
Clear the whole folio, as mte_sync_tags() does.
Fixes: 25c17c4b55def ("hugetlb: arm64: add mte support")
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
---
arch/arm64/kvm/mmu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 9ba86450fe4af..a551b6bb13c21 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1512,10 +1512,10 @@ static void sanitise_mte_tags(struct kvm *kvm, kvm_pfn_t pfn,
}
if (folio_test_hugetlb(folio)) {
- /* Hugetlb has MTE flags set on head page only */
+ /* A hugetlb folio is marked tagged as a whole, so clear every page */
if (folio_try_hugetlb_mte_tagging(folio)) {
- for (i = 0; i < nr_pages; i++, page++)
- mte_clear_page_tags(page_address(page));
+ for (i = 0; i < folio_nr_pages(folio); i++)
+ mte_clear_page_tags(page_address(folio_page(folio, i)));
folio_set_hugetlb_mte_tagged(folio);
}
return;
--
2.47.3