Skip to content

Commit 0e0bcf0

Browse files
committed
io_uring/eventfd: move refs to refcount_t
atomic_t for the struct io_ev_fd references and there are no issues with it. While the ref getting and putting for the eventfd code is somewhat performance critical for cases where eventfd signaling is used (news flash, you should not...), it probably doesn't warrant using an atomic_t for this. Let's just move to it to refcount_t to get the added protection of over/underflows. Link: https://lore.kernel.org/lkml/[email protected]/ Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Jens Axboe <[email protected]>
1 parent c9f9ce6 commit 0e0bcf0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

io_uring/eventfd.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct io_ev_fd {
1515
struct eventfd_ctx *cq_ev_fd;
1616
unsigned int eventfd_async: 1;
1717
struct rcu_head rcu;
18-
atomic_t refs;
18+
refcount_t refs;
1919
atomic_t ops;
2020
};
2121

@@ -37,7 +37,7 @@ static void io_eventfd_do_signal(struct rcu_head *rcu)
3737

3838
eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
3939

40-
if (atomic_dec_and_test(&ev_fd->refs))
40+
if (refcount_dec_and_test(&ev_fd->refs))
4141
io_eventfd_free(rcu);
4242
}
4343

@@ -63,7 +63,7 @@ void io_eventfd_signal(struct io_ring_ctx *ctx)
6363
*/
6464
if (unlikely(!ev_fd))
6565
return;
66-
if (!atomic_inc_not_zero(&ev_fd->refs))
66+
if (!refcount_inc_not_zero(&ev_fd->refs))
6767
return;
6868
if (ev_fd->eventfd_async && !io_wq_current_is_worker())
6969
goto out;
@@ -77,7 +77,7 @@ void io_eventfd_signal(struct io_ring_ctx *ctx)
7777
}
7878
}
7979
out:
80-
if (atomic_dec_and_test(&ev_fd->refs))
80+
if (refcount_dec_and_test(&ev_fd->refs))
8181
call_rcu(&ev_fd->rcu, io_eventfd_free);
8282
}
8383

@@ -137,7 +137,7 @@ int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg,
137137

138138
ev_fd->eventfd_async = eventfd_async;
139139
ctx->has_evfd = true;
140-
atomic_set(&ev_fd->refs, 1);
140+
refcount_set(&ev_fd->refs, 1);
141141
atomic_set(&ev_fd->ops, 0);
142142
rcu_assign_pointer(ctx->io_ev_fd, ev_fd);
143143
return 0;
@@ -152,7 +152,7 @@ int io_eventfd_unregister(struct io_ring_ctx *ctx)
152152
if (ev_fd) {
153153
ctx->has_evfd = false;
154154
rcu_assign_pointer(ctx->io_ev_fd, NULL);
155-
if (atomic_dec_and_test(&ev_fd->refs))
155+
if (refcount_dec_and_test(&ev_fd->refs))
156156
call_rcu(&ev_fd->rcu, io_eventfd_free);
157157
return 0;
158158
}

0 commit comments

Comments
 (0)