* [PATCH 0/2] iommu: apple-dart: device specific DMA aperture support
@ 2026-08-19 14:52 Janne Grunau
2026-08-19 14:52 ` [PATCH 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture Janne Grunau
2026-08-19 14:52 ` [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
0 siblings, 2 replies; 4+ messages in thread
From: Janne Grunau @ 2026-08-19 14:52 UTC (permalink / raw)
To: Sven Peter, Neal Gompa, Joerg Roedel (AMD), Will Deacon,
Robin Murphy, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, iommu, devicetree, linux-kernel,
Janne Grunau, Hector Martin
Apple DARTs are often connected directly to devices that expect only a
portion of their address space to be used for DMA (for example, because
other ranges are mapped directly to something else).
The USB4 native host controller on M2 Pro/Max/Ultra devices expected to
be sent by Sven after v7.3-rc1 requires this. In the Asahi downstream
kernel the display controller and ISP require a specified DMA aperture
as well.
The downstream kernel uses a "apple,dma-range" property in the iommu
node to specify the aperture. This is not a good way to describe the
aperture as it is not property of the iommu itself but of its connected
device. iommu.txt describes this use case as DMA window in its
"#iommu-cells = <4>" example.
Implement this for DART allowing additionally 5 iommu-cells specifying a
64-bit aperture start and length. 0x100_0000_0000 is a commonly used
aperture start and the aperture often spans 36-bit address space.
This range *can* be outside of the DART's IAS. In that case, it is
assumed that the hardware truncates addresses and the page tables will
only map the lower bits of the address. However, the specified range
cannot straddle an IAS boundary (you cannot cover more than IAS worth
of address space nor wrap).
This corresponds to the vm-base and vm-size properties on the Apple
device tree side of things.
Signed-off-by: Janne Grunau <j@jannau.net>
---
Janne Grunau (2):
dt-bindings: iommu: dart: Support specifying the DMA aperture
iommu: apple-dart: Support specifying the DMA aperture in the DT
.../devicetree/bindings/iommu/apple,dart.yaml | 12 +++--
drivers/iommu/Kconfig | 2 +-
drivers/iommu/apple-dart.c | 62 ++++++++++++++++++----
3 files changed, 61 insertions(+), 15 deletions(-)
---
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
change-id: 20260819-iommu-apple-dart-aperture-c3b9cc79d7e1
Best regards,
--
Janne Grunau <j@jannau.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture
2026-08-19 14:52 [PATCH 0/2] iommu: apple-dart: device specific DMA aperture support Janne Grunau
@ 2026-08-19 14:52 ` Janne Grunau
2026-08-19 14:52 ` [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
1 sibling, 0 replies; 4+ messages in thread
From: Janne Grunau @ 2026-08-19 14:52 UTC (permalink / raw)
To: Sven Peter, Neal Gompa, Joerg Roedel (AMD), Will Deacon,
Robin Murphy, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, iommu, devicetree, linux-kernel,
Janne Grunau
Apple DARTs are often connected directly to devices that expect only a
portion of their address space to be used for DMA (for example, because
other ranges are mapped directly to something else).
Follow the "#iommu-cells = <4>" example from iommu.txt and allow
specifying the DMA aperture via additional cells. Since DART is used on
64-bit Apple silicon systems use two cells to specify the start and
length of the aperture. A common aperture starts at 0x100_0000_0000
and spans a 36-bit address space.
This corresponds to the vm-base and vm-size properties on the Apple
device tree side of things.
As not all devices require this and to keep compatibility with existing
device trees allow 1 and 5 as values for #iommu-cells.
Signed-off-by: Janne Grunau <j@jannau.net>
---
Documentation/devicetree/bindings/iommu/apple,dart.yaml | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml
index 47ec7fa52c3a..6efbe732b4ce 100644
--- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml
+++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml
@@ -44,10 +44,12 @@ properties:
Optional since not all IOMMUs are attached to a clock gate.
'#iommu-cells':
- const: 1
+ enum: [ 1, 5 ]
description:
- Has to be one. The single cell describes the stream id emitted by
- a master to the IOMMU.
+ Has to be one or five. The first cell describes the stream id emitted by
+ a master to the IOMMU. The optional second and third cell describe the
+ aperture start of a master's DMA window and fourth and fifth cell describe
+ the size of DMA window.
power-domains:
maxItems: 1
@@ -66,11 +68,11 @@ examples:
compatible = "apple,t8103-dart";
reg = <0x82f80000 0x4000>;
interrupts = <1 781 4>;
- #iommu-cells = <1>;
+ #iommu-cells = <5>;
};
master1 {
- iommus = <&dart1 0>;
+ iommus = <&dart1 0 0x100 0x0 0x10 0x0>;
};
- |+
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT
2026-08-19 14:52 [PATCH 0/2] iommu: apple-dart: device specific DMA aperture support Janne Grunau
2026-08-19 14:52 ` [PATCH 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture Janne Grunau
@ 2026-08-19 14:52 ` Janne Grunau
2026-08-19 15:06 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Janne Grunau @ 2026-08-19 14:52 UTC (permalink / raw)
To: Sven Peter, Neal Gompa, Joerg Roedel (AMD), Will Deacon,
Robin Murphy, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, iommu, devicetree, linux-kernel,
Janne Grunau, Hector Martin
Apple DARTs are often connected directly to devices that expect only a
portion of their address space to be used for DMA (for example, because
other ranges are mapped directly to something else). Devices can specify
the start and end of the aperture via "iommus" args if the DART device
node specifies "#iommu-cells = <5>. Aperture start and lengt are 64-bit
values since most of the devices use such values. Limit compile testing
to 64-bit architectures to avoid warnings when construction 64-bit
dma_addr_t values.
This range *can* be outside of the DART's IAS. In that case, it is
assumed that the hardware truncates addresses and the page tables will
only map the lower bits of the address. However, the specified range
cannot straddle an IAS boundary (you cannot cover more than IAS worth
of address space nor wrap).
This corresponds to the vm-base and vm-size properties on the Apple
device tree side of things.
Co-developed-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Janne Grunau <j@jannau.net>
---
drivers/iommu/Kconfig | 2 +-
drivers/iommu/apple-dart.c | 62 +++++++++++++++++++++++++++++++++++++++-------
2 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 6e07bd69467a..27954f462582 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -303,7 +303,7 @@ config SPAPR_TCE_IOMMU
config APPLE_DART
tristate "Apple DART IOMMU Support"
- depends on ARCH_APPLE || COMPILE_TEST
+ depends on ARCH_APPLE || (COMPILE_TEST && 64BIT)
depends on !GENERIC_ATOMIC64 # for IOMMU_IO_PGTABLE_DART
select IOMMU_API
select IOMMU_IO_PGTABLE_DART
diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index b160fb464c5f..16ba65a6b8ff 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -21,6 +21,7 @@
#include <linux/io-pgtable.h>
#include <linux/iommu.h>
#include <linux/iopoll.h>
+#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
@@ -267,6 +268,7 @@ struct apple_dart_domain {
struct io_pgtable_ops *pgtbl_ops;
bool finalized;
+ u64 mask;
struct mutex init_lock;
struct apple_dart_atomic_stream_map stream_maps[MAX_DARTS_PER_DEVICE];
@@ -285,6 +287,13 @@ struct apple_dart_master_cfg {
/* Intersection of DART capabilitles */
u32 supports_bypass : 1;
+ /*
+ * DMA aperture start and end to be overridden by "iommus"' phandle
+ * args. By default determined by DART's ias but may be outside of it.
+ */
+ dma_addr_t dma_min;
+ dma_addr_t dma_max;
+
struct apple_dart_stream_map stream_maps[MAX_DARTS_PER_DEVICE];
};
@@ -537,7 +546,7 @@ static phys_addr_t apple_dart_iova_to_phys(struct iommu_domain *domain,
if (!ops)
return 0;
- return ops->iova_to_phys(ops, iova);
+ return ops->iova_to_phys(ops, iova & dart_domain->mask);
}
static int apple_dart_map_pages(struct iommu_domain *domain, unsigned long iova,
@@ -551,8 +560,8 @@ static int apple_dart_map_pages(struct iommu_domain *domain, unsigned long iova,
if (!ops)
return -ENODEV;
- return ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot, gfp,
- mapped);
+ return ops->map_pages(ops, iova & dart_domain->mask, paddr, pgsize,
+ pgcount, prot, gfp, mapped);
}
static size_t apple_dart_unmap_pages(struct iommu_domain *domain,
@@ -563,7 +572,8 @@ static size_t apple_dart_unmap_pages(struct iommu_domain *domain,
struct apple_dart_domain *dart_domain = to_dart_domain(domain);
struct io_pgtable_ops *ops = dart_domain->pgtbl_ops;
- return ops->unmap_pages(ops, iova, pgsize, pgcount, gather);
+ return ops->unmap_pages(ops, iova & dart_domain->mask, pgsize, pgcount,
+ gather);
}
static void
@@ -590,6 +600,7 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
{
struct apple_dart *dart = cfg->stream_maps[0].dart;
struct io_pgtable_cfg pgtbl_cfg;
+ u32 ias = min_t(u32, dart->ias, fls64(cfg->dma_max));
int ret = 0;
int i, j;
@@ -610,7 +621,7 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
pgtbl_cfg = (struct io_pgtable_cfg){
.pgsize_bitmap = dart->pgsize,
- .ias = dart->ias,
+ .ias = ias,
.oas = dart->oas,
.coherent_walk = 1,
.iommu_dev = dart->dev,
@@ -623,10 +634,10 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
goto done;
}
+ dart_domain->mask = DMA_BIT_MASK(pgtbl_cfg.ias);
dart_domain->domain.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
- dart_domain->domain.geometry.aperture_start = 0;
- dart_domain->domain.geometry.aperture_end =
- (dma_addr_t)DMA_BIT_MASK(pgtbl_cfg.ias);
+ dart_domain->domain.geometry.aperture_start = cfg->dma_min;
+ dart_domain->domain.geometry.aperture_end = cfg->dma_max;
dart_domain->domain.geometry.force_aperture = true;
dart_domain->finalized = true;
@@ -803,20 +814,53 @@ static int apple_dart_of_xlate(struct device *dev,
struct platform_device *iommu_pdev = of_find_device_by_node(args->np);
struct apple_dart *dart = platform_get_drvdata(iommu_pdev);
struct apple_dart *cfg_dart;
+ dma_addr_t dma_max = DMA_BIT_MASK(dart->ias);
+ dma_addr_t dma_min = 0;
int i, sid;
put_device(&iommu_pdev->dev);
- if (args->args_count != 1)
+ if (args->args_count != 1 && args->args_count != 5)
return -EINVAL;
+
sid = args->args[0];
+ if (args->args_count == 5) {
+ dma_addr_t length = ((dma_addr_t)args->args[3] << 32) | args->args[4];
+
+ if (!length)
+ return -EINVAL;
+
+ dma_min = ((dma_addr_t)args->args[1] << 32) | args->args[2];
+ dma_max = dma_min + length - 1;
+
+ /*
+ * Ensure that the DMA window does not exceed the dart's ias.
+ */
+ if ((dma_min ^ dma_max) & ~DMA_BIT_MASK(dart->ias)) {
+ dev_err(dev, "Invalid DMA window for ias=%d\n",
+ dart->ias);
+ return -EINVAL;
+ }
+ }
+
if (!cfg) {
cfg = kzalloc_obj(*cfg);
if (!cfg)
return -ENOMEM;
/* Will be ANDed with DART capabilities */
cfg->supports_bypass = true;
+ cfg->dma_min = dma_min;
+ cfg->dma_max = dma_max;
+ } else {
+ if (dma_min >= cfg->dma_max || cfg->dma_min >= dma_max) {
+ dev_err(dev, "non-overlapping DMA windows: %pad..%pad, %pad..%pad\n",
+ &dma_min, &dma_max,
+ &cfg->dma_min, &cfg->dma_max);
+ return -EINVAL;
+ }
+ cfg->dma_min = max(dma_min, cfg->dma_min);
+ cfg->dma_max = min(dma_max, cfg->dma_max);
}
dev_iommu_priv_set(dev, cfg);
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT
2026-08-19 14:52 ` [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
@ 2026-08-19 15:06 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-08-19 15:06 UTC (permalink / raw)
To: Janne Grunau; +Cc: robh, devicetree, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Undefined behavior via invalid bit shift when parsing a 1-byte DMA window starting at address 0.
--
--- Patch [2]: [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT ---
commit ce65194c53df34be71115a91f5d6328ad1a90109
Author: Janne Grunau <j@jannau.net>
iommu: apple-dart: Support specifying the DMA aperture in the DT
This commit adds support for restricting the DMA aperture via the Device Tree
using the iommus args. Devices can specify the start and end of the aperture
if the DART device node specifies #iommu-cells = <5>.
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -590,6 +600,7 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
> {
> struct apple_dart *dart = cfg->stream_maps[0].dart;
> struct io_pgtable_cfg pgtbl_cfg;
> + u32 ias = min_t(u32, dart->ias, fls64(cfg->dma_max));
> int ret = 0;
> int i, j;
[ ... ]
> @@ -623,10 +634,10 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
> goto done;
> }
>
> + dart_domain->mask = DMA_BIT_MASK(pgtbl_cfg.ias);
[Severity: Low]
Does this code trigger undefined behavior if a 1-byte DMA window starting at
address 0 is provided in the device tree?
If a device tree is configured with length = 1 and dma_min = 0,
apple_dart_of_xlate() calculates dma_max as 0:
apple_dart_of_xlate()
dma_max = dma_min + length - 1; /* 0 + 1 - 1 = 0 */
This means cfg->dma_max will be 0 here, making fls64(cfg->dma_max) 0,
and resulting in ias = 0.
If ias is 0, this expands to DMA_BIT_MASK(0), which performs an invalid bit
shift (~0ULL >> 64).
Since size 0 (!length) is explicitly rejected in apple_dart_of_xlate(),
should size 1 also be handled to avoid this edge case?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260819-iommu-apple-dart-aperture-v1-0-252703f381aa@jannau.net?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-19 15:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-19 14:52 [PATCH 0/2] iommu: apple-dart: device specific DMA aperture support Janne Grunau
2026-08-19 14:52 ` [PATCH 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture Janne Grunau
2026-08-19 14:52 ` [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
2026-08-19 15:06 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox