On Tue, May 12, 2026 at 10:14:01AM -0700, Yang Shi wrote: >On Tue, May 12, 2026 at 6:48 AM Jann Horn <[email protected]> wrote: >> >> On Tue, May 12, 2026 at 4:31 AM Lance Yang <[email protected]> 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. >> >

