From: lizetao <lizetao1@huawei.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring <io-uring@vger.kernel.org>
Subject: RE: [PATCH] io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period
Date: Thu, 9 Jan 2025 03:40:35 +0000 [thread overview]
Message-ID: <1722809acef1438fb99fb8b4ab435039@huawei.com> (raw)
In-Reply-To: <7812ebd4-674f-4ad7-8c13-401684e8099b@kernel.dk>
Hi,
> -----Original Message-----
> From: Jens Axboe <axboe@kernel.dk>
> Sent: Thursday, January 9, 2025 7:42 AM
> To: io-uring <io-uring@vger.kernel.org>
> 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 <jannh@google.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>
> ---
>
> 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 <lizetao1@huawei.com>
Reviewed-by: Li Zetao<lizetao1@huawei.com>
---
Li Zetao
next prev parent reply other threads:[~2025-01-09 3:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-01-09 5:06 ` Prasanna Kumar T S M
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1722809acef1438fb99fb8b4ab435039@huawei.com \
--to=lizetao1@huawei.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox