Skip to contentSkip to conversation

xen/arm: smmuv3: Advertise coherent table walk

PATCH In review Michal Orzel 5 participants 17 messages May 12, 2023 – May 15, 2023

lore
Share & tools
lore
#0 lore raw

cover xen/arm: smmuv3: Advertise coherent table walk

Based on the work done for SMMU v1,v2 by commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

Michal Orzel (2):
xen/arm: smmuv3: Constify arm_smmu_get_by_dev() parameter xen/arm: smmuv3: Advertise coherent table walk if supported

 xen/drivers/passthrough/arm/smmu-v3.c | 28 ++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 xen/arm: smmuv3: Constify arm_smmu_get_by_dev() parameter

This function does not modify its parameter 'dev' and it is not supposed to do it. Therefore, constify it.

---
 xen/drivers/passthrough/arm/smmu-v3.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/drivers/passthrough/arm/smmu-v3.c +2 -2
index bfdb62b395ad..bf053cdb6d5c 100644
@@ -1468,7 +1468,7 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid)
 	return sid < limit;
 }
 /* Forward declaration */
-static struct arm_smmu_device *arm_smmu_get_by_dev(struct device *dev);
+static struct arm_smmu_device *arm_smmu_get_by_dev(const struct device *dev);
 
 static int arm_smmu_add_device(u8 devfn, struct device *dev)
 {
@@ -2556,7 +2556,7 @@ static int __must_check arm_smmu_iotlb_flush(struct domain *d, dfn_t dfn,
 	return arm_smmu_iotlb_flush_all(d);
 }
 
-static struct arm_smmu_device *arm_smmu_get_by_dev(struct device *dev)
+static struct arm_smmu_device *arm_smmu_get_by_dev(const struct device *dev)
 {
 	struct arm_smmu_device *smmu = NULL;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/2
#3 lore raw

RE: [PATCH 1/2] xen/arm: smmuv3: Constify arm_smmu_get_by_dev() parameter

In reply to Michal Orzel

Hi Michal,

Quoted 8 lines

-----Original Message-----
Subject: [PATCH 1/2] xen/arm: smmuv3: Constify arm_smmu_get_by_dev() parameter

This function does not modify its parameter 'dev' and it is not supposed to do it. Therefore, constify it.

Kind regards,
Henry

#5 lore raw

PATCH 2/2 xen/arm: smmuv3: Advertise coherent table walk if supported

In reply to Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.

---
 xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +23 -1
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
 };
 
 /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;
+
 static int __must_check arm_smmu_iotlb_flush_all(struct domain *d)
 {
 	struct arm_smmu_xen_domain *xen_domain = dom_iommu(d)->arch.priv;
@@ -2708,8 +2717,12 @@ static int arm_smmu_iommu_xen_domain_init(struct domain *d)
 	INIT_LIST_HEAD(&xen_domain->contexts);
 
 	dom_iommu(d)->arch.priv = xen_domain;
-	return 0;
 
+	/* Coherent walk can be enabled only when all SMMUs support it. */
+	if (platform_features & ARM_SMMU_FEAT_COHERENCY)
+		iommu_set_feature(d, IOMMU_FEAT_COHERENT_WALK);
+
+	return 0;
 }
 
 static void arm_smmu_iommu_xen_domain_teardown(struct domain *d)
@@ -2738,6 +2751,7 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
 				const void *data)
 {
 	int rc;
+	const struct arm_smmu_device *smmu;
 
 	/*
 	 * Even if the device can't be initialized, we don't want to
@@ -2751,6 +2765,14 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
 
 	iommu_set_ops(&arm_smmu_iommu_ops);
 
+	/* Find the just added SMMU and retrieve its features. */
+	smmu = arm_smmu_get_by_dev(dt_to_dev(dev));
+
+	/* It would be a bug not to find the SMMU we just added. */
+	BUG_ON(!smmu);
+
+	platform_features &= smmu->features;
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

Hi Michal,

Quoted 49 lines · Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.

---
  xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-
  1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +9 -0
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
  };
 
  /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;
+
  static int __must_check arm_smmu_iotlb_flush_all(struct domain *d)
  {
  	struct arm_smmu_xen_domain *xen_domain = dom_iommu(d)->arch.priv;
@@ -2708,8 +2717,12 @@ static int arm_smmu_iommu_xen_domain_init(struct domain *d)
  	INIT_LIST_HEAD(&xen_domain->contexts);
 

xen/drivers/passthrough/arm/smmu-v3.c static int arm_smmu_iommu_xen_domain_init(struct domain *d) · line 2727

Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +5 -1
  	dom_iommu(d)->arch.priv = xen_domain;
-	return 0;
 
+	/* Coherent walk can be enabled only when all SMMUs support it. */
+	if (platform_features & ARM_SMMU_FEAT_COHERENCY)
+		iommu_set_feature(d, IOMMU_FEAT_COHERENT_WALK);
+
+	return 0;
  }
 

