Skip to contentSkip to conversation

media: iris: Migrate iommus to iris sub nodes

PATCH Superseded Vikash Garodia 9 participants 51 messages Sep 26 – Oct 26

Subsystems (8)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Vikash Garodia

author maintainer
#0 lore raw

v5 cover media: iris: Migrate iommus to iris sub nodes

The VPU issues DMA through several SMMU streams, and the hardware does not restricts specific streams with specific addressable range. The non-pixel stream is restricted to use 0-600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing keeps a non-pixel buffer inside the low 600 MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Fix was made in iris/venus driver to reserve the 0-600MB range and thereby prevent iova allocation from that range.
https://lore.kernel.org/all/20260818-reserve_iova_in_driver-v2-0-5005a1154408@oss.qualcomm.com

Given that the address range restriction is for specific VPU stream, it should be ideally moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range.

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The maintainers agreed to proceed with the subnode approach to address the VPU hardware limitation.

Reserving the iova address using "iommu-addresses" requires it to be placed in the reserved-memory node. But when "iommu-addresses" is the *only* property being described and there is no backing "reg" (i.e. no actual reserved system memory), it does not really belong to reserved-memory node. A device IOVA range is very much specific to the way device own address space is mapped, and not a description of memory shared across the system. Given this, "iommu-addresses" backed by a "reg", should be placed inside reserved-memory, otherwise, it should be defined within the device node. More info on this discussion can be found at
https://lore.kernel.org/all/[email protected]

"iommu-addresses" property expects a phandle, which does not make sense when the same is defined within individual device node itself. Introduced a new property, "iommu-ranges", for the IOVA ranges required for DMA memory mapping to that device node and when there is no physical memory reservation.

"iommu-ranges" is defined with the schema PR
https://github.com/devicetree-org/dt-schema/pull/207

This series migrate vpu3x platforms to subnodes. All new SOC having iris3x or onwards(4x 5x..) should follow the subnode approach. For VPU2x and AR50Lite SOCs, which are being migrated to iris, the subnode support would be added once the SOC is migrated away from venus to iris. There is no plan to upgrade venus enabled SOC to subnodes.

---
Changes in v5:
- Addressed review comments in #4 which seems valid (Sashiko)
- Added RB tags.
- Link to v4: https://lore.kernel.org/r/20260914-vpu_iommu_iova_handling-v4-0-9b9074a73c41@oss.qualcomm.com

Changes in v4:
- Dropped Daniel tested by tag (Krzysztof)
- Removed depends-on info from the commit description ((Krzysztof)
- Dropped the soc {} in example (Dmitry)
- Addressed review comments which seems valid (Sashiko)
- Binding patches depends-on: https://github.com/devicetree-org/dt-schema/pull/207
- Link to v3: https://lore.kernel.org/r/20260909-vpu_iommu_iova_handling-v3-0-2fe43ae45495@oss.qualcomm.com

Changes in v3:
- Drop iommu-addresses from reserved memory (Rob)
- Defined a new property iommu-ranges (Krzysztof, Dmitry)
- Moved the vpu specific context bank handling to common(Dmitry)
- Dropped fixes tag.
- Link to v2: https://lore.kernel.org/r/20260731-vpu_iommu_iova_handling-v2-0-da52b5228dbd@oss.qualcomm.com

Changes in v2:
- Fixed sashiko issues.
- Moved subnodes into common schema (Dmitry)
- Kept the firmware name as the one defained earlier (Dmitry)
- Added dma-ranges to specify parent-child address translation
- Moved context bank hooks to VPU ops (Dmitry)
- Updated commit description.
- Link to v1: https://lore.kernel.org/r/20260709-vpu_iommu_iova_handling-v1-0-72bb62cb2dfd@oss.qualcomm.com

---
Vikash Garodia (13):
dt-bindings: media: qcom,venus: Add context bank subnodes to common schema
dt-bindings: media: qcom,sm8550-iris: Add context bank subnodes
dt-bindings: media: qcom,sm8750-iris: Add context bank subnodes
iommu: of_iommu: Add support for "iommu-ranges" on a device node
media: iris: Add non-pixel and pixel context bank devices
media: iris: Route buffers to the matching context bank device
media: iris: Skip DMA mask setup when the core device has no IOMMU
arm64: dts: qcom: hamoa: Add Iris context bank subnodes
arm64: dts: qcom: sm8550: Add Iris context bank subnodes
arm64: dts: qcom: lemans: Add Iris context bank subnodes
arm64: dts: qcom: monaco: Add Iris context bank subnodes
arm64: dts: qcom: sm8650: Add Iris context bank subnodes
arm64: dts: qcom: sm8750: Add Iris context bank subnodes

 .../bindings/media/qcom,sc7180-venus.yaml          |  15 ---
 .../bindings/media/qcom,sm8550-iris.yaml           |  17 ++-
 .../bindings/media/qcom,sm8750-iris.yaml           |  16 ++-
 .../bindings/media/qcom,venus-common.yaml          |  97 ++++++++++++++++
 arch/arm64/boot/dts/qcom/hamoa.dtsi                |  15 ++-
 arch/arm64/boot/dts/qcom/lemans.dtsi               |  15 ++-
 arch/arm64/boot/dts/qcom/monaco.dtsi               |  15 ++-
 arch/arm64/boot/dts/qcom/sm8550.dtsi               |  15 ++-
 arch/arm64/boot/dts/qcom/sm8650.dtsi               |  16 ++-
 arch/arm64/boot/dts/qcom/sm8750.dtsi               |  15 ++-
 drivers/iommu/of_iommu.c                           | 128 +++++++++++++++++++--
 drivers/media/platform/qcom/iris/iris_buffer.c     |   8 +-
 drivers/media/platform/qcom/iris/iris_core.h       |   4 +
 drivers/media/platform/qcom/iris/iris_hfi_queue.c  |  16 +--
 drivers/media/platform/qcom/iris/iris_probe.c      |  79 ++++++++++++-
 drivers/media/platform/qcom/iris/iris_resources.c  |  41 +++++++
 drivers/media/platform/qcom/iris/iris_resources.h  |   1 +
 drivers/media/platform/qcom/iris/iris_vidc.c       |   4 +-
 18 files changed, 459 insertions(+), 58 deletions(-)

---
base-commit: f5f84daefcd92d7a630066635ecea1433ed5eac7
change-id: 20260701-vpu_iommu_iova_handling-556e969a1f1c

Best regards,

Signature · 1 line
Vikash Garodia <[email protected]>
author maintainer
#1 lore raw

PATCH v5 1/13 dt-bindings: media: qcom,venus: Add context bank subnodes to common schema

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

"iommu-ranges" on the subnode describes the *allowed* IOVA range that stream is allowed to use, so the IOVA is allocated from the specified range only. Define all the possible subnodes so as to describe all the VPU hardware iommu interfaces, both secure as well as non secure.

address-cells, size-cells and dma-ranges declares the 1:1 DMA translation into the parent.

The parent "iommus" is kept as an alternative via "oneOf", so platforms that have not been converted to subnodes still validate. New platforms should use the subnode form.

---
 .../bindings/media/qcom,sc7180-venus.yaml          | 15 ----
 .../bindings/media/qcom,venus-common.yaml          | 97 ++++++++++++++++++++++
 2 files changed, 97 insertions(+), 15 deletions(-)
Documentation/devicetree/bindings/media/qcom,sc7180-venus.yaml +0 -15
index b21bed314848480b82153e49602f0b19e08e7335..bfd8b1ad473128c974bce84639cb0aff59d8c2cc 100644
@@ -91,21 +91,6 @@ properties:
     deprecated: true
     additionalProperties: false
 
-  video-firmware:
-    type: object
-    additionalProperties: false
-
-    description: |
-      Firmware subnode is needed when the platform does not
-      have TrustZone.
-
-    properties:
-      iommus:
-        maxItems: 1
-
-    required:
-      - iommus
-
 required:
   - compatible
   - power-domain-names
Documentation/devicetree/bindings/media/qcom,venus-common.yaml +97 -0

107 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 01/13] dt-bindings: media: qcom,venus: Add context bank subnodes to common schema

Quoted 181 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

"iommu-ranges" on the subnode describes the *allowed* IOVA range that stream is allowed to use, so the IOVA is allocated from the specified range only. Define all the possible subnodes so as to describe all the VPU hardware iommu interfaces, both secure as well as non secure.

address-cells, size-cells and dma-ranges declares the 1:1 DMA translation into the parent.

The parent "iommus" is kept as an alternative via "oneOf", so platforms that have not been converted to subnodes still validate. New platforms should use the subnode form.

---
 .../bindings/media/qcom,sc7180-venus.yaml          | 15 ----
 .../bindings/media/qcom,venus-common.yaml          | 97 ++++++++++++++++++++++
 2 files changed, 97 insertions(+), 15 deletions(-)
Documentation/devicetree/bindings/media/qcom,sc7180-venus.yaml +0 -15
index b21bed314848480b82153e49602f0b19e08e7335..bfd8b1ad473128c974bce84639cb0aff59d8c2cc 100644
@@ -91,21 +91,6 @@ properties:
     deprecated: true
     additionalProperties: false
 
-  video-firmware:
-    type: object
-    additionalProperties: false
-
-    description: |
-      Firmware subnode is needed when the platform does not
-      have TrustZone.
-
-    properties:
-      iommus:
-        maxItems: 1
-
-    required:
-      - iommus
-
 required:
   - compatible
   - power-domain-names
Documentation/devicetree/bindings/media/qcom,venus-common.yaml +88 -0
index 59a3fde846d2196ab1e4588eb396012ba6860712..68d5e592a028c5eecde04ce72cd5ae6815ba5c82 100644
@@ -47,6 +47,93 @@ properties:
     minItems: 1
     maxItems: 4
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 1
+
+  dma-ranges:
+    maxItems: 1
+
+  non-pixel:
+    type: object
+    description:
+      Context bank for VPU non-pixel buffers, including compressed and internal buffers.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+      iommu-ranges:
+        maxItems: 1
+    required:
+      - iommus
+      - iommu-ranges
+
+  pixel:
+    type: object
+    description:
+      Context bank for VPU pixel buffers containing uncompressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  video-firmware:
+    type: object
+    description:
+      Context bank for the VPU firmware processing domain.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  secure-non-pixel:
+    type: object
+    description:
+      Context bank for VPU secure non-pixel buffers.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+      iommu-ranges:
+        maxItems: 1
+    required:
+      - iommus
+      - iommu-ranges
+
+  secure-pixel:
+    type: object
+    description:
+      Context bank for VPU secure pixel buffers containing uncompressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  secure-bitstream:
+    type: object
+    description:
+      Context bank for VPU secure bitstream buffers containing compressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
 required:
   - reg
   - clocks
@@ -55,4 +142,14 @@ required:
   - memory-region
   - power-domains
 
+oneOf:

Documentation/devicetree/bindings/media/qcom,venus-common.yaml required: · line 155

Quoted 10 lines
Documentation/devicetree/bindings/media/qcom,venus-common.yaml +9 -0
+  - required:
+      - iommus
+  - required:
+      - '#address-cells'
+      - '#size-cells'
+      - dma-ranges
+      - non-pixel
+      - pixel
+
 additionalProperties: true

Got this warning:
arch/arm64/boot/dts/qcom/nord-rrd.dtb: non-pixel: iommu-ranges:
b'%\x80\x00\x00\xda`\x00\x00' is not of type 'object', 'integer', 'array', 'boolean', 'null' arch/arm64/boot/dts/qcom/nord-ride-embedded.dtb: non-pixel:
iommu-ranges: b'%\x80\x00\x00\xda`\x00\x00' is not of type 'object', 'integer', 'array', 'boolean', 'null'

Need

Documentation/devicetree/bindings/media/qcom,venus-common.yaml +6 -2
@@ -67,7 +67,9 @@ properties:
         minItems: 1
         maxItems: 3
       iommu-ranges:
-        maxItems: 1
+        $ref: /schemas/types.yaml#/definitions/uint32-array
+        minItems: 2
+        maxItems: 2
     required:
       - iommus
       - iommu-ranges
@@ -106,7 +108,9 @@ properties:
       iommus:
         maxItems: 1
       iommu-ranges:
-        maxItems: 1
+        $ref: /schemas/types.yaml#/definitions/uint32-array
+        minItems: 2
+        maxItems: 2
     required:
       - iommus
       - iommu-ranges

Thanks

author maintainer
#3 lore raw

Re: [PATCH v5 01/13] dt-bindings: media: qcom,venus: Add context bank subnodes to common schema

Quoted 192 lines · Zhangfei Gao
Quoted 190 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

     +-----------------------------------------------------------+
     | non-pixel stream addressable range (600 MB - 3.5 GB)      |
     | 0x25800000 - 0xe0000000                                   |
     +-----------------------------------------------------------+
     | pixel stream addressable range (0 - 3.5 GB)               |
     | 0x00000000 - 0xe0000000                                   |
     +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

"iommu-ranges" on the subnode describes the *allowed* IOVA range that stream is allowed to use, so the IOVA is allocated from the specified range only. Define all the possible subnodes so as to describe all the VPU hardware iommu interfaces, both secure as well as non secure.

address-cells, size-cells and dma-ranges declares the 1:1 DMA translation into the parent.

The parent "iommus" is kept as an alternative via "oneOf", so platforms that have not been converted to subnodes still validate. New platforms should use the subnode form.

---
  .../bindings/media/qcom,sc7180-venus.yaml          | 15 ----
  .../bindings/media/qcom,venus-common.yaml          | 97 ++++++++++++++++++++++
  2 files changed, 97 insertions(+), 15 deletions(-)
Documentation/devicetree/bindings/media/qcom,sc7180-venus.yaml +0 -15
index b21bed314848480b82153e49602f0b19e08e7335..bfd8b1ad473128c974bce84639cb0aff59d8c2cc 100644
@@ -91,21 +91,6 @@ properties:
      deprecated: true
      additionalProperties: false
 
-  video-firmware:
-    type: object
-    additionalProperties: false
-
-    description: |
-      Firmware subnode is needed when the platform does not
-      have TrustZone.
-
-    properties:
-      iommus:
-        maxItems: 1
-
-    required:
-      - iommus
-
  required:
    - compatible
    - power-domain-names
Documentation/devicetree/bindings/media/qcom,venus-common.yaml +97 -0
index 59a3fde846d2196ab1e4588eb396012ba6860712..68d5e592a028c5eecde04ce72cd5ae6815ba5c82 100644
@@ -47,6 +47,93 @@ properties:
      minItems: 1
      maxItems: 4
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 1
+
+  dma-ranges:
+    maxItems: 1
+
+  non-pixel:
+    type: object
+    description:
+      Context bank for VPU non-pixel buffers, including compressed and internal buffers.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+      iommu-ranges:
+        maxItems: 1
+    required:
+      - iommus
+      - iommu-ranges
+
+  pixel:
+    type: object
+    description:
+      Context bank for VPU pixel buffers containing uncompressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  video-firmware:
+    type: object
+    description:
+      Context bank for the VPU firmware processing domain.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  secure-non-pixel:
+    type: object
+    description:
+      Context bank for VPU secure non-pixel buffers.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+      iommu-ranges:
+        maxItems: 1
+    required:
+      - iommus
+      - iommu-ranges
+
+  secure-pixel:
+    type: object
+    description:
+      Context bank for VPU secure pixel buffers containing uncompressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  secure-bitstream:
+    type: object
+    description:
+      Context bank for VPU secure bitstream buffers containing compressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
  required:
    - reg
    - clocks
@@ -55,4 +142,14 @@ required:
    - memory-region
    - power-domains
 
+oneOf:
+  - required:
+      - iommus
+  - required:
+      - '#address-cells'
+      - '#size-cells'
+      - dma-ranges
+      - non-pixel
+      - pixel
+
  additionalProperties: true
Quoted 9 lines
Quoted 1 line

