linux/arch/arm64/mm
Ryan Roberts 49c87f7677 arm64: hugetlb: Fix huge_ptep_get_and_clear() for non-present ptes
arm64 supports multiple huge_pte sizes. Some of the sizes are covered by
a single pte entry at a particular level (PMD_SIZE, PUD_SIZE), and some
are covered by multiple ptes at a particular level (CONT_PTE_SIZE,
CONT_PMD_SIZE). So the function has to figure out the size from the
huge_pte pointer. This was previously done by walking the pgtable to
determine the level and by using the PTE_CONT bit to determine the
number of ptes at the level.

But the PTE_CONT bit is only valid when the pte is present. For
non-present pte values (e.g. markers, migration entries), the previous
implementation was therefore erroneously determining the size. There is
at least one known caller in core-mm, move_huge_pte(), which may call
huge_ptep_get_and_clear() for a non-present pte. So we must be robust to
this case. Additionally the "regular" ptep_get_and_clear() is robust to
being called for non-present ptes so it makes sense to follow the
behavior.

Fix this by using the new sz parameter which is now provided to the
function. Additionally when clearing each pte in a contig range, don't
gather the access and dirty bits if the pte is not present.

An alternative approach that would not require API changes would be to
store the PTE_CONT bit in a spare bit in the swap entry pte for the
non-present case. But it felt cleaner to follow other APIs' lead and
just pass in the size.

As an aside, PTE_CONT is bit 52, which corresponds to bit 40 in the swap
entry offset field (layout of non-present pte). Since hugetlb is never
swapped to disk, this field will only be populated for markers, which
always set this bit to 0 and hwpoison swap entries, which set the offset
field to a PFN; So it would only ever be 1 for a 52-bit PVA system where
memory in that high half was poisoned (I think!). So in practice, this
bit would almost always be zero for non-present ptes and we would only
clear the first entry if it was actually a contiguous block. That's
probably a less severe symptom than if it was always interpreted as 1
and cleared out potentially-present neighboring PTEs.

Cc: stable@vger.kernel.org
Fixes: 66b3923a1a ("arm64: hugetlb: add support for PTE contiguous bit")
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Link: https://lore.kernel.org/r/20250226120656.2400136-3-ryan.roberts@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2025-02-27 17:40:58 +00:00
..
Makefile arm64/gcs: Context switch GCS state for EL0 2024-10-04 12:04:38 +01:00
cache.S efi: arm64: enter with MMU and caches enabled 2023-01-24 11:51:08 +00:00
context.c arm64: Ensure bits ASID[15:8] are masked out when the kernel uses 8-bit ASIDs 2024-12-05 11:24:38 +00:00
contpte.c mm: arm64: document why pte is not advanced in contpte_ptep_set_access_flags() 2024-09-06 12:28:33 +01:00
copypage.c arm64: mte: Fix copy_highpage() warning on hugetlb folios 2024-12-05 11:25:44 +00:00
dma-mapping.c arm64: Properly clean up iommu-dma remnants 2024-05-10 09:04:25 +02:00
extable.c arm64: extable: cleanup redundant extable type EX_TYPE_FIXUP 2022-06-28 12:11:47 +01:00
fault.c - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
fixmap.c arm64: Add support for FEAT_HAFT 2024-11-05 13:18:35 +00:00
flush.c arm64: implement the new page table range API 2023-08-24 16:20:20 -07:00
gcs.c arm64/mm: Implement map_shadow_stack() 2024-10-04 12:04:40 +01:00
hugetlbpage.c arm64: hugetlb: Fix huge_ptep_get_and_clear() for non-present ptes 2025-02-27 17:40:58 +00:00
init.c arm64/mm: Fix Boot panic on Ampere Altra 2025-02-27 00:26:49 +00:00
ioremap.c arm64: mm: Add confidential computing hook to ioremap_prot() 2024-08-30 16:30:41 +01:00
kasan_init.c - Sumanth Korikkar has taught s390 to allocate hotplug-time page frames 2024-03-14 17:43:30 -07:00
mem_encrypt.c arm64: mm: Add top-level dispatcher for internal mem_encrypt API 2024-08-30 16:30:41 +01:00
mmap.c arm64/mm: Map pages for guarded control stack 2024-10-04 12:04:36 +01:00
mmu.c arm64: mm: Test for pmd_sect() in vmemmap_check_pmd() 2025-01-07 16:51:42 +00:00
mteswap.c arm64: mm: swap: support THP_SWAP on hardware with MTE 2024-04-25 20:56:07 -07:00
pageattr.c - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
pgd.c asm-generic: pgalloc: provide generic __pgd_{alloc,free} 2025-01-25 20:22:24 -08:00
physaddr.c
proc.S arm64/sysreg: Get rid of the TCR2_EL1x SysregFields 2024-12-19 18:00:58 +00:00
ptdump.c arm64/ptdump: Test both PTE_TABLE_BIT and PTE_VALID for block mappings 2024-11-05 11:56:29 +00:00
ptdump_debugfs.c
trans_pgd-asm.S
trans_pgd.c arm64: Fix 5-level paging support in kexec/hibernate trampoline 2025-02-04 12:23:09 +00:00