public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Edward Adam Davis <eadavis@qq.com>
Cc: tiwai@suse.de, linux-kernel@vger.kernel.org,
	linux-sound@vger.kernel.org, perex@perex.cz,
	syzbot+73582d08864d8268b6fd@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com, tiwai@suse.com
Subject: Re: [PATCH] usb: fix a task hung in snd_card_free
Date: Wed, 13 Nov 2024 07:48:04 +0100	[thread overview]
Message-ID: <87servsk7v.wl-tiwai@suse.de> (raw)
In-Reply-To: <tencent_F41B22255CBA04BB3B33319E461BFF4B3708@qq.com>

On Wed, 13 Nov 2024 02:48:49 +0100,
Edward Adam Davis wrote:
> 
> On Tue, 12 Nov 2024 17:04:04 +0100, Takashi Iwai wrote:
> > On Wed, 06 Nov 2024 03:15:49 +0100,
> > Edward Adam Davis wrote:
> > >
> > > task 1: snd ctrl will add card_dev ref count and can't call close to dec it,
> > >         it is blocked waiting for task 2 to release the USB dev lock.
> > >
> > > task 2: usb dev lock has been locked by hung task (here is usb_disconnect),
> > >         it is hung waiting for task 1 to exit and release card_dev.
> > >
> > > Adjust the USB lock acquisition method to non-blocking in ioctl to avoid
> > > hang when the USB connection is closed.
> > 
> > I'm afraid that this change would break things too badly.
> > i.e. changing the blocking behavior to non-blocking is no-go.
> > 
> > > Reported-and-tested-by: syzbot+73582d08864d8268b6fd@syzkaller.appspotmail.com
> > > Closes: https://syzkaller.appspot.com/bug?extid=73582d08864d8268b6fd
> > 
> > This particular syzkaller entry can be fixed rather by replacing
> > snd_card_free() in snd_usx2y_disconnect() with
> > snd_card_free_when_closed() like other USB audio drivers, something
> > like below.
> > 
> > Judging from the git log, it had been with snd_card_free_in_thread(),
> > but was switch to snd_card_free() around year 2005.  Meanwhile the
> > handling of async card release got improved, and it's very likely OK
> > to use snd_card_free_when_closed() there with the recent kernel.
> The snd_card instance will be released in snd_card_do_free().
> So, if snd_card_free_when_closed() is used to replace snd_card_free(), who will release the snd_card instance?

Via the release callback of the card device object, which is triggered
at the last close by refcounting.


Takashi

> 
> BR,
> Edward
> > 
> > 
> > thanks,
> > 
> > Takashi
> > 
> > -- 8< --
> > --- a/sound/usb/usx2y/usbusx2y.c
> > +++ b/sound/usb/usx2y/usbusx2y.c
> > @@ -422,7 +422,7 @@ static void snd_usx2y_disconnect(struct usb_interface *intf)
> >  	}
> >  	if (usx2y->us428ctls_sharedmem)
> >  		wake_up(&usx2y->us428ctls_wait_queue_head);
> > -	snd_card_free(card);
> > +	snd_card_free_when_closed(card);
> >  }
> > 
> >  static int snd_usx2y_probe(struct usb_interface *intf,
> 
> 

      reply	other threads:[~2024-11-13  6:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-03  0:09 [syzbot] [sound?] INFO: task hung in snd_card_free syzbot
2024-11-03  1:28 ` Hillf Danton
2024-11-03  1:49   ` syzbot
2024-11-05  2:37 ` Edward Adam Davis
2024-11-05  3:12   ` syzbot
2024-11-05  3:59 ` Edward Adam Davis
2024-11-05  4:18   ` syzbot
2024-11-05  5:03 ` Edward Adam Davis
2024-11-05  5:23   ` syzbot
2024-11-05  6:57 ` Edward Adam Davis
2024-11-05  7:31   ` syzbot
2024-11-05  8:54 ` Edward Adam Davis
2024-11-05 10:52   ` syzbot
2024-11-05 11:22 ` Edward Adam Davis
2024-11-05 21:06   ` syzbot
2024-11-06  1:37 ` Edward Adam Davis
2024-11-06  2:02   ` syzbot
2024-11-06  2:15 ` [PATCH] usb: fix a " Edward Adam Davis
2024-11-12 16:04   ` Takashi Iwai
2024-11-13  1:48     ` Edward Adam Davis
2024-11-13  6:48       ` Takashi Iwai [this message]

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=87servsk7v.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=eadavis@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=syzbot+73582d08864d8268b6fd@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tiwai@suse.com \
    /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