All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Cen Zhang <zzzccc427@gmail.com>
Cc: perex@perex.cz, tiwai@suse.com, phucduc.bui@gmail.com,
	cassiogabrielcontato@gmail.com, cezary.rojewski@intel.com,
	kees+treewide@kernel.org, yilinzhang@moonshot.ai, tiwai@suse.de,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, baijiaju1990@gmail.com,
	jjzuming@gmail.com
Subject: Re: [PATCH] ALSA: pcm: Keep linked drain wait entries safe across unlink
Date: Thu, 15 Oct 2026 19:57:10 +0200	[thread overview]
Message-ID: <87a4oe7sp5.wl-tiwai@suse.de> (raw)
In-Reply-To: <pm-alsa-pcm-drain-wait-lifetime-20261014-v1-face1209fbc882aabda2@gmail.com>

On Thu, 15 Oct 2026 19:10:29 +0200,
Cen Zhang wrote:
> 
> snd_pcm_drain() queues an on-stack wait entry on a linked playback
> peer's runtime->sleep. After sleeping, it calls finish_wait() only if
> that runtime is still found in the caller's group, since the peer may
> otherwise have been freed.
> 
> Unlink wakes the group members before removing them, but the generic
> autoremove_wake_function() removes an entry only when the wake succeeds.
> If a signal or timeout has already made the drainer runnable, the entry
> can remain queued after unlink. With unlink performed before DROP at
> final close, the following ordering is possible:
> 
>   Drainer on A                       Final close of linked B
>   ------------                       -----------------------
>   Queue stack wait on B->sleep
>   Signal wakes A: TASK_RUNNING
>                                      snd_pcm_unlink(B)
>                                        Wake returns 0; wait stays queued
>                                        Remove B from the group
>   Cannot find B; skip finish_wait()
>   Return due to the pending signal
>                                      snd_pcm_drop(B)
>                                        Wake traverses the stale wait
> 
> Use a drain-specific wake function that removes the entry under the
> waitqueue lock even when the task is already runnable. Preserve the
> ordinary wake result. This lets unlink detach the stack entry before
> changing membership, while keeping the runtime check around finish_wait()
> so drain does not access a freed peer.
> 
> Also hold the existing group lock from selecting the peer through
> reading its runtime fields and queuing the wait. Releasing it before
> registration lets unlink perform its wake before the entry is queued,
> and can let the peer runtime be freed before it is accessed. Release
> the group lock after registration and on the no-peer exit path.
> 
> Fixes: f57f3df03a8e ("ALSA: pcm: More fine-grained PCM link locking")
> Cc: stable@vger.kernel.org
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>

This doesn't look needed / fitting for the latest code?


Takashi

  reply	other threads:[~2026-10-15 17:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 17:10 [PATCH] ALSA: pcm: Keep linked drain wait entries safe across unlink Cen Zhang
2026-10-15 17:57 ` Takashi Iwai [this message]
2026-10-16  1:02   ` Cen Zhang

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=87a4oe7sp5.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=baijiaju1990@gmail.com \
    --cc=cassiogabrielcontato@gmail.com \
    --cc=cezary.rojewski@intel.com \
    --cc=jjzuming@gmail.com \
    --cc=kees+treewide@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=phucduc.bui@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    --cc=yilinzhang@moonshot.ai \
    --cc=zzzccc427@gmail.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 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.