Skip to contentSkip to conversation

xen/arm: smmuv1: Fixed stream matching register allocation

PATCH In review Rahul Singh 3 participants 8 messages Jun 25, 2021 – Jul 3, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: smmuv1: Fixed stream matching register allocation

SMR allocation should be based on the number of supported stream matching register for each SMMU device.

Issue introduced by commit 5e08586afbb90b2e2d56c175c07db77a4afa873c when backported the patches from Linux to XEN to fix the stream match conflict issue when two devices have the same stream-id.

---
 xen/drivers/passthrough/arm/smmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +2 -1
index d9a3a0cbf6..da2cd457d7 100644
@@ -149,6 +149,7 @@ typedef enum irqreturn irqreturn_t;
 #define kzalloc(size, flags)		_xzalloc(size, sizeof(void *))
 #define devm_kzalloc(dev, size, flags)	_xzalloc(size, sizeof(void *))
 #define kmalloc_array(size, n, flags)	_xmalloc_array(size, sizeof(void *), n)
+#define kzalloc_array(size, n, flags)	_xzalloc_array(size, sizeof(void *), n)
 
 static void __iomem *devm_ioremap_resource(struct device *dev,
 					   struct resource *res)
@@ -2221,7 +2222,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
 		smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
 
 		/* Zero-initialised to mark as invalid */
-		smmu->smrs = devm_kzalloc(smmu->dev, sizeof(*smmu->smrs), GFP_KERNEL);
+		smmu->smrs = kzalloc_array(sizeof(*smmu->smrs), size, GFP_KERNEL);
 		if (!smmu->smrs)
 			return -ENOMEM;
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 xen/arm: smmuv1: Set privileged attr to 'default'

Backport commit e19898077cfb642fe151ba22981e795c74d9e114 "iommu/arm-smmu: Set privileged attribute to 'default' instead of 'unprivileged'"

Original commit message:
Currently the driver sets all the device transactions privileges to UNPRIVILEGED, but there are cases where the iommu masters wants to isolate privileged supervisor and unprivileged user. So don't override the privileged setting to unprivileged, instead set it to default as incoming and let it be controlled by the pagetable settings.

---
 xen/drivers/passthrough/arm/smmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +1 -1
index 1a68c2ab3b..d9a3a0cbf6 100644
@@ -1566,7 +1566,7 @@ static int arm_smmu_domain_add_master(struct arm_smmu_domain *smmu_domain,
 			continue;
 
 		s2cr[idx].type = type ;
-		s2cr[idx].privcfg = S2CR_PRIVCFG_UNPRIV;
+		s2cr[idx].privcfg = S2CR_PRIVCFG_DEFAULT;
 		s2cr[idx].cbndx = cbndx;
 		arm_smmu_write_s2cr(smmu, idx);
 	}
Signature · 1 line
2.17.1
Acked-by Tested-by on v1 1/1
#2 lore raw

Re: [PATCH] xen/arm: smmuv1: Set privileged attr to 'default'

Quoted 12 lines · Rahul Singh

Backport commit e19898077cfb642fe151ba22981e795c74d9e114 "iommu/arm-smmu: Set privileged attribute to 'default' instead of 'unprivileged'"

Original commit message:
Currently the driver sets all the device transactions privileges to UNPRIVILEGED, but there are cases where the iommu masters wants to isolate privileged supervisor and unprivileged user. So don't override the privileged setting to unprivileged, instead set it to default as incoming and let it be controlled by the pagetable settings.

Quoted 5 lines
Quoted 20 lines
---
 xen/drivers/passthrough/arm/smmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +1 -1
index 1a68c2ab3b..d9a3a0cbf6 100644
@@ -1566,7 +1566,7 @@ static int arm_smmu_domain_add_master(struct arm_smmu_domain *smmu_domain,
 			continue;
 
 		s2cr[idx].type = type ;
-		s2cr[idx].privcfg = S2CR_PRIVCFG_UNPRIV;
+		s2cr[idx].privcfg = S2CR_PRIVCFG_DEFAULT;
 		s2cr[idx].cbndx = cbndx;
 		arm_smmu_write_s2cr(smmu, idx);
 	}
Signature · 1 line
2.17.1
#3 lore raw
In reply to Rahul Singh

Hi Rahul,

Quoted 27 lines · Rahul Singh

SMR allocation should be based on the number of supported stream matching register for each SMMU device.

Issue introduced by commit 5e08586afbb90b2e2d56c175c07db77a4afa873c when backported the patches from Linux to XEN to fix the stream match conflict issue when two devices have the same stream-id.

