@@ -751,10 +751,50 @@ static int import_zcrx(struct io_ring_ctx *ctx,
751751 return ret ;
752752}
753753
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+
754795int io_register_zcrx_ifq (struct io_ring_ctx * ctx ,
755796 struct io_uring_zcrx_ifq_reg __user * arg )
756797{
757- struct pp_memory_provider_params mp_param = {};
758798 struct io_uring_zcrx_area_reg area ;
759799 struct io_uring_zcrx_ifq_reg reg ;
760800 struct io_uring_region_desc rd ;
@@ -821,33 +861,9 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
821861 if (ret )
822862 goto err ;
823863
824- ifq -> netdev = netdev_get_by_index_lock (current -> nsproxy -> net_ns , reg .if_idx );
825- if (!ifq -> netdev ) {
826- ret = - ENODEV ;
827- goto err ;
828- }
829- netdev_hold (ifq -> netdev , & ifq -> netdev_tracker , GFP_KERNEL );
830-
831- ifq -> dev = netdev_queue_get_dma_dev (ifq -> netdev , reg .if_rxq );
832- if (!ifq -> dev ) {
833- ret = - EOPNOTSUPP ;
834- goto netdev_put_unlock ;
835- }
836- get_device (ifq -> dev );
837-
838- ret = io_zcrx_create_area (ifq , & area , & reg );
839- if (ret )
840- goto netdev_put_unlock ;
841-
842- if (reg .rx_buf_len )
843- mp_param .rx_page_size = 1U << ifq -> niov_shift ;
844- mp_param .mp_ops = & io_uring_pp_zc_ops ;
845- mp_param .mp_priv = ifq ;
846- ret = __net_mp_open_rxq (ifq -> netdev , reg .if_rxq , & mp_param , NULL );
864+ ret = zcrx_register_netdev (ifq , & reg , & area );
847865 if (ret )
848- goto netdev_put_unlock ;
849- netdev_unlock (ifq -> netdev );
850- ifq -> if_rxq = reg .if_rxq ;
866+ goto err ;
851867
852868 reg .zcrx_id = id ;
853869
@@ -867,8 +883,6 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
867883 goto err ;
868884 }
869885 return 0 ;
870- netdev_put_unlock :
871- netdev_unlock (ifq -> netdev );
872886err :
873887 scoped_guard (mutex , & ctx -> mmap_lock )
874888 xa_erase (& ctx -> zcrx_ctxs , id );
0 commit comments