From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD0B8397332 for ; Tue, 9 Jun 2026 19:45:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781034353; cv=none; b=cImczbt7SzKHfp4rf+FGQXrpOsYFLstx6iIzqWi3FYQl+0ax/Co3Ftvbdz1mk7MRJwxmEWrVvjKtFjicNopBkB0C/OUxfPRKfcrPO3I/VDGHhy9XofpWXUTbykN1eJU51pEgm2yATsFXLAmOjGnTcDhO8NqnBLHwcsLODHW+kPk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781034353; c=relaxed/simple; bh=smzRik2LYOxboKhc6pmKU63gBz3kFuXqBeq9ZnPl4Xo=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=BgX8xyi1IZCaxSLG1HAm0uYJXShuoWtR1pYvBEjgiKe1th753YLYglRjAwRWDESbYd2H8FAWQ5ZdLQuwJ5l+C063YYM9Wt2cl63odxbA/K/DQ/Cvi1PpWOM7ALlbjFFbFAm7dW5qwwPmf5T9qNvFSGSMCeKXoEII/zUBHoHZbyM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=WAftlABo; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="WAftlABo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30D041F00893; Tue, 9 Jun 2026 19:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1781034351; bh=sDnT/R8r7fr0S+byBNjg5mZPhI3/Z2+xQc0Imi0qg1U=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=WAftlABopgVwyK7vGdX/rtSLAO9xtr0zc+DLl4US/9eBTEMgAwekI2vvfzqxbkLvT Wd4X5e2nqodqCSdGijAYC7Pm0so6Nq5F0UhcYuMuxk2QEPxd8donUTVOuSSVYE3uBv Zw7XdRWDnVlqpb2ACbHDkFj65maHJqMxriyS8hL0= Date: Tue, 9 Jun 2026 12:45:49 -0700 From: Andrew Morton To: Xueyuan Chen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, catalin.marinas@arm.com, will@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, hpa@zytor.com, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, yang@os.amperecomputing.com, jannh@google.com, Dave Hansen Subject: Re: [RFC PATCH v2 1/3] mm/huge_memory: make persistent huge zero folio read-only Message-Id: <20260609124549.aff7e774603c4af188009408@linux-foundation.org> In-Reply-To: <20260609143801.7917-2-xueyuan.chen21@gmail.com> References: <20260609143801.7917-1-xueyuan.chen21@gmail.com> <20260609143801.7917-2-xueyuan.chen21@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 9 Jun 2026 22:37:59 +0800 Xueyuan Chen wrote: > The huge zero folio is shared globally, and its contents should never > change after initialization. As Jann Horn pointed out[1], the kernel has > had bugs, including security bugs, where read-only pages were later written > to. If the persistent huge zero folio is read-only in the direct map, such > writes fault instead of silently corrupting the shared zero contents. > > Add arch_make_pages_readonly() so mm code can request read-only direct-map > protection for a page range. Direct-map protection is > architecture-specific, so the generic weak implementation does nothing. > > This was inspired by Jann Horn's read-only zero page work[1] and follow-up > discussion[2] with Yang Shi. > > [1] https://lore.kernel.org/linux-mm/20260508-ro-zeropage-v1-1-9808abc20b49@google.com/ > [2] https://lore.kernel.org/linux-mm/CAHbLzkrXXe7r3n3jXgDKtwZhRqj=jDx9E6dLOULohnhBguvi9A@mail.gmail.com/ > > ... > > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -308,6 +308,11 @@ static unsigned long shrink_huge_zero_folio_scan(struct shrinker *shrink, > return 0; > } > > +bool __weak arch_make_pages_readonly(struct page *page, int nr_pages) > +{ > + return false; > +} > + > static struct shrinker *huge_zero_folio_shrinker; > > #ifdef CONFIG_SYSFS > @@ -982,8 +987,14 @@ static int __init thp_shrinker_init(void) > * that get_huge_zero_folio() will most likely not fail as > * thp_shrinker_init() is invoked early on during boot. > */ > - if (!get_huge_zero_folio()) > + if (!get_huge_zero_folio()) { > pr_warn("Allocating persistent huge zero folio failed\n"); > + return 0; > + } > + > + arch_make_pages_readonly(folio_page(huge_zero_folio, 0), > + HPAGE_PMD_NR); Can it simply pass the folio?