Skip to contentSkip to conversation

iommu/fsl: Freescale PAMU driver and IOMMU API implementation.

PATCH Superseded Varun Sethi 8 participants 30 messages Mar 28, 2013 – Jun 20, 2013

Subsystems (8)

v11 of 18 Superseded Latest is v18 →

lore
Share & tools
lore
#0 lore raw

v11 cover iommu/fsl: Freescale PAMU driver and IOMMU API implementation.

This patchset provides the Freescale PAMU (Peripheral Access Management Unit) driver and the corresponding IOMMU API implementation. PAMU is the IOMMU present on Freescale QorIQ platforms. PAMU can authorize memory access, remap the memory address, and remap the I/O transaction type.

This set consists of the following patches:
1. Make iova dma_addr_t in the iommu_iova_to_phys API.
2. Addition of new field in the device (powerpc) archdata structure for storing iommu domain information pointer.
3. Add window permission flags in the iommu_domain_window_enable API.
4. Add domain attributes for FSL PAMU driver.
5. PAMU driver and IOMMU API implementation.

This patch set is based on the next branch Joerg's iommu git tree.

Varun Sethi (5):
Make iova dma_addr_t in the iommu_iova_to_phys API.
Add iommu domain pointer to device archdata
Add the window permission flag as a parameter to iommu_window_enable API.
Add addition iommu attributes required by the PAMU driver. FSL PAMU driver.

 arch/powerpc/include/asm/device.h |    6 +
 arch/powerpc/sysdev/fsl_pci.h     |    5 +
 drivers/iommu/Kconfig             |    8 +
 drivers/iommu/Makefile            |    1 +
 drivers/iommu/amd_iommu.c         |    2 +-
 drivers/iommu/exynos-iommu.c      |    2 +-
 drivers/iommu/fsl_pamu.c          | 1269 +++++++++++++++++++++++++++++++++++++
 drivers/iommu/fsl_pamu.h          |  405 ++++++++++++
 drivers/iommu/fsl_pamu_domain.c   | 1137 +++++++++++++++++++++++++++++++++
 drivers/iommu/fsl_pamu_domain.h   |   85 +++
 drivers/iommu/intel-iommu.c       |    2 +-
 drivers/iommu/iommu.c             |    8 +-
 drivers/iommu/msm_iommu.c         |    2 +-
 drivers/iommu/omap-iommu.c        |    2 +-
 drivers/iommu/shmobile-iommu.c    |    2 +-
 drivers/iommu/tegra-gart.c        |    2 +-
 drivers/iommu/tegra-smmu.c        |    2 +-
 include/linux/iommu.h             |   51 ++-
 18 files changed, 2970 insertions(+), 21 deletions(-)
 create mode 100644 drivers/iommu/fsl_pamu.c
 create mode 100644 drivers/iommu/fsl_pamu.h
 create mode 100644 drivers/iommu/fsl_pamu_domain.c
 create mode 100644 drivers/iommu/fsl_pamu_domain.h
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v11 1/5 iommu/fsl: Make iova dma_addr_t in the iommu_iova_to_phys API.

This is required in case of PAMU, as it can support a window size of up to 64G (even on 32bit).

---
changes in v11:
- Made iova dma_addr_t instead of u64.
- no change in v10.

 drivers/iommu/amd_iommu.c      |    2 +-
 drivers/iommu/exynos-iommu.c   |    2 +-
 drivers/iommu/intel-iommu.c    |    2 +-
 drivers/iommu/iommu.c          |    3 +--
 drivers/iommu/msm_iommu.c      |    2 +-
 drivers/iommu/omap-iommu.c     |    2 +-
 drivers/iommu/shmobile-iommu.c |    2 +-
 drivers/iommu/tegra-gart.c     |    2 +-
 drivers/iommu/tegra-smmu.c     |    2 +-
 include/linux/iommu.h          |    9 +++------
 10 files changed, 12 insertions(+), 16 deletions(-)
drivers/iommu/amd_iommu.c +1 -1
index 98f555d..ee5431d 100644
@@ -3412,7 +3412,7 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
 }
 
 static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
-					  unsigned long iova)
+					  dma_addr_t iova)
 {
 	struct protection_domain *domain = dom->priv;
 	unsigned long offset_mask;
drivers/iommu/exynos-iommu.c +1 -1
index 238a3ca..3f32d64 100644
@@ -1027,7 +1027,7 @@ done:
 }
 
 static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *domain,
-					  unsigned long iova)
+					  dma_addr_t iova)
 {
 	struct exynos_iommu_domain *priv = domain->priv;
 	unsigned long *entry;
drivers/iommu/intel-iommu.c +1 -1
index 0099667..6e0b9ff 100644
@@ -4111,7 +4111,7 @@ static size_t intel_iommu_unmap(struct iommu_domain *domain,
 }
 
 static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
-					    unsigned long iova)
+					    dma_addr_t iova)
 {
 	struct dmar_domain *dmar_domain = domain->priv;
 	struct dma_pte *pte;
drivers/iommu/iommu.c +1 -2
index b972d43..f730ed9 100644
@@ -706,8 +706,7 @@ void iommu_detach_group(struct iommu_domain *domain, struct iommu_group *group)
 }
 EXPORT_SYMBOL_GPL(iommu_detach_group);
 
-phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
-			       unsigned long iova)
+phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
 {
 	if (unlikely(domain->ops->iova_to_phys == NULL))
 		return 0;
drivers/iommu/msm_iommu.c +1 -1
index 6a8870a..8ab4f41 100644
@@ -554,7 +554,7 @@ fail:
 }
 
 static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain,
-					  unsigned long va)
+					  dma_addr_t va)
 {
 	struct msm_priv *priv;
 	struct msm_iommu_drvdata *iommu_drvdata;
drivers/iommu/omap-iommu.c +1 -1
index 6ac02fa..e02e5d7 100644
@@ -1219,7 +1219,7 @@ static void omap_iommu_domain_destroy(struct iommu_domain *domain)
 }
 
 static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
-					  unsigned long da)
+					  dma_addr_t da)
 {
 	struct omap_iommu_domain *omap_domain = domain->priv;
 	struct omap_iommu *oiommu = omap_domain->iommu_dev;
drivers/iommu/shmobile-iommu.c +1 -1
index b6e8b57..d572863 100644
@@ -296,7 +296,7 @@ done:
 }
 
 static phys_addr_t shmobile_iommu_iova_to_phys(struct iommu_domain *domain,
-					       unsigned long iova)
+					       dma_addr_t iova)
 {
 	struct shmobile_iommu_domain *sh_domain = domain->priv;
 	uint32_t l1entry = 0, l2entry = 0;
drivers/iommu/tegra-gart.c +1 -1
index 8643757..4aec8be 100644
@@ -279,7 +279,7 @@ static size_t gart_iommu_unmap(struct iommu_domain *domain, unsigned long iova,
 }
 
 static phys_addr_t gart_iommu_iova_to_phys(struct iommu_domain *domain,
-					   unsigned long iova)
+					   dma_addr_t iova)
 {
 	struct gart_device *gart = domain->priv;
 	unsigned long pte;
drivers/iommu/tegra-smmu.c +1 -1
index b34e5fd..bc9b599 100644
@@ -757,7 +757,7 @@ static size_t smmu_iommu_unmap(struct iommu_domain *domain, unsigned long iova,
 }
 
 static phys_addr_t smmu_iommu_iova_to_phys(struct iommu_domain *domain,
-					   unsigned long iova)
+					   dma_addr_t iova)
 {
 	struct smmu_as *as = domain->priv;
 	unsigned long *pte;
include/linux/iommu.h +3 -6
index ba3b8a9..bb0a0fc 100644
@@ -91,8 +91,7 @@ struct iommu_ops {
 		   phys_addr_t paddr, size_t size, int prot);
 	size_t (*unmap)(struct iommu_domain *domain, unsigned long iova,
 		     size_t size);
-	phys_addr_t (*iova_to_phys)(struct iommu_domain *domain,
-				    unsigned long iova);
+	phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
 	int (*domain_has_cap)(struct iommu_domain *domain,
 			      unsigned long cap);
 	int (*add_device)(struct device *dev);
@@ -134,8 +133,7 @@ extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
 		     phys_addr_t paddr, size_t size, int prot);
 extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova,
 		       size_t size);
-extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
-				      unsigned long iova);
+extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova);
 extern int iommu_domain_has_cap(struct iommu_domain *domain,
 				unsigned long cap);
 extern void iommu_set_fault_handler(struct iommu_domain *domain,
@@ -267,8 +265,7 @@ static inline void iommu_domain_window_disable(struct iommu_domain *domain,
 {
 }
 
-static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
-					     unsigned long iova)
+static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
 {
 	return 0;
 }
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH v11 2/5 powerpc: Add iommu domain pointer to device archdata

In reply to Varun Sethi

Add an iommu domain pointer to device (powerpc) archdata. Devices are attached to iommu domains and this pointer provides a mechanism to correlate between a device and the associated iommu domain. This field is set when a device is attached to a domain.

---
- no change in v11.
- no change in v10.
- Added CONFIG_IOMMU_API in v9.

 arch/powerpc/include/asm/device.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/device.h +6 -0
index 77e97dd..2d5c1c5 100644
@@ -28,6 +28,12 @@ struct dev_archdata {
 		void		*iommu_table_base;
 	} dma_data;
 
+	/* IOMMU domain information pointer. This would be set
+	 * when this device is attached to an iommu_domain.
+	 */
+#ifdef CONFIG_IOMMU_API
+	void			*iommu_domain;
+#endif
 #ifdef CONFIG_SWIOTLB
 	dma_addr_t		max_direct_dma_addr;
 #endif
Signature · 1 line
1.7.4.1
maintainer
#3 lore raw

Re: [PATCH 2/5 v11] powerpc: Add iommu domain pointer to device archdata

Quoted 6 lines · Varun Sethi

Add an iommu domain pointer to device (powerpc) archdata. Devices are attached to iommu domains and this pointer provides a mechanism to correlate between a device and the associated iommu domain. This field is set when a device is attached to a domain.

This patch needs to be Acked by the PPC maintainers.

#4 lore raw

RE: [PATCH 2/5 v11] powerpc: Add iommu domain pointer to device archdata

Kumar/Ben,
Any comments?

(Had checked with Ben (on IRC) sometime back, he was fine with this patch)

Regards
Varun

Quoted 22 lines

-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Tuesday, April 02, 2013 8:39 PM
To: Sethi Varun-B16395
Cc: Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs/[email protected] foundation.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/5 v11] powerpc: Add iommu domain pointer to device
archdata

