Skip to content

Commit 0457e51

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
Pull rdma fixes from Jason Gunthorpe: "Some medium sized bugs in the various drivers. A couple are more recent regressions: - Fix two panics in hfi1 and two allocation problems - Send the IGMP to the correct address in cma - Squash a syzkaller bug related to races reading the multicast list - Memory leak in siw and cm - Fix a corner case spec compliance for HFI/QIB - Correct the implementation of fences in siw - Error unwind bug in mlx4" * tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: RDMA/mlx4: Don't continue event handler after memory allocation failure RDMA/siw: Fix broken RDMA Read Fence/Resume logic. IB/rdmavt: Validate remote_addr during loopback atomic tests IB/cm: Release previously acquired reference counter in the cm_id_priv RDMA/siw: Fix refcounting leak in siw_create_qp() RDMA/ucma: Protect mc during concurrent multicast leaves RDMA/cma: Use correct address when leaving multicast group IB/hfi1: Fix tstats alloc and dealloc IB/hfi1: Fix AIP early init panic IB/hfi1: Fix alloc failure with larger txqueuelen IB/hfi1: Fix panic with larger ipoib send_queue_size
2 parents fc93310 + f3136c4 commit 0457e51

File tree

11 files changed

+95
-64
lines changed

11 files changed

+95
-64
lines changed

drivers/infiniband/core/cm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3322,7 +3322,7 @@ static int cm_lap_handler(struct cm_work *work)
33223322
ret = cm_init_av_by_path(param->alternate_path, NULL, &alt_av);
33233323
if (ret) {
33243324
rdma_destroy_ah_attr(&ah_attr);
3325-
return -EINVAL;
3325+
goto deref;
33263326
}
33273327

33283328
spin_lock_irq(&cm_id_priv->lock);

drivers/infiniband/core/cma.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ static const char * const cma_events[] = {
6767
[RDMA_CM_EVENT_TIMEWAIT_EXIT] = "timewait exit",
6868
};
6969

70-
static void cma_set_mgid(struct rdma_id_private *id_priv, struct sockaddr *addr,
71-
union ib_gid *mgid);
70+
static void cma_iboe_set_mgid(struct sockaddr *addr, union ib_gid *mgid,
71+
enum ib_gid_type gid_type);
7272

