• Daniel Vetter's avatar
    drm/gem: Use kref_get_unless_zero for the weak mmap references · 2225cfe4
    Daniel Vetter authored
    Compared to wrapping the final kref_put with dev->struct_mutex this
    allows us to only acquire the offset manager look both in the final
    cleanup and in the lookup. Which has the upside that no locks leak out
    of the core abstractions. But it means that we need to hold a
    temporary reference to the object while checking mmap constraints, to
    make sure the object doesn't disappear. Extended the critical region
    would have worked too, but would result in more leaky locking.
    
    Also, this is the final bit which required dev->struct_mutex in gem
    core, now modern drivers can be completely struct_mutex free!
    
    This needs a new drm_vma_offset_exact_lookup_locked and makes both
    drm_vma_offset_exact_lookup and drm_vma_offset_lookup unused.
    
    v2: Don't leak object references in failure paths (David).
    
    v3: Add a comment from Chris explaining how the ordering works, with
    the slight adjustment that I dropped any mention of struct_mutex since
    with this patch it's now immaterial ot core gem.
    
    Cc: David Herrmann <dh.herrmann@gmail.com>
    Reviewed-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
    Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
    Link: http://mid.gmane.org/1444901623-18918-1-git-send-email-daniel.vetter@ffwll.chSigned-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
    2225cfe4
drm_gem.c 26.1 KB