From nobody Wed Nov 27 10:52:02 2024 Received: from ksmg01.maxima.ru (ksmg01.maxima.ru [81.200.124.38]) (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 B8A651C9B67; Thu, 10 Oct 2024 14:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.200.124.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728569406; cv=none; b=N46pycW6V3VAqsABXMGIK5tLHHQNCqZS8FfEfAyW591asRiTaulvcdBzuE8otaoTrnw8h0e/8VewP804gV6OWdvSOtinIL23X9CSk9qS6XZe+OfuqduUcpEvSkfBXxsIQGToy7CNXfbI8y3KqMOiSTosYS6O3u+0TaUPYx1hfOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728569406; c=relaxed/simple; bh=rbj8Ml5y0TZf+zBBpOdNUB0GBpgNqjOeQWMM1fIVEE8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Ankt9jtCObK6wIDZ8Hf3ZNJgEUFmoW4RUwxres4MTKPUjc5JBAeRDCCV4jdY1cg2FMU51FnsLsMIdyM72fmh+gj0fSw5zzs+2EFsPEWDzy0KUNAKkwDOgT9+lX6QpfWS4FgEpSlRp6u8i/7uIeI/oCOk2TUQsX46yFBfi3EJT3k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=maxima.ru; spf=pass smtp.mailfrom=maxima.ru; dkim=pass (2048-bit key) header.d=maxima.ru header.i=@maxima.ru header.b=oD7avbpK; arc=none smtp.client-ip=81.200.124.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=maxima.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=maxima.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=maxima.ru header.i=@maxima.ru header.b="oD7avbpK" Received: from ksmg01.maxima.ru (localhost [127.0.0.1]) by ksmg01.maxima.ru (Postfix) with ESMTP id 4355AC0009; Thu, 10 Oct 2024 17:02:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 ksmg01.maxima.ru 4355AC0009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maxima.ru; s=sl; t=1728568941; bh=mTQWToLFTJPHNXH5pRrcnw/VZiXSpMsDPPC1XDk9tlU=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=oD7avbpK1yQRZUz3zoMzLnagyTS6LacMWi6uIXfkUIPeezg1exNspSln79ObJlDev BogkCnD5JWoRJ3sFYvbKsN/MXKPGdm4F/n6uxDJNnwO3Gt4q+OrAOTweqLjNL61tAi tSdDXf3pMaEGNvHzipKrACViHrfxv7Lm9iKT1LE7SC8lEunZ24zHxJZqBgEF7+GDcg fMlCE50omIJ7huCXBc3O87r0SquYUmqS3O9FUXTtR0zRFEbjlJiszYxYvrdoLj5gCr X9JdzdvY30jqvesqR7rOkll5bIByJgl55y7VigrosZIaOpgjR/t9EcPBfiyU1VaM0j c9BErd69fOLgg== Received: from ksmg01.maxima.ru (autodiscover.maxima.ru [81.200.124.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.maxima.ru", Issuer "GlobalSign GCC R3 DV TLS CA 2020" (verified OK)) by ksmg01.maxima.ru (Postfix) with ESMTPS; Thu, 10 Oct 2024 17:02:21 +0300 (MSK) Received: from localhost.maximatelecom.ru (10.0.247.250) by mmail-p-exch01.mt.ru (81.200.124.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.4; Thu, 10 Oct 2024 17:02:18 +0300 From: Vitaliy Shevtsov To: , Greg Kroah-Hartman CC: Vitaliy Shevtsov , Peter Ujfalusi , Ranjani Sridharan , Pierre-Louis Bossart , Mark Brown , Liam Girdwood , Bard Liao , Kai Vehmanen , Daniel Baluta , Jaroslav Kysela , Takashi Iwai , , , , Subject: [PATCH 6.1/6.6] ASoC: SOF: Fix runtime pm usage counter balance after fw exception Date: Thu, 10 Oct 2024 19:01:07 +0500 Message-ID: <20241010140110.1153-3-v.shevtsov@maxima.ru> X-Mailer: git-send-email 2.46.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: mt-exch-01.mt.ru (91.220.120.210) To mmail-p-exch01.mt.ru (81.200.124.61) X-KSMG-Rule-ID: 7 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 188361 [Oct 10 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: v.shevtsov@maxima.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dmarc=none header.from=maxima.ru;spf=none smtp.mailfrom=maxima.ru;dkim=none X-KSMG-AntiSpam-Info: LuaCore: 39 0.3.39 e168d0b3ce73b485ab2648dd465313add1404cce, {rep_avail}, {Tracking_uf_ne_domains}, {Tracking_from_domain_doesnt_match_to}, maxima.ru:7.1.1;127.0.0.199:7.1.2;81.200.124.61:7.1.2;msgid.link:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;ksmg01.maxima.ru:7.1.1, FromAlignment: s, ApMailHostAddress: 81.200.124.61 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean, bases: 2024/10/10 12:46:00 X-KSMG-LinksScanning: Clean, bases: 2024/10/10 12:46:00 X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/10/10 12:06:00 #26731330 X-KSMG-AntiVirus-Status: Clean, skipped Content-Type: text/plain; charset="utf-8" From: Peter Ujfalusi commit b30289e7fa927f921bfb4d0d04727461706ae822 upstream. If the retain context is enabled we will unconditionally increment the device's pm use count on each exception and when the drivers are unloaded we do not correct this (as we don't know how many times we 'prevented d3 entry'). Introduce a flag to make sure that we do not increment the use count more than once and on module unload decrement the use count if needed to balance it. Signed-off-by: Peter Ujfalusi Reviewed-by: Ranjani Sridharan Reviewed-by: Pierre-Louis Bossart Link: https://msgid.link/r/20240213114729.7055-1-peter.ujfalusi@linux.intel= .com Signed-off-by: Mark Brown Signed-off-by: Vitaliy Shevtsov --- sound/soc/sof/core.c | 10 ++++++++++ sound/soc/sof/debug.c | 8 +++++--- sound/soc/sof/sof-priv.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index 0938b259f703..cba0af5b86aa 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -477,6 +477,16 @@ int snd_sof_device_remove(struct device *dev) */ snd_sof_machine_unregister(sdev, pdata); =20 + /* + * Balance the runtime pm usage count in case we are faced with an + * exception and we forcably prevented D3 power state to preserve + * context + */ + if (sdev->d3_prevented) { + sdev->d3_prevented =3D false; + pm_runtime_put_noidle(sdev->dev); + } + if (sdev->fw_state > SOF_FW_BOOT_NOT_STARTED) { sof_fw_trace_free(sdev); ret =3D snd_sof_dsp_power_down_notify(sdev); diff --git a/sound/soc/sof/debug.c b/sound/soc/sof/debug.c index d547318e0d32..7c8aafca8fde 100644 --- a/sound/soc/sof/debug.c +++ b/sound/soc/sof/debug.c @@ -433,13 +433,15 @@ static void snd_sof_ipc_dump(struct snd_sof_dev *sdev) =20 void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev, const char *msg) { - if (IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_RETAIN_DSP_CONTEXT) || - sof_debug_check_flag(SOF_DBG_RETAIN_CTX)) { + if ((IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_RETAIN_DSP_CONTEXT) || + sof_debug_check_flag(SOF_DBG_RETAIN_CTX)) && !sdev->d3_prevented) { /* should we prevent DSP entering D3 ? */ if (!sdev->ipc_dump_printed) dev_info(sdev->dev, "Attempting to prevent DSP from entering D3 state to preserve context= \n"); - pm_runtime_get_if_in_use(sdev->dev); + + if (pm_runtime_get_if_in_use(sdev->dev) =3D=3D 1) + sdev->d3_prevented =3D true; } =20 /* dump vital information to the logs */ diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index d4f6702e93dc..b27a5f9e1bc8 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -593,6 +593,7 @@ struct snd_sof_dev { struct list_head dfsentry_list; bool dbg_dump_printed; bool ipc_dump_printed; + bool d3_prevented; /* runtime pm use count incremented to prevent context= lost */ =20 /* firmware loader */ struct sof_ipc_fw_ready fw_ready; --=20 2.46.2