All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: shy828301@gmail.com, jannh@google.com
Cc: lance.yang@linux.dev, 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: Wed, 13 May 2026 10:11:48 +0800	[thread overview]
Message-ID: <20260513021148.17588-1-lance.yang@linux.dev> (raw)
In-Reply-To: <CAHbLzkrXXe7r3n3jXgDKtwZhRqj=jDx9E6dLOULohnhBguvi9A@mail.gmail.com>


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.

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-13  2:12 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 [this message]
2026-05-13 23:10           ` Yang Shi
2026-05-14  2:16             ` Lance Yang
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=20260513021148.17588-1-lance.yang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.