Quoted 6 lines · Varun Sethi

Add an iommu domain pointer to device (powerpc) archdata. Devices are attached to iommu domains and this pointer provides a mechanism to correlate between a device and the associated iommu domain. This field is set when a device is attached to a domain.

This patch needs to be Acked by the PPC maintainers.

Acked-by on v11 2/5
#5 lore raw

Re: [PATCH 2/5 v11] powerpc: Add iommu domain pointer to device archdata

In reply to Varun Sethi
Quoted 5 lines · Varun Sethi

Add an iommu domain pointer to device (powerpc) archdata. Devices are attached to iommu domains and this pointer provides a mechanism to correlate between a device and the associated iommu domain. This field is set when a device is attached to a domain.

Quoted 7 lines

---
- no change in v11.
- no change in v10.
- Added CONFIG_IOMMU_API in v9.
arch/powerpc/include/asm/device.h | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)

- k

#6 lore raw

RE: [PATCH 2/5 v11] powerpc: Add iommu domain pointer to device archdata

Hi Joerg,
My PAMU driver patches depend on this patch which was Ack by Kumar. Should I resubmit this patch as well?

Regards
Varun

Quoted 29 lines

-----Original Message-----
From: Kumar Gala [mailto:[email protected]]
Sent: Thursday, April 11, 2013 11:46 PM
To: Sethi Varun-B16395
Cc: [email protected]; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 2/5 v11] powerpc: Add iommu domain pointer to device
archdata

Quoted 5 lines · Varun Sethi

Add an iommu domain pointer to device (powerpc) archdata. Devices are attached to iommu domains and this pointer provides a mechanism to correlate between a device and the associated iommu domain. This field is set when a device is attached to a domain.

Quoted 7 lines

---
- no change in v11.
- no change in v10.
- Added CONFIG_IOMMU_API in v9.
arch/powerpc/include/asm/device.h | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)

- k

#7 lore raw

Re: [PATCH 2/5 v11] powerpc: Add iommu domain pointer to device archdata

Quoted 2 lines · On Thu, Jun 20, 2013 at 02:29:30PM +0000, Sethi Varun-B16395 wrote:

Hi Joerg,
My PAMU driver patches depend on this patch which was Ack by Kumar. Should I resubmit this patch as well?

Yes, please. Add the collected Acked-bys and submit everything that is missing in v3.10-rc6.

Joerg

#8 lore raw

PATCH v11 3/5 iommu/fsl: Add the window permission flag as a parameter to iommu_window_enable API.

In reply to Varun Sethi

Each iommu window can have access permissions associated with it. Extended the window_enable API to incorporate window access permissions.

In case of PAMU each window can have its specific set of permissions.

---
- no change in v11.
- no change in v10.

 drivers/iommu/iommu.c |    5 +++--
 include/linux/iommu.h |    7 ++++---
 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/iommu/iommu.c +3 -2
index f730ed9..1d72b4f 100644
@@ -853,12 +853,13 @@ EXPORT_SYMBOL_GPL(iommu_unmap);
 
 
 int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
-			       phys_addr_t paddr, u64 size)
+			       phys_addr_t paddr, u64 size, int prot)
 {
 	if (unlikely(domain->ops->domain_window_enable == NULL))
 		return -ENODEV;
 
-	return domain->ops->domain_window_enable(domain, wnd_nr, paddr, size);
+	return domain->ops->domain_window_enable(domain, wnd_nr, paddr, size,
+						 prot);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_window_enable);
 
include/linux/iommu.h +4 -3
index bb0a0fc..2727810 100644
@@ -104,7 +104,7 @@ struct iommu_ops {
 
 	/* Window handling functions */
 	int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
-				    phys_addr_t paddr, u64 size);
+				    phys_addr_t paddr, u64 size, int prot);
 	void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
 	/* Set the numer of window per domain */
 	int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count);
@@ -169,7 +169,8 @@ extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr,
 
 /* Window handling function prototypes */
 extern int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