---
  xen/drivers/passthrough/arm/smmu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +1 -0
index d9a3a0cbf6..da2cd457d7 100644
@@ -149,6 +149,7 @@ typedef enum irqreturn irqreturn_t;
  #define kzalloc(size, flags)		_xzalloc(size, sizeof(void *))
  #define devm_kzalloc(dev, size, flags)	_xzalloc(size, sizeof(void *))
  #define kmalloc_array(size, n, flags)	_xmalloc_array(size, sizeof(void *), n)
+#define kzalloc_array(size, n, flags)	_xzalloc_array(size, sizeof(void *), n)
 
  static void __iomem *devm_ioremap_resource(struct device *dev,
  					   struct resource *res)

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) · line 2225

Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +1 -1
@@ -2221,7 +2222,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
  		smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
 
  		/* Zero-initialised to mark as invalid */
-		smmu->smrs = devm_kzalloc(smmu->dev, sizeof(*smmu->smrs), GFP_KERNEL);
+		smmu->smrs = kzalloc_array(sizeof(*smmu->smrs), size, GFP_KERNEL);

I noticed this is already in... However, I am a bit puzzled into why this was switched devm_kzalloc() to kzalloc_array(). This doesn't matter for Xen as they are just wrappers to x*alloc() but a mention in the commit message would have been useful.

Also, when sending series, please remember to create a cover letter and number each patch.

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw

Hi Julien,

Quoted 26 lines · Julien Grall

Hi Rahul,

Quoted 21 lines · Rahul Singh

SMR allocation should be based on the number of supported stream matching register for each SMMU device.
Issue introduced by commit 5e08586afbb90b2e2d56c175c07db77a4afa873c when backported the patches from Linux to XEN to fix the stream match conflict issue when two devices have the same stream-id.

---
 xen/drivers/passthrough/arm/smmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +1 -0
index d9a3a0cbf6..da2cd457d7 100644
@@ -149,6 +149,7 @@ typedef enum irqreturn irqreturn_t;
 #define kzalloc(size, flags)		_xzalloc(size, sizeof(void *))
 #define devm_kzalloc(dev, size, flags)	_xzalloc(size, sizeof(void *))
 #define kmalloc_array(size, n, flags)	_xmalloc_array(size, sizeof(void *), n)
+#define kzalloc_array(size, n, flags)	_xzalloc_array(size, sizeof(void *), n)
   static void __iomem *devm_ioremap_resource(struct device *dev,
Quoted 8 lines

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) · line 2224

Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +1 -1
 					   struct resource *res)
@@ -2221,7 +2222,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
 		smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
   		/* Zero-initialised to mark as invalid */
-		smmu->smrs = devm_kzalloc(smmu->dev, sizeof(*smmu->smrs), GFP_KERNEL);
+		smmu->smrs = kzalloc_array(sizeof(*smmu->smrs), size, GFP_KERNEL);

I noticed this is already in... However, I am a bit puzzled into why this was switched devm_kzalloc() to kzalloc_array(). This doesn't matter for Xen as they are just wrappers to x*alloc() but a mention in the commit message would have been useful.

Yes we can use the devm_kzalloc(..) but then we have to pass (sizeof(*smmu->smrs) * size ) as size argument to devm_kzalloc(..) I thought for better code readability I will use kzalloc_array() as the function name suggests we are allocating memory for an array.

Quoted 3 lines

Also, when sending series, please remember to create a cover letter and number each patch.

Ok.

Regards,
Rahul

Quoted 4 lines

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 1 line · Rahul Singh

Hi Julien,

Hi,

Quoted 35 lines
Quoted 26 lines · Julien Grall

Hi Rahul,

Quoted 21 lines · Rahul Singh

SMR allocation should be based on the number of supported stream matching register for each SMMU device.
Issue introduced by commit 5e08586afbb90b2e2d56c175c07db77a4afa873c when backported the patches from Linux to XEN to fix the stream match conflict issue when two devices have the same stream-id.

---
  xen/drivers/passthrough/arm/smmu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +1 -0
index d9a3a0cbf6..da2cd457d7 100644
@@ -149,6 +149,7 @@ typedef enum irqreturn irqreturn_t;
  #define kzalloc(size, flags)		_xzalloc(size, sizeof(void *))
  #define devm_kzalloc(dev, size, flags)	_xzalloc(size, sizeof(void *))
  #define kmalloc_array(size, n, flags)	_xmalloc_array(size, sizeof(void *), n)
