Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Joonho Lee <mynameisjune111@gmail.com>
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,
	linux-api@vger.kernel.org
Subject: Re: [RFC PATCH 2/2] ALSA: pcm: refresh capture pointers before drain
Date: Thu, 15 Oct 2026 00:20:55 +0900	[thread overview]
Message-ID: <core-drain-linked-lock-reply.cf2e307fcac34b6a@gmail.com> (raw)
In-Reply-To: <87y0c0el29.wl-tiwai@suse.de>

Hi Takashi,

Thanks for the suggestion and thoughts. I tried the smaller change and hit a
recursive locking issue with linked capture streams.

I used a test driver with two linked capture substreams and made the
later member's pointer callback return SNDRV_PCM_POS_XRUN during
drain. This led to the function calls as follows! :

  snd_pcm_do_drain_init()
    snd_pcm_update_hw_ptr()
      snd_pcm_update_hw_ptr0()
        __snd_pcm_xrun()
          snd_pcm_stop()
            snd_pcm_action()
              snd_pcm_stream_group_ref()

The outer drain action already holds the group locks here. Lockdep
reported the recursive acquisition of group->lock for atomic streams and
group->mutex for nonatomic streams. Both tests remained stuck until
the 45-second timeout. Removing the link let both tests complete.

I went back to the notify=false approach from your first sketch, which is keeping the pointer update inside snd_pcm_do_drain_init(). I also
added the guard to the early SNDRV_PCM_POS_XRUN branch, since that
path still called __snd_pcm_xrun(). Drain init then handles the stop,
while ordinary pointer updates keep their existing behavior.

With this change, all 24 linked test cases passed across both locking
modes, including pointer errors, tail reads and reopen/recovery.
KASAN and lockdep stayed quiet. This was tested with a synthetic
driver under ARM64 QEMU; physical-device testing is still pending.

One thing I wanted to check before sending a revision is, how should
drain report a pointer error?

The current change puts the failing member in SETUP and allows a
healthy linked member to keep its tail in DRAINING. A blocking
capture-only drain returns 0 if the rest of the action succeeds,
and reading the failed member afterwards returns -EBADFD.

Would you prefer that behavior, or should we remember the error,
finish stopping all members, and return -EPIPE from drain? My v2 proposal
returned -EPIPE and moved the linked group to XRUN, so this changes
what userspace sees.

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

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  3:30 [RFC PATCH 0/2] ALSA: pcm: preserve capture tail during drain Joonho Lee
2026-10-14  3:30 ` [RFC PATCH 1/2] ALSA: pcm: allow capture reads while draining Joonho Lee
2026-10-14  3:30 ` [RFC PATCH 2/2] ALSA: pcm: refresh capture pointers before drain Joonho Lee
2026-10-14  8:15   ` Takashi Iwai
2026-10-14  8:35     ` Takashi Iwai
2026-10-14 15:20       ` Joonho Lee [this message]
2026-10-14 15:24         ` [RFC PATCH v3 0/2] ALSA: pcm: preserve capture tail during drain Joonho Lee
2026-10-14 15:24           ` [RFC PATCH v3 1/2] ALSA: pcm: allow capture reads while draining Joonho Lee
2026-10-14 15:24           ` [RFC PATCH v3 2/2] ALSA: pcm: refresh capture pointers in the drain action Joonho Lee
2026-10-14 15:33         ` [RFC PATCH 2/2] ALSA: pcm: refresh capture pointers before drain Takashi Iwai
2026-10-14  8:15 ` [RFC PATCH v2 0/2] ALSA: pcm: preserve capture tail during drain Joonho Lee
2026-10-14  8:15   ` [RFC PATCH v2 1/2] ALSA: pcm: allow capture reads while draining Joonho Lee
2026-10-14  8:15   ` [RFC PATCH v2 2/2] ALSA: pcm: refresh capture pointers before drain Joonho Lee

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=core-drain-linked-lock-reply.cf2e307fcac34b6a@gmail.com \
    --to=mynameisjune111@gmail.com \
    --cc=linux-api@vger.kernel.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