Skip to content

Commit b1151b7

Browse files
Mike Marciniszynjgunthorpe
authored andcommitted
IB/hfi1: Fix alloc failure with larger txqueuelen
The following allocation with large txqueuelen will result in the following warning: Call Trace: __alloc_pages_nodemask+0x283/0x2c0 kmalloc_large_node+0x3c/0xa0 __kmalloc_node+0x22a/0x2f0 hfi1_ipoib_txreq_init+0x19f/0x330 [hfi1] hfi1_ipoib_setup_rn+0xd3/0x1a0 [hfi1] rdma_init_netdev+0x5a/0x80 [ib_core] ipoib_intf_init+0x6c/0x350 [ib_ipoib] ipoib_intf_alloc+0x5c/0xc0 [ib_ipoib] ipoib_add_one+0xbe/0x300 [ib_ipoib] add_client_context+0x12c/0x1a0 [ib_core] ib_register_client+0x147/0x190 [ib_core] ipoib_init_module+0xdd/0x132 [ib_ipoib] do_one_initcall+0x46/0x1c3 do_init_module+0x5a/0x220 load_module+0x14c5/0x17f0 __do_sys_init_module+0x13b/0x180 do_syscall_64+0x5b/0x1a0 entry_SYSCALL_64_after_hwframe+0x65/0xca For ipoib, the txqueuelen is modified with the module parameter send_queue_size. Fix by changing to use kv versions of the same allocator to handle the large allocations. The allocation embeds a hdr struct that is dma mapped. Change that struct to a pointer to a kzalloced struct. Cc: [email protected] Fixes: d99dc60 ("IB/hfi1: Add functions to transmit datagram ipoib packets") Link: https://lore.kernel.org/r/1642287756-182313-3-git-send-email-mike.marciniszyn@cornelisnetworks.com Reviewed-by: Dennis Dalessandro <[email protected]> Signed-off-by: Mike Marciniszyn <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 8c83d39 commit b1151b7

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

