summaryrefslogtreecommitdiff
path: root/mm/internal.h
diff options
context:
space:
mode:
authorLorenzo Stoakes <ljs@kernel.org>2026-07-10 21:16:59 +0100
committerAndrew Morton <akpm@linux-foundation.org>2026-08-04 19:19:00 -0700
commit5872168de5d5c1f69a2efcf80e331c32aa08ec9a (patch)
tree69b6d34c05bfe47857acda86eea6d5a3a2ff9057 /mm/internal.h
parent1268e1572ba545b75e11fbc33380f85a5d1ec1db (diff)
mm/vma: use vma_start_pgoff(), linear_page_index() in mm code
There are many instances in which linear_page_index() (as well as linear_page_delta()) is open-coded, which is confusing and inconsistent. Additionally, vma->vm_pgoff doesn't necessarily make it clear that this is the page offset of the start of the VMA range. Doing so also aids greppability. So use vma_start_pgoff() in favour of directly accessing vma->vm_pgoff, and linear_page_index() where we can. This also lays the ground for future changes which will add an anonymous page offset in order to be able to index MAP_PRIVATE-file backed anon folios in terms of their virtual page offset. No functional change intended. Link: https://lore.kernel.org/20260710-b4-pre-scalable-cow-v2-18-2a5aa403d977@kernel.org Signed-off-by: Lorenzo Stoakes <ljs@kernel.org> Reviewed-by: Gregory Price <gourry@gourry.net> Reviewed-by: SJ Park <sj@kernel.org> Reviewed-by: Pedro Falcato <pfalcato@suse.de> Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org> 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: Thomas Zimmermann <tzimmermann@suse.de> Cc: Liam R. Howlett (Oracle) <liam@infradead.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/internal.h')
-rw-r--r--mm/internal.h24
1 files changed, 14 insertions, 10 deletions
diff --git a/mm/internal.h b/mm/internal.h
index e5dcab69eb4f..f950e88fdb52 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -924,26 +924,28 @@ static inline bool
folio_within_range(struct folio *folio, struct vm_area_struct *vma,
unsigned long start, unsigned long end)
{
- pgoff_t pgoff, addr;
- unsigned long vma_pglen = vma_pages(vma);
+ const unsigned long vma_pglen = vma_pages(vma);
+ pgoff_t pgoff_folio, pgoff_vma_start;
+ unsigned long addr;
VM_WARN_ON_FOLIO(folio_test_ksm(folio), folio);
if (start > end)
return false;
+ pgoff_folio = folio_pgoff(folio);
+ pgoff_vma_start = vma_start_pgoff(vma);
+
if (start < vma->vm_start)
start = vma->vm_start;
if (end > vma->vm_end)
end = vma->vm_end;
- pgoff = folio_pgoff(folio);
-
/* if folio start address is not in vma range */
- if (!in_range(pgoff, vma->vm_pgoff, vma_pglen))
+ if (!in_range(pgoff_folio, pgoff_vma_start, vma_pglen))
return false;
- addr = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
+ addr = vma->vm_start + ((pgoff_folio - pgoff_vma_start) << PAGE_SHIFT);
return !(addr < start || end - addr < folio_size(folio));
}
@@ -1015,15 +1017,16 @@ extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
static inline unsigned long vma_address(const struct vm_area_struct *vma,
pgoff_t pgoff, unsigned long nr_pages)
{
+ const pgoff_t pgoff_start = vma_start_pgoff(vma);
unsigned long address;
- if (pgoff >= vma->vm_pgoff) {
+ if (pgoff >= pgoff_start) {
address = vma->vm_start +
- ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
+ ((pgoff - pgoff_start) << PAGE_SHIFT);
/* Check for address beyond vma (or wrapped through 0?) */
if (address < vma->vm_start || address >= vma->vm_end)
address = -EFAULT;
- } else if (pgoff + nr_pages - 1 >= vma->vm_pgoff) {
+ } else if (pgoff + nr_pages - 1 >= pgoff_start) {
/* Test above avoids possibility of wrap to 0 on 32-bit */
address = vma->vm_start;
} else {
@@ -1047,7 +1050,8 @@ static inline unsigned long vma_address_end(struct page_vma_mapped_walk *pvmw)
return pvmw->address + PAGE_SIZE;
pgoff = pvmw->pgoff + pvmw->nr_pages;
- address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
+ address = vma->vm_start +
+ ((pgoff - vma_start_pgoff(vma)) << PAGE_SHIFT);
/* Check for address beyond vma (or wrapped through 0?) */
if (address < vma->vm_start || address > vma->vm_end)
address = vma->vm_end;