All good till here.

Quoted 11 lines
xen/drivers/passthrough/arm/smmu-v3.c +1 -0
  static void arm_smmu_iommu_xen_domain_teardown(struct domain *d)
@@ -2738,6 +2751,7 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
  				const void *data)
  {
  	int rc;
+	const struct arm_smmu_device *smmu;
 
  	/*
  	 * Even if the device can't be initialized, we don't want to
@@ -2751,6 +2765,14 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
 

xen/drivers/passthrough/arm/smmu-v3.c static __init int arm_smmu_dt_init(struct dt_device_node *dev, · line 2775

Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +8 -0
  	iommu_set_ops(&arm_smmu_iommu_ops);
 
+	/* Find the just added SMMU and retrieve its features. */
+	smmu = arm_smmu_get_by_dev(dt_to_dev(dev));
+
+	/* It would be a bug not to find the SMMU we just added. */
+	BUG_ON(!smmu);
+
+	platform_features &= smmu->features;
+

Can you explain this change in the commit message ?

- Ayan

Quoted 3 lines
xen/drivers/passthrough/arm/smmu-v3.c +0 -0
  	return 0;
  }
 
#7 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

Hi Ayan,

Quoted 76 lines · Ayan Kumar Halder

Hi Michal,

Quoted 49 lines · Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.

---
  xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-
  1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +9 -0
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
  };
 
  /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;
+
  static int __must_check arm_smmu_iotlb_flush_all(struct domain *d)
  {
  	struct arm_smmu_xen_domain *xen_domain = dom_iommu(d)->arch.priv;
@@ -2708,8 +2717,12 @@ static int arm_smmu_iommu_xen_domain_init(struct domain *d)
  	INIT_LIST_HEAD(&xen_domain->contexts);
 

xen/drivers/passthrough/arm/smmu-v3.c static int arm_smmu_iommu_xen_domain_init(struct domain *d) · line 2727

Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +5 -1
  	dom_iommu(d)->arch.priv = xen_domain;
-	return 0;
 
+	/* Coherent walk can be enabled only when all SMMUs support it. */
+	if (platform_features & ARM_SMMU_FEAT_COHERENCY)
+		iommu_set_feature(d, IOMMU_FEAT_COHERENT_WALK);
+
+	return 0;
  }
 

All good till here.

Quoted 13 lines
xen/drivers/passthrough/arm/smmu-v3.c +1 -0
  static void arm_smmu_iommu_xen_domain_teardown(struct domain *d)
@@ -2738,6 +2751,7 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
  				const void *data)
  {
  	int rc;
+	const struct arm_smmu_device *smmu;
 
  	/*
  	 * Even if the device can't be initialized, we don't want to
@@ -2751,6 +2765,14 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
 
  	iommu_set_ops(&arm_smmu_iommu_ops);
 
Quoted 10 lines

xen/drivers/passthrough/arm/smmu-v3.c static __init int arm_smmu_dt_init(struct dt_device_node *dev, · line 2775

Quoted 8 lines
xen/drivers/passthrough/arm/smmu-v3.c +8 -0
+	/* Find the just added SMMU and retrieve its features. */
+	smmu = arm_smmu_get_by_dev(dt_to_dev(dev));
+
+	/* It would be a bug not to find the SMMU we just added. */
+	BUG_ON(!smmu);
+
+	platform_features &= smmu->features;
+

Can you explain this change in the commit message ?

I think it is already explained by saying that in order to advertise the *platform* feature, all SMMUs need to report it. If at least one doesn't, the feature is disabled. This is exactly what this line is doing. It is comparing platform features with a just probed SMMU features (arm_smmu_dt_init() is called for each SMMU).

~Michal

Reviewed-by
#8 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

Quoted 1 line · Michal Orzel

Hi Ayan,

Hi Michal,

Quoted 20 lines · Ayan Kumar Halder
Quoted 18 lines

Hi Michal,

Quoted 15 lines · Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

Quoted 63 lines
Quoted 54 lines
Quoted 30 lines

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.

---
   xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-
   1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +9 -0
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
   };
 
   /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;
