All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Fan <peng.fan@oss.nxp.com>
To: Frank Li <Frank.li@oss.nxp.com>
Cc: Frank Li <Frank.Li@nxp.com>, Vinod Koul <vkoul@kernel.org>,
	"Joerg Roedel (AMD)" <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Laxman Dewangan <ldewangan@nvidia.com>,
	Jon Hunter <jonathanh@nvidia.com>,
	Thierry Reding <thierry.reding@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	Frank Li <Frank.Li@kernel.org>,
	Larisa IIeana Grigore <larisa.grigore@nxp.com>,
	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 <peng.fan@nxp.com>
Subject: Re: [PATCH v5 2/7] dmaengine: add a bus for DMA channel devices
Date: Thu, 12 Nov 2026 08:27:32 +0800	[thread overview]
Message-ID: <avUH9MXGu5AzEkv/@shlinux89> (raw)
In-Reply-To: <avSmdAQhFqKIOMis@SMW015318>

On Wed, Nov 11, 2026 at 11:31:32AM -0600, Frank Li wrote:
>On Wed, Nov 11, 2026 at 09:47:30PM +0800, Peng Fan (OSS) wrote:
>> From: Peng Fan <peng.fan@nxp.com>
>>
>> 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.
>>
>> 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 <peng.fan@nxp.com>
>> ---
>>  drivers/dma/dmaengine.c   | 28 +++++++++++++++++++++++++---
>>  include/linux/dmaengine.h |  4 ++++
>>  2 files changed, 29 insertions(+), 3 deletions(-)
>>
>...
>
>> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
>> index 805668fbe437..14d8f182c7cb 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 dma_chan_bus_type;
>
>New API, need use dmaengine prefix, dmaengine_chan_bus_type

Fix in v6.

>
>Not sure how other dmaengine support it before? Maybe already block for
>long time.

In drivers/dma/tegra186-gpc-dma.c:
1543       if (use_iommu_map) {
1544                chdev->bus = pdev->dev.bus;

I used similar method, but Sashiko spotted issue for v1 [1], we have to
add a new bus to handle it.

"
Does this illegally modify the bus type of an already-registered device?

This is executed after dmaenginem_async_device_register() has already called
device_add(). Since bus_add_device() is never executed, won't device_del()
invoke bus_remove_device() during driver unbinding or removal, causing a fatal
reference count underflow and use-after-free on the global platform_bus_type
subsystem?
"

[1] https://lore.kernel.org/dmaengine/20260916160608.099201F000FF@smtp.kernel.org/

Thanks
Peng

>
>Frank
>
>> +#endif
>> +
>>  /**
>>   * enum dma_slave_buswidth - defines bus width of the DMA slave
>>   * device, source or target buses
>>
>> --
>> 2.34.1
>>
>

  reply	other threads:[~2026-11-12  0:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 13:47 [PATCH v5 0/7] dmaengine: add DMA channel bus and fsl-edma per-channel IOMMU support Peng Fan (OSS)
2026-11-11 13:47 ` [PATCH v5 1/7] dmaengine: fsl-edma: unregister channels before vchan cleanup Peng Fan (OSS)
2026-11-11 17:27   ` Frank Li
2026-11-11 13:47 ` [PATCH v5 2/7] dmaengine: add a bus for DMA channel devices Peng Fan (OSS)
2026-11-11 17:31   ` Frank Li
2026-11-12  0:27     ` Peng Fan [this message]
2026-11-12  2:16       ` Frank Li
2026-11-12  3:13         ` Peng Fan
2026-11-11 13:47 ` [PATCH v5 3/7] iommu: register the DMA channel bus for IOMMU notifications Peng Fan (OSS)
2026-11-11 13:47 ` [PATCH v5 4/7] dmaengine: move channel devices to the DMA channel bus Peng Fan (OSS)
2026-11-11 17:41   ` Frank Li
2026-11-11 13:47 ` [PATCH v5 5/7] dt-bindings: dma: fsl,edma: add per-channel child node support Peng Fan (OSS)
2026-11-11 13:47 ` [PATCH v5 6/7] dmaengine: fsl-edma: support per-channel DT child nodes Peng Fan (OSS)
2026-11-11 17:57   ` Frank Li
2026-11-12  0:41     ` Peng Fan
2026-11-11 13:47 ` [PATCH v5 7/7] arm64: dts: imx95: convert eDMA to per-channel " Peng Fan (OSS)
2026-11-11 17:59   ` Frank Li
2026-11-12  0:57     ` Peng Fan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avUH9MXGu5AzEkv/@shlinux89 \
    --to=peng.fan@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=Frank.li@oss.nxp.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=iommu@lists.linux.dev \
    --cc=jonathanh@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=larisa.grigore@nxp.com \
    --cc=ldewangan@nvidia.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=s.hauer@pengutronix.de \
    --cc=thierry.reding@kernel.org \
    --cc=vkoul@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.