This is a note to let you know that I've just added the patch titled block: don't allow multiple bios for IOCB_NOWAIT issue to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: block-don-t-allow-multiple-bios-for-iocb_nowait-issue.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 67d59247d4b52c917e373f05a807027756ab216f Mon Sep 17 00:00:00 2001 From: Jens Axboe <axboe@xxxxxxxxx> Date: Mon, 16 Jan 2023 08:55:53 -0700 Subject: block: don't allow multiple bios for IOCB_NOWAIT issue From: Jens Axboe <axboe@xxxxxxxxx> commit 67d59247d4b52c917e373f05a807027756ab216f upstream. 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") Cc: stable@xxxxxxxxxxxxxxx # 5.15+ Fixes: 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio") Link: https://github.com/axboe/liburing/issues/766 Reported-and-tested-by: Michael Kelley <mikelley@xxxxxxxxxxxxx> Signed-off-by: Jens Axboe <axboe@xxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- block/fops.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) --- a/block/fops.c +++ b/block/fops.c @@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct bio_endio(bio); break; } + if (iocb->ki_flags & IOCB_NOWAIT) { + /* + * This is nonblocking IO, and we need to allocate + * another bio if we have data left to map. As we + * cannot guarantee that one of the sub bios will not + * fail getting issued FOR NOWAIT and as error results + * are coalesced across all of them, be safe and ask for + * a retry of this from blocking context. + */ + 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) { if (dio->flags & DIO_SHOULD_DIRTY) @@ -228,9 +246,6 @@ static ssize_t __blkdev_direct_IO(struct } else { 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; Patches currently in stable-queue which might be from axboe@xxxxxxxxx are queue-6.1/sbitmap-use-single-per-bitmap-counting-to-wake-up-qu.patch queue-6.1/block-don-t-allow-multiple-bios-for-iocb_nowait-issue.patch queue-6.1/sbitmap-correct-wake_batch-recalculation-to-avoid-po.patch queue-6.1/blk-mq-avoid-sleep-in-blk_mq_alloc_request_hctx.patch queue-6.1/ublk_drv-remove-nr_aborted_queues-from-ublk_device.patch queue-6.1/blk-mq-fix-potential-io-hung-for-shared-sbitmap-per-.patch queue-6.1/blk-mq-wait-on-correct-sbitmap_queue-in-blk_mq_mark_.patch queue-6.1/block-clear-bio-bi_bdev-when-putting-a-bio-back-in-the-cache.patch queue-6.1/ublk_drv-don-t-probe-partitions-if-the-ubq-daemon-is.patch queue-6.1/trace-blktrace-fix-memory-leak-with-using-debugfs_lo.patch queue-6.1/x86-fpu-don-t-set-tif_need_fpu_load-for-pf_io_worker.patch queue-6.1/blk-cgroup-dropping-parent-refcount-after-pd_free_fn.patch queue-6.1/block-be-a-bit-more-careful-in-checking-for-null-bdev-while-polling.patch queue-6.1/block-use-proper-return-value-from-bio_failfast.patch queue-6.1/block-fix-io-statistics-for-cgroup-in-throttle-path.patch queue-6.1/block-ublk-check-io-buffer-based-on-flag-need_get_da.patch queue-6.1/blk-cgroup-synchronize-pd_free_fn-from-blkg_free_wor.patch queue-6.1/sbitmap-remove-redundant-check-in-__sbitmap_queue_ge.patch queue-6.1/block-sync-mixed-merged-request-s-failfast-with-1st-.patch queue-6.1/blk-mq-remove-stale-comment-for-blk_mq_sched_mark_re.patch queue-6.1/blk-iocost-fix-divide-by-0-error-in-calc_lcoefs.patch queue-6.1/s390-dasd-fix-potential-memleak-in-dasd_eckd_init.patch queue-6.1/blk-mq-correct-stale-comment-of-.get_budget.patch queue-6.1/block-bio-integrity-copy-flags-when-bio_integrity_pa.patch