Skip to content

Commit e0793de

Browse files
spikehaxboe
authored andcommitted
io_uring/zcrx: set pp memory provider for an rx queue
Set the page pool memory provider for the rx queue configured for zero copy to io_uring. Then the rx queue is reset using netdev_rx_queue_restart() and netdev core + page pool will take care of filling the rx queue from the io_uring zero copy memory provider. For now, there is only one ifq so its destruction happens implicitly during io_uring cleanup. Reviewed-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: David Wei <dw@davidwei.uk> Acked-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/r/20250215000947.789731-8-dw@davidwei.uk Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 11ed914 commit e0793de

1 file changed

Lines changed: 41 additions & 8 deletions

File tree

io_uring/zcrx.c

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
#include <net/page_pool/helpers.h>
1212
#include <net/page_pool/memory_provider.h>
1313
#include <net/netlink.h>
14-
15-
#include <trace/events/page_pool.h>
14+
#include <net/netdev_rx_queue.h>
1615
#include <net/tcp.h>
1716
#include <net/rps.h>
1817

18+
#include <trace/events/page_pool.h>
19+
1920
#include <uapi/linux/io_uring.h>
2021

2122
#include "io_uring.h"
@@ -275,8 +276,34 @@ static void io_zcrx_drop_netdev(struct io_zcrx_ifq *ifq)
275276
spin_unlock(&ifq->lock);
276277
}
277278

279+
static void io_close_queue(struct io_zcrx_ifq *ifq)
280+
{
281+
struct net_device *netdev;
282+
netdevice_tracker netdev_tracker;
283+
struct pp_memory_provider_params p = {
284+
.mp_ops = &io_uring_pp_zc_ops,
285+
.mp_priv = ifq,
286+
};
287+
288+
if (ifq->if_rxq == -1)
289+
return;
290+
291+
spin_lock(&ifq->lock);
292+
netdev = ifq->netdev;
293+
netdev_tracker = ifq->netdev_tracker;
294+
ifq->netdev = NULL;
295+
spin_unlock(&ifq->lock);
296+
297+
if (netdev) {
298+
net_mp_close_rxq(netdev, ifq->if_rxq, &p);
299+
netdev_put(netdev, &netdev_tracker);
300+
}
301+
ifq->if_rxq = -1;
302+
}
303+
278304
static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq)
279305
{
306+
io_close_queue(ifq);
280307
io_zcrx_drop_netdev(ifq);
281308

282309
if (ifq->area)
@@ -291,6 +318,7 @@ static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq)
291318
int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
292319
struct io_uring_zcrx_ifq_reg __user *arg)
293320
{
321+
struct pp_memory_provider_params mp_param = {};
294322
struct io_uring_zcrx_area_reg area;
295323
struct io_uring_zcrx_ifq_reg reg;
296324
struct io_uring_region_desc rd;
@@ -341,7 +369,6 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
341369
goto err;
342370

343371
ifq->rq_entries = reg.rq_entries;
344-
ifq->if_rxq = reg.if_rxq;
345372

346373
ret = -ENODEV;
347374
ifq->netdev = netdev_get_by_index(current->nsproxy->net_ns, reg.if_idx,
@@ -358,16 +385,20 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
358385
if (ret)
359386
goto err;
360387

388+
mp_param.mp_ops = &io_uring_pp_zc_ops;
389+
mp_param.mp_priv = ifq;
390+
ret = net_mp_open_rxq(ifq->netdev, reg.if_rxq, &mp_param);
391+
if (ret)
392+
goto err;
393+
ifq->if_rxq = reg.if_rxq;
394+
361395
reg.offsets.rqes = sizeof(struct io_uring);
362396
reg.offsets.head = offsetof(struct io_uring, head);
363397
reg.offsets.tail = offsetof(struct io_uring, tail);
364398

365399
if (copy_to_user(arg, &reg, sizeof(reg)) ||
366-
copy_to_user(u64_to_user_ptr(reg.region_ptr), &rd, sizeof(rd))) {
367-
ret = -EFAULT;
368-
goto err;
369-
}
370-
if (copy_to_user(u64_to_user_ptr(reg.area_ptr), &area, sizeof(area))) {
400+
copy_to_user(u64_to_user_ptr(reg.region_ptr), &rd, sizeof(rd)) ||
401+
copy_to_user(u64_to_user_ptr(reg.area_ptr), &area, sizeof(area))) {
371402
ret = -EFAULT;
372403
goto err;
373404
}
@@ -444,6 +475,8 @@ void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx)
444475

445476
if (ctx->ifq)
446477
io_zcrx_scrub(ctx->ifq);
478+
479+
io_close_queue(ctx->ifq);
447480
}
448481

449482
static inline u32 io_zcrx_rqring_entries(struct io_zcrx_ifq *ifq)

0 commit comments

Comments
 (0)