From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D0F237BE92 for ; Fri, 15 May 2026 09:22:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778836955; cv=none; b=u9APcljNe+YKxEPQGT2ZyYHhd5XL+W74XsBlaJIPRHcTdsVy3JouV3PltBl5JqsPQSQLYHJkfrPE10W7P7DgOiXV0Wj1CPPnaKcU87tB+vkivYADgPJ/4VV45aRaoEy/JVgIMkwj62GqjsUoiHl4CbGb74pockND4VL012F9Urw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778836955; c=relaxed/simple; bh=hF4eh7PcA0A1Lv3JKlJ8+3wozC/fVumc25/5SGMDYl0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LaNKkSwjJxISEHxGzI0+EefouRGhclXbi3t5gU9JeszKx8mOT3GA5bo5E/mTnDf/ml6ENAyVYhnyGRhHuRkhuAn0B8PJU5cwiOmBMXV0TG5SJq7RyGg2F/nUawRIbyofDxdSVnIDXQhNFmEjZYIC9Rb3hxMW+G7Dsf/NJ+71xtQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=VVg+AjF4; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=Ie5XLB07; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="VVg+AjF4"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="Ie5XLB07" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64F5fvtm1847980 for ; Fri, 15 May 2026 09:22:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ut9Rue+O79MhAWlyTZLlQHEgaFO1L9dTJk5rA6FaSjA=; b=VVg+AjF4uTbozmyn tXlHTBj14BIHKMspvS4qkRXlQyRuNBF5IhPp6UKV3dbFnJ1aNpOrVsBnd+uSyW0l a4NLvuhLgQWITViBg2WdL/5S3qIZFjQjWiiS4NP48v9/je+mD4w25WS84V2H+c0G X7OD0lMYjgQZLRjdOxJCZY1ZE8688GccFqhkMTxsBtvhntIg1TheKcOBrw6lQuMO Ock5RUOJtKkHaVGmEh0eaeCOncNJ3yQAAWlzHNPGnpqCUAT+CKLS+8hTu91ZOhAG 7J3mrd25im1WpFeXg4Z6brBH6VIp4oxLJ2vUsMmDRGKOe6v9l+UZxuWQwORyKRQk 8d8jBw== Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4e5m1t2je9-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 15 May 2026 09:22:33 +0000 (GMT) Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-5156c85538cso84310191cf.3 for ; Fri, 15 May 2026 02:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778836953; x=1779441753; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ut9Rue+O79MhAWlyTZLlQHEgaFO1L9dTJk5rA6FaSjA=; b=Ie5XLB07RCUrdOU6qPnamQp2umr0P295+EG758HFC8o6A28oPReRBKIp9Vlea+fj+W 5JJXuOLtatlAz3B+SsimZD6F/99La0F/0zF6PX3SVN7N6oP0WsxXivD2RM0Dp9sNztaZ QwEc6aRt+yhyeZnt1vTC5PpIDSQYt//MMsHeKqIih08eN0Pe4u6zmZPqmRN4uUnewP0j AEVuY9NvzPmNAP/+Z4HG29NjGZfIEiNZXxg0pGn29pjMwlslu/EPc3AW9tud5GytkU3L A5+WtiK/AHa/Uy2NSrBtWg9bUccOjAEO6DaQDIlKbpEGJAI8YFpOdhYfKNRFR4opkTnP 9ePg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778836953; x=1779441753; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ut9Rue+O79MhAWlyTZLlQHEgaFO1L9dTJk5rA6FaSjA=; b=GGDHWztDGVIcLtoyyyJuBVV0lxYiVIO4SviOunsEYKbvszy4l/KcHF7x5amHeqeqix bVtUb6wTdJz1AscfQ73UhgWJzdMWx3SrF3KDTtIIBGBCSmEc/+2B2+aMl7RSXsCwORTT kGBt0XZCCtQgMBJ04qbmNv++DY1gFOkglvt2tWoWX1X+BO6NzMW5JHudALYGL3SMgWzs dZoFN8+fb0npo1jYvUYu1lMJqA1/hPPzX1ItrwRW6jb893o3D6Ei+7yXMH44dTaAim0D fz1vNZFO8bRTNcCU+fW14iBUok/aL+sLgDPcx05d3r8z0W4wFQesJMdvbkbHfach6aDv Kw3Q== X-Forwarded-Encrypted: i=1; AFNElJ8P+Nrrxu8TFkdaLudPpQkJF/nbmb+9ZBqDGjMuxsfrvdx6d+OT5f9quorgkrcKgsPpDHF/1t3L9AMhIRc=@vger.kernel.org X-Gm-Message-State: AOJu0YxBlCbZCKWvOGqrx+gD/RsrNXj1jjhpf3RMFbaEmGjxCpeZt4VU ROVEvOspIIjByj0EUu+yCkgEjOMlDK13FsseuZE+cHVTCVm4APAIRgqcVuclnP40q8LnENQ+NvL poEyuR6Bm2MiEe2dNNQXrADT8FnLNvMDhD7/B1XDMDLULVAKRvE8IMehy0l1DV9NLMfQ= X-Gm-Gg: Acq92OFNReDlsQaX/gQDpuGZx96TozwT5rwltgxwV52c/MaSQXgurgo6G2jWHsqRUHh qqKXOMY8pa+67zte9dlVgOamAH451vLl7kZe2EHV7OIC+eOZm0uHlcsD44xWUVY0InmyI1GD9qj +69QkKRlSUwPYX7n665NbkD4nWD9nLKUEqyDbrn58L4dAcL+2CGhJm6SdKWJTBGiqAG3KB99Z6B 39bcxYfcVvv0Co6qDaBesYUTA9u3DpeWFNfJBzldNmyrqrB9p7DLu5CgqGs73dw8Y2IZZK0xSMT 4eGUX/dH4gqbot2V3fPY8evtbtC1GWkjs19+GOS0cGdQX7OyM5TMHJBMw1OwQ5ACYDLkYX1AF7K i1k9xFLIzsejE5HO32R/NVbC8hWS8w+IN0ZlNroIAqPc+/3W1 X-Received: by 2002:a05:622a:30f:b0:50d:9f33:9a5 with SMTP id d75a77b69052e-5165a02c2b1mr43772631cf.23.1778836952868; Fri, 15 May 2026 02:22:32 -0700 (PDT) X-Received: by 2002:a05:622a:30f:b0:50d:9f33:9a5 with SMTP id d75a77b69052e-5165a02c2b1mr43772231cf.23.1778836952311; Fri, 15 May 2026 02:22:32 -0700 (PDT) Received: from [192.168.68.112] ([5.133.47.210]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-48fe5694fbfsm87785005e9.6.2026.05.15.02.22.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 May 2026 02:22:31 -0700 (PDT) Message-ID: <16951a6b-0f5a-4777-ad70-8a70ac4060dd@oss.qualcomm.com> Date: Fri, 15 May 2026 09:22:30 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: ASoC q6asm race condition when stopping and preparing the stream To: Val Packett , Richard Acayan , Alexey Klimov Cc: Srinivas Kandagatla , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Greg Kroah-Hartman , Kees Cook , Joris Verhaegen , Kuninori Morimoto , linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org References: <553e6031-9705-48d3-8831-da49b3c67d01@packett.cool> Content-Language: en-US From: Srinivas Kandagatla In-Reply-To: <553e6031-9705-48d3-8831-da49b3c67d01@packett.cool> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=D7Z37PRj c=1 sm=1 tr=0 ts=6a06e5d9 cx=c_pps a=WeENfcodrlLV9YRTxbY/uA==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=Gbw9aFdXAAAA:8 a=xBXWW545i7Fg7s4S6_QA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=kacYvNCVWA4VmyqE58fU:22 a=9vIz8raoGPyDa4jBFAYH:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTE1MDA5NCBTYWx0ZWRfX8Rz1Dr8+laAB 2l1yo9/Sb1yF1zx2ZKoowzaH2m8ptdo8vUbDKgpTORgQIUyySenJq6pt6ejFlzLOkuqQ6D/q38M t8bHWXNGVp7k6DhZiM34CObqeyub6BiJKaNyriACm38lLjC2CVklaaqwcmaG4ZqkEdxbA86iEfp xWkcJi0+54AfjGZSKVS8wsRIes1AP3YdGGBQwZ+fLPv9UOLDVSSzN1GC0WZPOLPtQQdKWA0I6UB oOePCoPyAF7dph0xs0j7RylJKMLCqVxw6/s+8b+Hy5Wb+D8d6Ne9wEdyDAi7O4+i7T5ASX8N/dm LlmncZupvipiX/4ZY6pz3b/T1sQwAd8w8+z4Gye1EC/lRvtObdDcbWer2P/Pkx9vXM9KbntTgJK UULH6NW8w4hriD4Ud0Ivs0+/IKDsvUzPJUhM9uicvKmF5GGgIpscafyJB+AVAaI5XYrrP8ZSrdT uQJ6aZDQ9TsSGnx63Ug== X-Proofpoint-ORIG-GUID: fXO7ylDjNPfD657rPMLZfYr7CuJJYw2x X-Proofpoint-GUID: fXO7ylDjNPfD657rPMLZfYr7CuJJYw2x X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-15_02,2026-05-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 adultscore=0 phishscore=0 clxscore=1015 bulkscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605130000 definitions=main-2605150094 On 5/15/26 5:59 AM, Val Packett wrote: > Hi, > > On 5/1/26 8:53 PM, Richard Acayan wrote: >> On Fri, May 01, 2026 at 04:27:57PM +0100, Alexey Klimov wrote: >>> On Fri May 1, 2026 at 3:41 PM BST, Richard Acayan wrote: >>>> Hi, >>>> >>>> There seems to be a race condition in q6asm when stopping the stream >>>> (with uncompressed PCM). When receiving SNDRV_PCM_TRIGGER_STOP, the >>>> driver sets the state to Q6ASM_STREAM_STOPPED and sends CMD_EOS to the >>>> ADSP. If userspace decides to prepare the stream again in >>>> q6asm_dai_prepare before receiving ASM_CLIENT_EVENT_CMD_EOS_DONE, the >>>> memory-mapped region appears to still be in use and fails to map again. >>>> >>>> I believe this race was observed since commit 81c53b52de21 ("ASoC: >>>> qcom: >>>> qdsp6: q6asm-dai: set 10 ms period and buffer alignment."), but would >>>> need to verify. On sdm670, we are coping downstream by keeping the >>>> state >>>> as Q6ASM_STREAM_RUNNING until receiving CMD_EOS_DONE. > Are we sure that's only a workaround and not the correct solution? > Thank you for mentioning it, in any case! >>> Do you have a reproducer or specific steps to test/reproduce the issue? >> I don't really have an easy way to reproduce. On a device with a >> Qualcomm SoC and q6asm, running postmarketOS with Phosh and without the >> workaround, waiting a few hours usually reproduces it. > > I haven't seen this happen "randomly".. at least not with PulseAudio, > but after switching to PipeWire and properly configuring phone calls(*) > on my phone (sm7325-motorola-dubai) I have encountered what I think is > the exact same issue many times while doing this simple sequence: > > - boot phone, playback and recording work fine > - start a phone call, cancel when hearing dial tone (Wireplumber has > switched UCM profile to VoiceCall and then back to HiFi) > - try to record mic sound (using the GNOME sound recorder app or > whatever else) > > Actually just now I managed to hit this right after reboot, without any > calls..! > > So it might just be "try to record audio through PipeWire and you'll hit > it quickly enough". > > > (*) using the current infamous q6voice patchset, Wireplumber's script to > switch between HiFi/VoiceCall, and a better setup for starting the dummy > streams exposed by q6voice: https://gitlab.postmarketos.org/ > postmarketOS/q6voiced/-/work_items/3#note_553107 > > The log is usually something like this: > > kernel: q6asm-dai 3700000.remoteproc:glink-edge:apr:service@7:dais: > Buffer already allocated > kernel: q6asm-dai 3700000.remoteproc:glink-edge:apr:service@7:dais: cmd > = 0x10db4 returned error = 0x9 > kernel: q6asm-dai 3700000.remoteproc:glink-edge:apr:service@7:dais: DSP > returned error[9] this suggests that we are opening a capture stream that is already open. Somehow the driver seems to not doing the correct check and closing it or returning an error when try to open an existing stream. I will run some tests and let you know if I fund anything interesting. But in the mean time if you can find a way to reproduce this issue, please share. --srini > pipewire[5347]: [E][02:30:35.781627] spa.alsa     | [ alsa-pcm.c: 2722 > do_prepare()] hw:Motoroladubai,2c: snd_pcm_prepare error: Invalid argument > pipewire[5347]: [W][02:30:35.781714] spa.alsa     | [ alsa-pcm.c: 2885 > get_avail()] hw:Motoroladubai,2c: (0 suppressed) snd_pcm_avail after > recover: File desc> > pipewire[5347]: [E][02:30:35.781771] spa.alsa     | [ alsa-pcm.c: 2832 > alsa_recover()] hw:Motoroladubai,2c: recover from error state SETUP > pipewire[5347]: [E][02:30:35.781801] spa.alsa     | [ alsa-pcm.c: 2722 > do_prepare()] hw:Motoroladubai,2c: snd_pcm_prepare error: Invalid argument > pipewire[5347]: [E][02:30:35.781821] spa.alsa     | [ alsa-pcm.c: 2832 > alsa_recover()] hw:Motoroladubai,2c: recover from error state SETUP > pipewire[5347]: [E][02:30:35.781837] spa.alsa     | [ alsa-pcm.c: 2722 > do_prepare()] hw:Motoroladubai,2c: snd_pcm_prepare error: Invalid argument > pipewire[5347]: [E][02:30:35.786869] spa.alsa     | [ alsa-pcm.c: 2832 > alsa_recover()] hw:Motoroladubai,2c: recover from error state SETUP > pipewire[5347]: [E][02:30:35.786949] spa.alsa     | [ alsa-pcm.c: 2722 > do_prepare()] hw:Motoroladubai,2c: snd_pcm_prepare error: Invalid argument > kernel: q6asm-dai 3700000.remoteproc:glink-edge:apr:service@7:dais: > q6asm_dai_prepare: q6asm_open_write failed > kernel: q6asm-dai 3700000.remoteproc:glink-edge:apr:service@7:dais: ASoC > error (-22): at snd_soc_pcm_component_prepare() on > 3700000.remoteproc:glink-edge:apr:servi> > kernel: q6asm-dai 3700000.remoteproc:glink-edge:apr:service@7:dais: > q6asm_dai_prepare: private data null or audio client freed > kernel: q6asm-dai 3700000.remoteproc:glink-edge:apr:service@7:dais: ASoC > error (-22): at snd_soc_pcm_component_prepare() on > 3700000.remoteproc:glink-edge:apr:servi> > kernel: q6asm-dai 3700000.remoteproc:glink-edge:apr:service@7:dais: > q6asm_dai_prepare: private data null or audio client freed > … > > "Buffer already allocated", error 9 which is ADSP_EALREADY, so the state > is desynchronized. > > > Thanks, > ~val >