Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 59b8b32ac8d4 ("io_uring/zcrx: add support for custom DMA devices")
Signed-off-by: David Wei <dw@davidwei.uk>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

David Wei and committed by
Jens Axboe
b6c5f945 c07a491c

+10 -6
+10 -6
io_uring/zcrx.c
··· 620 620 if (ret) 621 621 goto err; 622 622 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); 625 624 if (!ifq->netdev) { 626 625 ret = -ENODEV; 627 626 goto err; 628 627 } 628 + netdev_hold(ifq->netdev, &ifq->netdev_tracker, GFP_KERNEL); 629 629 630 630 ifq->dev = netdev_queue_get_dma_dev(ifq->netdev, reg.if_rxq); 631 631 if (!ifq->dev) { 632 632 ret = -EOPNOTSUPP; 633 - goto err; 633 + goto netdev_put_unlock; 634 634 } 635 635 get_device(ifq->dev); 636 636 637 637 ret = io_zcrx_create_area(ifq, &area); 638 638 if (ret) 639 - goto err; 639 + goto netdev_put_unlock; 640 640 641 641 mp_param.mp_ops = &io_uring_pp_zc_ops; 642 642 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); 644 644 if (ret) 645 - goto err; 645 + goto netdev_put_unlock; 646 + netdev_unlock(ifq->netdev); 646 647 ifq->if_rxq = reg.if_rxq; 647 648 648 649 reg.zcrx_id = id; ··· 662 661 goto err; 663 662 } 664 663 return 0; 664 + netdev_put_unlock: 665 + netdev_put(ifq->netdev, &ifq->netdev_tracker); 666 + netdev_unlock(ifq->netdev); 665 667 err: 666 668 scoped_guard(mutex, &ctx->mmap_lock) 667 669 xa_erase(&ctx->zcrx_ctxs, id);