@@ -183,17 +183,12 @@ struct fixed_file_table {
183
183
struct file * * files ;
184
184
};
185
185
186
- enum {
187
- FFD_F_ATOMIC ,
188
- };
189
-
190
186
struct fixed_file_data {
191
187
struct fixed_file_table * table ;
192
188
struct io_ring_ctx * ctx ;
193
189
194
190
struct percpu_ref refs ;
195
191
struct llist_head put_llist ;
196
- unsigned long state ;
197
192
struct work_struct ref_work ;
198
193
struct completion done ;
199
194
};
@@ -5595,7 +5590,6 @@ static void io_ring_file_ref_switch(struct work_struct *work)
5595
5590
5596
5591
data = container_of (work , struct fixed_file_data , ref_work );
5597
5592
io_ring_file_ref_flush (data );
5598
- percpu_ref_get (& data -> refs );
5599
5593
percpu_ref_switch_to_percpu (& data -> refs );
5600
5594
}
5601
5595
@@ -5771,8 +5765,13 @@ static void io_atomic_switch(struct percpu_ref *ref)
5771
5765
{
5772
5766
struct fixed_file_data * data ;
5773
5767
5768
+ /*
5769
+ * Juggle reference to ensure we hit zero, if needed, so we can
5770
+ * switch back to percpu mode
5771
+ */
5774
5772
data = container_of (ref , struct fixed_file_data , refs );
5775
- clear_bit (FFD_F_ATOMIC , & data -> state );
5773
+ percpu_ref_put (& data -> refs );
5774
+ percpu_ref_get (& data -> refs );
5776
5775
}
5777
5776
5778
5777
static bool io_queue_file_removal (struct fixed_file_data * data ,
@@ -5795,11 +5794,7 @@ static bool io_queue_file_removal(struct fixed_file_data *data,
5795
5794
llist_add (& pfile -> llist , & data -> put_llist );
5796
5795
5797
5796
if (pfile == & pfile_stack ) {
5798
- if (!test_and_set_bit (FFD_F_ATOMIC , & data -> state )) {
5799
- percpu_ref_put (& data -> refs );
5800
- percpu_ref_switch_to_atomic (& data -> refs ,
5801
- io_atomic_switch );
5802
- }
5797
+ percpu_ref_switch_to_atomic (& data -> refs , io_atomic_switch );
5803
5798
wait_for_completion (& done );
5804
5799
flush_work (& data -> ref_work );
5805
5800
return false;
@@ -5873,10 +5868,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
5873
5868
up -> offset ++ ;
5874
5869
}
5875
5870
5876
- if (ref_switch && !test_and_set_bit (FFD_F_ATOMIC , & data -> state )) {
5877
- percpu_ref_put (& data -> refs );
5871
+ if (ref_switch )
5878
5872
percpu_ref_switch_to_atomic (& data -> refs , io_atomic_switch );
5879
- }
5880
5873
5881
5874
return done ? done : err ;
5882
5875
}
0 commit comments