7373
const char *__attribute_const__ rdma_event_msg(enum rdma_cm_event_type event)
7474
{
@@ -1846,17 +1846,19 @@ static void destroy_mc(struct rdma_id_private *id_priv,
18461846
if (dev_addr->bound_dev_if)
18471847
ndev = dev_get_by_index(dev_addr->net,
18481848
dev_addr->bound_dev_if);
1849-
if (ndev) {
1849+
if (ndev && !send_only) {
1850+
enum ib_gid_type gid_type;
18501851
union ib_gid mgid;
18511852

1852-
cma_set_mgid(id_priv, (struct sockaddr *)&mc->addr,
1853-
&mgid);
1854-
1855-
if (!send_only)
1856-
cma_igmp_send(ndev, &mgid, false);
1857-
1858-
dev_put(ndev);
1853+
gid_type = id_priv->cma_dev->default_gid_type
1854+
[id_priv->id.port_num -
1855+
rdma_start_port(
1856+
id_priv->cma_dev->device)];
1857+
cma_iboe_set_mgid((struct sockaddr *)&mc->addr, &mgid,
1858+
gid_type);
1859+
cma_igmp_send(ndev, &mgid, false);
18591860
}
1861+
dev_put(ndev);
18601862

18611863
cancel_work_sync(&mc->iboe_join.work);
18621864
}

drivers/infiniband/core/ucma.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct ucma_context {
9595
u64 uid;
9696

9797
struct list_head list;
98+
struct list_head mc_list;
9899
struct work_struct close_work;
99100
};
100101

@@ -105,6 +106,7 @@ struct ucma_multicast {
105106

106107
u64 uid;
107108
u8 join_state;
109+
struct list_head list;
108110
struct sockaddr_storage addr;
109111
};
110112

@@ -198,6 +200,7 @@ static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
198200

199201
INIT_WORK(&ctx->close_work, ucma_close_id);
200202
init_completion(&ctx->comp);
203+
INIT_LIST_HEAD(&ctx->mc_list);
201204
/* So list_del() will work if we don't do ucma_finish_ctx() */
202205
INIT_LIST_HEAD(&ctx->list);
203206
ctx->file = file;
@@ -484,19 +487,19 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
484487

485488
static void ucma_cleanup_multicast(struct ucma_context *ctx)
486489
{
487-
struct ucma_multicast *mc;
488-
unsigned long index;
490+
struct ucma_multicast *mc, *tmp;
489491

490-
xa_for_each(&multicast_table, index, mc) {
491-
if (mc->ctx != ctx)
492-
continue;
492+
xa_lock(&multicast_table);
493+
list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) {
494+
list_del(&mc->list);
493495
/*
494496
* At this point mc->ctx->ref is 0 so the mc cannot leave the
495497
* lock on the reader and this is enough serialization
496498
*/
497-
xa_erase(&multicast_table, index);
499+
__xa_erase(&multicast_table, mc->id);
498500
kfree(mc);
499501
}
502+
xa_unlock(&multicast_table);
500503
}
501504

502505
static void ucma_cleanup_mc_events(struct ucma_multicast *mc)
@@ -1469,12 +1472,16 @@ static ssize_t ucma_process_join(struct ucma_file *file,
14691472
mc->uid = cmd->uid;
14701473
memcpy(&mc->addr, addr, cmd->addr_size);
14711474

1472-
if (xa_alloc(&multicast_table, &mc->id, NULL, xa_limit_32b,
1475+
xa_lock(&multicast_table);
1476+
if (__xa_alloc(&multicast_table, &mc->id, NULL, xa_limit_32b,
14731477
GFP_KERNEL)) {
14741478
ret = -ENOMEM;
14751479
goto err_free_mc;
14761480
}
14771481

1482+
list_add_tail(&mc->list, &ctx->mc_list);
1483+
xa_unlock(&multicast_table);
1484+
14781485
mutex_lock(&ctx->mutex);
14791486
ret = rdma_join_multicast(ctx->cm_id, (struct sockaddr *)&mc->addr,
14801487
join_state, mc);
@@ -1500,8 +1507,11 @@ static ssize_t ucma_process_join(struct ucma_file *file,
15001507
mutex_unlock(&ctx->mutex);
15011508
ucma_cleanup_mc_events(mc);
15021509
err_xa_erase:
1503-
xa_erase(&multicast_table, mc->id);
1510+
xa_lock(&multicast_table);
1511+
list_del(&mc->list);
1512+
__xa_erase(&multicast_table, mc->id);
15041513
err_free_mc:
1514+
xa_unlock(&multicast_table);
15051515
kfree(mc);
15061516
err_put_ctx:
15071517
ucma_put_ctx(ctx);
@@ -1569,15 +1579,17 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file,
15691579
mc = ERR_PTR(-EINVAL);
15701580
else if (!refcount_inc_not_zero(&mc->ctx->ref))
15711581
mc = ERR_PTR(-ENXIO);
1572-
else
1573-
__xa_erase(&multicast_table, mc->id);
1574-
xa_unlock(&multicast_table);
15751582

15761583
if (IS_ERR(mc)) {
1584+
xa_unlock(&multicast_table);
15771585
ret = PTR_ERR(mc);
15781586
goto out;
15791587
}
15801588

1589+
list_del(&mc->list);
1590+
__xa_erase(&multicast_table, mc->id);
1591+
xa_unlock(&multicast_table);
1592+
15811593
mutex_lock(&mc->ctx->mutex);
15821594
rdma_leave_multicast(mc->ctx->cm_id, (struct sockaddr *) &mc->addr);
15831595
mutex_unlock(&mc->ctx->mutex);

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_main.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,35 @@ static int hfi1_ipoib_dev_init(struct net_device *dev)
2222
int ret;
2323

2424
dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
25+
if (!dev->tstats)
26+
return -ENOMEM;
2527

2628
ret = priv->netdev_ops->ndo_init(dev);
2729
if (ret)
28-
return ret;
30+
goto out_ret;
2931

3032
ret = hfi1_netdev_add_data(priv->dd,
3133
qpn_from_mac(priv->netdev->dev_addr),
3234
dev);
3335
if (ret < 0) {
3436
priv->netdev_ops->ndo_uninit(dev);
35-
return ret;
37+
goto out_ret;
3638
}
3739

3840
return 0;
41+
out_ret:
42+
free_percpu(dev->tstats);
43+
dev->tstats = NULL;
44+
return ret;
3945
}
4046

4147
static void hfi1_ipoib_dev_uninit(struct net_device *dev)
4248
{
4349
struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
4450

51+
free_percpu(dev->tstats);
52+
dev->tstats = NULL;
53+
4554
hfi1_netdev_remove_data(priv->dd, qpn_from_mac(priv->netdev->dev_addr));
4655

4756
priv->netdev_ops->ndo_uninit(dev);
@@ -166,12 +175,7 @@ static void hfi1_ipoib_netdev_dtor(struct net_device *dev)
166175
hfi1_ipoib_rxq_deinit(priv->netdev);
167176

168177
free_percpu(dev->tstats);
169-
}
170-
171-
static void hfi1_ipoib_free_rdma_netdev(struct net_device *dev)
172-
{
173-
hfi1_ipoib_netdev_dtor(dev);
174-
free_netdev(dev);
178+
dev->tstats = NULL;
175179
}
176180

177181
static void hfi1_ipoib_set_id(struct net_device *dev, int id)
@@ -211,24 +215,23 @@ static int hfi1_ipoib_setup_rn(struct ib_device *device,
211215
priv->port_num = port_num;
212216
priv->netdev_ops = netdev->netdev_ops;
213217

214-
netdev->netdev_ops = &hfi1_ipoib_netdev_ops;
215-
216218
ib_query_pkey(device, port_num, priv->pkey_index, &priv->pkey);
217219

218220
rc = hfi1_ipoib_txreq_init(priv);
219221
if (rc) {
220222
dd_dev_err(dd, "IPoIB netdev TX init - failed(%d)\n", rc);
221-
hfi1_ipoib_free_rdma_netdev(netdev);
222223
return rc;
223224
}
224225

225226
rc = hfi1_ipoib_rxq_init(netdev);
226227
if (rc) {
227228
dd_dev_err(dd, "IPoIB netdev RX init - failed(%d)\n", rc);
228-
hfi1_ipoib_free_rdma_netdev(netdev);
229+
hfi1_ipoib_txreq_deinit(priv);
229230
return rc;
230231
}
231232

233+
netdev->netdev_ops = &hfi1_ipoib_netdev_ops;
234+
232235
netdev->priv_destructor = hfi1_ipoib_netdev_dtor;
233236
netdev->needs_free_netdev = true;
234237

drivers/infiniband/hw/hfi1/ipoib_tx.c

Lines changed: 26 additions & 12 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;
734-
txq->tx_ring.shift = ilog2(tx_ring_size);
737+
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);

drivers/infiniband/hw/mlx4/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3237,7 +3237,7 @@ static void mlx4_ib_event(struct mlx4_dev *dev, void *ibdev_ptr,
32373237
case MLX4_DEV_EVENT_PORT_MGMT_CHANGE:
32383238
ew = kmalloc(sizeof *ew, GFP_ATOMIC);
32393239
if (!ew)
3240-
break;
3240+
return;
32413241

32423242
INIT_WORK(&ew->work, handle_port_mgmt_change_event);
32433243
memcpy(&ew->ib_eqe, eqe, sizeof *eqe);

drivers/infiniband/sw/rdmavt/qp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,6 +3073,8 @@ void rvt_ruc_loopback(struct rvt_qp *sqp)
30733073
case IB_WR_ATOMIC_FETCH_AND_ADD:
30743074
if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC)))
30753075
goto inv_err;
3076+
if (unlikely(wqe->atomic_wr.remote_addr & (sizeof(u64) - 1)))
3077+
goto inv_err;
30763078
if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
30773079
wqe->atomic_wr.remote_addr,
30783080
wqe->atomic_wr.rkey,

drivers/infiniband/sw/siw/siw.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,9 @@ static inline struct siw_sqe *orq_get_current(struct siw_qp *qp)
644644
return &qp->orq[qp->orq_get % qp->attrs.orq_size];
645645
}
646646

647-
static inline struct siw_sqe *orq_get_tail(struct siw_qp *qp)
648-
{
649-
return &qp->orq[qp->orq_put % qp->attrs.orq_size];
650-
}
651-
652647
static inline struct siw_sqe *orq_get_free(struct siw_qp *qp)
653648
{
654-
struct siw_sqe *orq_e = orq_get_tail(qp);
649+
struct siw_sqe *orq_e = &qp->orq[qp->orq_put % qp->attrs.orq_size];
655650

656651
if (READ_ONCE(orq_e->flags) == 0)
657652
return orq_e;

0 commit comments

Comments
 (0)