diff mbox series

[for-next,3/3] RDMA/erdma: Remove unnecessary __GFP_ZERO flag

Message ID 20240311113821.22482-4-boshiyu@alibaba-inc.com (mailing list archive)
State Accepted
Headers show
Series RDMA/erdma: A series of fixes for the erdma driver | expand

Commit Message

Boshi Yu March 11, 2024, 11:38 a.m. UTC
From: Boshi Yu <boshiyu@linux.alibaba.com>

The dma_alloc_coherent() interface automatically zero the memory returned.
Thus, we do not need to specify the __GFP_ZERO flag explicitly when we call
dma_alloc_coherent().

Reviewed-by: Cheng Xu <chengyou@linux.alibaba.com>
Signed-off-by: Boshi Yu <boshiyu@linux.alibaba.com>
---
 drivers/infiniband/hw/erdma/erdma_cmdq.c | 6 ++----
 drivers/infiniband/hw/erdma/erdma_eq.c   | 6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)

Comments

Leon Romanovsky March 12, 2024, 10:53 a.m. UTC | #1
On Mon, Mar 11, 2024 at 07:38:21PM +0800, Boshi Yu wrote:
> From: Boshi Yu <boshiyu@linux.alibaba.com>
> 
> The dma_alloc_coherent() interface automatically zero the memory returned.

Can you please point to the DMA code which does that?

> Thus, we do not need to specify the __GFP_ZERO flag explicitly when we call
> dma_alloc_coherent().
> 
> Reviewed-by: Cheng Xu <chengyou@linux.alibaba.com>
> Signed-off-by: Boshi Yu <boshiyu@linux.alibaba.com>
> ---
>  drivers/infiniband/hw/erdma/erdma_cmdq.c | 6 ++----
>  drivers/infiniband/hw/erdma/erdma_eq.c   | 6 ++----
>  2 files changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/erdma/erdma_cmdq.c b/drivers/infiniband/hw/erdma/erdma_cmdq.c
> index 0ac2683cfccf..43ff40b5a09d 100644
> --- a/drivers/infiniband/hw/erdma/erdma_cmdq.c
> +++ b/drivers/infiniband/hw/erdma/erdma_cmdq.c
> @@ -127,8 +127,7 @@ static int erdma_cmdq_cq_init(struct erdma_dev *dev)
>  
>  	cq->depth = cmdq->sq.depth;
>  	cq->qbuf = dma_alloc_coherent(&dev->pdev->dev, cq->depth << CQE_SHIFT,
> -				      &cq->qbuf_dma_addr,
> -				      GFP_KERNEL | __GFP_ZERO);
> +				      &cq->qbuf_dma_addr, GFP_KERNEL);
>  	if (!cq->qbuf)
>  		return -ENOMEM;
>  
> @@ -162,8 +161,7 @@ static int erdma_cmdq_eq_init(struct erdma_dev *dev)
>  
>  	eq->depth = cmdq->max_outstandings;
>  	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
> -				      &eq->qbuf_dma_addr,
> -				      GFP_KERNEL | __GFP_ZERO);
> +				      &eq->qbuf_dma_addr, GFP_KERNEL);
>  	if (!eq->qbuf)
>  		return -ENOMEM;
>  
> diff --git a/drivers/infiniband/hw/erdma/erdma_eq.c b/drivers/infiniband/hw/erdma/erdma_eq.c
> index 0a4746e6d05c..84ccdd8144c9 100644
> --- a/drivers/infiniband/hw/erdma/erdma_eq.c
> +++ b/drivers/infiniband/hw/erdma/erdma_eq.c
> @@ -87,8 +87,7 @@ int erdma_aeq_init(struct erdma_dev *dev)
>  	eq->depth = ERDMA_DEFAULT_EQ_DEPTH;
>  
>  	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
> -				      &eq->qbuf_dma_addr,
> -				      GFP_KERNEL | __GFP_ZERO);
> +				      &eq->qbuf_dma_addr, GFP_KERNEL);
>  	if (!eq->qbuf)
>  		return -ENOMEM;
>  
> @@ -237,8 +236,7 @@ static int erdma_ceq_init_one(struct erdma_dev *dev, u16 ceqn)
>  
>  	eq->depth = ERDMA_DEFAULT_EQ_DEPTH;
>  	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
> -				      &eq->qbuf_dma_addr,
> -				      GFP_KERNEL | __GFP_ZERO);
> +				      &eq->qbuf_dma_addr, GFP_KERNEL);
>  	if (!eq->qbuf)
>  		return -ENOMEM;
>  
> -- 
> 2.39.3
> 
>
Boshi Yu March 13, 2024, 2:40 a.m. UTC | #2
On Tue, Mar 12, 2024 at 12:53:05PM +0200, Leon Romanovsky wrote:
> On Mon, Mar 11, 2024 at 07:38:21PM +0800, Boshi Yu wrote:
> > From: Boshi Yu <boshiyu@linux.alibaba.com>
> > 
> > The dma_alloc_coherent() interface automatically zero the memory returned.
> 
> Can you please point to the DMA code which does that?

