mm: introduce and use vma_end_pgoff()

We already have vma_last_pgoff() which retrieves the last page offset
within a VMA.

However, code often wishes to span a page offset range, which requires the
exclusive end of this range.

So provide this in vma_end_pgoff() and update vma_last_pgoff() to use this
function.

Also update the VMA userland tests to reflect the change.

No functional change intended.

Link: https://lore.kernel.org/20260710-b4-pre-scalable-cow-v2-4-2a5aa403d977@kernel.org
Signed-off-by: Lorenzo Stoakes <ljs@kernel.org>
Reviewed-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Ackerley Tng <ackerleytng@google.com>
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: Kai Huang <kai.huang@intel.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: SJ Park <sj@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Liam R. Howlett (Oracle) <liam@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Lorenzo Stoakes 2026-07-10 21:16:45 +01:00 committed by Andrew Morton
parent 3542bc07f4
commit 1219731c49
2 changed files with 23 additions and 1 deletions

View File

@ -4335,6 +4335,23 @@ static inline pgoff_t vma_start_pgoff(const struct vm_area_struct *vma)
return vma->vm_pgoff;
}
/**
* vma_end_pgoff() - Get the page offset of the exclusive end of @vma
* @vma: The VMA whose end page offset is required.
*
* This returns the exclusive end page offset of @vma, which is useful for
* expressing page offset ranges.
*
* See the description of vma_start_pgoff() for a description of VMA page
* offsets.
*
* Returns: The exclusive end page offset of @vma.
*/
static inline pgoff_t vma_end_pgoff(const struct vm_area_struct *vma)
{
return vma_start_pgoff(vma) + vma_pages(vma);
}
/**
* vma_last_pgoff() - Get the page offset of the last page in @vma
* @vma: The VMA whose last page offset is required.
@ -4348,7 +4365,7 @@ static inline pgoff_t vma_start_pgoff(const struct vm_area_struct *vma)
*/
static inline pgoff_t vma_last_pgoff(const struct vm_area_struct *vma)
{
return vma_start_pgoff(vma) + vma_pages(vma) - 1;
return vma_end_pgoff(vma) - 1;
}
static inline unsigned long vma_desc_size(const struct vm_area_desc *desc)

View File

@ -1306,6 +1306,11 @@ static inline pgoff_t vma_start_pgoff(const struct vm_area_struct *vma)
return vma->vm_pgoff;
}
static inline pgoff_t vma_end_pgoff(const struct vm_area_struct *vma)
{
return vma_start_pgoff(vma) + vma_pages(vma);
}
static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc)
{
return file->f_op->mmap_prepare(desc);