From patchwork Wed Nov 16 11:55:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cezary Rojewski X-Patchwork-Id: 13044994 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7170EC43217 for ; Wed, 16 Nov 2022 11:40:04 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 9D89F169A; Wed, 16 Nov 2022 12:39:12 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9D89F169A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1668598802; bh=iXxWBfZWTqQV4C6XUkYcLHv5pKsPUEC8r9c+mmlfPxY=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MB8gmHxVKToEJD0IeZHiucQYaSppqrGWPonSCL1WKKn+360syVAMtpdVHhQRFkLvY 3LDke+vYZJPFTo24auUtCFqYyrosyDuidBv/GK9/I9OLPiKulxFp+hxJuxpTLo2hNb B6brfEIGGRUT/QPZ3QeqbEDexGX04/WUjd05cwYY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1CADEF8032D; Wed, 16 Nov 2022 12:38:54 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3A0E3F800B8; Wed, 16 Nov 2022 12:38:53 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 952E9F800B8 for ; Wed, 16 Nov 2022 12:38:46 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 952E9F800B8 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="liEdwaQ8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668598727; x=1700134727; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iXxWBfZWTqQV4C6XUkYcLHv5pKsPUEC8r9c+mmlfPxY=; b=liEdwaQ8vADlMUJ35fTjVi18FmhKQu3F8vZfP8oT0yp3xkCX1orSNJB3 uT7pGiKdVEoSYzt9Sd7a+AzqPnA9k99UHn5ib2N3c5iLaZ9+HU5TFLk5b t80Qw450M3ZzWO7XZA9D+J6NrJV63FCSUUeGNgB//CyXXj0N8wtzm8d2Y sMuhTHHQFITtmrmHUev2B5+848SnrsYtjMXuX8XL3o1nSoQC0esUpvDn5 TBJMsHHOVVHQ8wvWVygh8J5LVgXSQJq1iRVFM1OGwAer2dN1FpXFB+w9W oYaXOHJhCwCK3tzenIO3f1joOfopeXR8B/9ehie/Gxsk8qkxk3Y/tDaBG w==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="314336792" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="314336792" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 03:38:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="764304450" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="764304450" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by orsmga004.jf.intel.com with ESMTP; 16 Nov 2022 03:38:40 -0800 From: Cezary Rojewski To: alsa-devel@alsa-project.org, broonie@kernel.org Subject: [PATCH v3 1/2] ASoC: Intel: avs: Lock substream before snd_pcm_stop() Date: Wed, 16 Nov 2022 12:55:49 +0100 Message-Id: <20221116115550.1100398-2-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221116115550.1100398-1-cezary.rojewski@intel.com> References: <20221116115550.1100398-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Cc: Cezary Rojewski , pierre-louis.bossart@linux.intel.com, tiwai@suse.com, hdegoede@redhat.com, amadeuszx.slawinski@linux.intel.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" snd_pcm_stop() shall be called with stream lock held to prevent any races between nonatomic streaming operations. Fixes: 2f1f570cd730 ("ASoC: Intel: avs: Coredump and recovery flow") Signed-off-by: Cezary Rojewski --- Changes in v3: - added a comment why non-_irq() locking is used around snd_pcm_stop() sound/soc/intel/avs/ipc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sound/soc/intel/avs/ipc.c b/sound/soc/intel/avs/ipc.c index 152f8d0bdf8e..af8a260093f4 100644 --- a/sound/soc/intel/avs/ipc.c +++ b/sound/soc/intel/avs/ipc.c @@ -123,7 +123,10 @@ static void avs_dsp_recovery(struct avs_dev *adev) if (!substream || !substream->runtime) continue; + /* No need for _irq() as we are in nonatomic context. */ + snd_pcm_stream_lock(substream); snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED); + snd_pcm_stream_unlock(substream); } } } From patchwork Wed Nov 16 11:55:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cezary Rojewski X-Patchwork-Id: 13044995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B1982C433FE for ; Wed, 16 Nov 2022 11:40:32 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 7285C15CC; Wed, 16 Nov 2022 12:39:40 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7285C15CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1668598830; bh=Yr/0qBmCgbdb7d38WF85pkRxdBnyu9qE35POEXUdPMk=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=VBSh1/uG2/rRij700bR06N4EZBCcaF0CSAF6vUrJotifEKCVOe/EkCFv2YmK34JmB 4du0RF4OADs6LKOTMI+YLwPERuRg8vdVAZ1Hx6FQWXh8daVGNxlrkjuHJ3VM+dLPRc ErB0OyeocR3993P60ctytQ9KwSIXgpY4Nnx9A7Ww= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AC348F80549; Wed, 16 Nov 2022 12:38:56 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 314B7F804BC; Wed, 16 Nov 2022 12:38:54 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 4023CF80163 for ; Wed, 16 Nov 2022 12:38:46 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4023CF80163 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="J7ZBuTgt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668598728; x=1700134728; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Yr/0qBmCgbdb7d38WF85pkRxdBnyu9qE35POEXUdPMk=; b=J7ZBuTgtueH+NhOtINvAMo9pQumpTQHZ/tyCxnc495roh/kZu7QjzFwn MPUXrlkxwAy+DM7wEscp0SdMJIzsTSvCrzI/4sEsjS69avcws3ph9DH9K YXJ0HQq2A/ryfwqMQ9qMYMDGKKckBYjWWGKHe8xYSHBE6+TbhIssb8ZDQ MnPELD5vx4DIknpQ8+mzHj03I24TRz4TuY71GPiTzBu3QAHOmpJgAcUdY QXossySgqgULkJf7N5vMVoO+VtR2Hd+fYWtUvrJnEorLeh5gVoMzsm3rk YnHNTE4Ba6jQVLmALGNfhkdsj6PXr6BSsCr52xGxzcuM1g3E/3EQIUr0G Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="314336795" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="314336795" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 03:38:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="764304477" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="764304477" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by orsmga004.jf.intel.com with ESMTP; 16 Nov 2022 03:38:42 -0800 From: Cezary Rojewski To: alsa-devel@alsa-project.org, broonie@kernel.org Subject: [PATCH v3 2/2] ASoC: Intel: avs: Disconnect substream if suspend or resume fails Date: Wed, 16 Nov 2022 12:55:50 +0100 Message-Id: <20221116115550.1100398-3-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221116115550.1100398-1-cezary.rojewski@intel.com> References: <20221116115550.1100398-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Cc: Cezary Rojewski , pierre-louis.bossart@linux.intel.com, tiwai@suse.com, hdegoede@redhat.com, amadeuszx.slawinski@linux.intel.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" To improve performance and overall system stability, suspend/resume operations for ASoC cards always return success status and defer the actual work. Because of that, if a substream fails to resume, userspace may still attempt to invoke commands on it as from their perspective the operation completed successfully. Set substream's state to DISCONNECTED to ensure no further commands are attempted. Signed-off-by: Cezary Rojewski --- Changes in v2: - __snd_pcm_set_state() replaced direct assignments of PCM state sound/soc/intel/avs/pcm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sound/soc/intel/avs/pcm.c b/sound/soc/intel/avs/pcm.c index ca624fbb5c0d..70442b5212c2 100644 --- a/sound/soc/intel/avs/pcm.c +++ b/sound/soc/intel/avs/pcm.c @@ -934,8 +934,11 @@ static int avs_component_pm_op(struct snd_soc_component *component, bool be, rtd = snd_pcm_substream_chip(data->substream); if (rtd->dai_link->no_pcm == be && !rtd->dai_link->ignore_suspend) { ret = op(dai, data); - if (ret < 0) + if (ret < 0) { + __snd_pcm_set_state(data->substream->runtime, + SNDRV_PCM_STATE_DISCONNECTED); return ret; + } } } @@ -944,8 +947,11 @@ static int avs_component_pm_op(struct snd_soc_component *component, bool be, rtd = snd_pcm_substream_chip(data->substream); if (rtd->dai_link->no_pcm == be && !rtd->dai_link->ignore_suspend) { ret = op(dai, data); - if (ret < 0) + if (ret < 0) { + __snd_pcm_set_state(data->substream->runtime, + SNDRV_PCM_STATE_DISCONNECTED); return ret; + } } } }