Skip to content

Commit 39c9676

Browse files
isilenceaxboe
authored andcommitted
io_uring/zcrx: count zcrx users
zcrx tries to detach ifq / terminate page pools when the io_uring ctx owning it is being destroyed. There will be multiple io_uring instances attached to it in the future, so add a separate counter to track the users. Note, refs can't be reused for this purpose as it only used to prevent zcrx and rings destruction, and also used by page pools to keep it alive. Signed-off-by: David Wei <dw@davidwei.uk> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 475eb39 commit 39c9676

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

io_uring/zcrx.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx)
482482
spin_lock_init(&ifq->rq_lock);
483483
mutex_init(&ifq->pp_lock);
484484
refcount_set(&ifq->refs, 1);
485+
refcount_set(&ifq->user_refs, 1);
485486
return ifq;
486487
}
487488

@@ -742,8 +743,10 @@ void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx)
742743
if (!ifq)
743744
break;
744745

745-
io_close_queue(ifq);
746-
io_zcrx_scrub(ifq);
746+
if (refcount_dec_and_test(&ifq->user_refs)) {
747+
io_close_queue(ifq);
748+
io_zcrx_scrub(ifq);
749+
}
747750
io_put_zcrx_ifq(ifq);
748751
}
749752

io_uring/zcrx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ struct io_zcrx_ifq {
5555
struct net_device *netdev;
5656
netdevice_tracker netdev_tracker;
5757
refcount_t refs;
58+
/* counts userspace facing users like io_uring */
59+
refcount_t user_refs;
5860

5961
/*
6062
* Page pool and net configuration lock, can be taken deeper in the

0 commit comments

Comments
 (0)