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 C007F44998C; Fri, 10 Jul 2026 20:17:32 +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=1783714654; cv=none; b=PUHwIgyiNJ9m9Gx0cawUtN7DugS5iy/HhQpywnTBhupllAAO3pO1I7qJx34mW3EVRQbDmmp9GEaXNo0A/oL63fVuMJiQpY5qASG3OinorrR+RsNfg8raTehToqyUv1KmYMT5fUY+uA/04beBzE2xHnRfbXl7cFP9PoFyBA1F0Sw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783714654; c=relaxed/simple; bh=C4Yu71lac8pIy3vdGuBGIphs0YWMA1+aDi3eZhDjMUE=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=rA3WitmK+S9j9MGQBxvxJUVB4PEe2oUOhRjEouIrGCqWlLdW9zAbY/I5Ttld83kpErwlNQcC7H7WFYh9rzNh18DvZWLy/B57R6gONRzbZvXmm2qv8JP/ahkrLhWQ+/z3C8O6SeWG73GNvx0jT2O7y3XGmhKPVNO//xVpg6zruKE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NWDb4DQ7; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NWDb4DQ7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A3C61F000E9; Fri, 10 Jul 2026 20:17:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783714652; bh=JQW6B9yq7rR/bwTqnS+r6OlWEUSb89pRH27/Ug8BeOA=; h=From:Subject:Date:To:Cc; b=NWDb4DQ7MUeqgbRNqZUG7DgijSzbV62Fy1N9G8AUIWmqoFkWkyON/u0JGsQA6RGjE DAv/3eHtjQ9eNnO8S1+kjMzw2Xjd8DO/bkHNd8Lo57BOpOtPnRi3Y9gtg116qG/JUG AlUXR4P5IcAASHCG2tr0N4tZ1xgE6r8I4/VXRO+fnTBvj9tnCj7W/WVvsbHyoNCMYa KsutgjQ+wLupOjdkccJlxWzHu+dn39dkLU6XNEXXY8uUnf5bRPcP2a1AXJcM3PRL3y aW0ObkfHc/TGiZw/HW2cRlPATx2khiqfRhAlfGNWmcYwHzSAIU339YX9gaXhm9IYJo G+I52oYLhc95w== From: Lorenzo Stoakes Subject: [PATCH v2 00/33] mm: make VMA page offset handling more consistent Date: Fri, 10 Jul 2026 21:16:41 +0100 Message-Id: <20260710-b4-pre-scalable-cow-v2-0-2a5aa403d977@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAClTUWoC/yWNQQ6CMBBFr0JmbZu2gKgr72FYQBmh2LRmBlFDu LsFly95//0FGMkhwyVbgHB27GJIYA4Z2KEJPQrXJQajzFFVWom2EE9CwbbxTetR2PgWpsjVWem yQywgLZNwd5+9eqv/zK92RDttqc0YHE+RvvvtrDcPbJyRpK5OpspLrZXs3ST9yNcHUkAvI/VQr +v6A3HXvTCzAAAA X-Change-ID: 20260710-b4-pre-scalable-cow-24309015dee4 To: Andrew Morton , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Rik van Riel , Harry Yoo , Jann Horn , Lance Yang , Pedro Falcato , Russell King , Dinh Nguyen , Simon Schuster , "James E.J. Bottomley" , Helge Deller , Alexander Viro , Christian Brauner , Jan Kara , Dan Williams , Matthew Wilcox , Muchun Song , Oscar Salvador , Masami Hiramatsu , Oleg Nesterov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Miaohe Lin , Naoya Horiguchi , Xu Xin , Chengming Zhou , SJ Park , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hugh Dickins , Peter Xu , Kees Cook , Marek Szyprowski , Robin Murphy , Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Steven Rostedt , Mathieu Desnoyers , Jarkko Sakkinen , Dave Hansen , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Ian Abbott , H Hartley Sweeten , Lucas Stach , Christian Gmeiner , David Airlie , Simona Vetter , Patrik Jakobsson , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Clark , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , Tomi Valkeinen , Thierry Reding , Mikko Perttunen , Jonathan Hunter , Christian Koenig , Huang Rui , Matthew Auld , Jason Gunthorpe , Yishai Hadas , Shameer Kolothum , Kevin Tian , Ankit Agrawal , Alex Williamson , Paolo Bonzini , Shakeel Butt , Usama Arif Cc: Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-parisc@vger.kernel.org, linux-fsdevel@vger.kernel.org, nvdimm@lists.linux.dev, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, damon@lists.linux.dev, iommu@lists.linux.dev, kasan-dev@googlegroups.com, linux-sgx@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, linux-tegra@vger.kernel.org, kvm@vger.kernel.org, Russell King , Ackerley Tng , Kai Huang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=15609; i=ljs@kernel.org; h=from:subject:message-id; bh=C4Yu71lac8pIy3vdGuBGIphs0YWMA1+aDi3eZhDjMUE=; b=owGbwMvMwCV2fu7ZrsZH9SKMp9WSGLICg80tWR4+9zuUYB0pFfzLvnj1kgvesn57DAzNOTPrk 0OOXpncUcrCIMbFICumyPL8i/j+IJGweZ0X/N1g5rAygQxh4OIUgIn8vMzwz8KS18Nb49yDM1Hr O6fonH4i8/hpm8b86w/Fri4TD3v8bBfDH561m94eXr1k9uwtrU41fT1yb2w3ynduXn5tyQZHucT 73GwA X-Developer-Key: i=ljs@kernel.org; a=openpgp; fpr=E7F417BF5214569E89D04F46CF9DCD8A81E27F14 This series performs a series of cleanups and improvements around how the vma->vm_pgoff field is used. Folios belonging to file-backed mappings are simply indexed by the page offset within the file they map (excepting pfnmap and driver mappings which sometimes do things different). However, anonymous folios belonging to pure anonymous mappings are indexed by their "virtual" page offset, which is equal to addr >> PAGE_SHIFT at the time at which the VMA was first faulted in. The page offset of a VMA is stored in vma->vm_pgoff and indicates the page offset of the start of the VMA range, whether it be file-backed or anonymous. The work here both cleans up how we reference this field, as well as laying the foundations for a future series which addresses the inconsistency of CoW'd folios in MAP_PRIVATE-file backed mappings, which are indexed as if they were file-backed but behave as if they were anonymous. This future series will make it such that all anonymous folios are indexed by virtual page offset whether belonging to VMAs who satisfy vma_is_anonymous() or MAP_PRIVATE-mapped file-backed mappings. This series: * Exposes vma_start_pgoff() and updates the kernel to use it consistently. * Adds and uses the useful vma_end_pgoff() helper. * Parameterises the file-backed mapping helpers vma_interval_tree_*() by address_space rather than rb_root_cached. * Renames: the misleadingly-named vma_interval_tree_*() helpers to mapping_rmap_tree_*() to be consistent with the renamed anon_rmap_tree_*(). * Parameterises anon_rmap_tree_*() by anon_vma. * Moves mm/interval_tree.c to the rmap section. * Adds vmg_*() helpers for page offset. * Clarifies the confusing vmg_adjust_set_range() function. * Introduces linear_page_delta() to provide relative pgoff within a VMA. * Replaces open-coded versions of linear_page_delta() and linear_page_index() with invocations of these functions. * Introduces and uses vma_assert_can_modify() to account for whether a VMA can be modified (detached or write locked). * Adds and uses vma_[add,sub]_pgoff() to adjust VMA page offset. * Moves __install_special_mapping() to vma.c. * Makes vma_set_range() static and internal to vma.c. * Introduces and makes use of vma_set_pgoff(). * Fixes incorrect vma.h header inclusion. * Defaults VMA userland tests to 64-bit vma flags size. * Updates VMA userland tests to give better output on failure. * Various smaller cleanups. * Updated the vma_set_pgoff() assert to account for MAP_PRIVATE /dev/zero correctly. Signed-off-by: Lorenzo Stoakes --- v2: * Rebased on mm-unstable. * Updated tags (thanks to everyone and b4 trailers -F -u! ;) * Updated 1/30 to include the vma_start_pgoff() helper in VMA userland tests, which was previously causing a bisection hazard on the VMA userland tests. * Updated 2/30 to reference the pfnmap vma->vm_pgoff PFN abomination as per David. * Updated 4/30 to include vma_end_pgoff() helper in VMA userland tests at the appropriate point. * Updated 8/30 from mapping_interval_tree_*() to mapping_rmap_tree_*() and add commit to rename anon_vma_interval-tree_*() to anon_rmap_tree_*() as per Pedro. * Fixed issue in 8/30 where the internal helpers were still called __vma_interval_tree_*() rather than __mapping_rmap_tree_*(). * Updated 9/30 to separate out the rename and change of parameter type for clarity as per Gregory. * Updated 17/30 to put perf_mmap_aux() variables in reverse Christmas tree order as per Pedro. * Updated 19/30 to remove incorrectly placed vma_start_pgoff() invocation as per Thomas/Gregory. * Updated 20/30, 21/30 to put the vma_assert_can_modify() VMA userland test stub in the right place as per Pedro. * Confined the vma_set_pgoff() assert to CONFIG_MMU, as the ever helpful nommu of course violates all assumptions in this regard. * Fixed issue in improved ASSERT_[TRUE, FALSE, EQ, NE] test runners with re-evaluation of input expressions. * Updated the vma_start_pgoff() comment further to discuss the MAP_PRIVATE /dev/zero edge case. * Update the vma_set_pgoff() assert to handle the mmap_region() newly established file mapping case. * Updated the linear_page_index() comment to explicitly defer to vma_start_pgoff() to avoid duplicate information and future bitrot. * Updated vma_shrink() to no longer accept the useless start parameter, as it is invoked from relocate_vma_down() only, which has already expanded the VMA to cover the range [new_start, old_end) thus always shrinks the tail. * Moved sanity checks from vma_set_pgoff() to new helper assert_sane_pgoff() and documented it clearly. * Fixed issue with nascent file-backed VMAs hitting vma_set_pgoff() assert by checking for vma_is_anonymous(). * Moved vma_set_anonymous() earlier so vma_set_pgoff() works with nascent anonymous VMAs. * Updated the VMA userland tests so CONFIG_MMU, CONFIG_PER_VMA_LOCK work with IS_ENABLED(). v1: https://patch.msgid.link/cover.1782735110.git.ljs@kernel.org To: Andrew Morton To: David Hildenbrand To: "Liam R. Howlett" To: Vlastimil Babka To: Mike Rapoport To: Suren Baghdasaryan To: Michal Hocko To: Rik van Riel To: Harry Yoo To: Jann Horn To: Lance Yang To: Pedro Falcato To: Russell King To: Dinh Nguyen To: Simon Schuster To: "James E.J. Bottomley" To: Helge Deller To: Alexander Viro To: Christian Brauner To: Jan Kara To: Dan Williams To: Matthew Wilcox To: Muchun Song To: Oscar Salvador To: Masami Hiramatsu To: Oleg Nesterov To: Peter Zijlstra To: Ingo Molnar To: Arnaldo Carvalho de Melo To: Namhyung Kim To: Mark Rutland To: Alexander Shishkin To: Jiri Olsa To: Ian Rogers To: Adrian Hunter To: James Clark To: Zi Yan To: Baolin Wang To: Nico Pache To: Ryan Roberts To: Dev Jain To: Barry Song To: Miaohe Lin To: Naoya Horiguchi To: Xu Xin To: Chengming Zhou To: SJ Park To: Matthew Brost To: Joshua Hahn To: Rakie Kim To: Byungchul Park To: Gregory Price To: Ying Huang To: Alistair Popple To: Hugh Dickins To: Peter Xu To: Kees Cook To: Marek Szyprowski To: Robin Murphy To: Andrey Konovalov To: Alexander Potapenko To: Dmitry Vyukov To: Steven Rostedt To: Mathieu Desnoyers To: Jarkko Sakkinen To: Dave Hansen To: Thomas Gleixner To: Borislav Petkov To: x86@kernel.org To: "H. Peter Anvin" To: Ian Abbott To: H Hartley Sweeten To: Lucas Stach To: Christian Gmeiner To: David Airlie To: Simona Vetter To: Patrik Jakobsson To: Maarten Lankhorst To: Maxime Ripard To: Thomas Zimmermann To: Rob Clark To: Dmitry Baryshkov To: Abhinav Kumar To: Jessica Zhang To: Sean Paul To: Marijn Suijten To: Tomi Valkeinen To: Thierry Reding To: Mikko Perttunen To: Jonathan Hunter To: Christian Koenig To: Huang Rui To: Matthew Auld To: Jason Gunthorpe To: Yishai Hadas To: Shameer Kolothum To: Kevin Tian To: Ankit Agrawal To: Alex Williamson To: Paolo Bonzini To: Shakeel Butt To: Usama Arif Cc: ljs@kernel.org Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-parisc@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: nvdimm@lists.linux.dev Cc: linux-perf-users@vger.kernel.org Cc: linux-trace-kernel@vger.kernel.org Cc: damon@lists.linux.dev Cc: iommu@lists.linux.dev Cc: kasan-dev@googlegroups.com Cc: linux-sgx@vger.kernel.org Cc: etnaviv@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org Cc: freedreno@lists.freedesktop.org Cc: linux-tegra@vger.kernel.org Cc: kvm@vger.kernel.org Cc: Russell King --- Lorenzo Stoakes (33): mm: move vma_start_pgoff() into mm.h and clean up mm: add kdoc comments for vma_start/last_pgoff() tools/testing/vma: use vma_start_pgoff() in merge tests mm: introduce and use vma_end_pgoff() mm/rmap: update mm/interval_tree.c comments mm/rmap: parameterise vma_interval_tree_*() by address_space mm/rmap: elide unnecessary static inline's in interval_tree.c mm/rmap: rename vma_interval_tree_*() to mapping_rmap_tree_*() mm/rmap: parameterise anon_vma_interval_tree_*() by anon_vma mm/rmap: rename anon_vma_interval_tree_*() params and use pgoff_t mm/rmap: rename anon_vma_interval_tree_*() to anon_rmap_tree_*() MAINTAINERS: Move mm/interval_tree.c to rmap section mm/vma: introduce and use vmg_pages(), vmg_[start, end]_pgoff() mm/vma: clean up anon_vma_compatible() mm/vma: refactor vmg_adjust_set_range() for clarity mm/vma: minor cleanup of expand_[upwards, downwards]() mm: introduce and use linear_page_delta() mm/vma: use vma_start_pgoff(), linear_page_index() in mm code mm: prefer vma_[start,end]_pgoff() to vma->vm_pgoff in kernel/ mm/vma: remove duplicative vma_pgoff_offset() helper mm: use linear_page_[index, delta]() consistently mm/vma: introduce vma_assert_can_modify() mm/vma: add and use vma_[add/sub]_pgoff() mm/vma: move __install_special_mapping() to vma.c mm/vma: make vma_set_range() static, drop insert_vm_struct() decl mm/vma: update vma_shrink() to not pass start, pgoff parameters mm/vma: update vmg_adjust_set_range() to offset pgoff instead mm/vma: slightly rework the anonymous check in __mmap_new_vma() mm/vma: introduce and use vma_set_pgoff() mm/vma: correct incorrect vma.h inclusion mm/vma: use guard clauses in can_vma_merge_[before, after]() tools/testing/vma: default VMA, mm flag bits to 64-bit tools/testing/vma: output compared expression on ASSERT_[EQ, NE]() MAINTAINERS | 2 +- arch/arm/mm/fault-armv.c | 4 +- arch/arm/mm/flush.c | 2 +- arch/nios2/mm/cacheflush.c | 2 +- arch/parisc/kernel/cache.c | 2 +- arch/x86/kernel/cpu/sgx/virt.c | 3 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 3 +- drivers/gpu/drm/gma500/gem.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 3 +- drivers/gpu/drm/omapdrm/omap_gem.c | 5 +- drivers/gpu/drm/tegra/gem.c | 3 +- drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 +- drivers/vfio/pci/nvgrace-gpu/main.c | 3 +- drivers/vfio/pci/vfio_pci_core.c | 3 +- fs/dax.c | 2 +- fs/hugetlbfs/inode.c | 15 +- include/linux/huge_mm.h | 1 + include/linux/hugetlb.h | 3 +- include/linux/mm.h | 118 ++++++++++---- include/linux/mmap_lock.h | 8 + include/linux/pagemap.h | 35 +++- kernel/dma/coherent.c | 7 +- kernel/dma/direct.c | 6 +- kernel/dma/mapping.c | 8 +- kernel/dma/ops_helpers.c | 4 +- kernel/events/core.c | 20 +-- kernel/events/uprobes.c | 13 +- kernel/kcov.c | 2 +- kernel/trace/ring_buffer.c | 3 +- mm/damon/vaddr.c | 5 +- mm/debug.c | 2 +- mm/filemap.c | 7 +- mm/huge_memory.c | 2 +- mm/hugetlb.c | 15 +- mm/internal.h | 33 ++-- mm/interval_tree.c | 111 ++++++++----- mm/khugepaged.c | 7 +- mm/ksm.c | 7 +- mm/madvise.c | 6 +- mm/mapping_dirty_helpers.c | 2 +- mm/memory-failure.c | 10 +- mm/memory.c | 33 ++-- mm/mempolicy.c | 13 +- mm/mmap.c | 41 +---- mm/mmu_notifier.c | 2 +- mm/mremap.c | 12 +- mm/msync.c | 4 +- mm/nommu.c | 22 +-- mm/pagewalk.c | 4 +- mm/rmap.c | 14 +- mm/shmem.c | 9 +- mm/userfaultfd.c | 4 +- mm/util.c | 4 +- mm/vma.c | 293 ++++++++++++++++++++++------------ mm/vma.h | 80 ++++++++-- mm/vma_exec.c | 12 +- mm/vma_init.c | 6 +- mm/vma_internal.h | 4 +- tools/testing/vma/Makefile | 2 +- tools/testing/vma/include/dup.h | 41 ++++- tools/testing/vma/include/stubs.h | 16 +- tools/testing/vma/shared.c | 9 -- tools/testing/vma/shared.h | 43 +++-- tools/testing/vma/tests/merge.c | 40 ++--- tools/testing/vma/vma_internal.h | 4 +- virt/kvm/guest_memfd.c | 2 +- 66 files changed, 751 insertions(+), 459 deletions(-) --- base-commit: 4a6c88e10a0791d9c3b0677ce984365815c2ab4f change-id: 20260710-b4-pre-scalable-cow-24309015dee4 Cheers, -- Lorenzo Stoakes