public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 1/1] io_uring: fix delayed mm check
@ 2020-02-06 18:16 Pavel Begunkov
  2020-02-06 19:52 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Begunkov @ 2020-02-06 18:16 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

Fail fast if can't grab mm, so past that requests always have an mm
when required. This fixes not checking mm fault for
IORING_OP_{READ,WRITE}, as well allows to remove req->has_user
altogether.

Signed-off-by: Pavel Begunkov <[email protected]>
---

v2: remove ->has_user (Jens)

 fs/io_uring.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index ce3dbd2b1b5c..1914351ebd5e 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -516,6 +516,7 @@ enum {
 	REQ_F_TIMEOUT_NOSEQ	= BIT(REQ_F_TIMEOUT_NOSEQ_BIT),
 	/* completion under lock */
 	REQ_F_COMP_LOCKED	= BIT(REQ_F_COMP_LOCKED_BIT),
+
 };
 
 /*
@@ -548,7 +549,6 @@ struct io_kiocb {
 	 * llist_node is only used for poll deferred completions
 	 */
 	struct llist_node		llist_node;
-	bool				has_user;
 	bool				in_async;
 	bool				needs_fixed_file;
 	u8				opcode;
@@ -2051,9 +2051,6 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
 		return iorw->size;
 	}
 
-	if (!req->has_user)
-		return -EFAULT;
-
 #ifdef CONFIG_COMPAT
 	if (req->ctx->compat)
 		return compat_import_iovec(rw, buf, sqe_len, UIO_FASTIOV,
@@ -4418,7 +4415,6 @@ static void io_wq_submit_work(struct io_wq_work **workptr)
 	}
 
 	if (!ret) {
-		req->has_user = (work->flags & IO_WQ_WORK_HAS_MM) != 0;
 		req->in_async = true;
 		do {
 			ret = io_issue_sqe(req, NULL, &nxt, false);
@@ -4922,6 +4918,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
 	for (i = 0; i < nr; i++) {
 		const struct io_uring_sqe *sqe;
 		struct io_kiocb *req;
+		int err;
 
 		req = io_get_req(ctx, statep);
 		if (unlikely(!req)) {
@@ -4938,20 +4935,23 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
 		submitted++;
 
 		if (unlikely(req->opcode >= IORING_OP_LAST)) {
-			io_cqring_add_event(req, -EINVAL);
+			err = -EINVAL;
+fail_req:
+			io_cqring_add_event(req, err);
 			io_double_put_req(req);
 			break;
 		}
 
 		if (io_op_defs[req->opcode].needs_mm && !*mm) {
 			mm_fault = mm_fault || !mmget_not_zero(ctx->sqo_mm);
-			if (!mm_fault) {
-				use_mm(ctx->sqo_mm);
-				*mm = ctx->sqo_mm;
+			if (unlikely(mm_fault)) {
+				err = -EFAULT;
+				goto fail_req;
 			}
+			use_mm(ctx->sqo_mm);
+			*mm = ctx->sqo_mm;
 		}
 
-		req->has_user = *mm != NULL;
 		req->in_async = async;
 		req->needs_fixed_file = async;
 		trace_io_uring_submit_sqe(ctx, req->opcode, req->user_data,
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] io_uring: fix delayed mm check
  2020-02-06 18:16 [PATCH 1/1] io_uring: fix delayed mm check Pavel Begunkov
@ 2020-02-06 19:52 ` Jens Axboe
  2020-02-06 19:59   ` Pavel Begunkov
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2020-02-06 19:52 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring, linux-kernel

On 2/6/20 11:16 AM, Pavel Begunkov wrote:
> Fail fast if can't grab mm, so past that requests always have an mm
> when required. This fixes not checking mm fault for
> IORING_OP_{READ,WRITE}, as well allows to remove req->has_user
> altogether.

Looks fine, except that first hunk that I can just delete.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] io_uring: fix delayed mm check
  2020-02-06 19:52 ` Jens Axboe
@ 2020-02-06 19:59   ` Pavel Begunkov
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2020-02-06 19:59 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 416 bytes --]

On 06/02/2020 22:52, Jens Axboe wrote:
> On 2/6/20 11:16 AM, Pavel Begunkov wrote:
>> Fail fast if can't grab mm, so past that requests always have an mm
>> when required. This fixes not checking mm fault for
>> IORING_OP_{READ,WRITE}, as well allows to remove req->has_user
>> altogether.
> 
> Looks fine, except that first hunk that I can just delete.
> 
Oops, missed it. Thanks

-- 
Pavel Begunkov


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-06 19:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-06 18:16 [PATCH 1/1] io_uring: fix delayed mm check Pavel Begunkov
2020-02-06 19:52 ` Jens Axboe
2020-02-06 19:59   ` Pavel Begunkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox