From patchwork Tue May 16 13:24:00 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: 13243172 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 C1C2CC77B7A for ; Tue, 16 May 2023 13:26:24 +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 051701ED; Tue, 16 May 2023 15:25:32 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 051701ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684243582; bh=lSTQENumdjLPEEB/5Wj4d0ZFovoINuizvnCvWKnGpOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=A+W00p47qgQH7nUgTXMIuGsnDz/xRYax3VvHUrIUOOoGJtVS44B9IQ9pIKA/oLug9 HIvnw94X8LuNgOHnEAbPvLByNwiIOce+daL/Vzp0Fw/zRbcKZ0ozpLqkXg+Yeuh67p 1LVSZgvd8WTZjx0s0+IJIjRC8LfdiTQXISKc/Xr8= Received: by alsa1.perex.cz (Postfix, from userid 50401) id A7A11F80579; Tue, 16 May 2023 15:24:43 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 2EF45F80579; Tue, 16 May 2023 15:24:43 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3FDBEF80551; Tue, 16 May 2023 15:24:37 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on20603.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1a::603]) (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 4E318F80087 for ; Tue, 16 May 2023 15:24:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4E318F80087 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=l0Je9Z2/ ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RDoebli8+vzuZocTQEIC2hWIukLGhuN7KErIQ8nLtMftOoboe3op9C/mTeXsbpplAFOEtoZPlmCP4ZKkvZKmLKe6ace24EVkxGdei8v1Or2mFCfkPZfSzjs7Uk1QCltjFc4YwWadi4aMmV/QXMhqIvA3EzvZ70XkQC8+0WurZ2vcS5VQxNpaIEyE4eebOis9AC4UYNIK0eIO5KddjNpsqhKbk71SKswUD0M/ZKRaX3RmqNpZT26U9ksw45IFz0ni8eF4pSD0+YAcMzhBMwoFbnrk3otLbSdOtY/OcH3qc5/QK6X1/h0wz2VDleBHQ75FHh/me1cugC/k3ML1r+Ouqg== 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=YZ1f2nsWjtIS1UeAh/ZYJL6u/ol+ouQX60pU0pnEq2FrXB5WCVJ6C5xmsqBDo3ClzaXfCay9mH8HEXtWzQ+EQCM1wy5CtmFvI1rviJjAphkMqYUHrkJwIO8KcYIvgnStrS3FQohDCXf/LWqyaknIC6G7A41eLuR7DrqJUt5wpHSN5HBETFtmFt6k45byyP04Rbn+ltaJf+9BS1hJFPvuVrtbRcTzojfcHo9/Z/hTy6D4qN6dQVkQNzeJ1lLsr6l2ba+410w/70mVWt+yLnWhpJm+cn7EBDrp/FRPH9dUr2JRpVat0a1V3CzboCeDDrfDWmR3FckAvx29IE+wSopdYA== 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=l0Je9Z2/+lCH8LHuOYAhhqJSE3w09bTFef0BdmyTvoRnbEWzIgz/vTfmo6NDSxSFxp/UtpUhM9CNPKolLVVo6o8kHyp/m66ubCI5lpa054KDMuA5tf1rEiM1OX89XW9/Dgx3kU6oCVFzh06K1MBGzVT2v3gm5uIa16yBTzjKUl4= 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 DU0PR04MB9635.eurprd04.prod.outlook.com (2603:10a6:10:31f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.30; Tue, 16 May 2023 13:24:25 +0000 Received: from VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9]) by VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9%7]) with mapi id 15.20.6387.030; Tue, 16 May 2023 13:24:25 +0000 From: Daniel Baluta To: broonie@kernel.org, alsa-devel@alsa-project.org 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 Subject: [RESEND PATCH 1/2] ASoC: sof: Improve sof_ipc3_bytes_ext_put function Date: Tue, 16 May 2023 16:24:00 +0300 Message-Id: <20230516132401.205563-2-daniel.baluta@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230516132401.205563-1-daniel.baluta@oss.nxp.com> References: <20230516132401.205563-1-daniel.baluta@oss.nxp.com> X-ClientProxiedBy: AS4P195CA0032.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:65a::6) 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_|DU0PR04MB9635:EE_ X-MS-Office365-Filtering-Correlation-Id: d32730dd-eca8-4ebd-22a7-08db5610de13 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: 8WEZqJMY+C7hvnW9j57PyzeGRiNk1yEt6VX5qoVspeKIzpmMCLC1tJQZ2dpd7Uzd9tv1GFjR/g/kxoYXPzQ4Q7AIPJjAssNTlRWe7aesZBUD41RQ1K4KY5DvURwwDuQFv3vuI9iYLbg3JfAKN9FFNlrqpPdLhRCcDox+85vui0v+ZICf/XVvoXZg4mKuZL4PX7c6AXdQ1dSVUV8IWtxPXVoXBAZpHRihFR+E/FHqZoP6aaYx+fEs9gfDQsWm8+oJhh5IiM1bID57PHPjUwU68J5VOltJFpM7jsHbGirNNDncn84FpNKYM0cf5B3I1Vzi4F/Jkfl7OgAnOT8cjbwTowLbojJ/bI2km8UxNN+Ry27YLCDLxdZol5cvsJ7yXgs6VzsCUVrCEru9TwfB7MOQX5qPJck0aWy19p9QeEutdRwACyygQdTZXD5ltaUXwX7lN9Nn7q6LURWGeFxFQjcrA+G3pb9QHFT+OU4kohNo0Z847488Wk6+ZzJ2SU5K2Sq2Da9aQQADw3q4D4VFkPHo2a54YTWh7mwcWcAY+cyxVLnSLqUsRkfKaPqoApenfnZt 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)(396003)(136003)(376002)(366004)(39860400002)(451199021)(83380400001)(66574015)(66476007)(66946007)(2616005)(52116002)(1076003)(6486002)(478600001)(8936002)(66556008)(44832011)(7416002)(6666004)(186003)(5660300002)(86362001)(2906002)(8676002)(6512007)(4326008)(316002)(6506007)(38100700002)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?/THuUuDsQ5frx/pb+naIlG8bQJJ4?= =?utf-8?q?YOSt91ZWs/A1JjbgpnNerUWN3yrNJYNHZHyyLEqVhOXkwKizcP8K/yCVSkZWVk5q6?= =?utf-8?q?/uT7C+VBveEThWUpumHO42OdGfZO9uiNf6LnPdMBoZA3Nk62cVM6jvym6FiJAWA5L?= =?utf-8?q?fXtOAwByAPNMAUg+P/+CFae93LNA06Ol+9199KmMczgzWu2XwiHn0mHA0BLs8qYmG?= =?utf-8?q?Jk67tb6Bi3UY6FcPa9mtAd2NrWUshWGXI7IVrMHTbp24PumVQA18hn/OFNEDfLwV4?= =?utf-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ZRoxWHLJsFgau0RU0yP/PyU2BvIHveVXVqCsqFL9m4zAUqF5Fhk/1?= =?utf-8?q?emhkyYjN6In107xPWsjs+KTZ1mIiiuMYOi0K2WYSr2HPGHNRChHstEXt3uUUsdx+P?= =?utf-8?q?PB/xrBBPXZs82K564qDRFb85LBdaXjBmLA1nzXNvsYDYgnKeaPE2kNZ2W4r+Y8Wzd?= =?utf-8?q?HtT13yi44tvopHPBSHzgI3Gs50KaQd84aT39PyIID1mca+AwS7lY7k06LTNoWeSjR?= =?utf-8?q?LbWpSrgU4NN1yt/60Zb5MGCOaDyEcLbUy5nQN8i7dMTZpT2Sp8Sw9dlaaqVVXteu2?= =?utf-8?q?riG7FzvRZqNwh4JSR9OroVMRauKZmDi71YPo2W60enXsYhYb7OdPVYaewYI/sNdGz?= =?utf-8?q?Nv22Utp4hHmjufBwdwJr6T/euD19viuOB+bm3ho3SQb2BoLoRy/Ii/YYZgdkSgKhT?= =?utf-8?q?+KfR14LE13h5Zes0l2u3RtcWBGA0HwYDA=3D=3D?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d32730dd-eca8-4ebd-22a7-08db5610de13 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5151.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 13:24:25.1001 (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: hu3VSr9ahasiJwwl1olRNPS60UJ11lnKyUuhPqNrFHZzLxphaErIsQi3DJiGOWmnhAyDogfl2PYsSW9YGvzJtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9635 Message-ID-Hash: 5KDHFXV6Z2WWKNRJU4VYH4D5V6HX6W2I X-Message-ID-Hash: 5KDHFXV6Z2WWKNRJU4VYH4D5V6HX6W2I 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 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 Tue May 16 13:24:01 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: 13243171 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 EDF1EC77B7F for ; Tue, 16 May 2023 13:26:21 +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 731411DF; Tue, 16 May 2023 15:25:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 731411DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684243579; bh=d1mmm0s70maG1iaKOxL+UKeJbxEJHZ24xNV8tsWHiMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=LzFd+2+RmJNckC9tX6pOt9X83ojzI8DJv3Rr+8ont+dMaTrwYf5p6NOzDzorbRBr5 IhrTJxHkLrLsCf7Km1mawTRqvoZtO40WwgzCsFaouK7S+ZPzFw3XqY6NeB/ndQ+wRb s/F2/7wQT9p3QBhD8fFciL9avB44veV1dOEKLDnk= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 572F6F80557; Tue, 16 May 2023 15:24:39 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 18073F80552; Tue, 16 May 2023 15:24:39 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4C696F802E8; Tue, 16 May 2023 15:24:36 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on20603.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1a::603]) (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 901EDF80272 for ; Tue, 16 May 2023 15:24:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 901EDF80272 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=N8N1gm5g ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xm2xsnmGflIrPzadm0HXrCB+IXwgEJGmW+GjCBji5BSALFtSGUWiahhRgvdYXY1jjSbavliPM6felBzC82pGnvu0+WpSD68LvWjJQOE95wLGrBL47VcWl91X78kZHozhp1pjwhHGGwxQ5E0ERSnFOgZXO7ow9enMHeCuyBjcn+bjjncCpC3rBxksNo9CHCA8lYBgH94wa9S/msfu2ZsD1bmCfHI1L7ftzypAcDb6mY5s6hW9McBwlKnnVI205QNeaeng5pEZYnggte5s/0UfLP1V6ZzLx0/i0f5gj03JzxerlBNzo0F9UkMxO6u/lhiBWjN5D97fgnOlJPnqMQRJLg== 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=D0LFy19i15rJaRCW0qe1zEqfZr3UZ4ZvH7Anrls34byon3nMqlX1ebt3fNxviibw7oY1y06yMwMSu50geriYxa3YQsufmkYDaZdZFxe2T9GWxyBHS3a1+/XCk6Lqst+EgmbjHfaGOoORkBmwci+nwyIOTsUTSnbbbT6gZVR8cmElGvQA4dLj4fCu/+KwDA8YZpvtyT1cQKBaQyhG/j9xIzCckyU04OYEFE9CNV8Gico/L3hg7oxvHa6SQ5VNaU3yHqUiqed+XruSNRaWYFELLw6or8W2xWetxKHfaVkcsQuDNfizMSRLtK5OAMVWs+O7j1u/L8k/MpDi2h73goKeLA== 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=N8N1gm5gbxIzAdUsxUWa7WWH4wxjPapxdKyDMC4vDG+NU4UntrWWBpoZpSl+Z4HJitnv+uWI6zbpZBCvLZk6yjfi2VlAfYdWp2JfkAT9wGyUe6aAOD8Iq5WLeQoYuz+4SlbBLxzxr/BsLiSOvi8G0pxgQB6k890MrJZbixQdjZ4= 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 DU0PR04MB9635.eurprd04.prod.outlook.com (2603:10a6:10:31f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.30; Tue, 16 May 2023 13:24:26 +0000 Received: from VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9]) by VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9%7]) with mapi id 15.20.6387.030; Tue, 16 May 2023 13:24:26 +0000 From: Daniel Baluta To: broonie@kernel.org, alsa-devel@alsa-project.org 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 Subject: [RESEND PATCH 2/2] ASoC: sof: Improve sof_ipc4_bytes_ext_put function Date: Tue, 16 May 2023 16:24:01 +0300 Message-Id: <20230516132401.205563-3-daniel.baluta@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230516132401.205563-1-daniel.baluta@oss.nxp.com> References: <20230516132401.205563-1-daniel.baluta@oss.nxp.com> X-ClientProxiedBy: AS4P195CA0032.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:65a::6) 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_|DU0PR04MB9635:EE_ X-MS-Office365-Filtering-Correlation-Id: afd348d5-9271-4910-c6de-08db5610dedd 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: jD1xkEDqjQwT0NWJkmIZsAiDlmwutNxa8a9y6AoHj8VGjN6BealkcjLN4hYQFOoR+sDmbG9RjLpFZzDe5nXx7SIEE9mI1Wrrc69WGws2Is4mNN20sPz5BHafR3B8ZRMBztnOCL6jfD2cBoMBKRL/604JEr7Z6361FrXVZ53xvFJQX4bWiO3sLDc7TkI3wJJP8aY9o9iuh1lbtDwaZlfYEi8NAfcU09EyKf85j5gWeEAdJVwwcAqKYa/VdvoNSgO47AxeB7MrN3zt+7tpm8L70Ua+6kkm841gRSLX/8E6xxMwXA52341lTB27GKaqCC3OgSzQys6YKpQkwbUi38O2xyypUClKwPhRMTWJWVoPhec1iaXvmEVwGFuq/eu4duRw9b9wPMzuVBjcv3mUdzRQVq1QZIDwk9ExO8M9veAc9Zv/NGKP0vmhFCRCKbvBGAV1hgLJEKA1e4geBX3bqGaPldiI77+DYOqN0QRSa2DbPt8UdmLVlrWxLcR7P+ZwLzL6fdXOFMY6IJF0dPaRQucY2iCPVjRN7iom14OKlWS46FHH2KAolrHwipKZo/iQNqLo 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)(396003)(136003)(376002)(366004)(39860400002)(451199021)(83380400001)(66574015)(66476007)(66946007)(2616005)(52116002)(1076003)(6486002)(478600001)(8936002)(66556008)(44832011)(7416002)(6666004)(186003)(5660300002)(86362001)(2906002)(8676002)(6512007)(4326008)(316002)(6506007)(38100700002)(41300700001);DIR:OUT;SFP:1101; X-MS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a7Bin0CdnaAu53/EGQvQ53Tfa6ME62tLu?= =?utf-8?q?BJmxyH01lOF14fQfFG6pTG37Ksy/NFTvz9cg2mHiWtbl4bFZd8UBi9W25CwHyARHD?= =?utf-8?q?p94GGiDm3vTiv0u0UD2/WDfQY3n+08bICbJum/PKBi5onHzBlbGqA/EEYT96j4W5v?= =?utf-8?q?AuaZLrFvQckOSTIvjiNtzL5QWa3x+tKUL3hH6O7fnxdtSUHUUa/3PheEiX4VqxxL9?= =?utf-8?q?54I7j3peJ9BlqplEqNarhbKesiKz9C1PHKLudzNm3q6ItHtr0vnjfvF/800MfSCNR?= =?utf-8?q?NEwmaZk+VeLbo+AOa0ia79gWFjj+8cLHR8SQpPXzyCQf/ceI/rW+tF1pRTUjO3G7W?= =?utf-8?q?/0w6H1b5lacdOl2xdbGbHnonqmwUIFoJiY3nEMoxyO2pxC+raWp79EFqbl47gUdAD?= =?utf-8?q?E6TC1fXGH7w0+1axjRmSCF7nuAxBb3xcMc/MGx0Iz1JylSZIETtGe5QQVQlFjW5kI?= =?utf-8?q?IaTUqMMLJ4tw+ZHQywIF7H1Jgxx1HUPR6xLk9bLgyyXUWk+VkE0p5yhK8pAK8kPAP?= =?utf-8?q?O8B3zdIuQDyNL5N+rdiE27INL2WKIfu+iewU22TVc0+Dhu+fwDjPczlhwZAddbSL5?= =?utf-8?q?A0a0jse5U8zyNhL14bSGXA+zeiHlEqkvQllii0WLzU0HMKuMXQrjBATxv6XM7vjyM?= =?utf-8?q?oSImx6HOMEWC/6ImB7aBq6+Qu2HUvorXSGVOjojsp7/JEZCK5f+EEEasvbgbYiih4?= =?utf-8?q?UhH0jW+lnW2sugImNPVTTz0Y7tlakR7oHeNKoCp4wGsUEO94l7mzE5H/+g9M+Gx1B?= =?utf-8?q?Z67iZ8fPbXH4T1bp2yS1JgVa4P2Acs9AQ=3D=3D?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: afd348d5-9271-4910-c6de-08db5610dedd X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5151.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 13:24:26.3507 (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: o5OzjfRBfuKrjGLXjmc9quigUKWWDSN0EcRQBJ3xoPgn2CouDtdtzaSClZV3lCZ/cLbowjjieHZOUggoe1W40A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9635 Message-ID-Hash: XSF4FG5KIGX2FAJUYCPPATMYK4UU32XX X-Message-ID-Hash: XSF4FG5KIGX2FAJUYCPPATMYK4UU32XX 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 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,