@@ -1929,17 +1929,44 @@ static int io_req_task_work_add(struct io_kiocb *req)
1929
1929
return ret ;
1930
1930
}
1931
1931
1932
- static void io_req_task_work_add_fallback (struct io_kiocb * req ,
1933
- task_work_func_t cb )
1932
+ static bool io_run_task_work_head (struct callback_head * * work_head )
1933
+ {
1934
+ struct callback_head * work , * next ;
1935
+ bool executed = false;
1936
+
1937
+ do {
1938
+ work = xchg (work_head , NULL );
1939
+ if (!work )
1940
+ break ;
1941
+
1942
+ do {
1943
+ next = work -> next ;
1944
+ work -> func (work );
1945
+ work = next ;
1946
+ cond_resched ();
1947
+ } while (work );
1948
+ executed = true;
1949
+ } while (1 );
1950
+
1951
+ return executed ;
1952
+ }
1953
+
1954
+ static void io_task_work_add_head (struct callback_head * * work_head ,
1955
+ struct callback_head * task_work )
1934
1956
{
1935
- struct io_ring_ctx * ctx = req -> ctx ;
1936
1957
struct callback_head * head ;
1937
1958
1938
- init_task_work (& req -> task_work , cb );
1939
1959
do {
1940
- head = READ_ONCE (ctx -> exit_task_work );
1941
- req -> task_work .next = head ;
1942
- } while (cmpxchg (& ctx -> exit_task_work , head , & req -> task_work ) != head );
1960
+ head = READ_ONCE (* work_head );
1961
+ task_work -> next = head ;
1962
+ } while (cmpxchg (work_head , head , task_work ) != head );
1963
+ }
1964
+
1965
+ static void io_req_task_work_add_fallback (struct io_kiocb * req ,
1966
+ task_work_func_t cb )
1967
+ {
1968
+ init_task_work (& req -> task_work , cb );
1969
+ io_task_work_add_head (& req -> ctx -> exit_task_work , & req -> task_work );
1943
1970
}
1944
1971
1945
1972
static void __io_req_task_cancel (struct io_kiocb * req , int error )
@@ -8471,26 +8498,9 @@ static int io_unregister_personality(struct io_ring_ctx *ctx, unsigned id)
8471
8498
return - EINVAL ;
8472
8499
}
8473
8500
8474
- static bool io_run_ctx_fallback (struct io_ring_ctx * ctx )
8501
+ static inline bool io_run_ctx_fallback (struct io_ring_ctx * ctx )
8475
8502
{
8476
- struct callback_head * work , * next ;
8477
- bool executed = false;
8478
-
8479
- do {
8480
- work = xchg (& ctx -> exit_task_work , NULL );
8481
- if (!work )
8482
- break ;
8483
-
8484
- do {
8485
- next = work -> next ;
8486
- work -> func (work );
8487
- work = next ;
8488
- cond_resched ();
8489
- } while (work );
8490
- executed = true;
8491
- } while (1 );
8492
-
8493
- return executed ;
8503
+ return io_run_task_work_head (& ctx -> exit_task_work );
8494
8504
}
8495
8505
8496
8506
struct io_tctx_exit {
0 commit comments