mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ali Ahmet Memiş" <aliamemis@disroot.org>
To: Takashi Iwai <tiwai@suse.de>
Cc: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ALSA: control_led: Fix deadlock between sysfs writes and card disconnect
Date: Mon, 12 Oct 2026 17:12:35 +0300	[thread overview]
Message-ID: <20261012141238.1823718-1-aliamemis@disroot.org> (raw)
In-Reply-To: <874ieridp1.wl-tiwai@suse.de>

On Mon, 12 Oct 2026 09:24:26 +0200, Takashi Iwai wrote:
> Hm, it's not clear to me how this happens: I see no controls_rwsem
> down around snd_ctl_led_disconnect() call.  Could you elaborate about
> it a bit more?

It's taken in the call_snd_ctl_lops() macro in control.c:

	guard(rwsem_read)(&(_card)->controls_rwsem);
	guard(rwsem_read)(&snd_ctl_layer_rwsem);

so snd_ctl_dev_disconnect() calls ->ldisconnect() with controls_rwsem
held for read.  snd_ctl_led_sysfs_remove() then waits in kernfs_drain()
for the attach write which is blocked on down_write(controls_rwsem) in
snd_ctl_led_set_id().

I hit it in QEMU with snd-dummy writing to attach in a loop while
unloading the module.  It hung on the third iteration:

rmmod:
[<0>] kernfs_drain+0x2eb/0x510
[<0>] __kernfs_remove+0x2e6/0x890
[<0>] kernfs_remove_by_name_ns+0x7d/0x100
[<0>] remove_files+0x8d/0x1b0
[<0>] sysfs_remove_group+0x71/0xd0
[<0>] sysfs_remove_groups+0x67/0xd0
[<0>] device_remove_attrs+0x181/0x270
[<0>] device_del+0x31f/0x8d0
[<0>] device_unregister+0x12/0x30
[<0>] snd_ctl_led_sysfs_remove+0x161/0x2f0
[<0>] snd_ctl_led_disconnect+0x16/0xd0
[<0>] snd_ctl_dev_disconnect+0x151/0x210
[<0>] snd_device_disconnect_all+0xf0/0x180
[<0>] snd_card_disconnect.part.0+0x25d/0x4c0

attach writer:
[<0>] set_led_id+0x2d9/0xc60
[<0>] kernfs_fop_write_iter+0x33c/0x510
[<0>] vfs_write+0x516/0x1340

and lockdep reports it as well:

  Possible unsafe locking scenario:
        CPU0                    CPU1
        ----                    ----
   rlock(snd_ctl_layer_rwsem);
                                lock(&card->controls_rwsem);
                                lock(snd_ctl_layer_rwsem);
   lock(kn->active#37);

   #1: ffff88800768a1f0 (&card->controls_rwsem){++++}-{4:4}, at: snd_ctl_dev_disconnect+0x10e/0x210
   #2: ffffffff881fdf28 (snd_ctl_layer_rwsem){++++}-{4:4}, at: snd_ctl_dev_disconnect+0x11a/0x210

  reply	other threads:[~2026-10-12 14:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 18:06 Ali Ahmet Memiş
2026-10-12  7:24 ` Takashi Iwai
2026-10-12 14:12   ` Ali Ahmet Memiş [this message]
2026-10-12 14:51     ` 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=20261012141238.1823718-1-aliamemis@disroot.org \
    --to=aliamemis@disroot.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /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®