Got this warning:
arch/arm64/boot/dts/qcom/nord-rrd.dtb: non-pixel: iommu-ranges:
b'%\x80\x00\x00\xda`\x00\x00' is not of type 'object', 'integer', 'array', 'boolean', 'null' arch/arm64/boot/dts/qcom/nord-ride-embedded.dtb: non-pixel:
iommu-ranges: b'%\x80\x00\x00\xda`\x00\x00' is not of type 'object', 'integer', 'array', 'boolean', 'null'

You have not picked the latest dt schema. Please go through the cover letter where a PR is mentioned, please pull that or validate against latest schema.

Regards,
Vikash

#4 lore raw

Re: [PATCH v5 01/13] dt-bindings: media: qcom,venus: Add context bank subnodes to common schema

Quoted 205 lines · Vikash Garodia
Quoted 192 lines · Zhangfei Gao
Quoted 190 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

     +-----------------------------------------------------------+
     | non-pixel stream addressable range (600 MB - 3.5 GB)      |
     | 0x25800000 - 0xe0000000                                   |
     +-----------------------------------------------------------+
     | pixel stream addressable range (0 - 3.5 GB)               |
     | 0x00000000 - 0xe0000000                                   |
     +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

"iommu-ranges" on the subnode describes the *allowed* IOVA range that stream is allowed to use, so the IOVA is allocated from the specified range only. Define all the possible subnodes so as to describe all the VPU hardware iommu interfaces, both secure as well as non secure.

address-cells, size-cells and dma-ranges declares the 1:1 DMA translation into the parent.

The parent "iommus" is kept as an alternative via "oneOf", so platforms that have not been converted to subnodes still validate. New platforms should use the subnode form.

---
  .../bindings/media/qcom,sc7180-venus.yaml          | 15 ----
  .../bindings/media/qcom,venus-common.yaml          | 97 ++++++++++++++++++++++
  2 files changed, 97 insertions(+), 15 deletions(-)
Documentation/devicetree/bindings/media/qcom,sc7180-venus.yaml +0 -15
index b21bed314848480b82153e49602f0b19e08e7335..bfd8b1ad473128c974bce84639cb0aff59d8c2cc 100644
@@ -91,21 +91,6 @@ properties:
      deprecated: true
      additionalProperties: false
 
-  video-firmware:
-    type: object
-    additionalProperties: false
-
-    description: |
-      Firmware subnode is needed when the platform does not
-      have TrustZone.
-
-    properties:
-      iommus:
-        maxItems: 1
-
-    required:
-      - iommus
-
  required:
    - compatible
    - power-domain-names
Documentation/devicetree/bindings/media/qcom,venus-common.yaml +97 -0
index 59a3fde846d2196ab1e4588eb396012ba6860712..68d5e592a028c5eecde04ce72cd5ae6815ba5c82 100644
@@ -47,6 +47,93 @@ properties:
      minItems: 1
      maxItems: 4
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 1
+
+  dma-ranges:
+    maxItems: 1
+
+  non-pixel:
+    type: object
+    description:
+      Context bank for VPU non-pixel buffers, including compressed and internal buffers.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+      iommu-ranges:
+        maxItems: 1
+    required:
+      - iommus
+      - iommu-ranges
+
+  pixel:
+    type: object
+    description:
+      Context bank for VPU pixel buffers containing uncompressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  video-firmware:
+    type: object
+    description:
+      Context bank for the VPU firmware processing domain.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  secure-non-pixel:
+    type: object
+    description:
+      Context bank for VPU secure non-pixel buffers.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+      iommu-ranges:
+        maxItems: 1
+    required:
+      - iommus
+      - iommu-ranges
+
+  secure-pixel:
+    type: object
+    description:
+      Context bank for VPU secure pixel buffers containing uncompressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  secure-bitstream:
+    type: object
+    description:
+      Context bank for VPU secure bitstream buffers containing compressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
  required:
    - reg
    - clocks
@@ -55,4 +142,14 @@ required:
    - memory-region
    - power-domains
 
+oneOf:
+  - required:
+      - iommus
+  - required:
+      - '#address-cells'
+      - '#size-cells'
+      - dma-ranges
+      - non-pixel
+      - pixel
+
  additionalProperties: true
Quoted 9 lines
Quoted 1 line

Got this warning:
arch/arm64/boot/dts/qcom/nord-rrd.dtb: non-pixel: iommu-ranges:
b'%\x80\x00\x00\xda`\x00\x00' is not of type 'object', 'integer', 'array', 'boolean', 'null' arch/arm64/boot/dts/qcom/nord-ride-embedded.dtb: non-pixel:
iommu-ranges: b'%\x80\x00\x00\xda`\x00\x00' is not of type 'object', 'integer', 'array', 'boolean', 'null'

Quoted 3 lines

You have not picked the latest dt schema. Please go through the cover letter where a PR is mentioned, please pull that or validate against latest schema.

Yes, with the latest dt schema, the check passes, thanks.

Reviewed-by on v5 1/13
#5 lore raw

Re: [PATCH v5 01/13] dt-bindings: media: qcom,venus: Add context bank subnodes to common schema

In reply to Vikash Garodia
Quoted 191 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

     +-----------------------------------------------------------+
     | non-pixel stream addressable range (600 MB - 3.5 GB)      |
     | 0x25800000 - 0xe0000000                                   |
     +-----------------------------------------------------------+
     | pixel stream addressable range (0 - 3.5 GB)               |
     | 0x00000000 - 0xe0000000                                   |
     +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

"iommu-ranges" on the subnode describes the *allowed* IOVA range that stream is allowed to use, so the IOVA is allocated from the specified range only. Define all the possible subnodes so as to describe all the VPU hardware iommu interfaces, both secure as well as non secure.

address-cells, size-cells and dma-ranges declares the 1:1 DMA translation into the parent.

The parent "iommus" is kept as an alternative via "oneOf", so platforms that have not been converted to subnodes still validate. New platforms should use the subnode form.

---
  .../bindings/media/qcom,sc7180-venus.yaml          | 15 ----
  .../bindings/media/qcom,venus-common.yaml          | 97 ++++++++++++++++++++++
  2 files changed, 97 insertions(+), 15 deletions(-)
Documentation/devicetree/bindings/media/qcom,sc7180-venus.yaml +0 -15
index b21bed314848480b82153e49602f0b19e08e7335..bfd8b1ad473128c974bce84639cb0aff59d8c2cc 100644
@@ -91,21 +91,6 @@ properties:
      deprecated: true
      additionalProperties: false
 
-  video-firmware:
-    type: object
-    additionalProperties: false
-
-    description: |
-      Firmware subnode is needed when the platform does not
-      have TrustZone.
-
-    properties:
-      iommus:
-        maxItems: 1
-
-    required:
-      - iommus
-
  required:
    - compatible
    - power-domain-names
Documentation/devicetree/bindings/media/qcom,venus-common.yaml +97 -1
index 59a3fde846d2196ab1e4588eb396012ba6860712..68d5e592a028c5eecde04ce72cd5ae6815ba5c82 100644
@@ -47,6 +47,93 @@ properties:
      minItems: 1
      maxItems: 4
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 1
+
+  dma-ranges:
+    maxItems: 1
+
+  non-pixel:
+    type: object
+    description:
+      Context bank for VPU non-pixel buffers, including compressed and internal buffers.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+      iommu-ranges:
+        maxItems: 1
+    required:
+      - iommus
+      - iommu-ranges
+
+  pixel:
+    type: object
+    description:
+      Context bank for VPU pixel buffers containing uncompressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  video-firmware:
+    type: object
+    description:
+      Context bank for the VPU firmware processing domain.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  secure-non-pixel:
+    type: object
+    description:
+      Context bank for VPU secure non-pixel buffers.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+      iommu-ranges:
+        maxItems: 1
+    required:
+      - iommus
+      - iommu-ranges
+
+  secure-pixel:
+    type: object
+    description:
+      Context bank for VPU secure pixel buffers containing uncompressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
+  secure-bitstream:
+    type: object
+    description:
+      Context bank for VPU secure bitstream buffers containing compressed video data.
+    additionalProperties: false
+
+    properties:
+      iommus:
+        maxItems: 1
+    required:
+      - iommus
+
  required:
    - reg
    - clocks
@@ -55,4 +142,14 @@ required:
    - memory-region
    - power-domains
 
+oneOf:
+  - required:
+      - iommus
+  - required:
+      - '#address-cells'
+      - '#size-cells'
+      - dma-ranges
+      - non-pixel
+      - pixel
+
  additionalProperties: true
 
--
Quoted 2 lines

2.34.1

author maintainer
#6 lore raw

PATCH v5 2/13 dt-bindings: media: qcom,sm8550-iris: Add context bank subnodes

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

Update example to the subnode form. Doing so, it picks up the supporting properties needed on the video-codec node, address-cells, size-cells and dma-ranges to declare 1:1 DMA translation into the parent.

---
 .../devicetree/bindings/media/qcom,sm8550-iris.yaml     | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/media/qcom,sm8550-iris.yaml +14 -3
index 0400ca1bff05dcef6b742c3fbf77e38adca9f280..6ee9d23554cffb30c92017ef99de15c2493455ac 100644
@@ -98,10 +98,10 @@ required:
   - interconnect-names
   - resets
   - reset-names
-  - iommus
   - dma-coherent
 
 allOf:
+  - $ref: qcom,venus-common.yaml#
   - if:
       properties:
         compatible:
@@ -177,12 +177,23 @@ examples:
         resets = <&gcc GCC_VIDEO_AXI0_CLK_ARES>;
         reset-names = "bus";
 
-        iommus = <&apps_smmu 0x1940 0x0000>,
-                 <&apps_smmu 0x1947 0x0000>;
         dma-coherent;
 
         operating-points-v2 = <&iris_opp_table>;
 
+        #address-cells = <1>;
+        #size-cells = <1>;
+        dma-ranges = <0x0 0x0 0xe0000000>;
+
+        non-pixel {
+            iommus = <&apps_smmu 0x1940 0x0>;
+            iommu-ranges = <0x25800000 0xba800000>;
+        };
+
+        pixel {
+            iommus = <&apps_smmu 0x1947 0x0>;
+        };
+
         iris_opp_table: opp-table {
             compatible = "operating-points-v2";
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v5 2/13
#7 lore raw

Re: [PATCH v5 02/13] dt-bindings: media: qcom,sm8550-iris: Add context bank subnodes

Quoted 31 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

     +-----------------------------------------------------------+
     | non-pixel stream addressable range (600 MB - 3.5 GB)      |
     | 0x25800000 - 0xe0000000                                   |
     +-----------------------------------------------------------+
     | pixel stream addressable range (0 - 3.5 GB)               |
     | 0x00000000 - 0xe0000000                                   |
     +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines

Update example to the subnode form. Doing so, it picks up the supporting properties needed on the video-codec node, address-cells, size-cells and dma-ranges to declare 1:1 DMA translation into the parent.

author maintainer
#8 lore raw

PATCH v5 3/13 dt-bindings: media: qcom,sm8750-iris: Add context bank subnodes

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

Update example to the subnode form. Doing so, it picks up the supporting properties needed on the video-codec node, address-cells, size-cells and dma-ranges to declare 1:1 DMA translation into the parent.

---
 .../devicetree/bindings/media/qcom,sm8750-iris.yaml      | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/media/qcom,sm8750-iris.yaml +13 -3
index c42d3470bdac796cc878090e65becf6b62bd80ca..b6d5ded1aae6a1a6836c2c24b1dae548cdc6f9d2 100644
@@ -72,7 +72,6 @@ required:
   - dma-coherent
   - interconnects
   - interconnect-names
-  - iommus
   - power-domain-names
   - resets
   - reset-names
@@ -110,8 +109,6 @@ examples:
                       "vcodec0_core_freerun";
 
         dma-coherent;
-        iommus = <&apps_smmu 0x1940 0>,
-                 <&apps_smmu 0x1947 0>;
 
         interconnects = <&gem_noc MASTER_APPSS_PROC QCOM_ICC_TAG_ACTIVE_ONLY
                          &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
@@ -144,6 +141,19 @@ examples:
                       "core",
                       "vcodec0_core";
 
+        #address-cells = <1>;
+        #size-cells = <1>;
+        dma-ranges = <0x0 0x0 0xe0000000>;
+
+        non-pixel {
+            iommus = <&apps_smmu 0x1940 0x0>;
+            iommu-ranges = <0x25800000 0xba800000>;
+        };
+
+        pixel {
+            iommus = <&apps_smmu 0x1947 0x0>;
+        };
+
         iris_opp_table: opp-table {
             compatible = "operating-points-v2";
 
Signature · 1 line
2.34.1
author maintainer
#9 lore raw

PATCH v5 4/13 iommu: of_iommu: Add support for "iommu-ranges" on a device node

In reply to Vikash Garodia

Reserving an IOVA address using "iommu-addresses" requires it to be placed in the reserved-memory node. But when "iommu-addresses" is the only property being described and there is no backing "reg" (i.e. no actual reserved system memory), it does not really belong under /reserved-memory. A device IOVA range is specific to its own address space, and does not describe the system physical memory to make it qualify under reserved-memory. Given this, place "iommu-addresses" inside reserved-memory only when it is paired with a "reg", otherwise, define it within the device own node. It was discussed here:
https://lore.kernel.org/all/[email protected]

Existing "iommu-addresses" property expects a phandle, which does not make sense when the property is defined within the device node. Introduce a new property, "iommu-ranges", to specify the device specific IOVA ranges when there is no backing "reg".

---
 drivers/iommu/of_iommu.c | 128 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 121 insertions(+), 7 deletions(-)
drivers/iommu/of_iommu.c +121 -7
index a18bb60f6f3dfdba853b6e16dd2a8616f6a731c7..9766a6944d0e11a6cd8b74b1b89428acffe3dfdf 100644
@@ -190,6 +190,111 @@ iommu_resv_region_get_type(struct device *dev,
 	return IOMMU_RESV_RESERVED;
 }
 
+/**
+ * of_iommu_derive_resv_regions - derive reserved regions which
+ *                                are outside of iommu-ranges
+ * @dev: device for which to get reserved regions
+ * @list: reserved region list
+ *
+ * A device can describe its own usable IOVA ranges directly on its node
+ * via "iommu-ranges". Everything not under those ranges is derived
+ * as a reserved region so the IOMMU allocator won't use it. Entries may
+ * appear in any order in the property.
+ */
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{
+	struct of_iommu_range {
+		struct list_head node;
+		phys_addr_t start;
+		phys_addr_t end;
+	} *pos, *new, *next_range;
+	int size, prot = IOMMU_READ | IOMMU_WRITE;
+	struct iommu_resv_region *region;
+	const __be32 *maps, *end;
+	struct list_head *prev;
+	phys_addr_t next = 0;
+	LIST_HEAD(ranges);
+
+	maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+	if (!maps)
+		return;
+
+	end = maps + size / sizeof(__be32);
+
+	while (maps < end) {
+		phys_addr_t iova, iova_end;
+		size_t length;
+
+		maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);
+		if (!maps) {
+			dev_err(dev, "%pOF: failed to parse iommu-ranges\n",
+				dev->of_node);
+			break;
+		}
+
+		if (!length)
+			continue;
+
+		iova_end = iova + length - 1;
+
+		if (iova_end < iova) {
+			dev_err(dev, "%pOF: iommu-ranges overflows address space\n",
+				dev->of_node);
+			continue;
+		}
+
+		prev = &ranges;
+		list_for_each_entry(pos, &ranges, node) {
+			if (pos->start > iova)
+				break;
+			prev = &pos->node;
+		}
+
+		new = kmalloc_obj(*new);
+		if (!new)
+			continue;
+
+		new->start = iova;
+		new->end = iova_end;
+		list_add(&new->node, prev);
+	}
+
+	if (list_empty(&ranges))
+		return;
+
+	if (of_dma_is_coherent(dev->of_node))
+		prot |= IOMMU_CACHE;
+
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		if (pos->start > next) {
+			region = iommu_alloc_resv_region(next, pos->start - next, prot,
+							 IOMMU_RESV_RESERVED, GFP_KERNEL);
+			if (region)
+				list_add_tail(&region->list, list);
+		}
+
+		if (pos->end == PHYS_ADDR_MAX)
+			goto exit;
+
+		if (pos->end >= next)
+			next = pos->end + 1;
+
+		list_del(&pos->node);
+		kfree(pos);
+	}
+
+	region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+					 prot, IOMMU_RESV_RESERVED, GFP_KERNEL);
+	if (region)
+		list_add_tail(&region->list, list);
+
+exit:
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		list_del(&pos->node);
+		kfree(pos);
+	}
+}
+
 /**
  * of_iommu_get_resv_regions - reserved region driver helper for device tree
  * @dev: device for which to get reserved regions
@@ -214,10 +319,14 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
 
 		memset(&phys, 0, sizeof(phys));
 
+		maps = of_get_property(it.node, "iommu-addresses", &size);
+		if (!maps)
+			continue;
+
 		/*
-		 * The "reg" property is optional and can be omitted by reserved-memory regions
-		 * that represent reservations in the IOVA space, which are regions that should
-		 * not be mapped.
+		 * "iommu-addresses" must be used in combination with a "reg" that provides
+		 * the physical address and size of this memory region, for an identity 1:1
+		 * IOVA mapping to that physical memory.
 		 */
 		if (of_property_present(it.node, "reg")) {
 			err = of_address_to_resource(it.node, 0, &phys);
@@ -226,11 +335,11 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
 					it.node, err);
 				continue;
 			}
