Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 AF6392DB794 for ; Sat, 18 Jul 2026 09:56:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368618; cv=none; b=nwxdu84xQD7aidpjGzwjDrwWuGB7y82v7bh9aun253BVRz1pJEdtkmNdJfOF+IcWt/uEwItzArxemSuXW0KICwVTQ4VPPhtyHETdH1q39ZbHhB3UXtuY+PJdnzMEj891gHHI6VONETHXR2+kmmYAENtdEb5zuuBB1IUl3Y22kgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368618; c=relaxed/simple; bh=ruzQy+6gOkJqaliPHfZlaqm1JPYtGWsjmhP5hrq9aYs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZJIytMmg63JinElk83rpYBy8gK19CbGMkjxVk04lQXxn40AqYHMTxvSGnShTHlCtsGlAJhTmWHxYXDX6MfaEaTepiECPrlnzpJ2RZRSqwgr8R4KEZCWZSLMjowlpwZT5l/94YU+2ZWH1dV0Fu3kLPDRZWUKxtpi2Zs8skwJ9q3w= 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=bmopLqqF; arc=none smtp.client-ip=209.85.216.49 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="bmopLqqF" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-384422b05b5so1061917a91.2 for ; Sat, 18 Jul 2026 02:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784368617; x=1784973417; 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=XHtCFulTi7QuN+vcsXlI37N2cwZV1gauKNkUTz4LeTU=; b=bmopLqqFMtefg4D7Oy8aYp00gSj+yGyhLfWx2QFVIQpvXfPWK5E0wUds473dcNVx1M dFjhkh2r1KsBtvp0yQUTVjCxC2dVo4Lr1ieY7LBy47CMQLA2h1vGVKo/gkjmVLX6sAkw 5HvXdFw6E8+MV4CGBDYW5lkJFTOZn+9GY7UOPAIyd6m+6eB3cQDIA6R+YgSnjgR7AZO7 jxxswXJVw+pALdfyA7/zbDPXgKuh729LOxt0p0YxEHYoiqNMtq/IRaLNA3Ficy/KYd/5 PckEB3mm1j5aIHp+ey63TyVQuKoT5XJ7mKPsMHQYMj+s1OzObpobH2Ys+2zd0d1KkkId 7kjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784368617; x=1784973417; 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=XHtCFulTi7QuN+vcsXlI37N2cwZV1gauKNkUTz4LeTU=; b=cgcpCp2qLOhV94+0hxGFwwQ5SuBcoboczwGGoo2KcbAPO35AcFHIEpVOceJXiTXJuE WXBPGD73OD5oLfDu9xKC19q0O/6ClaNI5WogpJGYC/5U61bYFUavbHOY+A/djUTzMZw9 mnAD/MqxHq4jtetyZcfBN3Le8HCrEb9MhnF4EHxRuLMD6OY4iNKBlkBjFH86djp1tq2h vn9/nmWv9vDuhk5cGM4TopJeDOrbzpRHbC0SIY1P/kp1mJia9HtHyXQsNcbu51Ns+iDV ngW4r8u7s3983tV33fknEpskp2qNj0y+MWOUAUxGOs+auCtcwMSRahCCcmvRKL+3quTv Xm+w== X-Gm-Message-State: AOJu0Yw2GCAKd7USypybN10clEQqDpYMm8CnltTwVOiBy4Or2y2QmP5R IBJA3XRX+TtNb4vx/wwHQBOju6wwIM6vJBRiXzEpJUkuZW/MqpYOrI3N X-Gm-Gg: AfdE7cl8iYRazn1J92JdT0mrqheZiJOy1qB9P1PuDl0CHC5bPi4ZShXza5O2afp6zrR 0Wy7M5Z3YB2wcP/qd1N4AsS3nUNOE6YESk0oPl34gRFIizCWw962IX5dJ+JYTlG+FT2+OmCpLsG BHTF5g+4UUPtDlFhayizjZ6CKFOXe8ahelRtfH17x1VUHONYVH1c2rE2X2yKPfLiBh5zTdIYvr4 g4IJbm72Rg3ld58BivyB6jle1kpzRnKY5fLXEc/5oZtyCE1AqhiFv1hTYmN7WOeHI22uULghI8G LINPyc1SrR5/Nii6RmTw3NZxk/f4SqVQa2fahB4yYqVsyHCyXG7Crsrse1tPdG0HfnI4GdaZ4UK gmopVziEy1n5HLMfFk+TG5j8BunJa/jyE4SaD5m1uvEoYwoDkE1Am2l29YWS/e004Aqg+kHaGLu hiMkhEfh7tOfUexbwGbP6O9RjRceZTokzKsSUmIbAdDfjk X-Received: by 2002:a05:6a00:80e6:b0:842:5a15:6fa6 with SMTP id d2e1a72fcca58-84c294b7ad8mr3410940b3a.3.1784368616755; Sat, 18 Jul 2026 02:56:56 -0700 (PDT) Received: from debian.lan ([240e:391:eb4:a240::1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84c2af317c8sm2417248b3a.30.2026.07.18.02.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jul 2026 02:56:56 -0700 (PDT) From: Xueyuan Chen To: linux-mm@kvack.org, Andrew Morton , David Hildenbrand , Lorenzo Stoakes Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Lance Yang , Usama Arif , Jann Horn , Yang Shi , Mike Rapoport , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Xueyuan Chen Subject: [RFC PATCH v4 0/3] make persistent huge zero folio read-only Date: Sat, 18 Jul 2026 17:56:44 +0800 Message-ID: <20260718095647.182592-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. v4 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. Patches 2 and 3 add arm64 and x86 implementations. [1]: https://lore.kernel.org/linux-mm/20260508-ro-zeropage-v1-1-9808abc20b49@google.com/ [2]: https://lore.kernel.org/linux-mm/0e5b23a6-4895-454a-9dfa-6dc21adc2991@kernel.org/ [3]: https://lore.kernel.org/linux-mm/CAHbLzkrXXe7r3n3jXgDKtwZhRqj=jDx9E6dLOULohnhBguvi9A@mail.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