xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation
@ 2021-06-25 16:37 Rahul Singh
  2021-06-25 16:37 ` [PATCH] xen/arm: smmuv1: Set privileged attr to 'default' Rahul Singh
  2021-06-30  9:09 ` [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation Julien Grall
  0 siblings, 2 replies; 8+ messages in thread
From: Rahul Singh @ 2021-06-25 16:37 UTC (permalink / raw)
  To: xen-devel
  Cc: bertrand.marquis, rahul.singh, Stefano Stabellini, Julien Grall,
	Volodymyr Babchuk

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.

Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Tested-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
---
 xen/drivers/passthrough/arm/smmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index d9a3a0cbf6..da2cd457d7 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -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;
 
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] xen/arm: smmuv1: Set privileged attr to 'default'
  2021-06-25 16:37 [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation Rahul Singh
@ 2021-06-25 16:37 ` Rahul Singh
  2021-06-25 22:00   ` Stefano Stabellini
  2021-06-30  9:09 ` [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation Julien Grall
  1 sibling, 1 reply; 8+ messages in thread
From: Rahul Singh @ 2021-06-25 16:37 UTC (permalink / raw)
  To: xen-devel
  Cc: bertrand.marquis, rahul.singh, Stefano Stabellini, Julien Grall,
	Volodymyr Babchuk

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.

    Acked-by: Will Deacon <will.deacon@arm.com>
    Signed-off-by: Sricharan R <sricharan@codeaurora.org>
    Signed-off-by: Will Deacon <will.deacon@arm.com>

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
---
 xen/drivers/passthrough/arm/smmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index 1a68c2ab3b..d9a3a0cbf6 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -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);
 	}
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/arm: smmuv1: Set privileged attr to 'default'
  2021-06-25 16:37 ` [PATCH] xen/arm: smmuv1: Set privileged attr to 'default' Rahul Singh
@ 2021-06-25 22:00   ` Stefano Stabellini
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Stabellini @ 2021-06-25 22:00 UTC (permalink / raw)
  To: Rahul Singh
  Cc: xen-devel, bertrand.marquis, Stefano Stabellini, Julien Grall,
	Volodymyr Babchuk

On Fri, 25 Jun 2021, Rahul Singh wrote:
> 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.
> 
>     Acked-by: Will Deacon <will.deacon@arm.com>
>     Signed-off-by: Sricharan R <sricharan@codeaurora.org>
>     Signed-off-by: Will Deacon <will.deacon@arm.com>
> 
> Signed-off-by: Rahul Singh <rahul.singh@arm.com>


Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Tested-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>  xen/drivers/passthrough/arm/smmu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
> index 1a68c2ab3b..d9a3a0cbf6 100644
> --- a/xen/drivers/passthrough/arm/smmu.c
> +++ b/xen/drivers/passthrough/arm/smmu.c
> @@ -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);
>  	}
> -- 
> 2.17.1
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation
  2021-06-25 16:37 [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation Rahul Singh
  2021-06-25 16:37 ` [PATCH] xen/arm: smmuv1: Set privileged attr to 'default' Rahul Singh
@ 2021-06-30  9:09 ` Julien Grall
  2021-06-30 17:49   ` Rahul Singh
  1 sibling, 1 reply; 8+ messages in thread
From: Julien Grall @ 2021-06-30  9:09 UTC (permalink / raw)
  To: Rahul Singh, xen-devel
  Cc: bertrand.marquis, Stefano Stabellini, Volodymyr Babchuk

Hi Rahul,

On 25/06/2021 17:37, Rahul Singh wrote:
> 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.
> 
> Acked-by: Stefano Stabellini <sstabellini@kernel.org>
> Tested-by: Stefano Stabellini <sstabellini@kernel.org>
> Signed-off-by: Rahul Singh <rahul.singh@arm.com>
> ---
>   xen/drivers/passthrough/arm/smmu.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
> index d9a3a0cbf6..da2cd457d7 100644
> --- a/xen/drivers/passthrough/arm/smmu.c
> +++ b/xen/drivers/passthrough/arm/smmu.c
> @@ -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);

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,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation
  2021-06-30  9:09 ` [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation Julien Grall
@ 2021-06-30 17:49   ` Rahul Singh
  2021-06-30 18:00     ` Julien Grall
  0 siblings, 1 reply; 8+ messages in thread
From: Rahul Singh @ 2021-06-30 17:49 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, Bertrand Marquis, Stefano Stabellini, Volodymyr Babchuk

Hi Julien,

> On 30 Jun 2021, at 10:09 am, Julien Grall <julien@xen.org> wrote:
> 
> Hi Rahul,
> 
> On 25/06/2021 17:37, Rahul Singh wrote:
>> 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.
>> Acked-by: Stefano Stabellini <sstabellini@kernel.org>
>> Tested-by: Stefano Stabellini <sstabellini@kernel.org>
>> Signed-off-by: Rahul Singh <rahul.singh@arm.com>
>> ---
>>  xen/drivers/passthrough/arm/smmu.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
>> index d9a3a0cbf6..da2cd457d7 100644
>> --- a/xen/drivers/passthrough/arm/smmu.c
>> +++ b/xen/drivers/passthrough/arm/smmu.c
>> @@ -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);
> 
> 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.

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

Ok.

Regards,
Rahul
> Cheers,
> 
> -- 
> Julien Grall



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation
  2021-06-30 17:49   ` Rahul Singh
