Skip to content

Commit 2f3cc8e

Browse files
Olivier Langloisaxboe
authored andcommitted
io_uring/napi: protect concurrent io_napi_entry timeout accesses
io_napi_entry timeout value can be updated while accessed from the poll functions. Its concurrent accesses are wrapped with READ_ONCE()/WRITE_ONCE() macros to avoid incorrect compiler optimizations. Signed-off-by: Olivier Langlois <[email protected]> Link: https://lore.kernel.org/r/3de3087563cf98f75266fd9f85fdba063a8720db.1728828877.git.olivier@trillion01.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 4832427 commit 2f3cc8e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

io_uring/napi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock)
6060
rcu_read_lock();
6161
e = io_napi_hash_find(hash_list, napi_id);
6262
if (e) {
63-
e->timeout = jiffies + NAPI_TIMEOUT;
63+
WRITE_ONCE(e->timeout, jiffies + NAPI_TIMEOUT);
6464
rcu_read_unlock();
6565
return;
6666
}
@@ -92,7 +92,7 @@ static void __io_napi_remove_stale(struct io_ring_ctx *ctx)
9292

9393
spin_lock(&ctx->napi_lock);
9494
hash_for_each(ctx->napi_ht, i, e, node) {
95-
if (time_after(jiffies, e->timeout)) {
95+
if (time_after(jiffies, READ_ONCE(e->timeout))) {
9696
list_del(&e->list);
9797
hash_del_rcu(&e->node);
9898
kfree_rcu(e, rcu);
@@ -150,7 +150,7 @@ static bool __io_napi_do_busy_loop(struct io_ring_ctx *ctx,
150150
napi_busy_loop_rcu(e->napi_id, loop_end, loop_end_arg,
151151
ctx->napi_prefer_busy_poll, BUSY_POLL_BUDGET);
152152

153-
if (time_after(jiffies, e->timeout))
153+
if (time_after(jiffies, READ_ONCE(e->timeout)))
154154
is_stale = true;
155155
}
156156

0 commit comments

Comments
 (0)