Devicetree
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] rockchip: keep the bootloader framebuffer mapped behind the VOP IOMMU
@ 2026-12-04  6:24 Francesco Saverio Pavone
  2026-12-04  6:24 ` [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree Francesco Saverio Pavone
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Francesco Saverio Pavone @ 2026-12-04  6:24 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Robin Murphy, Sandy Huang,
	Heiko Stuebner, Andy Yan, Chaoyi Chen
  Cc: Damon Ding, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jiaxing Hu, iommu, dri-devel, devicetree,
	linux-rockchip, linux-arm-kernel

Hi,

This is the series Chaoyi asked for in [1]. On a ROCK 5B+ (RK3588)
started from EDK2 the firmware leaves one VOP2 window scanning out of
its framebuffer, and the VOP MMU faults on it: first when the default
DMA domain is installed with an empty page table and, with the fbdev
client on, again when the VOP is moved to the private domain of the
DRM driver.

Patch 1 makes rockchip-iommu report the reserved regions from the
devicetree, so the core maps them 1:1 in the default domain. Patch 2
lets a VOP2 node carry memory-region. Patch 3 gives the same regions a
1:1 mapping in the DRM domain and keeps them out of the drm_mm.

Tested on v7.4-rc5 on the ROCK 5B+, with this node added to the board
DTS by hand (not part of the series):

  reserved-memory {
    fw_fb: framebuffer@e6810000 {
      reg = <0x0 0xe6810000 0x0 0x00e10000>;
      iommu-addresses = <&vop 0x0 0xe6810000 0x0 0x00e10000>;
    };
  };

  &vop {
    memory-region = <&fw_fb>;
  };

Boots with rk_iommu errors in the log:

                              fbdev client off   fbdev client on
  v7.4-rc5                    3 of 3             2 of 2
  series, no node             2 of 2             2 of 2
  series, node                0 of 4             0 of 4

The two "series" rows are the same kernel image with a different DTB.
With the client off the errors are the two "Enable stall request timed
out" lines at 0.2 s. With the client on the same two lines come back
when the compositor starts, in all four boots, and there are one to
three page faults on the firmware buffer (0xe6810000 and up), at 0.4 s
and in two of the four boots again at that point. With the node, the
VOP group lists the region 0xe6810000-0xe761ffff as direct in
reserved_regions and the log has no rk_iommu line at all.

I watched one boot with the series, the node and the client on: the
TV shows the firmware logo, then the kernel console, then the desktop,
and never loses the signal.

Robin, on the points you raised in [2]:

 - rk_iommu_probe() does not touch the hardware. For the default
   domain the page table is first loaded from the runtime resume, when
   the VOP resumes through the device link, and by then the core has
   already created the direct mappings. rk_iommu_enable() still does a
   force reset first, with the window running; I have not changed
   that.
 - The switch to the DRM domain is different: it happens with the VOP
   active, so rk_iommu_attach_device() turns paging off, resets and
   loads the new table. Patch 3 has the region mapped in that table
   before the attach. The logs above show no fault across it, but the
   reset with a live window is still there.
 - The IOMMU starts runtime suspended and I found nothing that resumes
   it before the consumer link exists. On suspend the driver turns
   paging off, which for a 1:1 region addresses the same memory, and
   on resume it loads the same table again.

What this does not cover, and where I would like your opinion:

 - Patch 1 uses of_iommu_get_resv_regions() directly, not
   iommu_dma_get_resv_regions(), so that patch 3 can read the regions
   on 32-bit ARM, where IOMMU_DMA is not there. On 32-bit ARM the core
   maps nothing (the default domain is the identity domain) and the
   ARM DMA mapping installed for the VOP is empty, so until the DRM
   attach nothing is mapped there. Compile-tested only on 32-bit ARM.
 - The region is reported as direct, so the core keeps it as a
   required direct mapping for the life of the device. Is that
   acceptable for a buffer that is only needed until the first frame?
 - The IOVA space is 32 bits. A buffer above 4 GiB cannot be mapped
   1:1; patch 3 skips it with a warning, patch 1 does not check.
 - Patch 3 calls iommu_get_resv_regions() from a DRM driver, which no
   other driver does. Should this be a helper in the iommu core?
 - The mapping and the hole in the IOVA space stay until the domain is
   freed, because the driver does not know when the old buffer is read
   for the last time.
 - The power domain of the VOP is switched off as unused when the DRM
   driver binds late, as a module. The picture is lost then, whatever
   is mapped. I saw that on v7.4-rc4; not retested with the series.
 - Nothing in mainline writes the node. The address depends on the
   mode the firmware picked, so the firmware has to add it, the way
   the exynos7870 boards describe theirs for the decon.
 - VOP1 resets itself and turns its windows off at bind, so I left
   rockchip-vop.yaml alone. Not tested on VOP1 hardware.

dt_binding_check is clean for rockchip-vop2.yaml (dtschema 2026.9),
and so is CHECK_DTBS for the board DTB with the node added.

The patches were written with Claude (Anthropic). I ran the boots
above on my board and checked the logs.

[1] https://lore.kernel.org/all/2148a630-6aec-40ee-9c82-3541c65e87bc@rock-chips.com/
[2] https://lore.kernel.org/all/2ea06ad1-779d-47fd-aa7a-20aba129d14e@arm.com/

Francesco Saverio Pavone (3):
  iommu/rockchip: Report the reserved regions from the devicetree
  dt-bindings: display: vop2: Allow memory-region
  drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain

 .../display/rockchip/rockchip-vop2.yaml       |   6 +
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c   | 121 ++++++++++++++++++
 drivers/gpu/drm/rockchip/rockchip_drm_drv.h   |   2 +
 drivers/iommu/rockchip-iommu.c                |   2 +
 4 files changed, 131 insertions(+)


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.54.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree
  2026-12-04  6:24 [RFC PATCH 0/3] rockchip: keep the bootloader framebuffer mapped behind the VOP IOMMU Francesco Saverio Pavone
@ 2026-12-04  6:24 ` Francesco Saverio Pavone
  2026-12-04  6:32   ` Chaoyi Chen
  2026-12-04  6:44   ` sashiko-bot
  2026-12-04  6:24 ` [RFC PATCH 2/3] dt-bindings: display: vop2: Allow memory-region Francesco Saverio Pavone
  2026-12-04  6:24 ` [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain Francesco Saverio Pavone
  2 siblings, 2 replies; 8+ messages in thread
From: Francesco Saverio Pavone @ 2026-12-04  6:24 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Robin Murphy, Sandy Huang,
	Heiko Stuebner, Andy Yan, Chaoyi Chen
  Cc: Damon Ding, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jiaxing Hu, iommu, dri-devel, devicetree,
	linux-rockchip, linux-arm-kernel

The driver has no .get_resv_regions callback, so a reserved-memory node
that lists a device in "iommu-addresses" is ignored: the region is
neither kept out of the IOVA allocator nor mapped 1:1 in the default
domain.

This matters for the VOP when the bootloader leaves a window scanning
out of its own framebuffer. On RK3588 the default DMA domain is
installed on the VOP MMU as soon as the MMU is resumed, with an empty
page table, and the running scanout faults. On a ROCK 5B+ started from
EDK2 this shows as

  rk_iommu fdd97e00.iommu: Enable stall request timed out, status: 0x00001d
  rk_iommu fdd97e00.iommu: Enable stall request timed out, status: 0x00030b

Use of_iommu_get_resv_regions() as the callback, so that the core maps
such a region before the MMU is enabled: the probe does not touch the
hardware, and the page table is first loaded from the runtime resume.

The driver is devicetree only, and calling the OF helper directly,
instead of going through iommu_dma_get_resv_regions(), lets a consumer
read the regions on 32-bit ARM too, where IOMMU_DMA is not available.
The default domain is not a DMA domain there, so the core maps nothing
and this patch alone changes nothing on 32-bit ARM.

The IOVA space of the driver is 32 bits wide, so a region above 4 GiB
cannot be mapped 1:1. Nothing checks for that here.
Signed-off-by: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
---
 drivers/iommu/rockchip-iommu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 1fa3110b142ad..757532a86975c 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -20,6 +20,7 @@
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/of.h>
+#include <linux/of_iommu.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
@@ -1204,6 +1205,7 @@ static const struct iommu_ops rk_iommu_ops = {
 	.probe_device = rk_iommu_probe_device,
 	.release_device = rk_iommu_release_device,
 	.device_group = generic_single_device_group,
+	.get_resv_regions = of_iommu_get_resv_regions,
 	.of_xlate = rk_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= rk_iommu_attach_device,
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 2/3] dt-bindings: display: vop2: Allow memory-region
  2026-12-04  6:24 [RFC PATCH 0/3] rockchip: keep the bootloader framebuffer mapped behind the VOP IOMMU Francesco Saverio Pavone
  2026-12-04  6:24 ` [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree Francesco Saverio Pavone
@ 2026-12-04  6:24 ` Francesco Saverio Pavone
  2026-12-04  6:24 ` [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain Francesco Saverio Pavone
  2 siblings, 0 replies; 8+ messages in thread
From: Francesco Saverio Pavone @ 2026-12-04  6:24 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Robin Murphy, Sandy Huang,
	Heiko Stuebner, Andy Yan, Chaoyi Chen
  Cc: Damon Ding, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jiaxing Hu, iommu, dri-devel, devicetree,
	linux-rockchip, linux-arm-kernel

A bootloader that shows a splash screen can leave a VOP2 window
scanning out of its own framebuffer when it starts the kernel.
Describing that buffer as a reserved-memory node with
"iommu-addresses", and pointing the VOP2 at it with "memory-region", is
the generic way to keep it mapped 1:1 behind the IOMMU until the kernel
has taken the display over.

The binding sets additionalProperties to false, so allow the property.
Signed-off-by: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
---
 .../devicetree/bindings/display/rockchip/rockchip-vop2.yaml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/display/rockchip/rockchip-vop2.yaml b/Documentation/devicetree/bindings/display/rockchip/rockchip-vop2.yaml
index 93da1fb9adc47..be75c5ee7042e 100644
--- a/Documentation/devicetree/bindings/display/rockchip/rockchip-vop2.yaml
+++ b/Documentation/devicetree/bindings/display/rockchip/rockchip-vop2.yaml
@@ -120,6 +120,12 @@ properties:
   iommus:
     maxItems: 1
 
+  memory-region:
+    maxItems: 1
+    description:
+      Phandle to a node describing a reserved framebuffer memory region.
+      For example, the splash memory region set up by the bootloader.
+
   power-domains:
     maxItems: 1
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain
  2026-12-04  6:24 [RFC PATCH 0/3] rockchip: keep the bootloader framebuffer mapped behind the VOP IOMMU Francesco Saverio Pavone
  2026-12-04  6:24 ` [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree Francesco Saverio Pavone
  2026-12-04  6:24 ` [RFC PATCH 2/3] dt-bindings: display: vop2: Allow memory-region Francesco Saverio Pavone
@ 2026-12-04  6:24 ` Francesco Saverio Pavone
  2026-12-04  6:48   ` sashiko-bot
  2026-12-04  7:14   ` Chaoyi Chen
  2 siblings, 2 replies; 8+ messages in thread
From: Francesco Saverio Pavone @ 2026-12-04  6:24 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Robin Murphy, Sandy Huang,
	Heiko Stuebner, Andy Yan, Chaoyi Chen
  Cc: Damon Ding, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jiaxing Hu, iommu, dri-devel, devicetree,
	linux-rockchip, linux-arm-kernel

The driver allocates its own IOMMU domain and attaches a VOP to it on
the first CRTC enable. If the bootloader left a window scanning out of
its own framebuffer, that buffer has no mapping in the new domain, and
the VOP reads it until the first new frame is latched. On a ROCK 5B+
started from EDK2, with the buffer mapped in the default domain only,
this shows at the first modeset as

  rk_iommu fdd97e00.iommu: Page fault at 0x00000000e6810400 of type read

and the two "Enable stall request timed out" lines come back later,
when the compositor takes over.

When the devicetree describes the buffer as a reserved region of the
VOP ("memory-region" with "iommu-addresses"), the iommu core maps it
1:1 in the default domain. Collect the direct-mapped regions of every
VOP when it is bound, then give them the same mapping in the DRM domain
before any device is attached, and reserve the range in the drm_mm so
that no GEM object is given those addresses.

A region that does not fit in the aperture of the domain is skipped
with a warning. The mappings are kept until the domain is freed: the
driver does not know when the last read of the old buffer happens.
Signed-off-by: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
---
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 121 ++++++++++++++++++++
 drivers/gpu/drm/rockchip/rockchip_drm_drv.h |   2 +
 2 files changed, 123 insertions(+)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
index ba417f7e9e474..aed22787c05e2 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
@@ -88,6 +88,121 @@ void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,
 	iommu_detach_device(private->domain, dev);
 }
 
+struct rockchip_drm_resv {
+	struct list_head list;
+	struct drm_mm_node node;
+	int prot;
+};
+
+/*
+ * Remember the direct-mapped reserved regions of a VOP. The iommu core maps
+ * them 1:1 in the default domain of the device; rockchip_drm_init_iommu()
+ * gives them the same mapping in the DRM domain.
+ */
+static void rockchip_drm_collect_resv_regions(struct drm_device *drm_dev,
+					      struct device *dev)
+{
+	struct rockchip_drm_private *private = drm_dev->dev_private;
+	struct iommu_resv_region *region;
+	struct rockchip_drm_resv *resv;
+	LIST_HEAD(regions);
+
+	iommu_get_resv_regions(dev, &regions);
+
+	list_for_each_entry(region, &regions, list) {
+		if (region->type != IOMMU_RESV_DIRECT &&
+		    region->type != IOMMU_RESV_DIRECT_RELAXABLE)
+			continue;
+
+		resv = devm_kzalloc_obj(drm_dev->dev, *resv);
+		if (!resv)
+			break;
+
+		resv->node.start = region->start;
+		resv->node.size = region->length;
+		resv->prot = region->prot;
+		list_add_tail(&resv->list, &private->resv_list);
+	}
+
+	iommu_put_resv_regions(dev, &regions);
+}
+
+static void rockchip_drm_unmap_resv_regions(struct rockchip_drm_private *private)
+{
+	struct rockchip_drm_resv *resv;
+
+	list_for_each_entry(resv, &private->resv_list, list) {
+		if (!drm_mm_node_allocated(&resv->node))
+			continue;
+
+		iommu_unmap(private->domain, resv->node.start, resv->node.size);
+		drm_mm_remove_node(&resv->node);
+	}
+}
+
+/*
+ * Map the reserved regions of the VOPs 1:1 in the DRM domain and keep their
+ * addresses away from the GEM objects, so that a scanout left running by the
+ * bootloader keeps working when a VOP is moved over to this domain. The VOP
+ * reads the old buffer until the first new frame is latched, so the mappings
+ * stay for as long as the domain does.
+ */
+static void rockchip_drm_map_resv_regions(struct drm_device *drm_dev)
+{
+	struct rockchip_drm_private *private = drm_dev->dev_private;
+	struct iommu_domain_geometry *geometry = &private->domain->geometry;
+	unsigned long pgsz = 1UL << __ffs(private->domain->pgsize_bitmap);
+	struct rockchip_drm_resv *resv, *other;
+	u64 start, end;
+	int ret;
+
+	list_for_each_entry(resv, &private->resv_list, list) {
+		/* Same rounding as the direct mappings of the iommu core. */
+		start = ALIGN(resv->node.start, pgsz);
+		end = ALIGN(resv->node.start + resv->node.size, pgsz);
+		if (start >= end)
+			continue;
+
+		/* Two VOPs may point at the same region. */
+		ret = 0;
+		list_for_each_entry(other, &private->resv_list, list) {
+			if (other == resv)
+				break;
+			if (drm_mm_node_allocated(&other->node) &&
+			    other->node.start == start &&
+			    other->node.size == end - start)
+				ret = -EEXIST;
+		}
+		if (ret)
+			continue;
+
+		if (start < geometry->aperture_start ||
+		    end - 1 > geometry->aperture_end) {
+			drm_warn(drm_dev,
+				 "reserved region [%#llx-%#llx] is outside the IOMMU aperture\n",
+				 start, end - 1);
+			continue;
+		}
+
+		resv->node.start = start;
+		resv->node.size = end - start;
+		ret = drm_mm_reserve_node(&private->mm, &resv->node);
+		if (ret) {
+			drm_warn(drm_dev, "cannot reserve [%#llx-%#llx]: %d\n",
+				 start, end - 1, ret);
+			continue;
+		}
+
+		ret = iommu_map(private->domain, start, start, end - start,
+				resv->prot, GFP_KERNEL);
+		if (ret) {
+			drm_warn(drm_dev, "cannot map [%#llx-%#llx]: %d\n",
+				 start, end - 1, ret);
+			drm_mm_remove_node(&resv->node);
+		}
+	}
+}
+
 void rockchip_drm_dma_init_device(struct drm_device *drm_dev,
 				  struct device *dev)
 {
@@ -100,6 +215,9 @@ void rockchip_drm_dma_init_device(struct drm_device *drm_dev,
 
 	if (!IS_ERR(private->iommu_dev))
 		drm_dev_set_dma_dev(drm_dev, private->iommu_dev);
+
+	if (device_iommu_mapped(dev))
+		rockchip_drm_collect_resv_regions(drm_dev, dev);
 }
 
 static int rockchip_drm_init_iommu(struct drm_device *drm_dev)
@@ -127,6 +245,7 @@ static int rockchip_drm_init_iommu(struct drm_device *drm_dev)
 		  start, end);
 	drm_mm_init(&private->mm, start, end - start + 1);
 	mutex_init(&private->mm_lock);
+	rockchip_drm_map_resv_regions(drm_dev);
 
 	return 0;
 }
