@@ -2525,9 +2525,14 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
2525
2525
* find it from a io_do_iopoll() thread before the issuer is done
2526
2526
* accessing the kiocb cookie.
2527
2527
*/
2528
- static void io_iopoll_req_issued (struct io_kiocb * req , bool in_async )
2528
+ static void io_iopoll_req_issued (struct io_kiocb * req )
2529
2529
{
2530
2530
struct io_ring_ctx * ctx = req -> ctx ;
2531
+ const bool in_async = io_wq_current_is_worker ();
2532
+
2533
+ /* workqueue context doesn't hold uring_lock, grab it now */
2534
+ if (unlikely (in_async ))
2535
+ mutex_lock (& ctx -> uring_lock );
2531
2536
2532
2537
/*
2533
2538
* Track whether we have multiple files in our lists. This will impact
@@ -2554,14 +2559,19 @@ static void io_iopoll_req_issued(struct io_kiocb *req, bool in_async)
2554
2559
else
2555
2560
list_add_tail (& req -> inflight_entry , & ctx -> iopoll_list );
2556
2561
2557
- /*
2558
- * If IORING_SETUP_SQPOLL is enabled, sqes are either handled in sq thread
2559
- * task context or in io worker task context. If current task context is
2560
- * sq thread, we don't need to check whether should wake up sq thread.
2561
- */
2562
- if (in_async && (ctx -> flags & IORING_SETUP_SQPOLL ) &&
2563
- wq_has_sleeper (& ctx -> sq_data -> wait ))
2564
- wake_up (& ctx -> sq_data -> wait );
2562
+ if (unlikely (in_async )) {
2563
+ /*
2564
+ * If IORING_SETUP_SQPOLL is enabled, sqes are either handle
2565
+ * in sq thread task context or in io worker task context. If
2566
+ * current task context is sq thread, we don't need to check
2567
+ * whether should wake up sq thread.
2568
+ */
2569
+ if ((ctx -> flags & IORING_SETUP_SQPOLL ) &&
2570
+ wq_has_sleeper (& ctx -> sq_data -> wait ))
2571
+ wake_up (& ctx -> sq_data -> wait );
2572
+
2573
+ mutex_unlock (& ctx -> uring_lock );
2574
+ }
2565
2575
}
2566
2576
2567
2577
static inline void io_state_file_put (struct io_submit_state * state )
@@ -6215,23 +6225,11 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
6215
6225
6216
6226
if (creds )
6217
6227
revert_creds (creds );
6218
-
6219
6228
if (ret )
6220
6229
return ret ;
6221
-
6222
6230
/* If the op doesn't have a file, we're not polling for it */
6223
- if ((ctx -> flags & IORING_SETUP_IOPOLL ) && req -> file ) {
6224
- const bool in_async = io_wq_current_is_worker ();
6225
-
6226
- /* workqueue context doesn't hold uring_lock, grab it now */
6227
- if (in_async )
6228
- mutex_lock (& ctx -> uring_lock );
6229
-
6230
- io_iopoll_req_issued (req , in_async );
6231
-
6232
- if (in_async )
6233
- mutex_unlock (& ctx -> uring_lock );
6234
- }
6231
+ if ((ctx -> flags & IORING_SETUP_IOPOLL ) && req -> file )
6232
+ io_iopoll_req_issued (req );
6235
6233
6236
6234
return 0 ;
6237
6235
}
0 commit comments