+#define kzalloc_array(size, n, flags)	_xzalloc_array(size, sizeof(void *), n)
    static void __iomem *devm_ioremap_resource(struct device *dev,
Quoted 8 lines

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) · line 2224

Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +1 -1
  					   struct resource *res)
@@ -2221,7 +2222,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
  		smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
    		/* Zero-initialised to mark as invalid */
-		smmu->smrs = devm_kzalloc(smmu->dev, sizeof(*smmu->smrs), GFP_KERNEL);
+		smmu->smrs = kzalloc_array(sizeof(*smmu->smrs), size, GFP_KERNEL);

I noticed this is already in... However, I am a bit puzzled into why this was switched devm_kzalloc() to kzalloc_array(). This doesn't matter for Xen as they are just wrappers to x*alloc() but a mention in the commit message would have been useful.

Quoted 2 lines

Yes we can use the devm_kzalloc(..) but then we have to pass (sizeof(*smmu->smrs) * size ) as size argument to devm_kzalloc(..) I thought for better code readability I will use kzalloc_array() as the function name suggests we are allocating memory for an array.

My point is devm_k*alloc() and k*alloc() are quite different on the paper. One will allocate memory for a given device while the other is unknown memory.

It would have been better to call the function devm_kzalloc_array() to keep to keep the code coherent. Can you please send a patch to make the switch?

Cheers,

Signature · 1 line
Julien Grall
#6 lore raw

Hi Julien,

Quoted 43 lines · Julien Grall
Quoted 1 line · Rahul Singh

Hi Julien,

Hi,

Quoted 34 lines
Quoted 34 lines · Julien Grall

Hi Rahul,

Quoted 23 lines · Rahul Singh

SMR allocation should be based on the number of supported stream matching register for each SMMU device.
Issue introduced by commit 5e08586afbb90b2e2d56c175c07db77a4afa873c when backported the patches from Linux to XEN to fix the stream match conflict issue when two devices have the same stream-id.

---
 xen/drivers/passthrough/arm/smmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +1 -0
index d9a3a0cbf6..da2cd457d7 100644
@@ -149,6 +149,7 @@ typedef enum irqreturn irqreturn_t;
 #define kzalloc(size, flags)		_xzalloc(size, sizeof(void *))
 #define devm_kzalloc(dev, size, flags)	_xzalloc(size, sizeof(void *))
 #define kmalloc_array(size, n, flags)	_xmalloc_array(size, sizeof(void *), n)
+#define kzalloc_array(size, n, flags)	_xzalloc_array(size, sizeof(void *), n)
   static void __iomem *devm_ioremap_resource(struct device *dev,
 					   struct resource *res)

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) · line 2224

Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +1 -1
@@ -2221,7 +2222,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
 		smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
   		/* Zero-initialised to mark as invalid */
-		smmu->smrs = devm_kzalloc(smmu->dev, sizeof(*smmu->smrs), GFP_KERNEL);
+		smmu->smrs = kzalloc_array(sizeof(*smmu->smrs), size, GFP_KERNEL);

I noticed this is already in... However, I am a bit puzzled into why this was switched devm_kzalloc() to kzalloc_array(). This doesn't matter for Xen as they are just wrappers to x*alloc() but a mention in the commit message would have been useful.

Quoted 6 lines
Quoted 2 lines

Yes we can use the devm_kzalloc(..) but then we have to pass (sizeof(*smmu->smrs) * size ) as size argument to devm_kzalloc(..) I thought for better code readability I will use kzalloc_array() as the function name suggests we are allocating memory for an array.

My point is devm_k*alloc() and k*alloc() are quite different on the paper. One will allocate memory for a given device while the other is unknown memory.

It would have been better to call the function devm_kzalloc_array() to keep to keep the code coherent. Can you please send a patch to make the switch?

Ok. I will modify the code as per your request as below . I will use devm_kcalloc(..) as this will be more coherent.

xen/drivers/passthrough/arm/smmu.c +4 -2
index da2cd457d7..658c40433c 100644
@@ -149,7 +149,8 @@ typedef enum irqreturn irqreturn_t;
 #define kzalloc(size, flags)           _xzalloc(size, sizeof(void *))
 #define devm_kzalloc(dev, size, flags) _xzalloc(size, sizeof(void *))
 #define kmalloc_array(size, n, flags)  _xmalloc_array(size, sizeof(void *), n)
-#define kzalloc_array(size, n, flags)  _xzalloc_array(size, sizeof(void *), n)
+#define devm_kcalloc(dev, n, size, flags)                      \
+       _xzalloc_array(size, sizeof(void *), n)
 
 static void __iomem *devm_ioremap_resource(struct device *dev,
                                           struct resource *res)
