Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795944037; b=JD1ivqtcOSvyhhnkFiu/X8N+SSfuzvvnPwn7wWJG9o8OmHOqEXGI4XATf7kmvXcB6326 RKT1eUsCDqraXk9GgHWK9wzg3q5M/7TReLZS4uZC/pxZg56VVFlFqUZUskWuWSCb0THBR VCv7zW0luIYB7ppQVuaNN53givfria8/He671xetDhgE4agqWraQf7wC/XZJU/pbmJH1+ 2NTUYn3L4f3D56f1JHhJDI0SIHYwwFxdpT08uvgCadIgIds1bXPeo5bzj7+L5bn+Q84d9 SZ440RizWGqIc//HZSWgYJKC4r7s/Xq3/Ky1s+ZgTD14Fqgpw+KEE8rpdLSC3jv2+FQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795944037; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=39iGWRRQqR8yKv0AwomLNItSoTikitqdAru2JhevBow=; b=qaTvZ3IvTbrp7oNvVxzAZYSUkMKuA6G3ZYIM9bGQSQ7ydNoftPDswFyIDjJYSxmOmNEx twcM0Oia2KvwpB/asKX49b+ziRF4wo8m2jUx1WBOo3c1gojKSf4gysz9MkHeOq1Jfaa4+ IC51UDw7HtlyrK2msQH+z4blj73eY4yjpXbS4tyt/AdrJMqEpVe4zG05UT9Vcoic1AIPB 2xN4Lgf9D5fd93gKgV5oW5Qn3Dd5LPh7bIybnWSkYFocCtbonJPLpVTwVjPfZKXNc7iL6 H3wJaxHb4ZnjTcw8BVXIP6bXP/j86paXtH6d5h9RNNSDey4FtU61mBBJ1YSL1NpQOFQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qMfnx6r5; arc=none smtp.remote-ip=209.85.221.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B681606A68D for ; Sun, 29 Nov 2026 09:20:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B681606A68D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qMfnx6r5 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-4c3f0acc1easo222986f8f.0 for ; Sun, 29 Nov 2026 01:20:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795944036; x=1796548836; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=39iGWRRQqR8yKv0AwomLNItSoTikitqdAru2JhevBow=; b=qMfnx6r5UeufdRFyEASwuUPRG44+sZtUud8dqKlsiCyBMfP34U0pzJdkJu6CQprCNJ 1djqfqgGvf+76XtFoP+Opr09iFqBaH8My6lOGThySH+RL0duGSGqVntqeoigJ2XrLwzb 8CRYLfcffYpgkfHNth1gWRnHtirQw+dzKZE/onvLltOl5PQeA7W+z1xYiYUZryiiVWoi 0TfUZBPd/bqcATcJJ47TeKYDOGo9Kq2rOxrm6y/upIAY8CvmcONJ1ge7cZy50uMz9WOE mWjHltxpSkMJ+C4CU+W1Lz9OtOMUOLvjImx15vw7wDYwwCUYst0Dr8RI0X16YXv+CF6v +/FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795944036; x=1796548836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=39iGWRRQqR8yKv0AwomLNItSoTikitqdAru2JhevBow=; b=BYtcGt0aQmqmhPakwvw0Pix3eenWg0/TDQiFCNLK4xcRh3VCsxLthV8NQUQbVW8BdV nwtDuTf1UNwWUZT2I6E2XnrsbpdPo2jU9ziETECsKB2L0NEI9yK7+CNI97f/prqUnQPG lYk013+dROFCcc/69/ctiaS7lrXB4QatGxoOgooj5xU/lV+A0HX2Os7L4wnDOBIzFVou IITTgAewnjrgzTmWk90vYfmPhsvRey6snOlAaBCJ8V0WmOavwE4WOHXX10oLVw+jRSVc i0sQO3zltbzvFz5B/FhwlGlAdCwmm2J0chKTDKQuMztyeJhIYX1VDtcnbssF3blZWdAZ LgrA== X-Forwarded-Encrypted: i=1; AL+hErHu6isH3H7RoHdSDhLLZsQVU20I1uJMcdFcmBYZfDXMRPXGJqCRk1Ck1qQxB7PhzkBuBsqO9m+HANcq36e4@vger.kernel.org X-Gm-Message-State: APuU4Z9KF2kcctiYIt7JcUyJF/zgxYxBNPMeVdfm0RlNMDbjdo1IFGol s8Zr7CwVkRuR+kcu/YVB/BjwE+65LHQMtPbOqcyiUYntipyM/praDrzQ X-Gm-Gg: AZFdTZdyRCOlGT9AfLqGkXV8CDtW02PwFBiD7dO4VogNX5Eso1KJW75mL7+XMmMMMpP dnG6vz34Gqh4YUH/Lf5NjxWc9Ip/vksvtk2zG/p0n3K4HJqZXeEyOrYweSBKTz9XKU5keXYyei8 scxcC6Q1K5DqLL+B/0wnMVlQKMI2I4JJ6iDLZ3YSUB/tdHAI6KPayjOaUnRGKeIox36A7NsCQSa iVR+rcIYn1GFEzDhgSbbfZExvWtZARYCV+84laY7pgkNx+QcUyXLFj2blMl0NymrzSImxrMUEaH N2E74mK0fERle4Hlg82Ht1gwg4UADLa8O4u4goMyGdFshZFFFDvEe3oqGTf+xDXmzCY0yHqv0jk H/7KQPUHVMfoJK1iIN/Wxx+B171ZC9anW09Qjzn7DbyUxKZLnguaal2ergywzwh/XNcspSOkE9F 0q6hMEBeWeWZb8G1TMnyi+odp+c7hSaR2FkeX91n2TvcEiQ3VveG3ZeMzhewUQ8pU4/NJWv5Z3I 3eKjvGPLBpfcGaj2j67l7GZXF6O7Jj0nzsZezoGBZzxDzY2VwLKRq1HisVe3jrf236dABblHr6z v75w8B/wxqfnnfYXUMJ/O94iN1va0/RoGoODnKkrEkLWorzr7Wb4ShaJU50Nq39p75hDXorQ8/k = X-Received: by 2002:a05:6000:41d2:b0:4a7:5eea:fd1a with SMTP id ffacd0b85a97d-4abab4f5a9fmr59034510f8f.1.1795944035576; Sun, 29 Nov 2026 01:20:35 -0800 (PST) Received: from vlw-PC.. (static.18.103.245.188.clients.your-server.de. [188.245.103.18]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b205443sm60800423f8f.39.2026.11.29.01.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 01:20:34 -0800 (PST) From: Vladimir Bely To: Srinivas Kandagatla , Liam Girdwood , Mark Brown Cc: Jaroslav Kysela , Takashi Iwai , linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Vladimir Bely , stable@vger.kernel.org Subject: [PATCH v3 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Date: Sun, 29 Nov 2026 12:20:28 +0300 Message-ID: <20261129092028.239529-3-vlwwwwww@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261129011802.1025539-1-vlwwwwww@gmail.com> References: <20261129011802.1025539-1-vlwwwwww@gmail.com> X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 <= runtime->buffer_size, and stop cleanly on -EAGAIN without returning an error. Defer playback queuing in q6asm_dai_ack() until snd_pcm_running(substream) and queue initial periods in q6asm_dai_trigger() after q6asm_run_nowait() succeeds so a pre-start burst cannot exhaust the SMD FIFO and fail SNDRV_PCM_TRIGGER_START with -EAGAIN. Retry any remaining periods in event_handler() on ASM_CLIENT_EVENT_CMD_RUN_DONE and under a single pcm_stream_lock_irqsave critical section with snd_pcm_period_elapsed_under_stream_lock() on ASM_CLIENT_EVENT_DATA_WRITE_DONE. Fixes: e386c2cf3df2 ("ASoC: qcom: q6asm-dai: schedule all available frames to avoid dsp under-runs") Cc: stable@vger.kernel.org Signed-off-by: Vladimir Bely --- Changes in v3: - Only queue in q6asm_dai_ack() when snd_pcm_running(substream), queue initial playback periods in q6asm_dai_trigger() after q6asm_run_nowait() succeeds, and retry on ASM_CLIENT_EVENT_CMD_RUN_DONE so a full SMD FIFO cannot fail SNDRV_PCM_TRIGGER_START with -EAGAIN (reported by Sashiko AI). - Use snd_pcm_period_elapsed_under_stream_lock() inside the same pcm_stream_lock_irqsave guard in event_handler(). - Fix the Fixes: trailer subject. Changes in v2: - Bound avail <= runtime->buffer_size and serialize event_handler() via pcm_stream_lock_irqsave + snd_pcm_running(substream). sound/soc/qcom/qdsp6/q6asm-dai.c | 75 ++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c index 57cbce2bb..b88f431de 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 = { .descriptor[0].formats = 0, }; +/* + * 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 signals + * CMD_RUN_DONE or 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 = prtd->substream->runtime; + int ret; + + while (prtd->state == Q6ASM_STREAM_RUNNING) { + snd_pcm_sframes_t avail = runtime->control->appl_ptr - prtd->queue_ptr; + + if (avail < 0) + avail += runtime->boundary; + if (avail < runtime->period_size || avail > runtime->buffer_size) + break; + + ret = q6asm_write_async(prtd->audio_client, prtd->stream_id, + prtd->pcm_count, 0, 0, 0); + if (ret == -EAGAIN) + break; + if (ret < 0) + return ret; + + prtd->queue_ptr += runtime->period_size; + if (prtd->queue_ptr >= runtime->boundary) + prtd->queue_ptr -= runtime->boundary; + } + + return 0; +} + static void event_handler(uint32_t opcode, uint32_t token, void *payload, void *priv) { @@ -187,11 +221,29 @@ static void event_handler(uint32_t opcode, uint32_t token, switch (opcode) { case ASM_CLIENT_EVENT_CMD_RUN_DONE: + if (substream && + substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + 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; case ASM_CLIENT_EVENT_CMD_EOS_DONE: break; case ASM_CLIENT_EVENT_DATA_WRITE_DONE: - snd_pcm_period_elapsed(substream); + if (substream) { + scoped_guard(pcm_stream_lock_irqsave, substream) { + snd_pcm_period_elapsed_under_stream_lock(substream); + /* Push any periods left behind by a full SMD FIFO */ + if (substream->runtime && + snd_pcm_running(substream) && + q6asm_dai_queue_playback(prtd) < 0) + pr_err_ratelimited("q6asm-dai: Error queuing playback buffer\n"); + } + } break; case ASM_CLIENT_EVENT_DATA_READ_DONE: snd_pcm_period_elapsed(substream); @@ -321,20 +373,13 @@ static int q6asm_dai_ack(struct snd_soc_component *component, struct snd_pcm_sub { struct snd_pcm_runtime *runtime = substream->runtime; struct q6asm_dai_rtd *prtd = runtime->private_data; - int i, ret = 0, avail_periods; - - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && prtd->state == Q6ASM_STREAM_RUNNING) { - avail_periods = (runtime->control->appl_ptr - prtd->queue_ptr)/runtime->period_size; - for (i = 0; i < avail_periods; i++) { - ret = q6asm_write_async(prtd->audio_client, prtd->stream_id, - prtd->pcm_count, 0, 0, 0); + int ret = 0; - if (ret < 0) { - dev_err(component->dev, "Error queuing playback buffer %d\n", ret); - return ret; - } - prtd->queue_ptr += runtime->period_size; - } + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && + snd_pcm_running(substream)) { + ret = q6asm_dai_queue_playback(prtd); + if (ret < 0) + dev_err(component->dev, "Error queuing playback buffer %d\n", ret); } return ret; @@ -353,6 +398,8 @@ static int q6asm_dai_trigger(struct snd_soc_component *component, case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: ret = q6asm_run_nowait(prtd->audio_client, prtd->stream_id, 0, 0, 0); + if (!ret && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + ret = q6asm_dai_queue_playback(prtd); break; case SNDRV_PCM_TRIGGER_STOP: ret = q6asm_cmd_nowait(prtd->audio_client, prtd->stream_id, -- 2.43.0