@@ -31,11 +31,6 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
3131#define IORING_MAX_FIXED_FILES (1U << 20)
3232#define IORING_MAX_REG_BUFFERS (1U << 14)
3333
34- static inline bool io_put_rsrc_data_ref (struct io_rsrc_data * rsrc_data )
35- {
36- return !-- rsrc_data -> refs ;
37- }
38-
3934int __io_account_mem (struct user_struct * user , unsigned long nr_pages )
4035{
4136 unsigned long page_limit , cur_pages , new_pages ;
@@ -158,7 +153,6 @@ static void io_rsrc_put_work_one(struct io_rsrc_data *rsrc_data,
158153static void __io_rsrc_put_work (struct io_rsrc_node * ref_node )
159154{
160155 struct io_rsrc_data * rsrc_data = ref_node -> rsrc_data ;
161- struct io_ring_ctx * ctx = rsrc_data -> ctx ;
162156 struct io_rsrc_put * prsrc , * tmp ;
163157
164158 if (ref_node -> inline_items )
@@ -171,14 +165,6 @@ static void __io_rsrc_put_work(struct io_rsrc_node *ref_node)
171165 }
172166
173167 io_rsrc_node_destroy (rsrc_data -> ctx , ref_node );
174- if (io_put_rsrc_data_ref (rsrc_data ))
175- wake_up_all (& ctx -> rsrc_quiesce_wq );
176- }
177-
178- void io_wait_rsrc_data (struct io_rsrc_data * data )
179- {
180- if (data )
181- WARN_ON_ONCE (!io_put_rsrc_data_ref (data ));
182168}
183169
184170void io_rsrc_node_destroy (struct io_ring_ctx * ctx , struct io_rsrc_node * node )
@@ -201,6 +187,8 @@ void io_rsrc_node_ref_zero(struct io_rsrc_node *node)
201187 list_del (& node -> node );
202188 __io_rsrc_put_work (node );
203189 }
190+ if (list_empty (& ctx -> rsrc_ref_list ) && unlikely (ctx -> rsrc_quiesce ))
191+ wake_up_all (& ctx -> rsrc_quiesce_wq );
204192}
205193
206194struct io_rsrc_node * io_rsrc_node_alloc (struct io_ring_ctx * ctx )
@@ -235,7 +223,6 @@ void io_rsrc_node_switch(struct io_ring_ctx *ctx,
235223 if (WARN_ON_ONCE (!backup ))
236224 return ;
237225
238- data_to_kill -> refs ++ ;
239226 node -> rsrc_data = data_to_kill ;
240227 list_add_tail (& node -> node , & ctx -> rsrc_ref_list );
241228 /* put master ref */
@@ -269,15 +256,15 @@ __cold static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
269256 return ret ;
270257 io_rsrc_node_switch (ctx , data );
271258
272- /* kill initial ref */
273- if (io_put_rsrc_data_ref (data ))
259+ if (list_empty (& ctx -> rsrc_ref_list ))
274260 return 0 ;
275261
276262 if (ctx -> flags & IORING_SETUP_DEFER_TASKRUN ) {
277263 atomic_set (& ctx -> cq_wait_nr , 1 );
278264 smp_mb ();
279265 }
280266
267+ ctx -> rsrc_quiesce ++ ;
281268 data -> quiesce = true;
282269 do {
283270 prepare_to_wait (& ctx -> rsrc_quiesce_wq , & we , TASK_INTERRUPTIBLE );
@@ -286,23 +273,21 @@ __cold static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
286273 ret = io_run_task_work_sig (ctx );
287274 if (ret < 0 ) {
288275 mutex_lock (& ctx -> uring_lock );
289- if (! data -> refs ) {
276+ if (list_empty ( & ctx -> rsrc_ref_list ))
290277 ret = 0 ;
291- } else {
292- /* restore the master reference */
293- data -> refs ++ ;
294- }
295278 break ;
296279 }
297280
298281 schedule ();
299282 __set_current_state (TASK_RUNNING );
300283 mutex_lock (& ctx -> uring_lock );
301284 ret = 0 ;
302- } while (data -> refs );
285+ } while (! list_empty ( & ctx -> rsrc_ref_list ) );
303286
304287 finish_wait (& ctx -> rsrc_quiesce_wq , & we );
305288 data -> quiesce = false;
289+ ctx -> rsrc_quiesce -- ;
290+
306291 if (ctx -> flags & IORING_SETUP_DEFER_TASKRUN ) {
307292 atomic_set (& ctx -> cq_wait_nr , 0 );
308293 smp_mb ();
@@ -371,7 +356,6 @@ __cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx,
371356 data -> nr = nr ;
372357 data -> ctx = ctx ;
373358 data -> do_put = do_put ;
374- data -> refs = 1 ;
375359 if (utags ) {
376360 ret = - EFAULT ;
377361 for (i = 0 ; i < nr ; i ++ ) {
0 commit comments