Skip to content

Add a seqcount between gup_fast and copy_page_range()

Jason Gunthorpe linux-mm lkml 4 versions – Applied

Status from this message: [merged] mm-reorganize-internal_get_user_pages_fast.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 4 repliesApplied 2/2
  2. v32 patches 3 repliesSuperseded
  3. v22 patches 29 repliesApplied
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches16 repliesSuperseded

Changes in v4 from the cover letter

- Use read_seqcount_retry() not read_seqcount_t_retry
v3: https://lore.kernel.org/r/[email protected]
- Revise comment for write_protect_seq
- Revise comment in copy_page_range
- Use raw_write_seqcount_begin() not raw_write_seqcount_t_begin()
v2: https://lore.kernel.org/r/[email protected]
- Use start not addr in lockless_pages_from_mm
- Replace unsigned long casts with using the proper variable type
- Update comments
- Use raw_write_seqcount_t_begin() instead of open coding
- Update commit messages
v1: https://lore.kernel.org/r/[email protected]

Patches in v4 All 2 applied

#Subject and filesSizeRepliesApplied
1/2mm: reorganize internal_get_user_pages_fast()mm/gup.c+54 -450 repliesApplied
2/2mm: prevent gup_fast from racing with COW during forkarch/x86/kernel/tboot.c drivers/firmware/efi/efi.c include/linux/mm_types.h +4 more+42 -13 repliesApplied

Reviews trailers per patch

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

PatchJan KaraJohn HubbardPeter XuAhmed S. Darwish
1/2R-b R-b R-b
2/2R-b R-b R-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 v4 thread

Cover letter [PATCH v4 0/2] Add a seqcount between gup_fast and copy_page_range()

As discussed and suggested by Linus use a seqcount to close the small race between gup_fast and copy_page_range().

Ahmed confirms that raw_write_seqcount_begin() is the correct API to use in this case and it doesn't trigger any lockdeps.

I was able to test it using two threads, one forking and the other using ibv_reg_mr() to trigger GUP fast. Modifying copy_page_range() to sleep made the window large enough to reliably hit to test the logic.

v4:
- Use read_seqcount_retry() not read_seqcount_t_retry
v3: https://lore.kernel.org/r/[email protected]
- Revise comment for write_protect_seq
- Revise comment in copy_page_range
- Use raw_write_seqcount_begin() not raw_write_seqcount_t_begin()
v2: https://lore.kernel.org/r/[email protected]
- Use start not addr in lockless_pages_from_mm
- Replace unsigned long casts with using the proper variable type
- Update comments
- Use raw_write_seqcount_t_begin() instead of open coding
- Update commit messages
v1: https://lore.kernel.org/r/[email protected]

To: [email protected]
To: Peter Xu <[email protected]>
To: Linus Torvalds <[email protected]>
Cc: Peter Xu <[email protected]>
Cc: John Hubbard <[email protected]>
Cc: Linux-MM <[email protected]>
Cc: Linux Kernel Mailing List <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Kirill Tkhai <[email protected]>
Cc: Kirill Shutemov <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Jann Horn <[email protected]>
Cc: "Ahmed S. Darwish" <[email protected]>

Jason Gunthorpe (2):
mm: reorganize internal_get_user_pages_fast()
mm: prevent gup_fast from racing with COW during fork

 arch/x86/kernel/tboot.c    |   1 +
 drivers/firmware/efi/efi.c |   1 +
 include/linux/mm_types.h   |   8 +++
 kernel/fork.c              |   1 +
 mm/gup.c                   | 117 +++++++++++++++++++++++--------------
 mm/init-mm.c               |   1 +
 mm/memory.c                |  13 ++++-
 7 files changed, 96 insertions(+), 46 deletions(-)
Signature · 1 line
2.29.2