Skip to content

Commit e3c81ba

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: "Seems bigger than usual, a number of things were posted near/during the merg window: - Fix some compilation regressions related to the new DMABUF code - Close a race with ib_register_device() vs netdev events that causes GID table corruption - Compilation warnings with some compilers in bng_re - Correct error unwind in bng_re and the umem pinned dmabuf - Avoid NULL pointer crash in ionic during query_port() - Check the size for uAPI validation checks in EFA - Several system call stack leaks in drivers found with AI - Fix the new restricted_node_type so it works with wildcard listens too" * tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: RDMA/uverbs: Import DMA-BUF module in uverbs_std_types_dmabuf file RDMA/umem: Fix double dma_buf_unpin in failure path RDMA/core: Check id_priv->restricted_node_type in cma_listen_on_dev() RDMA/ionic: Fix kernel stack leak in ionic_create_cq() RDMA/irdma: Fix kernel stack leak in irdma_create_user_ah() IB/mthca: Add missed mthca_unmap_user_db() for mthca_create_srq() RDMA/efa: Fix typo in efa_alloc_mr() RDMA/ionic: Fix potential NULL pointer dereference in ionic_query_port RDMA/bng_re: Unwind bng_re_dev_init properly RDMA/bng_re: Remove unnessary validity checks RDMA/core: Fix stale RoCE GIDs during netdev events at registration RDMA/uverbs: select CONFIG_DMA_SHARED_BUFFER
2 parents b9c8fc2 + 7c2889a commit e3c81ba

14 files changed

Lines changed: 86 additions & 48 deletions

File tree

drivers/infiniband/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ menuconfig INFINIBAND
66
depends on INET
77
depends on m || IPV6 != m
88
depends on !ALPHA
9+
select DMA_SHARED_BUFFER
910
select IRQ_POLL
1011
select DIMLIB
1112
help

drivers/infiniband/core/cache.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,13 @@ static int gid_table_setup_one(struct ib_device *ib_dev)
926926
if (err)
927927
return err;
928928

929+
/*
930+
* Mark the device as ready for GID cache updates. This allows netdev
931+
* event handlers to update the GID cache even before the device is
932+
* fully registered.
933+
*/
934+
ib_device_enable_gid_updates(ib_dev);
935+
929936
rdma_roce_rescan_device(ib_dev);
930937

931938
return err;
@@ -1637,6 +1644,12 @@ void ib_cache_release_one(struct ib_device *device)
16371644

