From: Karl Mehltretter <kmehltretter@gmail.com>
To: Yoshinori Sato <ysato@users.sourceforge.jp>,
Rich Felker <dalias@libc.org>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: linux-sh@vger.kernel.org, Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
David Hildenbrand <david@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Karl Mehltretter <kmehltretter@gmail.com>
Subject: [PATCH 0/2] sh: mm: fix hugetlb on SH-4
Date: Sat, 26 Sep 2026 20:39:02 +0200 [thread overview]
Message-ID: <20260926183904.76186-1-kmehltretter@gmail.com> (raw)
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/5AB6FE85-4CB9-41EF-A700-BC5E071F29F5@linux.dev
[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
--
2.39.5 (Apple Git-154)
next reply other threads:[~2026-09-26 18:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 18:39 Karl Mehltretter [this message]
2026-09-26 18:39 ` [PATCH 1/2] sh: mm: replace the page size bits in pte_mkhuge() Karl Mehltretter
2026-09-26 18:39 ` [PATCH 2/2] sh: mm: align hugetlb mappings to the huge page size Karl Mehltretter
2026-09-26 18:43 ` [PATCH 0/2] sh: mm: fix hugetlb on SH-4 John Paul Adrian Glaubitz
2026-09-27 18:35 ` Karl Mehltretter
2026-09-27 19:58 ` John Paul Adrian Glaubitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260926183904.76186-1-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dalias@libc.org \
--cc=david@kernel.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-sh@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=ysato@users.sourceforge.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®