From: Jens Axboe <[email protected]>
To: io-uring <[email protected]>
Subject: [PATCH for-next] io_uring/eventfd: replace out-of-line signaling with a workqueue
Date: Thu, 9 Jan 2025 07:50:22 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
Rather than (ab)use RCU for this kind of thing, add a work queue item
and use that for the unlikely case of a notification being done inside
another notification. This cleans up the code and better adheres to
expected usage of RCU, and it means that the odd ->ops serializing
can be removed as queue_work() will handle that for us.
Signed-off-by: Jens Axboe <[email protected]>
---
diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c
index 100d5da94cb9..8ecf3c106f89 100644
--- a/io_uring/eventfd.c
+++ b/io_uring/eventfd.c
@@ -17,12 +17,8 @@ struct io_ev_fd {
/* protected by ->completion_lock */
unsigned last_cq_tail;
refcount_t refs;
- atomic_t ops;
struct rcu_head rcu;
-};
-
-enum {
- IO_EVENTFD_OP_SIGNAL_BIT,
+ struct work_struct work;
};
static void io_eventfd_free(struct rcu_head *rcu)
@@ -39,9 +35,9 @@ static void io_eventfd_put(struct io_ev_fd *ev_fd)
call_rcu(&ev_fd->rcu, io_eventfd_free);
}
-static void io_eventfd_do_signal(struct rcu_head *rcu)
+static void io_eventfd_do_signal(struct work_struct *work)
{
- struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
+ struct io_ev_fd *ev_fd = container_of(work, struct io_ev_fd, work);
eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
io_eventfd_put(ev_fd);
@@ -63,11 +59,7 @@ static bool __io_eventfd_signal(struct io_ev_fd *ev_fd)
eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
return true;
}
- if (!atomic_fetch_or(BIT(IO_EVENTFD_OP_SIGNAL_BIT), &ev_fd->ops)) {
- call_rcu_hurry(&ev_fd->rcu, io_eventfd_do_signal);
- return false;
- }
- return true;
+ return !queue_work(system_unbound_wq, &ev_fd->work);
}
/*
@@ -184,7 +176,7 @@ int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg,
ev_fd->eventfd_async = eventfd_async;
ctx->has_evfd = true;
refcount_set(&ev_fd->refs, 1);
- atomic_set(&ev_fd->ops, 0);
+ INIT_WORK(&ev_fd->work, io_eventfd_do_signal);
rcu_assign_pointer(ctx->io_ev_fd, ev_fd);
return 0;
}
--
Jens Axboe
reply other threads:[~2025-01-09 14:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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 \
[email protected] \
[email protected] \
[email protected] \
/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