16381645
void ib_cache_cleanup_one(struct ib_device *device)
16391646
{
1647+
/*
1648+
* Clear the GID updates mark first to prevent event handlers from
1649+
* accessing the device while it's being torn down.
1650+
*/
1651+
ib_device_disable_gid_updates(device);
1652+
16401653
/* The cleanup function waits for all in-progress workqueue
16411654
* elements and cleans up the GID cache. This function should be
16421655
* called after the device was removed from the devices list and

drivers/infiniband/core/cma.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2729,13 +2729,17 @@ static int cma_listen_on_dev(struct rdma_id_private *id_priv,
27292729
*to_destroy = NULL;
27302730
if (cma_family(id_priv) == AF_IB && !rdma_cap_ib_cm(cma_dev->device, 1))
27312731
return 0;
2732+
if (id_priv->restricted_node_type != RDMA_NODE_UNSPECIFIED &&
2733+
id_priv->restricted_node_type != cma_dev->device->node_type)
2734+
return 0;
27322735

27332736
dev_id_priv =
27342737
__rdma_create_id(net, cma_listen_handler, id_priv,
27352738
id_priv->id.ps, id_priv->id.qp_type, id_priv);
27362739
if (IS_ERR(dev_id_priv))
27372740
return PTR_ERR(dev_id_priv);
27382741

2742+
dev_id_priv->restricted_node_type = id_priv->restricted_node_type;
27392743
dev_id_priv->state = RDMA_CM_ADDR_BOUND;
27402744
memcpy(cma_src_addr(dev_id_priv), cma_src_addr(id_priv),
27412745
rdma_addr_size(cma_src_addr(id_priv)));
@@ -4194,7 +4198,7 @@ int rdma_restrict_node_type(struct rdma_cm_id *id, u8 node_type)
41944198
}
41954199

41964200
mutex_lock(&lock);
4197-
if (id_priv->cma_dev)
4201+
if (READ_ONCE(id_priv->state) != RDMA_CM_IDLE)
41984202
ret = -EALREADY;
41994203
else
42004204
id_priv->restricted_node_type = node_type;

drivers/infiniband/core/core_priv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
100100
roce_netdev_callback cb,
101101
void *cookie);
102102

103+
void ib_device_enable_gid_updates(struct ib_device *device);
104+
void ib_device_disable_gid_updates(struct ib_device *device);
105+
103106
typedef int (*nldev_callback)(struct ib_device *device,
104107
struct sk_buff *skb,
105108
struct netlink_callback *cb,

drivers/infiniband/core/device.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static struct workqueue_struct *ib_unreg_wq;
9393
static DEFINE_XARRAY_FLAGS(devices, XA_FLAGS_ALLOC);
9494
static DECLARE_RWSEM(devices_rwsem);
9595
#define DEVICE_REGISTERED XA_MARK_1
96+
#define DEVICE_GID_UPDATES XA_MARK_2
9697

9798
static u32 highest_client_id;
9899
#define CLIENT_REGISTERED XA_MARK_1
@@ -2412,11 +2413,42 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
24122413
unsigned long index;
24132414

24142415
down_read(&devices_rwsem);
2415-
xa_for_each_marked (&devices, index, dev, DEVICE_REGISTERED)
2416+
xa_for_each_marked(&devices, index, dev, DEVICE_GID_UPDATES)
24162417
ib_enum_roce_netdev(dev, filter, filter_cookie, cb, cookie);
24172418
up_read(&devices_rwsem);
24182419
}
24192420

2421+
/**
2422+
* ib_device_enable_gid_updates - Mark device as ready for GID cache updates
2423+
* @device: Device to mark
2424+
*
2425+
* Called after GID table is allocated and initialized. After this mark is set,
2426+
* netdevice event handlers can update the device's GID cache. This allows
2427+
* events that arrive during device registration to be processed, avoiding
2428+
* stale GID entries when netdev properties change during the device
2429+
* registration process.
2430+
*/
2431+
void ib_device_enable_gid_updates(struct ib_device *device)
2432+
{
2433+
down_write(&devices_rwsem);
2434+
xa_set_mark(&devices, device->index, DEVICE_GID_UPDATES);
2435+
up_write(&devices_rwsem);
2436+
}
2437+
2438+
/**
2439+
* ib_device_disable_gid_updates - Clear the GID updates mark
2440+
* @device: Device to unmark
2441+
*
2442+
* Called before GID table cleanup to prevent event handlers from accessing
2443+
* the device while it's being torn down.
2444+
*/
2445+
void ib_device_disable_gid_updates(struct ib_device *device)
2446+
{
2447+
down_write(&devices_rwsem);
2448+
xa_clear_mark(&devices, device->index, DEVICE_GID_UPDATES);
2449+
up_write(&devices_rwsem);
2450+
}
2451+
24202452
/*
24212453
* ib_enum_all_devs - enumerate all ib_devices
24222454
* @cb: Callback to call for each found ib_device

drivers/infiniband/core/umem_dmabuf.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,11 @@ ib_umem_dmabuf_get_pinned_with_dma_device(struct ib_device *device,
218218

219219
err = ib_umem_dmabuf_map_pages(umem_dmabuf);
220220
if (err)
221-
goto err_unpin;
221+
goto err_release;
222222
dma_resv_unlock(umem_dmabuf->attach->dmabuf->resv);
223223

224224
return umem_dmabuf;
225225

226-
err_unpin:
227-
dma_buf_unpin(umem_dmabuf->attach);
228226
err_release:
229227
dma_resv_unlock(umem_dmabuf->attach->dmabuf->resv);
230228
ib_umem_release(&umem_dmabuf->umem);

drivers/infiniband/core/uverbs_std_types_dmabuf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "rdma_core.h"
1111
#include "uverbs.h"
1212

13+
MODULE_IMPORT_NS("DMA_BUF");
14+
1315
static int uverbs_dmabuf_attach(struct dma_buf *dmabuf,
1416
struct dma_buf_attachment *attachment)
1517
{

drivers/infiniband/hw/bng_re/bng_dev.c

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ static void bng_re_destroy_chip_ctx(struct bng_re_dev *rdev)
5454
{
5555
struct bng_re_chip_ctx *chip_ctx;
5656

57-
if (!rdev->chip_ctx)
58-
return;
59-
6057
kfree(rdev->dev_attr);
6158
rdev->dev_attr = NULL;
6259

@@ -124,12 +121,6 @@ static int bng_re_net_ring_free(struct bng_re_dev *rdev,
124121
struct bnge_fw_msg fw_msg = {};
125122
int rc = -EINVAL;
126123

127-
if (!rdev)
128-
return rc;
129-
130-
if (!aux_dev)
131-
return rc;
132-
133124
bng_re_init_hwrm_hdr((void *)&req, HWRM_RING_FREE);
134125
req.ring_type = type;
135126
req.ring_id = cpu_to_le16(fw_ring_id);
@@ -150,10 +141,7 @@ static int bng_re_net_ring_alloc(struct bng_re_dev *rdev,
150141
struct hwrm_ring_alloc_input req = {};
151142
struct hwrm_ring_alloc_output resp;
152143
struct bnge_fw_msg fw_msg = {};
153-
int rc = -EINVAL;
154-
155-
if (!aux_dev)
156-
return rc;
144+
int rc;
157145

158146
bng_re_init_hwrm_hdr((void *)&req, HWRM_RING_ALLOC);
159147
req.enables = 0;
@@ -184,10 +172,7 @@ static int bng_re_stats_ctx_free(struct bng_re_dev *rdev)
184172
struct hwrm_stat_ctx_free_input req = {};
185173
struct hwrm_stat_ctx_free_output resp = {};
186174
struct bnge_fw_msg fw_msg = {};
187-
int rc = -EINVAL;
188-
189-
if (!aux_dev)
190-
return rc;
175+
int rc;
191176

192177
bng_re_init_hwrm_hdr((void *)&req, HWRM_STAT_CTX_FREE);
193178
req.stat_ctx_id = cpu_to_le32(rdev->stats_ctx.fw_id);
@@ -208,13 +193,10 @@ static int bng_re_stats_ctx_alloc(struct bng_re_dev *rdev)
208193
struct hwrm_stat_ctx_alloc_output resp = {};
209194
struct hwrm_stat_ctx_alloc_input req = {};
210195
struct bnge_fw_msg fw_msg = {};
211-
int rc = -EINVAL;
196+
int rc;
212197

213198
stats->fw_id = BNGE_INVALID_STATS_CTX_ID;
214199

215-
if (!aux_dev)
216-
return rc;
217-
218200
bng_re_init_hwrm_hdr((void *)&req, HWRM_STAT_CTX_ALLOC);
219201
req.update_period_ms = cpu_to_le32(1000);
220202
req.stats_dma_addr = cpu_to_le64(stats->dma_map);
@@ -303,7 +285,7 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
303285
if (rc) {
304286
ibdev_err(&rdev->ibdev,
305287
"Failed to register with netedev: %#x\n", rc);
306-
return -EINVAL;
288+
goto reg_netdev_fail;
307289
}
308290

309291
set_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
@@ -312,19 +294,16 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
312294
ibdev_err(&rdev->ibdev,
313295
"RoCE requires minimum 2 MSI-X vectors, but only %d reserved\n",
314296
rdev->aux_dev->auxr_info->msix_requested);
315-
bnge_unregister_dev(rdev->aux_dev);
316-
clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
317-
return -EINVAL;
297+
rc = -EINVAL;
298+
goto msix_ctx_fail;
318299
}
319300
ibdev_dbg(&rdev->ibdev, "Got %d MSI-X vectors\n",
320301
rdev->aux_dev->auxr_info->msix_requested);
321302

322303
rc = bng_re_setup_chip_ctx(rdev);
323304
if (rc) {
324-
bnge_unregister_dev(rdev->aux_dev);
325-
clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
326305
ibdev_err(&rdev->ibdev, "Failed to get chip context\n");
327-
return -EINVAL;
306+
goto msix_ctx_fail;
328307
}
329308

330309
bng_re_query_hwrm_version(rdev);
@@ -333,16 +312,14 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
333312
if (rc) {
334313
ibdev_err(&rdev->ibdev,
335314
"Failed to allocate RCFW Channel: %#x\n", rc);
336-
goto fail;
315+
goto alloc_fw_chl_fail;
337316
}
338317

339318
/* Allocate nq record memory */
340319
rdev->nqr = kzalloc_obj(*rdev->nqr);
341320
if (!rdev->nqr) {
342-
bng_re_destroy_chip_ctx(rdev);
343-
bnge_unregister_dev(rdev->aux_dev);
344-
clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
345-
return -ENOMEM;
321+
rc = -ENOMEM;
322+
goto nq_alloc_fail;
346323
}
347324

348325
rdev->nqr->num_msix = rdev->aux_dev->auxr_info->msix_requested;
@@ -411,9 +388,15 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
411388
free_ring:
412389
bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id, type);
413390
free_rcfw:
391+
kfree(rdev->nqr);
392+
nq_alloc_fail:
414393
bng_re_free_rcfw_channel(&rdev->rcfw);
415-
fail:
416-
bng_re_dev_uninit(rdev);
394+
alloc_fw_chl_fail:
395+
bng_re_destroy_chip_ctx(rdev);
396+
msix_ctx_fail:
397+
bnge_unregister_dev(rdev->aux_dev);
398+
clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
399+
reg_netdev_fail:
417400
return rc;
418401
}
419402