@ 2021-06-30 18:00     ` Julien Grall
  2021-07-02  9:54       ` Rahul Singh
  0 siblings, 1 reply; 8+ messages in thread
From: Julien Grall @ 2021-06-30 18:00 UTC (permalink / raw)
  To: Rahul Singh
  Cc: xen-devel, Bertrand Marquis, Stefano Stabellini, Volodymyr Babchuk



On 30/06/2021 18:49, Rahul Singh wrote:
> Hi Julien,

Hi,

>> On 30 Jun 2021, at 10:09 am, Julien Grall <julien@xen.org> wrote:
>>
>> Hi Rahul,
>>
>> On 25/06/2021 17:37, Rahul Singh wrote:
>>> 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.
>>> Acked-by: Stefano Stabellini <sstabellini@kernel.org>
>>> Tested-by: Stefano Stabellini <sstabellini@kernel.org>
>>> Signed-off-by: Rahul Singh <rahul.singh@arm.com>
>>> ---
>>>   xen/drivers/passthrough/arm/smmu.c | 3 ++-
>>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
>>> index d9a3a0cbf6..da2cd457d7 100644
>>> --- a/xen/drivers/passthrough/arm/smmu.c
>>> +++ b/xen/drivers/passthrough/arm/smmu.c
>>> @@ -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);
>>
>> 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.

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,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation
  2021-06-30 18:00     ` Julien Grall
@ 2021-07-02  9:54       ` Rahul Singh
  2021-07-03 12:28         ` Julien Grall
  0 siblings, 1 reply; 8+ messages in thread
From: Rahul Singh @ 2021-07-02  9:54 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, Bertrand Marquis, Stefano Stabellini, Volodymyr Babchuk

Hi Julien,

> On 30 Jun 2021, at 7:00 pm, Julien Grall <julien@xen.org> wrote:
> 
> 
> 
> On 30/06/2021 18:49, Rahul Singh wrote:
>> Hi Julien,
> 
> Hi,
> 
>>> On 30 Jun 2021, at 10:09 am, Julien Grall <julien@xen.org> wrote:
>>> 
>>> Hi Rahul,
>>> 
>>> On 25/06/2021 17:37, Rahul Singh wrote:
>>>> 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.
>>>> Acked-by: Stefano Stabellini <sstabellini@kernel.org>
>>>> Tested-by: Stefano Stabellini <sstabellini@kernel.org>
>>>> Signed-off-by: Rahul Singh <rahul.singh@arm.com>
>>>> ---
>>>>  xen/drivers/passthrough/arm/smmu.c | 3 ++-
>>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
>>>> index d9a3a0cbf6..da2cd457d7 100644
>>>> --- a/xen/drivers/passthrough/arm/smmu.c
>>>> +++ b/xen/drivers/passthrough/arm/smmu.c
>>>> @@ -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);
>>> 
>>> 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.
> 
> 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.

diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index da2cd457d7..658c40433c 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -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

> 
> Cheers,
> 
> -- 
> Julien Grall



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation
  2021-07-02  9:54       ` Rahul Singh
@ 2021-07-03 12:28         ` Julien Grall
  0 siblings, 0 replies; 8+ messages in thread
From: Julien Grall @ 2021-07-03 12:28 UTC (permalink / raw)
  To: Rahul Singh
  Cc: xen-devel, Bertrand Marquis, Stefano Stabellini, Volodymyr Babchuk

On 02/07/2021 10:54, Rahul Singh wrote:
> Hi Julien,

Hi Rahul,

>> On 30 Jun 2021, at 7:00 pm, Julien Grall <julien@xen.org> wrote:
>>
>>
>>
>> On 30/06/2021 18:49, Rahul Singh wrote:
>>> Hi Julien,
>>
>> Hi,
>>
>>>> On 30 Jun 2021, at 10:09 am, Julien Grall <julien@xen.org> wrote:
>>>>
>>>> Hi Rahul,
>>>>
>>>> On 25/06/2021 17:37, Rahul Singh wrote:
>>>>> 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.
>>>>> Acked-by: Stefano Stabellini <sstabellini@kernel.org>
>>>>> Tested-by: Stefano Stabellini <sstabellini@kernel.org>
>>>>> Signed-off-by: Rahul Singh <rahul.singh@arm.com>
>>>>> ---
>>>>>   xen/drivers/passthrough/arm/smmu.c | 3 ++-
>>>>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>>>> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
>>>>> index d9a3a0cbf6..da2cd457d7 100644
>>>>> --- a/xen/drivers/passthrough/arm/smmu.c
>>>>> +++ b/xen/drivers/passthrough/arm/smmu.c
>>>>> @@ -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);
>>>>
>>>> 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.
>>
>> 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.
> 
> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
> index da2cd457d7..658c40433c 100644
> --- a/xen/drivers/passthrough/arm/smmu.c
> +++ b/xen/drivers/passthrough/arm/smmu.c
> @@ -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;

This sounds good to me.

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-07-03 12:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 16:37 [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation Rahul Singh
2021-06-25 16:37 ` [PATCH] xen/arm: smmuv1: Set privileged attr to 'default' Rahul Singh
2021-06-25 22:00   ` Stefano Stabellini
2021-06-30  9:09 ` [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation Julien Grall
2021-06-30 17:49   ` Rahul Singh
2021-06-30 18:00     ` Julien Grall
2021-07-02  9:54       ` Rahul Singh
2021-07-03 12:28         ` Julien Grall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).