We have noticed a patchset which ensures that dma_alloc_coherent() always
returns zeroed memory. The url of this patchset is listed as below:
https://lore.kernel.org/all/20181214082515.14835-1-hch@lst.de/T/#m70c723c646004445713f31b7837f7e9d910c06f5

Besides, you may refer to commit 518a2f1925c3 ("dma-mapping: zero memory returned from dma_alloc_*")
for details. This commit zeros memory by passing __GFP_ZERO flag or
calling memset internally. For example, the dma_alloc_direct() interface
calls memset() to zero the allocated memory.

Thanks,
Boshi Yu

> 
> > Thus, we do not need to specify the __GFP_ZERO flag explicitly when we call
> > dma_alloc_coherent().
> > 
> > Reviewed-by: Cheng Xu <chengyou@linux.alibaba.com>
> > Signed-off-by: Boshi Yu <boshiyu@linux.alibaba.com>
> > ---
> >  drivers/infiniband/hw/erdma/erdma_cmdq.c | 6 ++----
> >  drivers/infiniband/hw/erdma/erdma_eq.c   | 6 ++----
> >  2 files changed, 4 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/infiniband/hw/erdma/erdma_cmdq.c b/drivers/infiniband/hw/erdma/erdma_cmdq.c
> > index 0ac2683cfccf..43ff40b5a09d 100644
> > --- a/drivers/infiniband/hw/erdma/erdma_cmdq.c
> > +++ b/drivers/infiniband/hw/erdma/erdma_cmdq.c
> > @@ -127,8 +127,7 @@ static int erdma_cmdq_cq_init(struct erdma_dev *dev)
> >  
> >  	cq->depth = cmdq->sq.depth;
> >  	cq->qbuf = dma_alloc_coherent(&dev->pdev->dev, cq->depth << CQE_SHIFT,
> > -				      &cq->qbuf_dma_addr,
> > -				      GFP_KERNEL | __GFP_ZERO);
> > +				      &cq->qbuf_dma_addr, GFP_KERNEL);
> >  	if (!cq->qbuf)
> >  		return -ENOMEM;
> >  
> > @@ -162,8 +161,7 @@ static int erdma_cmdq_eq_init(struct erdma_dev *dev)
> >  
> >  	eq->depth = cmdq->max_outstandings;
> >  	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
> > -				      &eq->qbuf_dma_addr,
> > -				      GFP_KERNEL | __GFP_ZERO);
> > +				      &eq->qbuf_dma_addr, GFP_KERNEL);
> >  	if (!eq->qbuf)
> >  		return -ENOMEM;
> >  
> > diff --git a/drivers/infiniband/hw/erdma/erdma_eq.c b/drivers/infiniband/hw/erdma/erdma_eq.c
> > index 0a4746e6d05c..84ccdd8144c9 100644
> > --- a/drivers/infiniband/hw/erdma/erdma_eq.c
> > +++ b/drivers/infiniband/hw/erdma/erdma_eq.c
> > @@ -87,8 +87,7 @@ int erdma_aeq_init(struct erdma_dev *dev)
> >  	eq->depth = ERDMA_DEFAULT_EQ_DEPTH;
> >  
> >  	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
> > -				      &eq->qbuf_dma_addr,
> > -				      GFP_KERNEL | __GFP_ZERO);
> > +				      &eq->qbuf_dma_addr, GFP_KERNEL);
> >  	if (!eq->qbuf)
> >  		return -ENOMEM;
> >  
> > @@ -237,8 +236,7 @@ static int erdma_ceq_init_one(struct erdma_dev *dev, u16 ceqn)
> >  
> >  	eq->depth = ERDMA_DEFAULT_EQ_DEPTH;
> >  	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
> > -				      &eq->qbuf_dma_addr,
> > -				      GFP_KERNEL | __GFP_ZERO);
> > +				      &eq->qbuf_dma_addr, GFP_KERNEL);
> >  	if (!eq->qbuf)
> >  		return -ENOMEM;
> >  
> > -- 
> > 2.39.3
> > 
> >
Leon Romanovsky March 13, 2024, 9:31 a.m. UTC | #3
On Wed, Mar 13, 2024 at 10:40:06AM +0800, Boshi Yu wrote:
> On Tue, Mar 12, 2024 at 12:53:05PM +0200, Leon Romanovsky wrote:
> > On Mon, Mar 11, 2024 at 07:38:21PM +0800, Boshi Yu wrote:
> > > From: Boshi Yu <boshiyu@linux.alibaba.com>
> > > 
> > > The dma_alloc_coherent() interface automatically zero the memory returned.
> > 
> > Can you please point to the DMA code which does that?
> 
> We have noticed a patchset which ensures that dma_alloc_coherent() always
> returns zeroed memory. The url of this patchset is listed as below:
> https://lore.kernel.org/all/20181214082515.14835-1-hch@lst.de/T/#m70c723c646004445713f31b7837f7e9d910c06f5
> 
> Besides, you may refer to commit 518a2f1925c3 ("dma-mapping: zero memory returned from dma_alloc_*")
> for details. This commit zeros memory by passing __GFP_ZERO flag or
> calling memset internally. For example, the dma_alloc_direct() interface
> calls memset() to zero the allocated memory.