-		}
-
-		maps = of_get_property(it.node, "iommu-addresses", &size);
-		if (!maps)
+		} else {
+			dev_err(dev, "%pOF: iommu-addresses requires a reg property\n",
+				it.node);
 			continue;
+		}
 
 		end = maps + size / sizeof(__be32);
 
@@ -258,6 +367,9 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
 				}
 				type = iommu_resv_region_get_type(dev, &phys, iova, length);
 
+				if (type != IOMMU_RESV_DIRECT)
+					continue;
+
 				region = iommu_alloc_resv_region(iova, length, prot, type,
 								 GFP_KERNEL);
 				if (region)
@@ -265,6 +377,8 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
 			}
 		}
 	}
+
+	of_iommu_derive_resv_regions(dev, list);
 #endif
 }
 EXPORT_SYMBOL(of_iommu_get_resv_regions);
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] iommu: size_t truncation of derived reserved region length on 32-bit systems - [Medium] iommu: DT…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu: size_t truncation of derived reserved region length on 32-bit systems
- [Medium] iommu: DT ABI breakage by rejecting iommu-addresses without reg
- [Medium] iommu: OOB read in of_iommu_derive_resv_regions when parsing malformed iommu-ranges --

commit 08a09989ffefcbf5d38171159dcc911ca993ff18
Author: Vikash Garodia <[email protected]>

iommu: of_iommu: Add support for "iommu-ranges" on a device node

Add support for "iommu-ranges" on device nodes to specify usable IOVA ranges directly when there is no backing "reg". Introduce logic to derive reserved regions outside of "iommu-ranges" and restrict "iommu-addresses" to be paired with a "reg" property.

Quoted 4 lines
drivers/iommu/of_iommu.c +0 -0
index a18bb60f6f3df..9766a6944d0e1 100644

[ ... ]

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 228

Quoted 11 lines
drivers/iommu/of_iommu.c +11 -0
+	maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+	if (!maps)
+		return;
+
+	end = maps + size / sizeof(__be32);
+
+	while (maps < end) {
+		phys_addr_t iova, iova_end;
+		size_t length;
+
+		maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);

[Severity: Medium]
Could this result in an out-of-bounds read if the "iommu-ranges" property is malformed?

The loop condition checks maps < end, but of_translate_dma_region() implicitly reads na + ns cells from the maps array.

Does this loop need to ensure there are at least na + ns cells remaining before calling the translation function to prevent reading past the buffer?

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 271

Quoted 4 lines
drivers/iommu/of_iommu.c +4 -0
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		if (pos->start > next) {
+			region = iommu_alloc_resv_region(next, pos->start - next, prot,
+							 IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Can the length argument overflow on 32-bit systems?

On 32-bit systems with 64-bit physical addresses (like ARM LPAE), address differences can easily exceed 4GB. Because iommu_alloc_resv_region() takes a 32-bit size_t length, passing a 64-bit gap size causes it to truncate.

Will this truncation result in a reservation of at most 4GB, leaving the IOVA address space above that unprotected?

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 287

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+	region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+					 prot, IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Similarly, can passing PHYS_ADDR_MAX - next + 1 here truncate the length to its lower 32 bits on 32-bit systems?

If the remaining address space exceeds 4GB, this truncation could leave high IOVA addresses unprotected, allowing the IOMMU allocator to hand out reserved IOVAs.

[ ... ]

Quoted 1 line
drivers/iommu/of_iommu.c +0 -0
@@ -214,10 +319,14 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)

[ ... ]

Quoted 9 lines
drivers/iommu/of_iommu.c +3 -3
-		 * The "reg" property is optional and can be omitted by reserved-memory regions
-		 * that represent reservations in the IOVA space, which are regions that should
-		 * not be mapped.
+		 * "iommu-addresses" must be used in combination with a "reg" that provides
+		 * the physical address and size of this memory region, for an identity 1:1
+		 * IOVA mapping to that physical memory.
 		 */
 		if (of_property_present(it.node, "reg")) {
 			err = of_address_to_resource(it.node, 0, &phys);

[ ... ]

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, struct list_head *list) · line 342

Quoted 9 lines
drivers/iommu/of_iommu.c +4 -4
-		}
-
-		maps = of_get_property(it.node, "iommu-addresses", &size);
-		if (!maps)
+		} else {
+			dev_err(dev, "%pOF: iommu-addresses requires a reg property\n",
+				it.node);
 			continue;
+		}

[Severity: Medium]
Will this break existing device trees?

This explicitly rejects the previously valid 'no reg' device tree configurations. Existing device trees that validly relied on "iommu-addresses" without a "reg" property to create IOVA reservations will now have their reservations silently ignored.

Could this lead to the IOMMU allocating IOVAs in reserved spaces, causing DMA faults?

[ ... ]

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, struct list_head *list) · line 374

Quoted 9 lines
drivers/iommu/of_iommu.c +3 -0
@@ -258,6 +367,9 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
 				}
 				type = iommu_resv_region_get_type(dev, &phys, iova, length);
 
+				if (type != IOMMU_RESV_DIRECT)
+					continue;
+
 				region = iommu_alloc_resv_region(iova, length, prot, type,
 								 GFP_KERNEL);

[Severity: Medium]
Does this newly added check actively block pure reservations?

By enforcing that only identity mappings are honored, does this violate backward compatibility for device trees that used pure reservations?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260926-vpu_iommu_iova_handling-v5-0-0322ca5dc10c@oss.qualcomm.com?part=4
#11 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Quoted 42 lines · On 9/26/2026 12:17 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu: size_t truncation of derived reserved region length on 32-bit systems
- [Medium] iommu: DT ABI breakage by rejecting iommu-addresses without reg
- [Medium] iommu: OOB read in of_iommu_derive_resv_regions when parsing malformed iommu-ranges --

commit 08a09989ffefcbf5d38171159dcc911ca993ff18
Author: Vikash Garodia <[email protected]>

iommu: of_iommu: Add support for "iommu-ranges" on a device node

Add support for "iommu-ranges" on device nodes to specify usable IOVA ranges directly when there is no backing "reg". Introduce logic to derive reserved regions outside of "iommu-ranges" and restrict "iommu-addresses" to be paired with a "reg" property.

Quoted 4 lines
drivers/iommu/of_iommu.c +0 -0
index a18bb60f6f3df..9766a6944d0e1 100644

[ ... ]

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 228

Quoted 11 lines
drivers/iommu/of_iommu.c +11 -0
+	maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+	if (!maps)
+		return;
+
+	end = maps + size / sizeof(__be32);
+
+	while (maps < end) {
+		phys_addr_t iova, iova_end;
+		size_t length;
+
+		maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);

[Severity: Medium]
Could this result in an out-of-bounds read if the "iommu-ranges" property is malformed?

Quoted 6 lines

The loop condition checks maps < end, but of_translate_dma_region() implicitly reads na + ns cells from the maps array.

Does this loop need to ensure there are at least na + ns cells remaining before calling the translation function to prevent reading past the buffer?

This function intention is not to validate the address and size cells here and it's not valid to read those properties here. If the out of bound ranges are there, then it's part of dtc checks that dt node contains invalid ranges.

Quoted 24 lines

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 271

Quoted 4 lines
drivers/iommu/of_iommu.c +4 -0
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		if (pos->start > next) {
+			region = iommu_alloc_resv_region(next, pos->start - next, prot,
+							 IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Can the length argument overflow on 32-bit systems?

On 32-bit systems with 64-bit physical addresses (like ARM LPAE), address differences can easily exceed 4GB. Because iommu_alloc_resv_region() takes a 32-bit size_t length, passing a 64-bit gap size causes it to truncate.

Will this truncation result in a reservation of at most 4GB, leaving the IOVA address space above that unprotected?

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 287

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+	region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+					 prot, IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Similarly, can passing PHYS_ADDR_MAX - next + 1 here truncate the length to its lower 32 bits on 32-bit systems?

Quoted 4 lines

If the remaining address space exceeds 4GB, this truncation could leave high IOVA addresses unprotected, allowing the IOMMU allocator to hand out reserved IOVAs.

size_t can hold up to 32 bit range in LPAE platforms. The relevant driver has to set the dma_limit max range in that case.

Quoted 26 lines

[ ... ]

Quoted 1 line
drivers/iommu/of_iommu.c +0 -0
@@ -214,10 +319,14 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)

[ ... ]

Quoted 9 lines
drivers/iommu/of_iommu.c +3 -3
-		 * The "reg" property is optional and can be omitted by reserved-memory regions
-		 * that represent reservations in the IOVA space, which are regions that should
-		 * not be mapped.
+		 * "iommu-addresses" must be used in combination with a "reg" that provides
+		 * the physical address and size of this memory region, for an identity 1:1
+		 * IOVA mapping to that physical memory.
 		 */
 		if (of_property_present(it.node, "reg")) {
 			err = of_address_to_resource(it.node, 0, &phys);

[ ... ]

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, struct list_head *list) · line 342

Quoted 9 lines
drivers/iommu/of_iommu.c +4 -4
-		}
-
-		maps = of_get_property(it.node, "iommu-addresses", &size);
-		if (!maps)
+		} else {
+			dev_err(dev, "%pOF: iommu-addresses requires a reg property\n",
+				it.node);
 			continue;
+		}

[Severity: Medium]
Will this break existing device trees?

Quoted 8 lines

This explicitly rejects the previously valid 'no reg' device tree configurations. Existing device trees that validly relied on "iommu-addresses" without a "reg" property to create IOVA reservations will now have their reservations silently ignored.

Could this lead to the IOMMU allocating IOVAs in reserved spaces, causing DMA faults?

This change is intentional and clearly mentioned in commit description. dt_schema is updated accordingly. It was discussed here:
https://lore.kernel.org/all/CAL_JsqLGOz7Fh=AsM+g84=Uko10YXU4QN1buApD3CJMkOmsebA@mail.gmail.com/

Quoted 14 lines

[ ... ]

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, struct list_head *list) · line 374

Quoted 9 lines
drivers/iommu/of_iommu.c +3 -0
@@ -258,6 +367,9 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
 				}
 				type = iommu_resv_region_get_type(dev, &phys, iova, length);
 
+				if (type != IOMMU_RESV_DIRECT)
+					continue;
+
 				region = iommu_alloc_resv_region(iova, length, prot, type,
 								 GFP_KERNEL);

[Severity: Medium]
Does this newly added check actively block pure reservations?

Quoted 3 lines

By enforcing that only identity mappings are honored, does this violate backward compatibility for device trees that used pure reservations?

If the pure reservation is carveouts region without reg, it is not allowed, which is aligned as per the discussion. This logic now handles the case where reg indicates the iova reserve range for direct mapping.

Thanks,
Vishnu Reddy

#12 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Quoted 80 lines · Vishnu Reddy
Quoted 42 lines · On 9/26/2026 12:17 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu: size_t truncation of derived reserved region length on 32-bit systems
- [Medium] iommu: DT ABI breakage by rejecting iommu-addresses without reg
- [Medium] iommu: OOB read in of_iommu_derive_resv_regions when parsing malformed iommu-ranges --

commit 08a09989ffefcbf5d38171159dcc911ca993ff18
Author: Vikash Garodia <[email protected]>

iommu: of_iommu: Add support for "iommu-ranges" on a device node

Add support for "iommu-ranges" on device nodes to specify usable IOVA ranges directly when there is no backing "reg". Introduce logic to derive reserved regions outside of "iommu-ranges" and restrict "iommu-addresses" to be paired with a "reg" property.

Quoted 4 lines
drivers/iommu/of_iommu.c +0 -0
index a18bb60f6f3df..9766a6944d0e1 100644

[ ... ]

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 228

Quoted 11 lines
drivers/iommu/of_iommu.c +11 -0
+	maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+	if (!maps)
+		return;
+
+	end = maps + size / sizeof(__be32);
+
+	while (maps < end) {
+		phys_addr_t iova, iova_end;
+		size_t length;
+
+		maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);

[Severity: Medium]
Could this result in an out-of-bounds read if the "iommu-ranges" property is malformed?

Quoted 6 lines

The loop condition checks maps < end, but of_translate_dma_region() implicitly reads na + ns cells from the maps array.

Does this loop need to ensure there are at least na + ns cells remaining before calling the translation function to prevent reading past the buffer?

This function intention is not to validate the address and size cells here and it's not valid to read those properties here. If the out of bound ranges are there, then it's part of dtc checks that dt node contains invalid ranges.

Quoted 24 lines

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 271

