mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: A Akhil <akhilarul324@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	tiwai@suse.com, perex@perex.cz, linux-sound@vger.kernel.org,
	linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: Sound/seq: hung task in odev_open - unuse callback sleeps under list_mutex
Date: Thu, 17 Sep 2026 16:55:38 +0200	[thread overview]
Message-ID: <874ifogc5x.wl-tiwai@suse.de> (raw)
In-Reply-To: <CACygGA9h-qehZVFxRMOgtt8y-kHMwSCuuvZwBSi_7R0xpp-dRg@mail.gmail.com>

On Thu, 17 Sep 2026 16:11:27 +0200,
A Akhil wrote:
> 
> Hi Takashi,
> 
> Thanks for the quick patch. Right, it's not a deadlock, that was my
> reading of it too. Nothing locks up permanently, it's just a wait long
> enough to trip the detector. That's the reason I bothered with it though.
> On the syzbot run the wait was over 140 s, and for the whole of that
> anything else touching the sequencer is stuck behind it.
> 
> I ran it on the setup I used to find this in the first place. One thread
> opening and closing /dev/sequencer2 while two others try to open it,
> hung_task_timeout_secs=30, three runs each.
> 
>   variant                       hung tasks    worst opener block
>   ---------------------------------------------------------------
>   unpatched                     10, 10, 10    ~130 s
>   your patch                    0, 0, 7       30.7 / 30.6 / 129.9 s
>   yours + open_mutex narrowed   7, 0, 0       129.9 / 41.3 / 40.9 s
>   drain bounded to 1s           0, 0, 0       20.6 / 18.4 / 21.8 s
>   drop instead of drain         0, 0, 0       4.0 / 2.4 / 2.4 s
> 
> Your patch builds clean and clearly helps, two of the three runs were
> completely quiet. The third still hung though, and when it does it's
> coming from the opening side rather than the closing side.
> 
>   task 98:  odev_open                      holds register_mutex
>              snd_seq_oss_open
>               snd_seq_oss_synth_setup_midi
>                snd_seq_oss_midi_open+0x8e  blocked on mdev->open_mutex
>   tasks 97, 99: blocked on register_mutex owned by 98 -> hung task
> 
> An opener grabs register_mutex, blocks deeper down, and sits on it while
> it waits.
> 
> I tried stacking my earlier open_mutex narrowing in snd_seq_oss_midi_close
> on top of yours, so the closer would be holding neither lock over the
> drain. Still hung 1 in 3, and the wait had just moved further down again,
> this time into snd_seq_port_connect() on grp->list_mutex.
> 
> Three attempts at moving locks around now (mine, yours, both together) and
> every one of them just shifts where the wait happens. I don't think the
> locking is really the problem here. It's the 10*HZ per substream.
> 
> Bounding the drain to 1*HZ in midisynth_unuse() does stop the hangs, but
> the cap is per substream and there are about twenty of them, so teardown
> still runs ~20 s. Capping the total across the teardown would do better,
> though that's more surgery.
> 
> The one that actually worked was swapping snd_rawmidi_drain_output() for
> snd_rawmidi_drop_output() in midisynth_unuse(). ~2.4 s, nothing hung in
> any run. Most of what's left there isn't even the data wait, it's the
> msleep(50) per substream for the Tx FIFOs.
> 
> I did wonder about throwing the data away, so I went and looked. As far as
> I can tell snd_rawmidi_drain_output() already drops the buffer once the
> 10*HZ expires, so the bytes are gone either way and dropping early only
> costs whatever the device would have taken during the timeout. For a
> device that isn't draining, which is the case that gets us here, that's
> nothing. Tell me if I've misread that.
> 
> So, do you want me to send the drop version as a proper patch? Or would
> you rather bound the drain, in which case I can try a total cap instead of
> a per substream one. I can also test a revised version of yours if you'd
> prefer to keep this inside seq_oss.

Hm, dropping isn't optimal, as that's a clear behavior change; there
can be pending bytes even in the real use case.

Actually, shortening the drain limit would be an easier way.
Practically seen, 1 second should be enough for the real hardware.
If this is enough for the syzkaller report, we can take it quickly.

Another option would be to offload the snd_seq_kernel_client_ctl()
calls in seq_oss_midi.c snd_seq_oss_midi_open() and close() to a work,
as you pointed out previously.  This would be relatively safe, I
suppose.

In general, I'd like to avoid touching too much outside the OSS
emulation layer.  The shortening of the drain limit would be OK, but
restructuring else isn't preferred.

In anyway, if you can pitch some good workaround, I'll happily take.

(But I'm going to be off from tomorrow, so it'll be continued after my
vacation.)


thanks,

Takashi

  reply	other threads:[~2026-09-17 14:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CACygGA9s1oWO53NPamL5tkaNhUt-W8S736OVAJZcYCU_UOni+A@mail.gmail.com>
2026-09-17 11:07 ` Takashi Iwai
2026-09-17 14:11   ` A Akhil
2026-09-17 14:55     ` Takashi Iwai [this message]
2026-09-17 15:42       ` A Akhil
2026-09-17 16:13         ` Takashi Iwai

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=874ifogc5x.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=akhilarul324@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --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

all inboxes | Powered by JetHome®