[PATCH V2 01/14] mm: Add read-write accessors for vm_page_prot

Anshuman Khandual anshuman.khandual at arm.com
Wed Sep 16 21:02:36 PDT 2026


On Wed, Sep 16, 2026 at 03:23:13PM +0200, David Hildenbrand (Arm) wrote:
> On 9/7/26 05:50, Anshuman Khandual wrote:
> > Currently vma->vm_page_prot is safely read from and written to, without any
> > locks with READ_ONCE() and WRITE_ONCE(). But with introduction of D128 page
> > tables on arm64 platform, vm_page_prot grows to 128 bits which can't safely
> > be handled with READ_ONCE() and WRITE_ONCE().
> > 
> > Add read and write accessors for vm_page_prot like pgprot_[read|write]()
> > which any platform can override when required, although still defaulting as
> > READ_ONCE() and WRITE_ONCE(), thus preserving the functionality for others.
> > 
> > Cc: Andrew Morton <akpm at linux-foundation.org>
> > Cc: David Hildenbrand <david at kernel.org>
> > Cc: Lorenzo Stoakes <lorenzo.stoakes at oracle.com>
> > Cc: Mike Rapoport <rppt at kernel.org>
> > Cc: linux-mm at kvack.org
> > Cc: linux-kernel at vger.kernel.org
> > Acked-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
> > Signed-off-by: Anshuman Khandual <anshuman.khandual at arm.com>
> > ---
> >  include/linux/pgtable.h | 14 ++++++++++++++
> >  mm/huge_memory.c        |  4 ++--
> >  mm/memory.c             |  2 +-
> >  mm/migrate.c            |  2 +-
> >  mm/mmap.c               |  2 +-
> >  5 files changed, 19 insertions(+), 5 deletions(-)
> > 
> > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> > index e3c8ab96941c..0df57a5c19ef 100644
> > --- a/include/linux/pgtable.h
> > +++ b/include/linux/pgtable.h
> > @@ -524,6 +524,20 @@ static inline pgd_t pgdp_get(pgd_t *pgdp)
> >  }
> >  #endif
> >  
> > +#ifndef pgprot_read
> > +static inline pgprot_t pgprot_read(pgprot_t *prot)
> 
> Try passing "const pgprot_t *prot" instead.

OK - will change.

> 
> [...]
> 
> > diff --git a/mm/migrate.c b/mm/migrate.c
> > index 15b45832bcfa..579152cce502 100644
> > --- a/mm/migrate.c
> > +++ b/mm/migrate.c
> > @@ -387,7 +387,7 @@ static bool remove_migration_pte(struct folio *folio,
> >  
> >  		folio_get(folio);
> >  		new = folio_page(folio, idx);
> > -		pte = mk_pte(new, READ_ONCE(vma->vm_page_prot));
> > +		pte = mk_pte(new, pgprot_read(&vma->vm_page_prot));
> I do wonder whether a
> 
> ogprot_t vma_get_page_prot(const struct vm_area_struct *vma)
> 
> where we hide the pgprot access would be a good complement for vma_set_page_prot().

Could you please elaborate ?

AFAICS both these helpers vma_get_page_prot()/vma_set_page_prot() are already present.
Are you suggesting to change vma_get_page_prot() instead ?

> 
> Just a thought.
> 
> 
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index 4bf26b0f1e6e..729bc244b317 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -89,7 +89,7 @@ void vma_set_page_prot(struct vm_area_struct *vma)
> >  		vm_page_prot = vma_pgprot_modify(vm_page_prot, vma_flags);
> >  	}
> >  	/* remove_protection_ptes reads vma->vm_page_prot without mmap_lock */
> > -	WRITE_ONCE(vma->vm_page_prot, vm_page_prot);
> > +	pgprot_write(&vma->vm_page_prot, vm_page_prot);
> >  }
> >  
> >  /*
> 
> 
> -- 
> Cheers,
> 
> David



More information about the linux-arm-kernel mailing list