Skip to content

Commit c9a4029

Browse files
committed
io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period
io_eventfd_do_signal() is invoked from an RCU callback, but when dropping the reference to the io_ev_fd, it calls io_eventfd_free() directly if the refcount drops to zero. This isn't correct, as any potential freeing of the io_ev_fd should be deferred another RCU grace period. Just call io_eventfd_put() rather than open-code the dec-and-test and free, which will correctly defer it another RCU grace period. Fixes: 21a091b ("io_uring: signal registered eventfd to process deferred task work") Reported-by: Jann Horn <[email protected]> Cc: [email protected] Tested-by: Li Zetao <[email protected]> Reviewed-by: Li Zetao<[email protected]> Reviewed-by: Prasanna Kumar T S M <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 60495b0 commit c9a4029

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

io_uring/eventfd.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,18 @@ static void io_eventfd_free(struct rcu_head *rcu)
3333
kfree(ev_fd);
3434
}
3535

36-
static void io_eventfd_do_signal(struct rcu_head *rcu)
36+
static void io_eventfd_put(struct io_ev_fd *ev_fd)
3737
{
38-
struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
39-
40-
eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
41-
4238
if (refcount_dec_and_test(&ev_fd->refs))
43-
io_eventfd_free(rcu);
39+
call_rcu(&ev_fd->rcu, io_eventfd_free);
4440
}
4541

46-
static void io_eventfd_put(struct io_ev_fd *ev_fd)
42+
static void io_eventfd_do_signal(struct rcu_head *rcu)
4743
{
48-
if (refcount_dec_and_test(&ev_fd->refs))
49-
call_rcu(&ev_fd->rcu, io_eventfd_free);
44+
struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
45+
46+
eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
47+
io_eventfd_put(ev_fd);
5048
}
5149

5250
static void io_eventfd_release(struct io_ev_fd *ev_fd, bool put_ref)

0 commit comments

Comments
 (0)