• Jason Gunthorpe's avatar
    mm/hmm: Remove confusing comment and logic from hmm_release · 14331726
    Jason Gunthorpe authored
    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: default avatarJason Gunthorpe <jgg@mellanox.com>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    Tested-by: default avatarPhilip Yang <Philip.Yang@amd.com>
    14331726
hmm.c 41.8 KB