Skip to contentSkip to conversation

dt-bindings: media: qcom,sm8550-iris: Allow IOVA reservation memory-region

PATCH In review Daniel J Blueman 4 participants 5 messages Jun 14 – Jun 16

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 dt-bindings: media: qcom,sm8550-iris: Allow IOVA reservation memory-region

In addition to the firmware-loaded codec carveout, some Iris platforms need to declare an IOMMU IOVA reservation (a reserved-memory node with iommu-addresses) to keep DMA away from IOVA ranges that earlier firmware stages have already mapped through the SMMU.

Permit a second memory-region phandle for this purpose, and describe the meaning of each entry so the ordering is unambiguous.

Fixes 9065340ac04d ("arm64: dts: qcom: x1e80100: Add IRIS video codec")

---
v2:
- drop redundant maxItems, keeping the items descriptions (Rob)
- add Fixes tag and Cc stable for the backport dependency
v1: https://lore.kernel.org/lkml/[email protected]/

 .../devicetree/bindings/media/qcom,sm8550-iris.yaml          | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/qcom,sm8550-iris.yaml +4 -1
index 9c4b760508b5..5abcaee4101c 100644
@@ -80,7 +80,10 @@ properties:
   dma-coherent: true
 
   memory-region:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: Firmware-loaded codec carveout
+      - description: IOMMU IOVA reservation region
 
   operating-points-v2: true
 
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 2/2 arm64: dts: qcom: hamoa: Reserve low IOVA range for Iris

On X1-family hamoa platforms, the Iris VPU reserves IOVA addresses below 0x25800000 (600MB), primarily for non-pixel buffers accessed via different Stream IDs. DMA into that range triggers unhandled SMMU page faults that cause spontaneous device reboots. This is readily reproduced with one or more browser tabs driving multiple concurrent video decode streams.

Add a reserved-memory IOVA reservation node covering [0, 0x25800000) and reference it from the Iris node so the IOMMU layer keeps DMA allocations above that boundary.

This applies to all current hamoa.dtsi consumers (X1E80100/X1P42100/ X1P64100 boards); other Iris-bearing SoCs (sm8550/sm8650/sa8775p/ qcs8300) do not include hamoa.dtsi thus not affected.

Backports also require the preceding binding patch ("dt-bindings:
media: qcom,sm8550-iris: Allow IOVA reservation memory-region"); without it, dtbs_check rejects the second memory-region entry.

Fixes 9065340ac04d ("arm64: dts: qcom: x1e80100: Add IRIS video codec")

---
v2:
- add Fixes tag
- clarify the reservation rationale
v1: https://lore.kernel.org/lkml/[email protected]/

 arch/arm64/boot/dts/qcom/hamoa.dtsi | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/hamoa.dtsi +12 -1
index 051dee076416..ce96e7f8d8c1 100644
@@ -716,6 +716,17 @@ smem_mem: smem@ffe00000 {
 			hwlocks = <&tcsr_mutex 3>;
 			no-map;
 		};
+
+		/*
+		 * The Iris VPU reserves IOVA below 0x25800000 (600MB),
+		 * primarily for non-pixel buffers using different Stream IDs.
+		 * DMA into that range triggers unhandled SMMU faults and
+		 * spontaneous reboots, so reserve it to keep IOMMU
+		 * allocations above this boundary.
+		 */
+		iris_iova: iris-iova {
+			iommu-addresses = <&iris 0x0 0x0 0x0 0x25800000>;
+		};
 	};
 
 	qup_opp_table_100mhz: opp-table-qup100mhz {
@@ -5479,7 +5490,7 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			interconnect-names = "cpu-cfg",
 					     "video-mem";
 
-			memory-region = <&video_mem>;
+			memory-region = <&video_mem>, <&iris_iova>;
 
 			resets = <&gcc GCC_VIDEO_AXI0_CLK_ARES>;
 			reset-names = "bus";
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2 2/2] arm64: dts: qcom: hamoa: Reserve low IOVA range for Iris

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing NULL check on the return value of of_translate_dma_region() causes use of uninitialized variables and a guaranteed NULL pointer dereference.
- [High] The parser fails to advance the maps pointer when skipping entries for other devices, leading to misaligned parsing and potential out-of-bounds memory reads. --

commit 9504aa19b1b75ded98afc02b95aff54f7fd1ba37
Author: Daniel J Blueman <[email protected]>

arm64: dts: qcom: hamoa: Reserve low IOVA range for Iris

On X1-family hamoa platforms, the Iris VPU reserves IOVA addresses below 0x25800000 (600MB), primarily for non-pixel buffers accessed via different Stream IDs. DMA into that range triggers unhandled SMMU page faults that cause spontaneous device reboots. This is readily reproduced with one or more browser tabs driving multiple concurrent video decode streams.

