From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795915911; b=wLqsrYtFGJtrihpSk+n62VtFbcGDZDpxtPAzYXK6hbT64EZsYzsaEleoJqfOTlaDMSf1 ZluPeqIM3j8m6uqmfNLGg0zl65cOAWAeod5YxqpWpzZ2ycTZyCS0XWswTkASolssQe7gQ jmj0E6GfVw5dA7IYKSHrdp/WyXHGcG0S03LXVtxXvM85XsM8Gm12NScjQyxZC2ZBvCPc7 WzKJt9gIrUhIAD8SEEeC9tylFZbobC2Y+oKd5qfkD5zVNQYjxv42omu3DIroy2hun194u ddvrOC5VUL1nlgpsG+xXYdMt4M5NHbLRFgQYw3sNFMb4CovxDZXJ38FYyPMSDNr45Fw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795915911; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=LebouWhzI6BXFkDvpkHKJZZMoKFr5Zt36qzXA3wsoWQ=; b=QJWB58ohiiyHi3bokJTVWj5/ziowXi7MEs3YWipMBPxo/+00x6fZnqVzyVMEER/ZdCMX CtYTDSn51rc1AwkOiAMNlYaPl1Ybv+X5KHP5N2818NUd2sldc9WoL2IhykHwz8EGIxzTD tirdMnNd860iV60gC82ShWkVBxBHBoiKwzsqIbjtoiZH1fyg+bgMONOsOfZic2rpuNcoj kNq0A0JocRQjS5TGGnTB8dPSrstAMFaK9wVu/I5RkONDrdbPrl8f7Ds0nWz1+k+MvmuTA ern3rNEemGsj7ngMWjgvFQwvT4Kyha5YKGo2t+s6uUg85i8Bb+pNz9ojq+NtwZCyffA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oIZAMGX2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24F9F606A31C for ; Sun, 29 Nov 2026 01:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oIZAMGX2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFD241F000C1; Sun, 29 Nov 2026 01:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795915911; bh=LebouWhzI6BXFkDvpkHKJZZMoKFr5Zt36qzXA3wsoWQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=oIZAMGX2NUSKUylvYpV/mh1FtT8806OCWcXOm750aXH2WIZYZ11n8iR293DN2dH8c Xezpj9WQa3VRjcZrB/husJDJAPwAlkEoezXOZoAN27kcyulhs16P0nw5YqQVPLAUJp xes71+lXiBgwu1DToO0zSdwL8vL2owjdhjoStRfkfDmxVZx7csNygm3mSWRWDKm5t6 sm32pG+z+sWGHs5sHMcjgMiBQyacvjG0EjXChNcXEh+kkCu70fWEqan4hyJ0B3XUIc usv1hnRsxc7Qawf7jyzyI0xY4tNbN1cupvvsCbY+VfcOkg0alUDJyIhfgoSbM/e4+u IDtLBAnztx+sQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Reply-To: sashiko-reviews@lists.linux.dev To: "Vladimir Bely" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261129011802.1025539-3-vlwwwwww@gmail.com> References: <20261129001951.991080-1-vlwwwwww@gmail.com> <20261129011802.1025539-3-vlwwwwww@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 01:31:50 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] ASoC: qcom: q6asm-dai: full SMD FIFO in q6asm_dai_ack() breaks trigger start - [Low] ASoC: qcom: q6asm-dai: redundant stream lock cycle in event_handler() - [Low] ASoC: qcom: q6asm-dai: wrong commit subject in Fixes trailer -- commit 2a93925c1ef34ca2638692fd522578e41fe20e98 Author: Vladimir Bely > ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN > > q6asm_dai_ack() sends one ASM_DATA_CMD_WRITE_V2 APR packet per available > period in a tight loop. On SoCs with a small SMD FIFO (such as MSM8916), > an initial playback write burst or a buffer with many periods can fill the > FIFO, making rpmsg_trysend() return -EAGAIN. q6asm_dai_ack() currently > aborts and propagates -EAGAIN to ALSA, causing userspace writes to fail > and playback to stall. > > Move playback period queuing into a helper q6asm_dai_queue_playback() > called with the PCM stream lock held. Handle appl_ptr wrap around > runtime->boundary, guard against appl_ptr moving behind queue_ptr (e.g. > on SNDRV_PCM_IOCTL_RESET or appl_ptr rollback) by requiring > avail <=3D runtime->buffer_size, and stop cleanly on -EAGAIN without > returning an error. Retry from event_handler() on > ASM_CLIENT_EVENT_DATA_WRITE_DONE under pcm_stream_lock_irqsave only when > snd_pcm_running(substream) is true, so queuing stays serialized with ack, > stop, XRUN, prepare, and close. > > Fixes: e386c2cf3df2 ("ASoC: qdsp6: q6asm: Add q6asm dai driver") > Cc: stable@vger.kernel.org > Signed-off-by: Vladimir Bely [Severity: Low] The subject in the Fixes: tag belongs to commit 2a9e92d371db ("ASoC: qdsp6: q6asm: Add q6asm dai driver"). Should this be: Fixes: e386c2cf3df2 ("ASoC: qcom: q6asm-dai: schedule all available frame= s to avoid dsp under-runs") > diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6as= m-dai.c > index 57cbce2bb0cb7..b2856e7a28e0d 100644 > --- a/sound/soc/qcom/qdsp6/q6asm-dai.c > +++ b/sound/soc/qcom/qdsp6/q6asm-dai.c > @@ -179,6 +179,40 @@ static const struct snd_compr_codec_caps q6asm_compr= _caps =3D { > .descriptor[0].formats =3D 0, > }; > =20 > +/* > + * Queue the periods the application has written so far. Each period is = one > + * APR packet sent with rpmsg_trysend(), and a burst can fill the small = SMD > + * FIFO (-EAGAIN). That is not an error: stop and retry when the DSP han= ds a > + * buffer back (DATA_WRITE_DONE). Caller must hold the PCM stream lock. > + */ > +static int q6asm_dai_queue_playback(struct q6asm_dai_rtd *prtd) > +{ > + struct snd_pcm_runtime *runtime =3D prtd->substream->runtime; > + int ret; > + > + while (prtd->state =3D=3D Q6ASM_STREAM_RUNNING) { > + snd_pcm_sframes_t avail =3D runtime->control->appl_ptr - prtd->queue_p= tr; > + > + if (avail < 0) > + avail +=3D runtime->boundary; > + if (avail < runtime->period_size || avail > runtime->buffer_size) > + break; > + > + ret =3D q6asm_write_async(prtd->audio_client, prtd->stream_id, > + prtd->pcm_count, 0, 0, 0); > + if (ret =3D=3D -EAGAIN) > + break; > + if (ret < 0) > + return ret; > + > + prtd->queue_ptr +=3D runtime->period_size; > + if (prtd->queue_ptr >=3D runtime->boundary) > + prtd->queue_ptr -=3D runtime->boundary; > + } > + > + return 0; > +} [Severity: High] Can filling the SMD FIFO in q6asm_dai_queue_playback() cause the subsequent SNDRV_PCM_TRIGGER_START to fail with -EAGAIN? q6asm_dai_prepare() sets prtd->state =3D Q6ASM_STREAM_RUNNING while runtime->state is still SNDRV_PCM_STATE_PREPARED. When an initial write burst in __snd_pcm_lib_xfer() reaches runtime->start_threshold, pcm_lib_apply_appl_ptr() calls q6asm_dai_ack() -> q6asm_dai_queue_playback() before calling snd_pcm_start(): sound/core/pcm_lib.c:__snd_pcm_lib_xfer() { ... err =3D pcm_lib_apply_appl_ptr(substream, appl_ptr); if (err < 0) goto _end_unlock; ... if (is_playback && runtime->state =3D=3D SNDRV_PCM_STATE_PREPARED && snd_pcm_playback_hw_avail(runtime) >=3D (snd_pcm_sframes_t)runtime->s= tart_threshold) { err =3D snd_pcm_start(substream); if (err < 0) goto _end_unlock; } ... } If q6asm_dai_queue_playback() fills the SMD FIFO until q6asm_write_async() returns -EAGAIN and then returns 0, the immediately following snd_pcm_start() -> q6asm_dai_trigger(SNDRV_PCM_TRIGGER_START) -> q6asm_run_nowait() tries to send ASM_SESSION_CMD_RUN_V2 via rpmsg_trysend() on the same exhausted SMD FIFO and fails with -EAGAIN. snd_pcm_start() then runs snd_pcm_undo_start() and leaves runtime->state in SNDRV_PCM_STATE_PREPARED with prtd->queue_ptr and port->dsp_buf already advanced, while __snd_pcm_lib_xfer() returns the positive xfer count to userspace. Because the DSP stream never starts (or whenever -EAGAIN is hit with no buffers in flight on the DSP), ASM_CLIENT_EVENT_DATA_WRITE_DONE never fires and playback stalls permanently. > @@ -192,6 +226,15 @@ static void event_handler(uint32_t opcode, uint32_t = token, > break; > case ASM_CLIENT_EVENT_DATA_WRITE_DONE: > snd_pcm_period_elapsed(substream); > + /* Push any periods left behind by a full SMD FIFO */ > + if (substream) { > + scoped_guard(pcm_stream_lock_irqsave, substream) { > + if (substream->runtime && > + snd_pcm_running(substream) && > + q6asm_dai_queue_playback(prtd) < 0) > + pr_err_ratelimited("q6asm-dai: Error queuing playback buffer\n"); > + } > + } > break; [Severity: Low] snd_pcm_period_elapsed() already takes and releases pcm_stream_lock_irqsave(substream) around snd_pcm_period_elapsed_under_stream_lock(). Calling snd_pcm_period_elapsed_under_stream_lock(substream) and q6asm_dai_queue_playback(prtd) under a single scoped_guard(pcm_stream_lock_irqsave, substream) (as q6apm-dai does) would avoid taking the stream lock twice on every period and queue pending periods before releasing the lock to woken userspace writers. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129011802.1025= 539-1-vlwwwwww@gmail.com?part=3D2