+
   static int __must_check arm_smmu_iotlb_flush_all(struct domain *d)
   {
   	struct arm_smmu_xen_domain *xen_domain = dom_iommu(d)->arch.priv;
@@ -2708,8 +2717,12 @@ static int arm_smmu_iommu_xen_domain_init(struct domain *d)
   	INIT_LIST_HEAD(&xen_domain->contexts);
 

xen/drivers/passthrough/arm/smmu-v3.c static int arm_smmu_iommu_xen_domain_init(struct domain *d) · line 2727

Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +5 -1
   	dom_iommu(d)->arch.priv = xen_domain;
-	return 0;
 
+	/* Coherent walk can be enabled only when all SMMUs support it. */
+	if (platform_features & ARM_SMMU_FEAT_COHERENCY)
+		iommu_set_feature(d, IOMMU_FEAT_COHERENT_WALK);
+
+	return 0;
   }
 

All good till here.

Quoted 13 lines
xen/drivers/passthrough/arm/smmu-v3.c +1 -0
   static void arm_smmu_iommu_xen_domain_teardown(struct domain *d)
@@ -2738,6 +2751,7 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
   				const void *data)
   {
   	int rc;
+	const struct arm_smmu_device *smmu;
 
   	/*
   	 * Even if the device can't be initialized, we don't want to
@@ -2751,6 +2765,14 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
 
   	iommu_set_ops(&arm_smmu_iommu_ops);
 
Quoted 9 lines

xen/drivers/passthrough/arm/smmu-v3.c static __init int arm_smmu_dt_init(struct dt_device_node *dev, · line 2775

Quoted 8 lines
xen/drivers/passthrough/arm/smmu-v3.c +8 -0
+	/* Find the just added SMMU and retrieve its features. */
+	smmu = arm_smmu_get_by_dev(dt_to_dev(dev));
+
+	/* It would be a bug not to find the SMMU we just added. */
+	BUG_ON(!smmu);
+
+	platform_features &= smmu->features;
+

Can you explain this change in the commit message ?

Quoted 4 lines

I think it is already explained by saying that in order to advertise the *platform* feature, all SMMUs need to report it. If at least one doesn't, the feature is disabled. This is exactly what this line is doing. It is comparing platform features with a just probed SMMU features (arm_smmu_dt_init() is called for each SMMU).

All good.

Quoted 2 lines

~Michal

#9 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

In reply to Michal Orzel

Hi Michal,

Quoted 88 lines · Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.
---
xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-

1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +23 -1
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
 };
 
 /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;
+
 static int __must_check arm_smmu_iotlb_flush_all(struct domain *d)
 {
 	struct arm_smmu_xen_domain *xen_domain = dom_iommu(d)->arch.priv;
@@ -2708,8 +2717,12 @@ static int arm_smmu_iommu_xen_domain_init(struct domain *d)
 	INIT_LIST_HEAD(&xen_domain->contexts);
 
 	dom_iommu(d)->arch.priv = xen_domain;
-	return 0;
 
+	/* Coherent walk can be enabled only when all SMMUs support it. */
+	if (platform_features & ARM_SMMU_FEAT_COHERENCY)
+		iommu_set_feature(d, IOMMU_FEAT_COHERENT_WALK);
+
+	return 0;
 }
 
 static void arm_smmu_iommu_xen_domain_teardown(struct domain *d)
@@ -2738,6 +2751,7 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
 				const void *data)
 {
 	int rc;
+	const struct arm_smmu_device *smmu;
 
 	/*
 	 * Even if the device can't be initialized, we don't want to
@@ -2751,6 +2765,14 @@ static __init int arm_smmu_dt_init(struct dt_device_node *dev,
 
 	iommu_set_ops(&arm_smmu_iommu_ops);
 
+	/* Find the just added SMMU and retrieve its features. */
+	smmu = arm_smmu_get_by_dev(dt_to_dev(dev));
+
+	/* It would be a bug not to find the SMMU we just added. */
+	BUG_ON(!smmu);
+
+	platform_features &= smmu->features;
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#10 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

In reply to Michal Orzel

Hi Michal,

On 12 May 2023, at 3:35 pm, Michal Orzel <[email protected]> wrote:

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

Regards,
Rahul

Reviewed-by on v1 2/2
#11 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

In reply to Michal Orzel

Hi,

Quoted 32 lines · Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.

---
  xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-
  1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +0 -0
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
  };

xen/drivers/passthrough/arm/smmu-v3.c static const struct dt_device_match arm_smmu_of_match[] = { · line 2536

Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +8 -0
 
  /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;

AFAICT, this variable is not meant to change after boot. So please add the attribute __ro_after_init.

With that:

Cheers,

Signature · 1 line
Julien Grall
#12 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

Hi Julien,

Quoted 38 lines · Julien Grall

Hi,

Quoted 33 lines · Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.

---
  xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-
  1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +0 -0
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
  };
 