@@ -138,6 +257,7 @@ static void rockchip_iommu_cleanup(struct drm_device *drm_dev)
 	if (!private->domain)
 		return;
 
+	rockchip_drm_unmap_resv_regions(private);
 	drm_mm_takedown(&private->mm);
 	iommu_domain_free(private->domain);
 }
@@ -170,6 +290,7 @@ static int rockchip_drm_bind(struct device *dev)
 	}
 
 	drm_dev->dev_private = private;
+	INIT_LIST_HEAD(&private->resv_list);
 
 	ret = drmm_mode_config_init(drm_dev);
 	if (ret)
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
index 4705dc6b8bd7d..f107342527c6d 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
@@ -67,12 +67,14 @@ struct rockchip_crtc_state {
  * @crtc: array of enabled CRTCs, used to map from "pipe" to drm_crtc.
  * @num_pipe: number of pipes for this device.
  * @mm_lock: protect drm_mm on multi-threads.
+ * @resv_list: reserved regions of the VOPs, mapped 1:1 in @domain.
  */
 struct rockchip_drm_private {
 	struct iommu_domain *domain;
 	struct device *iommu_dev;
 	struct mutex mm_lock;
 	struct drm_mm mm;
+	struct list_head resv_list;
 };
 
 struct rockchip_encoder {
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree
  2026-12-04  6:24 ` [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree Francesco Saverio Pavone
@ 2026-12-04  6:32   ` Chaoyi Chen
  2026-12-04  6:44   ` sashiko-bot
  1 sibling, 0 replies; 8+ messages in thread
From: Chaoyi Chen @ 2026-12-04  6:32 UTC (permalink / raw)
  To: Francesco Saverio Pavone
  Cc: Joerg Roedel, Will Deacon, Robin Murphy, Sandy Huang,
	Heiko Stuebner, Andy Yan, Damon Ding, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiaxing Hu, iommu,
	dri-devel, devicetree, linux-rockchip, linux-arm-kernel

Hi,

On 12/4/2026 2:24 PM, Francesco Saverio Pavone wrote:
> The driver has no .get_resv_regions callback, so a reserved-memory node
> that lists a device in "iommu-addresses" is ignored: the region is
> neither kept out of the IOVA allocator nor mapped 1:1 in the default
> domain.
> 
> This matters for the VOP when the bootloader leaves a window scanning
> out of its own framebuffer. On RK3588 the default DMA domain is
> installed on the VOP MMU as soon as the MMU is resumed, with an empty
> page table, and the running scanout faults. On a ROCK 5B+ started from
> EDK2 this shows as
> 
>   rk_iommu fdd97e00.iommu: Enable stall request timed out, status: 0x00001d
>   rk_iommu fdd97e00.iommu: Enable stall request timed out, status: 0x00030b
> 
> Use of_iommu_get_resv_regions() as the callback, so that the core maps
> such a region before the MMU is enabled: the probe does not touch the
> hardware, and the page table is first loaded from the runtime resume.
> 
> The driver is devicetree only, and calling the OF helper directly,
> instead of going through iommu_dma_get_resv_regions(), lets a consumer
> read the regions on 32-bit ARM too, where IOMMU_DMA is not available.
> The default domain is not a DMA domain there, so the core maps nothing
> and this patch alone changes nothing on 32-bit ARM.
> 
> The IOVA space of the driver is 32 bits wide, so a region above 4 GiB
> cannot be mapped 1:1. Nothing checks for that here.

Please consider condensing your commit message. 

It only adds the get_resv_regions functionality. There is no need
to describe it at such length.

> Signed-off-by: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
> ---
>  drivers/iommu/rockchip-iommu.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
> index 1fa3110b142ad..757532a86975c 100644
> --- a/drivers/iommu/rockchip-iommu.c
> +++ b/drivers/iommu/rockchip-iommu.c
> @@ -20,6 +20,7 @@
>  #include <linux/mm.h>
>  #include <linux/init.h>
>  #include <linux/of.h>
> +#include <linux/of_iommu.h>
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> @@ -1204,6 +1205,7 @@ static const struct iommu_ops rk_iommu_ops = {
>  	.probe_device = rk_iommu_probe_device,
>  	.release_device = rk_iommu_release_device,
>  	.device_group = generic_single_device_group,
> +	.get_resv_regions = of_iommu_get_resv_regions,
>  	.of_xlate = rk_iommu_of_xlate,
>  	.default_domain_ops = &(const struct iommu_domain_ops) {
>  		.attach_dev	= rk_iommu_attach_device,

-- 
Best, 
Chaoyi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree
  2026-12-04  6:24 ` [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree Francesco Saverio Pavone
  2026-12-04  6:32   ` Chaoyi Chen
@ 2026-12-04  6:44   ` sashiko-bot
  1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-04  6:44 UTC (permalink / raw)
  To: Francesco Saverio Pavone; +Cc: dri-devel, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] iommu/rockchip: >4 GiB reserved regions silently alias in
  rk_iommu_map()
--

commit a62eae58527cef7e91d832e94bf0e1249fddc4d9
Author: Francesco Saverio Pavone <pavone.lawyer@gmail.com>

iommu/rockchip: Report the reserved regions from the devicetree

This commit wires of_iommu_get_resv_regions() into rk_iommu_ops so that
devicetree reserved-memory regions listed in iommu-addresses are
reported for Rockchip IOMMUs.

> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
> index 1fa3110b142ad..757532a86975c 100644
> --- a/drivers/iommu/rockchip-iommu.c
> +++ b/drivers/iommu/rockchip-iommu.c

[ ... ]

> @@ -1204,6 +1205,7 @@ static const struct iommu_ops rk_iommu_ops = {
>  	.probe_device = rk_iommu_probe_device,
>  	.release_device = rk_iommu_release_device,
>  	.device_group = generic_single_device_group,
> +	.get_resv_regions = of_iommu_get_resv_regions,

[Severity: Medium]
Can a devicetree reserved region at or above 4 GiB silently alias into
the low 32-bit IOVA space here?

iommu_create_device_direct_mappings() passes the 64-bit addresses from
of_iommu_get_resv_regions() straight to rk_iommu_iova_to_phys() and
rk_iommu_map() without checking domain->geometry.aperture_end.

Because rk_iova_dte_index() masks the IOVA with 0xffc00000 and casts to
u32, bits 63:32 are silently discarded.  On a 64-bit board with >4 GiB
RAM, a reserved region at or above 4 GiB installs PTEs at the wrapped
low 32-bit IOVA and returns 0 instead of failing.

Meanwhile, iova_reserve_iommu_regions() reserves the >4 GiB PFN range,
leaving the aliased low IOVAs unreserved.  Later DMA allocations in that
range fail with -EADDRINUSE, and DMA to unallocated low IOVAs (including
IOVA 0 for a 4 GiB-aligned region) silently hits the reserved memory.

A Rockchip get_resv_regions wrapper could filter out regions above
DMA_BIT_MASK(32), alongside bounds checks in rk_iommu_map(),
rk_iommu_unmap(), and rk_iommu_iova_to_phys() for the IOVA aperture and
physical address width.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796334467.git.pavone.lawyer@gmail.com?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain
  2026-12-04  6:24 ` [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain Francesco Saverio Pavone
@ 2026-12-04  6:48   ` sashiko-bot
  2026-12-04  7:14   ` Chaoyi Chen
  1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-04  6:48 UTC (permalink / raw)
  To: Francesco Saverio Pavone; +Cc: dri-devel, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/rockchip: rockchip_drm_collect_resv_regions() ignores
  IOMMU_RESV_RESERVED
--

commit 7e781ea37d24b597e54bf98cdf417ce94c06861d
Author: Francesco Saverio Pavone <pavone.lawyer@gmail.com>

drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain

This commit collects direct-mapped IOMMU reserved regions from bound VOP
devices, maps them 1:1 in the DRM IOMMU domain, and reserves their IOVA
ranges in private->mm.

> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> index ba417f7e9e474..aed22787c05e2 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> @@ -88,6 +88,121 @@ void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,

[ ... ]

> +static void rockchip_drm_collect_resv_regions(struct drm_device *drm_dev,
> +					      struct device *dev)
> +{
> +	struct rockchip_drm_private *private = drm_dev->dev_private;
> +	struct iommu_resv_region *region;
> +	struct rockchip_drm_resv *resv;
> +	LIST_HEAD(regions);
> +
> +	iommu_get_resv_regions(dev, &regions);
> +
> +	list_for_each_entry(region, &regions, list) {
> +		if (region->type != IOMMU_RESV_DIRECT &&
> +		    region->type != IOMMU_RESV_DIRECT_RELAXABLE)
> +			continue;

[Severity: Medium]
Should rockchip_drm_collect_resv_regions() also record IOMMU_RESV_RESERVED
regions instead of skipping them?

Commit "iommu/rockchip: Report the reserved regions from the devicetree"
wires of_iommu_get_resv_regions() into rk_iommu_ops, which emits
IOMMU_RESV_RESERVED for an iommu-addresses memory-region without a reg
property.  Dropping those regions leaves them unreserved in private->mm,
so rockchip_gem_iommu_map() can allocate and map GEM buffer IOVAs inside
ranges that the IOMMU API contract forbids mapping.

Reserving IOMMU_RESV_RESERVED ranges in private->mm (and removing them on
teardown) without calling iommu_map() or iommu_unmap() would avoid handing
out those IOVAs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796334467.git.pavone.lawyer@gmail.com?part=3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain
  2026-12-04  6:24 ` [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain Francesco Saverio Pavone
  2026-12-04  6:48   ` sashiko-bot
@ 2026-12-04  7:14   ` Chaoyi Chen
  1 sibling, 0 replies; 8+ messages in thread
From: Chaoyi Chen @ 2026-12-04  7:14 UTC (permalink / raw)
  To: Francesco Saverio Pavone
  Cc: Joerg Roedel, Will Deacon, Robin Murphy, Sandy Huang,
	Heiko Stuebner, Andy Yan, Damon Ding, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiaxing Hu, iommu,
	dri-devel, devicetree, linux-rockchip, linux-arm-kernel

Hi,

On 12/4/2026 2:24 PM, Francesco Saverio Pavone wrote:
> The driver allocates its own IOMMU domain and attaches a VOP to it on
> the first CRTC enable. If the bootloader left a window scanning out of
> its own framebuffer, that buffer has no mapping in the new domain, and
> the VOP reads it until the first new frame is latched. On a ROCK 5B+
> started from EDK2, with the buffer mapped in the default domain only,
> this shows at the first modeset as
> 
>   rk_iommu fdd97e00.iommu: Page fault at 0x00000000e6810400 of type read
> 
> and the two "Enable stall request timed out" lines come back later,
> when the compositor takes over.
> 
> When the devicetree describes the buffer as a reserved region of the
> VOP ("memory-region" with "iommu-addresses"), the iommu core maps it
> 1:1 in the default domain. Collect the direct-mapped regions of every
> VOP when it is bound, then give them the same mapping in the DRM domain
> before any device is attached, and reserve the range in the drm_mm so
> that no GEM object is given those addresses.
> 
> A region that does not fit in the aperture of the domain is skipped
> with a warning. The mappings are kept until the domain is freed: the
> driver does not know when the last read of the old buffer happens.
> Signed-off-by: Francesco Saverio Pavone <pavone.lawyer@gmail.com>

Again, please consider condensing your commit message.

> ---
>  drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 121 ++++++++++++++++++++
>  drivers/gpu/drm/rockchip/rockchip_drm_drv.h |   2 +
>  2 files changed, 123 insertions(+)
> 
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> index ba417f7e9e474..aed22787c05e2 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> @@ -88,6 +88,121 @@ void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,
>  	iommu_detach_device(private->domain, dev);
>  }
>  
> +struct rockchip_drm_resv {
> +	struct list_head list;
> +	struct drm_mm_node node;
> +	int prot;
> +};
> +
> +/*
> + * Remember the direct-mapped reserved regions of a VOP. The iommu core maps
> + * them 1:1 in the default domain of the device; rockchip_drm_init_iommu()
> + * gives them the same mapping in the DRM domain.
> + */

Drop this comment.

> +static void rockchip_drm_collect_resv_regions(struct drm_device *drm_dev,
> +					      struct device *dev)
> +{
> +	struct rockchip_drm_private *private = drm_dev->dev_private;
> +	struct iommu_resv_region *region;
> +	struct rockchip_drm_resv *resv;
> +	LIST_HEAD(regions);
> +
> +	iommu_get_resv_regions(dev, &regions);
> +
> +	list_for_each_entry(region, &regions, list) {
> +		if (region->type != IOMMU_RESV_DIRECT &&
> +		    region->type != IOMMU_RESV_DIRECT_RELAXABLE)
> +			continue;
> +
> +		resv = devm_kzalloc_obj(drm_dev->dev, *resv);
> +		if (!resv)
> +			break;
> +
> +		resv->node.start = region->start;
> +		resv->node.size = region->length;

This looks somewhat similar to iommu_create_device_direct_mapping().
Consider aligning the address range to page_size?

> +		resv->prot = region->prot;
> +		list_add_tail(&resv->list, &private->resv_list);
> +	}
> +
> +	iommu_put_resv_regions(dev, &regions);
> +}
> +
> +static void rockchip_drm_unmap_resv_regions(struct rockchip_drm_private *private)
> +{
> +	struct rockchip_drm_resv *resv;
> +
> +	list_for_each_entry(resv, &private->resv_list, list) {
> +		if (!drm_mm_node_allocated(&resv->node))
> +			continue;
> +
> +		iommu_unmap(private->domain, resv->node.start, resv->node.size);
> +		drm_mm_remove_node(&resv->node);
> +	}
> +}
> +
> +/*
> + * Map the reserved regions of the VOPs 1:1 in the DRM domain and keep their
> + * addresses away from the GEM objects, so that a scanout left running by the
> + * bootloader keeps working when a VOP is moved over to this domain. The VOP
> + * reads the old buffer until the first new frame is latched, so the mappings
> + * stay for as long as the domain does.
> + */

Drop this comment.

> +static void rockchip_drm_map_resv_regions(struct drm_device *drm_dev)
> +{
> +	struct rockchip_drm_private *private = drm_dev->dev_private;
> +	struct iommu_domain_geometry *geometry = &private->domain->geometry;
> +	unsigned long pgsz = 1UL << __ffs(private->domain->pgsize_bitmap);
> +	struct rockchip_drm_resv *resv, *other;
> +	u64 start, end;
> +	int ret;
> +
> +	list_for_each_entry(resv, &private->resv_list, list) {
> +		/* Same rounding as the direct mappings of the iommu core. */
> +		start = ALIGN(resv->node.start, pgsz);
> +		end = ALIGN(resv->node.start + resv->node.size, pgsz);

Oops, it looks like you perform the alignment here, but isn't that 
too late for your subsequent comparison?

> +		if (start >= end)
> +			continue;
> +
> +		/* Two VOPs may point at the same region. */
> +		ret = 0;
> +		list_for_each_entry(other, &private->resv_list, list) {
> +			if (other == resv)
> +				break;
> +			if (drm_mm_node_allocated(&other->node) &&
> +			    other->node.start == start &&
> +			    other->node.size == end - start)
> +				ret = -EEXIST;
> +		}
> +		if (ret)
> +			continue;
> +

Hmm, this doesn't seem to handle overlapping cases,
but it's sufficient for now.

> +		if (start < geometry->aperture_start ||
> +		    end - 1 > geometry->aperture_end) {
> +			drm_warn(drm_dev,
> +				 "reserved region [%#llx-%#llx] is outside the IOMMU aperture\n",
> +				 start, end - 1);
> +			continue;
> +		}
> +
> +		resv->node.start = start;
> +		resv->node.size = end - start;
> +		ret = drm_mm_reserve_node(&private->mm, &resv->node);
> +		if (ret) {
> +			drm_warn(drm_dev, "cannot reserve [%#llx-%#llx]: %d\n",
> +				 start, end - 1, ret);
> +			continue;
> +		}
> +
> +		ret = iommu_map(private->domain, start, start, end - start,
> +				resv->prot, GFP_KERNEL);
> +		if (ret) {
> +			drm_warn(drm_dev, "cannot map [%#llx-%#llx]: %d\n",
> +				 start, end - 1, ret);
> +			drm_mm_remove_node(&resv->node);
> +		}
> +	}
> +}
> +
>  void rockchip_drm_dma_init_device(struct drm_device *drm_dev,
>  				  struct device *dev)
>  {
> @@ -100,6 +215,9 @@ void rockchip_drm_dma_init_device(struct drm_device *drm_dev,
>  
>  	if (!IS_ERR(private->iommu_dev))
>  		drm_dev_set_dma_dev(drm_dev, private->iommu_dev);
> +
> +	if (device_iommu_mapped(dev))
> +		rockchip_drm_collect_resv_regions(drm_dev, dev);
>  }
>  
>  static int rockchip_drm_init_iommu(struct drm_device *drm_dev)
> @@ -127,6 +245,7 @@ static int rockchip_drm_init_iommu(struct drm_device *drm_dev)
>  		  start, end);
>  	drm_mm_init(&private->mm, start, end - start + 1);
>  	mutex_init(&private->mm_lock);
> +	rockchip_drm_map_resv_regions(drm_dev);
>  
>  	return 0;
>  }
> @@ -138,6 +257,7 @@ static void rockchip_iommu_cleanup(struct drm_device *drm_dev)
>  	if (!private->domain)
>  		return;
>  
> +	rockchip_drm_unmap_resv_regions(private);
>  	drm_mm_takedown(&private->mm);
>  	iommu_domain_free(private->domain);
>  }
> @@ -170,6 +290,7 @@ static int rockchip_drm_bind(struct device *dev)
>  	}
>  
>  	drm_dev->dev_private = private;
> +	INIT_LIST_HEAD(&private->resv_list);
>  
>  	ret = drmm_mode_config_init(drm_dev);
>  	if (ret)
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
> index 4705dc6b8bd7d..f107342527c6d 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
> @@ -67,12 +67,14 @@ struct rockchip_crtc_state {
>   * @crtc: array of enabled CRTCs, used to map from "pipe" to drm_crtc.
>   * @num_pipe: number of pipes for this device.
>   * @mm_lock: protect drm_mm on multi-threads.
> + * @resv_list: reserved regions of the VOPs, mapped 1:1 in @domain.
>   */
>  struct rockchip_drm_private {
>  	struct iommu_domain *domain;
>  	struct device *iommu_dev;
>  	struct mutex mm_lock;
>  	struct drm_mm mm;
> +	struct list_head resv_list;
>  };
>  
>  struct rockchip_encoder {

-- 
Best, 
Chaoyi

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-04  7:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  6:24 [RFC PATCH 0/3] rockchip: keep the bootloader framebuffer mapped behind the VOP IOMMU Francesco Saverio Pavone
2026-12-04  6:24 ` [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree Francesco Saverio Pavone
2026-12-04  6:32   ` Chaoyi Chen
2026-12-04  6:44   ` sashiko-bot
2026-12-04  6:24 ` [RFC PATCH 2/3] dt-bindings: display: vop2: Allow memory-region Francesco Saverio Pavone
2026-12-04  6:24 ` [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain Francesco Saverio Pavone
2026-12-04  6:48   ` sashiko-bot
2026-12-04  7:14   ` Chaoyi Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox