Skip to contentSkip to conversation

Introduce the IOMMU_DEVICE flag.

RFC PATCH In review Varun Sethi 4 participants 8 messages Oct 6, 2014 4 messages not in the archive IOMMU

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 Introduce the IOMMU_DEVICE flag.

This is used for indicating device memory type for a DMA transaction. IOMMU driver would set up attributes indicationg access to device memory.

---
 include/linux/iommu.h |    1 +
 1 file changed, 1 insertion(+)
include/linux/iommu.h +1 -0
index 20f9a52..0599fe1 100644
@@ -28,6 +28,7 @@
 #define IOMMU_WRITE	(1 << 1)
 #define IOMMU_CACHE	(1 << 2) /* DMA cache coherency */
 #define IOMMU_EXEC	(1 << 3)
+#define IOMMU_DEVICE	(1 << 4) /* Indicates access to device memory */
 
 struct iommu_ops;
 struct iommu_group;
Signature · 1 line
1.7.9.5

A message that is not in the archive (sent off-list or not yet received): 1412591296-31934-1-git-send-email-Varun.Sethi-KZfg59tc24xl57MIdRCFDg@public.gmane.org

#2 lore raw

RFC PATCH 2/2 Add support of the IOMMU_DEVICE flag.

This flag is used for specifying access to device memory. SMMU would apply device memory attributes for a DMA transaction. This is required for setting access to GIC registers, for generating message interrupts. This would ensure that transactions targetting device memory are not gathered or reordered.

---
 drivers/iommu/arm-smmu.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/iommu/arm-smmu.c +7 -0
index ca18d6d..f8338d6 100644
@@ -1263,6 +1263,10 @@ static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd,
 		if (prot & IOMMU_CACHE)
 			pteval |= (MAIR_ATTR_IDX_CACHE <<
 				   ARM_SMMU_PTE_ATTRINDX_SHIFT);
+
+		if (prot & IOMMU_DEVICE)
+			pteval |= (MAIR_ATTR_IDX_DEV <<
+				   ARM_SMMU_PTE_ATTRINDX_SHIFT);
 	} else {
 		pteval |= ARM_SMMU_PTE_HAP_FAULT;
 		if (prot & IOMMU_READ)
@@ -1273,6 +1277,9 @@ static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd,
 			pteval |= ARM_SMMU_PTE_MEMATTR_OIWB;
 		else
 			pteval |= ARM_SMMU_PTE_MEMATTR_NC;
+
+		if (prot & IOMMU_DEVICE)
+			pteval |= ARM_SMMU_PTE_MEMATTR_DEV;
 	}
 
 	/* If no access, create a faulting entry to avoid TLB fills */
Signature · 1 line
1.7.9.5

A message that is not in the archive (sent off-list or not yet received): 1412591296-31934-2-git-send-email-Varun.Sethi-KZfg59tc24xl57MIdRCFDg@public.gmane.org

#4 lore raw

Re: [RFC][PATCH 2/2] Add support of the IOMMU_DEVICE flag.

Quoted 15 lines · Varun Sethi

This flag is used for specifying access to device memory. SMMU would apply device memory attributes for a DMA transaction. This is required for setting access to GIC registers, for generating message interrupts. This would ensure that transactions targetting device memory are not gathered or reordered.

---
 drivers/iommu/arm-smmu.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/iommu/arm-smmu.c +0 -0
index ca18d6d..f8338d6 100644

drivers/iommu/arm-smmu.c static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd, · line 1269

Quoted 7 lines
drivers/iommu/arm-smmu.c +4 -0
@@ -1263,6 +1263,10 @@ static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd,
 		if (prot & IOMMU_CACHE)
 			pteval |= (MAIR_ATTR_IDX_CACHE <<
 				   ARM_SMMU_PTE_ATTRINDX_SHIFT);
+
+		if (prot & IOMMU_DEVICE)
+			pteval |= (MAIR_ATTR_IDX_DEV <<
+				   ARM_SMMU_PTE_ATTRINDX_SHIFT);

This is slightly odd, as I could in theory pass IOMMU_CACHE | IOMMU_DEVICE to iommu_map.

Will

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

RE: [RFC][PATCH 2/2] Add support of the IOMMU_DEVICE flag.

Quoted 27 lines

-----Original Message-----
From: Will Deacon [mailto:[email protected]]
Sent: Monday, October 06, 2014 4:47 PM
To: Sethi Varun-B16395
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: Re: [RFC][PATCH 2/2] Add support of the IOMMU_DEVICE flag.

Quoted 4 lines · Varun Sethi

This flag is used for specifying access to device memory. SMMU would apply device memory attributes for a DMA transaction. This is required for setting access to GIC registers, for generating message interrupts. This would ensure that transactions targetting device memory are

not gathered or reordered.

