From patchwork Wed Sep 7 10:13:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 603838 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 4B1A9C38145 for ; Wed, 7 Sep 2022 10:15:43 +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 7374C1666; Wed, 7 Sep 2022 12:14:51 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7374C1666 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662545741; bh=4hfie7G9uozS4KcCzfm//dtvshwoOBMfIlcrtYusoAQ=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=eMM1FByuwdsMoHiRK5ehI5Skd2AtncxN4Qqq49ODEU8UWnlucp/IFoHJ051T14IPm JQ4VTrMx5ZDcABYJaBTuduGZqI30c2RvOYML9193vEPHlyO8w0Dny3Cx51VHyT2ZUO gGmsZxNLQP/R3WhWKF+jXNDCEZVDOBRxjm8vtw+M= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9D45FF80536; Wed, 7 Sep 2022 12:14:25 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D6D0CF80249; Wed, 7 Sep 2022 12:14:23 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (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 B653AF80249; Wed, 7 Sep 2022 12:14:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B653AF80249 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="m3p88bZV" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2877rCJq005930; Wed, 7 Sep 2022 05:14:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=Bl/hAN9eOUE5fEBUCRal2TYzv7rqHpfP3aY8V81esYM=; b=m3p88bZV2DgSjEeYXHsRxYNY+tfbxKb37WGlJ2IQvpNNvg+quYR3DYOy64bxzIye2KpH 3GTN9ZMA0sR9USISojxYI8kuoKNLRK0skpch3BIT6c7DJ/kYG1FicG0NIi88FqH8EDMK NKVfcKZmMiGJdgJ7P7eNfnpJsrzU8O8UlNpKCrhgEISccSlcD5elOiNU4YhRVGngl80H cKOT3MlSPm85itEH2yM59GfwpaER21fjH4385W3xGteT5kZ44MW9kjJk5QpEDvogbUV+ GXN8n92SlBdTPG4IvPJd5FgCARNvd1RNs7tD16cOuUHq0oJ+61wz7oSnm/a96Ko/dMOD iw== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3jc3bpw4sr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Sep 2022 05:14:14 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Wed, 7 Sep 2022 05:14:12 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.12 via Frontend Transport; Wed, 7 Sep 2022 05:14:12 -0500 Received: from debianA11184.ad.cirrus.com (unknown [198.61.65.149]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 4ECDC7C; Wed, 7 Sep 2022 10:14:12 +0000 (UTC) From: Richard Fitzgerald To: , , , , , , , , , Subject: [PATCH 1/7] soundwire: bus: Do not forcibly disable child pm_runtime Date: Wed, 7 Sep 2022 11:13:56 +0100 Message-ID: <20220907101402.4685-2-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907101402.4685-1-rf@opensource.cirrus.com> References: <20220907101402.4685-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: jOtVSBGoI6flwsCrmA4vF34gVFAe56ZT X-Proofpoint-ORIG-GUID: jOtVSBGoI6flwsCrmA4vF34gVFAe56ZT X-Proofpoint-Spam-Reason: safe Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Richard Fitzgerald , linux-kernel@vger.kernel.org, sound-open-firmware@alsa-project.org 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" Do not call pm_runtime_disable() of a child driver in sdw_delete_slave(). We really should never be trying to disable another driver's pm_runtime - it is up to the child driver to disable it or the core driver framework cleanup. The driver core will runtime-resume a driver before calling its remove() so we shouldn't break that. The patch that introduced this is commit dff70572e9a3 ("soundwire: bus: disable pm_runtime in sdw_slave_delete") which says: "prevent any race condition with the resume being executed after the bus and slave devices are removed" The actual problem is that the bus driver is shutting itself down before the child drivers have been removed, which is the wrong way around (see for example I2C and SPI drivers). If this is fixed, the bus driver will still be operational when the driver framework runtime_resumes the child drivers to remove them. Then the bus driver will remove() and can shut down safely. Also note that the child drivers are not necessarily idle when the bus driver is removed, so disabling their pm_runtime and stopping the bus might break more than only their remove(). Signed-off-by: Richard Fitzgerald --- drivers/soundwire/bus.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 0bcc2d161eb9..99429892221b 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -151,8 +151,6 @@ static int sdw_delete_slave(struct device *dev, void *data) struct sdw_slave *slave = dev_to_sdw_dev(dev); struct sdw_bus *bus = slave->bus; - pm_runtime_disable(dev); - sdw_slave_debugfs_exit(slave); mutex_lock(&bus->bus_lock); From patchwork Wed Sep 7 10:13:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 603364 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 8AD0DC38145 for ; Wed, 7 Sep 2022 10:16:23 +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 8A4EA1661; Wed, 7 Sep 2022 12:15:31 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8A4EA1661 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662545781; bh=nW6saLcJ60MMn8DeEdAs0wb1aFO3efpuE7f3R0tN3sQ=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=d+WXPnrzq/JVWhJXY7JEFJIm2tASUeWsw7E86TNvigP1e0cAj4l79H70+UQjHTrYU fhHFRymL4mJHf+URM5/jq5n/HUZBpDwY/7PDV0GvXd1blMkOK889tcqKefL8mRw0I/ sy3XriDcM8cS9MpCyTRNydo38y4tJ/rI4u0XjXl4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C72F7F80551; Wed, 7 Sep 2022 12:14:29 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1F079F8053C; Wed, 7 Sep 2022 12:14:27 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (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 F2A8DF804FC; Wed, 7 Sep 2022 12:14:16 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz F2A8DF804FC Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="V7QWk7sO" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2877rCJr005930; Wed, 7 Sep 2022 05:14:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=ot1Tl8QTYVtsDuCHedMkmJ33fXe9BMeDLR0TIH+3JGU=; b=V7QWk7sO38uS86TS+NlahQceUBlCHvX/8rcq6rqKmo/2fOKoClg5XwVgUwt4F4y4GLxg PmKM5kTNRY0Ux/iX5Jfs8B1cq8AWwrVBe4DsHiTu6UY+xvhqbwb2PfXucZc6mvBaSld3 5yq8dUBXF3jtcS1ijJ87JloUIxA61D36noN36zHPwZPOPBuuPcD9+0ktYiANPL2AEY5D BMqN4JF8rwegpM8/y7TWifZQHUYqkTy1QMpnQMuXFzL5r3srm72WTpWLin54EBaaTD0m vMGI8JHhynhQp61vXDksSxrkRIXus8ESzBRnndRUKJvFSObmAkZK7W9ve3qL3EXrUPfS qg== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3jc3bpw4sr-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Sep 2022 05:14:15 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Wed, 7 Sep 2022 05:14:13 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.12 via Frontend Transport; Wed, 7 Sep 2022 05:14:13 -0500 Received: from debianA11184.ad.cirrus.com (unknown [198.61.65.149]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id E36A5B10; Wed, 7 Sep 2022 10:14:12 +0000 (UTC) From: Richard Fitzgerald To: , , , , , , , , , Subject: [PATCH 2/7] soundwire: intel_init: Separate shutdown and cleanup Date: Wed, 7 Sep 2022 11:13:57 +0100 Message-ID: <20220907101402.4685-3-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907101402.4685-1-rf@opensource.cirrus.com> References: <20220907101402.4685-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: vWiTgViV4BfLhGN_tzoikE6XHgslZvo6 X-Proofpoint-ORIG-GUID: vWiTgViV4BfLhGN_tzoikE6XHgslZvo6 X-Proofpoint-Spam-Reason: safe Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Richard Fitzgerald , linux-kernel@vger.kernel.org, sound-open-firmware@alsa-project.org 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" Move the freeing of context data out of sdw_intel_exit() into a new exported function sdw_intel_remove(). This splits shutdown and cleanup into separate stages, allowing the calling code to perform its own shutdown after the bus has shutdown but before the context has been deleted. The struct sdw_intel_ctx pointer is passed to the calling code by sdw_intel_probe() and the calling code passes it back as an opaque token. When the caller is removed it must have the opportunity to teardown its use of this token after the bus driver has stopped but before the context memory has been freed. It should not be doing its teardown before calling sdw_intel_exit() because that will break any bus activity currently in progress and the removal of child drivers. Signed-off-by: Richard Fitzgerald --- drivers/soundwire/intel_init.c | 24 ++++++++++++++++++++---- include/linux/soundwire/sdw_intel.h | 2 ++ sound/soc/sof/intel/hda.c | 4 +++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/soundwire/intel_init.c b/drivers/soundwire/intel_init.c index d091513919df..078e01f67830 100644 --- a/drivers/soundwire/intel_init.c +++ b/drivers/soundwire/intel_init.c @@ -292,6 +292,13 @@ static struct sdw_intel_ctx return NULL; } +static void sdw_intel_remove_controller(struct sdw_intel_ctx *ctx) +{ + kfree(ctx->ids); + kfree(ctx->ldev); + kfree(ctx); +} + static int sdw_intel_startup_controller(struct sdw_intel_ctx *ctx) { @@ -360,6 +367,18 @@ struct sdw_intel_ctx } EXPORT_SYMBOL_NS(sdw_intel_probe, SOUNDWIRE_INTEL_INIT); +/** + * sdw_intel_remove() - SoundWire Intel remove routine + * @ctx: SoundWire context allocated in the probe + * + * Free all the context created by sdw_intel_probe. + */ +void sdw_intel_remove(struct sdw_intel_ctx *ctx) +{ + return sdw_intel_remove_controller(ctx); +} +EXPORT_SYMBOL_NS(sdw_intel_remove, SOUNDWIRE_INTEL_INIT); + /** * sdw_intel_startup() - SoundWire Intel startup * @ctx: SoundWire context allocated in the probe @@ -376,14 +395,11 @@ EXPORT_SYMBOL_NS(sdw_intel_startup, SOUNDWIRE_INTEL_INIT); * sdw_intel_exit() - SoundWire Intel exit * @ctx: SoundWire context allocated in the probe * - * Delete the controller instances created and cleanup + * Stop the controller instances. */ void sdw_intel_exit(struct sdw_intel_ctx *ctx) { sdw_intel_cleanup(ctx); - kfree(ctx->ids); - kfree(ctx->ldev); - kfree(ctx); } EXPORT_SYMBOL_NS(sdw_intel_exit, SOUNDWIRE_INTEL_INIT); diff --git a/include/linux/soundwire/sdw_intel.h b/include/linux/soundwire/sdw_intel.h index 2e9fd91572d4..7f7327cab712 100644 --- a/include/linux/soundwire/sdw_intel.h +++ b/include/linux/soundwire/sdw_intel.h @@ -282,6 +282,8 @@ void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx); struct sdw_intel_ctx * sdw_intel_probe(struct sdw_intel_res *res); +void sdw_intel_remove(struct sdw_intel_ctx *ctx); + int sdw_intel_startup(struct sdw_intel_ctx *ctx); void sdw_intel_exit(struct sdw_intel_ctx *ctx); diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index 8639ea63a10d..ee67e21e739f 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -241,8 +241,10 @@ static int hda_sdw_exit(struct snd_sof_dev *sdev) hda_sdw_int_enable(sdev, false); - if (hdev->sdw) + if (hdev->sdw) { sdw_intel_exit(hdev->sdw); + sdw_intel_remove(hdev->sdw); + } hdev->sdw = NULL; return 0; From patchwork Wed Sep 7 10:13:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 603835 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 B590BC6FA8E for ; Wed, 7 Sep 2022 10:17:22 +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 C21DC1657; Wed, 7 Sep 2022 12:16:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C21DC1657 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662545840; bh=7fMGZsHrUkanG1P92mPlVcUdOm+xsIxE2oJ00mjYTQc=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=H6NWSv0yehfbvEOls44QSmjKDEyZC1bEqOm7PWmKeU9P/ef2Sb2lnTR1R3bh6KcyR MDWF36P6s3+9t3dnhKK1PULSN4K1pT+JOuAEarlmr2hP5Z7av+naQWG1hBe8hpkLzJ GZqA6/erCeYWitcHb6vBbB21n/NxrjdA8VD+z7kA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 7692CF80587; Wed, 7 Sep 2022 12:14:42 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D38B2F80533; Wed, 7 Sep 2022 12:14:31 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (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 28519F80533; Wed, 7 Sep 2022 12:14:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 28519F80533 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="YVgoR3D7" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2877rCJs005930; Wed, 7 Sep 2022 05:14:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=Gp/uTF8GDKPfyMeYGc1Hdj6y6PqGS+VgIG+UYR8B8FI=; b=YVgoR3D7kVWQjD+AOI9dk/3aSCFFDAFS0d6X4Tk5P+vVREuYDnUmmcMXf32moX0Rcxup SDYTXKsG4tC85yuYO565v4dfNc2C4j3NIJjEUN03fNmm43NZs73jVqWkXArm1BOlIPkE 1I0ktAm8QzJj47Ft4qSWIv1TqL6DHQZQ/3hTwmhyco1K91JezrAqDl0ax0jBZg9jfwT2 ms/02XIiPRKmXbHJ9qIm9H+b+/qfwH5IS0Q0PLUtJkQTwUBeKC6/uG+COIaR4fNxIzgn b4e3eaa1Z4os/BQcKNy8olSmKBrFq04+Xtryec42I1u4zNngVCbESOMPpGWE5o26JQ0d 9w== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3jc3bpw4sr-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Sep 2022 05:14:15 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Wed, 7 Sep 2022 05:14:14 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.12 via Frontend Transport; Wed, 7 Sep 2022 05:14:14 -0500 Received: from debianA11184.ad.cirrus.com (unknown [198.61.65.149]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 88D7E7C; Wed, 7 Sep 2022 10:14:13 +0000 (UTC) From: Richard Fitzgerald To: , , , , , , , , , Subject: [PATCH 3/7] ASoC: SOF: Intel: Don't disable Soundwire interrupt before the bus has shut down Date: Wed, 7 Sep 2022 11:13:58 +0100 Message-ID: <20220907101402.4685-4-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907101402.4685-1-rf@opensource.cirrus.com> References: <20220907101402.4685-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: Hg_XoDk6Sv5Mpmkzh2SnQIEICaF7KUDS X-Proofpoint-ORIG-GUID: Hg_XoDk6Sv5Mpmkzh2SnQIEICaF7KUDS X-Proofpoint-Spam-Reason: safe Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Richard Fitzgerald , linux-kernel@vger.kernel.org, sound-open-firmware@alsa-project.org 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" Until the Soundwire child drivers have been removed and the bus driver has shut down any of them can still be actively doing something. And any of them may need bus transactions to shut down their hardware. So the Soundwire interrupt must not be disabled until the point that nothing can be using it. Normally it is up to the driver using the interrupt to ensure that it doesn't break if there is an interrupt while it is shutting down. However, the design of the Intel drivers means that the Soundwire bus driver doesn't have control of its own interrupt - instead its interrupt handler is called externally by the code in hda.c. Therefore hda.c must shutdown the bus before disabling the interrupt and freeing the context memory. Signed-off-by: Richard Fitzgerald --- sound/soc/sof/intel/hda.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index ee67e21e739f..34f5de052bc0 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -236,17 +236,25 @@ int hda_sdw_startup(struct snd_sof_dev *sdev) static int hda_sdw_exit(struct snd_sof_dev *sdev) { struct sof_intel_hda_dev *hdev; + void *tmp_sdw; hdev = sdev->pdata->hw_pdata; - - hda_sdw_int_enable(sdev, false); - - if (hdev->sdw) { + if (hdev->sdw) sdw_intel_exit(hdev->sdw); - sdw_intel_remove(hdev->sdw); - } + + /* The bus has now stopped so the interrupt can be disabled */ + hda_sdw_int_enable(sdev, false); + + /* Wait for last run of irq handler to complete */ + synchronize_irq(sdev->ipc_irq); + + /* Stop using the pointer */ + tmp_sdw = hdev->sdw; hdev->sdw = NULL; + if (tmp_sdw) + sdw_intel_remove(tmp_sdw); + return 0; } From patchwork Wed Sep 7 10:13:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 603365 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 95E3DC38145 for ; Wed, 7 Sep 2022 10:15:54 +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 AED6C163B; Wed, 7 Sep 2022 12:15:02 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AED6C163B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662545752; bh=l5T1egAsIpc7cS8dfcBr+Mv1JGHwQNvDt3cFcz4/Jao=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tHcEuCDbOBd9iMRyIv5LODs9hb/62zze2HZpdPNeUvs31gQhdWMHwIxp2FL02kSyB YQ9oevETh3KlFc/6zTQwCgUIeytQNtTu+cKjBU35Vvv8/+HUHx6lip39dZblOo+koA 6hSHu6AIiD5fiDd4uvW2fLF0Tv3hVhhj52JDot4s= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2EBEFF80538; Wed, 7 Sep 2022 12:14:28 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4F84DF8053A; Wed, 7 Sep 2022 12:14:26 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (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 D4744F8023B; Wed, 7 Sep 2022 12:14:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D4744F8023B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="J0NLYU/D" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2877rCJt005930; Wed, 7 Sep 2022 05:14:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=aqYA40ruUCIZdevPe+N+w30xxDeh8yKvlyprFh48KdA=; b=J0NLYU/DxQ6iZYVgO/9tl61Cpxb4DpCWYeQOAtd0iSlkZr/BAjqBcq5c8YLPcGbDovEk 3cxBDGDYpF+FdhudjRjbAwH/E4l+yE4Q0Ap3S1yU5Pr4QRq2lW9mEpaP7H8aHm2RxQxp jGe3H1p1+rZb9kzoeL8GRceb0HbLBYQyjOm6NZLzBp9km83fw5UQUzV4M93+HCOzTErw jnOpnGuN35UNSLiVa8UgAj1t3soLmesi3tyUs3sj4Vfx+oXp6Rfd8n9ChNfZpY5X/6a9 xrEQwgMmCnQFJr641gHdInOMMdmk5hdlFvLLUVIlHSrVkruqpnISswPWB4uhJ4+JOIGC kQ== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3jc3bpw4sr-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Sep 2022 05:14:16 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Wed, 7 Sep 2022 05:14:14 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.12 via Frontend Transport; Wed, 7 Sep 2022 05:14:14 -0500 Received: from debianA11184.ad.cirrus.com (unknown [198.61.65.149]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 30067B10; Wed, 7 Sep 2022 10:14:14 +0000 (UTC) From: Richard Fitzgerald To: , , , , , , , , , Subject: [PATCH 4/7] soundwire: bus: Add remove callback to struct sdw_master_ops Date: Wed, 7 Sep 2022 11:13:59 +0100 Message-ID: <20220907101402.4685-5-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907101402.4685-1-rf@opensource.cirrus.com> References: <20220907101402.4685-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: PcezryGsWGuJWSoJf8gsZ1-ET6M7BAOB X-Proofpoint-ORIG-GUID: PcezryGsWGuJWSoJf8gsZ1-ET6M7BAOB X-Proofpoint-Spam-Reason: safe Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Richard Fitzgerald , linux-kernel@vger.kernel.org, sound-open-firmware@alsa-project.org 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" During removal of a bus driver the bus must stay operational while child drivers are being removed, since (a) they might have been busy when the bus driver removal started and (b) the might need to access the bus to run their shutdown procedures. Only after that can the bus driver disable the bus. Add a new remove callback to struct sdw_master_ops that the bus driver can implement to disable the bus after children are removed. This is modeled on the ASoC component_remove, which indicates that the driver is no longer required. Signed-off-by: Richard Fitzgerald --- drivers/soundwire/bus.c | 5 +++++ include/linux/soundwire/sdw.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 99429892221b..1327a312be86 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -176,6 +176,11 @@ static int sdw_delete_slave(struct device *dev, void *data) void sdw_bus_master_delete(struct sdw_bus *bus) { device_for_each_child(bus->dev, NULL, sdw_delete_slave); + + /* Children have been removed so it is now safe for the bus to stop */ + if (bus->ops->remove) + bus->ops->remove(bus); + sdw_master_device_del(bus); sdw_bus_debugfs_exit(bus); diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h index a2b31d25ea27..aa492173d5eb 100644 --- a/include/linux/soundwire/sdw.h +++ b/include/linux/soundwire/sdw.h @@ -839,6 +839,7 @@ struct sdw_defer { * @set_bus_conf: Set the bus configuration * @pre_bank_switch: Callback for pre bank switch * @post_bank_switch: Callback for post bank switch + * @remove: Called when it is safe to stop the bus controller. */ struct sdw_master_ops { int (*read_prop)(struct sdw_bus *bus); @@ -855,7 +856,7 @@ struct sdw_master_ops { struct sdw_bus_params *params); int (*pre_bank_switch)(struct sdw_bus *bus); int (*post_bank_switch)(struct sdw_bus *bus); - + void (*remove)(struct sdw_bus *bus); }; /** From patchwork Wed Sep 7 10:14:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 603363 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 D92EBECAAD3 for ; Wed, 7 Sep 2022 10:16:55 +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 265911680; Wed, 7 Sep 2022 12:16:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 265911680 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662545814; bh=T6ndJyX1drIrGDeHhSDYxtwlLUPBYwfA+2oy9Xxh4qU=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nJxLqQqHbI6XqEPpiW/nwAosTs5ObR6BCRcnITncNZhHXEVTf4LrVJP3BPRNEwgId 2T/y+t2jX10t9AQAREO7lehR4PcDMRBLxcTA8BoXlIQDvyVvUQPhVT7HDlJ7zu7x0o KG0TEl9/O3IWOC2RWIYBg/VXJ4kRHC6Zwogz5LLY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4987AF80566; Wed, 7 Sep 2022 12:14:36 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 83FB5F8054A; Wed, 7 Sep 2022 12:14:29 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (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 4DD95F80118; Wed, 7 Sep 2022 12:14:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4DD95F80118 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="Ql0LJ86b" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2877rCJu005930; Wed, 7 Sep 2022 05:14:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=B6nn0DMduRe/b0wPBE0kJZuYuyehQzIVtGN50L5g4Mk=; b=Ql0LJ86b71n/DDop36XiXMnZ657dfSJcMMDykbBtKO0u/RVnZs9tq+J+CFnZIlR5Imdw gjZweqYzLO8UpLYc83m+w41RagXRZ4jnbDRmpQMD0IKZfB2s8UIgzxWK/orMZuEUzXMx C1Ok+wVsbzHvLLaXmGe/EKCPHMZW2NCR3t1NanOCFAiyonWIoYcp/coeXtLqq/zEjWOP UDgws0DkMcT5B7GYl9FfO0Kba1liYYZ7IHPlW56ePfxFjxGaxyzN8kDPIT1hi1rC/4LF SN2+UQ0c2G6847OsHT5Fvv6utpi1RyUaZyfeb9d5ReJEZn1bU9YXcndkHb0Wc/EjuBHl 5Q== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3jc3bpw4sr-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Sep 2022 05:14:17 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Wed, 7 Sep 2022 05:14:15 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.12 via Frontend Transport; Wed, 7 Sep 2022 05:14:15 -0500 Received: from debianA11184.ad.cirrus.com (unknown [198.61.65.149]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id C3086B06; Wed, 7 Sep 2022 10:14:14 +0000 (UTC) From: Richard Fitzgerald To: , , , , , , , , , Subject: [PATCH 5/7] soundwire: intel: Don't disable interrupt until children are removed Date: Wed, 7 Sep 2022 11:14:00 +0100 Message-ID: <20220907101402.4685-6-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907101402.4685-1-rf@opensource.cirrus.com> References: <20220907101402.4685-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: BS6SyyWSBXeYEESWKkhNzUK3mS-9E41G X-Proofpoint-ORIG-GUID: BS6SyyWSBXeYEESWKkhNzUK3mS-9E41G X-Proofpoint-Spam-Reason: safe Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Richard Fitzgerald , linux-kernel@vger.kernel.org, sound-open-firmware@alsa-project.org 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" The cadence_master code needs the interrupt to complete message transfers. When the bus driver is being removed child drivers are removed, and their remove actions might need bus transactions. Use the sdw_master_ops.remove callback to disable the interrupt handling only after the child drivers have been removed. Signed-off-by: Richard Fitzgerald --- drivers/soundwire/intel.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index 01be62fa6c83..d5e723a9c80b 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -1255,6 +1255,13 @@ static int intel_prop_read(struct sdw_bus *bus) return 0; } +static void intel_bus_remove(struct sdw_bus *bus) +{ + struct sdw_cdns *cdns = bus_to_cdns(bus); + + sdw_cdns_enable_interrupt(cdns, false); +} + static struct sdw_master_ops sdw_intel_ops = { .read_prop = sdw_master_read_prop, .override_adr = sdw_dmi_override_adr, @@ -1264,6 +1271,7 @@ static struct sdw_master_ops sdw_intel_ops = { .set_bus_conf = cdns_bus_conf, .pre_bank_switch = intel_pre_bank_switch, .post_bank_switch = intel_post_bank_switch, + .remove = intel_bus_remove, }; static int intel_init(struct sdw_intel *sdw) @@ -1502,7 +1510,6 @@ static void intel_link_remove(struct auxiliary_device *auxdev) */ if (!bus->prop.hw_disabled) { intel_debugfs_exit(sdw); - sdw_cdns_enable_interrupt(cdns, false); snd_soc_unregister_component(dev); } sdw_bus_master_delete(bus); From patchwork Wed Sep 7 10:14:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 603837 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 F32BFECAAD3 for ; Wed, 7 Sep 2022 10:16: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 3E9671655; Wed, 7 Sep 2022 12:15:13 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3E9671655 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662545763; bh=pngEVi3N+ZEwgMMqFUbEWRaD1NHXcKnxiXSFLfdMv8k=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AzIPjttVxFk42sBYyxD8eYmQm6CpEBff0aLsEo3eSQiQyUHwQzZ92hQCeTVGOh4d/ 1y4JXV0JZOSIcnKLP6tbrrFZWlamdwucXQDD4OgnU6BAtFm+nKAj5n4NVVBsN6L/nm nCyb8+8dwJ9tNo3QOt5HmOnIOTse8XujYX8MFAqI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id CABE7F8053C; Wed, 7 Sep 2022 12:14:28 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9EE4CF8053B; Wed, 7 Sep 2022 12:14:26 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (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 5071CF80528; Wed, 7 Sep 2022 12:14:20 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5071CF80528 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="nazYJdeq" Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2876a3M4006643; Wed, 7 Sep 2022 05:14:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=gAWorbqvu9wmVkfPa/PiPrn39wNLz/dXO8GV+EOWmyE=; b=nazYJdeqIKSsBCYbF96Z+Tr2V+W+Uj0i2OOQsooIXcvZC1dusucu0y27Dm1rGzUQltk3 vyCWkef6Vmag6S5Wn2lciim6GTtpVhmfzweC3KisWHYZYyKQACHEGjyDbz/rnYkZJL4z RWL+It21l3Hg+9NrTGY33e9HaUXEgrcyFlgPEsSjMJmpeK97IasvJMUZwARim6v1zhyg hkSWWJQZQ5cEKz75YK6kcccZfhHcPI0ly2T1Gcr0POPCYdUHHrHsjiZaXxjq3cRvluVJ vUpUF48DkJo+bQYuFW0vJKpCHp1Y0oiTkH660Kr5+tBpQgVTfUTzTAzFqXMhxzifF/Q3 3w== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3jc4b2dfns-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Sep 2022 05:14:17 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Wed, 7 Sep 2022 05:14:15 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.12 via Frontend Transport; Wed, 7 Sep 2022 05:14:15 -0500 Received: from debianA11184.ad.cirrus.com (unknown [198.61.65.149]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 632CBB10; Wed, 7 Sep 2022 10:14:15 +0000 (UTC) From: Richard Fitzgerald To: , , , , , , , , , Subject: [PATCH 6/7] soundwire: intel: Don't disable pm_runtime until children are removed Date: Wed, 7 Sep 2022 11:14:01 +0100 Message-ID: <20220907101402.4685-7-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907101402.4685-1-rf@opensource.cirrus.com> References: <20220907101402.4685-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: mmVUuAqqRom5Ky22p7pj3hn5CXe0KQZN X-Proofpoint-ORIG-GUID: mmVUuAqqRom5Ky22p7pj3hn5CXe0KQZN X-Proofpoint-Spam-Reason: safe Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Richard Fitzgerald , linux-kernel@vger.kernel.org, sound-open-firmware@alsa-project.org 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" When the bus driver is removed the child drivers will be removed first. These may need to perform bus transactions to shut down, and the device driver core will runtime-resume the driver before calling its remove(). For this to work the pm_runtime of the bus driver must still be enabled. So do not disable pm_runtime until the bus driver has been unregistered. Though this could be done by powering-up the bus driver and then disabling its pm_runtime with the bus still powered-up, there's no need to bypass the standard device framework behaviour. Signed-off-by: Richard Fitzgerald --- drivers/soundwire/intel.c | 4 +++- drivers/soundwire/intel_init.c | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index d5e723a9c80b..3345310e979c 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -1504,7 +1504,7 @@ static void intel_link_remove(struct auxiliary_device *auxdev) struct sdw_bus *bus = &cdns->bus; /* - * Since pm_runtime is already disabled, we don't decrease + * Since pm_runtime will be disabled, we don't decrease * the refcount when the clock_stop_quirk is * SDW_INTEL_CLK_STOP_NOT_ALLOWED */ @@ -1513,6 +1513,8 @@ static void intel_link_remove(struct auxiliary_device *auxdev) snd_soc_unregister_component(dev); } sdw_bus_master_delete(bus); + + pm_runtime_disable(&auxdev->dev); } int intel_link_process_wakeen_event(struct auxiliary_device *auxdev) diff --git a/drivers/soundwire/intel_init.c b/drivers/soundwire/intel_init.c index 078e01f67830..ce26d2df088a 100644 --- a/drivers/soundwire/intel_init.c +++ b/drivers/soundwire/intel_init.c @@ -115,7 +115,6 @@ static int sdw_intel_cleanup(struct sdw_intel_ctx *ctx) ldev = ctx->ldev[i]; - pm_runtime_disable(&ldev->auxdev.dev); if (!ldev->link_res.clock_stop_quirks) pm_runtime_put_noidle(ldev->link_res.dev); From patchwork Wed Sep 7 10:14:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 603836 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 DCE30ECAAD3 for ; Wed, 7 Sep 2022 10:16:47 +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 F289F167C; Wed, 7 Sep 2022 12:15:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz F289F167C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662545806; bh=aSgaVpi+ivV3bTqE4kNeJkYQRYEarr4qgnLCg6wHbVU=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=idN57UxgWLUvE4imIFuaO2lAk0XjyX+idg3nOeSSNUS7u24lmEW+OoB05s6KaBr/t VHS85f0geYwkEPWYRBCdOM717YxRCvDmJrdUoSCOn9Vg2IWVIW20u110O8rZMbm4Ul tZ+f5DIIg6IXcCA4hBfAUpdsFFuBr2vTfQvECLwI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id D0E4DF8055A; Wed, 7 Sep 2022 12:14:35 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C3EC1F80423; Wed, 7 Sep 2022 12:14:28 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (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 F23DEF80423; Wed, 7 Sep 2022 12:14:20 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz F23DEF80423 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="gjFKs0vp" Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2876a3M5006643; Wed, 7 Sep 2022 05:14:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=feKchwoppPrkELgyg0NGjoUkLqBZXbRFHwDJEun2AkY=; b=gjFKs0vphFcvAi4tr4FhImRRKRpFkev9Qp1oiC/Q0rqgYZeCDktNokwIaP9M2PXkCn3y uIGbk63aFTcS7ch5G08wK1NI9P4eC5bIgCyJiV85s6xHSbdLxFXMT2RdpC3BKl6D04bk pRHq+/Fdib4Mqe4U11CtMZy0E+RT7a7QwZbBQlnGV+6O9vyIdelqR71mfvVsqsuRXHch Vlf2g8UHKtPgRtIhZSOlrwAPnMq3A4e/qpwnAomwgEzD+T2mcZqcuCdD6caW1JFISiaj udWNqMcBlpEs2jlBt2mDJq/dEdkOfxThcywlE8cwqwqfGTscpJv4/mANGcSS6gRQDiMF ag== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3jc4b2dfns-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Sep 2022 05:14:18 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Wed, 7 Sep 2022 05:14:16 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.12 via Frontend Transport; Wed, 7 Sep 2022 05:14:16 -0500 Received: from debianA11184.ad.cirrus.com (unknown [198.61.65.149]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 0664C7C; Wed, 7 Sep 2022 10:14:15 +0000 (UTC) From: Richard Fitzgerald To: , , , , , , , , , Subject: [PATCH 7/7] soundwire: bus: Fix premature removal of sdw_slave objects Date: Wed, 7 Sep 2022 11:14:02 +0100 Message-ID: <20220907101402.4685-8-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907101402.4685-1-rf@opensource.cirrus.com> References: <20220907101402.4685-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: _ls588k8dOn_DCOUtnfdFdo7W2FW14bA X-Proofpoint-ORIG-GUID: _ls588k8dOn_DCOUtnfdFdo7W2FW14bA X-Proofpoint-Spam-Reason: safe Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Richard Fitzgerald , linux-kernel@vger.kernel.org, sound-open-firmware@alsa-project.org 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" When the bus manager is removed sdw_bus_master_delete() should not be deleting the struct sdw_slave objects until the bus manager has been stopped. The first step of removing child drivers should only be calling device_unregister() on the child. The counterpart to sdw_drv_probe() is sdw_drv_remove(), not sdw_delete_slave(). The sdw_slave objects are created by the bus manager probe() from ACPI/DT information. They are not created when a child driver probes so should not be deleted by a child driver remove. Change-Id: I25cc145df12fdc7c126f8f594a5f76eedce25488 Signed-off-by: Richard Fitzgerald --- drivers/soundwire/bus.c | 30 ++++++++++++++++++++++++++---- drivers/soundwire/slave.c | 21 +++++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 1327a312be86..5533eb589286 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -146,9 +146,8 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, } EXPORT_SYMBOL(sdw_bus_master_add); -static int sdw_delete_slave(struct device *dev, void *data) +static int sdw_delete_slave(struct sdw_slave *slave) { - struct sdw_slave *slave = dev_to_sdw_dev(dev); struct sdw_bus *bus = slave->bus; sdw_slave_debugfs_exit(slave); @@ -163,7 +162,24 @@ static int sdw_delete_slave(struct device *dev, void *data) list_del_init(&slave->node); mutex_unlock(&bus->bus_lock); + mutex_destroy(&slave->sdw_dev_lock); + kfree(slave); + + return 0; +} + +static int sdw_remove_child(struct device *dev, void *data) +{ + /* + * Do not remove the struct sdw_slave yet. This is created by + * the bus manager probe() from ACPI information and used by the + * bus manager to hold status of each peripheral. Its lifetime + * is that of the bus manager. + */ + + /* This will call sdw_drv_remove() */ device_unregister(dev); + return 0; } @@ -171,16 +187,22 @@ static int sdw_delete_slave(struct device *dev, void *data) * sdw_bus_master_delete() - delete the bus master instance * @bus: bus to be deleted * - * Remove the instance, delete the child devices. + * Remove the child devices, remove the master instance. */ void sdw_bus_master_delete(struct sdw_bus *bus) { - device_for_each_child(bus->dev, NULL, sdw_delete_slave); + struct sdw_slave *slave, *tmp; + + device_for_each_child(bus->dev, NULL, sdw_remove_child); /* Children have been removed so it is now safe for the bus to stop */ if (bus->ops->remove) bus->ops->remove(bus); + /* Now the bus is stopped it is safe to free things */ + list_for_each_entry_safe(slave, tmp, &bus->slaves, node) + sdw_delete_slave(slave); + sdw_master_device_del(bus); sdw_bus_debugfs_exit(bus); diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c index c1c1a2ac293a..b6161d002b97 100644 --- a/drivers/soundwire/slave.c +++ b/drivers/soundwire/slave.c @@ -10,10 +10,23 @@ static void sdw_slave_release(struct device *dev) { - struct sdw_slave *slave = dev_to_sdw_dev(dev); - - mutex_destroy(&slave->sdw_dev_lock); - kfree(slave); + /* + * The release() callback should not be empty + * (see Documentation/core-api/kobject.rst) but the ownership + * of struct sdw_slave is muddled. It is used for two separate + * purposes: + * 1) by the bus driver to track its own state information for + * physical devices on the bus and found in ACPI/DT, whether + * or not there is a child driver for it; + * 2) to hold the child driver object. + * + * The struct sdw_slave cannot be freed when the child driver + * is released because it is holding info used by the bus + * driver. It is freed when the bus driver is removed. + * + * Until the ownership issue is untangled this cannot free + * the struct sdw_slave object containing the child dev. + */ } struct device_type sdw_slave_type = {