Skip to content

mm: Add vma_lookup()

Liam Howlett linux-mm lkml 2 versions – Applied

Status from this message: [merged] mm-mempolicy-use-vma_lookup-in-__access_remote_vm.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest22 patches 1 replyApplied 22/22
  2. v10 of 21 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- Changed find_vma_intersection() comments and whitespace to be compliant. Thanks Davidlohr Bueso
- Moved vma_lookup() call in vma_to_resize() to be separate from the declaration as requested by Davidlohr Bueso
- Added Acked-by: Geert Uytterhoeven <[email protected]> for 08/22 "arch/m68k/kernel/sys_m68k: Use vma_lookup() in sys_cacheflush()"
- Added Reviewed-by: Laurent Dufour <[email protected]>
- Added Acked-by: Davidlohr Bueso <[email protected]>

Patches in v2 All 22 applied

#Subject and filesSizeRepliesApplied
1/22mm: Add vma_lookup(), update find_vma_intersection() commentsinclude/linux/mm.h+32 -40 repliesApplied
2/22drm/i915/selftests: Use vma_lookup() in __igt_mmap()drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c+1 -10 repliesApplied
3/22arch/arc/kernel/troubleshoot: use vma_lookup() instead of find_vma()arch/arc/kernel/troubleshoot.c+4 -40 repliesApplied
4/22arch/arm64/kvm: Use vma_lookup() instead of find_vma_intersection()arch/arm64/kvm/mmu.c+1 -10 repliesApplied
5/22arch/powerpc/kvm/book3s_hv_uvmem: Use vma_lookup() instead of find_vma_intersection()arch/powerpc/kvm/book3s_hv_uvmem.c+1 -10 repliesApplied
6/22arch/powerpc/kvm/book3s: Use vma_lookup() in kvmppc_hv_setup_htab_rma()arch/powerpc/kvm/book3s_hv.c+2 -20 repliesApplied
7/22arch/mips/kernel/traps: Use vma_lookup() instead of find_vma()arch/mips/kernel/traps.c+1 -30 repliesApplied
8/22arch/m68k/kernel/sys_m68k: Use vma_lookup() in sys_cacheflush()arch/m68k/kernel/sys_m68k.c+2 -20 repliesApplied
9/22x86/sgx: Use vma_lookup() in sgx_encl_find()arch/x86/kernel/cpu/sgx/encl.h+2 -20 repliesApplied
10/22virt/kvm: Use vma_lookup() instead of find_vma_intersection()virt/kvm/kvm_main.c+1 -10 repliesApplied
11/22vfio: Use vma_lookup() instead of find_vma_intersection()drivers/vfio/vfio_iommu_type1.c+1 -10 repliesApplied
12/22net/ipv5/tcp: Use vma_lookup() in tcp_zerocopy_receive()net/ipv4/tcp.c+2 -20 repliesApplied
13/22drm/amdgpu: Use vma_lookup() in amdgpu_ttm_tt_get_user_pages()drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c+2 -20 repliesApplied
14/22media: videobuf2: Use vma_lookup() in get_vaddr_frames()drivers/media/common/videobuf2/frame_vector.c+1 -10 repliesApplied
15/22misc/sgi-gru/grufault: Use vma_lookup() in gru_find_vma()drivers/misc/sgi-gru/grufault.c+2 -20 repliesApplied
16/22kernel/events/uprobes: Use vma_lookup() in find_active_uprobe()kernel/events/uprobes.c+2 -20 repliesApplied
17/22lib/test_hmm: Use vma_lookup() in dmirror_migrate()lib/test_hmm.c+2 -30 repliesApplied
18/22mm/ksm: Use vma_lookup() in find_mergeable_vma()mm/ksm.c+2 -40 repliesApplied
19/22mm/migrate: Use vma_lookup() in do_pages_stat_array()mm/migrate.c+2 -20 repliesApplied
20/22mm/mremap: Use vma_lookup() in vma_to_resize()mm/mremap.c+3 -20 repliesApplied
21/22mm/memory.c: Use vma_lookup() in __access_remote_vm()mm/memory.c+2 -20 repliesApplied
22/22mm/mempolicy: Use vma_lookup() in __access_remote_vm()mm/mempolicy.c+1 -10 repliesApplied

Reviews trailers per patch

All 22 patches have a Reviewed-by or Acked-by.

PatchLaurent DufourDavid HildenbrandDavidlohr BuesoGeert Uytterhoeven
1/22R-b A-b A-b
2/22R-b A-b A-b
3/22R-b A-b A-b
4/22R-b A-b A-b
5/22R-b A-b A-b
6/22R-b A-b A-b
7/22R-b A-b A-b
8/22R-b A-b A-b A-b
9/22R-b A-b A-b
10/22R-b A-b A-b
11/22R-b A-b A-b
12/22R-b A-b A-b
13/22R-b A-b A-b
14/22R-b A-b A-b
15/22R-b A-b A-b
16/22R-b A-b A-b
17/22R-b A-b A-b
18/22R-b A-b A-b
19/22R-b A-b A-b
20/22R-b A-b A-b
21/22R-b A-b A-b
22/22R-b A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v2 thread