Quoted 4 lines
drivers/iommu/of_iommu.c +4 -0
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		if (pos->start > next) {
+			region = iommu_alloc_resv_region(next, pos->start - next, prot,
+							 IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Can the length argument overflow on 32-bit systems?

On 32-bit systems with 64-bit physical addresses (like ARM LPAE), address differences can easily exceed 4GB. Because iommu_alloc_resv_region() takes a 32-bit size_t length, passing a 64-bit gap size causes it to truncate.

Will this truncation result in a reservation of at most 4GB, leaving the IOVA address space above that unprotected?

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 287

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+	region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+					 prot, IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Similarly, can passing PHYS_ADDR_MAX - next + 1 here truncate the length to its lower 32 bits on 32-bit systems?

Quoted 7 lines
Quoted 4 lines

If the remaining address space exceeds 4GB, this truncation could leave high IOVA addresses unprotected, allowing the IOMMU allocator to hand out reserved IOVAs.

size_t can hold up to 32 bit range in LPAE platforms. The relevant driver has to set the dma_limit max range in that case.

As this is generic code, could you please adapt the code to work correctly on LPAE systems?

Signature · 2 lines
With best wishes
Dmitry
#13 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Quoted 76 lines · Dmitry Baryshkov
Quoted 75 lines · Vishnu Reddy
Quoted 41 lines · On 9/26/2026 12:17 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu: size_t truncation of derived reserved region length on 32-bit systems
- [Medium] iommu: DT ABI breakage by rejecting iommu-addresses without reg
- [Medium] iommu: OOB read in of_iommu_derive_resv_regions when parsing malformed iommu-ranges --

commit 08a09989ffefcbf5d38171159dcc911ca993ff18
Author: Vikash Garodia <[email protected]>

iommu: of_iommu: Add support for "iommu-ranges" on a device node

Add support for "iommu-ranges" on device nodes to specify usable IOVA ranges directly when there is no backing "reg". Introduce logic to derive reserved regions outside of "iommu-ranges" and restrict "iommu-addresses" to be paired with a "reg" property.

Quoted 4 lines
drivers/iommu/of_iommu.c +0 -0
index a18bb60f6f3df..9766a6944d0e1 100644

[ ... ]

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 228

Quoted 11 lines
drivers/iommu/of_iommu.c +11 -0
+	maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+	if (!maps)
+		return;
+
+	end = maps + size / sizeof(__be32);
+
+	while (maps < end) {
+		phys_addr_t iova, iova_end;
+		size_t length;
+
+		maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);

[Severity: Medium]
Could this result in an out-of-bounds read if the "iommu-ranges" property is malformed?

Quoted 6 lines

The loop condition checks maps < end, but of_translate_dma_region() implicitly reads na + ns cells from the maps array.

Does this loop need to ensure there are at least na + ns cells remaining before calling the translation function to prevent reading past the buffer?

This function intention is not to validate the address and size cells here and it's not valid to read those properties here. If the out of bound ranges are there, then it's part of dtc checks that dt node contains invalid ranges.

Quoted 22 lines

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 271

Quoted 4 lines
drivers/iommu/of_iommu.c +4 -0
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		if (pos->start > next) {
+			region = iommu_alloc_resv_region(next, pos->start - next, prot,
+							 IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Can the length argument overflow on 32-bit systems?

On 32-bit systems with 64-bit physical addresses (like ARM LPAE), address differences can easily exceed 4GB. Because iommu_alloc_resv_region() takes a 32-bit size_t length, passing a 64-bit gap size causes it to truncate.

Will this truncation result in a reservation of at most 4GB, leaving the IOVA address space above that unprotected?

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 287

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+	region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+					 prot, IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Similarly, can passing PHYS_ADDR_MAX - next + 1 here truncate the length to its lower 32 bits on 32-bit systems?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

If the remaining address space exceeds 4GB, this truncation could leave high IOVA addresses unprotected, allowing the IOMMU allocator to hand out reserved IOVAs.

size_t can hold up to 32 bit range in LPAE platforms. The relevant driver has to set the dma_limit max range in that case.

As this is generic code, could you please adapt the code to work correctly on LPAE systems?

This is no different than the existing logic where client tries to reserve greater than 32bit length on the 32bit LPAE platforms.

I'm not convinced why sashiko claims this is introduced in this patch.

Quoted 1 line
#14 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Quoted 85 lines · Vishnu Reddy
Quoted 82 lines · Dmitry Baryshkov
Quoted 81 lines · Vishnu Reddy
Quoted 41 lines · On 9/26/2026 12:17 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu: size_t truncation of derived reserved region length on 32-bit systems
- [Medium] iommu: DT ABI breakage by rejecting iommu-addresses without reg
- [Medium] iommu: OOB read in of_iommu_derive_resv_regions when parsing malformed iommu-ranges --

commit 08a09989ffefcbf5d38171159dcc911ca993ff18
Author: Vikash Garodia <[email protected]>

iommu: of_iommu: Add support for "iommu-ranges" on a device node

Add support for "iommu-ranges" on device nodes to specify usable IOVA ranges directly when there is no backing "reg". Introduce logic to derive reserved regions outside of "iommu-ranges" and restrict "iommu-addresses" to be paired with a "reg" property.

Quoted 4 lines
drivers/iommu/of_iommu.c +0 -0
index a18bb60f6f3df..9766a6944d0e1 100644

[ ... ]

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 228

Quoted 11 lines
drivers/iommu/of_iommu.c +11 -0
+  maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+  if (!maps)
+          return;
+
+  end = maps + size / sizeof(__be32);
+
+  while (maps < end) {
+          phys_addr_t iova, iova_end;
+          size_t length;
+
+          maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);

[Severity: Medium]
Could this result in an out-of-bounds read if the "iommu-ranges" property is malformed?

Quoted 6 lines

The loop condition checks maps < end, but of_translate_dma_region() implicitly reads na + ns cells from the maps array.

Does this loop need to ensure there are at least na + ns cells remaining before calling the translation function to prevent reading past the buffer?

This function intention is not to validate the address and size cells here and it's not valid to read those properties here. If the out of bound ranges are there, then it's part of dtc checks that dt node contains invalid ranges.

Quoted 18 lines

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 271

Quoted 4 lines
drivers/iommu/of_iommu.c +4 -0
+  list_for_each_entry_safe(pos, next_range, &ranges, node) {
+          if (pos->start > next) {
+                  region = iommu_alloc_resv_region(next, pos->start - next, prot,
+                                                   IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Can the length argument overflow on 32-bit systems?

On 32-bit systems with 64-bit physical addresses (like ARM LPAE), address differences can easily exceed 4GB. Because iommu_alloc_resv_region() takes a 32-bit size_t length, passing a 64-bit gap size causes it to truncate.

Will this truncation result in a reservation of at most 4GB, leaving the IOVA address space above that unprotected?

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 287

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+  region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+                                   prot, IOMMU_RESV_RESERVED, GFP_KERNEL);
Quoted 8 lines

[Severity: High]
Similarly, can passing PHYS_ADDR_MAX - next + 1 here truncate the length to its lower 32 bits on 32-bit systems?

If the remaining address space exceeds 4GB, this truncation could leave high IOVA addresses unprotected, allowing the IOMMU allocator to hand out reserved IOVAs.

size_t can hold up to 32 bit range in LPAE platforms. The relevant driver has to set the dma_limit max range in that case.

Quoted 7 lines
Quoted 2 lines

As this is generic code, could you please adapt the code to work correctly on LPAE systems?

This is no different than the existing logic where client tries to reserve greater than 32bit length on the 32bit LPAE platforms.

I'm not convinced why sashiko claims this is introduced in this patch.

Because you are adding the line.

Quoted 2 lines
Quoted 2 lines
Signature · 2 lines
With best wishes
Dmitry
#15 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Quoted 90 lines · Dmitry Baryshkov
Quoted 88 lines · Vishnu Reddy
Quoted 84 lines · Dmitry Baryshkov
Quoted 75 lines · Vishnu Reddy
Quoted 41 lines · On 9/26/2026 12:17 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu: size_t truncation of derived reserved region length on 32-bit systems
- [Medium] iommu: DT ABI breakage by rejecting iommu-addresses without reg
- [Medium] iommu: OOB read in of_iommu_derive_resv_regions when parsing malformed iommu-ranges --

commit 08a09989ffefcbf5d38171159dcc911ca993ff18
Author: Vikash Garodia <[email protected]>

iommu: of_iommu: Add support for "iommu-ranges" on a device node

Add support for "iommu-ranges" on device nodes to specify usable IOVA ranges directly when there is no backing "reg". Introduce logic to derive reserved regions outside of "iommu-ranges" and restrict "iommu-addresses" to be paired with a "reg" property.

Quoted 4 lines
drivers/iommu/of_iommu.c +0 -0
index a18bb60f6f3df..9766a6944d0e1 100644

[ ... ]

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 228

Quoted 11 lines
drivers/iommu/of_iommu.c +11 -0
+  maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+  if (!maps)
+          return;
+
+  end = maps + size / sizeof(__be32);
+
+  while (maps < end) {
+          phys_addr_t iova, iova_end;
+          size_t length;
+
+          maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);

[Severity: Medium]
Could this result in an out-of-bounds read if the "iommu-ranges" property is malformed?

Quoted 6 lines

The loop condition checks maps < end, but of_translate_dma_region() implicitly reads na + ns cells from the maps array.

Does this loop need to ensure there are at least na + ns cells remaining before calling the translation function to prevent reading past the buffer?

This function intention is not to validate the address and size cells here and it's not valid to read those properties here. If the out of bound ranges are there, then it's part of dtc checks that dt node contains invalid ranges.

Quoted 22 lines

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 271

Quoted 4 lines
drivers/iommu/of_iommu.c +4 -0
+  list_for_each_entry_safe(pos, next_range, &ranges, node) {
+          if (pos->start > next) {
+                  region = iommu_alloc_resv_region(next, pos->start - next, prot,
+                                                   IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Can the length argument overflow on 32-bit systems?

On 32-bit systems with 64-bit physical addresses (like ARM LPAE), address differences can easily exceed 4GB. Because iommu_alloc_resv_region() takes a 32-bit size_t length, passing a 64-bit gap size causes it to truncate.

Will this truncation result in a reservation of at most 4GB, leaving the IOVA address space above that unprotected?

[ ... ]

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 287

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+  region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+                                   prot, IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Similarly, can passing PHYS_ADDR_MAX - next + 1 here truncate the length to its lower 32 bits on 32-bit systems?

Quoted 6 lines
Quoted 4 lines

If the remaining address space exceeds 4GB, this truncation could leave high IOVA addresses unprotected, allowing the IOMMU allocator to hand out reserved IOVAs.

size_t can hold up to 32 bit range in LPAE platforms. The relevant driver has to set the dma_limit max range in that case.

As this is generic code, could you please adapt the code to work correctly on LPAE systems?

Quoted 6 lines
Quoted 4 lines

This is no different than the existing logic where client tries to reserve greater than 32bit length on the 32bit LPAE platforms.

I'm not convinced why sashiko claims this is introduced in this patch.

Because you are adding the line.

So, is there anything to be addressed? If there is an issue in the current code, please fix it too instead of just pointing to it.

Signature · 2 lines
With best wishes
Dmitry
author maintainer
#16 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Quoted 94 lines · Dmitry Baryshkov
Quoted 93 lines · Dmitry Baryshkov
Quoted 91 lines · Vishnu Reddy
Quoted 76 lines · Dmitry Baryshkov
Quoted 75 lines · Vishnu Reddy
Quoted 41 lines · On 9/26/2026 12:17 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu: size_t truncation of derived reserved region length on 32-bit systems
- [Medium] iommu: DT ABI breakage by rejecting iommu-addresses without reg
- [Medium] iommu: OOB read in of_iommu_derive_resv_regions when parsing malformed iommu-ranges --

commit 08a09989ffefcbf5d38171159dcc911ca993ff18
Author: Vikash Garodia <[email protected]>

iommu: of_iommu: Add support for "iommu-ranges" on a device node

Add support for "iommu-ranges" on device nodes to specify usable IOVA ranges directly when there is no backing "reg". Introduce logic to derive reserved regions outside of "iommu-ranges" and restrict "iommu-addresses" to be paired with a "reg" property.

Quoted 4 lines
drivers/iommu/of_iommu.c +0 -0
index a18bb60f6f3df..9766a6944d0e1 100644

[ ... ]

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{

[ ... ]

drivers/iommu/of_iommu.c

Quoted 11 lines
drivers/iommu/of_iommu.c +11 -0
+  maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+  if (!maps)
+          return;
+
+  end = maps + size / sizeof(__be32);
+
+  while (maps < end) {
+          phys_addr_t iova, iova_end;
+          size_t length;
+
+          maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);

[Severity: Medium]
Could this result in an out-of-bounds read if the "iommu-ranges" property is malformed?

Quoted 6 lines

The loop condition checks maps < end, but of_translate_dma_region() implicitly reads na + ns cells from the maps array.

Does this loop need to ensure there are at least na + ns cells remaining before calling the translation function to prevent reading past the buffer?

This function intention is not to validate the address and size cells here and it's not valid to read those properties here. If the out of bound ranges are there, then it's part of dtc checks that dt node contains invalid ranges.

Quoted 22 lines

[ ... ]

drivers/iommu/of_iommu.c

Quoted 4 lines
drivers/iommu/of_iommu.c +4 -0
+  list_for_each_entry_safe(pos, next_range, &ranges, node) {
+          if (pos->start > next) {
+                  region = iommu_alloc_resv_region(next, pos->start - next, prot,
+                                                   IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Can the length argument overflow on 32-bit systems?

On 32-bit systems with 64-bit physical addresses (like ARM LPAE), address differences can easily exceed 4GB. Because iommu_alloc_resv_region() takes a 32-bit size_t length, passing a 64-bit gap size causes it to truncate.

Will this truncation result in a reservation of at most 4GB, leaving the IOVA address space above that unprotected?

[ ... ]

drivers/iommu/of_iommu.c

Quoted 2 lines
drivers/iommu/of_iommu.c +2 -0
+  region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+                                   prot, IOMMU_RESV_RESERVED, GFP_KERNEL);

[Severity: High]
Similarly, can passing PHYS_ADDR_MAX - next + 1 here truncate the length to its lower 32 bits on 32-bit systems?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

If the remaining address space exceeds 4GB, this truncation could leave high IOVA addresses unprotected, allowing the IOMMU allocator to hand out reserved IOVAs.

size_t can hold up to 32 bit range in LPAE platforms. The relevant driver has to set the dma_limit max range in that case.

As this is generic code, could you please adapt the code to work correctly on LPAE systems?

This is no different than the existing logic where client tries to reserve greater than 32bit length on the 32bit LPAE platforms.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I'm not convinced why sashiko claims this is introduced in this patch.

Because you are adding the line.

So, is there anything to be addressed? If there is an issue in the current code, please fix it too instead of just pointing to it.

Yes, its an issue with the existing api "iommu_alloc_resv_region", so moving it, does not make it a new issue. Nevertheless, i plan to fix it.

I was looking for review comments from maintainer of this module, it would have been nice to get their comment/suggestion to move forward in this patch.

Regards,
Vikash

#17 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

In reply to Vikash Garodia
Quoted 16 lines · Vikash Garodia

Reserving an IOVA address using "iommu-addresses" requires it to be placed in the reserved-memory node. But when "iommu-addresses" is the only property being described and there is no backing "reg" (i.e. no actual reserved system memory), it does not really belong under /reserved-memory. A device IOVA range is specific to its own address space, and does not describe the system physical memory to make it qualify under reserved-memory. Given this, place "iommu-addresses" inside reserved-memory only when it is paired with a "reg", otherwise, define it within the device own node. It was discussed here:
https://lore.kernel.org/all/[email protected]

Existing "iommu-addresses" property expects a phandle, which does not make sense when the property is defined within the device node. Introduce a new property, "iommu-ranges", to specify the device specific IOVA ranges when there is no backing "reg".

Quoted 4 lines

I think we need to get buy-in from the IOMMU people on this change before we commit to bindings that may be affected by a rejection.

i.e. There's no point in absorbing potentially DOA bindings.
---
bod

author maintainer
#18 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

In reply to Vikash Garodia

Hello Joerg , Will, Murphy,

Quoted 16 lines · Vikash Garodia

Reserving an IOVA address using "iommu-addresses" requires it to be placed in the reserved-memory node. But when "iommu-addresses" is the only property being described and there is no backing "reg" (i.e. no actual reserved system memory), it does not really belong under /reserved-memory. A device IOVA range is specific to its own address space, and does not describe the system physical memory to make it qualify under reserved-memory. Given this, place "iommu-addresses" inside reserved-memory only when it is paired with a "reg", otherwise, define it within the device own node. It was discussed here:
https://lore.kernel.org/all/[email protected]

Existing "iommu-addresses" property expects a phandle, which does not make sense when the property is defined within the device node. Introduce a new property, "iommu-ranges", to specify the device specific IOVA ranges when there is no backing "reg".

Quoted 7 lines
---
  drivers/iommu/of_iommu.c | 128 ++++++++++++++++++++++++++++++++++++++++++++---
  1 file changed, 121 insertions(+), 7 deletions(-)

Do you see this patch getting into 7.4 ? Or, you have any other comments on this patch ?

If you are ok with this patch, maybe it would be a good idea to have the series applied by media maintainer.

Regards,
Vikash

Reviewed-by on v5 4/13
#19 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

In reply to Vikash Garodia
Quoted 24 lines · Vikash Garodia

Reserving an IOVA address using "iommu-addresses" requires it to be placed in the reserved-memory node. But when "iommu-addresses" is the only property being described and there is no backing "reg" (i.e. no actual reserved system memory), it does not really belong under /reserved-memory. A device IOVA range is specific to its own address space, and does not describe the system physical memory to make it qualify under reserved-memory. Given this, place "iommu-addresses" inside reserved-memory only when it is paired with a "reg", otherwise, define it within the device own node. It was discussed here:
https://lore.kernel.org/all/[email protected]

Existing "iommu-addresses" property expects a phandle, which does not make sense when the property is defined within the device node. Introduce a new property, "iommu-ranges", to specify the device specific IOVA ranges when there is no backing "reg".

---
 drivers/iommu/of_iommu.c | 128 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 121 insertions(+), 7 deletions(-)

drivers/iommu/of_iommu.c iommu_resv_region_get_type(struct device *dev, · line 270

Quoted 4 lines
drivers/iommu/of_iommu.c +4 -0
+
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		if (pos->start > next) {
+			region = iommu_alloc_resv_region(next, pos->start - next, prot,

As pointed out by Sashiko, this can overflow on 32-bit LPAE platforms.

Other than that:

As a note, we'd need this patch for the upcoming Qualcomm DCP display driver (posted a week ago).

Signature · 2 lines
With best wishes
Dmitry
#20 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

In reply to Vikash Garodia
Quoted 161 lines · Vikash Garodia

Reserving an IOVA address using "iommu-addresses" requires it to be placed in the reserved-memory node. But when "iommu-addresses" is the only property being described and there is no backing "reg" (i.e. no actual reserved system memory), it does not really belong under /reserved-memory. A device IOVA range is specific to its own address space, and does not describe the system physical memory to make it qualify under reserved-memory. Given this, place "iommu-addresses" inside reserved-memory only when it is paired with a "reg", otherwise, define it within the device own node. It was discussed here:
https://lore.kernel.org/all/[email protected]

Existing "iommu-addresses" property expects a phandle, which does not make sense when the property is defined within the device node. Introduce a new property, "iommu-ranges", to specify the device specific IOVA ranges when there is no backing "reg".

---
  drivers/iommu/of_iommu.c | 128 ++++++++++++++++++++++++++++++++++++++++++++---
  1 file changed, 121 insertions(+), 7 deletions(-)
drivers/iommu/of_iommu.c +112 -3
index a18bb60f6f3dfdba853b6e16dd2a8616f6a731c7..9766a6944d0e11a6cd8b74b1b89428acffe3dfdf 100644
@@ -190,6 +190,111 @@ iommu_resv_region_get_type(struct device *dev,
  	return IOMMU_RESV_RESERVED;
  }
 
+/**
+ * of_iommu_derive_resv_regions - derive reserved regions which
+ *                                are outside of iommu-ranges
+ * @dev: device for which to get reserved regions
+ * @list: reserved region list
+ *
+ * A device can describe its own usable IOVA ranges directly on its node
+ * via "iommu-ranges". Everything not under those ranges is derived
+ * as a reserved region so the IOMMU allocator won't use it. Entries may
+ * appear in any order in the property.
+ */
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{
+	struct of_iommu_range {
+		struct list_head node;
+		phys_addr_t start;
+		phys_addr_t end;
+	} *pos, *new, *next_range;
+	int size, prot = IOMMU_READ | IOMMU_WRITE;
+	struct iommu_resv_region *region;
+	const __be32 *maps, *end;
+	struct list_head *prev;
+	phys_addr_t next = 0;
+	LIST_HEAD(ranges);
+
+	maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+	if (!maps)
+		return;
+
+	end = maps + size / sizeof(__be32);
+
+	while (maps < end) {
+		phys_addr_t iova, iova_end;
+		size_t length;
+
+		maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);
+		if (!maps) {
+			dev_err(dev, "%pOF: failed to parse iommu-ranges\n",
+				dev->of_node);
+			break;
+		}
+
+		if (!length)
+			continue;
+
+		iova_end = iova + length - 1;
+
+		if (iova_end < iova) {
+			dev_err(dev, "%pOF: iommu-ranges overflows address space\n",
+				dev->of_node);
+			continue;
+		}
+
+		prev = &ranges;
+		list_for_each_entry(pos, &ranges, node) {
+			if (pos->start > iova)
+				break;
+			prev = &pos->node;
+		}
+
+		new = kmalloc_obj(*new);
+		if (!new)
+			continue;
+
+		new->start = iova;
+		new->end = iova_end;
+		list_add(&new->node, prev);
+	}
+
+	if (list_empty(&ranges))
+		return;
+
+	if (of_dma_is_coherent(dev->of_node))
+		prot |= IOMMU_CACHE;
+
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		if (pos->start > next) {
+			region = iommu_alloc_resv_region(next, pos->start - next, prot,
+							 IOMMU_RESV_RESERVED, GFP_KERNEL);
+			if (region)
+				list_add_tail(&region->list, list);
+		}
+
+		if (pos->end == PHYS_ADDR_MAX)
+			goto exit;
+
+		if (pos->end >= next)
+			next = pos->end + 1;
+
+		list_del(&pos->node);
+		kfree(pos);
+	}
+
+	region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+					 prot, IOMMU_RESV_RESERVED, GFP_KERNEL);
+	if (region)
+		list_add_tail(&region->list, list);
+
+exit:
+	list_for_each_entry_safe(pos, next_range, &ranges, node) {
+		list_del(&pos->node);
+		kfree(pos);
+	}
+}
+
  /**
   * of_iommu_get_resv_regions - reserved region driver helper for device tree
   * @dev: device for which to get reserved regions
@@ -214,10 +319,14 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
 
  		memset(&phys, 0, sizeof(phys));
 
+		maps = of_get_property(it.node, "iommu-addresses", &size);
+		if (!maps)
+			continue;
+
  		/*
-		 * The "reg" property is optional and can be omitted by reserved-memory regions
-		 * that represent reservations in the IOVA space, which are regions that should
-		 * not be mapped.
+		 * "iommu-addresses" must be used in combination with a "reg" that provides
+		 * the physical address and size of this memory region, for an identity 1:1
+		 * IOVA mapping to that physical memory.
  		 */
  		if (of_property_present(it.node, "reg")) {
  			err = of_address_to_resource(it.node, 0, &phys);
@@ -226,11 +335,11 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
  					it.node, err);
  				continue;

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, struct list_head *list) · line 342

Quoted 10 lines
drivers/iommu/of_iommu.c +4 -4
  			}
-		}
-
-		maps = of_get_property(it.node, "iommu-addresses", &size);
-		if (!maps)
+		} else {
+			dev_err(dev, "%pOF: iommu-addresses requires a reg property\n",
+				it.node);
  			continue;
+		}

The if/else doesn't belong in a path entitled 'Add support for "iommu-ranges"' as this changes he behaviour of iommu-addresses independently of whatever iommu-ranges does.

The reg update part basically has nothing to do with this series at all i.e. the code you depend on later in this series doesn't declare iommu-addresses so... this is an update to align with a DT schema change.

https://github.com/devicetree-org/dt-schema/pull/207

Perhaps splitting this into two patches as an iommu-series would be best.

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, struct list_head *list) · line 372

Quoted 10 lines
drivers/iommu/of_iommu.c +3 -0
  		end = maps + size / sizeof(__be32);
 
@@ -258,6 +367,9 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
  				}
  				type = iommu_resv_region_get_type(dev, &phys, iova, length);
 
+				if (type != IOMMU_RESV_DIRECT)
+					continue;
+

If you look in iommu_resv_region_get_type() you can emit

        dev_warn(dev, "treating non-direct mapping [%pr] -> [%pap-%pap] 
as reservation\n", phys,
                 &start, &end);
        return IOMMU_RESV_RESERVED;

on a mismatch - which is not what the code will do now. Mismatch will warn and then not map.

So maybe dev_err() saying you won't map - in the new patch for reg. Either way this isn't a change specific to iommu-ranges.

Quoted 13 lines
drivers/iommu/of_iommu.c +2 -0
  				region = iommu_alloc_resv_region(iova, length, prot, type,
  								 GFP_KERNEL);
  				if (region)
@@ -265,6 +377,8 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
  			}
  		}
  	}
+
+	of_iommu_derive_resv_regions(dev, list);
  #endif
  }
  EXPORT_SYMBOL(of_iommu_get_resv_regions);
author maintainer
#21 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Quoted 183 lines · Bryan O'Donoghue
Quoted 169 lines · Vikash Garodia

Reserving an IOVA address using "iommu-addresses" requires it to be placed in the reserved-memory node. But when "iommu-addresses" is the only property being described and there is no backing "reg" (i.e. no actual reserved system memory), it does not really belong under /reserved-memory. A device IOVA range is specific to its own address space, and does not describe the system physical memory to make it qualify under reserved-memory. Given this, place "iommu-addresses" inside reserved-memory only when it is paired with a "reg", otherwise, define it within the device own node. It was discussed here:
https://lore.kernel.org/all/662f7093- [email protected]

Existing "iommu-addresses" property expects a phandle, which does not make sense when the property is defined within the device node. Introduce a new property, "iommu-ranges", to specify the device specific IOVA ranges when there is no backing "reg".

---
  drivers/iommu/of_iommu.c | 128 +++++++++++++++++++++++++++++++++++++
+++++++---

  1 file changed, 121 insertions(+), 7 deletions(-)
drivers/iommu/of_iommu.c +105 -0
index a18bb60f6f3dfdba853b6e16dd2a8616f6a731c7..9766a6944d0e11a6cd8b74b1b89428acffe3dfdf 100644
@@ -190,6 +190,111 @@ iommu_resv_region_get_type(struct device *dev,
       return IOMMU_RESV_RESERVED;
   }
+/**
+ * of_iommu_derive_resv_regions - derive reserved regions which
+ *                                are outside of iommu-ranges
+ * @dev: device for which to get reserved regions
+ * @list: reserved region list
+ *
+ * A device can describe its own usable IOVA ranges directly on its node
+ * via "iommu-ranges". Everything not under those ranges is derived
+ * as a reserved region so the IOMMU allocator won't use it. Entries may
+ * appear in any order in the property.
+ */
+static void of_iommu_derive_resv_regions(struct device *dev, struct 
 list_head *list)
+{
+    struct of_iommu_range {
+        struct list_head node;
+        phys_addr_t start;
+        phys_addr_t end;
+    } *pos, *new, *next_range;
+    int size, prot = IOMMU_READ | IOMMU_WRITE;
+    struct iommu_resv_region *region;
+    const __be32 *maps, *end;
+    struct list_head *prev;
+    phys_addr_t next = 0;
+    LIST_HEAD(ranges);
+
+    maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+    if (!maps)
+        return;
+
+    end = maps + size / sizeof(__be32);
+
+    while (maps < end) {
+        phys_addr_t iova, iova_end;
+        size_t length;
+
+        maps = of_translate_dma_region(dev->of_node, maps, &iova, 
 &length);
+        if (!maps) {
+            dev_err(dev, "%pOF: failed to parse iommu-ranges\n",
+                dev->of_node);
+            break;
+        }
+
+        if (!length)
+            continue;
+
+        iova_end = iova + length - 1;
+
+        if (iova_end < iova) {
+            dev_err(dev, "%pOF: iommu-ranges overflows address space\n",
+                dev->of_node);
+            continue;
+        }
+
+        prev = &ranges;
+        list_for_each_entry(pos, &ranges, node) {
+            if (pos->start > iova)
+                break;
+            prev = &pos->node;
+        }
+
+        new = kmalloc_obj(*new);
+        if (!new)
+            continue;
+
+        new->start = iova;
+        new->end = iova_end;
+        list_add(&new->node, prev);
+    }
+
+    if (list_empty(&ranges))
+        return;
+
+    if (of_dma_is_coherent(dev->of_node))
+        prot |= IOMMU_CACHE;
+
+    list_for_each_entry_safe(pos, next_range, &ranges, node) {
+        if (pos->start > next) {
+            region = iommu_alloc_resv_region(next, pos->start - next, 
 prot,
+                             IOMMU_RESV_RESERVED, GFP_KERNEL);
+            if (region)
+                list_add_tail(&region->list, list);
+        }
+
+        if (pos->end == PHYS_ADDR_MAX)
+            goto exit;
+
+        if (pos->end >= next)
+            next = pos->end + 1;
+
+        list_del(&pos->node);
+        kfree(pos);
+    }
+
+    region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
+                     prot, IOMMU_RESV_RESERVED, GFP_KERNEL);
+    if (region)
+        list_add_tail(&region->list, list);
+
+exit:
+    list_for_each_entry_safe(pos, next_range, &ranges, node) {
+        list_del(&pos->node);
+        kfree(pos);
+    }
+}
+
   /**

   * of_iommu_get_resv_regions - reserved region driver helper for device tree
   * @dev: device for which to get reserved regions

drivers/iommu/of_iommu.c +4 -1
@@ -214,10 +319,14 @@ void of_iommu_get_resv_regions(struct device 
 *dev, struct list_head *list)
           memset(&phys, 0, sizeof(phys));
+        maps = of_get_property(it.node, "iommu-addresses", &size);
+        if (!maps)
+            continue;
+
           /*
-         * The "reg" property is optional and can be omitted by 

reserved-memory regions
-         * that represent reservations in the IOVA space, which are regions that should
-         * not be mapped.
+         * "iommu-addresses" must be used in combination with a "reg" that provides
+         * the physical address and size of this memory region, for an identity 1:1
+         * IOVA mapping to that physical memory.
           */
          if (of_property_present(it.node, "reg")) {
              err = of_address_to_resource(it.node, 0, &phys);

drivers/iommu/of_iommu.c +0 -0
@@ -226,11 +335,11 @@ void of_iommu_get_resv_regions(struct device 
 *dev, struct list_head *list)
                       it.node, err);
                   continue;
               }

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device · line 344

