The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: Yang Shi <shy828301@gmail.com>
Cc: jannh@google.com, rppt@kernel.org, akpm@linux-foundation.org,
	arnd@arndb.de, linux-mm@kvack.org, linux-arch@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
	ardb@kernel.org, sethjenkins@google.com
Subject: Re: [PATCH] mm: make zeropage read-only
Date: Thu, 14 May 2026 10:16:19 +0800	[thread overview]
Message-ID: <5478f96d-277c-46c3-b437-1660706fd784@linux.dev> (raw)
In-Reply-To: <CAHbLzkpBB2ia4pUG1khZy1w5G_sq6DD+9OnqjrJ6Yu0KxPAe=A@mail.gmail.com>



On 2026/5/14 07:10, Yang Shi wrote:
> On Tue, May 12, 2026 at 7:12 PM Lance Yang <lance.yang@linux.dev> wrote:
>>
>>
>> On Tue, May 12, 2026 at 10:14:01AM -0700, Yang Shi wrote:
>>> On Tue, May 12, 2026 at 6:48 AM Jann Horn <jannh@google.com> wrote:
>>>>
>>>> On Tue, May 12, 2026 at 4:31 AM Lance Yang <lance.yang@linux.dev> wrote:
>>>>> Would it makes sense to apply a similar treatment to huge_zero_folio
>>>>> as well?
>>>>>
>>>>> with CONFIG_PERSISTENT_HUGE_ZERO_FOLIO=y, it is allocated at boot and
>>>>> never freed, so it should never be written after initialization either :)
>>>>
>>>> Oh, neat, I didn't realize that that feature exists.
>>>>
>>>> I guess there are two aspects of making the huge zero folio RO that
>>>> could be problematic:
>>>>
>>>> 1. If the huge zero folio comes from the page allocator, making it
>>>> read-only might require splitting a huge PUD, which could have
>>>> performance implications.
>>>> 2. I vaguely remember arm64 has rules about how PUD/PMD entries in the
>>>> linear mapping can't be split at runtime at all depending on hardware
>>>> capabilities, meaning the entire linear mapping may need to be mapped
>>>> without any huge PUD/PMD entries - IDK if thp_shrinker_init() runs
>>>> early enough to be excepted from that. See can_set_direct_map() and
>>>> force_pte_mapping() in arch/arm64/.
>>>
>>> Yes. First of all, this relies rodata mode. If rodata=on (used to be
>>> called full), the linear mapping may be mapped by PUD/PMD if the
>>> hardware can support BBML2_NOABORT, otherwise it is mapped at PTE
>>> level all the time. But how huge zero folio is mapped in linear
>>> mapping should not matter, you just need to change the linear mapping
>>> permission to RO anyway.
>>>
>>> If the rodata mode is off or noalias (used to be called on), the
>>> linear mapping may be mapped by PUD/PMD, but basically changing linear
>>> mapping permission is not expected by kernel.
>>
>> Ah, right. So for huge_zero_folio the hard part is not just making the
>> backing memory read-only, but also whether we can change the linear
>> mapping permission for that range. That depends on the arm64 rodata mode
>> / direct-map setup.
> 
> An alternative is you can allocate huge zero folio in the early stage
> of boot before linear mapping is set up. Then when setting up linear
> mapping, you can just make that PMD RO. It should work regardless of
> rodata mode.

Cool. Good call. That would avoid changing the linear map permissions at
runtime.

Thanks for pointing that out! I'll take a look when I get a chance :)

Cheers, Lance

> Thanks,
> Yang
> 
>>
>> Thanks Jann and Yang for the explanations!
>> Lance
>>
>>> Thanks,
>>> Yang
>>>
>>>>
>>>> So making the huge zero folio RO in the linear map would probably
>>>> require adding a new config flag, connecting that to
>>>> ARCH_HAS_SET_DIRECT_MAP, and changing one or two places in arm64
>>>> memory management.
>>>>
>>>


  reply	other threads:[~2026-05-14  2:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08 16:12 [PATCH] mm: make zeropage read-only Jann Horn
2026-05-08 16:26 ` Jann Horn
2026-05-12  2:31   ` Lance Yang
2026-05-12 13:32     ` Jann Horn
2026-05-12 17:14       ` Yang Shi
2026-05-13  2:11         ` Lance Yang
2026-05-13 23:10           ` Yang Shi
2026-05-14  2:16             ` Lance Yang [this message]
2026-05-10 15:12 ` kernel test robot
2026-05-10 21:40 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5478f96d-277c-46c3-b437-1660706fd784@linux.dev \
    --to=lance.yang@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=jannh@google.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    --cc=sethjenkins@google.com \
    --cc=shy828301@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox