From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 BF166CD4F3D for ; Wed, 20 May 2026 22:01:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To: In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type: Subject:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4ktn4yDDK+X3BcUkupV/7FBh4aTe/41UXRom1OC5H5c=; b=KI0T2slDfeu2ZHXmLVIlOWI3iH QuBbZk+8V/oR/dXTl/DTp2k5FYMxzBRujaP7heX+dthLW8pls5Yb0+Q0klgs+EeIUu2yietsE4XMT ar36DTrafboA83Wx6Iwx2Wcb3LnMyrpTW3h4PeYh0C4hWitngSFw3zCEcWH7DMUdWvGOvEugb15dC 2RfY3wFgTa09cCjR43ehX7/o50eAUvtV/vG4Irldgh0z4+sHtMPBdGPEmO8sgSriIUj62jqZHmUDX mlu0aKce6cJzEFD2x/KSYc8zeMni9C0TKhuVbrdjUtAB/lIQHojNGTIXLhEOZ6LcqYrL0LHrZqYaN JXEJIzeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPoyV-00000005uEW-1zCw; Wed, 20 May 2026 22:01:11 +0000 Received: from mail-francecentralazlp170130007.outbound.protection.outlook.com ([2a01:111:f403:c20a::7] helo=PA4PR04CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPoyO-00000005u5F-0HqJ; Wed, 20 May 2026 22:01:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b4Y1UKL4TF2knxKiyKK4uRNk2PYO7in6ler3XDrdUtEiCdZN+AykeM5K7SrI+QwHhT8QYsD4pRGIY1Hrdx2bnvD3IoiNI5GPv81h30Z1752JDGTKFd21ksErJXyaE2RT+ThCpZo0Kxyj2Ku7OxJEU1qdluSfoyDqsye3rJDmJF6tYBHdiIIboyCTBoW6+lOaRi+4LUxnrV52Jqgp45j1cGuyeDPef5vuPftIlyx2pQW7SxqluM9NfLippT6SBHmRfhZMfVCJ7FFNwC+llM5c+7N9BpGj3vrZhFpquSsdLh9MhEanzzwv+QZuKtY23JppSqyN63ecA3T0SsWosn50ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=4ktn4yDDK+X3BcUkupV/7FBh4aTe/41UXRom1OC5H5c=; b=Li3fdwBfCLlDzTEFREOghnltZhHlkJf2Fadgh+nduQHkp+xeTNYNA/GHNyhB87G7L1vv4cm8dSKrtZaskUjq8NRgq2aTKhmVWxZlJYu+Iaj5mQeLoIFTnm2+Ai76qr5E+5mIBPTepv1C9XC2D5u7AGK/CCTtZtHaY7P2k05aF8wSYKxI/debUTnJJOrApR2m6YNJjRhX/YL0xMtwqy2gPI1YAKQWb7VtnsA0bWST93rWsB9qUA0t7UNvXwSApmvaBQqZoLTlDst4up25GNZJCWd2u1qgLujr/YcklnRazLBrnNrrtCRuUkm7uWryRV7eRZ/PAypAWPrUEfrPbl6REg== 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=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4ktn4yDDK+X3BcUkupV/7FBh4aTe/41UXRom1OC5H5c=; b=V8ZfvM3K4ZjHZ/P+KquRWwuU/0f6p/ZtsbCjtEO8FELVVffxK5wWJuZcvp1r9VXYbeHFu16gvmKOx5ksYkX1D7gPCs3CUrXy09icBn8//UaS7J1jtE7z3cNiHpKOsUUtkb6f0gR91nH121ElsUL9EEnCpq+7XLnh5DdNXJikGBkcyA+06pt9cW5VA22SXdQKFY0tTxgcc3SkfSeHtHwlgmvwRyTrTX3+0CA4LRG7z+xWGZQKE5S6mX5yPuLwR29n6D4iDFXakW6RuD5NHzbwNKTpjQz7XoTeZ9UqZ4QrPDYILqmf6AFOt+ApUrqWuCrtgqW4UbsJbn79fVbirX1aFg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from GV2PR04MB11799.eurprd04.prod.outlook.com (2603:10a6:150:2cf::9) by PA4PR04MB8029.eurprd04.prod.outlook.com (2603:10a6:102:c9::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.14; Wed, 20 May 2026 22:00:58 +0000 Received: from GV2PR04MB11799.eurprd04.prod.outlook.com ([fe80::2146:83a2:5329:b7c]) by GV2PR04MB11799.eurprd04.prod.outlook.com ([fe80::2146:83a2:5329:b7c%6]) with mapi id 15.21.0048.013; Wed, 20 May 2026 22:00:58 +0000 From: Frank.Li@oss.nxp.com Date: Wed, 20 May 2026 18:00:43 -0400 Subject: [PATCH v6 2/9] dmaengine: Add safe API to combine configuration and preparation Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260520-dma_prep_config-v6-2-06e49b7acb38@nxp.com> References: <20260520-dma_prep_config-v6-0-06e49b7acb38@nxp.com> In-Reply-To: <20260520-dma_prep_config-v6-0-06e49b7acb38@nxp.com> To: Vinod Koul , Manivannan Sadhasivam , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Herbert Xu , "David S. Miller" , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Koichiro Den , Niklas Cassel Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org, mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, Frank Li X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779314446; l=6305; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=uyPouf7iyzCcucDvUuV8ZtysqANoCh3TR/YpsX4alSI=; b=ngtZq9I90mmbIdnupiXwC7GVOw4pdjdeubZzsnNM2COERXHnq7YmJm0nQKoxo5+le1tmklGip ZINGEdDTxvpAeNFuv2SDbzo8sB/zi3Y8fafSB2evT8CmBR/vubtOFKt X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SA9PR13CA0114.namprd13.prod.outlook.com (2603:10b6:806:24::29) To GV2PR04MB11799.eurprd04.prod.outlook.com (2603:10a6:150:2cf::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV2PR04MB11799:EE_|PA4PR04MB8029:EE_ X-MS-Office365-Filtering-Correlation-Id: cd160737-5b14-4139-cb59-08deb6bb4616 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|7416014|19092799006|921020|56012099003|18002099003|22082099003|11063799006|6133799003; X-Microsoft-Antispam-Message-Info: HlI0IevGY9AvhaRsJMO+ofVyC5oZOXNHqhaB23UZUpXUi7gzWNr/BKKjhikHxsTzUIgz+zmtPmcpggNbEXwxf3uNgJ442fc3NmercTlL7LqLQdRss0DGtYvnLkv7I7U2ldV2246n5uFChnq//ZruRVuQvaE6YJMhJMbnzfdzb2/yOS29czvGTiVF2j3AcGUkEUyfiU7we6W5Xksv5tgxdrXw/YcqKN1K1INTsvSz0lCOa76iy8f11dixRp5J05UJQPVL9+bMWggk61bogowR0Dc9S9cmeGhxfsF2uSjA1dC/M+zda7wB5jwoK9t7q4Yj5Bt+IhXhsMDlfh29oqool+e8VF07f4TkguuSkQ59eQ5SSGtBvBP56+v6p+dbZ9mrfiZsUeDpIsW674dDEiXDOtoG2SVmF3Rg4HGXFSDx3NNVu2PbcdC0MAQBq68fHoYMApbcwGIcTvwL6+K9ZFRANtIu9dHpN4STI0xIiE79Y7nDtEa8FUvFSwHy+HCS+58jQAz87HkqqbEJpm5K6Xso2825mgjsfPPE9XcjUC3kKBLMk/xww17/u9qazttJRwRy6i2I3GHIZPkjfkFOFcPTVsP4QtT9dlau5Y+cl1CiC0RDC4S6B0vDZoDeJcrg9RODElC8mqdPgJ1Tdj26eB69bH/DDiTmcfRv2JTc+udEA45tIQ/5j2sPtRFt4NoTonWUcup5QQsSEPZt3+q41HTpf1TC8kN5JBeFX0sukXG5xYg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:GV2PR04MB11799.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(7416014)(19092799006)(921020)(56012099003)(18002099003)(22082099003)(11063799006)(6133799003);DIR:OUT;SFP:1101; X-MS-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QThCVnBwRmtidlp2QWxm?= =?utf-8?B?Q2NBTGE5UzVaMjhZLzUzbWFvVWNZdnRTQlhmTVdkT1NjRHR0cllNVDVpdHZn?= =?utf-8?B?b0RuQllCZWo5UklCdDdrT3dXOUJnVGpXUVpxNm5mMzFLdHFVb2FjWmQxOExh?= =?utf-8?B?Y0oydjFLZlZGOEE2aVR6MVRnQ0lhZ1J1Zjkvc3NQZis3czNoWUFNc2x0VUFG?= =?utf-8?B?VUczeERRWVV1UG5wQmdqQ0daSGJyMVBnMFdVeXZmcEtjZjgyY2wySXg3UEtI?= =?utf-8?B?UXlzZWRzTElkeTJEVytia09MWXIrd0ZSUGRkMzdEdkJDczhSd0JlMGIybmJz?= =?utf-8?B?VU93RnEwaU9ISzk2NVpWMXdSWkJxZ1VrNjRJbDdURnlBUUdUVFpWd2c5T1RI?= =?utf-8?B?OGwzK2VnVzNaby9QNHJ3ak9xd2dSSGZqOWRQNktpa21Mb0MzcTE5VDVxVEY4?= =?utf-8?B?RmRWVzRtYzBxWHZFSVBWOFhlMjVXRUxvNUZ6ZXBlOFo4bGh0aHdySXBNWkts?= =?utf-8?B?T1pHaEljZ1cyQWE3N0ZZcjJ4SVZ6cERwaE1FK3doM0tDSFJMNmpzVklXWG9t?= =?utf-8?B?TUVLS2JvNzU2cFVhNmFOaHcvR1BERnVvaGs3bVM2NzBpOExML2p1clVMRmhT?= =?utf-8?Q?7P961oubdMvUUtVIVQYA/JJWEOW55b3JDpqsY?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd160737-5b14-4139-cb59-08deb6bb4616 X-MS-Exchange-CrossTenant-AuthSource: GV2PR04MB11799.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2026 22:00:58.6102 (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: f88UsbjlGb8+214/FkyPtah/A0WMOH5uQvl2dTHnFpZ4vdAQxcdYDs4OdW+7pppqCNn2n8E+TBoYq+6XrmKldTKdaTqu2RgR6IDj4MV+o5ivWnleM++9Gn8WPQEatkrU X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB8029 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260520_150104_128545_2FF8130D X-CRM114-Status: GOOD ( 20.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Frank Li Introduce dmaengine_prep_config_single_safe() and dmaengine_prep_config_sg_safe() to provide a reentrant-safe way to combine slave configuration and transfer preparation. Drivers may implement the new device_prep_config_sg() callback to perform both steps atomically. If the callback is not provided, the helpers fall back to calling dmaengine_slave_config() followed by dmaengine_prep_slave_sg() under per-channel spinlock protection. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change in v6 - replace mutex with spinlock in commit message - use spinlock_saveirq according to AI review results "The documentation in struct dma_chan notes that *_prep() may be called from a completion callback. Since completion callbacks often execute in softirq or hardirq contexts, if a thread calls this function from process context, local interrupts remain enabled. If a DMA interrupt fires on the same CPU while the lock is held, the completion callback could attempt to call this function again to queue the next transfer, leading it to wait on the already-held chan->lock. Does this fallback path need to use spin_lock_irqsave() and spin_unlock_irqrestore() to safely disable interrupts? " chagne in v5 - remove reduntant lock commments. - use kernel doc to descritp API chagne in v4 - use spinlock() to protect config() and prep() change in v3 - new patch --- drivers/dma/dmaengine.c | 2 ++ include/linux/dmaengine.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 405bd2fbb4a3b..ba29e60160c1a 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -1099,6 +1099,8 @@ static int __dma_async_device_channel_register(struct dma_device *device, chan->dev->device.parent = device->dev; chan->dev->chan = chan; chan->dev->dev_id = device->dev_id; + spin_lock_init(&chan->lock); + if (!name) dev_set_name(&chan->dev->device, "dma%dchan%d", device->dev_id, chan->chan_id); else diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index defa377d2ef54..6fe46c0c94527 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -322,6 +322,8 @@ struct dma_router { * @slave: ptr to the device using this channel * @cookie: last cookie value returned to client * @completed_cookie: last completed cookie for this channel + * @lock: protect between config and prepare transfer when driver have not + * implemented callback device_prep_config_sg(). * @chan_id: channel ID for sysfs * @dev: class device for sysfs * @name: backlink name for sysfs @@ -341,6 +343,12 @@ struct dma_chan { dma_cookie_t cookie; dma_cookie_t completed_cookie; + /* + * protect between config and prepare transfer because *_prep() may be + * called from complete callback, which is in GFP_NOSLEEP context. + */ + spinlock_t lock; + /* sysfs */ int chan_id; struct dma_chan_dev *dev; @@ -1068,6 +1076,84 @@ dmaengine_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, return dmaengine_prep_config_sg(chan, sgl, sg_len, dir, flags, NULL); } +/** + * dmaengine_prep_config_sg_safe - prepare a scatter-gather DMA transfer + * with atomic slave configuration update + * @chan: DMA channel + * @sgl: scatterlist for the transfer + * @sg_len: number of entries in @sgl + * @dir: DMA transfer direction + * @flags: transfer preparation flags + * @config: DMA slave configuration for this transfer + * + * Prepare a DMA scatter-gather transfer together with a corresponding slave + * configuration update in a re-entrant and race-safe manner. + * + * DMA engine drivers may implement the optional + * device_prep_config_sg() callback to perform both the slave configuration + * and descriptor preparation atomically. In this case, the operation is + * fully handled by the DMA engine driver. + * + * If the DMA engine driver does not implement device_prep_config_sg(), falls + * back to calling dmaengine_slave_config() followed by dmaengine_prep_slave_sg(). + * The fallback path is protected by a per-channel spinlock to ensure that + * concurrent callers cannot interleave configuration and descriptor preparation + * on the same DMA channel. + * + * Return: Pointer to a prepared DMA async transaction descriptor on success, + * or %NULL if the transfer could not be prepared. + */ +static inline struct dma_async_tx_descriptor * +dmaengine_prep_config_sg_safe(struct dma_chan *chan, struct scatterlist *sgl, + unsigned int sg_len, + enum dma_transfer_direction dir, + unsigned long flags, + struct dma_slave_config *config) +{ + struct dma_async_tx_descriptor *tx; + unsigned long spinlock_flags; + + if (!chan || !chan->device) + return NULL; + + if (!chan->device->device_prep_config_sg) + spin_lock_irqsave(&chan->lock, spinlock_flags); + + tx = dmaengine_prep_config_sg(chan, sgl, sg_len, dir, flags, config); + + if (!chan->device->device_prep_config_sg) + spin_unlock_irqrestore(&chan->lock, spinlock_flags); + + return tx; +} + +/** + * dmaengine_prep_config_single_safe - prepare a single-buffer DMA transfer + * with atomic slave configuration update + * @chan: DMA channel + * @buf: DMA buffer address + * @len: length of the transfer in bytes + * @dir: DMA transfer direction + * @flags: transfer preparation flags + * @config: DMA slave configuration for this transfer + * + * Detail see dmaengine_prep_config_sg_safe(). + */ +static inline struct dma_async_tx_descriptor * +dmaengine_prep_config_single_safe(struct dma_chan *chan, dma_addr_t buf, + size_t len, enum dma_transfer_direction dir, + unsigned long flags, + struct dma_slave_config *config) +{ + struct scatterlist sg; + + sg_init_table(&sg, 1); + sg_dma_address(&sg) = buf; + sg_dma_len(&sg) = len; + + return dmaengine_prep_config_sg_safe(chan, &sg, 1, dir, flags, config); +} + #ifdef CONFIG_RAPIDIO_DMA_ENGINE struct rio_dma_ext; static inline struct dma_async_tx_descriptor *dmaengine_prep_rio_sg( -- 2.43.0