Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C0493EF678 for ; Thu, 30 Jul 2026 09:06:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785402420; cv=none; b=ODTyzfqapf1CYD/zaAm+2u/MdVh8S+X2RM4ZK/iBJ5jjviX1DX++ALHpt/EUpMO8AynY0ObSA+3VUyLxMgtnV4FfPJb2j4n85kVdHqnpBGa81x7g6/LicnjYorLIyiPS7sBd9lseu6OHo7Hh+IKXzgrxorGrhOprOifSP17yIQ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785402420; c=relaxed/simple; bh=zagWqobn7IoHQanBRAnp62RiVrqjMLO10Ak9WU5GEcA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=R+j2q5/iucm/k2Ygxkm0cMmCUUAi4qtBHvqK/k2GiN7gtKkhSk9FMsIWduvmj+VG/n0A69pcPda70SmEeBE9JtoVzaa1ooC/45AVUndVX+T1lHtWYPUYGpk/NZVW8FjGLYWJ7WdVpqXIUqxmrde5NlGDWBwq2cC6X9Xh/TnWMIY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JcD49kTO; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JcD49kTO" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-848c995c29dso148539b3a.3 for ; Thu, 30 Jul 2026 02:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785402418; x=1786007218; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=JyUPYL2OrXSKt8rHjiCQrmfpBKq5z8MLwljG9M1Hes8=; b=JcD49kTOqFBP+4UUXeoL6bpAUkM4joIHGHX2eV3fXGtanUaf3XadTbiXbIDSJnE0rZ pfk2k1UsL64dsQ4JsKuA3T1OzLXQ/ZIoGXMLbzwwvqaEG/S365aEtGuG7mplp/FhyHLs U15TQqVQitArv0BzY12BdfDgevE0aGJnpCgAWahzDVWRK/HY2UnbSjLs+eLEvKDvVnjJ /gj1X0pR2dFmomi8HXXQoK4iAN2/phDf+WSoz0brLwPZd2kH6b6RYyquKV2Z2l5VePqp RFB2OEAsv/smXIr8WXMOi+yKgNq/9nNzaxNJMYbdns/S4KTFSAuuylTvIUgh22H+nQjc WsXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785402418; x=1786007218; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JyUPYL2OrXSKt8rHjiCQrmfpBKq5z8MLwljG9M1Hes8=; b=LI6rTbc4NGm1kM4pXgroyDnq/C3uFv9EHUa2NEQctXgzFdeY93SoTAemQEzjqu7FsS U6Hrxc5TiDFygR2w4eJYQtniDYm3B+/1sXo97AxEADA5jNXbaSpoi8R5MzgI6ZjkaAI4 yHlfmcQNeR34FRWRGOMsEnsklAxdV9llRIaX/P1GcRO874HFN9VIj5PNPcfH4HsoimIU /35TYtpjKWQ0uO4ew/VGWu7rAssiiAWsjGfx4ubRDgiErEqxbH1P7MB3Z4/64N7Q8BMX 0qKsEn3xnFWDHVkhnOt4PyQGnw/4Jn3cAKGaEjI7ke2w3LLGVBBvVEcS9a2nY3nSWTCA pFKg== X-Forwarded-Encrypted: i=1; AHgh+RqfjN0q2C5YsQ0A8V2lLcfKoOIvygE9ebc+BgLEDyoy/nH1/4Hi+A934v2jbyGGBSmGPUDJGQLyOzqClKs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2oWKi1xTDkjw0gZNqX32SlNDvpxzJ8Be4aghtxOIAi4BngrZD Tc+UrXnhjpAXSLcSQAuH4ZOxQm2JjsimcLNr4VP1MYLLWIN9W9cGzomZ X-Gm-Gg: AR+sD13cPfH5AOgXuwUe2/uFmSGEcCTARRBqUpJvrcZke81RqZYIbxsHR+wvyIBWw8C XZOuaZwXpMkiXB2G+WOhX2MdRA7SViPhNT9peP93EF0WhzD1TugbiH0BTdSJw9sEypYUOEBOYFQ Z20qD4+FIy5ayY87j04S10zwK8ZFKCqtQMB2P/OAdCnU5RYUJ/wyaU3jGyKe/LaWmcoX3j0vjMC J75yusDBzRAeYJrSrBDM7KzjMOAW5CiMqSFRQaq1Hme3n+XnccsviiOukOaIZTeFnEdx77BCxtO 0+xTb+zxqABpC1ZGhaNLpfEcc1X7SCb7H7NFHbPRrqqj0gAQLoNqTcBSBmXC8xVGSAdfRbHGtLu 6tCnQoZsZN+Yhg3ajaglYCxx8e1Zsu8bBn253BjZnJi85qo9xhkod7p6WsJppHdKpiT8H2DuUTQ Bl/HzQv6eFaomcs+YRRR6gpdJ2/cqb1s7OHHU7Uul1Rj0+80o0h0kB92bcdxiBX88vxZuX9mqLi YExnyQIvuSn8B+ku1KWU93bi6rDJCqV+HC+7dX3EJ+s2MEnksxr X-Received: by 2002:a05:6a21:3997:b0:3c6:7648:5ab0 with SMTP id adf61e73a8af0-3c9003cc78cmr2258784637.0.1785402417981; Thu, 30 Jul 2026 02:06:57 -0700 (PDT) Received: from debian.lan ([155.117.85.23]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cbdba447107sm1902510a12.21.2026.07.30.02.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 02:06:57 -0700 (PDT) From: Xueyuan Chen 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 Subject: [PATCH v6 0/3] mm: make persistent huge zero folio read-only Date: Thu, 30 Jul 2026 17:06:44 +0800 Message-ID: <20260730090647.2401252-1-xueyuan.chen21@gmail.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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