@@ -2222,7 +2223,8 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
                smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
 
                /* Zero-initialised to mark as invalid */
-               smmu->smrs = kzalloc_array(sizeof(*smmu->smrs), size, GFP_KERNEL);
+               smmu->smrs = devm_kcalloc(smmu->dev, size, sizeof(*smmu->smrs),
+                                                               GFP_KERNEL);
                if (!smmu->smrs)
                        return -ENOMEM;
 

Regards,
Rahul

Quoted 5 lines

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw
Quoted 1 line · Rahul Singh

Hi Julien,

Hi Rahul,

Quoted 67 lines
Quoted 43 lines · Julien Grall
Quoted 1 line · Rahul Singh

Hi Julien,

Hi,

Quoted 34 lines
Quoted 34 lines · Julien Grall

Hi Rahul,

Quoted 23 lines · Rahul Singh

SMR allocation should be based on the number of supported stream matching register for each SMMU device.
Issue introduced by commit 5e08586afbb90b2e2d56c175c07db77a4afa873c when backported the patches from Linux to XEN to fix the stream match conflict issue when two devices have the same stream-id.

---
  xen/drivers/passthrough/arm/smmu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +1 -0
index d9a3a0cbf6..da2cd457d7 100644
@@ -149,6 +149,7 @@ typedef enum irqreturn irqreturn_t;
  #define kzalloc(size, flags)		_xzalloc(size, sizeof(void *))
  #define devm_kzalloc(dev, size, flags)	_xzalloc(size, sizeof(void *))
  #define kmalloc_array(size, n, flags)	_xmalloc_array(size, sizeof(void *), n)
+#define kzalloc_array(size, n, flags)	_xzalloc_array(size, sizeof(void *), n)
    static void __iomem *devm_ioremap_resource(struct device *dev,
  					   struct resource *res)

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) · line 2224

Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +1 -1
@@ -2221,7 +2222,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
  		smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
    		/* Zero-initialised to mark as invalid */
-		smmu->smrs = devm_kzalloc(smmu->dev, sizeof(*smmu->smrs), GFP_KERNEL);
+		smmu->smrs = kzalloc_array(sizeof(*smmu->smrs), size, GFP_KERNEL);

I noticed this is already in... However, I am a bit puzzled into why this was switched devm_kzalloc() to kzalloc_array(). This doesn't matter for Xen as they are just wrappers to x*alloc() but a mention in the commit message would have been useful.

Quoted 6 lines
Quoted 2 lines

Yes we can use the devm_kzalloc(..) but then we have to pass (sizeof(*smmu->smrs) * size ) as size argument to devm_kzalloc(..) I thought for better code readability I will use kzalloc_array() as the function name suggests we are allocating memory for an array.

My point is devm_k*alloc() and k*alloc() are quite different on the paper. One will allocate memory for a given device while the other is unknown memory.

It would have been better to call the function devm_kzalloc_array() to keep to keep the code coherent. Can you please send a patch to make the switch?

Ok. I will modify the code as per your request as below . I will use devm_kcalloc(..) as this will be more coherent.

xen/drivers/passthrough/arm/smmu.c +2 -1
index da2cd457d7..658c40433c 100644
@@ -149,7 +149,8 @@ typedef enum irqreturn irqreturn_t;
  #define kzalloc(size, flags)           _xzalloc(size, sizeof(void *))
  #define devm_kzalloc(dev, size, flags) _xzalloc(size, sizeof(void *))
  #define kmalloc_array(size, n, flags)  _xmalloc_array(size, sizeof(void *), n)
-#define kzalloc_array(size, n, flags)  _xzalloc_array(size, sizeof(void *), n)
+#define devm_kcalloc(dev, n, size, flags)                      \
+       _xzalloc_array(size, sizeof(void *), n)
 
  static void __iomem *devm_ioremap_resource(struct device *dev,
                                            struct resource *res)

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) · line 2229

Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +2 -1
@@ -2222,7 +2223,8 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
                 smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
 
                 /* Zero-initialised to mark as invalid */
-               smmu->smrs = kzalloc_array(sizeof(*smmu->smrs), size, GFP_KERNEL);
+               smmu->smrs = devm_kcalloc(smmu->dev, size, sizeof(*smmu->smrs),
+                                                               GFP_KERNEL);
                 if (!smmu->smrs)
                         return -ENOMEM;

This sounds good to me.

Cheers,

Signature · 1 line
Julien Grall