From patchwork Wed May 3 08:10:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Daniel Baluta (OSS)" X-Patchwork-Id: 13229803 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 2B1E0C7EE2C for ; Wed, 3 May 2023 08:13:08 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 771841371; Wed, 3 May 2023 10:12:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 771841371 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1683101584; bh=lSTQENumdjLPEEB/5Wj4d0ZFovoINuizvnCvWKnGpOU=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=o88gSwownjxH0fwhorrWDDtUTqEithyL9UaKqetR5xkaahm1h/prBSrHoUg30KyEF 40JxPEzNEislrTqJyy+yL5T6sgBTfQGOlkuYuEMe9zUeeafb7dgR33X7wEcIr5pWiQ brmTyfQHdgzTM3Wl8g9AhFzrWvku8ldB8Qq0XHAk= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 43740F80544; Wed, 3 May 2023 10:11:25 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 76F03F8052D; Wed, 3 May 2023 10:11:21 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20600.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::600]) (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 E3052F80137 for ; Wed, 3 May 2023 10:11:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E3052F80137 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-NXP1-onmicrosoft-com header.b=gA8B2WrP ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kXQX+UUJY2bu9LxYIgsO52Mqckz5jwvkjluqLGppct67bkVjxvot4eYZIoVTAP8vEdKzfP7MNswEHvMFHcbZ+UnB1odcR3BDl0JOwRHKFdqmfbLl2T2wZ1CMYN52E+25sjvVTzfpZbGRqkU+UMCYezO7YOiN4xXo/XMDN3XYfMNYmSCvoICMxDuAx8BC4fhnpcY6SuA+UAi0gaAxplcuT91pjrwwPDRoCzEAxSHmIz39Sr6vSjFSZysfpRfMkFIMh+QlauX2uQ/1ARoaNIfM5qYPgtxdA8zr4BCW2Bq0lheH44Z85pIyThhFu8dFHoHkj91L42uQT8Gy05f0d6+M6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OXAvWKaynpHsAI1tgqGNwCOSqmltsAuQnpT0Am+tucc=; b=Bll+tRMMUVTb/QwX30GKU5G1rBAbUCPGNNrb91Y4RJ5iftf7YKwVCOmCGBfp29Uqk1e59LwC9EeLHDrMUF+zYsQOH5KCejNUY7qLxsHsisSbSBsjnxDea/u0V28DERfg/wDdX2pL7MvRmr1eiIEZ3/kCiPxE+o4IwlhU8Ei8OIunwsMA3a0NEKDNaAPzBH0VCI+Zkx+gOYTfvUIvd6JE46go2y/7lQTMKi7Qy9R8OubBOgi+tpKKaQWmYlPhUT9w4f/ZCAb1ofhzk9bzvi1y3chcm9msMuJDhxq86NKY7BKiIag1DZISf5mjUtfLyCABji26YeNzKAIJT1j344QTFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OXAvWKaynpHsAI1tgqGNwCOSqmltsAuQnpT0Am+tucc=; b=gA8B2WrPgc0Av1aDvFhO+dr8ETd87lm38hJ55WzONcnqtXAt+He+skg/5urpo/bzr3hn04aaXPmLWf9zasvcP4KGWFrJ5JGHsOUh24VKLPQGGs4JFjwRuidv/uMAwjusUzco1kKPVel2BvZuXi16QVEGJefSahXc5CDbWsI2ArQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR04MB5151.eurprd04.prod.outlook.com (2603:10a6:803:61::28) by DB9PR04MB9865.eurprd04.prod.outlook.com (2603:10a6:10:4f0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Wed, 3 May 2023 08:11:07 +0000 Received: from VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9]) by VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9%5]) with mapi id 15.20.6363.021; Wed, 3 May 2023 08:11:07 +0000 From: Daniel Baluta To: broonie@kernel.org, alsa-devel@alsa-project.org Subject: [PATCH 1/2] ASoC: sof: Improve sof_ipc3_bytes_ext_put function Date: Wed, 3 May 2023 11:10:48 +0300 Message-Id: <20230503081049.73847-2-daniel.baluta@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230503081049.73847-1-daniel.baluta@oss.nxp.com> References: <20230503081049.73847-1-daniel.baluta@oss.nxp.com> X-ClientProxiedBy: AM8P190CA0030.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:219::35) To VI1PR04MB5151.eurprd04.prod.outlook.com (2603:10a6:803:61::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5151:EE_|DB9PR04MB9865:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c1ef4e1-761e-4dba-7643-08db4badf271 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pLFmu42TyUzSMTz3BtVhR1LaoyTdAkNnQXMAqw8uUeRU5zO2dsNtyRbO6pZ/XrQg/DyCVjCBxQZ3pIr+PGSkI42tsZ4ddWF+b+bACb4Y5sqj5DowzciAjOP392JQp1zjNwdqXcMFSKF85Fi7mkngQyYaKTE3QRp5rvWuMjap+XvGQT4vfPcVLdCxR4oVZBfiu8XzSO9ss3T08CrSLDn9INWGwEKjQq3t5gD33RhdoIXlneUxfeTlJUPt9n70wkuIg4M67H+W6qiwU47aQ1iidoJCQ2SD0tjSaf4grzZ90QPuHdMMg94vkP4UcAxbVTckXy/iFhOkzXozdTI8VbdFleo2W9w8OkFTLnVvKZK1L2+SkG3rpn8qxFlydpX5gwCGRILZXb6q6dpKgVItbnksuHGHt6VYsFlrcOpp7xDg/TdS6Gcprj+3r+lmr7HCTJqj/UKcz71fYxBLy+QZZC+KLkXSJZYBnQuZOcw7NVJwzE8yWR7sO7jutBcHKM4knvgdO7HTw9msMiq4bkrkWqd2+qHoR6csKrBOB8d2AfB3ITlCKZDFgfWa59VxYptlwtBdugnYF/dpYVS+jr4pSjGMlEHJuUn4VH34wNERV3/mSWW9TgSHK1KmMZU01xcmv0lC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5151.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(366004)(39860400002)(396003)(136003)(376002)(451199021)(2616005)(83380400001)(478600001)(186003)(4326008)(66556008)(66476007)(66946007)(26005)(6486002)(52116002)(66574015)(6666004)(6512007)(6506007)(1076003)(44832011)(316002)(8676002)(8936002)(7416002)(5660300002)(41300700001)(2906002)(38100700002)(38350700002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AeqWBJv7grjCU342FQHeiPFYfQRM?= =?utf-8?q?DN2pZp/3evp03nOqHzAheTdUk/km+7Cxkzpir3TGD4urDuAiNMFrtWsQvK3Paowmj?= =?utf-8?q?h4/dZ4iM3TgBiTrybNrDjLZJwgcCTM0PoWNqJ4we5Mq7p7ER+G38cG9IIg15Guy8I?= =?utf-8?q?6SqF6XFfQyGOfxRF/ndNbb/fhi1cTitMmrm5VM7V0bjwQjsxbCOHMZZlGZh3QsujQ?= =?utf-8?q?P6ybA01MJsrw1B/wqNy/cnCHOqUdeFLH1w30UUDLZuzCD7zA2lFoFKAZV2k/8nOHP?= =?utf-8?q?xFE0u4uKDHx3zXNfaW+y3lWnDB97f8qClCk4dLcbakYsRJM1a+jl9jmu8OJIXWoPP?= =?utf-8?q?Sc7ZT8tByr111BLcbSUeVuEnahjnLBC2HYE+lCVjmE833izo6t25Bd9rRQD6eAuPK?= =?utf-8?q?eOkkE37pDULckL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1GTc4wVowE+zRSs1Pram3d8O1Pk5hOFs+?= =?utf-8?q?O0HDn6JaWt9uUWXam265Z7eWlugCOPi1IENN/a1Frtf5eV6ZpuHGWapMAdM9oViJa?= =?utf-8?q?3iKdcXhFh5SS63aONGvWiZR9eK9ce7zBMPDdbY5M8WhQdEjciDp/AmJ9KUYon5pnn?= =?utf-8?q?ZkqEJlPZ33WMWujVc5FknEWlcaLrC/PmaIakjkPwd/1WqLFk/QFdl3Izic7UOp0+R?= =?utf-8?q?polaDzakkPbh?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c1ef4e1-761e-4dba-7643-08db4badf271 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5151.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 08:11:07.3688 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kALIMjIkHythEsRteD0X3ao3NhR0L7SP8+apg6/75sOffi4vsy1pqhBQwr+TpmMp+jgjGOOVnaUXOjYSFqYz0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9865 Message-ID-Hash: X6BOAR2BUFRPSAJY44PTJ5WXHV6ADLC5 X-Message-ID-Hash: X6BOAR2BUFRPSAJY44PTJ5WXHV6ADLC5 X-MailFrom: daniel.baluta@oss.nxp.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, peter.ujfalusi@linux.intel.com, yung-chuan.liao@linux.intel.com, ranjani.sridharan@linux.intel.com, kai.vehmanen@linux.intel.com, daniel.baluta@gmail.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Paul Olaru The function is improved in the way that if the firmware returns a validation error on the newly sent bytes, then the kernel will automatically restore to the old bytes value for a given kcontrol. This way, if the firmware rejects a data blob then the kernel will also reject it, instead of saving it for the next suspend/resume cycle. The old behaviour is that the kernel would save it anyway and on next firmware boot it would apply the previously-rejected configuration, leading to errors during playback. Additionally, the function also saves previously validated configurations, so that if the firmware does end up rejecting a new bytes value the kernel can send an old, previously-valid configuration. Reviewed-by: Daniel Baluta Reviewed-by: Péter Ujfalusi Signed-off-by: Paul Olaru Signed-off-by: Daniel Baluta --- sound/soc/sof/ipc3-control.c | 54 ++++++++++++++++++++++++++++++++---- sound/soc/sof/sof-audio.h | 1 + 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/sound/soc/sof/ipc3-control.c b/sound/soc/sof/ipc3-control.c index ad040e7bb850..a8deec7dc021 100644 --- a/sound/soc/sof/ipc3-control.c +++ b/sound/soc/sof/ipc3-control.c @@ -96,6 +96,26 @@ static int sof_ipc3_set_get_kcontrol_data(struct snd_sof_control *scontrol, cdata->elems_remaining = 0; ret = iops->set_get_data(sdev, cdata, cdata->rhdr.hdr.size, set); + if (!set) + goto unlock; + + /* It is a set-data operation, and we have a backup that we can restore */ + if (ret < 0) { + if (!scontrol->old_ipc_control_data) + goto unlock; + /* + * Current ipc_control_data is not valid, we use the last known good + * configuration + */ + memcpy(scontrol->ipc_control_data, scontrol->old_ipc_control_data, + scontrol->max_size); + kfree(scontrol->old_ipc_control_data); + scontrol->old_ipc_control_data = NULL; + /* Send the last known good configuration to firmware */ + ret = iops->set_get_data(sdev, cdata, cdata->rhdr.hdr.size, set); + if (ret < 0) + goto unlock; + } unlock: if (lock) @@ -351,6 +371,7 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data; struct snd_soc_component *scomp = scontrol->scomp; struct snd_ctl_tlv header; + int ret = -EINVAL; /* * The beginning of bytes data contains a header from where @@ -381,31 +402,52 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, return -EINVAL; } - if (copy_from_user(cdata->data, tlvd->tlv, header.length)) - return -EFAULT; + if (!scontrol->old_ipc_control_data) { + /* Create a backup of the current, valid bytes control */ + scontrol->old_ipc_control_data = kmemdup(scontrol->ipc_control_data, + scontrol->max_size, GFP_KERNEL); + if (!scontrol->old_ipc_control_data) + return -ENOMEM; + } + + if (copy_from_user(cdata->data, tlvd->tlv, header.length)) { + ret = -EFAULT; + goto err_restore; + } if (cdata->data->magic != SOF_ABI_MAGIC) { dev_err_ratelimited(scomp->dev, "Wrong ABI magic 0x%08x\n", cdata->data->magic); - return -EINVAL; + goto err_restore; } if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, cdata->data->abi)) { dev_err_ratelimited(scomp->dev, "Incompatible ABI version 0x%08x\n", cdata->data->abi); - return -EINVAL; + goto err_restore; } /* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */ if (cdata->data->size > scontrol->max_size - sizeof(struct sof_abi_hdr)) { dev_err_ratelimited(scomp->dev, "Mismatch in ABI data size (truncated?)\n"); - return -EINVAL; + goto err_restore; } /* notify DSP of byte control updates */ - if (pm_runtime_active(scomp->dev)) + if (pm_runtime_active(scomp->dev)) { + /* Actually send the data to the DSP; this is an opportunity to validate the data */ return sof_ipc3_set_get_kcontrol_data(scontrol, true, true); + } return 0; + +err_restore: + /* If we have an issue, we restore the old, valid bytes control data */ + if (scontrol->old_ipc_control_data) { + memcpy(cdata->data, scontrol->old_ipc_control_data, scontrol->max_size); + kfree(scontrol->old_ipc_control_data); + scontrol->old_ipc_control_data = NULL; + } + return ret; } static int _sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol, diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index a090a9eb4828..5d5eeb1a1a6f 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -362,6 +362,7 @@ struct snd_sof_control { size_t priv_size; /* size of private data */ size_t max_size; void *ipc_control_data; + void *old_ipc_control_data; int max; /* applicable to volume controls */ u32 size; /* cdata size */ u32 *volume_table; /* volume table computed from tlv data*/ From patchwork Wed May 3 08:10:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Daniel Baluta (OSS)" X-Patchwork-Id: 13229802 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 D1838C77B78 for ; Wed, 3 May 2023 08:13:01 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 3B8DF1364; Wed, 3 May 2023 10:12:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3B8DF1364 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1683101579; bh=d1mmm0s70maG1iaKOxL+UKeJbxEJHZ24xNV8tsWHiMo=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=b2sL2dq6OZe83LwsrgIIfA8OcH4aDItolAb/9RBC3MOF9yKjWfF7nHfJ8VEg96wtF MaWgGt0YqL+PIMs/2UPAlbRjAasOMxf2eG6uHHCZCnYz2Dc5dmxQM5UBj+uqd31xco R58gr1oShkWqcHz8WtJYl/jUfBBvQ2PqRqoUoxMQ= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id BF77CF8052D; Wed, 3 May 2023 10:11:21 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1BD0FF8032B; Wed, 3 May 2023 10:11:16 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20600.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::600]) (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 37D29F8032B for ; Wed, 3 May 2023 10:11:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 37D29F8032B Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-NXP1-onmicrosoft-com header.b=Lp0EW/wE ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QTqTlgYLnEMhsfYQROcOmprRN8oEy1wsfL66dIAnSiMgKXpZic+RKM3/DEub9xWO+dJDInbi2Oj64peQkWd71RX2+nFHXP15eIykKVTfUKPfdWq+/M7xSAUsnKLI7dWi/qNwFxsKJugncFQ+Ab5sphqPkU1DCnETNZQSym+sDScPK20VlF5jGQmr88wzBWD1y1LEb85rRzzYWaHL2wzdh0LgX01JEO8pgZRjgNPS7p+PNLk5i0dzDLhejBecx/dxbAUaogm/cisTyK4LjbXhjxL9u46RBAuSCKJueqWzEUUOSqg2UAMnH4egAa27jtbYpQF2uSHylfRuxCc8CkUwGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VdJB7DfPMN5TpI2aSmxNRf/xXhSL2fePyA3eXXbmOcQ=; b=D9u3pVrV01X8R/oQ4CR59qGi9EGEww6IqRc31yoG6D6nKgaQT5M9vp2CLvY6eomBLSmKNR54EDBKLP8mJyERKvJJDWB/M7GrMDgfZ4iuXKzharZFWowopbzcPUqFmwi5NgeHVfV4QzsyZJ+lbJv9j11HjW5gVPOFh4sDXCVTZQHR2HZ5F1LWDEfLPM2OC/vIZ7Yn9S7jMXW3nMChmcOqKFogE3rTK5CyNw1oX4WPLKJRMTHxeqX/iJqvAcin5Nww85m6eQG9sSdavs89cPJNpfnjG70nP6S5XJL8IveLygT/AdLL13BF4CBK08K5RMrPOuqofJEfN/tkiiQMNcU6rQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VdJB7DfPMN5TpI2aSmxNRf/xXhSL2fePyA3eXXbmOcQ=; b=Lp0EW/wEoyHgm7h4Ew5qRJcEO0iQjg9MhPo1o/hrqEXkjOnAxeZlAlh/hHfwdHrBv6MwQyQo68GYfI8PvnT1JyN3bkw9sT6dUMehtOexvUpM4FUtfFQIKkuia2DyP667XnSbva8npa802Mc1h5vQjE121dOZfesA1iRp1CtjCUM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR04MB5151.eurprd04.prod.outlook.com (2603:10a6:803:61::28) by DB9PR04MB9865.eurprd04.prod.outlook.com (2603:10a6:10:4f0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Wed, 3 May 2023 08:11:08 +0000 Received: from VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9]) by VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9%5]) with mapi id 15.20.6363.021; Wed, 3 May 2023 08:11:08 +0000 From: Daniel Baluta To: broonie@kernel.org, alsa-devel@alsa-project.org Subject: [PATCH 2/2] ASoC: sof: Improve sof_ipc4_bytes_ext_put function Date: Wed, 3 May 2023 11:10:49 +0300 Message-Id: <20230503081049.73847-3-daniel.baluta@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230503081049.73847-1-daniel.baluta@oss.nxp.com> References: <20230503081049.73847-1-daniel.baluta@oss.nxp.com> X-ClientProxiedBy: AM8P190CA0030.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:219::35) To VI1PR04MB5151.eurprd04.prod.outlook.com (2603:10a6:803:61::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5151:EE_|DB9PR04MB9865:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b490060-08b1-434a-ceb2-08db4badf30e X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gKoiAFxfHhWB5Gy3NX0lff7IHkHv5gHc56JewxRByijYaBWHdYQjjhxv/FJGEEHY3DdwEXYIWpafuyb9BAr5opRhHimVeuRTbiD6LKemscH8SuvA4rTKOHcxn37Jq9gTVm457Y4hZWs2xy+Mk1LrOnqHH8DY/fhaEMKtJs2bXrayLR1iRbxBBguDnoWu+rG2FIJMlDWD9bgNIFOI+8gwXFA+2uu/9EgUexJc3AvOVbH8bNOQLVR+ExCFDEsiEqjLwFhyTGKRb9z8R9Ec5V5dO7lyEvKP3Jz9KUr/Ic123P3j2A8eZqmPpFiF1BCi3ucRnvD8w+maCY3e7e/VdAdCFPsn+N4lZVP7/RosRT8GszdaF6OHt5nj8HCOomP8tE7Gm09Z2YZ72nlSFPLqppBY1LTXpoMpebbSWfPlMdlu3b4ze4Mlh3D41/3YOSBwI9FJB7oKkX1ZVvSp3wTbnNQJfwgStSCO0aGAngoXxyFoNyZe8ppSngHcY4KYhCTaoa7lca/uvEi7l5DMovKV8dlc9OGw3hIkje6a1HVPgYAEVNFn88FPbdYs0Riu1jNVVuEu+Y+rjFnYONKRWMqcXFO+VPKnpWCIWWbPL89GmPOwZEJp6zbLlwyN0ESgx+Nw7VQW X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5151.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(366004)(39860400002)(396003)(136003)(376002)(451199021)(2616005)(83380400001)(478600001)(186003)(4326008)(66556008)(66476007)(66946007)(26005)(6486002)(52116002)(66574015)(6666004)(6512007)(6506007)(1076003)(44832011)(316002)(8676002)(8936002)(7416002)(5660300002)(41300700001)(2906002)(38100700002)(38350700002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?lX62Wea9LJqBNduakuh8fbWCu/dE?= =?utf-8?q?HwzpjT3LKUmpHQexOBM3afVJNceZhj+e0AYVFgiwUb/5J2R4PyMLlwa0Gq/wpgWAI?= =?utf-8?q?DAoBVWxq0nWtLF76LbYjzXzFqo0mGLjklIrsOpMj4qzZEBOGrzSAtlWzCGLB71dfe?= =?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LwFoIbO4ck1m?= =?utf-8?q?kUGIudzW0zJHwUFKs1fdBlzYPVvw+WhCrDcKquljbvt5PqxW4cyCrRKKtSGbqWcAZ?= =?utf-8?q?znksmTVwr45eDx3oKsnzVmeNncIEZHKVvKPocn9fnfHGOudkBWuRq7NxUcwINsXQe?= =?utf-8?q?AgkI/NJfZeQVrGupT0+80M1W0wBJtrwVxWwMCFl0SyFhhVv2+7YCuG8JDbEBKHaNR?= =?utf-8?q?H0j1jVBFXCeUvvTAlHbicPd9kQa+VpqWjTY/OX9b2+f1+3AXkfHPY6t9wUqIxOq60?= =?utf-8?q?bTv07k3mrNQxBlDbs0dvzk9iOUkEHSGv9qI5N2L7WYEHQr3/8oqo7rBEUK89xBFUt?= =?utf-8?q?YBPTkWcYMcAcm+g52c0JLQlxY/b++4WzWucTiNFwAgtDB+PEV4mzpvLeNNKWeTjv2?= =?utf-8?q?fqIdwVPH/9lSCIRKcAZqeo1x/tQ8uRkfiat3csG+bNStfPaLdjEoJdFINZycqaRtE?= =?utf-8?q?r5hrijSgS2TliXTZK+xpMNpU5AA0PtbpOK7YCDxM+ORN/2KhTkoOpsv+XMOZsxz+O?= =?utf-8?q?oDJRuWODLI7c?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b490060-08b1-434a-ceb2-08db4badf30e X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5151.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 08:11:08.4182 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Kpfy4lJV8SZ7TSiSS8U9gvcq2I5U0qGjLzo73+lwHn09r4jLPB5SmMBixFRnz/j5VTWXXHDCaNOr6BDLBJdqzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9865 Message-ID-Hash: LDRPLZDFD7AZ7Q7PR6ZDVB3O55L7FS7R X-Message-ID-Hash: LDRPLZDFD7AZ7Q7PR6ZDVB3O55L7FS7R X-MailFrom: daniel.baluta@oss.nxp.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, peter.ujfalusi@linux.intel.com, yung-chuan.liao@linux.intel.com, ranjani.sridharan@linux.intel.com, kai.vehmanen@linux.intel.com, daniel.baluta@gmail.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Paul Olaru The function is improved in the way that if the firmware returns a validation error on the newly sent bytes, then the kernel will automatically restore to the old bytes value for a given kcontrol. This way, if the firmware rejects a data blob then the kernel will also reject it, instead of saving it for the next suspend/resume cycle. The old behaviour is that the kernel would save it anyway and on next firmware boot it would apply the previously-rejected configuration, leading to errors during playback. Additionally, the function also saves previously validated configurations, so that if the firmware does end up rejecting a new bytes value the kernel can send an old, previously-valid configuration. Reviewed-by: Daniel Baluta Reviewed-by: Péter Ujfalusi Signed-off-by: Paul Olaru Signed-off-by: Daniel Baluta --- sound/soc/sof/ipc4-control.c | 39 ++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/sound/soc/sof/ipc4-control.c b/sound/soc/sof/ipc4-control.c index 6f0698be9451..c6d404d44097 100644 --- a/sound/soc/sof/ipc4-control.c +++ b/sound/soc/sof/ipc4-control.c @@ -54,6 +54,26 @@ static int sof_ipc4_set_get_kcontrol_data(struct snd_sof_control *scontrol, msg->primary |= SOF_IPC4_MOD_INSTANCE(swidget->instance_id); ret = iops->set_get_data(sdev, msg, msg->data_size, set); + if (!set) + goto unlock; + + /* It is a set-data operation, and we have a valid backup that we can restore */ + if (ret < 0) { + if (!scontrol->old_ipc_control_data) + goto unlock; + /* + * Current ipc_control_data is not valid, we use the last known good + * configuration + */ + memcpy(scontrol->ipc_control_data, scontrol->old_ipc_control_data, + scontrol->max_size); + kfree(scontrol->old_ipc_control_data); + scontrol->old_ipc_control_data = NULL; + /* Send the last known good configuration to firmware */ + ret = iops->set_get_data(sdev, msg, msg->data_size, set); + if (ret < 0) + goto unlock; + } unlock: if (lock) @@ -327,13 +347,24 @@ static int sof_ipc4_bytes_ext_put(struct snd_sof_control *scontrol, return -EINVAL; } + if (!scontrol->old_ipc_control_data) { + /* Create a backup of the current, valid bytes control */ + scontrol->old_ipc_control_data = kmemdup(scontrol->ipc_control_data, + scontrol->max_size, GFP_KERNEL); + if (!scontrol->old_ipc_control_data) + return -ENOMEM; + } + /* Copy the whole binary data which includes the ABI header and the payload */ - if (copy_from_user(data, tlvd->tlv, header.length)) + if (copy_from_user(data, tlvd->tlv, header.length)) { + memcpy(scontrol->ipc_control_data, scontrol->old_ipc_control_data, + scontrol->max_size); + kfree(scontrol->old_ipc_control_data); + scontrol->old_ipc_control_data = NULL; return -EFAULT; + } - sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true); - - return 0; + return sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true); } static int _sof_ipc4_bytes_ext_get(struct snd_sof_control *scontrol,