@@ -5812,8 +5812,7 @@ static void io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
5812
5812
}
5813
5813
5814
5814
static int io_submit_sqes (struct io_ring_ctx * ctx , unsigned int nr ,
5815
- struct file * ring_file , int ring_fd ,
5816
- struct mm_struct * * mm , bool async )
5815
+ struct file * ring_file , int ring_fd , bool async )
5817
5816
{
5818
5817
struct io_submit_state state , * statep = NULL ;
5819
5818
struct io_kiocb * link = NULL ;
@@ -5870,13 +5869,12 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
5870
5869
break ;
5871
5870
}
5872
5871
5873
- if (io_op_defs [req -> opcode ].needs_mm && !* mm ) {
5872
+ if (io_op_defs [req -> opcode ].needs_mm && !current -> mm ) {
5874
5873
if (unlikely (!mmget_not_zero (ctx -> sqo_mm ))) {
5875
5874
err = - EFAULT ;
5876
5875
goto fail_req ;
5877
5876
}
5878
5877
use_mm (ctx -> sqo_mm );
5879
- * mm = ctx -> sqo_mm ;
5880
5878
}
5881
5879
5882
5880
req -> needs_fixed_file = async ;
@@ -5902,10 +5900,19 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
5902
5900
return submitted ;
5903
5901
}
5904
5902
5903
+ static inline void io_sq_thread_drop_mm (struct io_ring_ctx * ctx )
5904
+ {
5905
+ struct mm_struct * mm = current -> mm ;
5906
+
5907
+ if (mm ) {
5908
+ unuse_mm (mm );
5909
+ mmput (mm );
5910
+ }
5911
+ }
5912
+
5905
5913
static int io_sq_thread (void * data )
5906
5914
{
5907
5915
struct io_ring_ctx * ctx = data ;
5908
- struct mm_struct * cur_mm = NULL ;
5909
5916
const struct cred * old_cred ;
5910
5917
mm_segment_t old_fs ;
5911
5918
DEFINE_WAIT (wait );
@@ -5946,11 +5953,7 @@ static int io_sq_thread(void *data)
5946
5953
* adding ourselves to the waitqueue, as the unuse/drop
5947
5954
* may sleep.
5948
5955
*/
5949
- if (cur_mm ) {
5950
- unuse_mm (cur_mm );
5951
- mmput (cur_mm );
5952
- cur_mm = NULL ;
5953
- }
5956
+ io_sq_thread_drop_mm (ctx );
5954
5957
5955
5958
/*
5956
5959
* We're polling. If we're within the defined idle
@@ -6014,7 +6017,7 @@ static int io_sq_thread(void *data)
6014
6017
}
6015
6018
6016
6019
mutex_lock (& ctx -> uring_lock );
6017
- ret = io_submit_sqes (ctx , to_submit , NULL , -1 , & cur_mm , true);
6020
+ ret = io_submit_sqes (ctx , to_submit , NULL , -1 , true);
6018
6021
mutex_unlock (& ctx -> uring_lock );
6019
6022
timeout = jiffies + ctx -> sq_thread_idle ;
6020
6023
}
@@ -6023,10 +6026,7 @@ static int io_sq_thread(void *data)
6023
6026
task_work_run ();
6024
6027
6025
6028
set_fs (old_fs );
6026
- if (cur_mm ) {
6027
- unuse_mm (cur_mm );
6028
- mmput (cur_mm );
6029
- }
6029
+ io_sq_thread_drop_mm (ctx );
6030
6030
revert_creds (old_cred );
6031
6031
6032
6032
kthread_parkme ();
@@ -7507,13 +7507,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
7507
7507
wake_up (& ctx -> sqo_wait );
7508
7508
submitted = to_submit ;
7509
7509
} else if (to_submit ) {
7510
- struct mm_struct * cur_mm ;
7511
-
7512
7510
mutex_lock (& ctx -> uring_lock );
7513
- /* already have mm, so io_submit_sqes() won't try to grab it */
7514
- cur_mm = ctx -> sqo_mm ;
7515
- submitted = io_submit_sqes (ctx , to_submit , f .file , fd ,
7516
- & cur_mm , false);
7511
+ submitted = io_submit_sqes (ctx , to_submit , f .file , fd , false);
7517
7512
mutex_unlock (& ctx -> uring_lock );
7518
7513
7519
7514
if (submitted != to_submit )
0 commit comments