Re: [PATCH v7 1/3] mm: make persistent huge zero folio read-only

From: Mike Rapoport

Date: Mon Sep 07 2026 - 02:03:54 EST


Hi Xueyuan,

On Mon, Sep 07, 2026 at 09:11:14AM +0800, Xueyuan Chen wrote:
> On Sun, Sep 6, 2026 at 6:00 PM Mike Rapoport <rppt@xxxxxxxxxx> wrote:
> >
> > > > > +
> > > > > + /* Highmem folios have no permanent direct-map mapping to protect. */
> > > > > + if (!folio_test_highmem(huge_zero_folio))
> > > > > + set_direct_map_ro(folio_page(huge_zero_folio, 0), HPAGE_PMD_NR);
> > > >
> > > > Sorry, I don't remember if it was discussed previously, but why can't we
> > > > use the existing set_memory_ro() here?
> > >
> > > Hi Mike,
> > >
> > > We want to change the linear map here, but arm64 set_memory_ro() only
> > > works on vmalloc addresses.
> >
> > I believe this is an historical artifact. change_memory_common() already
> > updates the linear map when a vmalloc mapping switches to RO and the system
> > supports it.
>
> On x86, set_memory_ro() does work on direct-map addresses.
>
> >
> > I believe arm64::set_memory_ro() can change the linear map in the general
> > case as well as long as can_set_direct_map() is true.
> >
>
> On arm64, I'm reading arch/arm64/mm/pageattr.c, and the linear-map
> update in change_memory_common() is only reachable for vmalloc
> addresses:
>
> set_memory_ro
> change_memory_common
> area = find_vm_area((void *)addr);
> if (!area || ...)
> return -EINVAL;
>
> So set_memory_ro() on a linear-map address returns -EINVAL on arm64.

And I believe this is an historical artifact rather than necessity. For
configurations that allow set_direct_map on arm64, change_memory_common can
update direct map too, it just need to be implemented there.

--
Sincerely yours,
Mike.