drivers/iommu/arm-smmu.c static int arm_smmu_alloc_init_pte(struct

Quoted 11 lines
---
 drivers/iommu/arm-smmu.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/iommu/arm-smmu.c index renamed from drivers/iommu/arm-smmu.c +0 -0

ca18d6d..f8338d6 100644

drivers/iommu/arm-smmu.c +0 -0
@@ -1263,6 +1263,10 @@ static int arm_smmu_alloc_init_pte(struct

arm_smmu_device *smmu, pmd_t *pmd,

Quoted 10 lines

drivers/iommu/arm-smmu.c static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd, · line 1269

Quoted 7 lines
drivers/iommu/arm-smmu.c +4 -0
 		if (prot & IOMMU_CACHE)
 			pteval |= (MAIR_ATTR_IDX_CACHE <<
 				   ARM_SMMU_PTE_ATTRINDX_SHIFT);
+
+		if (prot & IOMMU_DEVICE)
+			pteval |= (MAIR_ATTR_IDX_DEV <<
+				   ARM_SMMU_PTE_ATTRINDX_SHIFT);

This is slightly odd, as I could in theory pass IOMMU_CACHE | IOMMU_DEVICE to iommu_map.

Agreed, this should only be relevant for the non-cacheable case.

-Varun

#7 lore raw

Re: [RFC][PATCH 2/2] Add support of the IOMMU_DEVICE flag.

In reply to a message not in the archive
Quoted 3 lines · Varun Sethi

This flag is used for specifying access to device memory. SMMU would apply device memory attributes for a DMA transaction. This is required for setting access to GIC registers, for generating message interrupts. This would ensure that

Nit: long line and trailing whitespace.

-Mitch

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#8 lore raw
In reply to a message not in the archive

Hi Varun,

[adding the Qualcomm guys, as I have an open question below]

Quoted 13 lines · Varun Sethi

This is used for indicating device memory type for a DMA transaction. IOMMU driver would set up attributes indicationg access to device memory.

---
 include/linux/iommu.h |    1 +
 1 file changed, 1 insertion(+)
include/linux/iommu.h +0 -0
index 20f9a52..0599fe1 100644

include/linux/iommu.h line 31

Quoted 4 lines
include/linux/iommu.h +1 -0
@@ -28,6 +28,7 @@
 #define IOMMU_WRITE	(1 << 1)
 #define IOMMU_CACHE	(1 << 2) /* DMA cache coherency */
 #define IOMMU_EXEC	(1 << 3)
+#define IOMMU_DEVICE	(1 << 4) /* Indicates access to device memory */

An alternative to this would be to make device-memory the default type for !IOMMU_CACHE mappings (i.e. MAIR index 0).

I'd value feedback either way; the argument comes down to whether we should use normal non-cacheable or device-nGnRE as the default (!IOMMU_CACHE) memory type. The latter is likely to be significantly slower, but provides the ordering guarantees that you need for MSI delivery.

If we do go down the route of adding a new IOMMU_* option, it probably needs a better name (IOMMU_MMIO, for example).

Will

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Hi Will,

Quoted 35 lines

-----Original Message-----
From: Will Deacon [mailto:[email protected]]
Sent: Monday, October 06, 2014 4:34 PM
To: Sethi Varun-B16395
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; [email protected]; [email protected]
Subject: Re: [RFC][PATCH 1/2] Introduce the IOMMU_DEVICE flag.

Hi Varun,

[adding the Qualcomm guys, as I have an open question below]

Quoted 13 lines · Varun Sethi

This is used for indicating device memory type for a DMA transaction. IOMMU driver would set up attributes indicationg access to device memory.

---
 include/linux/iommu.h |    1 +
 1 file changed, 1 insertion(+)
include/linux/iommu.h index renamed from include/linux/iommu.h +0 -0

20f9a52..0599fe1 100644

include/linux/iommu.h line 31

Quoted 4 lines
include/linux/iommu.h +1 -0
@@ -28,6 +28,7 @@
 #define IOMMU_WRITE	(1 << 1)
 #define IOMMU_CACHE	(1 << 2) /* DMA cache coherency */
 #define IOMMU_EXEC	(1 << 3)
+#define IOMMU_DEVICE	(1 << 4) /* Indicates access to device memory

*/

An alternative to this would be to make device-memory the default type for !IOMMU_CACHE mappings (i.e. MAIR index 0).

Quoted 7 lines

I'd value feedback either way; the argument comes down to whether we should use normal non-cacheable or device-nGnRE as the default (!IOMMU_CACHE) memory type. The latter is likely to be significantly slower, but provides the ordering guarantees that you need for MSI delivery.

If we do go down the route of adding a new IOMMU_* option, it probably needs a better name (IOMMU_MMIO, for example).

I think it would be better to have a separate flag for handling DMA access to device memory. There might be cases where we might want DMA accesses to be non cacheable. This may be required for preventing cache evictions (depending on the cache size).

-Varun

#11 lore raw
In reply to a message not in the archive
Quoted 26 lines · Will Deacon

Hi Varun,

[adding the Qualcomm guys, as I have an open question below]

Quoted 13 lines · Varun Sethi

This is used for indicating device memory type for a DMA transaction. IOMMU driver would set up attributes indicationg access to device memory.

---
  include/linux/iommu.h |    1 +
  1 file changed, 1 insertion(+)
include/linux/iommu.h +0 -0
index 20f9a52..0599fe1 100644

include/linux/iommu.h line 31

Quoted 4 lines
include/linux/iommu.h +1 -0
@@ -28,6 +28,7 @@
  #define IOMMU_WRITE	(1 << 1)
  #define IOMMU_CACHE	(1 << 2) /* DMA cache coherency */
  #define IOMMU_EXEC	(1 << 3)
+#define IOMMU_DEVICE	(1 << 4) /* Indicates access to device memory */

An alternative to this would be to make device-memory the default type for !IOMMU_CACHE mappings (i.e. MAIR index 0).

Quoted 4 lines

I'd value feedback either way; the argument comes down to whether we should use normal non-cacheable or device-nGnRE as the default (!IOMMU_CACHE) memory type. The latter is likely to be significantly slower, but provides the ordering guarantees that you need for MSI delivery.

We would prefer to stay with normal non-cacheable as the default since this is our most common use case and this is what is the default now.

.Olav

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation