Skip to contentSkip to conversation

soc: ti: Add and use PVU on K3-AM65 for DMA isolation

PATCH Superseded Jan Kiszka 3 participants 19 messages Aug 26, 2024 – Aug 27, 2024

Subsystems (5)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

v2 cover soc: ti: Add and use PVU on K3-AM65 for DMA isolation

Changes in v2:
- fix dt_bindings_check issues (patch 1)
- address first review comments (patch 2)
- extend ti,am65-pci-host bindings for PVU (new patch 3)

Only few of the K3 SoCs have an IOMMU and, thus, can isolate the system against DMA-based attacks of external PCI devices. The AM65 is without an IOMMU, but it comes with something close to it: the Peripheral Virtualization Unit (PVU).

The PVU was originally designed to establish static compartments via a hypervisor, isolate those DMA-wise against each other and the host and even allow remapping of guest-physical addresses. But it only provides a static translation region, not page-granular mappings. Thus, it cannot be handled transparently like an IOMMU.

Now, to use the PVU for the purpose of isolated PCI devices from the Linux host, this series takes a different approach. It defines a restricted-dma-pool for the PCI host, using swiotlb to map all DMA buffers from a static memory carve-out. And to enforce that the devices actually follow this, a special PVU soc driver is introduced. The driver permits access to the GIC ITS and otherwise waits for other drivers that detect devices with constrained DMA to register pools with the PVU.

For the AM65, the first (and possibly only) driver where this is introduced is the pci-keystone host controller. Finally, this series configures the IOT2050 devices (all have MiniPCIe or M.2 extension slots) to make use of this protection scheme.

Due to the cross-cutting nature of these changes, multiple subsystems are affected. However, I wanted to present the whole thing in one series to allow everyone to review with the complete picture in hands. If preferred, I can also split the series up, of course.

Jan

CC Bjorn Helgaas <[email protected]>
CC "Krzysztof Wilczyński" <[email protected]>
CC Lorenzo Pieralisi <[email protected]>

Jan Kiszka (6):
dt-bindings: soc: ti: Add AM65 peripheral virtualization unit
soc: ti: Add IOMPU-like PVU driver
dt-bindings: PCI: ti,am65: Extend for use with PVU
arm64: dts: ti: k3-am65-main: Add VMAP registers to PCI root complexes
PCI: keystone: Add supported for PVU-based DMA isolation on AM654
arm64: dts: ti: iot2050: Enforce DMA isolation for devices behind PCI
RC

 .../bindings/pci/ti,am65-pci-host.yaml        |  13 +-
 .../bindings/soc/ti/ti,am654-pvu.yaml         |  51 ++
 .../boot/dts/ti/k3-am65-iot2050-common.dtsi   |  32 ++
 arch/arm64/boot/dts/ti/k3-am65-main.dtsi      |  18 +-
 drivers/pci/controller/dwc/pci-keystone.c     | 101 ++++
 drivers/soc/ti/Kconfig                        |   4 +
 drivers/soc/ti/Makefile                       |   1 +
 drivers/soc/ti/ti-pvu.c                       | 487 ++++++++++++++++++
 include/linux/ti-pvu.h                        |  16 +
 9 files changed, 716 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml
 create mode 100644 drivers/soc/ti/ti-pvu.c
 create mode 100644 include/linux/ti-pvu.h
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 1/6 dt-bindings: soc: ti: Add AM65 peripheral virtualization unit

From: Jan Kiszka <[email protected]>

The PVU allows to define a limited set of mappings for incoming DMA requests to the system memory. It is not a real IOMMU, thus hooked up under the TI SoC bindings.

---
 .../bindings/soc/ti/ti,am654-pvu.yaml         | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +51 -0
new file mode 100644
index 000000000000..fd0f86fa27b0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) Siemens AG, 2024
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/ti/ti,am654-pvu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI AM654 Peripheral Virtualization Unit
+
+maintainers:
+  - Jan Kiszka <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - ti,am654-pvu
+
+  reg:
+    minItems: 2
+
+  reg-names:
+    items:
+      - const: cfg
+      - const: tlbif
+
+  interrupts:
+    items:
+      - description: fault interrupt
+
+  interrupt-names:
+    items:
+      - const: pvu
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+
+additionalProperties: false
+
+examples:
+  - |
+    ti-pvu@30f80000 {
+        compatible = "ti,am654-pvu";
+        reg = <0x30f80000 0x1000>,
+              <0x36000000 0x100000>;
+        reg-names = "cfg", "tlbif";
+        interrupts-extended = <&intr_main_navss 390>;
+        interrupt-names = "pvu";
+    };
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/6] dt-bindings: soc: ti: Add AM65 peripheral virtualization unit

