* [PATCH] io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period
@ 2025-01-08 23:42 Jens Axboe
2025-01-09 3:40 ` lizetao
2025-01-09 5:06 ` Prasanna Kumar T S M
0 siblings, 2 replies; 3+ messages in thread
From: Jens Axboe @ 2025-01-08 23:42 UTC (permalink / raw)
To: io-uring
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: 21a091b970cd ("io_uring: signal registered eventfd to process deferred task work")
Reported-by: Jann Horn <[email protected]>
Cc: [email protected]
Signed-off-by: Jens Axboe <[email protected]>
---
diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c
index fab936d31ba8..100d5da94cb9 100644
--- a/io_uring/eventfd.c
+++ b/io_uring/eventfd.c
@@ -33,20 +33,18 @@ static void io_eventfd_free(struct rcu_head *rcu)
kfree(ev_fd);
}
-static void io_eventfd_do_signal(struct rcu_head *rcu)
+static void io_eventfd_put(struct io_ev_fd *ev_fd)
{
- struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
-
- eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
-
if (refcount_dec_and_test(&ev_fd->refs))
- io_eventfd_free(rcu);
+ call_rcu(&ev_fd->rcu, io_eventfd_free);
}
-static void io_eventfd_put(struct io_ev_fd *ev_fd)
+static void io_eventfd_do_signal(struct rcu_head *rcu)
{
- if (refcount_dec_and_test(&ev_fd->refs))
- call_rcu(&ev_fd->rcu, io_eventfd_free);
+ struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
+
+ eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
+ io_eventfd_put(ev_fd);
}
static void io_eventfd_release(struct io_ev_fd *ev_fd, bool put_ref)
--
Jens Axboe
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH] io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period
2025-01-08 23:42 [PATCH] io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period Jens Axboe
@ 2025-01-09 3:40 ` lizetao
2025-01-09 5:06 ` Prasanna Kumar T S M
1 sibling, 0 replies; 3+ messages in thread
From: lizetao @ 2025-01-09 3:40 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring
Hi,
> -----Original Message-----
> From: Jens Axboe <[email protected]>
> Sent: Thursday, January 9, 2025 7:42 AM
> To: io-uring <[email protected]>
> Subject: [PATCH] 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: 21a091b970cd ("io_uring: signal registered eventfd to process deferred
> task work")
> Reported-by: Jann Horn <[email protected]>
> Cc: [email protected]
> Signed-off-by: Jens Axboe <[email protected]>
>
> ---
>
> diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c index
> fab936d31ba8..100d5da94cb9 100644
> --- a/io_uring/eventfd.c
> +++ b/io_uring/eventfd.c
> @@ -33,20 +33,18 @@ static void io_eventfd_free(struct rcu_head *rcu)
> kfree(ev_fd);
> }
>
> -static void io_eventfd_do_signal(struct rcu_head *rcu)
> +static void io_eventfd_put(struct io_ev_fd *ev_fd)
> {
> - struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
> -
> - eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
> -
> if (refcount_dec_and_test(&ev_fd->refs))
> - io_eventfd_free(rcu);
> + call_rcu(&ev_fd->rcu, io_eventfd_free);
> }
>
> -static void io_eventfd_put(struct io_ev_fd *ev_fd)
> +static void io_eventfd_do_signal(struct rcu_head *rcu)
> {
> - if (refcount_dec_and_test(&ev_fd->refs))
> - call_rcu(&ev_fd->rcu, io_eventfd_free);
> + struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
> +
> + eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
> + io_eventfd_put(ev_fd);
> }
>
> static void io_eventfd_release(struct io_ev_fd *ev_fd, bool put_ref)
>
> --
> Jens Axboe
>
>
Tested-by: Li Zetao <[email protected]>
Reviewed-by: Li Zetao<[email protected]>
---
Li Zetao
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period
2025-01-08 23:42 [PATCH] io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period Jens Axboe
2025-01-09 3:40 ` lizetao
@ 2025-01-09 5:06 ` Prasanna Kumar T S M
1 sibling, 0 replies; 3+ messages in thread
From: Prasanna Kumar T S M @ 2025-01-09 5:06 UTC (permalink / raw)
To: Jens Axboe, io-uring
On 09-01-2025 05:12, Jens Axboe wrote:
> 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: 21a091b970cd ("io_uring: signal registered eventfd to process deferred task work")
> Reported-by: Jann Horn <[email protected]>
> Cc: [email protected]
> Signed-off-by: Jens Axboe <[email protected]>
>
> ---
>
> diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c
> index fab936d31ba8..100d5da94cb9 100644
> --- a/io_uring/eventfd.c
> +++ b/io_uring/eventfd.c
> @@ -33,20 +33,18 @@ static void io_eventfd_free(struct rcu_head *rcu)
> kfree(ev_fd);
> }
>
> -static void io_eventfd_do_signal(struct rcu_head *rcu)
> +static void io_eventfd_put(struct io_ev_fd *ev_fd)
> {
> - struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
> -
> - eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
> -
> if (refcount_dec_and_test(&ev_fd->refs))
> - io_eventfd_free(rcu);
> + call_rcu(&ev_fd->rcu, io_eventfd_free);
> }
>
> -static void io_eventfd_put(struct io_ev_fd *ev_fd)
> +static void io_eventfd_do_signal(struct rcu_head *rcu)
> {
> - if (refcount_dec_and_test(&ev_fd->refs))
> - call_rcu(&ev_fd->rcu, io_eventfd_free);
> + struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
> +
> + eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
> + io_eventfd_put(ev_fd);
> }
>
> static void io_eventfd_release(struct io_ev_fd *ev_fd, bool put_ref)
>
Looks good to me.
Reviewed-by: Prasanna Kumar T S M <[email protected]>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-09 5:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08 23:42 [PATCH] io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period Jens Axboe
2025-01-09 3:40 ` lizetao
2025-01-09 5:06 ` Prasanna Kumar T S M
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox