Re: [PATCH V2 01/14] mm: Add read-write accessors for vm_page_prot
From: David Hildenbrand (Arm)
Date: Wed Sep 16 2026 - 09:30:25 EST
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@xxxxxxxxxxxxxxxxxxxx>
> Cc: David Hildenbrand <david@xxxxxxxxxx>
> Cc: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
> Cc: Mike Rapoport <rppt@xxxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Acked-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
> ---
> 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.
[...]
> 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().
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