Quoted 5 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

The PVU allows to define a limited set of mappings for incoming DMA requests to the system memory. It is not a real IOMMU, thus hooked up under the TI SoC bindings.

You still keep developing it on wrong, old kernel (or not using get_maintainers.pl, but this one seems too obvious so I assumed wrong kernel).

Quoted 22 lines
---
 .../bindings/soc/ti/ti,am654-pvu.yaml         | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +9 -0
new file mode 100644
index 000000000000..fd0f86fa27b0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) Siemens AG, 2024
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/ti/ti,am654-pvu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI AM654 Peripheral Virtualization Unit
+

Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml line 19

Quoted 10 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +10 -0
+maintainers:
+  - Jan Kiszka <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - ti,am654-pvu
+
+  reg:
+    minItems: 2

maxItems instead.

Quoted 15 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +15 -0
+
+  reg-names:
+    items:
+      - const: cfg
+      - const: tlbif
+
+  interrupts:
+    items:
+      - description: fault interrupt
+
+  interrupt-names:
+    items:
+      - const: pvu
+
+required:

Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml line 44

Quoted 10 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +10 -0
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+
+additionalProperties: false
+
+examples:
+  - |
+    ti-pvu@30f80000 {

Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

for sure "ti" is not generic. pvu is the device name.

Best regards,
Krzysztof

author
#3 lore raw

Re: [PATCH v2 1/6] dt-bindings: soc: ti: Add AM65 peripheral virtualization unit

Quoted 10 lines · Krzysztof Kozlowski
Quoted 5 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

The PVU allows to define a limited set of mappings for incoming DMA requests to the system memory. It is not a real IOMMU, thus hooked up under the TI SoC bindings.

You still keep developing it on wrong, old kernel (or not using get_maintainers.pl, but this one seems too obvious so I assumed wrong kernel).

Explained elsewhere, will update the two subtly changed addresses in the next round.

Quoted 27 lines
Quoted 27 lines
---
 .../bindings/soc/ti/ti,am654-pvu.yaml         | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +13 -0
new file mode 100644
index 000000000000..fd0f86fa27b0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) Siemens AG, 2024
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/ti/ti,am654-pvu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI AM654 Peripheral Virtualization Unit
+
+maintainers:
+  - Jan Kiszka <[email protected]>
+
+properties:
Quoted 8 lines

Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml line 19

Quoted 6 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +6 -0
+  compatible:
+    enum:
+      - ti,am654-pvu
+
+  reg:
+    minItems: 2

maxItems instead.

Can change, but maybe use the chance to explain to me why "maxItems" and why also "instead".

Quoted 31 lines
Quoted 16 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +15 -0
+
+  reg-names:
+    items:
+      - const: cfg
+      - const: tlbif
+
+  interrupts:
+    items:
+      - description: fault interrupt
+
+  interrupt-names:
+    items:
+      - const: pvu
+
+required:

Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml line 44

