Skip to content

Commit

Permalink
IB/hfi1: Convert kzalloc_node and kcalloc to use kcalloc_node
Browse files Browse the repository at this point in the history
Kzalloc_node API doesn't check for overflows in size multiplication.
While kcalloc API check for overflows in size multiplication
but these implementations are not NUMA-aware.

This conversion allowed for correcting an allocation used in the hot
path to be on the local NUMA and ensure us overflow free multiplication
for the size of a memory allocation.

Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Kamenee Arumugam <kamenee.arumugam@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
  • Loading branch information
Kamenee Arumugam authored and Jason Gunthorpe committed Feb 1, 2018
1 parent 2ff124d commit 953a9ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
17 changes: 9 additions & 8 deletions drivers/infiniband/hw/hfi1/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int hfi1_create_kctxts(struct hfi1_devdata *dd)
u16 i;
int ret;

dd->rcd = kzalloc_node(dd->num_rcv_contexts * sizeof(*dd->rcd),
dd->rcd = kcalloc_node(dd->num_rcv_contexts, sizeof(*dd->rcd),
GFP_KERNEL, dd->node);
if (!dd->rcd)
return -ENOMEM;
Expand Down Expand Up @@ -439,15 +439,16 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,
* The resulting value will be rounded down to the closest
* multiple of dd->rcv_entries.group_size.
*/
rcd->egrbufs.buffers = kzalloc_node(
rcd->egrbufs.count * sizeof(*rcd->egrbufs.buffers),
GFP_KERNEL, numa);
rcd->egrbufs.buffers =
kcalloc_node(rcd->egrbufs.count,
sizeof(*rcd->egrbufs.buffers),
GFP_KERNEL, numa);
if (!rcd->egrbufs.buffers)
goto bail;
rcd->egrbufs.rcvtids = kzalloc_node(
rcd->egrbufs.count *
sizeof(*rcd->egrbufs.rcvtids),
GFP_KERNEL, numa);
rcd->egrbufs.rcvtids =
kcalloc_node(rcd->egrbufs.count,
sizeof(*rcd->egrbufs.rcvtids),
GFP_KERNEL, numa);
if (!rcd->egrbufs.rcvtids)
goto bail;
rcd->egrbufs.size = eager_buffer_size;
Expand Down
15 changes: 8 additions & 7 deletions drivers/infiniband/hw/hfi1/pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ int init_send_contexts(struct hfi1_devdata *dd)
dd->hw_to_sw = kmalloc_array(TXE_NUM_CONTEXTS, sizeof(u8),
GFP_KERNEL);
dd->send_contexts = kcalloc(dd->num_send_contexts,
sizeof(struct send_context_info),
GFP_KERNEL);
sizeof(struct send_context_info),
GFP_KERNEL);
if (!dd->send_contexts || !dd->hw_to_sw) {
kfree(dd->hw_to_sw);
kfree(dd->send_contexts);
Expand Down Expand Up @@ -856,8 +856,9 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type,
* so head == tail can mean empty.
*/
sc->sr_size = sci->credits + 1;
sc->sr = kzalloc_node(sizeof(union pio_shadow_ring) *
sc->sr_size, GFP_KERNEL, numa);
sc->sr = kcalloc_node(sc->sr_size,
sizeof(union pio_shadow_ring),
GFP_KERNEL, numa);
if (!sc->sr) {
sc_free(sc);
return NULL;
Expand Down Expand Up @@ -1958,9 +1959,9 @@ int init_pervl_scs(struct hfi1_devdata *dd)
hfi1_init_ctxt(dd->vld[15].sc);
dd->vld[15].mtu = enum_to_mtu(OPA_MTU_2048);

dd->kernel_send_context = kzalloc_node(dd->num_send_contexts *
sizeof(struct send_context *),
GFP_KERNEL, dd->node);
dd->kernel_send_context = kcalloc_node(dd->num_send_contexts,
sizeof(struct send_context *),
GFP_KERNEL, dd->node);
if (!dd->kernel_send_context)
goto freesc15;

Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/hfi1/sdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,8 @@ int sdma_init(struct hfi1_devdata *dd, u8 port)
num_engines, descq_cnt);

/* alloc memory for array of send engines */
dd->per_sdma = kcalloc(num_engines, sizeof(*dd->per_sdma), GFP_KERNEL);
dd->per_sdma = kcalloc_node(num_engines, sizeof(*dd->per_sdma),
GFP_KERNEL, dd->node);
if (!dd->per_sdma)
return ret;

Expand Down

0 comments on commit 953a9ce

Please sign in to comment.