Skip to content

Commit 67f1819

Browse files
spikehaxboe
authored andcommitted
io_uring/zcrx: call netdev_queue_get_dma_dev() under instance lock
netdev ops must be called under instance lock or rtnl_lock, but io_register_zcrx_ifq() isn't doing this for netdev_queue_get_dma_dev(). Fix this by taking the instance lock using netdev_get_by_index_lock(). Extended the instance lock section to include attaching a memory provider. Could not move io_zcrx_create_area() outside, since the dmabuf codepath IORING_ZCRX_AREA_DMABUF requires ifq->dev. Fixes: 59b8b32 ("io_uring/zcrx: add support for custom DMA devices") Signed-off-by: David Wei <[email protected]> Reviewed-by: Pavel Begunkov <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 0da5d94 commit 67f1819

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

io_uring/zcrx.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,29 +620,30 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
620620
if (ret)
621621
goto err;
622622

623-
ifq->netdev = netdev_get_by_index(current->nsproxy->net_ns, reg.if_idx,
624-
&ifq->netdev_tracker, GFP_KERNEL);
623+
ifq->netdev = netdev_get_by_index_lock(current->nsproxy->net_ns, reg.if_idx);
625624
if (!ifq->netdev) {
626625
ret = -ENODEV;
627626
goto err;
628627
}
628+
netdev_hold(ifq->netdev, &ifq->netdev_tracker, GFP_KERNEL);
629629

630630
ifq->dev = netdev_queue_get_dma_dev(ifq->netdev, reg.if_rxq);
631631
if (!ifq->dev) {
632632
ret = -EOPNOTSUPP;
633-
goto err;
633+
goto netdev_put_unlock;
634634
}
635635
get_device(ifq->dev);
636636

637637
ret = io_zcrx_create_area(ifq, &area);
638638
if (ret)
639-
goto err;
639+
goto netdev_put_unlock;
640640

641641
mp_param.mp_ops = &io_uring_pp_zc_ops;
642642
mp_param.mp_priv = ifq;
643-
ret = net_mp_open_rxq(ifq->netdev, reg.if_rxq, &mp_param);
643+
ret = __net_mp_open_rxq(ifq->netdev, reg.if_rxq, &mp_param, NULL);
644644
if (ret)
645-
goto err;
645+
goto netdev_put_unlock;
646+
netdev_unlock(ifq->netdev);
646647
ifq->if_rxq = reg.if_rxq;
647648

648649
reg.zcrx_id = id;
@@ -661,6 +662,9 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
661662
goto err;
662663
}
663664
return 0;
665+
netdev_put_unlock:
666+
netdev_put(ifq->netdev, &ifq->netdev_tracker);
667+
netdev_unlock(ifq->netdev);
664668
err:
665669
scoped_guard(mutex, &ctx->mmap_lock)
666670
xa_erase(&ctx->zcrx_ctxs, id);

0 commit comments

Comments
 (0)