Skip to contentSkip to conversation

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

PATCH In review [email protected] 4 participants 5 messages Jul 25, 2024 – Jul 28, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

From: Peng Hao <[email protected]>

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.

---
 drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hfi1/tid_rdma.c +1 -1
index c465966a1d9c..6b1921f6280b 100644
@@ -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;
Signature · 1 line
2.27.0
#1 lore raw
Quoted 8 lines · 在 2024/7/25 9:17, [email protected] 写道:

From: Peng Hao <[email protected]>

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.

---
  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

Quoted 15 lines
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hfi1/tid_rdma.c +1 -1
index c465966a1d9c..6b1921f6280b 100644
@@ -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 lore raw
In reply to [email protected]
Quoted 15 lines · On 7/25/2024 2:17 AM, [email protected] wrote:

From: Peng Hao <[email protected]>

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.

---
 drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hfi1/tid_rdma.c +0 -0
index c465966a1d9c..6b1921f6280b 100644

drivers/infiniband/hw/hfi1/tid_rdma.c static int hfi1_kern_exp_rcv_alloc_flows(struct tid_rdma_request *req, · line 1642

Quoted 8 lines
drivers/infiniband/hw/hfi1/tid_rdma.c +1 -1
@@ -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

#3 lore raw
Quoted 27 lines · Dean Luick
Quoted 15 lines · On 7/25/2024 2:17 AM, [email protected] wrote:

From: Peng Hao <[email protected]>

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.

---
 drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hfi1/tid_rdma.c +0 -0
index c465966a1d9c..6b1921f6280b 100644

drivers/infiniband/hw/hfi1/tid_rdma.c static int hfi1_kern_exp_rcv_alloc_flows(struct tid_rdma_request *req, · line 1642

Quoted 8 lines
drivers/infiniband/hw/hfi1/tid_rdma.c +1 -1
@@ -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.

Quoted 1 line

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

Quoted 5 lines

-Dean

External recipient

#4 lore raw
In reply to [email protected]
Quoted 4 lines · On Thu, Jul 25, 2024 at 03:17:16PM +0800, [email protected] wrote:

From: Peng Hao <[email protected]>

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

Quoted 22 lines
---
 drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hfi1/tid_rdma.c +1 -1
index c465966a1d9c..6b1921f6280b 100644
@@ -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;
Signature · 1 line
2.27.0