Quoted 10 lines
drivers/iommu/of_iommu.c +4 -4
-        }
-
-        maps = of_get_property(it.node, "iommu-addresses", &size);
-        if (!maps)
+        } else {
+            dev_err(dev, "%pOF: iommu-addresses requires a reg 
 property\n",
+                it.node);
               continue;
+        }

The if/else doesn't belong in a path entitled 'Add support for "iommu- ranges"' as this changes he behaviour of iommu-addresses independently of whatever iommu-ranges does.

Quoted 5 lines

The reg update part basically has nothing to do with this series at all i.e. the code you depend on later in this series doesn't declare iommu- addresses so... this is an update to align with a DT schema change.

https://github.com/devicetree-org/dt-schema/pull/207

Perhaps splitting this into two patches as an iommu-series would be best.

Intention was to keep the patch to add iommu-ranges property as part of iris driver patches to show the usage of this new property.

I am fine either ways, whatever it takes for the maintainers of this file to review.

Regards,
Vikash

Quoted 35 lines

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, · line 372

Quoted 8 lines
drivers/iommu/of_iommu.c +3 -0
           end = maps + size / sizeof(__be32);
@@ -258,6 +367,9 @@ void of_iommu_get_resv_regions(struct device *dev, 
 struct list_head *list)
                   }
                   type = iommu_resv_region_get_type(dev, &phys, iova, length);
+                if (type != IOMMU_RESV_DIRECT)
+                    continue;
+

If you look in iommu_resv_region_get_type() you can emit

        dev_warn(dev, "treating non-direct mapping [%pr] -> [%pap-%pap]
as reservation\n", phys,
                 &start, &end);
        return IOMMU_RESV_RESERVED;

on a mismatch - which is not what the code will do now. Mismatch will warn and then not map.

So maybe dev_err() saying you won't map - in the new patch for reg. Either way this isn't a change specific to iommu-ranges.

Quoted 14 lines
drivers/iommu/of_iommu.c +2 -0
                   region = iommu_alloc_resv_region(iova, length, prot, type,
                                    GFP_KERNEL);
                   if (region)
@@ -265,6 +377,8 @@ void of_iommu_get_resv_regions(struct device *dev, 
 struct list_head *list)
               }
           }
       }
+
+    of_iommu_derive_resv_regions(dev, list);
   #endif
   }

  EXPORT_SYMBOL(of_iommu_get_resv_regions);

maintainer
#22 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

Quoted 33 lines · Vikash Garodia
Quoted 3 lines

https://github.com/devicetree-org/dt-schema/pull/207

Perhaps splitting this into two patches as an iommu-series would be best.

Intention was to keep the patch to add iommu-ranges property as part of iris driver patches to show the usage of this new property.

