io_uring/napi: clean up list traversal with list_for_each_entry_safe()
PATCH v2 1/1 io_uring/napi: clean up list traversal with list_for_each_entry_safe()
Switch both loops to the standard list_for_each_entry_safe() pattern and remove the explanatory comment.
---
v2:
- Resend as a cleanup rather than a PREEMPT_RT UAF fix.
io_uring/napi.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
io_uring/napi.c +4 -10
@@ -110,16 +110,10 @@ static int __io_napi_del_id(struct io_ring_ctx *ctx, unsigned int napi_id)static void __io_napi_remove_stale (struct io_ring_ctx *ctx) { -struct io_napi_entry *e; +struct io_napi_entry *e, *next;guard (spinlock)(&ctx->napi_lock); -/* -* list_for_each_entry_safe() is not required as long as: -* 1. list_del_rcu() does not reset the deleted node next pointer -* 2. kfree_rcu() delays the memory freeing until the next quiescent -* state -*/ -list_for_each_entry (e, &ctx->napi_list, list) { +list_for_each_entry_safe (e, next, &ctx->napi_list, list) {if (time_after (jiffies,READ_ONCE (e->timeout))) {list_del_rcu (&e->list);hash_del_rcu (&e->node);
@@ -264,10 +258,10 @@ void io_napi_init(struct io_ring_ctx *ctx)*/ void io_napi_free (struct io_ring_ctx *ctx) { -struct io_napi_entry *e; +struct io_napi_entry *e, *next;guard (spinlock)(&ctx->napi_lock); -list_for_each_entry (e, &ctx->napi_list, list) { +list_for_each_entry_safe (e, next, &ctx->napi_list, list) {hash_del_rcu (&e->node);kfree_rcu (e, rcu); }
Quoted 2 lines · Anvik Loitongbam
Switch both loops to the standard
list_for_each_entry_safe()pattern and remove the explanatory comment.
Applied, thanks!
[1/1] io_uring/napi: clean up list traversal with list_for_each_entry_safe()
commit: e18504a4d378b4c9e1ee522ae7fc18cac8b1fc82
Best regards,
Signature · 1 line
Jens Axboe
Quoted 2 lines · Anvik Loitongbam
Switch both loops to the standard
list_for_each_entry_safe()pattern and remove the explanatory comment.
I don't think this is useful as in clean-up or needed. The 'next' pointer is pre-loaded with the next element but list_del_rcu() does not destroy it (unlike list_del()). The spinlock_t holds off the grace period. The item's next pointer needs to remain valid for a RCU traversal that can happen.
The comment in __io_napi_remove_stale() explained the situation to non-RCU fluent person. The list is not touched in io_napi_free() at all.
But okay, it is not a hot path…
Quoted 1 line
Signed-off-by Anvik Loitongbam <[email protected]>
Sebastian