Cover letter [PATCH v2 00/22] mm: Add vma_lookup()

Many places in the kernel use find_vma() to get a vma and then check the start address of the vma to ensure the next vma was not returned.

Other places use the find_vma_intersection() call with add, addr + 1 as the range; looking for just the vma at a specific address.

The third use of find_vma() is by developers who do not know that the function starts searching at the provided address upwards for the next vma. This results in a bug that is often overlooked for a long time.

Adding the new vma_lookup() function will allow for cleaner code by removing the find_vma() calls which check limits, making find_vma_intersection() calls of a single address to be shorter, and potentially reduce the incorrect uses of find_vma().

v2:
- Changed find_vma_intersection() comments and whitespace to be compliant. Thanks Davidlohr Bueso
- Moved vma_lookup() call in vma_to_resize() to be separate from the declaration as requested by Davidlohr Bueso
- Added Acked-by: Geert Uytterhoeven <[email protected]> for 08/22 "arch/m68k/kernel/sys_m68k: Use vma_lookup() in sys_cacheflush()"
- Added Reviewed-by: Laurent Dufour <[email protected]>
- Added Acked-by: Davidlohr Bueso <[email protected]>

This patch set was originally part of the maple tree patch set. Changes since being broken out on its own:
- Changed initial implementation of vma_lookup() to use find_vma() as requested by Michel Lespinasse.
- Updated commit comments to be more descriptive

These patches are based on next-20210506

Liam R. Howlett (22):
mm: Add vma_lookup(), update find_vma_intersection() comments drm/i915/selftests: Use vma_lookup() in __igt_mmap() arch/arc/kernel/troubleshoot: use vma_lookup() instead of find_vma() arch/arm64/kvm: Use vma_lookup() instead of find_vma_intersection() arch/powerpc/kvm/book3s_hv_uvmem: Use vma_lookup() instead of
find_vma_intersection()
arch/powerpc/kvm/book3s: Use vma_lookup() in
kvmppc_hv_setup_htab_rma()
arch/mips/kernel/traps: Use vma_lookup() instead of find_vma() arch/m68k/kernel/sys_m68k: Use vma_lookup() in sys_cacheflush() x86/sgx: Use vma_lookup() in sgx_encl_find()
virt/kvm: Use vma_lookup() instead of find_vma_intersection()
vfio: Use vma_lookup() instead of find_vma_intersection() net/ipv5/tcp: Use vma_lookup() in tcp_zerocopy_receive() drm/amdgpu: Use vma_lookup() in amdgpu_ttm_tt_get_user_pages()
media: videobuf2: Use vma_lookup() in get_vaddr_frames() misc/sgi-gru/grufault: Use vma_lookup() in gru_find_vma() kernel/events/uprobes: Use vma_lookup() in find_active_uprobe() lib/test_hmm: Use vma_lookup() in dmirror_migrate() mm/ksm: Use vma_lookup() in find_mergeable_vma() mm/migrate: Use vma_lookup() in do_pages_stat_array() mm/mremap: Use vma_lookup() in vma_to_resize() mm/memory.c: Use vma_lookup() in __access_remote_vm() mm/mempolicy: Use vma_lookup() in __access_remote_vm()

 arch/arc/kernel/troubleshoot.c                |  8 ++---
 arch/arm64/kvm/mmu.c                          |  2 +-
 arch/m68k/kernel/sys_m68k.c                   |  4 +--
 arch/mips/kernel/traps.c                      |  4 +--
 arch/powerpc/kvm/book3s_hv.c                  |  4 +--
 arch/powerpc/kvm/book3s_hv_uvmem.c            |  2 +-
 arch/x86/kernel/cpu/sgx/encl.h                |  4 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  4 +--
 .../drm/i915/gem/selftests/i915_gem_mman.c    |  2 +-
 drivers/media/common/videobuf2/frame_vector.c |  2 +-
 drivers/misc/sgi-gru/grufault.c               |  4 +--
 drivers/vfio/vfio_iommu_type1.c               |  2 +-
 include/linux/mm.h                            | 36 ++++++++++++++++---
 kernel/events/uprobes.c                       |  4 +--
 lib/test_hmm.c                                |  5 ++-
 mm/ksm.c                                      |  6 ++--
 mm/memory.c                                   |  4 +--
 mm/mempolicy.c                                |  2 +-
 mm/migrate.c                                  |  4 +--
 mm/mremap.c                                   |  5 +--
 net/ipv4/tcp.c                                |  4 +--
 virt/kvm/kvm_main.c                           |  2 +-
 22 files changed, 69 insertions(+), 45 deletions(-)
Signature · 1 line
2.30.2