-				      phys_addr_t offset, u64 size);
+				      phys_addr_t offset, u64 size,
+				      int prot);
 extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr);
 /**
  * report_iommu_fault() - report about an IOMMU fault to the IOMMU framework
@@ -255,7 +256,7 @@ static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
 
 static inline int iommu_domain_window_enable(struct iommu_domain *domain,
 					     u32 wnd_nr, phys_addr_t paddr,
-					     u64 size)
+					     u64 size, int prot)
 {
 	return -ENODEV;
 }
Signature · 1 line
1.7.4.1
#9 lore raw

PATCH v11 4/5 iommu/fsl: Add additional iommu attributes required by the PAMU driver.

In reply to Varun Sethi

Added the following domain attributes for the FSL PAMU driver:
1. Added new iommu stash attribute, which allows setting of the LIODN specific stash id parameter through IOMMU API.
2. Added an attribute for enabling/disabling DMA to a particular memory window.
3. Added domain attribute to check for PAMUV1 specific constraints.

---
- no change in v11.
- no change in v10.

 include/linux/iommu.h |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
include/linux/iommu.h +35 -0
index 2727810..af8f996 100644
@@ -40,6 +40,25 @@ struct notifier_block;
 typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
 			struct device *, unsigned long, int, void *);
 
+/* cache stash targets */
+enum stash_target {
+	IOMMU_ATTR_CACHE_L1 = 1,
+	IOMMU_ATTR_CACHE_L2,
+	IOMMU_ATTR_CACHE_L3,
+};
+
+/* This attribute corresponds to IOMMUs capable of generating
+ * a stash transaction. A stash transaction is typically a
+ * hardware initiated prefetch of data from memory to cache.
+ * This attribute allows configuring stashig specific parameters
+ * in the IOMMU hardware.
+ */
+
+struct iommu_stash_attribute {
+	u32 	cpu;	/* cpu number */
+	u32 	cache;	/* cache to stash to: L1,L2,L3 */
+};
+
 struct iommu_domain_geometry {
 	dma_addr_t aperture_start; /* First address that can be mapped    */
 	dma_addr_t aperture_end;   /* Last address that can be mapped     */
@@ -57,10 +76,26 @@ struct iommu_domain {
 #define IOMMU_CAP_CACHE_COHERENCY	0x1
 #define IOMMU_CAP_INTR_REMAP		0x2	/* isolates device intrs */
 
+/*
+ * Following constraints are specifc to PAMUV1:
+ *  -aperture must be power of 2, and naturally aligned
+ *  -number of windows must be power of 2, and address space size
+ *   of each window is determined by aperture size / # of windows
+ *  -the actual size of the mapped region of a window must be power
+ *   of 2 starting with 4KB and physical address must be naturally
+ *   aligned.
+ * DOMAIN_ATTR_FSL_PAMUV1 corresponds to the above mentioned contraints.
+ * The caller can invoke iommu_domain_get_attr to check if the underlying
+ * iommu implementation supports these constraints.
+ */
+
 enum iommu_attr {
 	DOMAIN_ATTR_GEOMETRY,
 	DOMAIN_ATTR_PAGING,
 	DOMAIN_ATTR_WINDOWS,
+	DOMAIN_ATTR_PAMU_STASH,
+	DOMAIN_ATTR_PAMU_ENABLE,
+	DOMAIN_ATTR_FSL_PAMUV1,
 	DOMAIN_ATTR_MAX,
 };
 
Signature · 1 line
1.7.4.1
maintainer
#10 lore raw

Re: [PATCH 4/5 v11] iommu/fsl: Add additional iommu attributes required by the PAMU driver.

Quoted 9 lines · Varun Sethi
include/linux/iommu.h +9 -0
+/* cache stash targets */
+enum stash_target {
+	IOMMU_ATTR_CACHE_L1 = 1,
+	IOMMU_ATTR_CACHE_L2,
+	IOMMU_ATTR_CACHE_L3,
+};
+
+/* This attribute corresponds to IOMMUs capable of generating
+ * a stash transaction. A stash transaction is typically a

include/linux/iommu.h struct notifier_block; · line 61

Quoted 10 lines
include/linux/iommu.h +10 -0
+ * hardware initiated prefetch of data from memory to cache.
+ * This attribute allows configuring stashig specific parameters
+ * in the IOMMU hardware.
+ */
+
+struct iommu_stash_attribute {
+	u32 	cpu;	/* cpu number */
+	u32 	cache;	/* cache to stash to: L1,L2,L3 */
+};
+

I would prefer these PAMU specific enum and struct to be in a pamu-specific iommu-header.

Joerg

#11 lore raw

RE: [PATCH 4/5 v11] iommu/fsl: Add additional iommu attributes required by the PAMU driver.

Quoted 28 lines

-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Tuesday, April 02, 2013 8:40 PM
To: Sethi Varun-B16395
Cc: Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs/[email protected] foundation.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 4/5 v11] iommu/fsl: Add additional iommu attributes
required by the PAMU driver.

Quoted 14 lines · Varun Sethi
include/linux/iommu.h +14 -0
+/* cache stash targets */
+enum stash_target {
+	IOMMU_ATTR_CACHE_L1 = 1,
+	IOMMU_ATTR_CACHE_L2,
+	IOMMU_ATTR_CACHE_L3,
+};
+
+/* This attribute corresponds to IOMMUs capable of generating
+ * a stash transaction. A stash transaction is typically a
+ * hardware initiated prefetch of data from memory to cache.
+ * This attribute allows configuring stashig specific parameters
+ * in the IOMMU hardware.
+ */
+
Quoted 9 lines

include/linux/iommu.h struct notifier_block; · line 61

Quoted 5 lines
include/linux/iommu.h +5 -0
+struct iommu_stash_attribute {
+	u32 	cpu;	/* cpu number */
+	u32 	cache;	/* cache to stash to: L1,L2,L3 */
+};
+

I would prefer these PAMU specific enum and struct to be in a pamu- specific iommu-header.

[Sethi Varun-B16395] But, these would be used by the IOMMU API users (e.g. VFIO), they shouldn't depend on PAMU specific headers.

-Varun

maintainer
#12 lore raw

Re: [PATCH 4/5 v11] iommu/fsl: Add additional iommu attributes required by the PAMU driver.

Quoted 6 lines · On Wed, Apr 03, 2013 at 05:21:16AM +0000, Sethi Varun-B16395 wrote:
Quoted 3 lines

I would prefer these PAMU specific enum and struct to be in a pamu- specific iommu-header.

[Sethi Varun-B16395] But, these would be used by the IOMMU API users (e.g. VFIO), they shouldn't depend on PAMU specific headers.

Drivers that use PAMU specifics (like the PAMU specific VFIO parts) can also include the PAMU specific header.

Joerg

#13 lore raw

PATCH v11 5/5 iommu/fsl: Freescale PAMU driver and iommu implementation.

In reply to Varun Sethi

Following is a brief description of the PAMU hardware:
PAMU determines what action to take and whether to authorize the action on the basis of the memory address, a Logical IO Device Number (LIODN), and PAACT table (logically) indexed by LIODN and address. Hardware devices which need to access memory must provide an LIODN in addition to the memory address.

Peripheral Access Authorization and Control Tables (PAACTs) are the primary data structures used by PAMU. A PAACT is a table of peripheral access authorization and control entries (PAACE).Each PAACE defines the range of I/O bus address space that is accessible by the LIOD and the associated access capabilities.

There are two types of PAACTs: primary PAACT (PPAACT) and secondary PAACT (SPAACT).A given physical I/O device may be able to act as one or more independent logical I/O devices (LIODs). Each such logical I/O device is assigned an identifier called logical I/O device number (LIODN). A LIODN is allocated a contiguous portion of the I/O bus address space called the DSA window for performing DSA operations. The DSA window may optionally be divided into multiple sub-windows, each of which may be used to map to a region in system storage space. The first sub-window is referred to as the primary sub-window and the remaining are called secondary sub-windows.

This patch provides the PAMU driver (fsl_pamu.c) and the corresponding IOMMU API implementation (fsl_pamu_domain.c). The PAMU hardware driver (fsl_pamu.c) has been derived from the work done by Ashish Kalra and Timur Tabi.

---
changes in v11:
- changed iova to dma_addr_t in iova_to_phys API.
changes in v10:
- Support for new guts compatibe string for T4 & B4 devices.
- Modified comment about port ID and mentioned the errata number.
- Fixed the issue where data pointer was not freed in case of a an error.
- Pass data pointer while freeing irq.
- Whle initializing the SPAACE entry clear the valid bit. changes in v9:
- Merged and createad a single function to delete
a device from domain list.
- Refactored the add_device API code.
- Renamed the paace and spaace init fucntions.
- Renamed functions for mapping windows and subwindows.
- Changed the MAX LIODN value to MAX value u-boot can program.
- Hard coded maximum number of subwindows.
changes in v8:
- implemented the new API for window based IOMMUs.
changes in v7:
- Set max_subwidows in the geometry attribute.
- Add checking for maximum supported LIODN value.
- Use upper_32_bits and lower_32_bits macros while intializing PAMU data structures.
changes in v6:
- Simplified complex conditional statements.
- Fixed indentation issues.
- Added comments for IOMMU API implementation.
changes in v5:
- Addressed comments from Timur.
changes in v4:
- Addressed comments from Timur and Scott.
changes in v3:
- Addressed comments by Kumar Gala
- dynamic fspi allocation
- fixed alignment check in map and unmap

 arch/powerpc/sysdev/fsl_pci.h   |    5 +
 drivers/iommu/Kconfig           |    8 +
 drivers/iommu/Makefile          |    1 +
 drivers/iommu/fsl_pamu.c        | 1269 +++++++++++++++++++++++++++++++++++++++
 drivers/iommu/fsl_pamu.h        |  405 +++++++++++++
 drivers/iommu/fsl_pamu_domain.c | 1137 +++++++++++++++++++++++++++++++++++
 drivers/iommu/fsl_pamu_domain.h |   85 +++
 7 files changed, 2910 insertions(+), 0 deletions(-)
 create mode 100644 drivers/iommu/fsl_pamu.c
 create mode 100644 drivers/iommu/fsl_pamu.h
 create mode 100644 drivers/iommu/fsl_pamu_domain.c
 create mode 100644 drivers/iommu/fsl_pamu_domain.h
arch/powerpc/sysdev/fsl_pci.h +5 -0
index c495c00..feb34f6 100644
@@ -14,6 +14,11 @@
 #ifndef __POWERPC_FSL_PCI_H
 #define __POWERPC_FSL_PCI_H
 
+
+/* FSL PCI controller BRR1 register */
+#define PCI_FSL_BRR1      0xbf8
+#define PCI_FSL_BRR1_VER 0xffff
+
 #define PCIE_LTSSM	0x0404		/* PCIE Link Training and Status */
 #define PCIE_LTSSM_L0	0x16		/* L0 state */
 #define PCIE_IP_REV_2_2		0x02080202 /* PCIE IP block version Rev2.2 */
drivers/iommu/Kconfig +8 -0
index c332fb9..3274333 100644
@@ -17,6 +17,14 @@ config OF_IOMMU
        def_bool y
        depends on OF
 
+config FSL_PAMU
+	bool "Freescale IOMMU support"
+	depends on PPC_E500MC
+	select IOMMU_API
+	select GENERIC_ALLOCATOR
+	help
+	  Freescale PAMU support.
+
 # MSM IOMMU support
 config MSM_IOMMU
 	bool "MSM IOMMU Support"
drivers/iommu/Makefile +1 -0
index ef0e520..027d1af 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o
 obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o
 obj-$(CONFIG_SHMOBILE_IOMMU) += shmobile-iommu.o
 obj-$(CONFIG_SHMOBILE_IPMMU) += shmobile-ipmmu.o
+obj-$(CONFIG_FSL_PAMU) += fsl_pamu.o fsl_pamu_domain.o
drivers/iommu/fsl_pamu.c new file +1269 -0

1,269 lines not on this page · raw message

drivers/iommu/fsl_pamu.h new file +405 -0

405 lines not on this page · raw message

drivers/iommu/fsl_pamu_domain.c new file +1137 -0

1,137 lines not on this page · raw message

drivers/iommu/fsl_pamu_domain.h new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#14 lore raw

RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 74 lines

-----Original Message-----
From: Sethi Varun-B16395
Sent: Thursday, March 28, 2013 2:54 PM
To: [email protected]; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc- dev-uLR06cmDAlY/[email protected]; [email protected]; [email protected]; [email protected]
Cc: Sethi Varun-B16395
Subject: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Following is a brief description of the PAMU hardware:
PAMU determines what action to take and whether to authorize the action on the basis of the memory address, a Logical IO Device Number (LIODN), and PAACT table (logically) indexed by LIODN and address. Hardware devices which need to access memory must provide an LIODN in addition to the memory address.

Peripheral Access Authorization and Control Tables (PAACTs) are the primary data structures used by PAMU. A PAACT is a table of peripheral access authorization and control entries (PAACE).Each PAACE defines the range of I/O bus address space that is accessible by the LIOD and the associated access capabilities.

There are two types of PAACTs: primary PAACT (PPAACT) and secondary PAACT (SPAACT).A given physical I/O device may be able to act as one or more independent logical I/O devices (LIODs). Each such logical I/O device is assigned an identifier called logical I/O device number (LIODN). A LIODN is allocated a contiguous portion of the I/O bus address space called the DSA window for performing DSA operations. The DSA window may optionally be divided into multiple sub-windows, each of which may be used to map to a region in system storage space. The first sub-window is referred to as the primary sub-window and the remaining are called secondary sub-windows.

This patch provides the PAMU driver (fsl_pamu.c) and the corresponding IOMMU API implementation (fsl_pamu_domain.c). The PAMU hardware driver (fsl_pamu.c) has been derived from the work done by Ashish Kalra and Timur Tabi.

---
changes in v11:
- changed iova to dma_addr_t in iova_to_phys API.
changes in v10:
- Support for new guts compatibe string for T4 & B4 devices.
- Modified comment about port ID and mentioned the errata number.
- Fixed the issue where data pointer was not freed in case of a an error.
- Pass data pointer while freeing irq.
- Whle initializing the SPAACE entry clear the valid bit. changes in v9:
- Merged and createad a single function to delete
a device from domain list.
- Refactored the add_device API code.
- Renamed the paace and spaace init fucntions.
- Renamed functions for mapping windows and subwindows.
- Changed the MAX LIODN value to MAX value u-boot can program.
- Hard coded maximum number of subwindows.
changes in v8:
- implemented the new API for window based IOMMUs.
changes in v7:
- Set max_subwidows in the geometry attribute.
- Add checking for maximum supported LIODN value.
- Use upper_32_bits and lower_32_bits macros while intializing PAMU data structures.
changes in v6:
- Simplified complex conditional statements.
- Fixed indentation issues.
- Added comments for IOMMU API implementation.
changes in v5:
- Addressed comments from Timur.
changes in v4:
- Addressed comments from Timur and Scott.
changes in v3:
- Addressed comments by Kumar Gala
- dynamic fspi allocation
- fixed alignment check in map and unmap

Quoted 12 lines
 arch/powerpc/sysdev/fsl_pci.h   |    5 +
 drivers/iommu/Kconfig           |    8 +
 drivers/iommu/Makefile          |    1 +
 drivers/iommu/fsl_pamu.c        | 1269 +++++++++++++++++++++++++++++++++++++++
 drivers/iommu/fsl_pamu.h        |  405 +++++++++++++
 drivers/iommu/fsl_pamu_domain.c | 1137 +++++++++++++++++++++++++++++++++++
 drivers/iommu/fsl_pamu_domain.h |   85 +++
 7 files changed, 2910 insertions(+), 0 deletions(-)
 create mode 100644 drivers/iommu/fsl_pamu.c
 create mode 100644 drivers/iommu/fsl_pamu.h
 create mode 100644 drivers/iommu/fsl_pamu_domain.c
 create mode 100644 drivers/iommu/fsl_pamu_domain.h

Ack.

Stuart

maintainer
#15 lore raw

Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

In reply to Varun Sethi

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

My comments so far are below:

drivers/iommu/Kconfig config OF_IOMMU · line 26

Quoted 7 lines · Varun Sethi
drivers/iommu/Kconfig +7 -0
+config FSL_PAMU
+	bool "Freescale IOMMU support"
+	depends on PPC_E500MC
+	select IOMMU_API
+	select GENERIC_ALLOCATOR
+	help
+	  Freescale PAMU support.

A bit lame for a help text. Can you elaborate more what PAMU is and when it should be enabled?

Quoted 10 lines
drivers/iommu/fsl_pamu.c new file +10 -0
+int pamu_enable_liodn(int liodn)
+{
+	struct paace *ppaace;
+
+	ppaace = pamu_get_ppaace(liodn);
+	if (!ppaace) {
+		pr_err("Invalid primary paace entry\n");
+		return -ENOENT;
+	}
+

drivers/iommu/fsl_pamu.c line 127

Quoted 10 lines
drivers/iommu/fsl_pamu.c new file +10 -0
+	if (!get_bf(ppaace->addr_bitfields, PPAACE_AF_WSE)) {
+		pr_err("liodn %d not configured\n", liodn);
+		return -EINVAL;
+	}
+
+	/* Ensure that all other stores to the ppaace complete first */
+	mb();
+
+	ppaace->addr_bitfields |= PAACE_V_VALID;
+	mb();

Why is it sufficient to set the bit in a variable when enabling liodn but when disabling it set_bf needs to be called? This looks a bit assymetric.

drivers/iommu/fsl_pamu.c line 158

Quoted 5 lines
drivers/iommu/fsl_pamu.c new file +5 -0
+/* Derive the window size encoding for a particular PAACE entry */
+static unsigned int map_addrspace_size_to_wse(phys_addr_t addrspace_size)
+{
+	/* Bug if not a power of 2 */
+	BUG_ON((addrspace_size & (addrspace_size - 1)));

Please use is_power_of_2 here.

drivers/iommu/fsl_pamu.c line 161

Quoted 3 lines
drivers/iommu/fsl_pamu.c new file +3 -0
+
+	/* window size is 2^(WSE+1) bytes */
+	return __ffs(addrspace_size >> PAMU_PAGE_SHIFT) + PAMU_PAGE_SHIFT - 1;

The PAMU_PAGE_SHIFT shifting and adding looks redundant.

drivers/iommu/fsl_pamu.c line 347

Quoted 9 lines
drivers/iommu/fsl_pamu.c new file +9 -0
+	if ((win_size & (win_size - 1)) || win_size < PAMU_PAGE_SIZE) {
+		pr_err("window size too small or not a power of two %llx\n", win_size);
+		return -EINVAL;
+	}
+
+	if (win_addr & (win_size - 1)) {
+		pr_err("window address is not aligned with window size\n");
+		return -EINVAL;
+	}

Again, use is_power_of_2 instead of hand-coding.

drivers/iommu/fsl_pamu.c line 490

Quoted 7 lines
drivers/iommu/fsl_pamu.c new file +7 -0
+	if (~stashid != 0)
+		set_bf(paace->impl_attr, PAACE_IA_CID, stashid);
+
+	smp_wmb();
+
+	if (enable)
+		paace->addr_bitfields |= PAACE_V_VALID;

Havn't you written a helper funtion to set this bit?

Quoted 28 lines
drivers/iommu/fsl_pamu.c new file +28 -0
+irqreturn_t pamu_av_isr(int irq, void *arg)
+{
+	struct pamu_isr_data *data = arg;
+	phys_addr_t phys;
+	unsigned int i, j;
+
+	pr_emerg("fsl-pamu: access violation interrupt\n");
+
+	for (i = 0; i < data->count; i++) {
+		void __iomem *p = data->pamu_reg_base + i * PAMU_OFFSET;
+		u32 pics = in_be32(p + PAMU_PICS);
+
+		if (pics & PAMU_ACCESS_VIOLATION_STAT) {
+			pr_emerg("POES1=%08x\n", in_be32(p + PAMU_POES1));
+			pr_emerg("POES2=%08x\n", in_be32(p + PAMU_POES2));
+			pr_emerg("AVS1=%08x\n", in_be32(p + PAMU_AVS1));
+			pr_emerg("AVS2=%08x\n", in_be32(p + PAMU_AVS2));
+			pr_emerg("AVA=%016llx\n", make64(in_be32(p + PAMU_AVAH),
+				in_be32(p + PAMU_AVAL)));
+			pr_emerg("UDAD=%08x\n", in_be32(p + PAMU_UDAD));
+			pr_emerg("POEA=%016llx\n", make64(in_be32(p + PAMU_POEAH),
+				in_be32(p + PAMU_POEAL)));
+
+			phys = make64(in_be32(p + PAMU_POEAH),
+				in_be32(p + PAMU_POEAL));
+
+			/* Assume that POEA points to a PAACE */
+			if (phys) {

drivers/iommu/fsl_pamu.c line 793

Quoted 10 lines
drivers/iommu/fsl_pamu.c new file +10 -0
+				u32 *paace = phys_to_virt(phys);
+
+				/* Only the first four words are relevant */
+				for (j = 0; j < 4; j++)
+					pr_emerg("PAACE[%u]=%08x\n", j, in_be32(paace + j));
+			}
+		}
+	}
+
+	panic("\n");

A kernel panic seems like an over-reaction to an access violation. Besides the device that caused the violation the system should still work, no?

Quoted 1 line

+#define make64(high, low) (((u64)(high) << 32) | (low))

You redefined this make64 here.

drivers/iommu/fsl_pamu_domain.c line 122

Quoted 12 lines
drivers/iommu/fsl_pamu_domain.c new file +12 -0
+static int map_subwins(int liodn, struct fsl_dma_domain *dma_domain)
+{
+	struct dma_window *sub_win_ptr =
+				&dma_domain->win_arr[0];
+	int i, ret;
+	unsigned long rpn;
+
+	for (i = 0; i < dma_domain->win_cnt; i++) {
+		if (sub_win_ptr[i].valid) {
+			rpn = sub_win_ptr[i].paddr >>
+				 PAMU_PAGE_SHIFT;
+			spin_lock(&iommu_lock);

IOMMU code might run in interrupt context, so please use spin_lock_irqsave for the iommu_lock.

Quoted 6 lines
drivers/iommu/fsl_pamu_domain.c new file +6 -0
+static void detach_device(struct device *dev, struct fsl_dma_domain *dma_domain)
+{
+	struct device_domain_info *info;
+	struct list_head *entry, *tmp;
+	unsigned long flags;
+

drivers/iommu/fsl_pamu_domain.c line 369

Quoted 10 lines
drivers/iommu/fsl_pamu_domain.c new file +10 -0
+	spin_lock_irqsave(&dma_domain->domain_lock, flags);
+	/* Remove the device from the domain device list */
+	if (!list_empty(&dma_domain->devices)) {
+		list_for_each_safe(entry, tmp, &dma_domain->devices) {
+			info = list_entry(entry, struct device_domain_info, link);
+			if (!dev || (info->dev == dev))
+				remove_device_ref(info, dma_domain->win_cnt);
+		}
+	}
+	spin_unlock_irqrestore(&dma_domain->domain_lock, flags);

list_empty check is not needed. You can also use
list_for_each_entry_safe.

Quoted 21 lines
drivers/iommu/fsl_pamu_domain.c new file +21 -0
+static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct device *dev)
+{
+	struct device_domain_info *info, *old_domain_info;
+
+	spin_lock(&device_domain_lock);
+	/*
+	 * Check here if the device is already attached to domain or not.
+	 * If the device is already attached to a domain detach it.
+	 */
+	old_domain_info = find_domain(dev);
+	if (old_domain_info && old_domain_info->domain != dma_domain) {
+		spin_unlock(&device_domain_lock);
+		detach_device(dev, old_domain_info->domain);
+		spin_lock(&device_domain_lock);
+	}
+
+	info = kmem_cache_zalloc(iommu_devinfo_cache, GFP_KERNEL);
+
+	info->dev = dev;
+	info->liodn = liodn;
+	info->domain = dma_domain;

drivers/iommu/fsl_pamu_domain.c line 402

Quoted 10 lines
drivers/iommu/fsl_pamu_domain.c new file +10 -0
+
+	list_add(&info->link, &dma_domain->devices);
+	/*
+	 * In case of devices with multiple LIODNs just store
+	 * the info for the first LIODN as all
+	 * LIODNs share the same domain
+	 */
+	if (!old_domain_info)
+		dev->archdata.iommu_domain = info;
+	spin_unlock(&device_domain_lock);

Don't you have to tell the hardware that a device was added to a domain? I don't see that, what I am missing?

drivers/iommu/fsl_pamu_domain.c line 907

Quoted 5 lines
drivers/iommu/fsl_pamu_domain.c new file +5 -0
+static void swap_pci_ref(struct pci_dev **from, struct pci_dev *to)
+{
+	pci_dev_put(*from);
+	*from = to;
+}

Hmm, looks like this function is re-implemented in a few IOMMU drivers. Want to use the chance to consolidate these implementations?

Joerg

#16 lore raw

Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 3 lines · Joerg Roedel
Quoted 1 line

+ panic("\n");

A kernel panic seems like an over-reaction to an access violation.

We have no way to determining what code caused the violation, so we can't just kill the process. I agree it seems like overkill, but what else should we do? Does the IOMMU layer have a way for the IOMMU driver to stop the device that caused the problem?

Quoted 2 lines

Besides the device that caused the violation the system should still work, no?

Not really. The PAMU was designed to add IOMMU support to legacy devices, which have no concept of an MMU. If the PAMU detects an access violation, there's no way for the device to recover, because it has no idea that a violation has occurred. It's going to keep on writing to bad data.

Maybe we need a mechanism where a driver can register a callback function to handle IOMMU exceptions?

Quoted 11 lines

drivers/iommu/fsl_pamu_domain.c line 402

Quoted 8 lines
drivers/iommu/fsl_pamu_domain.c new file +8 -0
+     /*
+      * In case of devices with multiple LIODNs just store
+      * the info for the first LIODN as all
+      * LIODNs share the same domain
+      */
+     if (!old_domain_info)
+             dev->archdata.iommu_domain = info;
+     spin_unlock(&device_domain_lock);

Don't you have to tell the hardware that a device was added to a domain? I don't see that, what I am missing?

I'm not sure I understand. What "hardware" do you think needs to be notified?

The PAMU reads everything it needs from the PAACT, which we update. The PAMU does not know anything about the devices that it monitors, and the devices don't know anything about the PAMU.

#17 lore raw

Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 10 lines · Timur Tabi
Quoted 3 lines · Joerg Roedel
Quoted 1 line

+ panic("\n");

A kernel panic seems like an over-reaction to an access violation.

We have no way to determining what code caused the violation, so we can't just kill the process. I agree it seems like overkill, but what else should we do? Does the IOMMU layer have a way for the IOMMU driver to stop the device that caused the problem?

At a minimum, log a message and continue. Probably turn off the LIODN, at least if it continues to be noisy (otherwise we could get stuck in an interrupt storm as you note). Possibly let the user know somehow, especially if it's a VFIO domain.

Don't take down the whole kernel. It's not just overkill; it undermines VFIO's efforts to make it safe for users to control devices.

Quoted 8 lines
Quoted 2 lines

Besides the device that caused the violation the system should still work, no?

Not really. The PAMU was designed to add IOMMU support to legacy devices, which have no concept of an MMU. If the PAMU detects an access violation, there's no way for the device to recover, because it has no idea that a violation has occurred. It's going to keep on writing to bad data.

I think that's only the case for posted writes (or devices which fail to take a hint and stop even after they see an I/O error).

-Scott

#18 lore raw

RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 24 lines

-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, April 03, 2013 7:23 AM
To: Timur Tabi
Cc: Joerg Roedel; Sethi Varun-B16395; lkml; Kumar Gala; Yoder Stuart-
B08248; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; Benjamin Herrenschmidt; linuxppc-dev-uLR06cmDAlY/[email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 10 lines · Timur Tabi
Quoted 3 lines · Joerg Roedel
Quoted 1 line

+ panic("\n");

A kernel panic seems like an over-reaction to an access violation.

We have no way to determining what code caused the violation, so we can't just kill the process. I agree it seems like overkill, but what else should we do? Does the IOMMU layer have a way for the IOMMU driver to stop the device that caused the problem?

Quoted 4 lines

At a minimum, log a message and continue. Probably turn off the LIODN, at least if it continues to be noisy (otherwise we could get stuck in an interrupt storm as you note). Possibly let the user know somehow, especially if it's a VFIO domain.

[Sethi Varun-B16395] Can definitely log the message and disable the LIODN (to avoid an interrupt storm), but we definitely need a mechanism to inform vfio subsystem about the error. Also, disabling LIODN may not be a viable option with the new LIODN allocation scheme (where LIODN would be associated with a domain).

Quoted 7 lines

Don't take down the whole kernel. It's not just overkill; it undermines VFIO's efforts to make it safe for users to control devices.

Quoted 3 lines
Quoted 2 lines

Besides the device that caused the violation the system should still work, no?

Quoted 9 lines
Quoted 5 lines

Not really. The PAMU was designed to add IOMMU support to legacy devices, which have no concept of an MMU. If the PAMU detects an access violation, there's no way for the device to recover, because it has no idea that a violation has occurred. It's going to keep on writing to bad data.

I think that's only the case for posted writes (or devices which fail to take a hint and stop even after they see an I/O error).

[Sethi Varun-B16395] Even in the case where the guest driver detects a failure, it may not be able to fix the problem without intervention from the VFIO subsystem.

-Varun

#19 lore raw

RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 38 lines

-----Original Message-----
From: Sethi Varun-B16395
Sent: Wednesday, April 03, 2013 12:12 AM
To: Wood Scott-B07421; Timur Tabi
Cc: Joerg Roedel; lkml; Kumar Gala; Yoder Stuart-B08248; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; Benjamin Herrenschmidt; linuxppc-dev-uLR06cmDAlY/[email protected]
Subject: RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 22 lines

-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, April 03, 2013 7:23 AM
To: Timur Tabi
Cc: Joerg Roedel; Sethi Varun-B16395; lkml; Kumar Gala; Yoder Stuart-
B08248; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; Benjamin Herrenschmidt; linuxppc-dev-uLR06cmDAlY/[email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 10 lines · Timur Tabi
Quoted 3 lines · Joerg Roedel
Quoted 1 line

+ panic("\n");

A kernel panic seems like an over-reaction to an access violation.

We have no way to determining what code caused the violation, so we can't just kill the process. I agree it seems like overkill, but what else should we do? Does the IOMMU layer have a way for the IOMMU driver to stop the device that caused the problem?

Quoted 4 lines

At a minimum, log a message and continue. Probably turn off the LIODN, at least if it continues to be noisy (otherwise we could get stuck in an interrupt storm as you note). Possibly let the user know somehow, especially if it's a VFIO domain.

Quoted 5 lines

[Sethi Varun-B16395] Can definitely log the message and disable the LIODN (to avoid an interrupt storm), but
we definitely need a mechanism to inform vfio subsystem about the error. Also, disabling LIODN may not be a viable
option with the new LIODN allocation scheme (where LIODN would be associated with a domain).

I think for phase 1 of this, just log the error, shut down DMA as you described. We can implement more full featured error management, like notifying vfio or the VM somehow in the future.

Stuart

#20 lore raw

RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

In reply to Joerg Roedel
Quoted 20 lines

-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Tuesday, April 02, 2013 9:48 PM
To: Sethi Varun-B16395
Cc: Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs/[email protected] foundation.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]; Alex Williamson
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu
implementation.

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

My comments so far are below:

On Fri, Mar 29, 2013 at 01:24:02AM +0530, Varun Sethi wrote:

Quoted 11 lines

drivers/iommu/Kconfig config OF_IOMMU · line 26

Quoted 7 lines
drivers/iommu/Kconfig +7 -0
+config FSL_PAMU
+	bool "Freescale IOMMU support"
+	depends on PPC_E500MC
+	select IOMMU_API
+	select GENERIC_ALLOCATOR
+	help
+	  Freescale PAMU support.

A bit lame for a help text. Can you elaborate more what PAMU is and when it should be enabled?

[Sethi Varun-B16395] Will update the description.

Quoted 15 lines
Quoted 15 lines
drivers/iommu/fsl_pamu.c new file +15 -0
+int pamu_enable_liodn(int liodn)
+{
+	struct paace *ppaace;
+
+	ppaace = pamu_get_ppaace(liodn);
+	if (!ppaace) {
+		pr_err("Invalid primary paace entry\n");
+		return -ENOENT;
+	}
+
+	if (!get_bf(ppaace->addr_bitfields, PPAACE_AF_WSE)) {
+		pr_err("liodn %d not configured\n", liodn);
+		return -EINVAL;
+	}
+
Quoted 9 lines

drivers/iommu/fsl_pamu.c line 127

Quoted 5 lines
drivers/iommu/fsl_pamu.c new file +5 -0
+	/* Ensure that all other stores to the ppaace complete first */
+	mb();
+
+	ppaace->addr_bitfields |= PAACE_V_VALID;
+	mb();

Why is it sufficient to set the bit in a variable when enabling liodn but when disabling it set_bf needs to be called? This looks a bit assymetric.

[Sethi Varun-B16395] Will make it symetric :)

Quoted 18 lines

drivers/iommu/fsl_pamu.c line 158

Quoted 5 lines
drivers/iommu/fsl_pamu.c new file +5 -0
+/* Derive the window size encoding for a particular PAACE entry */
+static unsigned int map_addrspace_size_to_wse(phys_addr_t
+addrspace_size) {
+	/* Bug if not a power of 2 */
+	BUG_ON((addrspace_size & (addrspace_size - 1)));

Please use is_power_of_2 here.

drivers/iommu/fsl_pamu.c

Quoted 4 lines
drivers/iommu/fsl_pamu.c new file +4 -0
+
+	/* window size is 2^(WSE+1) bytes */
+	return __ffs(addrspace_size >> PAMU_PAGE_SHIFT) + PAMU_PAGE_SHIFT -
+1;

The PAMU_PAGE_SHIFT shifting and adding looks redundant.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if ((win_size & (win_size - 1)) || win_size < PAMU_PAGE_SIZE) {
+		pr_err("window size too small or not a power of two %llx\n",

win_size);

Quoted 10 lines

drivers/iommu/fsl_pamu.c line 347

Quoted 7 lines
drivers/iommu/fsl_pamu.c new file +7 -0
+		return -EINVAL;
+	}
+
+	if (win_addr & (win_size - 1)) {
+		pr_err("window address is not aligned with window size\n");
+		return -EINVAL;
+	}

Again, use is_power_of_2 instead of hand-coding.

[Sethi Varun-B16395] ok

Quoted 10 lines

drivers/iommu/fsl_pamu.c line 490

Quoted 7 lines
drivers/iommu/fsl_pamu.c new file +7 -0
+	if (~stashid != 0)
+		set_bf(paace->impl_attr, PAACE_IA_CID, stashid);
+
+	smp_wmb();
+
+	if (enable)
+		paace->addr_bitfields |= PAACE_V_VALID;

Havn't you written a helper funtion to set this bit?

[Sethi Varun-B16395] We already have a PAACE entry with us here so we can directly manipulate it here.

Quoted 35 lines
Quoted 7 lines
drivers/iommu/fsl_pamu.c new file +7 -0
+irqreturn_t pamu_av_isr(int irq, void *arg) {
+	struct pamu_isr_data *data = arg;
+	phys_addr_t phys;
+	unsigned int i, j;
+
+	pr_emerg("fsl-pamu: access violation interrupt\n");
+

drivers/iommu/fsl_pamu.c

Quoted 10 lines
drivers/iommu/fsl_pamu.c new file +10 -0
+	for (i = 0; i < data->count; i++) {
+		void __iomem *p = data->pamu_reg_base + i * PAMU_OFFSET;
+		u32 pics = in_be32(p + PAMU_PICS);
+
+		if (pics & PAMU_ACCESS_VIOLATION_STAT) {
+			pr_emerg("POES1=%08x\n", in_be32(p + PAMU_POES1));
+			pr_emerg("POES2=%08x\n", in_be32(p + PAMU_POES2));
+			pr_emerg("AVS1=%08x\n", in_be32(p + PAMU_AVS1));
+			pr_emerg("AVS2=%08x\n", in_be32(p + PAMU_AVS2));
+			pr_emerg("AVA=%016llx\n", make64(in_be32(p +

PAMU_AVAH),

drivers/iommu/fsl_pamu.c

Quoted 3 lines
drivers/iommu/fsl_pamu.c new file +3 -0
+				in_be32(p + PAMU_AVAL)));
+			pr_emerg("UDAD=%08x\n", in_be32(p + PAMU_UDAD));
+			pr_emerg("POEA=%016llx\n", make64(in_be32(p +

PAMU_POEAH),

drivers/iommu/fsl_pamu.c

Quoted 12 lines
drivers/iommu/fsl_pamu.c new file +12 -0
+				in_be32(p + PAMU_POEAL)));
+
+			phys = make64(in_be32(p + PAMU_POEAH),
+				in_be32(p + PAMU_POEAL));
+
+			/* Assume that POEA points to a PAACE */
+			if (phys) {
+				u32 *paace = phys_to_virt(phys);
+
+				/* Only the first four words are relevant */
+				for (j = 0; j < 4; j++)
+					pr_emerg("PAACE[%u]=%08x\n", j,

in_be32(paace + j));

Quoted 10 lines

drivers/iommu/fsl_pamu.c line 793

Quoted 5 lines
drivers/iommu/fsl_pamu.c new file +5 -0
+			}
+		}
+	}
+
+	panic("\n");

A kernel panic seems like an over-reaction to an access violation. Besides the device that caused the violation the system should still work, no?

[Sethi Varun-B16395] Well, if device continues to DMA outside the set aperture then it's a serious problem. We can run in to an interrupt storm (access violations). Alternative could be to disable LIODN, but after that device DMAs would never go through. So, for the guest device is not functional.

Quoted 3 lines
Quoted 1 line

+#define make64(high, low) (((u64)(high) << 32) | (low))

You redefined this make64 here.

[Sethi Varun-B16395] :(

Quoted 16 lines

drivers/iommu/fsl_pamu_domain.c line 122

Quoted 13 lines
drivers/iommu/fsl_pamu_domain.c new file +12 -0
+static int map_subwins(int liodn, struct fsl_dma_domain *dma_domain)
+{
+	struct dma_window *sub_win_ptr =
+				&dma_domain->win_arr[0];
+	int i, ret;
+	unsigned long rpn;
+
+	for (i = 0; i < dma_domain->win_cnt; i++) {
+		if (sub_win_ptr[i].valid) {
+			rpn = sub_win_ptr[i].paddr >>
+				 PAMU_PAGE_SHIFT;
+			spin_lock(&iommu_lock);

IOMMU code might run in interrupt context, so please use spin_lock_irqsave for the iommu_lock.

[Sethi Varun-B16395] ok

Quoted 13 lines

drivers/iommu/fsl_pamu_domain.c

Quoted 12 lines
drivers/iommu/fsl_pamu_domain.c new file +11 -0
+static void detach_device(struct device *dev, struct fsl_dma_domain
+*dma_domain) {
+	struct device_domain_info *info;
+	struct list_head *entry, *tmp;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dma_domain->domain_lock, flags);
+	/* Remove the device from the domain device list */
+	if (!list_empty(&dma_domain->devices)) {
+		list_for_each_safe(entry, tmp, &dma_domain->devices) {
+			info = list_entry(entry, struct device_domain_info,

link);

Quoted 8 lines

drivers/iommu/fsl_pamu_domain.c line 369

Quoted 5 lines
drivers/iommu/fsl_pamu_domain.c new file +5 -0
+			if (!dev || (info->dev == dev))
+				remove_device_ref(info, dma_domain->win_cnt);
+		}
+	}
+	spin_unlock_irqrestore(&dma_domain->domain_lock, flags);

list_empty check is not needed. You can also use
list_for_each_entry_safe.

[Sethi Varun-B16395] ok.

Quoted 27 lines
Quoted 27 lines
drivers/iommu/fsl_pamu_domain.c new file +26 -0
+static void attach_device(struct fsl_dma_domain *dma_domain, int
+liodn, struct device *dev) {
+	struct device_domain_info *info, *old_domain_info;
+
+	spin_lock(&device_domain_lock);
+	/*
+	 * Check here if the device is already attached to domain or not.
+	 * If the device is already attached to a domain detach it.
+	 */
+	old_domain_info = find_domain(dev);
+	if (old_domain_info && old_domain_info->domain != dma_domain) {
+		spin_unlock(&device_domain_lock);
+		detach_device(dev, old_domain_info->domain);
+		spin_lock(&device_domain_lock);
+	}
+
+	info = kmem_cache_zalloc(iommu_devinfo_cache, GFP_KERNEL);
+
+	info->dev = dev;
+	info->liodn = liodn;
+	info->domain = dma_domain;
+
+	list_add(&info->link, &dma_domain->devices);
+	/*
+	 * In case of devices with multiple LIODNs just store
+	 * the info for the first LIODN as all
Quoted 8 lines

drivers/iommu/fsl_pamu_domain.c line 402

Quoted 5 lines
drivers/iommu/fsl_pamu_domain.c new file +5 -0
+	 * LIODNs share the same domain
+	 */
+	if (!old_domain_info)
+		dev->archdata.iommu_domain = info;
+	spin_unlock(&device_domain_lock);

Don't you have to tell the hardware that a device was added to a domain? I don't see that, what I am missing?

[Sethi Varun-B16395] Not sure I understand, once the device is attached to the domain we can do the PAMU window setup corresponding to the device LIODN (if the window information is available).

Quoted 9 lines

drivers/iommu/fsl_pamu_domain.c line 907

Quoted 5 lines
drivers/iommu/fsl_pamu_domain.c new file +4 -0
+static void swap_pci_ref(struct pci_dev **from, struct pci_dev *to) {
+	pci_dev_put(*from);
+	*from = to;
+}

Hmm, looks like this function is re-implemented in a few IOMMU drivers. Want to use the chance to consolidate these implementations?

[Sethi Varun-B16395] Will consolidate :)

-Varun

#21 lore raw

Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

In reply to Joerg Roedel
Quoted 3 lines · Joerg Roedel

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

Sure, it looks pretty reasonable. AIUI, all PCI devices are below some kind of host bridge that is either new and supports partitioning or old and doesn't. I don't know if that's a visibility or isolation requirement, perhaps PCI ACS-ish. In the new host bridge case, each device gets a group. This seems not to have any quirks for multifunction devices though. On AMD and Intel IOMMUs we test multifunction device ACS support to determine whether all the functions should be in the same group. Is there any reason to trust multifunction devices on PAMU?

I also find it curious what happens to the iommu group of the host bridge. In the partitionable case the host bridge group is removed, in the non-partitionable case the host bridge group becomes the group for the children, removing the host bridge. It's unique to PAMU so far that these host bridges are even in an iommu group (x86 only adds pci devices), but I don't see it as necessarily wrong leaving it in either scenario. Does it solve some problem to remove them from the groups? Thanks,

Alex

#22 lore raw

RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 18 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, April 03, 2013 11:32 PM
To: Joerg Roedel
Cc: Sethi Varun-B16395; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu
implementation.

Quoted 3 lines · Joerg Roedel

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

Quoted 9 lines

Sure, it looks pretty reasonable. AIUI, all PCI devices are below some kind of host bridge that is either new and supports partitioning or old and doesn't. I don't know if that's a visibility or isolation requirement, perhaps PCI ACS-ish. In the new host bridge case, each device gets a group. This seems not to have any quirks for multifunction devices though. On AMD and Intel IOMMUs we test multifunction device ACS support to determine whether all the functions should be in the same group. Is there any reason to trust multifunction devices on PAMU?

[Sethi Varun-B16395] In the case where we can partition endpoints we can distinguish transactions based on the bus,device,function number combination. This support is available in the PCIe controller (host bridge).

Quoted 8 lines

I also find it curious what happens to the iommu group of the host bridge. In the partitionable case the host bridge group is removed, in the non-partitionable case the host bridge group becomes the group for the children, removing the host bridge. It's unique to PAMU so far that these host bridges are even in an iommu group (x86 only adds pci devices), but I don't see it as necessarily wrong leaving it in either scenario. Does it solve some problem to remove them from the groups? Thanks,

[Sethi Varun-B16395] The PCIe controller isn't a partitionable entity, it would always be owned by the host.

-Varun

#23 lore raw

Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 26 lines · On Thu, 2013-04-04 at 13:00 +0000, Sethi Varun-B16395 wrote:
Quoted 17 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, April 03, 2013 11:32 PM
To: Joerg Roedel
Cc: Sethi Varun-B16395; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu
implementation.

Quoted 3 lines · Joerg Roedel

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

Quoted 9 lines

Sure, it looks pretty reasonable. AIUI, all PCI devices are below some kind of host bridge that is either new and supports partitioning or old and doesn't. I don't know if that's a visibility or isolation requirement, perhaps PCI ACS-ish. In the new host bridge case, each device gets a group. This seems not to have any quirks for multifunction devices though. On AMD and Intel IOMMUs we test multifunction device ACS support to determine whether all the functions should be in the same group. Is there any reason to trust multifunction devices on PAMU?

Quoted 4 lines

[Sethi Varun-B16395] In the case where we can partition endpoints we can distinguish transactions based on the bus,device,function number combination. This support is available in the PCIe controller (host bridge).

So can x86 IOMMUs, that's the visibility aspect of IOMMU groups. Visibility alone doesn't necessarily imply that a device is isolated though. A multifunction PCI device that doesn't expose ACS support may not isolate functions from each other. For example a peer-to-peer DMA between functions may not be translated by the upstream IOMMU. IOMMU groups should encompass both visibility and isolation.

Quoted 10 lines
Quoted 8 lines

I also find it curious what happens to the iommu group of the host bridge. In the partitionable case the host bridge group is removed, in the non-partitionable case the host bridge group becomes the group for the children, removing the host bridge. It's unique to PAMU so far that these host bridges are even in an iommu group (x86 only adds pci devices), but I don't see it as necessarily wrong leaving it in either scenario. Does it solve some problem to remove them from the groups? Thanks,

[Sethi Varun-B16395] The PCIe controller isn't a partitionable entity, it would always be owned by the host.

Ownership of a device shouldn't play into the group context. An IOMMU group should be defined by it's visibility and isolation from other devices. Whether the PCIe controller is allowed to be handed to userspace is a question for VFIO. Thanks,

Alex

#24 lore raw

RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 46 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Thursday, April 04, 2013 8:52 PM
To: Sethi Varun-B16395
Cc: Joerg Roedel; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu
implementation.

Quoted 17 lines · On Thu, 2013-04-04 at 13:00 +0000, Sethi Varun-B16395 wrote:
Quoted 17 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, April 03, 2013 11:32 PM
To: Joerg Roedel
Cc: Sethi Varun-B16395; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and
iommu implementation.

Quoted 3 lines · Joerg Roedel

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

Quoted 8 lines
Quoted 8 lines

Sure, it looks pretty reasonable. AIUI, all PCI devices are below some kind of host bridge that is either new and supports partitioning or old and doesn't. I don't know if that's a visibility or isolation requirement, perhaps PCI ACS-ish. In the new host bridge case, each device gets a group. This seems not to have any quirks for multifunction devices though. On AMD and Intel IOMMUs we test multifunction device ACS support to determine whether all the functions should be in the same group. Is there any reason

to trust multifunction devices on PAMU?

Quoted 5 lines
Quoted 1 line

[Sethi Varun-B16395] In the case where we can partition endpoints we can distinguish transactions based on the bus,device,function number combination. This support is available in the PCIe controller (host bridge).

Quoted 6 lines

So can x86 IOMMUs, that's the visibility aspect of IOMMU groups. Visibility alone doesn't necessarily imply that a device is isolated though. A multifunction PCI device that doesn't expose ACS support may not isolate functions from each other. For example a peer-to-peer DMA between functions may not be translated by the upstream IOMMU. IOMMU groups should encompass both visibility and isolation.

[Sethi Varun-B16395] We can isolate the DMA access to the host based on the to the pci bus,device,function number.
I thought that was enough to put devices in to separate iommu groups. This is a PCIe controller property which allows us to partition PCIe devices. But, what I can understand from your point is that we also need to consider isolation at PCIe device level as well. I will check for the case of multifunction devices.

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

I also find it curious what happens to the iommu group of the host bridge. In the partitionable case the host bridge group is removed, in the non-partitionable case the host bridge group becomes the group for the children, removing the host bridge. It's unique to PAMU so far that these host bridges are even in an iommu group (x86 only adds pci devices), but I don't see it as necessarily wrong leaving it in either scenario. Does it solve some problem to remove

them from the groups?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Thanks,

[Sethi Varun-B16395] The PCIe controller isn't a partitionable entity, it would always be owned by the host.

Ownership of a device shouldn't play into the group context. An IOMMU group should be defined by it's visibility and isolation from other devices. Whether the PCIe controller is allowed to be handed to userspace is a question for VFIO.

[Sethi Varun-B16395] The problem is in the case, where we can't partition PCIe devices. PCIe devices share the same device group as the PCI controller. This becomes a problem while assigning the devices to the guest, as you are required to unbind all the PCIe devices including the controller from the host. PCIe controller can't be unbound from the host, so we simply delete the controller iommu_group.

-Varun

#25 lore raw

Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 45 lines · On Thu, 2013-04-04 at 16:35 +0000, Sethi Varun-B16395 wrote:
Quoted 45 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Thursday, April 04, 2013 8:52 PM
To: Sethi Varun-B16395
Cc: Joerg Roedel; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu
implementation.

Quoted 17 lines · On Thu, 2013-04-04 at 13:00 +0000, Sethi Varun-B16395 wrote:
Quoted 17 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, April 03, 2013 11:32 PM
To: Joerg Roedel
Cc: Sethi Varun-B16395; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and
iommu implementation.

Quoted 3 lines · Joerg Roedel

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

Quoted 8 lines
Quoted 8 lines

Sure, it looks pretty reasonable. AIUI, all PCI devices are below some kind of host bridge that is either new and supports partitioning or old and doesn't. I don't know if that's a visibility or isolation requirement, perhaps PCI ACS-ish. In the new host bridge case, each device gets a group. This seems not to have any quirks for multifunction devices though. On AMD and Intel IOMMUs we test multifunction device ACS support to determine whether all the functions should be in the same group. Is there any reason

to trust multifunction devices on PAMU?

Quoted 5 lines
Quoted 1 line

[Sethi Varun-B16395] In the case where we can partition endpoints we can distinguish transactions based on the bus,device,function number combination. This support is available in the PCIe controller (host bridge).

Quoted 8 lines
Quoted 6 lines

So can x86 IOMMUs, that's the visibility aspect of IOMMU groups. Visibility alone doesn't necessarily imply that a device is isolated though. A multifunction PCI device that doesn't expose ACS support may not isolate functions from each other. For example a peer-to-peer DMA between functions may not be translated by the upstream IOMMU. IOMMU groups should encompass both visibility and isolation.

[Sethi Varun-B16395] We can isolate the DMA access to the host based on the to the pci bus,device,function number.

The IOMMU can only isolate DMA that it can see. A multifunction device may never expose peer-to-peer DMA to the upstream device, it's implementation specific. The ACS flags allow that possibility to be controlled and prevented.

Quoted 23 lines

I thought that was enough to put devices in to separate iommu groups. This is a PCIe controller property which allows us to partition PCIe devices. But, what I can understand from your point is that we also need to consider isolation at PCIe device level as well. I will check for the case of multifunction devices.

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

I also find it curious what happens to the iommu group of the host bridge. In the partitionable case the host bridge group is removed, in the non-partitionable case the host bridge group becomes the group for the children, removing the host bridge. It's unique to PAMU so far that these host bridges are even in an iommu group (x86 only adds pci devices), but I don't see it as necessarily wrong leaving it in either scenario. Does it solve some problem to remove

them from the groups?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Thanks,

[Sethi Varun-B16395] The PCIe controller isn't a partitionable entity, it would always be owned by the host.

Ownership of a device shouldn't play into the group context. An IOMMU group should be defined by it's visibility and isolation from other devices. Whether the PCIe controller is allowed to be handed to userspace is a question for VFIO.

Quoted 6 lines

[Sethi Varun-B16395] The problem is in the case, where we can't partition PCIe devices. PCIe devices share the same device group as the PCI controller. This becomes a problem while assigning the devices to the guest, as you are required to unbind all the PCIe devices including the controller from the host. PCIe controller can't be unbound from the host, so we simply delete the controller iommu_group.

Unbinding devices is a VFIO implementation, it shouldn't leak into IOMMU groups. Also note that VFIO has a driver white list where we can have exceptions to the rule. I recently added pciehp to that list because the host driver provides functionality. Being attached to the host driver means the device is not accessible to the user through VFIO, but other devices in the group are. Thanks,

Alex

#26 lore raw

RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 106 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Thursday, April 04, 2013 10:14 PM
To: Sethi Varun-B16395
Cc: Joerg Roedel; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu
implementation.

Quoted 46 lines · On Thu, 2013-04-04 at 16:35 +0000, Sethi Varun-B16395 wrote:
Quoted 46 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Thursday, April 04, 2013 8:52 PM
To: Sethi Varun-B16395
Cc: Joerg Roedel; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and
iommu implementation.

Quoted 17 lines · On Thu, 2013-04-04 at 13:00 +0000, Sethi Varun-B16395 wrote:
Quoted 17 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, April 03, 2013 11:32 PM
To: Joerg Roedel
Cc: Sethi Varun-B16395; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver
and iommu implementation.

Quoted 3 lines · Joerg Roedel

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

Quoted 9 lines
Quoted 9 lines

Sure, it looks pretty reasonable. AIUI, all PCI devices are below some kind of host bridge that is either new and supports partitioning or old and doesn't. I don't know if that's a visibility or isolation requirement, perhaps PCI ACS-ish. In the new host bridge case, each device gets a group. This seems not to have any quirks for multifunction devices though. On AMD and Intel IOMMUs we test multifunction device ACS support to determine whether all the functions should be in the same group. Is there any reason

to trust multifunction devices on PAMU?

Quoted 5 lines
Quoted 1 line

[Sethi Varun-B16395] In the case where we can partition endpoints we can distinguish transactions based on the bus,device,function number combination. This support is available in the PCIe controller (host bridge).

Quoted 6 lines
Quoted 6 lines

So can x86 IOMMUs, that's the visibility aspect of IOMMU groups. Visibility alone doesn't necessarily imply that a device is isolated though. A multifunction PCI device that doesn't expose ACS support may not isolate functions from each other. For example a peer-to-peer DMA between functions may not be translated by the upstream IOMMU. IOMMU groups should encompass both visibility and

isolation.

Quoted 2 lines

[Sethi Varun-B16395] We can isolate the DMA access to the host based on the to the pci bus,device,function number.

The IOMMU can only isolate DMA that it can see. A multifunction device may never expose peer-to-peer DMA to the upstream device, it's implementation specific. The ACS flags allow that possibility to be controlled and prevented.

Quoted 24 lines

I thought that was enough to put devices in to separate iommu groups. This is a PCIe controller property which allows us to partition PCIe devices. But, what I can understand from your point is that we also need to consider isolation at PCIe device level as well. I will check for the case of multifunction devices.

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

I also find it curious what happens to the iommu group of the host bridge. In the partitionable case the host bridge group is removed, in the non-partitionable case the host bridge group becomes the group for the children, removing the host bridge. It's unique to PAMU so far that these host bridges are even in an iommu group (x86 only adds pci devices), but I don't see it as necessarily wrong leaving it in either scenario. Does it solve some problem to remove

them from the groups?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Thanks,

[Sethi Varun-B16395] The PCIe controller isn't a partitionable entity, it would always be owned by the host.

Ownership of a device shouldn't play into the group context. An IOMMU group should be defined by it's visibility and isolation from other devices. Whether the PCIe controller is allowed to be handed to userspace is a question for VFIO.

Quoted 6 lines

[Sethi Varun-B16395] The problem is in the case, where we can't partition PCIe devices. PCIe devices share the same device group as the PCI controller. This becomes a problem while assigning the devices to the guest, as you are required to unbind all the PCIe devices including the controller from the host. PCIe controller can't be unbound from the host, so we simply delete the controller iommu_group.

Quoted 7 lines

Unbinding devices is a VFIO implementation, it shouldn't leak into IOMMU groups. Also note that VFIO has a driver white list where we can have exceptions to the rule. I recently added pciehp to that list because the host driver provides functionality. Being attached to the host driver means the device is not accessible to the user through VFIO, but other devices in the group are. Thanks,

Also, as Stuart pointed out the PCIe controller aren't the actual DMA devices (endpoints are the actual DMA devices). So, we remove the device group allocated for the PCIe controllers.

-Varun

#27 lore raw

RE: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

In reply to Alex Williamson
Quoted 57 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Thursday, April 04, 2013 10:22 AM
To: Sethi Varun-B16395
Cc: Joerg Roedel; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc- dev-uLR06cmDAlY/[email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu implementation.

Quoted 26 lines · On Thu, 2013-04-04 at 13:00 +0000, Sethi Varun-B16395 wrote:
Quoted 17 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, April 03, 2013 11:32 PM
To: Joerg Roedel
Cc: Sethi Varun-B16395; Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/5 v11] iommu/fsl: Freescale PAMU driver and iommu
implementation.

Quoted 3 lines · Joerg Roedel

Cc'ing Alex Williamson

Alex, can you please review the iommu-group part of this patch?

Quoted 9 lines

Sure, it looks pretty reasonable. AIUI, all PCI devices are below some kind of host bridge that is either new and supports partitioning or old and doesn't. I don't know if that's a visibility or isolation requirement, perhaps PCI ACS-ish. In the new host bridge case, each device gets a group. This seems not to have any quirks for multifunction devices though. On AMD and Intel IOMMUs we test multifunction device ACS support to determine whether all the functions should be in the same group. Is there any reason to trust multifunction devices on PAMU?

Quoted 4 lines

[Sethi Varun-B16395] In the case where we can partition endpoints we can distinguish transactions based on the bus,device,function number combination. This support is available in the PCIe controller (host bridge).

So can x86 IOMMUs, that's the visibility aspect of IOMMU groups. Visibility alone doesn't necessarily imply that a device is isolated though. A multifunction PCI device that doesn't expose ACS support may not isolate functions from each other. For example a peer-to-peer DMA between functions may not be translated by the upstream IOMMU. IOMMU groups should encompass both visibility and isolation.

Quoted 8 lines
Quoted 8 lines

I also find it curious what happens to the iommu group of the host bridge. In the partitionable case the host bridge group is removed, in the non-partitionable case the host bridge group becomes the group for the children, removing the host bridge. It's unique to PAMU so far that these host bridges are even in an iommu group (x86 only adds pci devices), but I don't see it as necessarily wrong leaving it in either scenario. Does it solve some problem to remove them from the groups? Thanks,

Quoted 7 lines
Quoted 2 lines

[Sethi Varun-B16395] The PCIe controller isn't a partitionable entity, it would always be owned by the host.

Ownership of a device shouldn't play into the group context. An IOMMU group should be defined by it's visibility and isolation from other devices. Whether the PCIe controller is allowed to be handed to userspace is a question for VFIO. Thanks,

Right now the add_device() callback gets called for all platform devices (including PCI controller) and PCI devices. PCI controllers are a kind of special case in that their device tree node has a property indicating that it is DMA capable...but in fact the PCI controller itself does not DMA, but it's the PCI endpoints under it.

So, as you noted the bridge/controller shouldn't be in an IOMMU group and so since the platform 'add device' code didn't special case PCI controllers, this patch removes their group if it's there.

Stuart

maintainer
#28 lore raw
In reply to Varun Sethi
Quoted 5 lines · Varun Sethi

This patchset provides the Freescale PAMU (Peripheral Access Management Unit) driver and the corresponding IOMMU API implementation. PAMU is the IOMMU present on Freescale QorIQ platforms. PAMU can authorize memory access, remap the memory address, and remap the I/O transaction type.

Quoted 7 lines

This set consists of the following patches:
1. Make iova dma_addr_t in the iommu_iova_to_phys API.
2. Addition of new field in the device (powerpc) archdata structure for storing iommu domain information pointer.
3. Add window permission flags in the iommu_domain_window_enable API.
4. Add domain attributes for FSL PAMU driver.
5. PAMU driver and IOMMU API implementation.

Okay, I am about to apply patches 1 and 3 to a new ppc/pamu branch in my tree.

As a general question, how did you test the IOMMU driver and what will you do in the future to avoid regressions?

Joerg

#29 lore raw
Quoted 29 lines

-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Tuesday, April 02, 2013 9:53 PM
To: Sethi Varun-B16395
Cc: Yoder Stuart-B08248; Wood Scott-B07421; iommu-cunTk1MwBs/[email protected] foundation.org; linuxppc-dev-uLR06cmDAlY/[email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 0/5 v11] iommu/fsl: Freescale PAMU driver and IOMMU
API implementation.

Quoted 4 lines · Varun Sethi

This patchset provides the Freescale PAMU (Peripheral Access Management Unit) driver and the corresponding IOMMU API implementation. PAMU is the IOMMU present on Freescale QorIQ platforms. PAMU can authorize memory access, remap the memory address,

and remap the I/O transaction type.

Quoted 4 lines

This set consists of the following patches:
1. Make iova dma_addr_t in the iommu_iova_to_phys API.
2. Addition of new field in the device (powerpc) archdata structure for

storing iommu domain information

Quoted 4 lines

pointer.
3. Add window permission flags in the iommu_domain_window_enable API.
4. Add domain attributes for FSL PAMU driver.
5. PAMU driver and IOMMU API implementation.

Quoted 6 lines

Okay, I am about to apply patches 1 and 3 to a new ppc/pamu branch in my tree.

As a general question, how did you test the IOMMU driver and what will you do in the future to avoid regressions?

I use a kernel module for testing the iommu_api support. The module allows for dynamic creation and deletion of iommu domains for the devices in the device tree. Also, the vfio support (under development) for Freescale SOCs with APMU hardware would depend on the PAMU driver.

-Varun