mm/hmm: Remove confusing comment and logic from hmm_release
authorJason Gunthorpe <jgg@mellanox.com>
Fri, 24 May 2019 15:14:08 +0000 (12:14 -0300)
committerJason Gunthorpe <jgg@mellanox.com>
Mon, 24 Jun 2019 20:38:18 +0000 (17:38 -0300)
commit14331726a3c47bb1649dab155a84610f509d414e
tree9dc1a6341e79bdaf3c3ac93bd6fa23ac8c316eae
parent2dcc3eb8ab50c9ca816cc60abfd94bea559d3e86
mm/hmm: Remove confusing comment and logic from hmm_release

hmm_release() is called exactly once per hmm. ops->release() cannot
accidentally trigger any action that would recurse back onto
hmm->mirrors_sem.

This fixes a use after-free race of the form:

       CPU0                                   CPU1
                                           hmm_release()
                                             up_write(&hmm->mirrors_sem);
 hmm_mirror_unregister(mirror)
  down_write(&hmm->mirrors_sem);
  up_write(&hmm->mirrors_sem);
  kfree(mirror)
                                             mirror->ops->release(mirror)

The only user we have today for ops->release is an empty function, so this
is unambiguously safe.

As a consequence of plugging this race drivers are not allowed to
register/unregister mirrors from within a release op.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Philip Yang <Philip.Yang@amd.com>
mm/hmm.c