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: 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 <asml.silence@gmail.com>
Link: https://patch.msgid.link/88cb6f746ecb496a9030756125419df273d0b003.1774261953.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
06fc3b6d b8d6eb6c

+43 -29
+43 -29
io_uring/zcrx.c
··· 751 751 return ret; 752 752 } 753 753 754 + static int zcrx_register_netdev(struct io_zcrx_ifq *ifq, 755 + struct io_uring_zcrx_ifq_reg *reg, 756 + struct io_uring_zcrx_area_reg *area) 757 + { 758 + struct pp_memory_provider_params mp_param = {}; 759 + unsigned if_rxq = reg->if_rxq; 760 + int ret; 761 + 762 + ifq->netdev = netdev_get_by_index_lock(current->nsproxy->net_ns, 763 + reg->if_idx); 764 + if (!ifq->netdev) 765 + return -ENODEV; 766 + 767 + netdev_hold(ifq->netdev, &ifq->netdev_tracker, GFP_KERNEL); 768 + 769 + ifq->dev = netdev_queue_get_dma_dev(ifq->netdev, if_rxq); 770 + if (!ifq->dev) { 771 + ret = -EOPNOTSUPP; 772 + goto netdev_put_unlock; 773 + } 774 + get_device(ifq->dev); 775 + 776 + ret = io_zcrx_create_area(ifq, area, reg); 777 + if (ret) 778 + goto netdev_put_unlock; 779 + 780 + if (reg->rx_buf_len) 781 + mp_param.rx_page_size = 1U << ifq->niov_shift; 782 + mp_param.mp_ops = &io_uring_pp_zc_ops; 783 + mp_param.mp_priv = ifq; 784 + ret = __net_mp_open_rxq(ifq->netdev, if_rxq, &mp_param, NULL); 785 + if (ret) 786 + goto netdev_put_unlock; 787 + 788 + ifq->if_rxq = if_rxq; 789 + ret = 0; 790 + netdev_put_unlock: 791 + netdev_unlock(ifq->netdev); 792 + return ret; 793 + } 794 + 754 795 int io_register_zcrx_ifq(struct io_ring_ctx *ctx, 755 796 struct io_uring_zcrx_ifq_reg __user *arg) 756 797 { 757 - struct pp_memory_provider_params mp_param = {}; 758 798 struct io_uring_zcrx_area_reg area; 759 799 struct io_uring_zcrx_ifq_reg reg; 760 800 struct io_uring_region_desc rd; ··· 861 821 if (ret) 862 822 goto err; 863 823 864 - ifq->netdev = netdev_get_by_index_lock(current->nsproxy->net_ns, reg.if_idx); 865 - if (!ifq->netdev) { 866 - ret = -ENODEV; 824 + ret = zcrx_register_netdev(ifq, &reg, &area); 825 + if (ret) 867 826 goto err; 868 - } 869 - netdev_hold(ifq->netdev, &ifq->netdev_tracker, GFP_KERNEL); 870 - 871 - ifq->dev = netdev_queue_get_dma_dev(ifq->netdev, reg.if_rxq); 872 - if (!ifq->dev) { 873 - ret = -EOPNOTSUPP; 874 - goto netdev_put_unlock; 875 - } 876 - get_device(ifq->dev); 877 - 878 - ret = io_zcrx_create_area(ifq, &area, &reg); 879 - if (ret) 880 - goto netdev_put_unlock; 881 - 882 - if (reg.rx_buf_len) 883 - mp_param.rx_page_size = 1U << ifq->niov_shift; 884 - mp_param.mp_ops = &io_uring_pp_zc_ops; 885 - mp_param.mp_priv = ifq; 886 - ret = __net_mp_open_rxq(ifq->netdev, reg.if_rxq, &mp_param, NULL); 887 - if (ret) 888 - goto netdev_put_unlock; 889 - netdev_unlock(ifq->netdev); 890 - ifq->if_rxq = reg.if_rxq; 891 827 892 828 reg.zcrx_id = id; 893 829 ··· 883 867 goto err; 884 868 } 885 869 return 0; 886 - netdev_put_unlock: 887 - netdev_unlock(ifq->netdev); 888 870 err: 889 871 scoped_guard(mutex, &ctx->mmap_lock) 890 872 xa_erase(&ctx->zcrx_ctxs, id);