Skip to content

Commit bf9c2f1

Browse files
isilenceaxboe
authored andcommitted
io_uring: track mm through current->mm
As a preparation for extracting request init bits, remove self-coded mm tracking from io_submit_sqes(), but rely on current->mm. It's more convenient, than passing this piece of state in other functions. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent dccc587 commit bf9c2f1

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

fs/io_uring.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5812,8 +5812,7 @@ static void io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
58125812
}
58135813

58145814
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)
58175816
{
58185817
struct io_submit_state state, *statep = NULL;
58195818
struct io_kiocb *link = NULL;
@@ -5870,13 +5869,12 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
58705869
break;
58715870
}
58725871

5873-
if (io_op_defs[req->opcode].needs_mm && !*mm) {
5872+
if (io_op_defs[req->opcode].needs_mm && !current->mm) {
58745873
if (unlikely(!mmget_not_zero(ctx->sqo_mm))) {
58755874
err = -EFAULT;
58765875
goto fail_req;
58775876
}
58785877
use_mm(ctx->sqo_mm);
5879-
*mm = ctx->sqo_mm;
58805878
}
58815879

58825880
req->needs_fixed_file = async;
@@ -5902,10 +5900,19 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
59025900
return submitted;
59035901
}
59045902

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+
59055913
static int io_sq_thread(void *data)
59065914
{
59075915
struct io_ring_ctx *ctx = data;
5908-
struct mm_struct *cur_mm = NULL;
59095916
const struct cred *old_cred;
59105917
mm_segment_t old_fs;
59115918
DEFINE_WAIT(wait);
@@ -5946,11 +5953,7 @@ static int io_sq_thread(void *data)
59465953
* adding ourselves to the waitqueue, as the unuse/drop
59475954
* may sleep.
59485955
*/
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);
59545957

59555958
/*
59565959
* We're polling. If we're within the defined idle
@@ -6014,7 +6017,7 @@ static int io_sq_thread(void *data)
60146017
}
60156018

60166019
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);
60186021
mutex_unlock(&ctx->uring_lock);
60196022
timeout = jiffies + ctx->sq_thread_idle;
60206023
}
@@ -6023,10 +6026,7 @@ static int io_sq_thread(void *data)
60236026
task_work_run();
60246027

60256028
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);
60306030
revert_creds(old_cred);
60316031

60326032
kthread_parkme();
@@ -7507,13 +7507,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
75077507
wake_up(&ctx->sqo_wait);
75087508
submitted = to_submit;
75097509
} else if (to_submit) {
7510-
struct mm_struct *cur_mm;
7511-
75127510
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);
75177512
mutex_unlock(&ctx->uring_lock);
75187513

75197514
if (submitted != to_submit)

0 commit comments

Comments
 (0)