Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 8111535836B for ; Mon, 6 Jul 2026 13:05:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783343112; cv=none; b=NYzGSF4SzThf+6lYFOLFlQIt1PMTqE2IEYANHmRO3VbEm3DMjEK+0paH87710HC0Ku6IE4L3slpu2mA9it0kXayOtJ61iBcbhE0ZjT9yn/zOHz1bIGcTNRADhX9NXxeEyrKe3DuSHzC3qpzuEVbcrVawPKchKHWPaemFH5nO1H4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783343112; c=relaxed/simple; bh=P4VJa7HdSualQ1xz5oDbMi/z0BKqWnb43Q+FD8TsIUA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=c30jH4z0r2wTRQCu44eLx3YdwY2WWo95+gBLGakdHVx3fU3T/6eezZyErb4Ii2og9IfEPsjrDAW6RyDP0Gsku14rOL3u3Zlu5L2w/h+ksCzmidI6Hg4ke/LG17+drBsAtYFP2aPm3cYAnJrUbvn93N4l6DNFFcvH/0Y3qR1b6q0= 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=EmqE7YRz; arc=none smtp.client-ip=209.85.221.43 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="EmqE7YRz" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-4731f5ffa74so285875f8f.1 for ; Mon, 06 Jul 2026 06:05:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783343110; x=1783947910; 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=OH8Zt8IpG4afTGjwrwNv/V/3GqQR4XmcV5U6B0IG+d8=; b=EmqE7YRzQ2D5cla9fk5Y+dmaMvyqE1Ekhpm4t2UVj/SO1kNq7+iYMu31t/t7PaU2PW YNA6uDoAQlQc+Nl1XT/qekUERwMUi6nbAofjhrKsX6x5oTJ+iFfKivKJr+NS5VC62ZiR bSbNtkCtteSednQA54kijx/TI7SZAGpIhIj9GgA4dJuZcGVHD4bjly/L0fu+RGQOSy2m sl533HrTWkkR6EsHGE45OseiJwhYOlvOu5+5P2VNHPi+5h47PvnvQUCTGOE+CuFceDUP 2l4/tRSFoS2T9JE4em8phNDcMqrWk43fRC7cuRMk+8/a/SUJ0RHC+6vybY0ljzjzXE/4 I7sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783343110; x=1783947910; 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=OH8Zt8IpG4afTGjwrwNv/V/3GqQR4XmcV5U6B0IG+d8=; b=Gl2abatfst9ZcTplavQyMYrXrmSqP0NHv3h3Cal7dvc0g0DI5MJCMzoKyQFHFdLBMA MMjLUnAvmH3kxJhWr20LdTwPLeJB+4efSuNf7gFzH5/Q/ErUpsDcToyB1Zs2m6SWDUHB e0SDcHGMyTbC4Ps/MCRcIxZgGTe5dTq9abfactRt/w32xdBVZksVvjf+ua3H1WbjS6G+ BfuIZcqHXUuqtRLKqIDLPRJnRaRgZFMYdLPnA84HAWcG1gz8gW6Is6nGDMXi2B9UWax3 bzNFi9unhT61wS5GFvdpmXhaNAJ9lOn/nWBN5A9zT1KrNnyL+Qn8iUYyg2jjmxHA8YkK P7Kw== X-Forwarded-Encrypted: i=1; AHgh+Rr98fZARg0NXPF8kb7vBaAolMMboenxn6NnRAad6SQSD6pHVD+VUYlNj9OHeMWExOglUDwoKSxxPayy1F8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3sZBiRU+iYQ5nhCAf8AgmZfIEt8BSwc7W+LZSzKyYRA2agrcU pOMvSHSEwzbd74XbOB4bhXGQ11KndSykEIlq8M52quU8HoHWA5dJazoO X-Gm-Gg: AfdE7ckqyA3WYSzgixLK+BZdrYbdIrESlXheoUS2455fL8AJPjqDXP8UtMawas8aARn +P4ug7A6WOFiuQ29nGfOaUpwD5YcxGaouXn2/Qhxk8U18KNQZvY6iQoyfcEsUpHIlCVrZ7nlC+S QIKEzf2zbpliEMumQ5/rkf9NYRY9/ka+1TBFbuKtDb7JdwId+MMJrNy3xRV9S6VW4xQllkdFjg3 22IExZ4meLZCA/AnG8UzevKjB+2z9V8vLsSUUSdMiIRBk3vrnMLWVBmz3qyxUBa5l5xzwvL30z7 hrzpCkU9y9Iq7BAaYYetzC1UNmzSi7u5ZtqFbdO6EPCD94rzTk45PPBF0D2qK1Xr/Vr+kAfv8hH OeVBWEzelq/bAb9gtIEbAop7rnnIbiBNajJPZWLrdwlsKJehFlKsbeY0ofe0FHdpG5Fh2JteJki tFD5hSCnID2CHVCnZbYUc1uhUhU94bxoruDwnA6ZQ8OxVZoNSURuzAcD21/b1v0z19fO/K7DuEc pa+JlNC1hnT3UMUlkJJzcjDYrstCwZeiCY= X-Received: by 2002:a05:6000:24c9:b0:474:3708:ca with SMTP id ffacd0b85a97d-47aabd3af09mr6808952f8f.3.1783343108571; Mon, 06 Jul 2026 06:05:08 -0700 (PDT) Received: from debian.lan (vmi1894487.contaboserver.net. [154.26.158.71]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47a9de1d8f1sm24515956f8f.3.2026.07.06.06.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 06:05:07 -0700 (PDT) From: Xueyuan Chen To: Andrew Morton , David Hildenbrand , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Lance Yang , Jann Horn , Yang Shi , Mike Rapoport , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra Subject: [RFC PATCH v3 0/3] make persistent huge zero folio read-only Date: Mon, 6 Jul 2026 21:04:37 +0800 Message-ID: <20260706130440.9295-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 persistent huge zero 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 persistent huge zero folio. The helper is direct-map specific, takes an address-based range as discussed for set_direct_map* helpers[2], and does not flush TLBs. Persistent huge zero folio setup happens during early boot, so no explicit TLB flush is needed here. Inspired by Jann Horn's read-only zero page work[1] and follow-up discussion[3] with Yang Shi. 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 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(). - 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. - 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 | 26 ++++++++++++++++++++++++++ mm/huge_memory.c | 9 ++++++++- 6 files changed, 63 insertions(+), 1 deletion(-) -- 2.49.0