From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8C5C606A32D for ; Thu, 12 Nov 2026 15:48:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=WLr/OuOG; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=gpHWiBHb 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:In-Reply-To: Content-Type:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=sAl1s24kP8ODnZ2bhPBD7erUVW/lulh9YNRN1oKpN7o=; b=WLr/OuOGVM9fXS2nlUpLc7Z/Eb BMAIQtA0wEMZHFJdXqAro4Q+aPhv4S4mOInHU+um8QDcZoBWjLqc++SkczzS9xgFLAmutAFkxUsC4 wcxIZwF/AawV9A2Vh0jP+vrVrNde9GP5XP+PUmByrup+lKtGDDuRdtuWQKx8ffVQni7w0u/Hp+3Bu zs2YtUMZmRsXKU3AEgPbS1R0h9riA2iId79KGFYIyrerZsn0yC9GNp1Ss+4IlxExZPbuvgIhlC75b v9pHF9gYd5/gM/mLFTF/07WKidXET5MK0SC9HDNZ/yMHNSk+Rk1tl04aGcVHNRXLXKurbN4/WSPKD 1aqRySxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xRX1t-0000000AVg5-1fth; Thu, 12 Nov 2026 15:48:01 +0000 Received: from mail-westeuropeazlp170100001.outbound.protection.outlook.com ([2a01:111:f403:c201::1] helo=AM0PR83CU005.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xRX1q-0000000AVfd-2qjX for linux-arm-kernel@lists.infradead.org; Thu, 12 Nov 2026 15:47:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=v6MeYUhy9b8Wr/kDB19czlazqF2Zx0/m2W4l1qbD2Qe1ckq0YE4Ajjo5MUyHlCkwl1UG0/LN5dmmwqPv/w8yptUUSFVeQ2nme0Ig/pieCCWcFM/Ban95O6gEwCI/AfWYnfZVPkNpd/ZPc5Md2lvuFwXYhSHNZfrbp1e37hunIVIM9HdzVF1ACCXh5ycAPzRfod+yE8O8R9txgAxjMa0T1xnHoMMpRI5cYW8OAFsZy+LuYMhljnm2/4G0dL4YrK//P36Ks6Q47IJCVIe5xYztd6to081fB+n8VODMeFTD69CpUNxZnShjr02v00CsUqZoi4IhABzl7yW3uJj3XnjW6w== 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=sAl1s24kP8ODnZ2bhPBD7erUVW/lulh9YNRN1oKpN7o=; b=pNy6DRJ0mkRh2C6DgG6Agjqr5idhyE0oIeXVJ+F6UGflc1a65Eh8BsjPDObTD7n2wL5hltrlfzfvNVYUyANFqKASG/no/0co8WD8SBEzYbZb7yNYA2FX4E8w7L2TCYJc3mGdL97DWFVT+qxhEZJrbH8QDhHB6GOdMZiUsdA+TK5YQoTxfGaJVuskzZLv13Vad5sxsll3EL7+fqr2NSOLKADdoRYpVYgimkSbirBjVGrZuA2fz8nQLL68lpK48jlEgeMrZIpPbREFCd2h/FzAuRGWI8xS9ErGxjN5uCLDcDvLR8lZZLaidnq5SsBKalbWdYweaF02C+V+mkVtZl+ASQ== 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=sAl1s24kP8ODnZ2bhPBD7erUVW/lulh9YNRN1oKpN7o=; b=gpHWiBHb4tCIHjNjwrzel9cjX5MRys8pRc6dBdSul8FPGGLYIdhs1H5LsF5RlcF2LAYcxdFIT0NqZerH+Dqm6EakSgLZFVCJ1/PWsWg4jzcPozkDy/XosYEYQ81moRIii8JAI+Rjs9jzIIIAhY0iMMaz3MgQo3xiUROIW/yjHs0d40plbX4pqjn2uuXkkva7wjgtD3D+1r0XR670K3UlkYwFBks6eSiSHt+TUGWspAlP3rVodLGOduzGD2hP2bLaVbKuNlOwNk5t8Pb1dSkz3k+FbXc7GeDYGMk+oyfg6mqbU0dAuOnk8E/bZs0LNzF8MPVKEu1fhWPlT+YUoBp4GA== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from MI3PR04MB12438.eurprd04.prod.outlook.com (2603:10a6:290:76::14) by WA4PR04MB786416.eurprd04.prod.outlook.com (2603:10a6:1d0:2b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.615.8; Thu, 12 Nov 2026 15:47:51 +0000 Received: from MI3PR04MB12438.eurprd04.prod.outlook.com ([fe80::c715:c32:8bb1:b70b]) by MI3PR04MB12438.eurprd04.prod.outlook.com ([fe80::c715:c32:8bb1:b70b%4]) with mapi id 15.21.0615.009; Thu, 12 Nov 2026 15:47:51 +0000 Date: Thu, 12 Nov 2026 09:47:40 -0600 From: Frank Li To: "Peng Fan (OSS)" Cc: Frank Li , Vinod Koul , "Joerg Roedel (AMD)" , Will Deacon , Robin Murphy , Laxman Dewangan , Jon Hunter , Thierry Reding , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Frank Li , Larisa IIeana Grigore , imx@lists.linux.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-tegra@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Peng Fan Subject: Re: [PATCH v6 2/9] dmaengine: add a bus for DMA channel devices Message-ID: References: <20261112-edma-iommu-v3-v6-0-b038edb8ce6f@nxp.com> <20261112-edma-iommu-v3-v6-2-b038edb8ce6f@nxp.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261112-edma-iommu-v3-v6-2-b038edb8ce6f@nxp.com> X-ClientProxiedBy: DS1PR07CA0024.namprd07.prod.outlook.com (2603:10b6:8:44d::6) To MI3PR04MB12438.eurprd04.prod.outlook.com (2603:10a6:290:76::14) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MI3PR04MB12438:EE_|WA4PR04MB786416:EE_ X-MS-Office365-Filtering-Correlation-Id: 1805f44f-7a55-4c3e-6b3d-08df40d44eea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|23010399003|366016|19092799006|1800799024|261102130727099003|260925021911599003|260925022911599003|260925021311599003|11063799006|261026121527099003|4143699003|261022105027099003|56012099006|261021121427099003|261026140227099003|261102124527099003|261009223027099003|261021123027099003|261022075727099003|261028144727099003|261102123227099003|22082099003|18002099003|6133799003|10067099003; X-Microsoft-Antispam-Message-Info: b7YEeaurCpJP++hcai4uapI9Ob3rn8QJHpjBHhp5ge/L/ei31cbyqFObbTO8L+TjvIz/+xzW3OT00sWXAQ55SpLYG/8rboag/OC75x4uPDjeYJUxl/OFUW8BRpJlTjN0jsfspW7wmo8nTNx0aDxyIBflri5ZFx7L3EGCbuKkI+1sSPX/54uqwg2RkOFYIgQynK/lR2Z/fMT2XSL8TziyWsjXQTTYIE4rcen7koHtXm6KlGNOFr9iXLwY9GVEARreTK9oFSWdy33hzWTGlnsqFn1LXVL+OxG6fhWiKVGL0YKCdIhVYpezTiJzWVIBOQ73qwp9ma1s8KgdsDr7DbfaDnOY7XPXsz9lA65oxnyU5P1OcLK2hlQ2+yz629RwU4r3eVPtmJESSJTUv3MT/QoeihEtDkYCD3pF7Gzf0s2WnkvLgJxYiDddaF7YSE3oXKZ0Fd7X6BQ3H1Qf7n6ZtxgTCIFPw7n2qfsrzu4Tfb5vYhB7dfcxN7I7FhMjcbb1gOaQHb2F06y3UXtaKw4OLd/a529NWtSGELynD0yEWg5cPDvkaSXzK30Y07IV4xhPctuKR8tr/JMukTRTFH7vDATofrHFwyo6lvBImutWW9tLw5cPs7bv/xPI2unZ0sqo5fNY5UnEECaAUqWujl1THp3+zjf3r4vyX0+Ua30Cx2pwcCA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MI3PR04MB12438.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(23010399003)(366016)(19092799006)(1800799024)(261102130727099003)(260925021911599003)(260925022911599003)(260925021311599003)(11063799006)(261026121527099003)(4143699003)(261022105027099003)(56012099006)(261021121427099003)(261026140227099003)(261102124527099003)(261009223027099003)(261021123027099003)(261022075727099003)(261028144727099003)(261102123227099003)(22082099003)(18002099003)(6133799003)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Hti6NSkNL2kWMvtW6weE+gJtL6NWDQnmmYCATYhVNyFvtyOMzeG8kmYQsDkf?= =?us-ascii?Q?vZMdNUJi0LEvMWf89pfZlCE9m24XNKymnLMLNhtj5seJc+gmq6hcgkia/fTH?= =?us-ascii?Q?cJZAg46U63IrboUwMj1QiQtDIC1wc/X0byf+l4YofnFvLKr6qEoO+8YKGI+P?= =?us-ascii?Q?vIfRrwM9ph2QOWx2yBZ0HuBi2hS3ReZ6R/qaga+3FcJWwS8gTJB+XDh2lQlk?= =?us-ascii?Q?wzLpNm9OYcZoFFuPzbQcmZVkkF2Qh4laA7IC4spb7z/tLbfhAQqgvfAyWGLY?= =?us-ascii?Q?/u+5GDLZWHjBHPrKxTL6cU001pNoez7mhf6aps9IA+/nPw2hs6qpYbaitbPg?= =?us-ascii?Q?AVFl3vtRg3Pyo+k0eoKg4zisV+a6BGurj71mDjwhGUg4EKpp4lmW748oBgYO?= =?us-ascii?Q?hfa5j3e50m9so754M53i9C++vUxUPjx2LyIxd7LHBmkDAdL9/Cyb0r7rwhXE?= =?us-ascii?Q?bg6Ni8OQUAP4+gbnoipn2KCfIyCZxR/ndgYbwuoCs56My/MfmGk1xWwhdxHY?= =?us-ascii?Q?dQFC9v2I1A0KrVwG2gBtc4/1uFIVWaNViMMv2aeZQq0Dp8H1WVMJJD0TMg20?= =?us-ascii?Q?Hivb/R5Pnd5waaY44NFX/519O0A4ZpUutRhEbrDPkPA+V/QzY6r3aLkQdzNo?= =?us-ascii?Q?lF6M5kA0L5B3aE2Y292btNKls8zOGD74nDqtF44P6V/2gCvHwwOL24BWiX/J?= =?us-ascii?Q?h+V4Mf5TqHOrDfC/sadrRWqQArvYpu0VSlaLwUj2BpJ6EQJWuNTyCuDqdqs6?= =?us-ascii?Q?0nphqHJj7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ZiH?= =?us-ascii?Q?K8nlW+/MXu2gDRZA2kSmYZyyjMzgij0gIav3nwZZXulx+D48n97LdRsFxj7k?= =?us-ascii?Q?VzoN/Fwl+A84ujlWuuyFhxz/DL+OZVBKhMV+uOVVLNiY9U8VYxoJ?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1805f44f-7a55-4c3e-6b3d-08df40d44eea X-MS-Exchange-CrossTenant-AuthSource: MI3PR04MB12438.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2026 15:47:51.2446 (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: BjrJAdPx5qlm8x5MPwNMeliGsZBAZa5/fzXoYBOcU+aqP1NHGNXm/1aHByeYomIvUuYydaFF64M8sYn4OBF79ctVvmISQkUxYT3QcQBkknmMrR8LUM2XRkZMFnvW3N3z X-MS-Exchange-Transport-CrossTenantHeadersStamped: WA4PR04MB786416 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261112_074758_730623_671370A4 X-CRM114-Status: GOOD ( 30.55 ) X-Spam-Score: 0.0 (/) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Thu, Nov 12, 2026 at 03:53:05PM +0800, Peng Fan (OSS) wrote: > From: Peng Fan > > DMA channel devices are currently created as class devices without a bus. > This works for sysfs, but it prevents per-channel DMA/IOMMU configuration: > of_dma_configure() only probes the IOMMU when dev->bus is set, and the > IOMMU core only installs probe/release notifiers for buses listed in > iommu_buses[]. > > Drivers that need per-channel IOMMU support currently work around this by > assigning dev->bus after device_register(). That leaves the bus subsystem > reference count unbalanced because bus_add_device() already ran with a NULL > bus, and bus_remove_device() will later drop a reference that was never > taken. For example, tegra186-gpc-dma.c assigns chdev->bus after channel > registration. Review noted that this can underflow the platform bus > reference count and lead to a use-after-free when the device is removed. > > Add a dedicated bus for DMA channel devices and register it during > dmaengine initialisation. Use core_initcall so the bus exists before any > IOMMU driver can call iommu_device_register(), which iterates iommu_buses[] > and fails on an unregistered bus. The match callback always reports no > match, so no driver can bind to these devices. A follow-up patch will > register the channel devices on this bus. > > Clean up the unmap pools if dmaengine initialisation fails after they have > been allocated. > > Signed-off-by: Peng Fan > --- Reviewed-by: Frank Li > drivers/dma/dmaengine.c | 28 +++++++++++++++++++++++++--- > include/linux/dmaengine.h | 4 ++++ > 2 files changed, 29 insertions(+), 3 deletions(-) > > diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c > index 34be53487a21..e1022d297674 100644 > --- a/drivers/dma/dmaengine.c > +++ b/drivers/dma/dmaengine.c > @@ -1643,6 +1643,17 @@ void dma_run_dependencies(struct dma_async_tx_descriptor *tx) > } > EXPORT_SYMBOL_GPL(dma_run_dependencies); > > +static int dma_chan_bus_match(struct device *dev, > + const struct device_driver *drv) > +{ > + return 0; > +} > + > +const struct bus_type dmaengine_chan_bus_type = { > + .name = "dmaengine-chan", > + .match = dma_chan_bus_match, > +}; > + > static int __init dma_bus_init(void) > { > int err = dmaengine_init_unmap_pool(); > @@ -1650,10 +1661,21 @@ static int __init dma_bus_init(void) > if (err) > return err; > > + err = bus_register(&dmaengine_chan_bus_type); > + if (err) > + goto err_destroy_unmap_pool; > + > err = class_register(&dma_devclass); > - if (!err) > - dmaengine_debugfs_init(); > + if (err) > + goto err_unregister_bus; > > + dmaengine_debugfs_init(); > + return 0; > + > +err_unregister_bus: > + bus_unregister(&dmaengine_chan_bus_type); > +err_destroy_unmap_pool: > + dmaengine_destroy_unmap_pool(); > return err; > } > -arch_initcall(dma_bus_init); > +core_initcall(dma_bus_init); > diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h > index 805668fbe437..be9308739676 100644 > --- a/include/linux/dmaengine.h > +++ b/include/linux/dmaengine.h > @@ -412,6 +412,10 @@ struct dma_chan_dev { > bool chan_dma_dev; > }; > > +#ifdef CONFIG_DMA_ENGINE > +extern const struct bus_type dmaengine_chan_bus_type; > +#endif > + > /** > * enum dma_slave_buswidth - defines bus width of the DMA slave > * device, source or target buses > > -- > 2.34.1 >