* [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
@ 2021-07-23 7:58 ` Michel Dänzer
0 siblings, 0 replies; 11+ messages in thread
From: Michel Dänzer @ 2021-07-23 7:58 UTC (permalink / raw)
To: Christian König
Cc: Sumit Semwal, dri-devel, linux-media, linaro-mm-sig, linux-kernel
From: Michel Dänzer <mdaenzer@redhat.com>
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: stable@vger.kernel.org
Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
---
drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 6c520c9bd93c..ec25498a971f 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
BUG_ON(dmabuf->vmapping_counter);
/*
- * Any fences that a dma-buf poll can wait on should be signaled
- * before releasing dma-buf. This is the responsibility of each
- * driver that uses the reservation objects.
- *
- * If you hit this BUG() it means someone dropped their ref to the
- * dma-buf while still having pending operation to the buffer.
+ * If you hit this BUG() it could mean:
+ * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
+ * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
*/
BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
@@ -196,6 +193,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)
{
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;
spin_lock_irqsave(&dcb->poll->lock, flags);
@@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
dcb->active = 0;
spin_unlock_irqrestore(&dcb->poll->lock, flags);
dma_fence_put(fence);
+ /* Paired with get_file in dma_buf_poll */
+ fput(dmabuf->file);
}
static bool dma_buf_poll_shared(struct dma_resv *resv,
@@ -278,6 +278,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
spin_unlock_irq(&dmabuf->poll.lock);
if (events & EPOLLOUT) {
+ /* Paired with fput in dma_buf_poll_cb */
+ get_file(dmabuf->file);
+
if (!dma_buf_poll_shared(resv, dcb) &&
!dma_buf_poll_excl(resv, dcb))
/* No callback queued, wake up any other waiters */
@@ -299,6 +302,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
spin_unlock_irq(&dmabuf->poll.lock);
if (events & EPOLLIN) {
+ /* Paired with fput in dma_buf_poll_cb */
+ get_file(dmabuf->file);
+
if (!dma_buf_poll_excl(resv, dcb))
/* No callback queued, wake up any other waiters */
dma_buf_poll_cb(NULL, &dcb->cb);
--
2.32.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
@ 2021-07-23 7:58 ` Michel Dänzer
0 siblings, 0 replies; 11+ messages in thread
From: Michel Dänzer @ 2021-07-23 7:58 UTC (permalink / raw)
To: Christian König; +Cc: linaro-mm-sig, linux-kernel, dri-devel, linux-media
From: Michel Dänzer <mdaenzer@redhat.com>
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: stable@vger.kernel.org
Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
---
drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 6c520c9bd93c..ec25498a971f 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
BUG_ON(dmabuf->vmapping_counter);
/*
- * Any fences that a dma-buf poll can wait on should be signaled
- * before releasing dma-buf. This is the responsibility of each
- * driver that uses the reservation objects.
- *
- * If you hit this BUG() it means someone dropped their ref to the
- * dma-buf while still having pending operation to the buffer.
+ * If you hit this BUG() it could mean:
+ * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
+ * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
*/
BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
@@ -196,6 +193,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)
{
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;
spin_lock_irqsave(&dcb->poll->lock, flags);
@@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
dcb->active = 0;
spin_unlock_irqrestore(&dcb->poll->lock, flags);
dma_fence_put(fence);
+ /* Paired with get_file in dma_buf_poll */
+ fput(dmabuf->file);
}
static bool dma_buf_poll_shared(struct dma_resv *resv,
@@ -278,6 +278,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
spin_unlock_irq(&dmabuf->poll.lock);
if (events & EPOLLOUT) {
+ /* Paired with fput in dma_buf_poll_cb */
+ get_file(dmabuf->file);
+
if (!dma_buf_poll_shared(resv, dcb) &&
!dma_buf_poll_excl(resv, dcb))
/* No callback queued, wake up any other waiters */
@@ -299,6 +302,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
spin_unlock_irq(&dmabuf->poll.lock);
if (events & EPOLLIN) {
+ /* Paired with fput in dma_buf_poll_cb */
+ get_file(dmabuf->file);
+
if (!dma_buf_poll_excl(resv, dcb))
/* No callback queued, wake up any other waiters */
dma_buf_poll_cb(NULL, &dcb->cb);
--
2.32.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
2021-07-23 7:58 ` Michel Dänzer
@ 2021-07-23 8:04 ` Christian König
-1 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2021-07-23 8:04 UTC (permalink / raw)
To: Michel Dänzer
Cc: Sumit Semwal, dri-devel, linux-media, linaro-mm-sig, linux-kernel
Am 23.07.21 um 09:58 schrieb Michel Dänzer:
> From: Michel Dänzer <mdaenzer@redhat.com>
>
> 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.
I was also wondering the same thing while working on this, but then
thought that the poll interface would take care of this.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
> ---
> drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 6c520c9bd93c..ec25498a971f 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
> BUG_ON(dmabuf->vmapping_counter);
>
> /*
> - * Any fences that a dma-buf poll can wait on should be signaled
> - * before releasing dma-buf. This is the responsibility of each
> - * driver that uses the reservation objects.
> - *
> - * If you hit this BUG() it means someone dropped their ref to the
> - * dma-buf while still having pending operation to the buffer.
> + * If you hit this BUG() it could mean:
> + * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
> + * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
> */
> BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
>
> @@ -196,6 +193,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)
> {
> 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;
>
> spin_lock_irqsave(&dcb->poll->lock, flags);
> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
> dcb->active = 0;
> spin_unlock_irqrestore(&dcb->poll->lock, flags);
> dma_fence_put(fence);
> + /* Paired with get_file in dma_buf_poll */
> + fput(dmabuf->file);
Is calling fput() in interrupt context ok? IIRC that could potentially
sleep.
Regards,
Christian.
> }
>
> static bool dma_buf_poll_shared(struct dma_resv *resv,
> @@ -278,6 +278,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
> spin_unlock_irq(&dmabuf->poll.lock);
>
> if (events & EPOLLOUT) {
> + /* Paired with fput in dma_buf_poll_cb */
> + get_file(dmabuf->file);
> +
> if (!dma_buf_poll_shared(resv, dcb) &&
> !dma_buf_poll_excl(resv, dcb))
> /* No callback queued, wake up any other waiters */
> @@ -299,6 +302,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
> spin_unlock_irq(&dmabuf->poll.lock);
>
> if (events & EPOLLIN) {
> + /* Paired with fput in dma_buf_poll_cb */
> + get_file(dmabuf->file);
> +
> if (!dma_buf_poll_excl(resv, dcb))
> /* No callback queued, wake up any other waiters */
> dma_buf_poll_cb(NULL, &dcb->cb);
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
@ 2021-07-23 8:04 ` Christian König
0 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2021-07-23 8:04 UTC (permalink / raw)
To: Michel Dänzer; +Cc: linaro-mm-sig, linux-kernel, dri-devel, linux-media
Am 23.07.21 um 09:58 schrieb Michel Dänzer:
> From: Michel Dänzer <mdaenzer@redhat.com>
>
> 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.
I was also wondering the same thing while working on this, but then
thought that the poll interface would take care of this.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
> ---
> drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 6c520c9bd93c..ec25498a971f 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
> BUG_ON(dmabuf->vmapping_counter);
>
> /*
> - * Any fences that a dma-buf poll can wait on should be signaled
> - * before releasing dma-buf. This is the responsibility of each
> - * driver that uses the reservation objects.
> - *
> - * If you hit this BUG() it means someone dropped their ref to the
> - * dma-buf while still having pending operation to the buffer.
> + * If you hit this BUG() it could mean:
> + * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
> + * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
> */
> BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
>
> @@ -196,6 +193,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)
> {
> 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;
>
> spin_lock_irqsave(&dcb->poll->lock, flags);
> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
> dcb->active = 0;
> spin_unlock_irqrestore(&dcb->poll->lock, flags);
> dma_fence_put(fence);
> + /* Paired with get_file in dma_buf_poll */
> + fput(dmabuf->file);
Is calling fput() in interrupt context ok? IIRC that could potentially
sleep.
Regards,
Christian.
> }
>
> static bool dma_buf_poll_shared(struct dma_resv *resv,
> @@ -278,6 +278,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
> spin_unlock_irq(&dmabuf->poll.lock);
>
> if (events & EPOLLOUT) {
> + /* Paired with fput in dma_buf_poll_cb */
> + get_file(dmabuf->file);
> +
> if (!dma_buf_poll_shared(resv, dcb) &&
> !dma_buf_poll_excl(resv, dcb))
> /* No callback queued, wake up any other waiters */
> @@ -299,6 +302,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
> spin_unlock_irq(&dmabuf->poll.lock);
>
> if (events & EPOLLIN) {
> + /* Paired with fput in dma_buf_poll_cb */
> + get_file(dmabuf->file);
> +
> if (!dma_buf_poll_excl(resv, dcb))
> /* No callback queued, wake up any other waiters */
> dma_buf_poll_cb(NULL, &dcb->cb);
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
2021-07-23 8:04 ` Christian König
(?)
@ 2021-07-23 8:19 ` Michel Dänzer
2021-07-23 8:22 ` [Linaro-mm-sig] " Christian König
2021-07-23 9:02 ` Daniel Vetter
-1 siblings, 2 replies; 11+ messages in thread
From: Michel Dänzer @ 2021-07-23 8:19 UTC (permalink / raw)
To: Christian König; +Cc: linaro-mm-sig, linux-kernel, dri-devel, linux-media
On 2021-07-23 10:04 a.m., Christian König wrote:
> Am 23.07.21 um 09:58 schrieb Michel Dänzer:
>> From: Michel Dänzer <mdaenzer@redhat.com>
>>
>> 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.
>
> I was also wondering the same thing while working on this, but then thought that the poll interface would take care of this.
I was able to hit the BUG_ON with https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880 .
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
>> ---
>> drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
>> 1 file changed, 12 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
>> index 6c520c9bd93c..ec25498a971f 100644
>> --- a/drivers/dma-buf/dma-buf.c
>> +++ b/drivers/dma-buf/dma-buf.c
>> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
>> BUG_ON(dmabuf->vmapping_counter);
>> /*
>> - * Any fences that a dma-buf poll can wait on should be signaled
>> - * before releasing dma-buf. This is the responsibility of each
>> - * driver that uses the reservation objects.
>> - *
>> - * If you hit this BUG() it means someone dropped their ref to the
>> - * dma-buf while still having pending operation to the buffer.
>> + * If you hit this BUG() it could mean:
>> + * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
>> + * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
>> */
>> BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
>> @@ -196,6 +193,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)
>> {
>> 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;
>> spin_lock_irqsave(&dcb->poll->lock, flags);
>> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
>> dcb->active = 0;
>> spin_unlock_irqrestore(&dcb->poll->lock, flags);
>> dma_fence_put(fence);
>> + /* Paired with get_file in dma_buf_poll */
>> + fput(dmabuf->file);
>
> Is calling fput() in interrupt context ok? IIRC that could potentially sleep.
Looks fine AFAICT: It has
if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
and as a fallback for that, it adds the file to a lock-less delayed_fput_list which is processed by a workqueue.
--
Earthling Michel Dänzer | https://redhat.com
Libre software enthusiast | Mesa and X developer
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Linaro-mm-sig] [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
2021-07-23 8:19 ` Michel Dänzer
@ 2021-07-23 8:22 ` Christian König
2021-11-03 14:50 ` Michel Dänzer
2021-07-23 9:02 ` Daniel Vetter
1 sibling, 1 reply; 11+ messages in thread
From: Christian König @ 2021-07-23 8:22 UTC (permalink / raw)
To: Michel Dänzer, Christian König
Cc: linaro-mm-sig, linux-kernel, dri-devel, linux-media
Am 23.07.21 um 10:19 schrieb Michel Dänzer:
> On 2021-07-23 10:04 a.m., Christian König wrote:
>> Am 23.07.21 um 09:58 schrieb Michel Dänzer:
>>> From: Michel Dänzer <mdaenzer@redhat.com>
>>>
>>> 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.
>> I was also wondering the same thing while working on this, but then thought that the poll interface would take care of this.
> I was able to hit the BUG_ON with https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880 .
>
>
>>> Cc: stable@vger.kernel.org
>>> Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
>>> ---
>>> drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
>>> 1 file changed, 12 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
>>> index 6c520c9bd93c..ec25498a971f 100644
>>> --- a/drivers/dma-buf/dma-buf.c
>>> +++ b/drivers/dma-buf/dma-buf.c
>>> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
>>> BUG_ON(dmabuf->vmapping_counter);
>>> /*
>>> - * Any fences that a dma-buf poll can wait on should be signaled
>>> - * before releasing dma-buf. This is the responsibility of each
>>> - * driver that uses the reservation objects.
>>> - *
>>> - * If you hit this BUG() it means someone dropped their ref to the
>>> - * dma-buf while still having pending operation to the buffer.
>>> + * If you hit this BUG() it could mean:
>>> + * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
>>> + * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
>>> */
>>> BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
>>> @@ -196,6 +193,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)
>>> {
>>> 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;
>>> spin_lock_irqsave(&dcb->poll->lock, flags);
>>> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
>>> dcb->active = 0;
>>> spin_unlock_irqrestore(&dcb->poll->lock, flags);
>>> dma_fence_put(fence);
>>> + /* Paired with get_file in dma_buf_poll */
>>> + fput(dmabuf->file);
>> Is calling fput() in interrupt context ok? IIRC that could potentially sleep.
> Looks fine AFAICT: It has
>
> if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
>
> and as a fallback for that, it adds the file to a lock-less delayed_fput_list which is processed by a workqueue.
Ah, yes that makes sense.
Fell free to add Reviewed-by: Christian König <christian.koenig@amd.com>
Thanks,
Christian.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
2021-07-23 8:19 ` Michel Dänzer
@ 2021-07-23 9:02 ` Daniel Vetter
2021-07-23 9:02 ` Daniel Vetter
1 sibling, 0 replies; 11+ messages in thread
From: Daniel Vetter @ 2021-07-23 9:02 UTC (permalink / raw)
To: Michel Dänzer
Cc: Christian König, linaro-mm-sig, linux-kernel, dri-devel,
linux-media
On Fri, Jul 23, 2021 at 10:19:49AM +0200, Michel Dänzer wrote:
> On 2021-07-23 10:04 a.m., Christian König wrote:
> > Am 23.07.21 um 09:58 schrieb Michel Dänzer:
> >> From: Michel Dänzer <mdaenzer@redhat.com>
> >>
> >> 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.
> >
> > I was also wondering the same thing while working on this, but then thought that the poll interface would take care of this.
>
> I was able to hit the BUG_ON with https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880 .
igt test would be really lovely. Maybe base something off the
import/export igts from Jason?
-Daniel
>
>
> >> Cc: stable@vger.kernel.org
> >> Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
> >> ---
> >> drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
> >> 1 file changed, 12 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> >> index 6c520c9bd93c..ec25498a971f 100644
> >> --- a/drivers/dma-buf/dma-buf.c
> >> +++ b/drivers/dma-buf/dma-buf.c
> >> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
> >> BUG_ON(dmabuf->vmapping_counter);
> >> /*
> >> - * Any fences that a dma-buf poll can wait on should be signaled
> >> - * before releasing dma-buf. This is the responsibility of each
> >> - * driver that uses the reservation objects.
> >> - *
> >> - * If you hit this BUG() it means someone dropped their ref to the
> >> - * dma-buf while still having pending operation to the buffer.
> >> + * If you hit this BUG() it could mean:
> >> + * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
> >> + * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
> >> */
> >> BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
> >> @@ -196,6 +193,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)
> >> {
> >> 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;
> >> spin_lock_irqsave(&dcb->poll->lock, flags);
> >> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
> >> dcb->active = 0;
> >> spin_unlock_irqrestore(&dcb->poll->lock, flags);
> >> dma_fence_put(fence);
> >> + /* Paired with get_file in dma_buf_poll */
> >> + fput(dmabuf->file);
> >
> > Is calling fput() in interrupt context ok? IIRC that could potentially sleep.
>
> Looks fine AFAICT: It has
>
> if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
>
> and as a fallback for that, it adds the file to a lock-less delayed_fput_list which is processed by a workqueue.
>
>
> --
> Earthling Michel Dänzer | https://redhat.com
> Libre software enthusiast | Mesa and X developer
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
@ 2021-07-23 9:02 ` Daniel Vetter
0 siblings, 0 replies; 11+ messages in thread
From: Daniel Vetter @ 2021-07-23 9:02 UTC (permalink / raw)
To: Michel Dänzer
Cc: linaro-mm-sig, linux-media, Christian König, dri-devel,
linux-kernel
On Fri, Jul 23, 2021 at 10:19:49AM +0200, Michel Dänzer wrote:
> On 2021-07-23 10:04 a.m., Christian König wrote:
> > Am 23.07.21 um 09:58 schrieb Michel Dänzer:
> >> From: Michel Dänzer <mdaenzer@redhat.com>
> >>
> >> 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.
> >
> > I was also wondering the same thing while working on this, but then thought that the poll interface would take care of this.
>
> I was able to hit the BUG_ON with https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880 .
igt test would be really lovely. Maybe base something off the
import/export igts from Jason?
-Daniel
>
>
> >> Cc: stable@vger.kernel.org
> >> Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
> >> ---
> >> drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
> >> 1 file changed, 12 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> >> index 6c520c9bd93c..ec25498a971f 100644
> >> --- a/drivers/dma-buf/dma-buf.c
> >> +++ b/drivers/dma-buf/dma-buf.c
> >> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
> >> BUG_ON(dmabuf->vmapping_counter);
> >> /*
> >> - * Any fences that a dma-buf poll can wait on should be signaled
> >> - * before releasing dma-buf. This is the responsibility of each
> >> - * driver that uses the reservation objects.
> >> - *
> >> - * If you hit this BUG() it means someone dropped their ref to the
> >> - * dma-buf while still having pending operation to the buffer.
> >> + * If you hit this BUG() it could mean:
> >> + * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
> >> + * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
> >> */
> >> BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
> >> @@ -196,6 +193,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)
> >> {
> >> 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;
> >> spin_lock_irqsave(&dcb->poll->lock, flags);
> >> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
> >> dcb->active = 0;
> >> spin_unlock_irqrestore(&dcb->poll->lock, flags);
> >> dma_fence_put(fence);
> >> + /* Paired with get_file in dma_buf_poll */
> >> + fput(dmabuf->file);
> >
> > Is calling fput() in interrupt context ok? IIRC that could potentially sleep.
>
> Looks fine AFAICT: It has
>
> if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
>
> and as a fallback for that, it adds the file to a lock-less delayed_fput_list which is processed by a workqueue.
>
>
> --
> Earthling Michel Dänzer | https://redhat.com
> Libre software enthusiast | Mesa and X developer
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
2021-07-23 9:02 ` Daniel Vetter
(?)
@ 2021-07-23 9:11 ` Michel Dänzer
-1 siblings, 0 replies; 11+ messages in thread
From: Michel Dänzer @ 2021-07-23 9:11 UTC (permalink / raw)
To: Christian König; +Cc: linaro-mm-sig, linux-kernel, dri-devel, linux-media
On 2021-07-23 11:02 a.m., Daniel Vetter wrote:
> On Fri, Jul 23, 2021 at 10:19:49AM +0200, Michel Dänzer wrote:
>> On 2021-07-23 10:04 a.m., Christian König wrote:
>>> Am 23.07.21 um 09:58 schrieb Michel Dänzer:
>>>> From: Michel Dänzer <mdaenzer@redhat.com>
>>>>
>>>> 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.
>>>
>>> I was also wondering the same thing while working on this, but then thought that the poll interface would take care of this.
>>
>> I was able to hit the BUG_ON with https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880 .
>
> igt test would be really lovely. Maybe base something off the
> import/export igts from Jason?
I'll see what I can do, busy with other stuff right now though.
--
Earthling Michel Dänzer | https://redhat.com
Libre software enthusiast | Mesa and X developer
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Linaro-mm-sig] [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
2021-07-23 8:22 ` [Linaro-mm-sig] " Christian König
@ 2021-11-03 14:50 ` Michel Dänzer
2021-11-04 8:20 ` Christian König
0 siblings, 1 reply; 11+ messages in thread
From: Michel Dänzer @ 2021-11-03 14:50 UTC (permalink / raw)
To: Christian König, Christian König
Cc: linaro-mm-sig, linux-kernel, dri-devel, linux-media
On 2021-07-23 10:22, Christian König wrote:
> Am 23.07.21 um 10:19 schrieb Michel Dänzer:
>> On 2021-07-23 10:04 a.m., Christian König wrote:
>>> Am 23.07.21 um 09:58 schrieb Michel Dänzer:
>>>> From: Michel Dänzer <mdaenzer@redhat.com>
>>>>
>>>> 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.
>>> I was also wondering the same thing while working on this, but then thought that the poll interface would take care of this.
>> I was able to hit the BUG_ON with https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880 .
>>
>>
>>>> Cc: stable@vger.kernel.org
>>>> Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
>>>> ---
>>>> drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
>>>> 1 file changed, 12 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
>>>> index 6c520c9bd93c..ec25498a971f 100644
>>>> --- a/drivers/dma-buf/dma-buf.c
>>>> +++ b/drivers/dma-buf/dma-buf.c
>>>> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
>>>> BUG_ON(dmabuf->vmapping_counter);
>>>> /*
>>>> - * Any fences that a dma-buf poll can wait on should be signaled
>>>> - * before releasing dma-buf. This is the responsibility of each
>>>> - * driver that uses the reservation objects.
>>>> - *
>>>> - * If you hit this BUG() it means someone dropped their ref to the
>>>> - * dma-buf while still having pending operation to the buffer.
>>>> + * If you hit this BUG() it could mean:
>>>> + * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
>>>> + * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
>>>> */
>>>> BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
>>>> @@ -196,6 +193,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)
>>>> {
>>>> 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;
>>>> spin_lock_irqsave(&dcb->poll->lock, flags);
>>>> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
>>>> dcb->active = 0;
>>>> spin_unlock_irqrestore(&dcb->poll->lock, flags);
>>>> dma_fence_put(fence);
>>>> + /* Paired with get_file in dma_buf_poll */
>>>> + fput(dmabuf->file);
>>> Is calling fput() in interrupt context ok? IIRC that could potentially sleep.
>> Looks fine AFAICT: It has
>>
>> if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
>>
>> and as a fallback for that, it adds the file to a lock-less delayed_fput_list which is processed by a workqueue.
>
> Ah, yes that makes sense.
>
> Fell free to add Reviewed-by: Christian König <christian.koenig@amd.com>
Thanks! AFAICT this fix can be merged now for 5.16?
--
Earthling Michel Dänzer | https://redhat.com
Libre software enthusiast | Mesa and Xwayland developer
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Linaro-mm-sig] [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
2021-11-03 14:50 ` Michel Dänzer
@ 2021-11-04 8:20 ` Christian König
0 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2021-11-04 8:20 UTC (permalink / raw)
To: Michel Dänzer, Christian König
Cc: linaro-mm-sig, linux-kernel, dri-devel, linux-media
Am 03.11.21 um 15:50 schrieb Michel Dänzer:
> On 2021-07-23 10:22, Christian König wrote:
>> Am 23.07.21 um 10:19 schrieb Michel Dänzer:
>>> On 2021-07-23 10:04 a.m., Christian König wrote:
>>>> Am 23.07.21 um 09:58 schrieb Michel Dänzer:
>>>>> From: Michel Dänzer <mdaenzer@redhat.com>
>>>>>
>>>>> 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.
>>>> I was also wondering the same thing while working on this, but then thought that the poll interface would take care of this.
>>> I was able to hit the BUG_ON with https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.gnome.org%2FGNOME%2Fmutter%2F-%2Fmerge_requests%2F1880&data=04%7C01%7Cchristian.koenig%40amd.com%7C8d930ab39011481a839c08d99ed95755%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637715479787056688%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=SjxSZIsWkP7ru1iHyL0IY9hN9882ENv7Cy38vzOtqyc%3D&reserved=0 .
>>>
>>>
>>>>> Cc: stable@vger.kernel.org
>>>>> Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
>>>>> ---
>>>>> drivers/dma-buf/dma-buf.c | 18 ++++++++++++------
>>>>> 1 file changed, 12 insertions(+), 6 deletions(-)
>>>>>
>>>>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
>>>>> index 6c520c9bd93c..ec25498a971f 100644
>>>>> --- a/drivers/dma-buf/dma-buf.c
>>>>> +++ b/drivers/dma-buf/dma-buf.c
>>>>> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry)
>>>>> BUG_ON(dmabuf->vmapping_counter);
>>>>> /*
>>>>> - * Any fences that a dma-buf poll can wait on should be signaled
>>>>> - * before releasing dma-buf. This is the responsibility of each
>>>>> - * driver that uses the reservation objects.
>>>>> - *
>>>>> - * If you hit this BUG() it means someone dropped their ref to the
>>>>> - * dma-buf while still having pending operation to the buffer.
>>>>> + * If you hit this BUG() it could mean:
>>>>> + * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
>>>>> + * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
>>>>> */
>>>>> BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
>>>>> @@ -196,6 +193,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)
>>>>> {
>>>>> 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;
>>>>> spin_lock_irqsave(&dcb->poll->lock, flags);
>>>>> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
>>>>> dcb->active = 0;
>>>>> spin_unlock_irqrestore(&dcb->poll->lock, flags);
>>>>> dma_fence_put(fence);
>>>>> + /* Paired with get_file in dma_buf_poll */
>>>>> + fput(dmabuf->file);
>>>> Is calling fput() in interrupt context ok? IIRC that could potentially sleep.
>>> Looks fine AFAICT: It has
>>>
>>> if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
>>>
>>> and as a fallback for that, it adds the file to a lock-less delayed_fput_list which is processed by a workqueue.
>> Ah, yes that makes sense.
>>
>> Fell free to add Reviewed-by: Christian König <christian.koenig@amd.com>
> Thanks! AFAICT this fix can be merged now for 5.16?
I've just pushed it to drm-misc-next-fixes since it won't even apply to
drm-misc-fixes.
Could be that we get requests to backport this because of the CC stable.
Christian.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-11-04 8:20 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 7:58 [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks Michel Dänzer
2021-07-23 7:58 ` Michel Dänzer
2021-07-23 8:04 ` Christian König
2021-07-23 8:04 ` Christian König
2021-07-23 8:19 ` Michel Dänzer
2021-07-23 8:22 ` [Linaro-mm-sig] " Christian König
2021-11-03 14:50 ` Michel Dänzer
2021-11-04 8:20 ` Christian König
2021-07-23 9:02 ` Daniel Vetter
2021-07-23 9:02 ` Daniel Vetter
2021-07-23 9:11 ` Michel Dänzer
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.