From: Takashi Iwai <tiwai@suse.de>
To: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: alsa-devel@alsa-project.org, John Keeping <john@metanate.com>
Subject: Re: [PATCH] ALSA: usb-audio: Fix recursive locking at XRUN during syncing
Date: Thu, 23 Mar 2023 14:37:12 +0100 [thread overview]
Message-ID: <87pm8z612v.wl-tiwai@suse.de> (raw)
In-Reply-To: <20230323132916.GA235532@workstation>
On Thu, 23 Mar 2023 14:29:16 +0100,
Takashi Sakamoto wrote:
>
> On Thu, Mar 23, 2023 at 07:19:45AM +0100, Takashi Iwai wrote:
> > On Tue, 21 Mar 2023 05:02:58 +0100,
> > Takashi Sakamoto wrote:
> > >
> > > Hi,
> > >
> > > On Mon, Mar 20, 2023 at 03:28:38PM +0100, Takashi Iwai wrote:
> > > > The recent support of low latency playback in USB-audio driver made
> > > > the snd_usb_queue_pending_output_urbs() function to be called via PCM
> > > > ack ops. In the new code path, the function is performed alread in
> > >
> > > 's/alread/already/' or slang.
> > >
> > > > the PCM stream lock. The problem is that, when an XRUN is detected,
> > > > the function calls snd_pcm_xrun() to notify, but snd_pcm_xrun() is
> > >
> > > 's/the function/the function/'
> >
> > Corrected at applying.
> >
> > > > supposed to be called only outside the stream lock. As a result, it
> > > > leads to a deadlock of PCM stream locking.
> > > >
> > > > For avoiding such a recursive locking, this patch adds an additional
> > > > check to the code paths in PCM core that call the ack callback; now it
> > > > checks the error code from the callback, and if it's -EPIPE, the XRUN
> > > > is handled in the PCM core side gracefully. Along with it, the
> > > > USB-audio driver code is changed to follow that, i.e. -EPIPE is
> > > > returned instead of the explicit snd_pcm_xrun() call when the function
> > > > is performed already in the stream lock.
> > >
> > > Practically, the implementation of 'pcm_hw' in alsa-lib never evaluates
> > > the return value (see 'snd_pcm_hw_mmap_commit()' and the others). I guess
> > > that it is inconvenient for the low-latency mode of USB Audio device class
> > > driver for the case of failure.
> > >
> > > My additional concern is PCM indirect layer, since typically the layer
> > > is used by drivers with SNDRV_PCM_INFO_SYNC_APPLPTR. But as long as I
> > > read, the change does not matter to them.
> >
> > I find rather that's an extra bonus :) It allows the existing code to
> > give a more proper error handling. For example, the indirect PCM
> > helper returned -EINVAL, but this can be switched to -EPIPE for
> > stopping the stream.
> >
> > I'm going to submit the patch together with the documentation
> > updates.
>
> In my opinion, extra care is required for the simple replacement of
> -EINVAL with -EPIPE, since it may not come from any operation relevant
> to hardware. In my understanding, it comes from just careless
> implementation of user space PCM application, thus it is still reasonable
> to return -EINVAL.
Yeah, we can't always replace such condition blindly. But in the case
of indirect PCM helpers, it's the place where the bogus values have
been already set and processed, so we can't return -EINVAL, hence an
XRUN notification would be appreciate.
Takashi
prev parent reply other threads:[~2023-03-23 13:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-20 14:28 [PATCH] ALSA: usb-audio: Fix recursive locking at XRUN during syncing Takashi Iwai
2023-03-20 14:42 ` Jaroslav Kysela
2023-03-21 4:02 ` Takashi Sakamoto
2023-03-21 4:23 ` Takashi Sakamoto
2023-03-23 6:19 ` Takashi Iwai
2023-03-23 13:29 ` Takashi Sakamoto
2023-03-23 13:37 ` 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=87pm8z612v.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=john@metanate.com \
--cc=o-takashi@sakamocchi.jp \
/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.