Quoted 8 lines
arch/arm64/boot/dts/qcom/hamoa.dtsi +0 -0
index 051dee0764167..ce96e7f8d8c10 100644
@@ -716,6 +716,17 @@ smem_mem: smem@ffe00000 {
 			hwlocks = <&tcsr_mutex 3>;
 			no-map;
 		};

arch/arm64/boot/dts/qcom/hamoa.dtsi smem_mem: smem@ffe00000 { · line 728

Quoted 10 lines
arch/arm64/boot/dts/qcom/hamoa.dtsi +10 -0
+
+		/*
+		 * The Iris VPU reserves IOVA below 0x25800000 (600MB),
+		 * primarily for non-pixel buffers using different Stream IDs.
+		 * DMA into that range triggers unhandled SMMU faults and
+		 * spontaneous reboots, so reserve it to keep IOMMU
+		 * allocations above this boundary.
+		 */
+		iris_iova: iris-iova {
+			iommu-addresses = <&iris 0x0 0x0 0x0 0x25800000>;

[Severity: High]
This isn't a bug introduced by this patch, but adding this iommu-addresses property exercises a pre-existing issue in drivers/iommu/of_iommu.c:of_iommu_get_resv_regions().

If of_translate_dma_region() fails (e.g. returning OF_BAD_ADDR), it returns NULL without populating the local variables iova and length. The maps pointer is unconditionally overwritten with this NULL value:

drivers/iommu/of_iommu.c:of_iommu_get_resv_regions() {
    ...
    maps = of_translate_dma_region(np, maps, &iova, &length);
    ...
}

The code then evaluates if (length == 0) using uninitialized stack garbage.

If it proceeds to the next iteration, the while (maps < end) condition evaluates as true because NULL (0) is less than the valid kernel pointer end. The next iteration then blindly dereferences the NULL pointer with be32_to_cpup(maps++), causing a kernel panic.

Does the IOMMU core need to be fixed to handle a NULL return from of_translate_dma_region() before adding new users of iommu-addresses?

[Severity: High]
This is a pre-existing issue, but there is a second bug in drivers/iommu/of_iommu.c:of_iommu_get_resv_regions() related to iommu-addresses parsing that makes shared memory regions unsafe.

If an entry's phandle belongs to a different device, the loop skips the translation block:

drivers/iommu/of_iommu.c:of_iommu_get_resv_regions() {
    ...
    if (np == dev->of_node) {
        // ...
    }
    // missing else branch to advance maps pointer
    ...
}

Because it lacks an else branch to advance the maps pointer by the required #address-cells + #size-cells, the next iteration erroneously reads the first cell of the skipped address as a new phandle.

This desynchronizes the entire parser, potentially causing it to interpret an address or size value as a matching device phandle. It would then call of_translate_dma_region() on misaligned data, risking an out-of-bounds memory read since there is no bounds checking against the end of the property buffer.

Should the parsing logic be corrected to properly advance the maps pointer for non-matching devices?

Quoted 2 lines
arch/arm64/boot/dts/qcom/hamoa.dtsi +1 -0
+		};
 	};
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Reviewed-by on v2 1/2
#3 lore raw
In reply to Daniel J Blueman
Quoted 5 lines · Daniel J Blueman

In addition to the firmware-loaded codec carveout, some Iris platforms need to declare an IOMMU IOVA reservation (a reserved-memory node with iommu-addresses) to keep DMA away from IOVA ranges that earlier firmware stages have already mapped through the SMMU.

Quoted 7 lines

Permit a second memory-region phandle for this purpose, and describe the meaning of each entry so the ordering is unambiguous.

Fixes 9065340ac04d ("arm64: dts: qcom: x1e80100: Add IRIS video codec")

---

Best regards,
Krzysztof

#4 lore raw
In reply to Daniel J Blueman
Quoted 7 lines · Daniel J Blueman

In addition to the firmware-loaded codec carveout, some Iris platforms need to declare an IOMMU IOVA reservation (a reserved-memory node with iommu-addresses) to keep DMA away from IOVA ranges that earlier firmware stages have already mapped through the SMMU.

Permit a second memory-region phandle for this purpose, and describe the meaning of each entry so the ordering is unambiguous.

With no driver changes?

Quoted 32 lines
Fixes 9065340ac04d ("arm64: dts: qcom: x1e80100: Add IRIS video codec")

---
v2:
- drop redundant maxItems, keeping the items descriptions (Rob)
- add Fixes tag and Cc stable for the backport dependency
v1: https://lore.kernel.org/lkml/[email protected]/

 .../devicetree/bindings/media/qcom,sm8550-iris.yaml          | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/qcom,sm8550-iris.yaml +4 -1
index 9c4b760508b5..5abcaee4101c 100644
@@ -80,7 +80,10 @@ properties:
   dma-coherent: true
 
   memory-region:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: Firmware-loaded codec carveout
+      - description: IOMMU IOVA reservation region
 
   operating-points-v2: true
 
Signature · 1 line
2.53.0
Signature · 2 lines
With best wishes
Dmitry