From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC2151F91E3 for ; Fri, 10 Jul 2026 22:46:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783723600; cv=none; b=GpDE03QvhK1z5EKmK896j9seiGGtkq+BTYykICFe/gg6l+AuxyB3aq3H7SUa1imWqf0y03IDq2GQUFTmLXn7G1dbJpWtSjzq8GENtkNcfWqVEyBgtmkpT1/8KKwsZgUlpn3NjaMxHJXsdERzNXh6GeSVbxF7EGm3pET5xbltLkY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783723600; c=relaxed/simple; bh=/yt2abCBvGExA1f4g2IRchPMhMU0r0hehBWpnRH1erA=; h=Date:To:From:Subject:Message-Id; b=RuPH5Klalut2CjpX0RU0w0Pc6pdNxmJR9WqSb7UFLRnfW4KacGiH65ZGB53H78IYlSbt77NPWAEXHG9FmBkAC53Vt79rMkGW3vEJO6TDi7kyvjYrwycpH/yME10S55pO2kMeklLkxwRpGwMggItmC5pDkZeob/Q9Cg649ZRQmQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=XnuuDuyO; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="XnuuDuyO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AF081F000E9; Fri, 10 Jul 2026 22:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1783723598; bh=nnDhhwAI1ZGuzLNi+QVbgfzb0+xMZPtd/80PgTD+lsc=; h=Date:To:From:Subject; b=XnuuDuyOk2BWqB4DdtPjlEDXkRQCfo/eiWitN/1DeH9nezCNTcUFUG3jZY9d/dS5j clmuR6Z7IY/+NrZKJqyAzcX9C6C6foPMMFUOVTJ0PgM4R6EhiIA2ZV5R6OYiNSx3d7 hrhq3lGIlbx4P1BjabW57ISpxigxYCERg8vNkkCs= Date: Fri, 10 Jul 2026 15:46:38 -0700 To: mm-commits@vger.kernel.org,ljs@kernel.org,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code.patch added to mm-new branch Message-Id: <20260710224638.9AF081F000E9@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm/vma: use vma_start_pgoff(), linear_page_index() in mm code has been added to the -mm mm-new branch. Its filename is mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Lorenzo Stoakes Subject: mm/vma: use vma_start_pgoff(), linear_page_index() in mm code Date: Fri, 10 Jul 2026 21:16:59 +0100 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 Reviewed-by: Gregory Price Reviewed-by: SJ Park Reviewed-by: Pedro Falcato Cc: Ackerley Tng Cc: David Hildenbrand (Arm) Cc: Kai Huang Cc: Marek Szyprowski Cc: Thomas Zimmermann Cc: Vlastimil Babka (SUSE) Signed-off-by: Andrew Morton --- include/linux/huge_mm.h | 1 + include/linux/hugetlb.h | 3 +-- include/linux/pagemap.h | 2 +- mm/damon/vaddr.c | 5 +++-- mm/debug.c | 2 +- mm/filemap.c | 7 ++++--- mm/huge_memory.c | 2 +- mm/hugetlb.c | 11 ++++------- mm/internal.h | 24 ++++++++++++++---------- mm/khugepaged.c | 3 ++- mm/madvise.c | 6 +++--- mm/mapping_dirty_helpers.c | 2 +- mm/memory.c | 25 +++++++++++++------------ mm/mempolicy.c | 13 +++++++------ mm/mremap.c | 12 ++++-------- mm/msync.c | 4 ++-- mm/nommu.c | 7 ++++--- mm/pagewalk.c | 2 +- mm/shmem.c | 9 +++++---- mm/userfaultfd.c | 4 ++-- mm/util.c | 4 ++-- mm/vma.c | 15 +++++++-------- mm/vma_exec.c | 4 ++-- mm/vma_init.c | 2 +- 24 files changed, 86 insertions(+), 83 deletions(-) --- a/include/linux/huge_mm.h~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/include/linux/huge_mm.h @@ -230,6 +230,7 @@ static inline bool thp_vma_suitable_orde /* Don't have to check pgoff for anonymous vma */ if (!vma_is_anonymous(vma)) { + /* vma_start_pgoff() in mm.h so not available. */ if (!IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, hpage_size >> PAGE_SHIFT)) return false; --- a/include/linux/hugetlb.h~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/include/linux/hugetlb.h @@ -801,8 +801,7 @@ static inline pgoff_t hugetlb_linear_pag { struct hstate *h = hstate_vma(vma); - return ((address - vma->vm_start) >> huge_page_shift(h)) + - (vma->vm_pgoff >> huge_page_order(h)); + return linear_page_index(vma, address) >> huge_page_order(h); } static inline bool order_is_gigantic(unsigned int order) --- a/include/linux/pagemap.h~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/include/linux/pagemap.h @@ -1097,7 +1097,7 @@ static inline pgoff_t linear_page_index( pgoff_t pgoff; pgoff = linear_page_delta(vma, address); - pgoff += vma->vm_pgoff; + pgoff += vma_start_pgoff(vma); return pgoff; } --- a/mm/damon/vaddr.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/damon/vaddr.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -623,8 +624,8 @@ static void damos_va_migrate_dests_add(s } order = folio_order(folio); - ilx = vma->vm_pgoff >> order; - ilx += (addr - vma->vm_start) >> (PAGE_SHIFT + order); + ilx = vma_start_pgoff(vma) >> order; + ilx += linear_page_delta(vma, addr) >> order; for (i = 0; i < dests->nr_dests; i++) weight_total += dests->weight_arr[i]; --- a/mm/debug.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/debug.c @@ -163,7 +163,7 @@ void dump_vma(const struct vm_area_struc "flags: %#lx(%pGv)\n", vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_mm, (unsigned long)pgprot_val(vma->vm_page_prot), - vma->anon_vma, vma->vm_ops, vma->vm_pgoff, + vma->anon_vma, vma->vm_ops, vma_start_pgoff(vma), vma->vm_file, vma->vm_private_data, #ifdef CONFIG_PER_VMA_LOCK refcount_read(&vma->vm_refcnt), --- a/mm/filemap.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/filemap.c @@ -3411,8 +3411,8 @@ static struct file *do_sync_mmap_readahe * of memory. */ struct vm_area_struct *vma = vmf->vma; - unsigned long start = vma->vm_pgoff; - unsigned long end = start + vma_pages(vma); + const unsigned long start = vma_start_pgoff(vma); + const unsigned long end = vma_end_pgoff(vma); unsigned long ra_end; ra->order = exec_folio_order(); @@ -3930,7 +3930,8 @@ vm_fault_t filemap_map_pages(struct vm_f goto out; } - addr = vma->vm_start + ((start_pgoff - vma->vm_pgoff) << PAGE_SHIFT); + addr = vma->vm_start + + ((start_pgoff - vma_start_pgoff(vma)) << PAGE_SHIFT); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, addr, &vmf->ptl); if (!vmf->pte) { folio_unlock(folio); --- a/mm/huge_memory.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/huge_memory.c @@ -180,7 +180,7 @@ unsigned long __thp_vma_allowable_orders */ if (!in_pf && shmem_file(vma->vm_file)) return orders & shmem_allowable_huge_orders(file_inode(vma->vm_file), - vma, vma->vm_pgoff, 0, + vma, vma_start_pgoff(vma), 0, forced_collapse); if (!vma_is_anonymous(vma)) { --- a/mm/hugetlb.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/hugetlb.c @@ -1012,8 +1012,7 @@ static long region_count(struct resv_map static pgoff_t vma_hugecache_offset(struct hstate *h, struct vm_area_struct *vma, unsigned long address) { - return ((address - vma->vm_start) >> huge_page_shift(h)) + - (vma->vm_pgoff >> huge_page_order(h)); + return linear_page_index(vma, address) >> huge_page_order(h); } /* @@ -5445,8 +5444,7 @@ static void unmap_ref_private(struct mm_ * from page cache lookup which is in HPAGE_SIZE units. */ address = address & huge_page_mask(h); - pgoff = ((address - vma->vm_start) >> PAGE_SHIFT) + - vma->vm_pgoff; + pgoff = linear_page_index(vma, address); mapping = vma->vm_file->f_mapping; /* @@ -6905,7 +6903,7 @@ static unsigned long page_table_shareabl struct vm_area_struct *vma, unsigned long addr, pgoff_t idx) { - unsigned long saddr = ((idx - svma->vm_pgoff) << PAGE_SHIFT) + + unsigned long saddr = ((idx - vma_start_pgoff(svma)) << PAGE_SHIFT) + svma->vm_start; unsigned long sbase = saddr & PUD_MASK; unsigned long s_end = sbase + PUD_SIZE; @@ -6990,8 +6988,7 @@ pte_t *huge_pmd_share(struct mm_struct * unsigned long addr, pud_t *pud) { struct address_space *mapping = vma->vm_file->f_mapping; - pgoff_t idx = ((addr - vma->vm_start) >> PAGE_SHIFT) + - vma->vm_pgoff; + const pgoff_t idx = linear_page_index(vma, addr); struct vm_area_struct *svma; unsigned long saddr; pte_t *spte = NULL; --- a/mm/internal.h~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/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 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_ 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; --- a/mm/khugepaged.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/khugepaged.c @@ -2150,7 +2150,8 @@ static void retract_page_tables(struct a spinlock_t *ptl; bool success = false; - addr = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); + addr = vma->vm_start + + ((pgoff - vma_start_pgoff(vma)) << PAGE_SHIFT); if (addr & ~HPAGE_PMD_MASK || vma->vm_end < addr + HPAGE_PMD_SIZE) continue; --- a/mm/madvise.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/madvise.c @@ -253,7 +253,7 @@ static void shmem_swapin_range(struct vm continue; addr = vma->vm_start + - ((xas.xa_index - vma->vm_pgoff) << PAGE_SHIFT); + ((xas.xa_index - vma_start_pgoff(vma)) << PAGE_SHIFT); xas_pause(&xas); rcu_read_unlock(); @@ -318,7 +318,7 @@ static long madvise_willneed(struct madv mark_mmap_lock_dropped(madv_behavior); get_file(file); offset = (loff_t)(start - vma->vm_start) - + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); + + ((loff_t)vma_start_pgoff(vma) << PAGE_SHIFT); mmap_read_unlock(mm); vfs_fadvise(file, offset, end - start, POSIX_FADV_WILLNEED); fput(file); @@ -1022,7 +1022,7 @@ static long madvise_remove(struct madvis return -EACCES; offset = (loff_t)(start - vma->vm_start) - + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); + + ((loff_t)vma_start_pgoff(vma) << PAGE_SHIFT); /* * Filesystem's fallocate may need to take i_rwsem. We need to --- a/mm/mapping_dirty_helpers.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/mapping_dirty_helpers.c @@ -95,7 +95,7 @@ static int clean_record_pte(pte_t *pte, if (pte_dirty(ptent)) { pgoff_t pgoff = ((addr - walk->vma->vm_start) >> PAGE_SHIFT) + - walk->vma->vm_pgoff - cwalk->bitmap_pgoff; + vma_start_pgoff(walk->vma) - cwalk->bitmap_pgoff; pte_t old_pte = ptep_modify_prot_start(walk->vma, addr, pte); ptent = pte_mkclean(old_pte); --- a/mm/memory.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/memory.c @@ -775,10 +775,10 @@ static inline struct page *__vm_normal_p if (!pfn_valid(pfn)) return NULL; } else { - unsigned long off = (addr - vma->vm_start) >> PAGE_SHIFT; + const pgoff_t index = linear_page_index(vma, addr); /* Only CoW'ed anon folios are "normal". */ - if (pfn == vma->vm_pgoff + off) + if (pfn == index) return NULL; if (!is_cow_mapping(vma->vm_flags)) return NULL; @@ -2719,7 +2719,7 @@ static int __vm_map_pages(struct vm_area int vm_map_pages(struct vm_area_struct *vma, struct page **pages, unsigned long num) { - return __vm_map_pages(vma, pages, num, vma->vm_pgoff); + return __vm_map_pages(vma, pages, num, vma_start_pgoff(vma)); } EXPORT_SYMBOL(vm_map_pages); @@ -3374,7 +3374,8 @@ int vm_iomap_memory(struct vm_area_struc unsigned long pfn; int err; - err = __simple_ioremap_prep(vm_len, vma->vm_pgoff, start, len, &pfn); + err = __simple_ioremap_prep(vm_len, vma_start_pgoff(vma), start, len, + &pfn); if (err) return err; @@ -4422,15 +4423,15 @@ static inline void unmap_mapping_range_t struct zap_details *details) { struct vm_area_struct *vma; - unsigned long start, size; struct mmu_gather tlb; mapping_rmap_tree_foreach(vma, mapping, first_index, last_index) { - const pgoff_t start_idx = max(first_index, vma->vm_pgoff); + const pgoff_t start_idx = max(first_index, vma_start_pgoff(vma)); const pgoff_t end_idx = min(last_index, vma_last_pgoff(vma)) + 1; - - start = vma->vm_start + ((start_idx - vma->vm_pgoff) << PAGE_SHIFT); - size = (end_idx - start_idx) << PAGE_SHIFT; + const pgoff_t offset = start_idx - vma_start_pgoff(vma); + const unsigned long offset_bytes = offset << PAGE_SHIFT; + const unsigned long start = vma->vm_start + offset_bytes; + const unsigned long size = (end_idx - start_idx) << PAGE_SHIFT; tlb_gather_mmu(&tlb, vma->vm_mm); zap_vma_range_batched(&tlb, vma, start, size, details); @@ -5768,7 +5769,7 @@ fallback: } else if (nr_pages > 1) { pgoff_t idx = folio_page_idx(folio, page); /* The page offset of vmf->address within the VMA. */ - pgoff_t vma_off = vmf->pgoff - vmf->vma->vm_pgoff; + pgoff_t vma_off = vmf->pgoff - vma_start_pgoff(vmf->vma); /* The index of the entry in the pagetable for fault page. */ pgoff_t pte_off = pte_index(vmf->address); @@ -5880,7 +5881,7 @@ static vm_fault_t do_fault_around(struct pgoff_t nr_pages = READ_ONCE(fault_around_pages); pgoff_t pte_off = pte_index(vmf->address); /* The page offset of vmf->address within the VMA. */ - pgoff_t vma_off = vmf->pgoff - vmf->vma->vm_pgoff; + pgoff_t vma_off = vmf->pgoff - vma_start_pgoff(vmf->vma); pgoff_t from_pte, to_pte; vm_fault_t ret; @@ -7408,7 +7409,7 @@ void print_vma_addr(char *prefix, unsign if (vma && vma->vm_file) { struct file *f = vma->vm_file; ip -= vma->vm_start; - ip += vma->vm_pgoff << PAGE_SHIFT; + ip += vma_start_pgoff(vma) << PAGE_SHIFT; printk("%s%pD[%lx,%lx+%lx]", prefix, f, ip, vma->vm_start, vma->vm_end - vma->vm_start); --- a/mm/mempolicy.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/mempolicy.c @@ -2049,8 +2049,8 @@ struct mempolicy *get_vma_policy(struct pol = get_task_policy(current); if (pol->mode == MPOL_INTERLEAVE || pol->mode == MPOL_WEIGHTED_INTERLEAVE) { - *ilx += vma->vm_pgoff >> order; - *ilx += (addr - vma->vm_start) >> (PAGE_SHIFT + order); + *ilx += vma_start_pgoff(vma) >> order; + *ilx += linear_page_delta(vma, addr) >> order; } return pol; } @@ -3244,16 +3244,17 @@ EXPORT_SYMBOL_FOR_MODULES(mpol_shared_po int mpol_set_shared_policy(struct shared_policy *sp, struct vm_area_struct *vma, struct mempolicy *pol) { - int err; + const pgoff_t pgoff = vma_start_pgoff(vma); + const pgoff_t pgoff_end = vma_end_pgoff(vma); struct sp_node *new = NULL; - unsigned long sz = vma_pages(vma); + int err; if (pol) { - new = sp_alloc(vma->vm_pgoff, vma->vm_pgoff + sz, pol); + new = sp_alloc(pgoff, pgoff_end, pol); if (!new) return -ENOMEM; } - err = shared_policy_replace(sp, vma->vm_pgoff, vma->vm_pgoff + sz, new); + err = shared_policy_replace(sp, pgoff, pgoff_end, new); if (err && new) sp_free(new); return err; --- a/mm/mremap.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/mremap.c @@ -957,8 +957,7 @@ static unsigned long vrm_set_new_addr(st struct vm_area_struct *vma = vrm->vma; unsigned long map_flags = 0; /* Page Offset _into_ the VMA. */ - pgoff_t internal_pgoff = (vrm->addr - vma->vm_start) >> PAGE_SHIFT; - pgoff_t pgoff = vma->vm_pgoff + internal_pgoff; + const pgoff_t pgoff = linear_page_index(vma, vrm->addr); unsigned long new_addr = vrm_implies_new_addr(vrm) ? vrm->new_addr : 0; unsigned long res; @@ -1264,12 +1263,10 @@ static void unmap_source_vma(struct vma_ static int copy_vma_and_data(struct vma_remap_struct *vrm, struct vm_area_struct **new_vma_ptr) { - unsigned long internal_offset = vrm->addr - vrm->vma->vm_start; - unsigned long internal_pgoff = internal_offset >> PAGE_SHIFT; - unsigned long new_pgoff = vrm->vma->vm_pgoff + internal_pgoff; - unsigned long moved_len; + const unsigned long new_pgoff = linear_page_index(vrm->vma, vrm->addr); struct vm_area_struct *vma = vrm->vma; struct vm_area_struct *new_vma; + unsigned long moved_len; int err = 0; PAGETABLE_MOVE(pmc, NULL, NULL, vrm->addr, vrm->new_addr, vrm->old_len); @@ -1811,8 +1808,7 @@ static int check_prep_vma(struct vma_rem vrm->populate_expand = true; /* Need to be careful about a growing mapping */ - pgoff = (addr - vma->vm_start) >> PAGE_SHIFT; - pgoff += vma->vm_pgoff; + pgoff = linear_page_index(vma, addr); if (pgoff + (new_len >> PAGE_SHIFT) < pgoff) return -EINVAL; --- a/mm/msync.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/msync.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -85,8 +86,7 @@ SYSCALL_DEFINE3(msync, unsigned long, st goto out_unlock; } file = vma->vm_file; - fstart = (start - vma->vm_start) + - ((loff_t)vma->vm_pgoff << PAGE_SHIFT); + fstart = (loff_t)linear_page_index(vma, start) << PAGE_SHIFT; fend = fstart + (min(end, vma->vm_end) - start) - 1; start = vma->vm_end; if ((flags & MS_SYNC) && file && --- a/mm/nommu.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/nommu.c @@ -975,7 +975,7 @@ static int do_mmap_private(struct vm_are /* read the contents of a file into the copy */ loff_t fpos; - fpos = vma->vm_pgoff; + fpos = vma_start_pgoff(vma); fpos <<= PAGE_SHIFT; ret = kernel_read(vma->vm_file, base, len, &fpos); @@ -1378,7 +1378,8 @@ static int split_vma(struct vma_iterator delete_nommu_region(vma->vm_region); if (new_below) { vma->vm_region->vm_start = vma->vm_start = addr; - vma->vm_region->vm_pgoff = vma->vm_pgoff += npages; + vma->vm_pgoff += npages; + vma->vm_region->vm_pgoff = vma_start_pgoff(vma); } else { vma->vm_region->vm_end = vma->vm_end = addr; vma->vm_region->vm_top = addr; @@ -1630,7 +1631,7 @@ int vm_iomap_memory(struct vm_area_struc unsigned long pfn = start >> PAGE_SHIFT; unsigned long vm_len = vma->vm_end - vma->vm_start; - pfn += vma->vm_pgoff; + pfn += vma_start_pgoff(vma); return io_remap_pfn_range(vma, vma->vm_start, pfn, vm_len, vma->vm_page_prot); } EXPORT_SYMBOL(vm_iomap_memory); --- a/mm/pagewalk.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/pagewalk.c @@ -815,7 +815,7 @@ int walk_page_mapping(struct address_spa mapping_rmap_tree_foreach(vma, mapping, first_index, first_index + nr - 1) { /* Clip to the vma */ - vba = vma->vm_pgoff; + vba = vma_start_pgoff(vma); vea = vba + vma_pages(vma); cba = first_index; cba = max(cba, vba); --- a/mm/shmem.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/shmem.c @@ -1032,6 +1032,8 @@ unsigned long shmem_swap_usage(struct vm struct inode *inode = file_inode(vma->vm_file); struct shmem_inode_info *info = SHMEM_I(inode); struct address_space *mapping = inode->i_mapping; + const pgoff_t pgoff = vma_start_pgoff(vma); + const pgoff_t pgoff_end = vma_end_pgoff(vma); unsigned long swapped; /* Be careful as we don't hold info->lock */ @@ -1045,12 +1047,11 @@ unsigned long shmem_swap_usage(struct vm if (!swapped) return 0; - if (!vma->vm_pgoff && vma->vm_end - vma->vm_start >= inode->i_size) + if (!pgoff && vma->vm_end - vma->vm_start >= inode->i_size) return swapped << PAGE_SHIFT; /* Here comes the more involved part */ - return shmem_partial_swap_usage(mapping, vma->vm_pgoff, - vma->vm_pgoff + vma_pages(vma)); + return shmem_partial_swap_usage(mapping, pgoff, pgoff_end); } /* @@ -2840,7 +2841,7 @@ static struct mempolicy *shmem_get_polic * by page order, as in shmem_get_pgoff_policy() and get_vma_policy()). */ *ilx = inode->i_ino; - index = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; + index = linear_page_index(vma, addr); return mpol_shared_policy_lookup(&SHMEM_I(inode)->policy, index); } --- a/mm/userfaultfd.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/userfaultfd.c @@ -481,7 +481,7 @@ static void mfill_retry_state_save(struc { s->flags = vma_flags_and_mask(&vma->flags, MFILL_RETRY_STATE_VMA_FLAGS); s->ops = vma_uffd_ops(vma); - s->pgoff = vma->vm_pgoff; + s->pgoff = vma_start_pgoff(vma); if (vma->vm_file) s->file = get_file(vma->vm_file); @@ -507,7 +507,7 @@ static bool mfill_retry_state_changed(st /* VMA was file backed, but file, inode or offset has changed */ if (!vma->vm_file || vma->vm_file->f_inode != state->file->f_inode || - state->file != vma->vm_file || vma->vm_pgoff != state->pgoff) + state->file != vma->vm_file || vma_start_pgoff(vma) != state->pgoff) return true; return false; --- a/mm/util.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/util.c @@ -1188,7 +1188,7 @@ void compat_set_desc_from_vma(struct vm_ desc->start = vma->vm_start; desc->end = vma->vm_end; - desc->pgoff = vma->vm_pgoff; + desc->pgoff = vma_start_pgoff(vma); desc->vm_file = vma->vm_file; desc->vma_flags = vma->flags; desc->page_prot = vma->vm_page_prot; @@ -1379,7 +1379,7 @@ static int call_vma_mapped(struct vm_are if (!vm_ops || !vm_ops->mapped) return 0; - err = vm_ops->mapped(vma->vm_start, vma->vm_end, vma->vm_pgoff, + err = vm_ops->mapped(vma->vm_start, vma->vm_end, vma_start_pgoff(vma), vma->vm_file, &vm_private_data); if (err) return err; --- a/mm/vma.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/vma.c @@ -967,10 +967,9 @@ static __must_check struct vm_area_struc * prev middle next * extend delete delete */ - vmg->start = prev->vm_start; vmg->end = next->vm_end; - vmg->pgoff = prev->vm_pgoff; + vmg->pgoff = vma_start_pgoff(prev); /* * We already ensured anon_vma compatibility above, so now it's @@ -987,9 +986,8 @@ static __must_check struct vm_area_struc * prev middle * extend shrink/delete */ - vmg->start = prev->vm_start; - vmg->pgoff = prev->vm_pgoff; + vmg->pgoff = vma_start_pgoff(prev); if (!vmg->__remove_middle) vmg->__adjust_middle_start = true; @@ -1011,13 +1009,13 @@ static __must_check struct vm_area_struc if (vmg->__remove_middle) { vmg->end = next->vm_end; - vmg->pgoff = next->vm_pgoff - pglen; + vmg->pgoff = vma_start_pgoff(next) - pglen; } else { /* We shrink middle and expand next. */ vmg->__adjust_next_start = true; vmg->start = middle->vm_start; vmg->end = start; - vmg->pgoff = middle->vm_pgoff; + vmg->pgoff = vma_start_pgoff(middle); } err = dup_anon_vma(next, middle, &anon_dup); @@ -1126,7 +1124,7 @@ struct vm_area_struct *vma_merge_new_ran if (can_merge_left) { vmg->start = prev->vm_start; vmg->target = prev; - vmg->pgoff = prev->vm_pgoff; + vmg->pgoff = vma_start_pgoff(prev); /* * If this merge would result in removal of the next VMA but we @@ -1957,7 +1955,8 @@ struct vm_area_struct *copy_vma(struct v VM_BUG_ON_VMA(faulted_in_anon_vma, new_vma); *vmap = vma = new_vma; } - *need_rmap_locks = (new_vma->vm_pgoff <= vma->vm_pgoff); + *need_rmap_locks = + (vma_start_pgoff(new_vma) <= vma_start_pgoff(vma)); } else { new_vma = vm_area_dup(vma); if (!new_vma) --- a/mm/vma_exec.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/vma_exec.c @@ -37,7 +37,7 @@ int relocate_vma_down(struct vm_area_str unsigned long new_end = old_end - shift; VMA_ITERATOR(vmi, mm, new_start); VMG_STATE(vmg, mm, &vmi, new_start, old_end, EMPTY_VMA_FLAGS, - vma->vm_pgoff); + vma_start_pgoff(vma)); struct vm_area_struct *next; struct mmu_gather tlb; PAGETABLE_MOVE(pmc, vma, vma, old_start, new_start, length); @@ -89,7 +89,7 @@ int relocate_vma_down(struct vm_area_str vma_prev(&vmi); /* Shrink the vma to just the new range */ - return vma_shrink(&vmi, vma, new_start, new_end, vma->vm_pgoff); + return vma_shrink(&vmi, vma, new_start, new_end, vma_start_pgoff(vma)); } /* --- a/mm/vma_init.c~mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code +++ a/mm/vma_init.c @@ -46,7 +46,7 @@ static void vm_area_init_from(const stru dest->vm_start = src->vm_start; dest->vm_end = src->vm_end; dest->anon_vma = src->anon_vma; - dest->vm_pgoff = src->vm_pgoff; + dest->vm_pgoff = vma_start_pgoff(src); dest->vm_file = src->vm_file; dest->vm_private_data = src->vm_private_data; vm_flags_init(dest, src->vm_flags); _ Patches currently in -mm which might be from ljs@kernel.org are mm-move-alloc-tag-to-mm.patch mm-ptdump-always-stabilise-against-page-table-freeing-using-init_mm.patch mm-vmalloc-acquire-init_mm-read-lock-on-huge-vmap-promotion.patch revert-arm64-enable-vmalloc-huge-with-ptdump.patch mm-move-vma_start_pgoff-into-mmh-and-clean-up.patch mm-add-kdoc-comments-for-vma_start-last_pgoff.patch tools-testing-vma-use-vma_start_pgoff-in-merge-tests.patch mm-introduce-and-use-vma_end_pgoff.patch mm-rmap-update-mm-interval_treec-comments.patch mm-rmap-parameterise-vma_interval_tree_-by-address_space.patch mm-rmap-elide-unnecessary-static-inlines-in-interval_treec.patch mm-rmap-rename-vma_interval_tree_-to-mapping_rmap_tree_.patch mm-rmap-parameterise-anon_vma_interval_tree_-by-anon_vma.patch mm-rmap-rename-anon_vma_interval_tree_-params-and-use-pgoff_t.patch mm-rmap-rename-anon_vma_interval_tree_-to-anon_rmap_tree_.patch maintainers-move-mm-interval_treec-to-rmap-section.patch mm-vma-introduce-and-use-vmg_pages-vmg__pgoff.patch mm-vma-clean-up-anon_vma_compatible.patch mm-vma-refactor-vmg_adjust_set_range-for-clarity.patch mm-vma-minor-cleanup-of-expand_.patch mm-introduce-and-use-linear_page_delta.patch mm-vma-use-vma_start_pgoff-linear_page_index-in-mm-code.patch mm-prefer-vma__pgoff-to-vma-vm_pgoff-in-kernel.patch mm-vma-remove-duplicative-vma_pgoff_offset-helper.patch mm-use-linear_page_-consistently.patch mm-vma-introduce-vma_assert_can_modify.patch mm-vma-add-and-use-vma__pgoff.patch mm-vma-move-__install_special_mapping-to-vmac.patch mm-vma-make-vma_set_range-static-drop-insert_vm_struct-decl.patch mm-vma-update-vma_shrink-to-not-pass-start-pgoff-parameters.patch mm-vma-update-vmg_adjust_set_range-to-offset-pgoff-instead.patch mm-vma-slightly-rework-the-anonymous-check-in-__mmap_new_vma.patch mm-vma-introduce-and-use-vma_set_pgoff.patch mm-vma-correct-incorrect-vmah-inclusion.patch mm-vma-use-guard-clauses-in-can_vma_merge_.patch tools-testing-vma-default-vma-mm-flag-bits-to-64-bit.patch tools-testing-vma-output-compared-expression-on-assert_.patch