linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 hmm 00/12] mm/hmm: Various revisions from a locking/code review
@ 2019-06-14  0:44 Jason Gunthorpe
  2019-06-14  0:44 ` [PATCH v3 hmm 01/12] mm/hmm: fix use after free with struct hmm in the mmu notifiers Jason Gunthorpe
                   ` (11 more replies)
  0 siblings, 12 replies; 45+ messages in thread
From: Jason Gunthorpe @ 2019-06-14  0:44 UTC (permalink / raw)
  To: Jerome Glisse, Ralph Campbell, John Hubbard, Felix.Kuehling
  Cc: linux-rdma, linux-mm, Andrea Arcangeli, dri-devel, amd-gfx,
	Ben Skeggs, Jason Gunthorpe

From: Jason Gunthorpe <jgg@mellanox.com>

This patch series arised out of discussions with Jerome when looking at the
ODP changes, particularly informed by use after free races we have already
found and fixed in the ODP code (thanks to syzkaller) working with mmu
notifiers, and the discussion with Ralph on how to resolve the lifetime model.

Overall this brings in a simplified locking scheme and easy to explain
lifetime model:

 If a hmm_range is valid, then the hmm is valid, if a hmm is valid then the mm
 is allocated memory.

 If the mm needs to still be alive (ie to lock the mmap_sem, find a vma, etc)
 then the mmget must be obtained via mmget_not_zero().

The use unlocked reads on 'hmm->dead' are also eliminated in favour of using
standard mmget() locking to prevent the mm from being released. Many of the
debugging checks of !range->hmm and !hmm->mm are dropped in favour of poison -
which is much clearer as to the lifetime intent.

The trailing patches are just some random cleanups I noticed when reviewing
this code.

I would like to run some testing with the ODP patch, but haven't
yet. Otherwise I think this is reviewed enough, and if there is nothing more
say I hope to apply it next week.

I plan to continue to work on the idea with CH to move more of this mirror
code into mmu notifiers and other places, but this will take some time and
research.

Thanks to everyone who took time to look at this!

Jason Gunthorpe (12):
  mm/hmm: fix use after free with struct hmm in the mmu notifiers
  mm/hmm: Use hmm_mirror not mm as an argument for hmm_range_register
  mm/hmm: Hold a mmgrab from hmm to mm
  mm/hmm: Simplify hmm_get_or_create and make it reliable
  mm/hmm: Remove duplicate condition test before wait_event_timeout
  mm/hmm: Hold on to the mmget for the lifetime of the range
  mm/hmm: Use lockdep instead of comments
  mm/hmm: Remove racy protection against double-unregistration
  mm/hmm: Poison hmm_range during unregister
  mm/hmm: Do not use list*_rcu() for hmm->ranges
  mm/hmm: Remove confusing comment and logic from hmm_release
  mm/hmm: Fix error flows in hmm_invalidate_range_start

 drivers/gpu/drm/nouveau/nouveau_svm.c |   2 +-
 include/linux/hmm.h                   |  52 +----
 kernel/fork.c                         |   1 -
 mm/hmm.c                              | 286 ++++++++++++--------------
 4 files changed, 140 insertions(+), 201 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 45+ messages in thread

end of thread, other threads:[~2019-06-19 12:03 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-14  0:44 [PATCH v3 hmm 00/12] mm/hmm: Various revisions from a locking/code review Jason Gunthorpe
2019-06-14  0:44 ` [PATCH v3 hmm 01/12] mm/hmm: fix use after free with struct hmm in the mmu notifiers Jason Gunthorpe
2019-06-15 13:56   ` Christoph Hellwig
2019-06-14  0:44 ` [PATCH v3 hmm 02/12] mm/hmm: Use hmm_mirror not mm as an argument for hmm_range_register Jason Gunthorpe
2019-06-15 13:59   ` Christoph Hellwig
2019-06-18 13:05     ` Jason Gunthorpe
2019-06-19  8:14       ` Christoph Hellwig
2019-06-14  0:44 ` [PATCH v3 hmm 03/12] mm/hmm: Hold a mmgrab from hmm to mm Jason Gunthorpe
2019-06-15 13:59   ` Christoph Hellwig
2019-06-14  0:44 ` [PATCH v3 hmm 04/12] mm/hmm: Simplify hmm_get_or_create and make it reliable Jason Gunthorpe
2019-06-15 14:12   ` Christoph Hellwig
2019-06-18  0:36     ` Jason Gunthorpe
2019-06-18 18:55     ` Jason Gunthorpe
2019-06-14  0:44 ` [PATCH v3 hmm 05/12] mm/hmm: Remove duplicate condition test before wait_event_timeout Jason Gunthorpe
2019-06-15 14:12   ` Christoph Hellwig
2019-06-14  0:44 ` [PATCH v3 hmm 06/12] mm/hmm: Hold on to the mmget for the lifetime of the range Jason Gunthorpe
2019-06-15 14:14   ` Christoph Hellwig
2019-06-18 15:11     ` Jason Gunthorpe
2019-06-19  8:18       ` Christoph Hellwig
2019-06-19 11:34         ` Jason Gunthorpe
2019-06-19 11:54           ` Christoph Hellwig
2019-06-14  0:44 ` [PATCH v3 hmm 07/12] mm/hmm: Use lockdep instead of comments Jason Gunthorpe
2019-06-15 14:14   ` Christoph Hellwig
2019-06-14  0:44 ` [PATCH v3 hmm 08/12] mm/hmm: Remove racy protection against double-unregistration Jason Gunthorpe
2019-06-15 14:16   ` Christoph Hellwig
2019-06-18 13:13     ` Jason Gunthorpe
2019-06-18 13:27       ` Christoph Hellwig
2019-06-18 18:57         ` Jason Gunthorpe
2019-06-19  8:19           ` Christoph Hellwig
2019-06-14  0:44 ` [PATCH v3 hmm 09/12] mm/hmm: Poison hmm_range during unregister Jason Gunthorpe
2019-06-15 14:17   ` Christoph Hellwig
2019-06-18 18:04     ` Jason Gunthorpe
2019-06-14  0:44 ` [PATCH v3 hmm 10/12] mm/hmm: Do not use list*_rcu() for hmm->ranges Jason Gunthorpe
2019-06-15 14:18   ` Christoph Hellwig
2019-06-18  0:38     ` Jason Gunthorpe
2019-06-14  0:44 ` [PATCH v3 hmm 11/12] mm/hmm: Remove confusing comment and logic from hmm_release Jason Gunthorpe
2019-06-15 14:21   ` Christoph Hellwig
2019-06-18  0:45     ` Jason Gunthorpe
2019-06-18  5:37       ` Christoph Hellwig
2019-06-19  0:53         ` Kuehling, Felix
2019-06-19  8:07           ` Christoph Hellwig
2019-06-19 11:56             ` Jason Gunthorpe
2019-06-19 12:03               ` Christoph Hellwig
2019-06-14  0:44 ` [PATCH v3 hmm 12/12] mm/hmm: Fix error flows in hmm_invalidate_range_start Jason Gunthorpe
2019-06-15 14:25   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).