]> git.proxmox.com Git - pve-kernel.git/blob - patches/kernel/0018-block-don-t-allow-multiple-bios-for-IOCB_NOWAIT-issu.patch
add patch to fix issue with large IO requests
[pve-kernel.git] / patches / kernel / 0018-block-don-t-allow-multiple-bios-for-IOCB_NOWAIT-issu.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Jens Axboe <axboe@kernel.dk>
3 Date: Mon, 16 Jan 2023 08:55:53 -0700
4 Subject: [PATCH] block: don't allow multiple bios for IOCB_NOWAIT issue
5
6 If we're doing a large IO request which needs to be split into multiple
7 bios for issue, then we can run into the same situation as the below
8 marked commit fixes - parts will complete just fine, one or more parts
9 will fail to allocate a request. This will result in a partially
10 completed read or write request, where the caller gets EAGAIN even though
11 parts of the IO completed just fine.
12
13 Do the same for large bios as we do for splits - fail a NOWAIT request
14 with EAGAIN. This isn't technically fixing an issue in the below marked
15 patch, but for stable purposes, we should have either none of them or
16 both.
17
18 This depends on: 613b14884b85 ("block: handle bio_split_to_limits() NULL return")
19
20 Cc: stable@vger.kernel.org # 5.15+
21 Fixes: 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")
22 Link: https://github.com/axboe/liburing/issues/766
23 Reported-and-tested-by: Michael Kelley <mikelley@microsoft.com>
24 Signed-off-by: Jens Axboe <axboe@kernel.dk>
25 (commit 67d59247d4b52c917e373f05a807027756ab216f upstream)
26 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
27 ---
28 block/fops.c | 21 ++++++++++++++++++---
29 1 file changed, 18 insertions(+), 3 deletions(-)
30
31 diff --git a/block/fops.c b/block/fops.c
32 index 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