@@ -1075,8 +1075,11 @@ static bool io_match_task(struct io_kiocb *head,
10751075 return true;
10761076
10771077 io_for_each_link (req , head ) {
1078- if ((req -> flags & REQ_F_WORK_INITIALIZED ) &&
1079- (req -> work .flags & IO_WQ_WORK_FILES ) &&
1078+ if (!(req -> flags & REQ_F_WORK_INITIALIZED ))
1079+ continue ;
1080+ if (req -> file && req -> file -> f_op == & io_uring_fops )
1081+ return true;
1082+ if ((req -> work .flags & IO_WQ_WORK_FILES ) &&
10801083 req -> work .identity -> files == files )
10811084 return true;
10821085 }
@@ -1505,11 +1508,14 @@ static bool io_grab_identity(struct io_kiocb *req)
15051508 return false;
15061509 atomic_inc (& id -> files -> count );
15071510 get_nsproxy (id -> nsproxy );
1508- req -> flags |= REQ_F_INFLIGHT ;
15091511
1510- spin_lock_irq (& ctx -> inflight_lock );
1511- list_add (& req -> inflight_entry , & ctx -> inflight_list );
1512- spin_unlock_irq (& ctx -> inflight_lock );
1512+ if (!(req -> flags & REQ_F_INFLIGHT )) {
1513+ req -> flags |= REQ_F_INFLIGHT ;
1514+
1515+ spin_lock_irq (& ctx -> inflight_lock );
1516+ list_add (& req -> inflight_entry , & ctx -> inflight_list );
1517+ spin_unlock_irq (& ctx -> inflight_lock );
1518+ }
15131519 req -> work .flags |= IO_WQ_WORK_FILES ;
15141520 }
15151521 if (!(req -> work .flags & IO_WQ_WORK_MM ) &&
@@ -6164,8 +6170,10 @@ static void io_req_drop_files(struct io_kiocb *req)
61646170 struct io_uring_task * tctx = req -> task -> io_uring ;
61656171 unsigned long flags ;
61666172
6167- put_files_struct (req -> work .identity -> files );
6168- put_nsproxy (req -> work .identity -> nsproxy );
6173+ if (req -> work .flags & IO_WQ_WORK_FILES ) {
6174+ put_files_struct (req -> work .identity -> files );
6175+ put_nsproxy (req -> work .identity -> nsproxy );
6176+ }
61696177 spin_lock_irqsave (& ctx -> inflight_lock , flags );
61706178 list_del (& req -> inflight_entry );
61716179 spin_unlock_irqrestore (& ctx -> inflight_lock , flags );
@@ -6450,6 +6458,15 @@ static struct file *io_file_get(struct io_submit_state *state,
64506458 file = __io_file_get (state , fd );
64516459 }
64526460
6461+ if (file && file -> f_op == & io_uring_fops ) {
6462+ io_req_init_async (req );
6463+ req -> flags |= REQ_F_INFLIGHT ;
6464+
6465+ spin_lock_irq (& ctx -> inflight_lock );
6466+ list_add (& req -> inflight_entry , & ctx -> inflight_list );
6467+ spin_unlock_irq (& ctx -> inflight_lock );
6468+ }
6469+
64536470 return file ;
64546471}
64556472
@@ -8860,8 +8877,7 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
88608877
88618878 spin_lock_irq (& ctx -> inflight_lock );
88628879 list_for_each_entry (req , & ctx -> inflight_list , inflight_entry ) {
8863- if (req -> task != task ||
8864- req -> work .identity -> files != files )
8880+ if (!io_match_task (req , task , files ))
88658881 continue ;
88668882 found = true;
88678883 break ;
0 commit comments