Thanks
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/erdma/erdma_cmdq.c b/drivers/infiniband/hw/erdma/erdma_cmdq.c
index 0ac2683cfccf..43ff40b5a09d 100644
--- a/drivers/infiniband/hw/erdma/erdma_cmdq.c
+++ b/drivers/infiniband/hw/erdma/erdma_cmdq.c
@@ -127,8 +127,7 @@  static int erdma_cmdq_cq_init(struct erdma_dev *dev)
 
 	cq->depth = cmdq->sq.depth;
 	cq->qbuf = dma_alloc_coherent(&dev->pdev->dev, cq->depth << CQE_SHIFT,
-				      &cq->qbuf_dma_addr,
-				      GFP_KERNEL | __GFP_ZERO);
+				      &cq->qbuf_dma_addr, GFP_KERNEL);
 	if (!cq->qbuf)
 		return -ENOMEM;
 
@@ -162,8 +161,7 @@  static int erdma_cmdq_eq_init(struct erdma_dev *dev)
 
 	eq->depth = cmdq->max_outstandings;
 	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
-				      &eq->qbuf_dma_addr,
-				      GFP_KERNEL | __GFP_ZERO);
+				      &eq->qbuf_dma_addr, GFP_KERNEL);
 	if (!eq->qbuf)
 		return -ENOMEM;
 
diff --git a/drivers/infiniband/hw/erdma/erdma_eq.c b/drivers/infiniband/hw/erdma/erdma_eq.c
index 0a4746e6d05c..84ccdd8144c9 100644
--- a/drivers/infiniband/hw/erdma/erdma_eq.c
+++ b/drivers/infiniband/hw/erdma/erdma_eq.c
@@ -87,8 +87,7 @@  int erdma_aeq_init(struct erdma_dev *dev)
 	eq->depth = ERDMA_DEFAULT_EQ_DEPTH;
 
 	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
-				      &eq->qbuf_dma_addr,
-				      GFP_KERNEL | __GFP_ZERO);
+				      &eq->qbuf_dma_addr, GFP_KERNEL);
 	if (!eq->qbuf)
 		return -ENOMEM;
 
@@ -237,8 +236,7 @@  static int erdma_ceq_init_one(struct erdma_dev *dev, u16 ceqn)
 
 	eq->depth = ERDMA_DEFAULT_EQ_DEPTH;
 	eq->qbuf = dma_alloc_coherent(&dev->pdev->dev, eq->depth << EQE_SHIFT,
-				      &eq->qbuf_dma_addr,
-				      GFP_KERNEL | __GFP_ZERO);
+				      &eq->qbuf_dma_addr, GFP_KERNEL);
 	if (!eq->qbuf)
 		return -ENOMEM;