From: Xueyuan Chen <xueyuan.chen21@gmail.com>
To: akpm@linux-foundation.org
Cc: david@kernel.org, ljs@kernel.org, usama.arif@linux.dev,
catalin.marinas@arm.com, will@kernel.org,
linux-arm-kernel@lists.infradead.org, tglx@kernel.org,
mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
x86@kernel.org, hpa@zytor.com, rppt@kernel.org,
ryan.roberts@arm.com, ziy@nvidia.com, baohua@kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Xueyuan Chen <xueyuan.chen21@gmail.com>
Subject: [PATCH v6 0/3] mm: make persistent huge zero folio read-only
Date: Thu, 30 Jul 2026 17:06:44 +0800 [thread overview]
Message-ID: <20260730090647.2401252-1-xueyuan.chen21@gmail.com> (raw)
The persistent huge zero folio is shared globally and should stay zero
after initialization. As Jann Horn pointed out[1], kernel bugs have ended
up writing to pages that were meant to be read-only, including in
security-sensitive cases. Making the folio read-only in the direct map
turns such writes into faults instead of silent zero-page corruption.
This series adds set_direct_map_ro_noflush() so mm code can make a
direct-map range read-only, then uses it for the persistent huge zero
folio. The helper is direct-map specific, takes an address-based range as
discussed for set_direct_map* helpers[2], and leaves TLB invalidation to
the caller.
The folio is allocated and zeroed through the writable direct map before
thp_shrinker_init() changes its permissions. thp_shrinker_init() is called
from hugepage_init(), which is registered as a subsys_initcall and runs
after SMP initialization. Writable TLB entries may therefore already be
cached when the page-table permissions change. Patch 1 flushes the exact
direct-map range immediately after the noflush page-table update. Keeping
the flush at the call site preserves the helper's explicit noflush contract
and follows existing direct-map helper users such as secretmem and
hibernation.
GFP_TRANSHUGE can allocate from high memory on 32-bit systems. Since a
highmem folio has no permanent direct-map mapping, patch 1 skips both the
permission change and TLB flush in that case.
Patches 2 and 3 add arm64 and x86 implementations.
Link: https://lore.kernel.org/linux-mm/20260508-ro-zeropage-v1-1-9808abc20b49@google.com/ [1]
Link: https://lore.kernel.org/linux-mm/0e5b23a6-4895-454a-9dfa-6dc21adc2991@kernel.org/ [2]
Link: https://lore.kernel.org/linux-mm/CAHbLzkrXXe7r3n3jXgDKtwZhRqj=jDx9E6dLOULohnhBguvi9A@mail.gmail.com/ [3]
v5 -> v6:
- Patch #01: Skip the direct-map permission change and TLB flush for
highmem folios, which have no permanent direct-map mapping.
Link: https://lore.kernel.org/all/20260727143426.1077133-1-xueyuan.chen21@gmail.com/
RFC v4 -> v5:
- Drop the RFC tag.
- No code changes.
Link: https://lore.kernel.org/all/20260718095647.182592-1-xueyuan.chen21@gmail.com/
RFC v3 -> RFC v4:
- Patch #01: Flush the direct-map range after changing it read-only, since
the folio was cleared through writable mappings after SMP initialization
(per Usama, thanks!).
- Patch #01: Keep the flush in the caller to preserve the
set_direct_map_ro_noflush() contract and make the flushed range explicit.
- Patch #01: Clarify the noflush API contract and the reason stale writable
translations must be invalidated.
Link: https://lore.kernel.org/linux-mm/20260706130440.9295-1-xueyuan.chen21@gmail.com/
RFC v2 -> RFC v3:
- Patch #01: Replace arch_make_pages_readonly() with
set_direct_map_ro_noflush() in the existing set_direct_map* family
(per Mike and David, thanks!).
- Patch #01: Use a direct-map address and number of pages, and document the
direct-map-only and no-TLB-flush semantics (per David, thanks!).
- Patch #02 and #03: Update the arm64 and x86 implementations for
set_direct_map_ro_noflush().
Link: https://lore.kernel.org/linux-mm/20260609143801.7917-1-xueyuan.chen21@gmail.com/
RFC v1 -> RFC v2:
- Patch #01: Drop the READONLY_HUGE_ZERO_FOLIO Kconfig option
(per Dave, thanks!).
- Patch #01: Replace the huge-zero-folio-specific hook with a generic
page-range hook (per David, thanks!).
- Patch #02 and #03: Update the arm64 and x86 implementations for the new
hook.
Link: https://lore.kernel.org/linux-mm/20260527035607.14919-1-xueyuan.chen21@gmail.com/
Xueyuan Chen (3):
mm: make persistent huge zero folio read-only
arm64/mm: add set_direct_map_ro_noflush()
x86/mm: add set_direct_map_ro_noflush()
arch/arm64/include/asm/set_memory.h | 2 ++
arch/arm64/mm/pageattr.c | 10 ++++++++++
arch/x86/include/asm/set_memory.h | 2 ++
arch/x86/mm/pat/set_memory.c | 15 +++++++++++++++
include/linux/set_memory.h | 29 +++++++++++++++++++++++++++++
mm/huge_memory.c | 20 +++++++++++++++++++-
6 files changed, 77 insertions(+), 1 deletion(-)
--
2.47.3
next reply other threads:[~2026-07-30 9:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 9:06 Xueyuan Chen [this message]
2026-07-30 9:06 ` [PATCH v6 1/3] mm: make persistent huge zero folio read-only Xueyuan Chen
2026-08-25 15:51 ` David Hildenbrand (Arm)
2026-08-25 16:29 ` Dave Hansen
2026-07-30 9:06 ` [PATCH v6 2/3] arm64/mm: add set_direct_map_ro_noflush() Xueyuan Chen
2026-08-25 15:52 ` David Hildenbrand (Arm)
2026-08-25 16:44 ` Will Deacon
2026-08-25 16:46 ` David Hildenbrand (Arm)
2026-08-26 7:53 ` Xueyuan Chen
2026-07-30 9:06 ` [PATCH v6 3/3] x86/mm: " Xueyuan Chen
2026-08-25 15:52 ` David Hildenbrand (Arm)
2026-08-25 16:18 ` Dave Hansen
2026-08-25 16:43 ` David Hildenbrand (Arm)
2026-08-25 16:57 ` Dave Hansen
2026-08-25 17:30 ` David Hildenbrand (Arm)
2026-08-26 12:19 ` Xueyuan Chen
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=20260730090647.2401252-1-xueyuan.chen21@gmail.com \
--to=xueyuan.chen21@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=hpa@zytor.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mingo@redhat.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=tglx@kernel.org \
--cc=usama.arif@linux.dev \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=ziy@nvidia.com \
/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