I am fine either ways, whatever it takes for the maintainers of this file to review.

Regards,
Vikash

Quoted 21 lines

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, · line 373

Quoted 9 lines

          end = maps + size / sizeof(__be32);

drivers/iommu/of_iommu.c +3 -0
@@ -258,6 +367,9 @@ void of_iommu_get_resv_regions(struct device *dev,
 struct list_head *list)
                   }
                   type = iommu_resv_region_get_type(dev, &phys, iova,
 length);
+                if (type != IOMMU_RESV_DIRECT)
+                    continue;
+

If you look in iommu_resv_region_get_type() you can emit

        dev_warn(dev, "treating non-direct mapping [%pr] -> [%pap-%pap]
as reservation\n", phys,
                 &start, &end);
        return IOMMU_RESV_RESERVED;

on a mismatch - which is not what the code will do now. Mismatch will warn and then not map.

So maybe dev_err() saying you won't map - in the new patch for reg. Either way this isn't a change specific to iommu-ranges.

Sure the above needs to be addressed though because its not a straight change.

Before if there was a mismatch it would sill be mapped - now we print a warning and _don't_ map.

I'm not sure that's really what you meant to do here but if it is it should be stated in the git log and IMO it should be a follow on change _after_ the initial addition (or before it) stating why mismatched will no longer be mapped.

Because add iommu-ranges != don't map mismatched, basically.

---
bod

#23 lore raw

