Commit 4a390c2e authored by Dave Airlie's avatar Dave Airlie

Merge tag 'drm-misc-next-fixes-2021-11-05' of...

Merge tag 'drm-misc-next-fixes-2021-11-05' of git://anongit.freedesktop.org/drm/drm-misc into drm-next

A refcounting fix for outstanding fence callbacks.
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>

From: Maxime Ripard <maxime@cerno.tech>
Link: https://patchwork.freedesktop.org/patch/msgid/20211105074318.oy6rwjr5wcw6qpjj@gilmour
parents 806acd38 ff2d2384
...@@ -67,12 +67,9 @@ static void dma_buf_release(struct dentry *dentry) ...@@ -67,12 +67,9 @@ static void dma_buf_release(struct dentry *dentry)
BUG_ON(dmabuf->vmapping_counter); BUG_ON(dmabuf->vmapping_counter);
/* /*
* Any fences that a dma-buf poll can wait on should be signaled * If you hit this BUG() it could mean:
* before releasing dma-buf. This is the responsibility of each * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
* driver that uses the reservation objects. * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
*
* If you hit this BUG() it means someone dropped their ref to the
* dma-buf while still having pending operation to the buffer.
*/ */
BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active); BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
...@@ -200,6 +197,7 @@ static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence) ...@@ -200,6 +197,7 @@ static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence)
static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb) static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
{ {
struct dma_buf_poll_cb_t *dcb = (struct dma_buf_poll_cb_t *)cb; struct dma_buf_poll_cb_t *dcb = (struct dma_buf_poll_cb_t *)cb;
struct dma_buf *dmabuf = container_of(dcb->poll, struct dma_buf, poll);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&dcb->poll->lock, flags); spin_lock_irqsave(&dcb->poll->lock, flags);
...@@ -207,6 +205,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb) ...@@ -207,6 +205,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
dcb->active = 0; dcb->active = 0;
spin_unlock_irqrestore(&dcb->poll->lock, flags); spin_unlock_irqrestore(&dcb->poll->lock, flags);
dma_fence_put(fence); dma_fence_put(fence);
/* Paired with get_file in dma_buf_poll */
fput(dmabuf->file);
} }
static bool dma_buf_poll_add_cb(struct dma_resv *resv, bool write, static bool dma_buf_poll_add_cb(struct dma_resv *resv, bool write,
...@@ -259,6 +259,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) ...@@ -259,6 +259,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
spin_unlock_irq(&dmabuf->poll.lock); spin_unlock_irq(&dmabuf->poll.lock);
if (events & EPOLLOUT) { if (events & EPOLLOUT) {
/* Paired with fput in dma_buf_poll_cb */
get_file(dmabuf->file);
if (!dma_buf_poll_add_cb(resv, true, dcb)) if (!dma_buf_poll_add_cb(resv, true, dcb))
/* No callback queued, wake up any other waiters */ /* No callback queued, wake up any other waiters */
dma_buf_poll_cb(NULL, &dcb->cb); dma_buf_poll_cb(NULL, &dcb->cb);
...@@ -279,6 +282,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) ...@@ -279,6 +282,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
spin_unlock_irq(&dmabuf->poll.lock); spin_unlock_irq(&dmabuf->poll.lock);
if (events & EPOLLIN) { if (events & EPOLLIN) {
/* Paired with fput in dma_buf_poll_cb */
get_file(dmabuf->file);
if (!dma_buf_poll_add_cb(resv, false, dcb)) if (!dma_buf_poll_add_cb(resv, false, dcb))
/* No callback queued, wake up any other waiters */ /* No callback queued, wake up any other waiters */
dma_buf_poll_cb(NULL, &dcb->cb); dma_buf_poll_cb(NULL, &dcb->cb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment