All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] io_uring: fix refcounting with OOM
@ 2020-01-25  8:59 Pavel Begunkov
  2020-01-25 16:46 ` Jens Axboe
  2020-01-25 19:34 ` [PATCH v2] " Pavel Begunkov
  0 siblings, 2 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-01-25  8:59 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

In case of out of memory the second argument of percpu_ref_put_many() in
io_submit_sqes() may evaluate into "nr - (-EAGAIN)", that is clearly
wrong.

Fixes: 2b85edfc0c90 ("io_uring: batch getting pcpu references")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index a4b496815783..744e8a90b543 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4912,8 +4912,11 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
 			break;
 	}
 
-	if (submitted != nr)
-		percpu_ref_put_many(&ctx->refs, nr - submitted);
+	if (unlikely(submitted != nr)) {
+		int ref_used = (submitted == -EAGAIN) ? 0 : submitted;
+
+		percpu_ref_put_many(&ctx->refs, nr - ref_used);
+	}
 
 	io_submit_end(ctx);
 	if (nr > IO_PLUG_THRESHOLD)
-- 
2.24.0


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

* Re: [PATCH 1/1] io_uring: fix refcounting with OOM
  2020-01-25  8:59 [PATCH 1/1] io_uring: fix refcounting with OOM Pavel Begunkov
@ 2020-01-25 16:46 ` Jens Axboe
  2020-01-25 19:27   ` Pavel Begunkov
  2020-01-25 19:34 ` [PATCH v2] " Pavel Begunkov
  1 sibling, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2020-01-25 16:46 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring, linux-kernel

On 1/25/20 1:59 AM, Pavel Begunkov wrote:
> In case of out of memory the second argument of percpu_ref_put_many() in
> io_submit_sqes() may evaluate into "nr - (-EAGAIN)", that is clearly
> wrong.

Can you reorder this one before your series, I haven't had time
to take a look at that yet and I don't think this bug fix should
depend on it.

-- 
Jens Axboe


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

* Re: [PATCH 1/1] io_uring: fix refcounting with OOM
  2020-01-25 16:46 ` Jens Axboe
@ 2020-01-25 19:27   ` Pavel Begunkov
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-01-25 19:27 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel


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

On 25/01/2020 19:46, Jens Axboe wrote:
> On 1/25/20 1:59 AM, Pavel Begunkov wrote:
>> In case of out of memory the second argument of percpu_ref_put_many() in
>> io_submit_sqes() may evaluate into "nr - (-EAGAIN)", that is clearly
>> wrong.
> 
> Can you reorder this one before your series, I haven't had time
> to take a look at that yet and I don't think this bug fix should
> depend on it.
> 
Sure.

-- 
Pavel Begunkov


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

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

* [PATCH v2] io_uring: fix refcounting with OOM
  2020-01-25  8:59 [PATCH 1/1] io_uring: fix refcounting with OOM Pavel Begunkov
  2020-01-25 16:46 ` Jens Axboe
@ 2020-01-25 19:34 ` Pavel Begunkov
  1 sibling, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-01-25 19:34 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

In case of out of memory the second argument of percpu_ref_put_many() in
io_submit_sqes() may evaluate into "nr - (-EAGAIN)", that is clearly
wrong.

Fixes: 2b85edfc0c90 ("io_uring: batch getting pcpu references")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---

v2: rebase

 fs/io_uring.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 25f29ef81698..e79d6e47dc7b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4896,8 +4896,11 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
 			break;
 	}
 
-	if (submitted != nr)
-		percpu_ref_put_many(&ctx->refs, nr - submitted);
+	if (unlikely(submitted != nr)) {
+		int ref_used = (submitted == -EAGAIN) ? 0 : submitted;
+
+		percpu_ref_put_many(&ctx->refs, nr - ref_used);
+	}
 	if (link)
 		io_queue_link_head(link);
 	if (statep)
-- 
2.24.0


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

end of thread, other threads:[~2020-01-25 19:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-25  8:59 [PATCH 1/1] io_uring: fix refcounting with OOM Pavel Begunkov
2020-01-25 16:46 ` Jens Axboe
2020-01-25 19:27   ` Pavel Begunkov
2020-01-25 19:34 ` [PATCH v2] " Pavel Begunkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.