sh: mm: fix hugetlb on SH-4
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest2 patches 4 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | sh: mm: replace the page size bits in pte_mkhuge()arch/ | +5 | 1 reply | |
| 2/2 | sh: mm: align hugetlb mappings to the huge page sizearch/ | +9 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/2] sh: mm: fix hugetlb on SH-4
Muchun Song noted in the review of the Arm hugetlb alignment fix [1] that SuperH has the same arch_get_unmapped_area() gap. Reproducing it in QEMU turned up a second, older bug that corrupts memory once the mappings are aligned.
Patch 1 fixes the page size in hugetlb PTEs. pte_mkhuge() ORs the huge size into the base page size bits, so 64 KiB huge pages over 4 KiB pages are loaded into the TLB as 1 MiB pages. User writes then land in unrelated kernel memory. This dates back to the start of git history.
Patch 2 aligns hugetlb mappings to the huge page size. Without it mmap(MAP_HUGETLB) can return an address that is not aligned to the huge page size, and process exit hits the BUG_ON() in __unmap_hugepage_range(). This is a 6.13
regression.
Patch 1 goes first because patch 2 alone makes the corruption reachable through a plain mmap(). Both are marked for stable.
Tested on QEMU r2d (SH7751R, rts7751r2dplus_defconfig plus HUGETLBFS with 64 KiB huge pages, gcc 15.2) on top of fddfc3ec3179. A test init maps two huge pages with the default and legacy layouts and with MAP_FIXED, writes and reads back every 4 KiB, mprotect()s the mapping read-only and back, and checks a COW write in a forked child:
kernel MAP_FIXED default/legacy mmap base memory corrupt misaligned, BUG at mm/hugetlb.c:5215 patch 1 pass misaligned, BUG patches 1+2 pass pass
SH-X2 (X2TLB) is only build tested (r7785rp_defconfig with 64 KiB huge pages).
QEMU's SH-4 TLB emulation flushes only the first 4 KiB of a 64 KiB or 1 MiB entry when the entry is dropped [2]. Keep that in mind when testing hugetlb on QEMU.
[1] https://lore.kernel.org/r/[email protected]
[2] https://gitlab.com/qemu-project/qemu/-/issues/4598
Karl Mehltretter (2):
sh: mm: replace the page size bits in pte_mkhuge()
sh: mm: align hugetlb mappings to the huge page size
arch/sh/include/asm/pgtable_32.h | 7 +++++-- arch/sh/mm/mmap.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-)
base-commit: fddfc3ec31799a932bb92f1b8a84cb3d1f963be9
Signature · 1 line
2.39.5 (Apple Git-154)