Quoted 12 lines

xen/drivers/passthrough/arm/smmu-v3.c static const struct dt_device_match arm_smmu_of_match[] = { · line 2536

Quoted 9 lines
xen/drivers/passthrough/arm/smmu-v3.c +8 -0
  /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;

AFAICT, this variable is not meant to change after boot. So please add the attribute __ro_after_init.

Yes, that makes total sense. After probing this variable is not meant to be modified. Is it something that can be done on commit or would you want me to respin this patch?

~Michal

Reviewed-by
#13 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 52 lines · Julien Grall
Quoted 38 lines

Hi,

Quoted 33 lines · Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.

---
   xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-
   1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +0 -0
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
   };
 
Quoted 12 lines

xen/drivers/passthrough/arm/smmu-v3.c static const struct dt_device_match arm_smmu_of_match[] = { · line 2536

Quoted 9 lines
xen/drivers/passthrough/arm/smmu-v3.c +8 -0
   /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;

AFAICT, this variable is not meant to change after boot. So please add the attribute __ro_after_init.

Quoted 2 lines

Yes, that makes total sense. After probing this variable is not meant to be modified. Is it something that can be done on commit or would you want me to respin this patch?

I can do it on commit. With that:

Cheers,

Signature · 1 line
Julien Grall
#14 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

Quoted 59 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 52 lines · Julien Grall
Quoted 50 lines

Hi,

Quoted 32 lines · Michal Orzel

At the moment, even in case of a SMMU being I/O coherent, we clean the updated PT as a result of not advertising the coherency feature. SMMUv3 coherency feature means that page table walks, accesses to memory structures and queues are I/O coherent (refer ARM IHI 0070 E.A, 3.15).

Follow the same steps that were done for SMMU v1,v2 driver by the commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

The same restrictions apply, meaning that in order to advertise coherent table walk platform feature, all the SMMU devices need to report coherency feature. This is because the page tables (we are sharing them with CPU) are populated before any device assignment and in case of a device being behind non-coherent SMMU, we would have to scan the tables and clean the cache.

It is to be noted that the SBSA/BSA (refer ARM DEN0094C 1.0C, section D) requires that all SMMUv3 devices support I/O coherency.

---
There are very few platforms out there with SMMUv3 but I have never seen a SMMUv3 that is not I/O coherent.

---
   xen/drivers/passthrough/arm/smmu-v3.c | 24 +++++++++++++++++++++++-
   1 file changed, 23 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu-v3.c +0 -0
index bf053cdb6d5c..2adaad0fa038 100644
@@ -2526,6 +2526,15 @@ static const struct dt_device_match arm_smmu_of_match[] = {
   };

xen/drivers/passthrough/arm/smmu-v3.c static const struct dt_device_match arm_smmu_of_match[] = { · line 2536

Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +8 -0
 
   /* Start of Xen specific code. */
+
+/*
+ * Platform features. It indicates the list of features supported by all
+ * SMMUs. Actually we only care about coherent table walk, which in case of
+ * SMMUv3 is implied by the overall coherency feature (refer ARM IHI 0070 E.A,
+ * section 3.15 and SMMU_IDR0.COHACC bit description).
+ */
+static uint32_t platform_features = ARM_SMMU_FEAT_COHERENCY;

AFAICT, this variable is not meant to change after boot. So please add the attribute __ro_after_init.

Quoted 6 lines
Quoted 2 lines

Yes, that makes total sense. After probing this variable is not meant to be modified. Is it something that can be done on commit or would you want me to respin this patch?

I can do it on commit. With that:

Thanks,
Bare in mind that Rahul responded in HTML so there will be a <mailto when using b4.

~Michal

#15 lore raw

Re: [PATCH 2/2] xen/arm: smmuv3: Advertise coherent table walk if supported

Quoted 3 lines · Michal Orzel
Quoted 1 line

Thanks,
Bare in mind that Rahul responded in HTML so there will be a <mailto when using b4.

Thanks for the reminder! The patch is now committed.

Cheers,

Signature · 1 line
Julien Grall
#16 lore raw
In reply to Michal Orzel

Hi Michal,

Quoted 5 lines · Michal Orzel

Based on the work done for SMMU v1,v2 by commit:
080dcb781e1bc3bb22f55a9dfdecb830ccbabe88

Michal Orzel (2):
xen/arm: smmuv3: Constify arm_smmu_get_by_dev() parameter

I have committed this patch.

Quoted 1 line

xen/arm: smmuv3: Advertise coherent table walk if supported

For this one, I would like on extra change to harden the code (see my reply to the patch).

Cheers,

Signature · 1 line
Julien Grall