drivers/infiniband/hw/hfi1/ipoib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ union hfi1_ipoib_flow {
5555
*/
5656
struct ipoib_txreq {
5757
struct sdma_txreq txreq;
58-
struct hfi1_sdma_header sdma_hdr;
58+
struct hfi1_sdma_header *sdma_hdr;
5959
int sdma_status;
6060
int complete;
6161
struct hfi1_ipoib_dev_priv *priv;

drivers/infiniband/hw/hfi1/ipoib_tx.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void hfi1_ipoib_free_tx(struct ipoib_txreq *tx, int budget)
122122
dd_dev_warn(priv->dd,
123123
"%s: Status = 0x%x pbc 0x%llx txq = %d sde = %d\n",
124124
__func__, tx->sdma_status,
125-
le64_to_cpu(tx->sdma_hdr.pbc), tx->txq->q_idx,
125+
le64_to_cpu(tx->sdma_hdr->pbc), tx->txq->q_idx,
126126
tx->txq->sde->this_idx);
127127
}
128128

@@ -231,7 +231,7 @@ static int hfi1_ipoib_build_tx_desc(struct ipoib_txreq *tx,
231231
{
232232
struct hfi1_devdata *dd = txp->dd;
233233
struct sdma_txreq *txreq = &tx->txreq;
234-
struct hfi1_sdma_header *sdma_hdr = &tx->sdma_hdr;
234+
struct hfi1_sdma_header *sdma_hdr = tx->sdma_hdr;
235235
u16 pkt_bytes =
236236
sizeof(sdma_hdr->pbc) + (txp->hdr_dwords << 2) + tx->skb->len;
237237
int ret;
@@ -256,7 +256,7 @@ static void hfi1_ipoib_build_ib_tx_headers(struct ipoib_txreq *tx,
256256
struct ipoib_txparms *txp)
257257
{
258258
struct hfi1_ipoib_dev_priv *priv = tx->txq->priv;
259-
struct hfi1_sdma_header *sdma_hdr = &tx->sdma_hdr;
259+
struct hfi1_sdma_header *sdma_hdr = tx->sdma_hdr;
260260
struct sk_buff *skb = tx->skb;
261261
struct hfi1_pportdata *ppd = ppd_from_ibp(txp->ibp);
262262
struct rdma_ah_attr *ah_attr = txp->ah_attr;
@@ -483,7 +483,7 @@ static int hfi1_ipoib_send_dma_single(struct net_device *dev,
483483
if (likely(!ret)) {
484484
tx_ok:
485485
trace_sdma_output_ibhdr(txq->priv->dd,
486-
&tx->sdma_hdr.hdr,
486+
&tx->sdma_hdr->hdr,
487487
ib_is_sc5(txp->flow.sc5));
488488
hfi1_ipoib_check_queue_depth(txq);
489489
return NETDEV_TX_OK;
@@ -547,7 +547,7 @@ static int hfi1_ipoib_send_dma_list(struct net_device *dev,
547547
hfi1_ipoib_check_queue_depth(txq);
548548

549549
trace_sdma_output_ibhdr(txq->priv->dd,
550-
&tx->sdma_hdr.hdr,
550+
&tx->sdma_hdr->hdr,
551551
ib_is_sc5(txp->flow.sc5));
552552

553553
if (!netdev_xmit_more())
@@ -683,7 +683,8 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
683683
{
684684
struct net_device *dev = priv->netdev;
685685
u32 tx_ring_size, tx_item_size;
686-
int i;
686+
struct hfi1_ipoib_circ_buf *tx_ring;
687+
int i, j;
687688

688689
/*
689690
* Ring holds 1 less than tx_ring_size
@@ -701,7 +702,9 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
701702

702703
for (i = 0; i < dev->num_tx_queues; i++) {
703704
struct hfi1_ipoib_txq *txq = &priv->txqs[i];
705+
struct ipoib_txreq *tx;
704706

707+
tx_ring = &txq->tx_ring;
705708
iowait_init(&txq->wait,
706709
0,
707710
hfi1_ipoib_flush_txq,
@@ -725,14 +728,19 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
725728
priv->dd->node);
726729

727730
txq->tx_ring.items =
728-
kcalloc_node(tx_ring_size, tx_item_size,
729-
GFP_KERNEL, priv->dd->node);
731+
kvzalloc_node(array_size(tx_ring_size, tx_item_size),
732+
GFP_KERNEL, priv->dd->node);
730733
if (!txq->tx_ring.items)
731734
goto free_txqs;
732735

733736
txq->tx_ring.max_items = tx_ring_size;
734737
txq->tx_ring.shift = ilog2(tx_item_size);
735738
txq->tx_ring.avail = hfi1_ipoib_ring_hwat(txq);
739+
tx_ring = &txq->tx_ring;
740+
for (j = 0; j < tx_ring_size; j++)
741+
hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr =
742+
kzalloc_node(sizeof(*tx->sdma_hdr),
743+
GFP_KERNEL, priv->dd->node);
736744

737745
netif_tx_napi_add(dev, &txq->napi,
738746
hfi1_ipoib_poll_tx_ring,
@@ -746,7 +754,10 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
746754
struct hfi1_ipoib_txq *txq = &priv->txqs[i];
747755

748756
netif_napi_del(&txq->napi);
749-
kfree(txq->tx_ring.items);
757+
tx_ring = &txq->tx_ring;
758+
for (j = 0; j < tx_ring_size; j++)
759+
kfree(hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr);
760+
kvfree(tx_ring->items);
750761
}
751762

752763
kfree(priv->txqs);
@@ -780,17 +791,20 @@ static void hfi1_ipoib_drain_tx_list(struct hfi1_ipoib_txq *txq)
780791

781792
void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv)
782793
{
783-
int i;
794+
int i, j;
784795

785796
for (i = 0; i < priv->netdev->num_tx_queues; i++) {
786797
struct hfi1_ipoib_txq *txq = &priv->txqs[i];
798+
struct hfi1_ipoib_circ_buf *tx_ring = &txq->tx_ring;
787799

788800
iowait_cancel_work(&txq->wait);
789801
iowait_sdma_drain(&txq->wait);
790802
hfi1_ipoib_drain_tx_list(txq);
791803
netif_napi_del(&txq->napi);
792804
hfi1_ipoib_drain_tx_ring(txq);
793-
kfree(txq->tx_ring.items);
805+
for (j = 0; j < tx_ring->max_items; j++)
806+
kfree(hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr);
807+
kvfree(tx_ring->items);
794808
}
795809

796810
kfree(priv->txqs);

0 commit comments

Comments
 (0)