Skip to content

Commit 45b3941

Browse files
Olivier Langloisaxboe
authored andcommitted
io_uring/napi: fix io_napi_entry RCU accesses
correct 3 RCU structures modifications that were not using the RCU functions to make their update. Signed-off-by: Olivier Langlois <[email protected]> Link: https://lore.kernel.org/r/9f53b5169afa8c7bf3665a0b19dc2f7061173530.1728828877.git.olivier@trillion01.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 2f3cc8e commit 45b3941

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

io_uring/napi.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,24 @@ void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock)
8181
}
8282

8383
hlist_add_tail_rcu(&e->node, hash_list);
84-
list_add_tail(&e->list, &ctx->napi_list);
84+
list_add_tail_rcu(&e->list, &ctx->napi_list);
8585
spin_unlock(&ctx->napi_lock);
8686
}
8787

8888
static void __io_napi_remove_stale(struct io_ring_ctx *ctx)
8989
{
9090
struct io_napi_entry *e;
91-
unsigned int i;
9291

9392
spin_lock(&ctx->napi_lock);
94-
hash_for_each(ctx->napi_ht, i, e, node) {
93+
/*
94+
* list_for_each_entry_safe() is not required as long as:
95+
* 1. list_del_rcu() does not reset the deleted node next pointer
96+
* 2. kfree_rcu() delays the memory freeing until the next quiescent
97+
* state
98+
*/
99+
list_for_each_entry(e, &ctx->napi_list, list) {
95100
if (time_after(jiffies, READ_ONCE(e->timeout))) {
96-
list_del(&e->list);
101+
list_del_rcu(&e->list);
97102
hash_del_rcu(&e->node);
98103
kfree_rcu(e, rcu);
99104
}
@@ -204,13 +209,13 @@ void io_napi_init(struct io_ring_ctx *ctx)
204209
void io_napi_free(struct io_ring_ctx *ctx)
205210
{
206211
struct io_napi_entry *e;
207-
unsigned int i;
208212

209213
spin_lock(&ctx->napi_lock);
210-
hash_for_each(ctx->napi_ht, i, e, node) {
214+
list_for_each_entry(e, &ctx->napi_list, list) {
211215
hash_del_rcu(&e->node);
212216
kfree_rcu(e, rcu);
213217
}
218+
INIT_LIST_HEAD_RCU(&ctx->napi_list);
214219
spin_unlock(&ctx->napi_lock);
215220
}
216221

0 commit comments

Comments
 (0)