[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation


  • To: Julien Grall <julien@xxxxxxx>
  • From: Rahul Singh <Rahul.Singh@xxxxxxx>
  • Date: Fri, 2 Jul 2021 09:54:41 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MAeN4g9hFqVqKa89MWTgNV1qnWJrfTy96z5kl5qbVYA=; b=HG+Gk7zB3fHUKzDVDLTTV1BHXkmia1NrPsbIn0C2hkY4U6ZZvCzzZ4X+6W/8JrK78zexZOqdmPYXxieKvz862ItYtEyZnXXQ+81pB4CmEZ/CbVNs/+hprJXWRkah66IRs8h1sqC06h5WTnvHZBwPNaP6rzbyVltz53POGfP8kMSIunfelu+0CkqYVbiHgcNgW+KxTmEISv4pg9fUZ0Ylv2YgE5nHnI20vEjIRC3N6Atz4U7kLqXlQlmLcRiOHwI9Izho0gesjNkfvzo/jisoHd3/g+Cfuv1M9GiuOO3V7hMp8uOP4g2V4aA1Fj6RyGCeN2eYRFjCSlxU3L8l22k5+Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cbFLS3PzWzUmJyoa9Or9fsW3CJC5o6FOGVqf26D2iERwhuaOsKuq5gzrUt0yRFxR1R1f8Wexjx/ZZJhHl2idazLC89VXSRAnpVZwFO/NKB/IklB+pN3dmBHjLbrbaObvDycj2TaFZVdG6kYbAmv6ZbafRWoslStY2W7MKd3TPm3/Hqg3LeeKEY47vuoLRUsGdQzjOOmRX/Xy1fu5UikeE8Oomld+w5AkKhRRxpOz0qdukJgF7nfF4Dys76qHdPNFEJu2JIPnMGzn/JNSunED+jzbyv38sOKhxAWH8dBd+GL4ByzFKtn6R77w0U5LbqSbnO+duewW6zqj0SOFTqK8hQ==
  • Authentication-results-original: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 02 Jul 2021 09:55:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHXaeBuO8lC15Rvy0GU2dq6zulC56ssS6GAgACREoCAAAMWgIACnQOA
  • Thread-topic: [PATCH] xen/arm: smmuv1: Fixed stream matching register allocation

Hi Julien,

> On 30 Jun 2021, at 7:00 pm, Julien Grall <julien@xxxxxxx> wrote:
> 
> 
> 
> On 30/06/2021 18:49, Rahul Singh wrote:
>> Hi Julien,
> 
> Hi,
> 
>>> On 30 Jun 2021, at 10:09 am, Julien Grall <julien@xxxxxxx> 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@xxxxxxxxxx>
>>>> Tested-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
>>>> Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
>>>> ---
>>>>  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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.