mm/hmm: Simplify hmm_get_or_create and make it reliable
authorJason Gunthorpe <jgg@mellanox.com>
Thu, 23 May 2019 13:24:13 +0000 (10:24 -0300)
committerJason Gunthorpe <jgg@mellanox.com>
Tue, 18 Jun 2019 14:55:07 +0000 (11:55 -0300)
commit8a9320b7ec5d879884c547fb73c35ac411a0b977
tree618f60433e2626404a186d49275f9cfb90edb605
parentc8a53b2db0aec40d8b217936e1b7f3d840c50390
mm/hmm: Simplify hmm_get_or_create and make it reliable

As coded this function can false-fail in various racy situations. Make it
reliable and simpler by running under the write side of the mmap_sem and
avoiding the false-failing compare/exchange pattern. Due to the mmap_sem
this no longer has to avoid racing with a 2nd parallel
hmm_get_or_create().

Unfortunately this still has to use the page_table_lock as the
non-sleeping lock protecting mm->hmm, since the contexts where we free the
hmm are incompatible with mmap_sem.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Ralph Campbell <rcampbell@nvidia.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Philip Yang <Philip.Yang@amd.com>
mm/hmm.c