Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 BFBDF3876CC for ; Mon, 27 Jul 2026 14:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785162889; cv=none; b=jKC3+ZiwfSDYiN8y2oa7bc5Tyr1P4dJYIGRSiSwNAZdLtsRZ2DKj8lO849U5wxMQVACd7g5eiARLuiOYiV5aLsx++2R4MPpRmcZo0xpkyj9R7bFdpYU91PLSx22QZ98hNLdPNAYEomYobw3pJVRscOo/bEijG8vlCWr+b9srXs4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785162889; c=relaxed/simple; bh=b1frFxqmGvY9N7jfxhC9+mCqECVcuS7AtkBDk72pVfM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Q3H7D8LqxCLlKg4ZRmbBn2rmYkCE60bzqcspcpZeUFOpDTQzf5+T9bacG+fjyUztnmaNsIFucJ8RYbHnrkQZPcK5OfV2yOWxSm+5kqkn+j2OFsNwQ6KkPARBzBFCv1VhcCW1VYXGG9KYO212JhSnMbn/yqQqge+GdMnof7J5sFg= 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=Dwy9sHJz; arc=none smtp.client-ip=209.85.214.175 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="Dwy9sHJz" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2cc7a269ca1so5925735ad.3 for ; Mon, 27 Jul 2026 07:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785162887; x=1785767687; 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=8jVxeCFazqwknGlFRRbIYSIHmRn7jbRySRKJMOZEfOc=; b=Dwy9sHJzwkOQnBw6Gpjtp19elS/5wL2ytMvYGYk/Z++wqQ3ymRNae+jm9i13BBNdkg xv8gONyp/pPZpC3QEf7r1e0x//Ux4b0THBZuTt76zF7aOs/4NYGyjDWsptvdteafNVuh 3w11Fr+wJ8W2Q1mAnccFf5JrjTAhQgk4Wg1AwUhkrbYCSKcUNahppyNc7pXfDDmP7Mhd AnSupzVoOgcVjLR5s6eHJWdC6FFpY2Y4/YG3D6QbYq0MwB+O2lLIRD5HJDR0nwvSYugo oozvjm1zTVZIlWnCTR8zB2yD51VMwsbKShrwaMo0wbXMkj77eJeS94ZBfY6jpNbdg80w MLTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785162887; x=1785767687; 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=8jVxeCFazqwknGlFRRbIYSIHmRn7jbRySRKJMOZEfOc=; b=AOpbMFg/FT3UKLovIFGYyTkm7aAfcFygpMr14VIjoWaUq8Dv1UWjq8rAIqikGNJIgA 4Jw4i60wSbpFDQSfTc6uXjJheNlrKq3IguetDEhRUP2qosHoRNWohLZYSjevFYhERZTo Ow+TzxQ4W8ZyK+UXXP+4jW1tg4AplKv4iaX+eur5teUv6bUe0Md2bIVYiRKUKVXiKlnU zluuvp8N9RfZrhSzZZj0+OnRVDmUc4p4osFtHxw/a34cuaf2+M1WMzCnDMF1afzKBeB5 Tvzv6TemXCzbdk9/5XpaJCbTF94ABOjvbkouuVj7h8FsrPKucF4TW8xd0SC+Cr/NwhEC JQGA== X-Gm-Message-State: AOJu0Yw5Z4C7PDKvN5ZRUAEnvE99DvzXS1D4JIP+X/a8zc165DJiAFnp o7THLAHzuZ2gBI8prBOeYCeq0r4by4WR+aICa2af+KbiohxHteAr5Vcs X-Gm-Gg: AR+sD10fplwFHzufex37CpKkNG88Sk0BhzQyfijXU87Q28YYT3mepF/aVplpX4Bf9qc iVOp3tf55b2IPBBo+a2DMTRbVRsPxu1i6ONoUYBujpO4clP5nPlBlfoFZX3aMmK4hII94CBWWDY +M1zKQDVsU5c9PAqvF+b49xzYo3eX1YiHhg005C9Pt4hEhhq6eDcogJQelj0Exj41DupRtddbwG 330CG8RMkThD/ieDle/9BiSae32SobeDIhoj2eS7eT6uCJ4m3GwwFAakR5LzbVW5gfyzFDU3BuI lrmBcWQvK+yvijwK1PHXQsbDVhpcZVs/dYXqlqheZQctitMi5cD8EE7vjYrb3x9+SJONZPhjALN bFC+noUzofPqBYw3096ANkVmVYYc9vkvN7jWSuJ1aI9gF9H74wL4TaYSTXCflQ0S13V5hN+d1PM oCmwFn9o4sQWAPgRBocvU9gWHJ4qzYhq20j+P+jPLh3fm7BJMBguiq3JLIYv/FF4hgg2/UPGF4N rw= X-Received: by 2002:a17:902:e948:b0:2ca:d803:5c8f with SMTP id d9443c01a7336-2d00b42a776mr4692505ad.1.1785162886755; Mon, 27 Jul 2026 07:34:46 -0700 (PDT) Received: from debian.lan ([141.11.42.65]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cfde7d5297sm36877485ad.56.2026.07.27.07.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 07:34:46 -0700 (PDT) From: Xueyuan Chen To: linux-mm@kvack.org, akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, luto@kernel.org, peterz@infradead.org, lance.yang@linux.dev, usama.arif@linux.dev, jannh@google.com, yang@os.amperecomputing.com, rppt@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org Subject: [PATCH v5 0/3] mm: make persistent huge zero folio read-only Date: Mon, 27 Jul 2026 22:34:23 +0800 Message-ID: <20260727143426.1077133-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. This is the first non-RFC posting of the series. The direct-map helper interface and its TLB invalidation contract have stabilized through the RFC discussion, and the series is now intended for regular review and possible merging. 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] 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 | 16 +++++++++++++++- 6 files changed, 73 insertions(+), 1 deletion(-) -- 2.47.3