linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michel Dänzer" <michel@daenzer.net>
To: "Christian König" <christian.koenig@amd.com>
Cc: linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org
Subject: Re: [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks
Date: Fri, 23 Jul 2021 10:19:49 +0200	[thread overview]
Message-ID: <4cf94f59-f953-f5d7-9901-cfe5fd63bfbc@daenzer.net> (raw)
In-Reply-To: <f5f37693-bfe2-e52f-172b-00f4aa94dbd9@amd.com>

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

  reply	other threads:[~2021-07-23  8:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23  7:58 [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks Michel Dänzer
2021-07-23  8:04 ` Christian König
2021-07-23  8:19   ` Michel Dänzer [this message]
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:11       ` Michel Dänzer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4cf94f59-f953-f5d7-9901-cfe5fd63bfbc@daenzer.net \
    --to=michel@daenzer.net \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).