io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Two minor 5.11 io_uring fixes
@ 2020-12-17 15:21 Jens Axboe
  2020-12-17 15:21 ` [PATCH 1/2] io_uring: break links on shutdown failure Jens Axboe
  2020-12-17 15:21 ` [PATCH 2/2] io_uring: hold mmap_sem for mm->locked_vm manipulation Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Jens Axboe @ 2020-12-17 15:21 UTC (permalink / raw)
  To: io-uring

Hi,

1) Make sure we break links if a shutdown command fails
2) Play it safe and grab mmap_sem when modifying mm->locked_vm

-- 
Jens Axboe




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

* [PATCH 1/2] io_uring: break links on shutdown failure
  2020-12-17 15:21 [PATCH 0/2] Two minor 5.11 io_uring fixes Jens Axboe
@ 2020-12-17 15:21 ` Jens Axboe
  2020-12-17 15:21 ` [PATCH 2/2] io_uring: hold mmap_sem for mm->locked_vm manipulation Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-12-17 15:21 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

Ensure that the return value of __sys_shutdown_sock() is used to
potentially break links to the request, if we fail.

Fixes: 36f4fa6886a8 ("io_uring: add support for shutdown(2)")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 fs/io_uring.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6f9392c35eef..6a4560c9ed9a 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3784,6 +3784,8 @@ static int io_shutdown(struct io_kiocb *req, bool force_nonblock)
 		return -ENOTSOCK;
 
 	ret = __sys_shutdown_sock(sock, req->shutdown.how);
+	if (ret < 0)
+		req_set_fail_links(req);
 	io_req_complete(req, ret);
 	return 0;
 #else
-- 
2.29.2


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

* [PATCH 2/2] io_uring: hold mmap_sem for mm->locked_vm manipulation
  2020-12-17 15:21 [PATCH 0/2] Two minor 5.11 io_uring fixes Jens Axboe
  2020-12-17 15:21 ` [PATCH 1/2] io_uring: break links on shutdown failure Jens Axboe
@ 2020-12-17 15:21 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-12-17 15:21 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

The kernel doesn't seem to have clear rules around this, but various
spots are using the mmap_sem to serialize access to modifying the
locked_vm count. Play it safe and lock the mm for write when accounting
or unaccounting locked memory.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 fs/io_uring.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6a4560c9ed9a..2d07d35e7262 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8157,10 +8157,13 @@ static void io_unaccount_mem(struct io_ring_ctx *ctx, unsigned long nr_pages,
 		__io_unaccount_mem(ctx->user, nr_pages);
 
 	if (ctx->mm_account) {
-		if (acct == ACCT_LOCKED)
+		if (acct == ACCT_LOCKED) {
+			mmap_write_lock(ctx->mm_account);
 			ctx->mm_account->locked_vm -= nr_pages;
-		else if (acct == ACCT_PINNED)
+			mmap_write_unlock(ctx->mm_account);
+		}else if (acct == ACCT_PINNED) {
 			atomic64_sub(nr_pages, &ctx->mm_account->pinned_vm);
+		}
 	}
 }
 
@@ -8176,10 +8179,13 @@ static int io_account_mem(struct io_ring_ctx *ctx, unsigned long nr_pages,
 	}
 
 	if (ctx->mm_account) {
-		if (acct == ACCT_LOCKED)
+		if (acct == ACCT_LOCKED) {
+			mmap_write_lock(ctx->mm_account);
 			ctx->mm_account->locked_vm += nr_pages;
-		else if (acct == ACCT_PINNED)
+			mmap_write_unlock(ctx->mm_account);
+		} else if (acct == ACCT_PINNED) {
 			atomic64_add(nr_pages, &ctx->mm_account->pinned_vm);
+		}
 	}
 
 	return 0;
-- 
2.29.2


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

end of thread, other threads:[~2020-12-17 15:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 15:21 [PATCH 0/2] Two minor 5.11 io_uring fixes Jens Axboe
2020-12-17 15:21 ` [PATCH 1/2] io_uring: break links on shutdown failure Jens Axboe
2020-12-17 15:21 ` [PATCH 2/2] io_uring: hold mmap_sem for mm->locked_vm manipulation Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).