Skip to content

Commit ff2d238

Browse files
Michel DänzerChristianKoenigAMD
authored andcommitted
dma-buf/poll: Get a file reference for outstanding fence callbacks
This makes sure we don't hit the BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active); in dma_buf_release, which could be triggered by user space closing the dma-buf file description while there are outstanding fence callbacks from dma_buf_poll. Cc: [email protected] Signed-off-by: Michel Dänzer <[email protected]> Reviewed-by: Christian König <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Christian König <[email protected]>
1 parent b3ec8cd commit ff2d238

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/dma-buf/dma-buf.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ static void dma_buf_release(struct dentry *dentry)
6767
BUG_ON(dmabuf->vmapping_counter);
6868

6969
/*
70-
* Any fences that a dma-buf poll can wait on should be signaled
71-
* before releasing dma-buf. This is the responsibility of each
72-
* driver that uses the reservation objects.
73-
*
74-
* If you hit this BUG() it means someone dropped their ref to the
75-
* dma-buf while still having pending operation to the buffer.
70+
* If you hit this BUG() it could mean:
71+
* * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
72+
* * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
7673
*/
7774
BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
7875

@@ -200,13 +197,16 @@ static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence)
200197
static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
201198
{
202199
struct dma_buf_poll_cb_t *dcb = (struct dma_buf_poll_cb_t *)cb;
200+
struct dma_buf *dmabuf = container_of(dcb->poll, struct dma_buf, poll);
203201
unsigned long flags;
204202

205203
spin_lock_irqsave(&dcb->poll->lock, flags);
206204
wake_up_locked_poll(dcb->poll, dcb->active);
207205
dcb->active = 0;
208206
spin_unlock_irqrestore(&dcb->poll->lock, flags);
209207
dma_fence_put(fence);
208+
/* Paired with get_file in dma_buf_poll */
209+
fput(dmabuf->file);
210210
}
211211

212212
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)
259259
spin_unlock_irq(&dmabuf->poll.lock);
260260

261261
if (events & EPOLLOUT) {
262+
/* Paired with fput in dma_buf_poll_cb */
263+
get_file(dmabuf->file);
264+
262265
if (!dma_buf_poll_add_cb(resv, true, dcb))
263266
/* No callback queued, wake up any other waiters */
264267
dma_buf_poll_cb(NULL, &dcb->cb);
@@ -279,6 +282,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
279282
spin_unlock_irq(&dmabuf->poll.lock);
280283

281284
if (events & EPOLLIN) {
285+
/* Paired with fput in dma_buf_poll_cb */
286+
get_file(dmabuf->file);
287+
282288
if (!dma_buf_poll_add_cb(resv, false, dcb))
283289
/* No callback queued, wake up any other waiters */
284290
dma_buf_poll_cb(NULL, &dcb->cb);

0 commit comments

Comments
 (0)