Quoted 10 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +10 -0
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+
+additionalProperties: false
+
+examples:
+  - |
+    ti-pvu@30f80000 {

Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Quoted 1 line

for sure "ti" is not generic. pvu is the device name.

No problem - which one do you propose for this type of device?

Thanks,
Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#4 lore raw

Re: [PATCH v2 1/6] dt-bindings: soc: ti: Add AM65 peripheral virtualization unit

Quoted 7 lines · Jan Kiszka
Quoted 4 lines

Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml line 19

Quoted 2 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +2 -0
+  reg:
+    minItems: 2

maxItems instead.

Can change, but maybe use the chance to explain to me why "maxItems" and why also "instead".

because minItems is not constrained. maxItem is and, in case of lack of minItems, it implies minItems.

Quoted 32 lines
Quoted 32 lines
Quoted 17 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +15 -0
+
+  reg-names:
+    items:
+      - const: cfg
+      - const: tlbif
+
+  interrupts:
+    items:
+      - description: fault interrupt
+
+  interrupt-names:
+    items:
+      - const: pvu
+
+required:

Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml line 44

Quoted 10 lines
Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file +10 -0
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+
+additionalProperties: false
+
+examples:
+  - |
+    ti-pvu@30f80000 {

Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Quoted 3 lines
Quoted 1 line

for sure "ti" is not generic. pvu is the device name.

No problem - which one do you propose for this type of device?

iommu, but if this is not suitable, at pvu could stay. Just the first 'ti-' does not sound right in that case.

Best regards,
Krzysztof

author
#5 lore raw

PATCH v2 2/6 soc: ti: Add IOMPU-like PVU driver

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

The TI Peripheral Virtualization Unit (PVU) permits to define a limited set of mappings for DMA requests on the system memory. Unlike with an IOMMU, there is no fallback to a memory-backed page table, only a fixed set of register-backed TLBs. Emulating an IOMMU behavior appears to be the more fragile the more fragmentation of pending requests occur.

Therefore, this driver does not expose the PVU as an IOMMU. It rather introduces a simple, static interface to devices that are under restricted-dma-pool constraints. They can register their pools with the PVUs, enabling only those pools to work for DMA. As also MSI is issued as DMA, the PVU already register the related translator region of the AM654 as valid DMA target.

This driver is the essential building block for limiting DMA from untrusted devices to clearly defined memory regions in the absence of a real IOMMU (SMMU).

---
 drivers/soc/ti/Kconfig  |   4 +
 drivers/soc/ti/Makefile |   1 +
 drivers/soc/ti/ti-pvu.c | 487 ++++++++++++++++++++++++++++++++++++++++
 include/linux/ti-pvu.h  |  16 ++
 4 files changed, 508 insertions(+)
 create mode 100644 drivers/soc/ti/ti-pvu.c
 create mode 100644 include/linux/ti-pvu.h
drivers/soc/ti/Kconfig +4 -0
index 1a93001c9e36..af7173ad84de 100644
@@ -82,6 +82,10 @@ config TI_PRUSS
 	  processors on various TI SoCs. It's safe to say N here if you're
 	  not interested in the PRU or if you are unsure.
 
+config TI_PVU
+	bool "TI Peripheral Virtualization Unit driver"
+	depends on ARCH_K3 && DMA_RESTRICTED_POOL
+
 endif # SOC_TI
 
 config TI_SCI_INTA_MSI_DOMAIN
drivers/soc/ti/Makefile +1 -0
index cb800a745e66..ecff3fd8c433 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_TI_K3_RINGACC)		+= k3-ringacc.o
 obj-$(CONFIG_TI_K3_SOCINFO)		+= k3-socinfo.o
 obj-$(CONFIG_TI_PRUSS)			+= pruss.o
 obj-$(CONFIG_POWER_AVS_OMAP)		+= smartreflex.o
+obj-$(CONFIG_TI_PVU)			+= ti-pvu.o
drivers/soc/ti/ti-pvu.c new file +487 -0

487 lines not on this page · raw message

include/linux/ti-pvu.h new file +16 -0
new file mode 100644
index 000000000000..acd4d9e0dc86
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * TI Peripheral Virtualization Unit driver for static DMA isolation
+ *
+ * Copyright (c) 2024, Siemens AG
+ */
+
+#ifndef _LINUX_TI_PVU_H
+#define _LINUX_TI_PVU_H
+
+#include <linux/ioport.h>
+
+int ti_pvu_create_region(unsigned int virt_id, const struct resource *region);
+int ti_pvu_remove_region(unsigned int virt_id, const struct resource *region);
+
+#endif /* _LINUX_TI_PVU_H */
Signature · 1 line
2.43.0
author
#6 lore raw

PATCH v2 3/6 dt-bindings: PCI: ti,am65: Extend for use with PVU

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

---
 .../devicetree/bindings/pci/ti,am65-pci-host.yaml   | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +10 -3
index 0a9d10532cc8..72f78f21e1e8 100644
@@ -20,7 +20,7 @@ properties:
       - ti,keystone-pcie
 
   reg:
-    maxItems: 4
+    maxItems: 6
 
   reg-names:
     items:
@@ -28,6 +28,8 @@ properties:
       - const: dbics
       - const: config
       - const: atu
+      - const: vmap_lp
+      - const: vmap_hp
 
   interrupts:
     maxItems: 1
@@ -69,6 +71,9 @@ properties:
     items:
       pattern: '^pcie-phy[0-1]$'
 
+  memory-region:
+    description: phandle to restricted DMA pool to be used for all devices behind this controller
+
 required:
   - compatible
   - reg
@@ -104,8 +109,10 @@ examples:
         reg =  <0x5500000 0x1000>,
                <0x5501000 0x1000>,
                <0x10000000 0x2000>,
-               <0x5506000 0x1000>;
-        reg-names = "app", "dbics", "config", "atu";
+               <0x5506000 0x1000>,
+               <0x2900000 0x1000>,
+               <0x2908000 0x1000>;
+        reg-names = "app", "dbics", "config", "atu", "vmap_lp", "vmap_hp";
         power-domains = <&k3_pds 120 TI_SCI_PD_EXCLUSIVE>;
         #address-cells = <3>;
         #size-cells = <2>;
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

Quoted 5 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

That's an ABI break without explanation why it is necessary.

Quoted 29 lines
---
 .../devicetree/bindings/pci/ti,am65-pci-host.yaml   | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +3 -1
index 0a9d10532cc8..72f78f21e1e8 100644
@@ -20,7 +20,7 @@ properties:
       - ti,keystone-pcie
 
   reg:
-    maxItems: 4
+    maxItems: 6
 
   reg-names:
     items:
@@ -28,6 +28,8 @@ properties:
       - const: dbics
       - const: config
       - const: atu
+      - const: vmap_lp
+      - const: vmap_hp
 
   interrupts:
     maxItems: 1

Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml properties: · line 75

Quoted 5 lines
Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +2 -0
@@ -69,6 +71,9 @@ properties:
     items:
       pattern: '^pcie-phy[0-1]$'
 
+  memory-region:
+    description: phandle to restricted DMA pool to be used for all devices behind this controller

missing constraints, maxItems

Best regards,
Krzysztof

author
#8 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

Quoted 9 lines · Krzysztof Kozlowski
Quoted 5 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

That's an ABI break without explanation why it is necessary.

It is needed in order to support the PVU, as written above.

Previous versions of this binding likely didn't consider this use case and therefore didn't describe all registers associated with the hardware.

BTW, if you see a way to add the required registers without breaking more than needed, I'm all ears. At least the kernel driver will continue to work with older DTs when you disable PVU support or do not add a DMA pool to the DT.

Jan

Quoted 40 lines
Quoted 29 lines
---
 .../devicetree/bindings/pci/ti,am65-pci-host.yaml   | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +3 -1
index 0a9d10532cc8..72f78f21e1e8 100644
@@ -20,7 +20,7 @@ properties:
       - ti,keystone-pcie
 
   reg:
-    maxItems: 4
+    maxItems: 6
 
   reg-names:
     items:
@@ -28,6 +28,8 @@ properties:
       - const: dbics
       - const: config
       - const: atu
+      - const: vmap_lp
+      - const: vmap_hp
 
   interrupts:
     maxItems: 1

Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml properties: · line 75

Quoted 5 lines
Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +2 -0
@@ -69,6 +71,9 @@ properties:
     items:
       pattern: '^pcie-phy[0-1]$'
 
+  memory-region:
+    description: phandle to restricted DMA pool to be used for all devices behind this controller

missing constraints, maxItems

Best regards,
Krzysztof

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#9 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

That's an ABI break without explanation why it is necessary.

It is needed in order to support the PVU, as written above.

Above say only that you want a new feature and that's not really suitable explanation for ABI break, because answer to this is: add new feature without breaking existing users. But maybe there is a bug or something does not work or never work or there are no users, don't know.

Quoted 8 lines

Previous versions of this binding likely didn't consider this use case and therefore didn't describe all registers associated with the hardware.

BTW, if you see a way to add the required registers without breaking more than needed, I'm all ears. At least the kernel driver will continue to work with older DTs when you disable PVU support or do not add a DMA pool to the DT.

If there is no ABI break, because driver still handles correctly old DTB, then mention it in the commit msg.

Best regards,
Krzysztof

author
#10 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

Quoted 23 lines · Krzysztof Kozlowski
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

That's an ABI break without explanation why it is necessary.

It is needed in order to support the PVU, as written above.

Above say only that you want a new feature and that's not really suitable explanation for ABI break, because answer to this is: add new feature without breaking existing users. But maybe there is a bug or something does not work or never work or there are no users, don't know.

Quoted 4 lines

Previous versions of this binding likely didn't consider this use case and therefore didn't describe all registers associated with the hardware.

Quoted 7 lines
Quoted 4 lines

BTW, if you see a way to add the required registers without breaking more than needed, I'm all ears. At least the kernel driver will continue to work with older DTs when you disable PVU support or do not add a DMA pool to the DT.

If there is no ABI break, because driver still handles correctly old DTB, then mention it in the commit msg.

Well, this is strictly spoken not a topic for this commit because this one should have no clue about what drivers do with DTs according to this binding. But I can put a hint and go into details in the driver patch.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#11 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

Quoted 29 lines · Jan Kiszka
Quoted 28 lines · Krzysztof Kozlowski
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

That's an ABI break without explanation why it is necessary.

It is needed in order to support the PVU, as written above.

Above say only that you want a new feature and that's not really suitable explanation for ABI break, because answer to this is: add new feature without breaking existing users. But maybe there is a bug or something does not work or never work or there are no users, don't know.

Quoted 8 lines

Previous versions of this binding likely didn't consider this use case and therefore didn't describe all registers associated with the hardware.

BTW, if you see a way to add the required registers without breaking more than needed, I'm all ears. At least the kernel driver will continue to work with older DTs when you disable PVU support or do not add a DMA pool to the DT.

Quoted 6 lines
Quoted 2 lines

If there is no ABI break, because driver still handles correctly old DTB, then mention it in the commit msg.

Well, this is strictly spoken not a topic for this commit because this one should have no clue about what drivers do with DTs according to this binding. But I can put a hint and go into details in the driver patch.

Based on the Techincal Reference Manual for AM654 and the driver implementation in patch 5/6, I think that the following might be one way of hinting that ABI won't break:

The PVU on the AM65 SoC is capable of restricting DMA from PCIe devices to specific regions of host memory. Add the optional property "memory-regions" to point to such regions of memory when PVU is used. Since the PVU deals with system physical addresses, utilizing the PVU with PCIe devices also requires setting up the VMAP registers to map the Requester ID of the PCIe device to the CBA Virtual ID, which in turn is mapped to the system physical address. Hence, describe the VMAP registers which are optionally configured whenever PVU is used for PCIe.

Regards,
Siddharth.

author
#12 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

Quoted 41 lines · Siddharth Vadapalli
Quoted 29 lines · Jan Kiszka
Quoted 28 lines · Krzysztof Kozlowski
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

That's an ABI break without explanation why it is necessary.

It is needed in order to support the PVU, as written above.

Above say only that you want a new feature and that's not really suitable explanation for ABI break, because answer to this is: add new feature without breaking existing users. But maybe there is a bug or something does not work or never work or there are no users, don't know.

Quoted 8 lines

Previous versions of this binding likely didn't consider this use case and therefore didn't describe all registers associated with the hardware.

BTW, if you see a way to add the required registers without breaking more than needed, I'm all ears. At least the kernel driver will continue to work with older DTs when you disable PVU support or do not add a DMA pool to the DT.

Quoted 6 lines
Quoted 2 lines

If there is no ABI break, because driver still handles correctly old DTB, then mention it in the commit msg.

Well, this is strictly spoken not a topic for this commit because this one should have no clue about what drivers do with DTs according to this binding. But I can put a hint and go into details in the driver patch.

Based on the Techincal Reference Manual for AM654 and the driver implementation in patch 5/6, I think that the following might be one way of hinting that ABI won't break:

Quoted 8 lines

The PVU on the AM65 SoC is capable of restricting DMA from PCIe devices to specific regions of host memory. Add the optional property "memory-regions" to point to such regions of memory when PVU is used. Since the PVU deals with system physical addresses, utilizing the PVU with PCIe devices also requires setting up the VMAP registers to map the Requester ID of the PCIe device to the CBA Virtual ID, which in turn is mapped to the system physical address. Hence, describe the VMAP registers which are optionally configured whenever PVU is used for PCIe.

Thanks, will reuse this!

Additionally, we should then likely do

reg:
minItems: 4
maxItems: 6

to underline that the old form is still fine. Do I need to do anything to reg-names then as well?

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#13 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

Quoted 53 lines · Jan Kiszka
Quoted 41 lines · Siddharth Vadapalli
Quoted 29 lines · Jan Kiszka
Quoted 28 lines · Krzysztof Kozlowski
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

That's an ABI break without explanation why it is necessary.

It is needed in order to support the PVU, as written above.

Above say only that you want a new feature and that's not really suitable explanation for ABI break, because answer to this is: add new feature without breaking existing users. But maybe there is a bug or something does not work or never work or there are no users, don't know.

Quoted 8 lines

Previous versions of this binding likely didn't consider this use case and therefore didn't describe all registers associated with the hardware.

BTW, if you see a way to add the required registers without breaking more than needed, I'm all ears. At least the kernel driver will continue to work with older DTs when you disable PVU support or do not add a DMA pool to the DT.

Quoted 6 lines
Quoted 2 lines

If there is no ABI break, because driver still handles correctly old DTB, then mention it in the commit msg.

Well, this is strictly spoken not a topic for this commit because this one should have no clue about what drivers do with DTs according to this binding. But I can put a hint and go into details in the driver patch.

Based on the Techincal Reference Manual for AM654 and the driver implementation in patch 5/6, I think that the following might be one way of hinting that ABI won't break:

Quoted 8 lines

The PVU on the AM65 SoC is capable of restricting DMA from PCIe devices to specific regions of host memory. Add the optional property "memory-regions" to point to such regions of memory when PVU is used. Since the PVU deals with system physical addresses, utilizing the PVU with PCIe devices also requires setting up the VMAP registers to map the Requester ID of the PCIe device to the CBA Virtual ID, which in turn is mapped to the system physical address. Hence, describe the VMAP registers which are optionally configured whenever PVU is used for PCIe.

Thanks, will reuse this!

Quoted 8 lines

Additionally, we should then likely do

reg:
minItems: 4
maxItems: 6

to underline that the old form is still fine. Do I need to do anything to reg-names then as well?

They need "minItems: 4".

Best regards,
Krzysztof

author
#14 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

In reply to Krzysztof Kozlowski
Quoted 41 lines · Krzysztof Kozlowski
Quoted 5 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Describe also the VMAP registers which are needed in order to make use of the PVU with this PCI host. Furthermore, permit to specify a restricted DMA pool by phandle.

That's an ABI break without explanation why it is necessary.

Quoted 32 lines
---
 .../devicetree/bindings/pci/ti,am65-pci-host.yaml   | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +3 -1
index 0a9d10532cc8..72f78f21e1e8 100644
@@ -20,7 +20,7 @@ properties:
       - ti,keystone-pcie
 
   reg:
-    maxItems: 4
+    maxItems: 6
 
   reg-names:
     items:
@@ -28,6 +28,8 @@ properties:
       - const: dbics
       - const: config
       - const: atu
+      - const: vmap_lp
+      - const: vmap_hp
 
   interrupts:
     maxItems: 1
@@ -69,6 +71,9 @@ properties:
     items:
       pattern: '^pcie-phy[0-1]$'
 
Quoted 5 lines

Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml properties: · line 75

Quoted 2 lines
Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +2 -0
+  memory-region:
+    description: phandle to restricted DMA pool to be used for all devices behind this controller

missing constraints, maxItems

In fact, that was intentional: There could also be multiple region specified here. The driver already handles this.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#15 lore raw

Re: [PATCH v2 3/6] dt-bindings: PCI: ti,am65: Extend for use with PVU

Quoted 5 lines · Jan Kiszka
Quoted 5 lines
Quoted 5 lines

maxItems: 1

Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +0 -0
@@ -69,6 +71,9 @@ properties:
     items:
       pattern: '^pcie-phy[0-1]$'
 
Quoted 8 lines
Quoted 5 lines

Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml properties: · line 75

Quoted 2 lines
Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +2 -0
+  memory-region:
+    description: phandle to restricted DMA pool to be used for all devices behind this controller

missing constraints, maxItems

In fact, that was intentional: There could also be multiple region specified here. The driver already handles this.

Then list the items with description and minItems: 1.

Best regards,
Krzysztof

author
#16 lore raw

PATCH v2 4/6 arm64: dts: ti: k3-am65-main: Add VMAP registers to PCI root complexes

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Rewrap the long lines at this chance.

---
 arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/ti/k3-am65-main.dtsi +14 -4
index a8664b246795..c91969ddcf4d 100644
@@ -867,8 +867,13 @@ main_gpio1: gpio@601000 {
 
 	pcie0_rc: pcie@5500000 {
 		compatible = "ti,am654-pcie-rc";
-		reg = <0x0 0x5500000 0x0 0x1000>, <0x0 0x5501000 0x0 0x1000>, <0x0 0x10000000 0x0 0x2000>, <0x0 0x5506000 0x0 0x1000>;
-		reg-names = "app", "dbics", "config", "atu";
+		reg = <0x0 0x5500000 0x0 0x1000>,
+		      <0x0 0x5501000 0x0 0x1000>,
+		      <0x0 0x10000000 0x0 0x2000>,
+		      <0x0 0x5506000 0x0 0x1000>,
+		      <0x0 0x2900000 0x0 0x1000>,
+		      <0x0 0x2908000 0x0 0x1000>;
+		reg-names = "app", "dbics", "config", "atu", "vmap_lp", "vmap_hp";
 		power-domains = <&k3_pds 120 TI_SCI_PD_EXCLUSIVE>;
 		#address-cells = <3>;
 		#size-cells = <2>;
@@ -888,8 +893,13 @@ pcie0_rc: pcie@5500000 {
 
 	pcie1_rc: pcie@5600000 {
 		compatible = "ti,am654-pcie-rc";
-		reg = <0x0 0x5600000 0x0 0x1000>, <0x0 0x5601000 0x0 0x1000>, <0x0 0x18000000 0x0 0x2000>, <0x0 0x5606000 0x0 0x1000>;
-		reg-names = "app", "dbics", "config", "atu";
+		reg = <0x0 0x5600000 0x0 0x1000>,
+		      <0x0 0x5601000 0x0 0x1000>,
+		      <0x0 0x18000000 0x0 0x2000>,
+		      <0x0 0x5606000 0x0 0x1000>,
+		      <0x0 0x2910000 0x0 0x1000>,
+		      <0x0 0x2918000 0x0 0x1000>;
+		reg-names = "app", "dbics", "config", "atu", "vmap_lp", "vmap_hp";
 		power-domains = <&k3_pds 121 TI_SCI_PD_EXCLUSIVE>;
 		#address-cells = <3>;
 		#size-cells = <2>;
Signature · 1 line
2.43.0
author
#17 lore raw

PATCH v2 5/6 PCI: keystone: Add supported for PVU-based DMA isolation on AM654

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

The AM654 lacks an IOMMU, thus does not support isolating DMA requests from untrusted PCI devices to selected memory regions this way. Use static PVU-based protection instead.

For this, we use the availability of restricted-dma-pool memory regions as trigger and register those as valid DMA targets with the PVU. In addition, we need to enable the mapping of requester IDs to VirtIDs in the PCI RC. We only use a single VirtID so far, catching all devices. This may be extended later on.

---
CC: Lorenzo Pieralisi <[email protected]>
CC: "Krzysztof Wilczyński" <[email protected]>
CC: Bjorn Helgaas <[email protected]>
CC: [email protected]

---
 drivers/pci/controller/dwc/pci-keystone.c | 101 ++++++++++++++++++++++
 1 file changed, 101 insertions(+)
drivers/pci/controller/dwc/pci-keystone.c +101 -0
index 2219b1a866fa..96b871656da4 100644
@@ -19,6 +19,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/msi.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/of_pci.h>
 #include <linux/phy/phy.h>
@@ -26,6 +27,7 @@
 #include <linux/regmap.h>
 #include <linux/resource.h>
 #include <linux/signal.h>
+#include <linux/ti-pvu.h>
 
 #include "../../pci.h"
 #include "pcie-designware.h"
@@ -111,6 +113,16 @@
 
 #define PCI_DEVICE_ID_TI_AM654X		0xb00c
 
+#define KS_PCI_VIRTID			0
+
+#define PCIE_VMAP_xP_CTRL		0x0
+#define PCIE_VMAP_xP_REQID		0x4
+#define PCIE_VMAP_xP_VIRTID		0x8
+
+#define PCIE_VMAP_xP_CTRL_EN		BIT(0)
+
+#define PCIE_VMAP_xP_VIRTID_VID_MASK	0xfff
+
 struct ks_pcie_of_data {
 	enum dw_pcie_device_mode mode;
 	const struct dw_pcie_host_ops *host_ops;
@@ -1125,6 +1137,89 @@ static const struct of_device_id ks_pcie_of_match[] = {
 	{ },
 };
 
+#ifdef CONFIG_TI_PVU
+static const char *ks_vmap_res[] = {"vmap_lp", "vmap_hp"};
+
+static int ks_init_restricted_dma(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct of_phandle_iterator it;
+	bool init_vmap = false;
+	struct resource phys;
+	struct resource *res;
+	void __iomem *base;
+	unsigned int n;
+	u32 val;
+	int err;
+
+	of_for_each_phandle(&it, err, dev->of_node, "memory-region",
+			    NULL, 0) {
+		if (!of_device_is_compatible(it.node, "restricted-dma-pool"))
+			continue;
+
+		err = of_address_to_resource(it.node, 0, &phys);
+		if (err < 0) {
+			dev_err(dev, "failed to parse memory region %pOF: %d\n",
+				it.node, err);
+			continue;
+		}
+
+		err = ti_pvu_create_region(KS_PCI_VIRTID, &phys);
+		if (err < 0)
+			return err;
+
+		init_vmap = true;
+	}
+
+	if (init_vmap) {
+		for (n = 0; n < ARRAY_SIZE(ks_vmap_res); n++) {
+			res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+							   ks_vmap_res[n]);
+			base = devm_pci_remap_cfg_resource(dev, res);
+			if (IS_ERR(base))
+				return PTR_ERR(base);
+
+			writel(0, base + PCIE_VMAP_xP_REQID);
+
+			val = readl(base + PCIE_VMAP_xP_VIRTID);
+			val &= ~PCIE_VMAP_xP_VIRTID_VID_MASK;
+			val |= KS_PCI_VIRTID;
+			writel(val, base + PCIE_VMAP_xP_VIRTID);
+
+			val = readl(base + PCIE_VMAP_xP_CTRL);
+			val |= PCIE_VMAP_xP_CTRL_EN;
+			writel(val, base + PCIE_VMAP_xP_CTRL);
+		}
+	}
+
+	return 0;
+}
+
+static void ks_release_restricted_dma(struct platform_device *pdev)
+{
+	struct of_phandle_iterator it;
+	struct resource phys;
+	int err;
+
+	of_for_each_phandle(&it, err, pdev->dev.of_node, "memory-region",
+			    NULL, 0) {
+		if (of_device_is_compatible(it.node, "restricted-dma-pool") &&
+		    of_address_to_resource(it.node, 0, &phys) == 0)
+			ti_pvu_remove_region(KS_PCI_VIRTID, &phys);
+
+	}
+}
+#else
+static inline int ks_init_restricted_dma(struct platform_device *pdev)
+{
+	return 0;
+}
+
+static inline void ks_release_restricted_dma(struct platform_device *pdev)
+{
+}
+#endif
+
 static int ks_pcie_probe(struct platform_device *pdev)
 {
 	const struct dw_pcie_host_ops *host_ops;
@@ -1273,6 +1368,10 @@ static int ks_pcie_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto err_get_sync;
 
+	ret = ks_init_restricted_dma(pdev);
+	if (ret < 0)
+		goto err_get_sync;
+
 	switch (mode) {
 	case DW_PCIE_RC_TYPE:
 		if (!IS_ENABLED(CONFIG_PCI_KEYSTONE_HOST)) {
@@ -1354,6 +1453,8 @@ static void ks_pcie_remove(struct platform_device *pdev)
 	int num_lanes = ks_pcie->num_lanes;
 	struct device *dev = &pdev->dev;
 
+	ks_release_restricted_dma(pdev);
+
 	pm_runtime_put(dev);
 	pm_runtime_disable(dev);
 	ks_pcie_disable_phy(ks_pcie);
Signature · 1 line
2.43.0
author
#18 lore raw

PATCH v2 6/6 arm64: dts: ti: iot2050: Enforce DMA isolation for devices behind PCI RC

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Reserve a 64M memory region below the top of 1G RAM (smallest RAM size across the series, space left for firmware carve-outs) and ensure that all PCI devices do their DMA only inside that region. This is configured via a restricted-dma-pool and enforced with the help of the first PVU.

---
 .../boot/dts/ti/k3-am65-iot2050-common.dtsi   | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/ti/k3-am65-iot2050-common.dtsi +32 -0
index e76828ccf21b..cc0f33e3519c 100644
@@ -82,6 +82,11 @@ wdt_reset_memory_region: wdt-memory@a2200000 {
 			reg = <0x00 0xa2200000 0x00 0x1000>;
 			no-map;
 		};
+
+		pci_restricted_dma_region: restricted-dma@ba000000 {
+			compatible = "restricted-dma-pool";
+			reg = <0 0xba000000 0 0x4000000>;
+		};
 	};
 
 	leds {
@@ -571,6 +576,10 @@ seboot-backup@e80000 {
 	};
 };
 
+&pcie0_rc {
+	memory-region = <&pci_restricted_dma_region>;
+};
+
 &pcie1_rc {
 	status = "okay";
 	pinctrl-names = "default";
@@ -580,6 +589,8 @@ &pcie1_rc {
 	phys = <&serdes1 PHY_TYPE_PCIE 0>;
 	phy-names = "pcie-phy0";
 	reset-gpios = <&wkup_gpio0 27 GPIO_ACTIVE_HIGH>;
+
+	memory-region = <&pci_restricted_dma_region>;
 };
 
 &mailbox0_cluster0 {
@@ -640,3 +651,24 @@ &mcu_r5fss0 {
 	/* lock-step mode not supported on iot2050 boards */
 	ti,cluster-mode = <0>;
 };
+
+&main_navss {
+	ti_pvu0: ti-pvu@30f80000 {
+		compatible = "ti,am654-pvu";
+		reg = <0 0x30f80000 0 0x1000>,
+		      <0 0x36000000 0 0x100000>;
+		reg-names = "cfg", "tlbif";
+		interrupts-extended = <&intr_main_navss 390>;
+		interrupt-names = "pvu";
+	};
+
+	ti_pvu1: ti-pvu@30f81000 {
+		compatible = "ti,am654-pvu";
+		reg = <0 0x30f81000 0 0x1000>,
+		      <0 0x36100000 0 0x100000>;
+		reg-names = "cfg", "tlbif";
+		interrupts-extended = <&intr_main_navss 389>;
+		interrupt-names = "pvu";
+		status = "disabled";
+	};
+};
Signature · 1 line
2.43.0