]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0018-block-don-t-allow-multiple-bios-for-IOCB_NOWAIT-issu.patch
prepare for 6.2 release
[pve-kernel.git] / patches / kernel / 0018-block-don-t-allow-multiple-bios-for-IOCB_NOWAIT-issu.patch
CommitLineData
3d016e11
FE
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Jens Axboe <axboe@kernel.dk>
3Date: Mon, 16 Jan 2023 08:55:53 -0700
4Subject: [PATCH] block: don't allow multiple bios for IOCB_NOWAIT issue
5
6If we're doing a large IO request which needs to be split into multiple
7bios for issue, then we can run into the same situation as the below
8marked commit fixes - parts will complete just fine, one or more parts
9will fail to allocate a request. This will result in a partially
10completed read or write request, where the caller gets EAGAIN even though
11parts of the IO completed just fine.
12
13Do the same for large bios as we do for splits - fail a NOWAIT request
14with EAGAIN. This isn't technically fixing an issue in the below marked
15patch, but for stable purposes, we should have either none of them or
16both.
17
18This depends on: 613b14884b85 ("block: handle bio_split_to_limits() NULL return")
19
20Cc: stable@vger.kernel.org # 5.15+
21Fixes: 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")
22Link: https://github.com/axboe/liburing/issues/766
23Reported-and-tested-by: Michael Kelley <mikelley@microsoft.com>
24Signed-off-by: Jens Axboe <axboe@kernel.dk>
25(commit 67d59247d4b52c917e373f05a807027756ab216f upstream)
26Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
27---
28 block/fops.c | 21 ++++++++++++++++++---
29 1 file changed, 18 insertions(+), 3 deletions(-)
30
31diff --git a/block/fops.c b/block/fops.c
32index b90742595317..e406aa605327 100644
33--- a/block/fops.c
34+++ b/block/fops.c
35@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
36 bio_endio(bio);
37 break;
38 }
39+ if (iocb->ki_flags & IOCB_NOWAIT) {
40+ /*
41+ * This is nonblocking IO, and we need to allocate
42+ * another bio if we have data left to map. As we
43+ * cannot guarantee that one of the sub bios will not
44+ * fail getting issued FOR NOWAIT and as error results
45+ * are coalesced across all of them, be safe and ask for
46+ * a retry of this from blocking context.
47+ */
48+ if (unlikely(iov_iter_count(iter))) {
49+ bio_release_pages(bio, false);
50+ bio_clear_flag(bio, BIO_REFFED);
51+ bio_put(bio);
52+ blk_finish_plug(&plug);
53+ return -EAGAIN;
54+ }
55+ bio->bi_opf |= REQ_NOWAIT;
56+ }
57
58 if (is_read) {
59 if (dio->flags & DIO_SHOULD_DIRTY)
60@@ -228,9 +246,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
61 } else {
62 task_io_account_write(bio->bi_iter.bi_size);
63 }
64- if (iocb->ki_flags & IOCB_NOWAIT)
65- bio->bi_opf |= REQ_NOWAIT;
66-
67 dio->size += bio->bi_iter.bi_size;
68 pos += bio->bi_iter.bi_size;
69