Re: [PATCH 1/3] KVM: arm64: Clear the whole hugetlb folio when sanitising MTE tags
From: Lorenzo Stoakes (ARM)
Date: Tue Oct 20 2026 - 07:53:11 EST
hugetlb strikes again... :) the mm part of me apologises ;)
On Mon, Oct 19, 2026 at 02:21:01PM +0100, Fuad Tabba wrote:
> 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.
I'm guessing the folio size is always >= size here?
>
> Clear the whole folio, as mte_sync_tags() does.
>
> Fixes: 25c17c4b55def ("hugetlb: arm64: add mte support")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
Some nits below but generally looks sensible to me so:
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
> ---
> arch/arm64/kvm/mmu.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 9ba86450fe4af..48a08b608ea72 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -1514,7 +1514,8 @@ 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 */
Is this comment redundant now?
> if (folio_try_hugetlb_mte_tagging(folio)) {
> - for (i = 0; i < nr_pages; i++, page++)
> + page = folio_page(folio, 0);
> + for (i = 0; i < folio_nr_pages(folio); i++, page++)
I know it's a stable fix, but the fact that this pattern exists in multiple
places really argues for a mte_clear_folio_tags(), which would make this
trivially:
mte_clear_folio_tags(folio);
And avoid the re-use of page etc.
It's not a huge change and makes the next patch in the series simpler too so
arguably could be part of the series?
> mte_clear_page_tags(page_address(page));
> folio_set_hugetlb_mte_tagged(folio);
> }
> --
> 2.47.3
>
>
--
Cheers, Lorenzo