Re: [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node

In reply to Vikash Garodia
Quoted 48 lines · Bryan O'Donoghue
Quoted 4 lines · Vikash Garodia
Quoted 4 lines

https://github.com/devicetree-org/dt-schema/pull/207

Perhaps splitting this into two patches as an iommu-series would be best.

Quoted 31 lines

Intention was to keep the patch to add iommu-ranges property as part of iris driver patches to show the usage of this new property.

I am fine either ways, whatever it takes for the maintainers of this file to review.

Regards,
Vikash

Quoted 22 lines

drivers/iommu/of_iommu.c void of_iommu_get_resv_regions(struct device *dev, · line 373

Quoted 9 lines

           end = maps + size / sizeof(__be32);

drivers/iommu/of_iommu.c +3 -0
@@ -258,6 +367,9 @@ void of_iommu_get_resv_regions(struct device *dev,
 struct list_head *list)
                    }
                    type = iommu_resv_region_get_type(dev, &phys, iova,
 length);
+                if (type != IOMMU_RESV_DIRECT)
+                    continue;
+

If you look in iommu_resv_region_get_type() you can emit

          dev_warn(dev, "treating non-direct mapping [%pr] -> [%pap- %pap]
as reservation\n", phys,
                   &start, &end);
          return IOMMU_RESV_RESERVED;

on a mismatch - which is not what the code will do now. Mismatch will warn and then not map.

So maybe dev_err() saying you won't map - in the new patch for reg. Either way this isn't a change specific to iommu-ranges.

Sure the above needs to be addressed though because its not a straight change.

Before if there was a mismatch it would sill be mapped - now we print a warning and _don't_ map.

I'm not sure that's really what you meant to do here but if it is it should be stated in the git log and IMO it should be a follow on change _after_ the initial addition (or before it) stating why mismatched will no longer be mapped.

Quoted 4 lines

Because add iommu-ranges != don't map mismatched, basically.

---
bod

sic - "before it was reserved, now we will print a warning stating something we don't do and won't reserve it"

---
bod

author maintainer
#24 lore raw

PATCH v5 5/13 media: iris: Add non-pixel and pixel context bank devices

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Now the device tree describes "non-pixel" and "pixel" as separate context bank subnodes, each carrying its own "iommus" stream IDs.

Add helper functions to create and clean up devices from these DT subnodes, and call them from iris_probe() and iris_remove(). This applies to the common probe path as it is required for all platforms.

Set the context banks before v4l2_device_register() so the DMA plumbing is in place before any video device is visible to userspace, and tear them down on the probe error path and in iris_remove().

---
 drivers/media/platform/qcom/iris/iris_core.h  |  4 ++
 drivers/media/platform/qcom/iris/iris_probe.c | 71 ++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/iris/iris_core.h +4 -0
index 24da60448cf24820af7947b85eb7208555ab7786..3c96f46cf567b2802148b2a7cedb8488b6b9468b 100644
@@ -36,6 +36,8 @@ struct qcom_ubwc_cfg_data;
  * struct iris_core - holds core parameters valid for all instances
  *
  * @dev: reference to device structure
+ * @np_dev: reference to non-pixel device structure
+ * @p_dev: reference to pixel device structure
  * @reg_base: IO memory base address
  * @irq: iris irq
  * @v4l2_dev: a holder for v4l2 device structure
@@ -81,6 +83,8 @@ struct qcom_ubwc_cfg_data;
 
 struct iris_core {
 	struct device				*dev;
+	struct device				*np_dev;
+	struct device				*p_dev;
 	void __iomem				*reg_base;
 	int					irq;
 	struct v4l2_device			v4l2_dev;
drivers/media/platform/qcom/iris/iris_probe.c +70 -1

98 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#25 lore raw

PATCH v5 6/13 media: iris: Route buffers to the matching context bank device

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range.
Add iris_get_cb_dev(), which maps a buffer type to the owning context bank device. Bitstream and internal buffers (BIN, ARP, COMV, LINE, NON_COMV, PERSIST) belong to the non-pixel device, and uncompressed buffers (DPB, PARTIAL, SCRATCH_1, SCRATCH_2, VPSS) to the pixel device. BUF_INPUT and BUF_OUTPUT depend on direction and are resolved from inst->domain: for a decoder the input is non-pixel and the output pixel, and the other way round for an encoder.
Fall back to core->dev whenever the relevant context bank device is absent, so platforms still describing "iommus" on the parent iris node behave exactly as before to maintain backward compatibility.

---
 drivers/media/platform/qcom/iris/iris_buffer.c    |  8 ++---
 drivers/media/platform/qcom/iris/iris_hfi_queue.c | 16 +++++----
 drivers/media/platform/qcom/iris/iris_resources.c | 41 +++++++++++++++++++++++
 drivers/media/platform/qcom/iris/iris_resources.h |  1 +
 drivers/media/platform/qcom/iris/iris_vidc.c      |  4 +--
 5 files changed, 57 insertions(+), 13 deletions(-)
drivers/media/platform/qcom/iris/iris_buffer.c +4 -4
index eb8de60c1177f5e1ab83b90a3c8c80e0b4d1f02e..6e03d13ac1a792c539bf8fe6d26354aa29d7b3a2 100644
@@ -531,7 +531,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
 				       enum iris_buffer_type buffer_type, u32 index)
 {
 	struct iris_buffers *buffers = &inst->buffers[buffer_type];
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer_type);
 	struct iris_buffer *buffer;
 
 	if (!buffers->size)
@@ -547,7 +547,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
 	buffer->buffer_size = buffers->size;
 	buffer->dma_attrs = DMA_ATTR_WRITE_COMBINE | DMA_ATTR_NO_KERNEL_MAPPING;
 
-	buffer->kvaddr = dma_alloc_attrs(core->dev, buffer->buffer_size,
+	buffer->kvaddr = dma_alloc_attrs(dev, buffer->buffer_size,
 					 &buffer->device_addr, GFP_KERNEL, buffer->dma_attrs);
 	if (!buffer->kvaddr) {
 		kfree(buffer);
@@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
 
 void iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
 {
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer->type);
 
 	list_del(&buffer->list);
-	dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
+	dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,
 		       buffer->device_addr, buffer->dma_attrs);
 	kfree(buffer);
 }
drivers/media/platform/qcom/iris/iris_hfi_queue.c +9 -7
index bf6db23b53e2106c08f2139b643f8626af8bc40a..ce6a682b0f9ada79f9fae26289db298855d777c2 100644
@@ -245,25 +245,26 @@ static void iris_hfi_queue_deinit(struct iris_iface_q_info *iface_q)
 
 int iris_hfi_queues_init(struct iris_core *core)
 {
+	struct device *dev = core->np_dev ? core->np_dev : core->dev;
 	struct iris_hfi_queue_table_header *q_tbl_hdr;
 	u32 queue_size;
 
 	/* Iris hardware requires 4K queue alignment */
 	queue_size = ALIGN((sizeof(*q_tbl_hdr) + (IFACEQ_QUEUE_SIZE * IFACEQ_NUMQ)), SZ_4K);
-	core->iface_q_table_vaddr = dma_alloc_attrs(core->dev, queue_size,
+	core->iface_q_table_vaddr = dma_alloc_attrs(dev, queue_size,
 						    &core->iface_q_table_daddr,
 						    GFP_KERNEL, DMA_ATTR_WRITE_COMBINE);
 	if (!core->iface_q_table_vaddr) {
-		dev_err(core->dev, "queues alloc and map failed\n");
+		dev_err(dev, "queues alloc and map failed\n");
 		return -ENOMEM;
 	}
 
-	core->sfr_vaddr = dma_alloc_attrs(core->dev, SFR_SIZE,
+	core->sfr_vaddr = dma_alloc_attrs(dev, SFR_SIZE,
 					  &core->sfr_daddr,
 					  GFP_KERNEL, DMA_ATTR_WRITE_COMBINE);
 	if (!core->sfr_vaddr) {
-		dev_err(core->dev, "sfr alloc and map failed\n");
-		dma_free_attrs(core->dev, queue_size, core->iface_q_table_vaddr,
+		dev_err(dev, "sfr alloc and map failed\n");
+		dma_free_attrs(dev, queue_size, core->iface_q_table_vaddr,
 			       core->iface_q_table_daddr, DMA_ATTR_WRITE_COMBINE);
 		return -ENOMEM;
 	}
@@ -291,6 +292,7 @@ int iris_hfi_queues_init(struct iris_core *core)
 
 void iris_hfi_queues_deinit(struct iris_core *core)
 {
+	struct device *dev = core->np_dev ? core->np_dev : core->dev;
 	u32 queue_size;
 
 	if (!core->iface_q_table_vaddr)
@@ -300,7 +302,7 @@ void iris_hfi_queues_deinit(struct iris_core *core)
 	iris_hfi_queue_deinit(&core->message_queue);
 	iris_hfi_queue_deinit(&core->command_queue);
 
-	dma_free_attrs(core->dev, SFR_SIZE, core->sfr_vaddr,
+	dma_free_attrs(dev, SFR_SIZE, core->sfr_vaddr,
 		       core->sfr_daddr, DMA_ATTR_WRITE_COMBINE);
 
 	core->sfr_vaddr = NULL;
@@ -309,7 +311,7 @@ void iris_hfi_queues_deinit(struct iris_core *core)
 	queue_size = ALIGN(sizeof(struct iris_hfi_queue_table_header) +
 		(IFACEQ_QUEUE_SIZE * IFACEQ_NUMQ), SZ_4K);
 
-	dma_free_attrs(core->dev, queue_size, core->iface_q_table_vaddr,
+	dma_free_attrs(dev, queue_size, core->iface_q_table_vaddr,
 		       core->iface_q_table_daddr, DMA_ATTR_WRITE_COMBINE);
 
 	core->iface_q_table_vaddr = NULL;
drivers/media/platform/qcom/iris/iris_resources.c +41 -0

50 lines not on this page · raw message

drivers/media/platform/qcom/iris/iris_resources.h +1 -0
index 6bfbd2dc6db095ec05e53c894e048285f82446c6..a9a5bddb19c24917de4c5dba52567934b77e5c59 100644
@@ -15,5 +15,6 @@ int iris_unset_icc_bw(struct iris_core *core);
 int iris_set_icc_bw(struct iris_core *core, unsigned long icc_bw);
 int iris_disable_unprepare_clock(struct iris_core *core, enum platform_clk_type clk_type);
 int iris_prepare_enable_clock(struct iris_core *core, enum platform_clk_type clk_type);
+struct device *iris_get_cb_dev(struct iris_inst *inst, enum iris_buffer_type buffer_type);
 
 #endif
drivers/media/platform/qcom/iris/iris_vidc.c +2 -2
index fcbc60016beec693f2ce27927a09a2d51494bc38..064cf0a80748dab1be0515c4c2b6688aeb2b7022 100644
@@ -108,7 +108,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
 	src_vq->drv_priv = inst;
 	src_vq->buf_struct_size = sizeof(struct iris_buffer);
 	src_vq->min_reqbufs_allocation = MIN_BUFFERS;
-	src_vq->dev = inst->core->dev;
+	src_vq->dev = iris_get_cb_dev(inst, BUF_INPUT);
 	src_vq->lock = &inst->ctx_q_lock;
 	ret = vb2_queue_init(src_vq);
 	if (ret)
@@ -122,7 +122,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
 	dst_vq->drv_priv = inst;
 	dst_vq->buf_struct_size = sizeof(struct iris_buffer);
 	dst_vq->min_reqbufs_allocation = MIN_BUFFERS;
-	dst_vq->dev = inst->core->dev;
+	dst_vq->dev = iris_get_cb_dev(inst, BUF_OUTPUT);
 	dst_vq->lock = &inst->ctx_q_lock;
 
 	return vb2_queue_init(dst_vq);
Signature · 1 line
2.34.1
#26 lore raw

Re: [PATCH v5 06/13] media: iris: Route buffers to the matching context bank device

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] media: use-after-free of context bank devices during deferred V4L2 cleanup --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: use-after-free of context bank devices during deferred V4L2 cleanup --

commit 720de65140e46882c5d0651161ef771fcb1189a2
Author: Vikash Garodia <[email protected]>

media: iris: Route buffers to the matching context bank device

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range.
Add iris_get_cb_dev(), which maps a buffer type to the owning context bank device. Bitstream and internal buffers (BIN, ARP, COMV, LINE, NON_COMV, PERSIST) belong to the non-pixel device, and uncompressed buffers (DPB, PARTIAL, SCRATCH_1, SCRATCH_2, VPSS) to the pixel device. BUF_INPUT and BUF_OUTPUT depend on direction and are resolved from inst->domain: for a decoder the input is non-pixel and the output pixel, and the other way round for an encoder.
Fall back to core->dev whenever the relevant context bank device is absent, so platforms still describing "iommus" on the parent iris node behave exactly as before to maintain backward compatibility.

drivers/media/platform/qcom/iris/iris_buffer.c static int iris_create_internal_buffer(struct iris_inst *inst, · line 534

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +1 -1
index eb8de60c1177f..6e03d13ac1a79 100644
@@ -531,7 +531,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
 				       enum iris_buffer_type buffer_type, u32 index)
 {
 	struct iris_buffers *buffers = &inst->buffers[buffer_type];
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer_type);

[Severity: High]
Does this acquire the context bank device for DMA mapping without taking a reference to guarantee its lifetime matches the buffer?

If iris_remove() explicitly calls platform_device_unregister() on these devices upon sysfs driver unbind, and no standard buffers are active, their refcount can drop to 0 and they will be freed.

Quoted 3 lines
drivers/media/platform/qcom/iris/iris_buffer.c +0 -0
 	struct iris_buffer *buffer;
 
 	if (!buffers->size)

[ ... ]

drivers/media/platform/qcom/iris/iris_buffer.c int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane) · line 656

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +2 -2
@@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
 
 void iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
 {
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer->type);
 
 	list_del(&buffer->list);
-	dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
+	dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,

[Severity: High]
Can this result in a use-after-free of the context bank device during deferred V4L2 cleanup?

If standard buffers are active, videobuf2 holds a reference. However, during deferred cleanup in iris_close(), v4l2_m2m_ctx_release() frees standard buffers before iris_destroy_all_internal_buffers() runs. This drops the final refcount, freeing the devices.

Will this fetch and dereference the freed device pointer, passing it to dma_free_attrs()? Additionally, does the devm-allocated core also get freed on unbind, making inst->core a dangling pointer here?

[ ... ]

drivers/media/platform/qcom/iris/iris_vidc.c iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_ · line 111

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_vidc.c +1 -1
index fcbc60016beec..064cf0a80748d 100644
@@ -108,7 +108,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
 	src_vq->drv_priv = inst;
 	src_vq->buf_struct_size = sizeof(struct iris_buffer);
 	src_vq->min_reqbufs_allocation = MIN_BUFFERS;
-	src_vq->dev = inst->core->dev;
+	src_vq->dev = iris_get_cb_dev(inst, BUF_INPUT);

[Severity: High]
Does this assign a manually lifetime-managed, short-lived device to the long-lived vb2_queue context?

drivers/media/platform/qcom/iris/iris_vidc.c iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_ · line 125

Quoted 9 lines
drivers/media/platform/qcom/iris/iris_vidc.c +1 -1
 	src_vq->lock = &inst->ctx_q_lock;
 	ret = vb2_queue_init(src_vq);
 	if (ret)
@@ -122,7 +122,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
 	dst_vq->drv_priv = inst;
 	dst_vq->buf_struct_size = sizeof(struct iris_buffer);
 	dst_vq->min_reqbufs_allocation = MIN_BUFFERS;
-	dst_vq->dev = inst->core->dev;
+	dst_vq->dev = iris_get_cb_dev(inst, BUF_OUTPUT);

[Severity: High]
Does this also assign a manually lifetime-managed, short-lived device to the long-lived vb2_queue context?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260926-vpu_iommu_iova_handling-v5-0-0322ca5dc10c@oss.qualcomm.com?part=6
#27 lore raw

Re: [PATCH v5 06/13] media: iris: Route buffers to the matching context bank device

Quoted 39 lines · On 9/26/2026 12:19 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: use-after-free of context bank devices during deferred V4L2 cleanup --

commit 720de65140e46882c5d0651161ef771fcb1189a2
Author: Vikash Garodia <[email protected]>

media: iris: Route buffers to the matching context bank device

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range.
Add iris_get_cb_dev(), which maps a buffer type to the owning context bank device. Bitstream and internal buffers (BIN, ARP, COMV, LINE, NON_COMV, PERSIST) belong to the non-pixel device, and uncompressed buffers (DPB, PARTIAL, SCRATCH_1, SCRATCH_2, VPSS) to the pixel device. BUF_INPUT and BUF_OUTPUT depend on direction and are resolved from inst->domain: for a decoder the input is non-pixel and the output pixel, and the other way round for an encoder.
Fall back to core->dev whenever the relevant context bank device is absent, so platforms still describing "iommus" on the parent iris node behave exactly as before to maintain backward compatibility.

drivers/media/platform/qcom/iris/iris_buffer.c static int iris_create_internal_buffer(struct iris_inst *inst, · line 534

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +1 -1
index eb8de60c1177f..6e03d13ac1a79 100644
@@ -531,7 +531,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
 				       enum iris_buffer_type buffer_type, u32 index)
 {
 	struct iris_buffers *buffers = &inst->buffers[buffer_type];
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer_type);

[Severity: High]
Does this acquire the context bank device for DMA mapping without taking a reference to guarantee its lifetime matches the buffer?

Quoted 3 lines

If iris_remove() explicitly calls platform_device_unregister() on these devices upon sysfs driver unbind, and no standard buffers are active, their refcount can drop to 0 and they will be freed.

This is not true. Remove callback cannot complete if driver module->refcnt, refcounted during open, and not decremented with corresponding close call. iris_close() would call iris_destroy_internal_buffers() to free up the buffers before un-registering the device.

Quoted 22 lines
Quoted 4 lines
drivers/media/platform/qcom/iris/iris_buffer.c +0 -0
 	struct iris_buffer *buffer;
 
 	if (!buffers->size)

[ ... ]

drivers/media/platform/qcom/iris/iris_buffer.c int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane) · line 656

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +2 -2
@@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
 
 void iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
 {
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer->type);
 
 	list_del(&buffer->list);
-	dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
+	dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,

[Severity: High]
Can this result in a use-after-free of the context bank device during deferred V4L2 cleanup?

Quoted 4 lines

If standard buffers are active, videobuf2 holds a reference. However, during deferred cleanup in iris_close(), v4l2_m2m_ctx_release() frees standard buffers before iris_destroy_all_internal_buffers() runs. This drops the final refcount, freeing the devices.

iris_destroy_all_internal_buffers() frees the internal buffers which is managed within the driver outside the scope of v4l2_m2m_ctx_release().

Quoted 4 lines

Will this fetch and dereference the freed device pointer, passing it to dma_free_attrs()? Additionally, does the devm-allocated core also get freed on unbind, making inst->core a dangling pointer here?

Unbind will not happen until iris_close() completes(explained above), which avoids this scenario.

Quoted 18 lines

[ ... ]

drivers/media/platform/qcom/iris/iris_vidc.c iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_ · line 111

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_vidc.c +1 -1
index fcbc60016beec..064cf0a80748d 100644
@@ -108,7 +108,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
 	src_vq->drv_priv = inst;
 	src_vq->buf_struct_size = sizeof(struct iris_buffer);
 	src_vq->min_reqbufs_allocation = MIN_BUFFERS;
-	src_vq->dev = inst->core->dev;
+	src_vq->dev = iris_get_cb_dev(inst, BUF_INPUT);

[Severity: High]
Does this assign a manually lifetime-managed, short-lived device to the long-lived vb2_queue context?

Quoted 13 lines

drivers/media/platform/qcom/iris/iris_vidc.c iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_ · line 125

Quoted 9 lines
drivers/media/platform/qcom/iris/iris_vidc.c +1 -1
 	src_vq->lock = &inst->ctx_q_lock;
 	ret = vb2_queue_init(src_vq);
 	if (ret)
@@ -122,7 +122,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
 	dst_vq->drv_priv = inst;
 	dst_vq->buf_struct_size = sizeof(struct iris_buffer);
 	dst_vq->min_reqbufs_allocation = MIN_BUFFERS;
-	dst_vq->dev = inst->core->dev;
+	dst_vq->dev = iris_get_cb_dev(inst, BUF_OUTPUT);

[Severity: High]
Does this also assign a manually lifetime-managed, short-lived device to the long-lived vb2_queue context?

These devices are long-lived when compare to vb2_queue and are freed only in iris_remove().

Quoted 1 line
#28 lore raw

Re: [PATCH v5 06/13] media: iris: Route buffers to the matching context bank device

Quoted 42 lines · Vishnu Reddy
Quoted 39 lines · On 9/26/2026 12:19 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: use-after-free of context bank devices during deferred V4L2 cleanup --

commit 720de65140e46882c5d0651161ef771fcb1189a2
Author: Vikash Garodia <[email protected]>

media: iris: Route buffers to the matching context bank device

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range.
Add iris_get_cb_dev(), which maps a buffer type to the owning context bank device. Bitstream and internal buffers (BIN, ARP, COMV, LINE, NON_COMV, PERSIST) belong to the non-pixel device, and uncompressed buffers (DPB, PARTIAL, SCRATCH_1, SCRATCH_2, VPSS) to the pixel device. BUF_INPUT and BUF_OUTPUT depend on direction and are resolved from inst->domain: for a decoder the input is non-pixel and the output pixel, and the other way round for an encoder.
Fall back to core->dev whenever the relevant context bank device is absent, so platforms still describing "iommus" on the parent iris node behave exactly as before to maintain backward compatibility.

drivers/media/platform/qcom/iris/iris_buffer.c static int iris_create_internal_buffer(struct iris_inst *inst, · line 534

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +1 -1
index eb8de60c1177f..6e03d13ac1a79 100644
@@ -531,7 +531,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
 				       enum iris_buffer_type buffer_type, u32 index)
 {
 	struct iris_buffers *buffers = &inst->buffers[buffer_type];
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer_type);

[Severity: High]
Does this acquire the context bank device for DMA mapping without taking a reference to guarantee its lifetime matches the buffer?

Quoted 8 lines
Quoted 3 lines

If iris_remove() explicitly calls platform_device_unregister() on these devices upon sysfs driver unbind, and no standard buffers are active, their refcount can drop to 0 and they will be freed.

This is not true. Remove callback cannot complete if driver module->refcnt, refcounted during open, and not decremented with corresponding close call. iris_close() would call iris_destroy_internal_buffers() to free up the buffers before un-registering the device.

I don't follow this comment. There is nothing about module removal. Sashiko here (and in several other comments) tells about using the unbind file in sysfs to unbind the driver from the device. The module is still present in the memory, the module refcount is not decremented.

Quoted 39 lines
Quoted 23 lines
Quoted 5 lines
drivers/media/platform/qcom/iris/iris_buffer.c +0 -0
 	struct iris_buffer *buffer;
 
 	if (!buffers->size)

[ ... ]

drivers/media/platform/qcom/iris/iris_buffer.c int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane) · line 656

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +2 -2
@@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
 
 void iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
 {
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer->type);
 
 	list_del(&buffer->list);
-	dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
+	dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,

[Severity: High]
Can this result in a use-after-free of the context bank device during deferred V4L2 cleanup?

Quoted 4 lines

If standard buffers are active, videobuf2 holds a reference. However, during deferred cleanup in iris_close(), v4l2_m2m_ctx_release() frees standard buffers before iris_destroy_all_internal_buffers() runs. This drops the final refcount, freeing the devices.

iris_destroy_all_internal_buffers() frees the internal buffers which is managed within the driver outside the scope of v4l2_m2m_ctx_release().

Quoted 4 lines

Will this fetch and dereference the freed device pointer, passing it to dma_free_attrs()? Additionally, does the devm-allocated core also get freed on unbind, making inst->core a dangling pointer here?

Unbind will not happen until iris_close() completes(explained above), which avoids this scenario.

Signature · 2 lines
With best wishes
Dmitry
#29 lore raw

Re: [PATCH v5 06/13] media: iris: Route buffers to the matching context bank device

Quoted 44 lines · Dmitry Baryshkov
Quoted 43 lines · Vishnu Reddy
Quoted 41 lines · On 9/26/2026 12:19 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: use-after-free of context bank devices during deferred V4L2 cleanup --

commit 720de65140e46882c5d0651161ef771fcb1189a2
Author: Vikash Garodia <[email protected]>

media: iris: Route buffers to the matching context bank device

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range.
Add iris_get_cb_dev(), which maps a buffer type to the owning context bank device. Bitstream and internal buffers (BIN, ARP, COMV, LINE, NON_COMV, PERSIST) belong to the non-pixel device, and uncompressed buffers (DPB, PARTIAL, SCRATCH_1, SCRATCH_2, VPSS) to the pixel device. BUF_INPUT and BUF_OUTPUT depend on direction and are resolved from inst->domain: for a decoder the input is non-pixel and the output pixel, and the other way round for an encoder.
Fall back to core->dev whenever the relevant context bank device is absent, so platforms still describing "iommus" on the parent iris node behave exactly as before to maintain backward compatibility.

drivers/media/platform/qcom/iris/iris_buffer.c static int iris_create_internal_buffer(struct iris_inst *inst, · line 534

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +1 -1
index eb8de60c1177f..6e03d13ac1a79 100644
@@ -531,7 +531,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
 				       enum iris_buffer_type buffer_type, u32 index)
 {
 	struct iris_buffers *buffers = &inst->buffers[buffer_type];
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer_type);

[Severity: High]
Does this acquire the context bank device for DMA mapping without taking a reference to guarantee its lifetime matches the buffer?

If iris_remove() explicitly calls platform_device_unregister() on these devices upon sysfs driver unbind, and no standard buffers are active, their refcount can drop to 0 and they will be freed.

Quoted 8 lines
Quoted 4 lines

This is not true. Remove callback cannot complete if driver module->refcnt, refcounted during open, and not decremented with corresponding close call. iris_close() would call iris_destroy_internal_buffers() to free up the buffers before un-registering the device.

I don't follow this comment. There is nothing about module removal. Sashiko here (and in several other comments) tells about using the unbind file in sysfs to unbind the driver from the device. The module is still present in the memory, the module refcount is not decremented.

Thanks for clarifying the comment. Detaching the driver from device at runtime might leave the interaction with hardware unclosed.
Would prefer adding something like this
    .suppress_bind_attrs = true;

Again, this is not just applicable to sub-node devices, but to parent device too. Sashiko should classify this as a pre-existing issue.

Quoted 32 lines
Quoted 32 lines
Quoted 19 lines
Quoted 3 lines
drivers/media/platform/qcom/iris/iris_buffer.c +0 -0
 	struct iris_buffer *buffer;
 
 	if (!buffers->size)

[ ... ]

drivers/media/platform/qcom/iris/iris_buffer.c int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane) · line 656

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +2 -2
@@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
 
 void iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
 {
-	struct iris_core *core = inst->core;
+	struct device *dev = iris_get_cb_dev(inst, buffer->type);
 
 	list_del(&buffer->list);
-	dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
+	dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,

[Severity: High]
Can this result in a use-after-free of the context bank device during deferred V4L2 cleanup?

Quoted 4 lines

If standard buffers are active, videobuf2 holds a reference. However, during deferred cleanup in iris_close(), v4l2_m2m_ctx_release() frees standard buffers before iris_destroy_all_internal_buffers() runs. This drops the final refcount, freeing the devices.

iris_destroy_all_internal_buffers() frees the internal buffers which is managed within the driver outside the scope of v4l2_m2m_ctx_release().

Quoted 3 lines

Will this fetch and dereference the freed device pointer, passing it to dma_free_attrs()? Additionally, does the devm-allocated core also get freed on unbind, making inst->core a dangling pointer here?

Unbind will not happen until iris_close() completes(explained above), which avoids this scenario.

#30 lore raw

Re: [PATCH v5 06/13] media: iris: Route buffers to the matching context bank device

Quoted 56 lines · Vishnu Reddy
Quoted 44 lines · Dmitry Baryshkov
Quoted 43 lines · Vishnu Reddy
Quoted 41 lines · On 9/26/2026 12:19 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: use-after-free of context bank devices during deferred V4L2 cleanup --

commit 720de65140e46882c5d0651161ef771fcb1189a2
Author: Vikash Garodia <[email protected]>

media: iris: Route buffers to the matching context bank device

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range.
Add iris_get_cb_dev(), which maps a buffer type to the owning context bank device. Bitstream and internal buffers (BIN, ARP, COMV, LINE, NON_COMV, PERSIST) belong to the non-pixel device, and uncompressed buffers (DPB, PARTIAL, SCRATCH_1, SCRATCH_2, VPSS) to the pixel device. BUF_INPUT and BUF_OUTPUT depend on direction and are resolved from inst->domain: for a decoder the input is non-pixel and the output pixel, and the other way round for an encoder.
Fall back to core->dev whenever the relevant context bank device is absent, so platforms still describing "iommus" on the parent iris node behave exactly as before to maintain backward compatibility.

drivers/media/platform/qcom/iris/iris_buffer.c static int iris_create_internal_buffer(struct iris_inst *inst, · line 534

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +1 -1
index eb8de60c1177f..6e03d13ac1a79 100644
@@ -531,7 +531,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
                                  enum iris_buffer_type buffer_type, u32 index)
 {
   struct iris_buffers *buffers = &inst->buffers[buffer_type];
-  struct iris_core *core = inst->core;
+  struct device *dev = iris_get_cb_dev(inst, buffer_type);

[Severity: High]
Does this acquire the context bank device for DMA mapping without taking a reference to guarantee its lifetime matches the buffer?

If iris_remove() explicitly calls platform_device_unregister() on these devices upon sysfs driver unbind, and no standard buffers are active, their refcount can drop to 0 and they will be freed.

Quoted 8 lines
Quoted 4 lines

This is not true. Remove callback cannot complete if driver module->refcnt, refcounted during open, and not decremented with corresponding close call. iris_close() would call iris_destroy_internal_buffers() to free up the buffers before un-registering the device.

I don't follow this comment. There is nothing about module removal. Sashiko here (and in several other comments) tells about using the unbind file in sysfs to unbind the driver from the device. The module is still present in the memory, the module refcount is not decremented.

Quoted 4 lines

Thanks for clarifying the comment. Detaching the driver from device at runtime might leave the interaction with hardware unclosed.
Would prefer adding something like this

    .suppress_bind_attrs = true;

Please don't. It would be a sing of a badly written driver.

Quoted 3 lines

Again, this is not just applicable to sub-node devices, but to parent device too. Sashiko should classify this as a pre-existing issue.

Yes, Sashiko is writing about the parent. It can't be a preexisting issue, because there were no extra context bank mappings beforehand.

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 20 lines
Quoted 4 lines
drivers/media/platform/qcom/iris/iris_buffer.c +0 -0
   struct iris_buffer *buffer;
 
   if (!buffers->size)

[ ... ]

drivers/media/platform/qcom/iris/iris_buffer.c int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane) · line 656

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_buffer.c +2 -2
@@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
 
 void iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
 {
-  struct iris_core *core = inst->core;
+  struct device *dev = iris_get_cb_dev(inst, buffer->type);
 
   list_del(&buffer->list);
-  dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
+  dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,

[Severity: High]
Can this result in a use-after-free of the context bank device during deferred V4L2 cleanup?

Quoted 4 lines

If standard buffers are active, videobuf2 holds a reference. However, during deferred cleanup in iris_close(), v4l2_m2m_ctx_release() frees standard buffers before iris_destroy_all_internal_buffers() runs. This drops the final refcount, freeing the devices.

iris_destroy_all_internal_buffers() frees the internal buffers which is managed within the driver outside the scope of v4l2_m2m_ctx_release().

Quoted 3 lines

Will this fetch and dereference the freed device pointer, passing it to dma_free_attrs()? Additionally, does the devm-allocated core also get freed on unbind, making inst->core a dangling pointer here?

Unbind will not happen until iris_close() completes(explained above), which avoids this scenario.

Signature · 2 lines
With best wishes
Dmitry
author maintainer
#31 lore raw

PATCH v5 7/13 media: iris: Skip DMA mask setup when the core device has no IOMMU

In reply to Vikash Garodia

Once the streams are described as context bank subnodes, the "iommus" property no longer sits on the parent iris node. That device then has no IOMMU domain of its own and never performs DMA directly, so calling dma_set_mask_and_coherent() on it is meaningless, and on a device with no IOMMU it can fail and abort probe.

Set the DMA mask only when device_iommu_mapped() reports an IOMMU on the core device. Platforms that have not been converted still carry "iommus" on the parent node and keep the existing setup. For converted platforms the mask is applied to each context bank device instead, in iris_create_cb_dev().

---
 drivers/media/platform/qcom/iris/iris_probe.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/iris/iris_probe.c +5 -3
index debd1f0e57038d7abf463e82fd80f887b67750e8..4bdb078d83b5c331869dab2409bc4d10ab302737 100644
@@ -352,9 +352,11 @@ static int iris_probe(struct platform_device *pdev)
 
 	dma_mask = core->iris_platform_data->dma_mask;
 
-	ret = dma_set_mask_and_coherent(dev, dma_mask);
-	if (ret)
-		goto err_vdev_unreg_enc;
+	if (device_iommu_mapped(dev)) {
+		ret = dma_set_mask_and_coherent(dev, dma_mask);
+		if (ret)
+			goto err_vdev_unreg_enc;
+	}
 
 	dma_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
 	dma_set_seg_boundary(&pdev->dev, DMA_BIT_MASK(32));
Signature · 1 line
2.34.1
author maintainer
#32 lore raw

PATCH v5 8/13 arm64: dts: qcom: hamoa: Add Iris context bank subnodes

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

---
 arch/arm64/boot/dts/qcom/hamoa.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/hamoa.dtsi +13 -2
index 4e35254cdd11a87eb5e4817abd09a603522309e2..9819a1f5686ce92c2249cc1dd65a491665fcfb94 100644
@@ -5468,10 +5468,12 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			resets = <&gcc GCC_VIDEO_AXI0_CLK_ARES>;
 			reset-names = "bus";
 
-			iommus = <&apps_smmu 0x1940 0>,
-				 <&apps_smmu 0x1947 0>;
 			dma-coherent;
 
+			#address-cells = <1>;
+			#size-cells = <1>;
+			dma-ranges = <0x0 0x0 0x0 0xe0000000>;
+
 			/*
 			 * IRIS firmware is signed by vendors, only
 			 * enable on boards where the proper signed firmware
@@ -5479,6 +5481,15 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			 */
 			status = "disabled";
 
+			non-pixel {
+				iommus = <&apps_smmu 0x1940 0x0>;
+				iommu-ranges = <0x25800000 0xba800000>;
+			};
+
+			pixel {
+				iommus = <&apps_smmu 0x1947 0x0>;
+			};
+
 			iris_opp_table: opp-table {
 				compatible = "operating-points-v2";
 
Signature · 1 line
2.34.1
Reviewed-by on v5 8/13
#33 lore raw

Re: [PATCH v5 08/13] arm64: dts: qcom: hamoa: Add Iris context bank subnodes

Quoted 4 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

Konrad

Reviewed-by on v5 8/13
#34 lore raw

Re: [PATCH v5 08/13] arm64: dts: qcom: hamoa: Add Iris context bank subnodes

In reply to Vikash Garodia
Quoted 34 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

Quoted 7 lines
---
 arch/arm64/boot/dts/qcom/hamoa.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#35 lore raw

PATCH v5 9/13 arm64: dts: qcom: sm8550: Add Iris context bank subnodes

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

---
 arch/arm64/boot/dts/qcom/sm8550.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sm8550.dtsi +13 -2
index 23604436add303348867f890890f2f7af4f831af..60164b853ae0764cdd79c4680490e66a548b0613 100644
@@ -3690,8 +3690,6 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			resets = <&gcc GCC_VIDEO_AXI0_CLK_ARES>;
 			reset-names = "bus";
 
-			iommus = <&apps_smmu 0x1940 0>,
-				 <&apps_smmu 0x1947 0>;
 			dma-coherent;
 
 			/*
@@ -3701,6 +3699,19 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			 */
 			status = "disabled";
 
+			#address-cells = <1>;
+			#size-cells = <1>;
+			dma-ranges = <0x0 0x0 0x0 0xe0000000>;
+
+			non-pixel {
+				iommus = <&apps_smmu 0x1940 0x0>;
+				iommu-ranges = <0x25800000 0xba800000>;
+			};
+
+			pixel {
+				iommus = <&apps_smmu 0x1947 0x0>;
+			};
+
 			iris_opp_table: opp-table {
 				compatible = "operating-points-v2";
 
Signature · 1 line
2.34.1
Reviewed-by on v5 9/13
#36 lore raw

Re: [PATCH v5 09/13] arm64: dts: qcom: sm8550: Add Iris context bank subnodes

Quoted 31 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

Quoted 7 lines

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

---

Konrad

Reviewed-by on v5 9/13
#37 lore raw

Re: [PATCH v5 09/13] arm64: dts: qcom: sm8550: Add Iris context bank subnodes

In reply to Vikash Garodia
Quoted 34 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

Quoted 7 lines
---
 arch/arm64/boot/dts/qcom/sm8550.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#38 lore raw

PATCH v5 10/13 arm64: dts: qcom: lemans: Add Iris context bank subnodes

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

---
 arch/arm64/boot/dts/qcom/lemans.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/lemans.dtsi +13 -2
index 695eae1b7256911e656ab1ecdd92aca135d92f39..afed5e43b4fcda8b8400e815d24c5094834677f3 100644
@@ -4962,12 +4962,23 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			resets = <&gcc GCC_VIDEO_AXI0_CLK_ARES>;
 			reset-names = "bus";
 
-			iommus = <&apps_smmu 0x0880 0x0400>,
-				 <&apps_smmu 0x0887 0x0400>;
 			dma-coherent;
 
+			#address-cells = <1>;
+			#size-cells = <1>;
+			dma-ranges = <0x0 0x0 0x0 0xe0000000>;
+
 			status = "disabled";
 
+			non-pixel {
+				iommus = <&apps_smmu 0x0880 0x0400>;
+				iommu-ranges = <0x25800000 0xba800000>;
+			};
+
+			pixel {
+				iommus = <&apps_smmu 0x0887 0x0400>;
+			};
+
 			iris_opp_table: opp-table {
 				compatible = "operating-points-v2";
 
Signature · 1 line
2.34.1
Reviewed-by on v5 10/13
#39 lore raw

Re: [PATCH v5 10/13] arm64: dts: qcom: lemans: Add Iris context bank subnodes

Quoted 11 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

Konrad

Reviewed-by on v5 10/13
#40 lore raw

Re: [PATCH v5 10/13] arm64: dts: qcom: lemans: Add Iris context bank subnodes

In reply to Vikash Garodia
Quoted 34 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

Quoted 7 lines
---
 arch/arm64/boot/dts/qcom/lemans.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#41 lore raw

PATCH v5 11/13 arm64: dts: qcom: monaco: Add Iris context bank subnodes

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

---
 arch/arm64/boot/dts/qcom/monaco.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/monaco.dtsi +13 -2
index 395d32d368443e6c73b934b183c3de007ca2e6b5..89ea87a274a159da872facb688cd742d8d28f3c5 100644
@@ -5403,12 +5403,23 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			resets = <&gcc GCC_VIDEO_AXI0_CLK_ARES>;
 			reset-names = "bus";
 
-			iommus = <&apps_smmu 0x0880 0x0400>,
-				 <&apps_smmu 0x0887 0x0400>;
 			dma-coherent;
 
+			#address-cells = <1>;
+			#size-cells = <1>;
+			dma-ranges = <0x0 0x0 0x0 0xe0000000>;
+
 			status = "disabled";
 
+			non-pixel {
+				iommus = <&apps_smmu 0x0880 0x0400>;
+				iommu-ranges = <0x25800000 0xba800000>;
+			};
+
+			pixel {
+				iommus = <&apps_smmu 0x0887 0x0400>;
+			};
+
 			iris_opp_table: opp-table {
 				compatible = "operating-points-v2";
 
Signature · 1 line
2.34.1
Reviewed-by on v5 11/13
#42 lore raw

Re: [PATCH v5 11/13] arm64: dts: qcom: monaco: Add Iris context bank subnodes

Quoted 11 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

Konrad

Reviewed-by on v5 11/13
#43 lore raw

Re: [PATCH v5 11/13] arm64: dts: qcom: monaco: Add Iris context bank subnodes

In reply to Vikash Garodia
Quoted 34 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

Quoted 7 lines
---
 arch/arm64/boot/dts/qcom/monaco.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#44 lore raw

PATCH v5 12/13 arm64: dts: qcom: sm8650: Add Iris context bank subnodes

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

---
 arch/arm64/boot/dts/qcom/sm8650.dtsi | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/qcom/sm8650.dtsi +13 -3
index 4e317c422d92ed72dca8bd97ac33c89f9b462218..078115d57dacd5d5f407cb4592c989ba0e9f78c4 100644
@@ -5274,11 +5274,12 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 				      "xo",
 				      "core";
 
-			iommus = <&apps_smmu 0x1940 0>,
-				 <&apps_smmu 0x1947 0>;
-
 			dma-coherent;
 
+			#address-cells = <1>;
+			#size-cells = <1>;
+			dma-ranges = <0x0 0x0 0x0 0xe0000000>;
+
 			/*
 			 * IRIS firmware is signed by vendors, only
 			 * enable on boards where the proper signed firmware
@@ -5286,6 +5287,15 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			 */
 			status = "disabled";
 
+			non-pixel {
+				iommus = <&apps_smmu 0x1940 0x0>;
+				iommu-ranges = <0x25800000 0xba800000>;
+			};
+
+			pixel {
+				iommus = <&apps_smmu 0x1947 0x0>;
+			};
+
 			iris_opp_table: opp-table {
 				compatible = "operating-points-v2";
 
Signature · 1 line
2.34.1
Reviewed-by on v5 12/13
#45 lore raw

Re: [PATCH v5 12/13] arm64: dts: qcom: sm8650: Add Iris context bank subnodes

Quoted 7 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |

Konrad

Reviewed-by on v5 12/13
#46 lore raw

Re: [PATCH v5 12/13] arm64: dts: qcom: sm8650: Add Iris context bank subnodes

In reply to Vikash Garodia
Quoted 34 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

Quoted 7 lines
---
 arch/arm64/boot/dts/qcom/sm8650.dtsi | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#47 lore raw

PATCH v5 13/13 arm64: dts: qcom: sm8750: Add Iris context bank subnodes

In reply to Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

---
 arch/arm64/boot/dts/qcom/sm8750.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sm8750.dtsi +13 -2
index 28cf22da854d01413b8e86be3f6330354aad05f2..2e1e07eb5b6aa49850a7a5572ef9e755e298b799 100644
@@ -3025,8 +3025,6 @@ iris: video-codec@aa00000 {
 				      "vcodec0_core_freerun";
 
 			dma-coherent;
-			iommus = <&apps_smmu 0x1940 0>,
-				 <&apps_smmu 0x1947 0>;
 
 			interconnects = <&gem_noc MASTER_APPSS_PROC QCOM_ICC_TAG_ACTIVE_ONLY
 					 &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
@@ -3059,6 +3057,10 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 				      "core",
 				      "vcodec0_core";
 
+			#address-cells = <1>;
+			#size-cells = <1>;
+			dma-ranges = <0x0 0x0 0x0 0xe0000000>;
+
 			/*
 			 * IRIS firmware is signed by vendors, only
 			 * enable in boards where the proper signed firmware
@@ -3066,6 +3068,15 @@ &config_noc SLAVE_VENUS_CFG QCOM_ICC_TAG_ACTIVE_ONLY>,
 			 */
 			status = "disabled";
 
+			non-pixel {
+				iommus = <&apps_smmu 0x1940 0x0>;
+				iommu-ranges = <0x25800000 0xba800000>;
+			};
+
+			pixel {
+				iommus = <&apps_smmu 0x1947 0x0>;
+			};
+
 			iris_opp_table: opp-table {
 				compatible = "operating-points-v2";
 
Signature · 1 line
2.34.1
Reviewed-by on v5 13/13
#48 lore raw

Re: [PATCH v5 13/13] arm64: dts: qcom: sm8750: Add Iris context bank subnodes

Quoted 8 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

Konrad

Reviewed-by on v5 13/13
#49 lore raw

Re: [PATCH v5 13/13] arm64: dts: qcom: sm8750: Add Iris context bank subnodes

In reply to Vikash Garodia
Quoted 34 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA allocator, so nothing restricts a non-pixel buffer to avoid 0 to 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots:
https://gitlab.freedesktop.org/drm/msm/-/work_items/100

Given that the address range restriction is for specific VPU stream, it should be ideally be moved to that stream. To achieve the same, a subset of streams is now represented as subnodes, so that each can be associated with its respective addressable range. The design was discussed and agreed by mainatiners here
https://lore.kernel.org/all/[email protected]

In the past, this limitation was addressed with an iommu-map approach, with the iris driver dynamically creating the devices. That approach was later concluded to be a hack to avoid having subnodes, and was NAKed by the iommu maintainers. It was discussed in detail here:
https://lore.kernel.org/all/[email protected]/

The video-codec node includes address-cells, size-cells and dma-ranges to declare 1:1 mapping for DMA translation to the parent.

Quoted 7 lines
---
 arch/arm64/boot/dts/qcom/sm8750.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#50 lore raw
In reply to Vikash Garodia
Quoted 11 lines · Vikash Garodia

The VPU issues DMA through several SMMU streams, and the hardware does not restricts specific streams with specific addressable range. The non-pixel stream is restricted to use 0-600MB of IOVA space, while the pixel stream can address the full range:

    +-----------------------------------------------------------+
    | non-pixel stream addressable range (600 MB - 3.5 GB)      |
    | 0x25800000 - 0xe0000000                                   |
    +-----------------------------------------------------------+
    | pixel stream addressable range (0 - 3.5 GB)               |
    | 0x00000000 - 0xe0000000                                   |
    +-----------------------------------------------------------+

Please address all venus/iris-enabled platforms once this lands

Konrad