Skip to contentSkip to conversation

block: don't allow multiple bios for IOCB_NOWAIT issue

PATCH New Michael Kelley 1 participant 1 message Jan 28, 2023 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: don't allow multiple bios for IOCB_NOWAIT issue

If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.

Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.

This depends on: 613b14884b85 ("block: handle bio_split_to_limits() NULL return")

Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")

---

This is a backport to v5.15.90 of a patch[1] from Jens Axboe. I've tested the backport with my basic io_uring tests, but the code should be reviewed in the context of 5.15.90. Commit 613b14884b85 mentioned above has already been backported and included in v5.15.90.

[1] https://lore.kernel.org/linux-block/[email protected]/

 block/fops.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
block/fops.c +13 -5
index 1e970c2..42dafe7 100644
@@ -244,17 +244,25 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
 			break;
 		}
 
+		if (iocb->ki_flags & IOCB_NOWAIT) {
+			if (unlikely(iov_iter_count(iter))) {
+				bio_release_pages(bio, false);
+				bio_clear_flag(bio, BIO_REFFED);
+				bio_put(bio);
+				blk_finish_plug(&plug);
+				return -EAGAIN;
+			}
+			bio->bi_opf |= REQ_NOWAIT;
+		}
+
 		if (is_read) {
-			bio->bi_opf = REQ_OP_READ;
+			bio->bi_opf |= REQ_OP_READ;
 			if (dio->should_dirty)
 				bio_set_pages_dirty(bio);
 		} else {
-			bio->bi_opf = dio_bio_write_op(iocb);
+			bio->bi_opf |= dio_bio_write_op(iocb);
 			task_io_account_write(bio->bi_iter.bi_size);
 		}
-		if (iocb->ki_flags & IOCB_NOWAIT)
-			bio->bi_opf |= REQ_NOWAIT;
-
 		dio->size += bio->bi_iter.bi_size;
 		pos += bio->bi_iter.bi_size;
 
Signature · 1 line
1.8.3.1