• Daniel Vetter's avatar
    drm: reference framebuffers which are on the idr · 2b677e8c
    Daniel Vetter authored
    Since otherwise looking and reference-counting around
    drm_framebuffer_lookup will be an unmanageable mess. With this change,
    an object can either be found in the idr and will stay around once we
    incremented the reference counter. Or it will be gone for good and
    can't be looked up using its id any more.
    
    Atomicity is guaranteed by the dev->mode_config.fb_lock. The
    newly-introduce fpriv->fbs_lock looks a bit redundant, but the next
    patch will shuffle the locking order between these two locks and all
    the modeset locks taken in modeset_lock_all, so we'll need it.
    
    Also, since userspace could do really funky stuff and race e.g. a
    getresources with an rmfb, we need to make sure that the kernel
    doesn't fall over trying to look-up an inexistent fb, or causing
    confusion by having two fbs around with the same id. Simply reset the
    framebuffer id to 0, which marks it as reaped. Any lookups of that id
    will fail, so the object is really gone for good from userspace's pov.
    
    Note that we still need to protect the "remove framebuffer from all
    use-cases" and the final unreference with the modeset-lock, since most
    framebuffer use-sites don't implement proper reference counting yet.
    We can only lift this once _all_ users are converted.
    
    With this change, two references are held on alife, but unused
    framebuffers:
    - The reference for the idr lookup, created in this patch.
    - For user-created framebuffers the fpriv->fbs reference, for
      driver-private fbs the driver is supposed to hold it's own last
      reference.
    
    Note that the dev->mode_config.fb_list itself does _not_ hold a
    reference onto the framebuffers (this list is essentially only used
    for debugfs files). Hence if there's anything left there when the
    driver has cleaned up all it's modeset resources, this is a ref-leak.
    WARN about it.
    
    Now we only need to fix up all other places to properly reference
    count framebuffers.
    
    v2: Fix spelling fail in a comment spotted by Rob Clark.
    Reviewed-by: default avatarRob Clark <rob@ti.com>
    Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
    2b677e8c
drm_crtc.c 102 KB