diff mbox series

infiniband/hw/hfi1/tid_rdma: use kmalloc_array_node()

Message ID 20240725071716.26136-1-flyingpeng@tencent.com (mailing list archive)
State Rejected
Headers show
Series infiniband/hw/hfi1/tid_rdma: use kmalloc_array_node() | expand

Commit Message

Hao Peng July 25, 2024, 7:17 a.m. UTC
From: Peng Hao <flyingpeng@tencent.com>

kmalloc_array_node() is a NUMA-aware version of kmalloc_array that
has overflow checking and can be used as a replacement for kmalloc_node.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
 drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Zhu Yanjun July 25, 2024, 11:58 a.m. UTC | #1
在 2024/7/25 9:17, flyingpenghao@gmail.com 写道:
> From: Peng Hao <flyingpeng@tencent.com>
> 
> kmalloc_array_node() is a NUMA-aware version of kmalloc_array that
> has overflow checking and can be used as a replacement for kmalloc_node.
> 
> Signed-off-by: Peng Hao <flyingpeng@tencent.com>
> ---
>   drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-

drivers/infiniband/sw/rdmavt/mmap.c:124:

ip = kmalloc_node(sizeof(*ip), GFP_KERNEL, rdi->dparms.node);

In the above file, not sure if this kmalloc_node needs to be replaced 
with kmalloc_array_node or not.

Zhu Yanjun

>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/hfi1/tid_rdma.c b/drivers/infiniband/hw/hfi1/tid_rdma.c
> index c465966a1d9c..6b1921f6280b 100644
> --- a/drivers/infiniband/hw/hfi1/tid_rdma.c
> +++ b/drivers/infiniband/hw/hfi1/tid_rdma.c
> @@ -1636,7 +1636,7 @@ static int hfi1_kern_exp_rcv_alloc_flows(struct tid_rdma_request *req,
>   
>   	if (likely(req->flows))
>   		return 0;
> -	flows = kmalloc_node(MAX_FLOWS * sizeof(*flows), gfp,
> +	flows = kmalloc_array_node(MAX_FLOWS, sizeof(*flows), gfp,
>   			     req->rcd->numa_id);
>   	if (!flows)
>   		return -ENOMEM;
Dean Luick July 25, 2024, 1:46 p.m. UTC | #2
On 7/25/2024 2:17 AM, flyingpenghao@gmail.com wrote:
> From: Peng Hao <flyingpeng@tencent.com>
>
> kmalloc_array_node() is a NUMA-aware version of kmalloc_array that
> has overflow checking and can be used as a replacement for kmalloc_node.
>
> Signed-off-by: Peng Hao <flyingpeng@tencent.com>
> ---
>  drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/hw/hfi1/tid_rdma.c b/drivers/infiniband/hw/hfi1/tid_rdma.c
> index c465966a1d9c..6b1921f6280b 100644
> --- a/drivers/infiniband/hw/hfi1/tid_rdma.c
> +++ b/drivers/infiniband/hw/hfi1/tid_rdma.c
> @@ -1636,7 +1636,7 @@ static int hfi1_kern_exp_rcv_alloc_flows(struct tid_rdma_request *req,
>
>       if (likely(req->flows))
>               return 0;
> -     flows = kmalloc_node(MAX_FLOWS * sizeof(*flows), gfp,
> +     flows = kmalloc_array_node(MAX_FLOWS, sizeof(*flows), gfp,
>                            req->rcd->numa_id);
>       if (!flows)
>               return -ENOMEM;

This is clearly not going to overflow.  I see no reason to change it.

However, I don't know the current policy on such replacements.

-Dean

External recipient
Leon Romanovsky July 28, 2024, 7:52 a.m. UTC | #3
On Thu, Jul 25, 2024 at 08:46:30AM -0500, Dean Luick wrote:
> On 7/25/2024 2:17 AM, flyingpenghao@gmail.com wrote:
> > From: Peng Hao <flyingpeng@tencent.com>
> >
> > kmalloc_array_node() is a NUMA-aware version of kmalloc_array that
> > has overflow checking and can be used as a replacement for kmalloc_node.
> >
> > Signed-off-by: Peng Hao <flyingpeng@tencent.com>
> > ---
> >  drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/infiniband/hw/hfi1/tid_rdma.c b/drivers/infiniband/hw/hfi1/tid_rdma.c
> > index c465966a1d9c..6b1921f6280b 100644
> > --- a/drivers/infiniband/hw/hfi1/tid_rdma.c
> > +++ b/drivers/infiniband/hw/hfi1/tid_rdma.c
> > @@ -1636,7 +1636,7 @@ static int hfi1_kern_exp_rcv_alloc_flows(struct tid_rdma_request *req,
> >
> >       if (likely(req->flows))
> >               return 0;
> > -     flows = kmalloc_node(MAX_FLOWS * sizeof(*flows), gfp,
> > +     flows = kmalloc_array_node(MAX_FLOWS, sizeof(*flows), gfp,
> >                            req->rcd->numa_id);
> >       if (!flows)
> >               return -ENOMEM;
> 
> This is clearly not going to overflow.  I see no reason to change it.
> 
> However, I don't know the current policy on such replacements.

There is no policy. My preference is to change if other changes are done in
the same area, but do not change something that is not broken.

Thanks

> 
> -Dean
> 
> External recipient
>
Leon Romanovsky July 28, 2024, 7:53 a.m. UTC | #4
On Thu, Jul 25, 2024 at 03:17:16PM +0800, flyingpenghao@gmail.com wrote:
> From: Peng Hao <flyingpeng@tencent.com>
> 
> kmalloc_array_node() is a NUMA-aware version of kmalloc_array that
> has overflow checking and can be used as a replacement for kmalloc_node.

Original code is correct, the overflow is not going to happen.

Thanks

> 
> Signed-off-by: Peng Hao <flyingpeng@tencent.com>
> ---
>  drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/hfi1/tid_rdma.c b/drivers/infiniband/hw/hfi1/tid_rdma.c
> index c465966a1d9c..6b1921f6280b 100644
> --- a/drivers/infiniband/hw/hfi1/tid_rdma.c
> +++ b/drivers/infiniband/hw/hfi1/tid_rdma.c
> @@ -1636,7 +1636,7 @@ static int hfi1_kern_exp_rcv_alloc_flows(struct tid_rdma_request *req,
>  
>  	if (likely(req->flows))
>  		return 0;
> -	flows = kmalloc_node(MAX_FLOWS * sizeof(*flows), gfp,
> +	flows = kmalloc_array_node(MAX_FLOWS, sizeof(*flows), gfp,
>  			     req->rcd->numa_id);
>  	if (!flows)
>  		return -ENOMEM;
> -- 
> 2.27.0
>
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/hfi1/tid_rdma.c b/drivers/infiniband/hw/hfi1/tid_rdma.c
index c465966a1d9c..6b1921f6280b 100644
--- a/drivers/infiniband/hw/hfi1/tid_rdma.c
+++ b/drivers/infiniband/hw/hfi1/tid_rdma.c
@@ -1636,7 +1636,7 @@  static int hfi1_kern_exp_rcv_alloc_flows(struct tid_rdma_request *req,
 
 	if (likely(req->flows))
 		return 0;
-	flows = kmalloc_node(MAX_FLOWS * sizeof(*flows), gfp,
+	flows = kmalloc_array_node(MAX_FLOWS, sizeof(*flows), gfp,
 			     req->rcd->numa_id);
 	if (!flows)
 		return -ENOMEM;