@@ -486,8 +469,7 @@ static void bng_re_remove(struct auxiliary_device *adev)
486469

487470
rdev = dev_info->rdev;
488471

489-
if (rdev)
490-
bng_re_remove_device(rdev, adev);
472+
bng_re_remove_device(rdev, adev);
491473
kfree(dev_info);
492474
}
493475

drivers/infiniband/hw/efa/efa_verbs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ static struct efa_mr *efa_alloc_mr(struct ib_pd *ibpd, int access_flags,
16611661
struct efa_mr *mr;
16621662

16631663
if (udata && udata->inlen &&
1664-
!ib_is_udata_cleared(udata, 0, sizeof(udata->inlen))) {
1664+
!ib_is_udata_cleared(udata, 0, udata->inlen)) {
16651665
ibdev_dbg(&dev->ibdev,
16661666
"Incompatible ABI params, udata not cleared\n");
16671667
return ERR_PTR(-EINVAL);

drivers/infiniband/hw/ionic/ionic_controlpath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ int ionic_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
12181218
rdma_udata_to_drv_context(udata, struct ionic_ctx, ibctx);
12191219
struct ionic_vcq *vcq = to_ionic_vcq(ibcq);
12201220
struct ionic_tbl_buf buf = {};
1221-
struct ionic_cq_resp resp;
1221+
struct ionic_cq_resp resp = {};
12221222
struct ionic_cq_req req;
12231223
int udma_idx = 0, rc;
12241224

0 commit comments

Comments
 (0)