From: Pavel Begunkov Date: Mon, 23 Mar 2026 12:43:53 +0000 (+0000) Subject: io_uring/zcrx: extract netdev+area init into a helper X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06fc3b6d388dfa9c3df62830e07be828324b99e3;p=thirdparty%2Fkernel%2Flinux.git io_uring/zcrx: extract netdev+area init into a helper In preparation to following patches, add a function that is responsibly for looking up a netdev, creating an area, DMA mapping it and opening a queue. Signed-off-by: Pavel Begunkov Link: https://patch.msgid.link/88cb6f746ecb496a9030756125419df273d0b003.1774261953.git.asml.silence@gmail.com Signed-off-by: Jens Axboe --- diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index a6a08ee48b34f..b0f889b11b730 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -751,10 +751,50 @@ err: return ret; } +static int zcrx_register_netdev(struct io_zcrx_ifq *ifq, + struct io_uring_zcrx_ifq_reg *reg, + struct io_uring_zcrx_area_reg *area) +{ + struct pp_memory_provider_params mp_param = {}; + unsigned if_rxq = reg->if_rxq; + int ret; + + ifq->netdev = netdev_get_by_index_lock(current->nsproxy->net_ns, + reg->if_idx); + if (!ifq->netdev) + return -ENODEV; + + netdev_hold(ifq->netdev, &ifq->netdev_tracker, GFP_KERNEL); + + ifq->dev = netdev_queue_get_dma_dev(ifq->netdev, if_rxq); + if (!ifq->dev) { + ret = -EOPNOTSUPP; + goto netdev_put_unlock; + } + get_device(ifq->dev); + + ret = io_zcrx_create_area(ifq, area, reg); + if (ret) + goto netdev_put_unlock; + + if (reg->rx_buf_len) + mp_param.rx_page_size = 1U << ifq->niov_shift; + mp_param.mp_ops = &io_uring_pp_zc_ops; + mp_param.mp_priv = ifq; + ret = __net_mp_open_rxq(ifq->netdev, if_rxq, &mp_param, NULL); + if (ret) + goto netdev_put_unlock; + + ifq->if_rxq = if_rxq; + ret = 0; +netdev_put_unlock: + netdev_unlock(ifq->netdev); + return ret; +} + int io_register_zcrx_ifq(struct io_ring_ctx *ctx, struct io_uring_zcrx_ifq_reg __user *arg) { - struct pp_memory_provider_params mp_param = {}; struct io_uring_zcrx_area_reg area; struct io_uring_zcrx_ifq_reg reg; struct io_uring_region_desc rd; @@ -821,33 +861,9 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, if (ret) goto err; - ifq->netdev = netdev_get_by_index_lock(current->nsproxy->net_ns, reg.if_idx); - if (!ifq->netdev) { - ret = -ENODEV; - goto err; - } - netdev_hold(ifq->netdev, &ifq->netdev_tracker, GFP_KERNEL); - - ifq->dev = netdev_queue_get_dma_dev(ifq->netdev, reg.if_rxq); - if (!ifq->dev) { - ret = -EOPNOTSUPP; - goto netdev_put_unlock; - } - get_device(ifq->dev); - - ret = io_zcrx_create_area(ifq, &area, ®); - if (ret) - goto netdev_put_unlock; - - if (reg.rx_buf_len) - mp_param.rx_page_size = 1U << ifq->niov_shift; - mp_param.mp_ops = &io_uring_pp_zc_ops; - mp_param.mp_priv = ifq; - ret = __net_mp_open_rxq(ifq->netdev, reg.if_rxq, &mp_param, NULL); + ret = zcrx_register_netdev(ifq, ®, &area); if (ret) - goto netdev_put_unlock; - netdev_unlock(ifq->netdev); - ifq->if_rxq = reg.if_rxq; + goto err; reg.zcrx_id = id; @@ -867,8 +883,6 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, goto err; } return 0; -netdev_put_unlock: - netdev_unlock(ifq->netdev); err: scoped_guard(mutex, &ctx->mmap_lock) xa_erase(&ctx->zcrx_ctxs, id);