From: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
To: linux-block@vger.kernel.org
Cc: axboe@kernel.dk, hch@lst.de, kch@nvidia.com, dlemoal@kernel.org,
Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
Subject: [PATCH 2/2] zloop: respect REQ_NOWAIT for memory allocation
Date: Sat, 15 Nov 2025 18:52:29 -0800 [thread overview]
Message-ID: <20251116025229.29136-2-ckulkarnilinux@gmail.com> (raw)
In-Reply-To: <20251116025229.29136-1-ckulkarnilinux@gmail.com>
zloop advertises REQ_NOWAIT support via BLK_FEAT_NOWAIT (set by
default for all blk-mq devices), but violates REQ_NOWAIT semantics
by using GFP_NOIO allocations which can block.
BLK_FEAT_NOWAIT is advertised through this call chain:
zloop_add()
blk_mq_alloc_disk(&lim, ...)
__blk_mq_alloc_disk()
blk_mq_alloc_queue()
lim->features |= BLK_FEAT_NOWAIT <-- Set by default for blk-mq
However, the REQ_NOWAIT I/O path violates this contract. For io_uring
inline submissions, the call chain is:
1. Userspace (io_uring setup):
io_uring_setup(entries, ¶ms)
fd = io_uring_register(IORING_REGISTER_FILES, &zloop_fd, 1)
2. Userspace (submit I/O with NOWAIT):
sqe = io_uring_get_sqe(ring)
io_uring_prep_write(sqe, zloop_fd, buf, len, offset)
io_uring_submit(ring) <-- inline submission
3. io_uring core (inline path):
io_submit_sqes()
io_submit_sqe()
io_queue_sqe()
issue_flags = IO_URING_F_NONBLOCK <-- Sets inline/nowait mode
io_issue_sqe()
io_write()
if (force_nonblock) <-- true for inline submission
kiocb->ki_flags |= IOCB_NOWAIT
4. VFS layer:
call_write_iter()
blkdev_write_iter()
-> propagates IOCB_NOWAIT to REQ_NOWAIT on bio
__blkdev_direct_IO_simple() OR
__blkdev_direct_IO() OR
__blkdev_direct_IO_async()
5. Block layer:
blk_mq_submit_bio()
blk_mq_get_new_requests()
__blk_mq_alloc_requests()
blk_mq_rq_ctx_init()
-> propagates REQ_NOWAIT to request->cmd_flags
__blk_mq_try_issue_directly() OR blk_mq_sched_insert_request()
blk_mq_run_hw_queue()
__blk_mq_delay_run_hw_queue()
__blk_mq_run_hw_queue()
blk_mq_sched_dispatch_requests()
6. Zloop driver:
zloop_queue_rq()
zloop_rw()
kmalloc_array(..., GFP_NOIO) <-- BLOCKS (REQ_NOWAIT violation)
-> Should use GFP_NOWAIT when rq->cmd_flags & REQ_NOWAIT
Fix by using GFP_NOWAIT when REQ_NOWAIT is set, and return -EAGAIN
instead of -ENOMEM when NOWAIT allocation fails, allowing io_uring
to retry the operation with blocking allowed.
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
drivers/block/zloop.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 92be9f0af00a..9295c4817bd4 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -372,6 +372,8 @@ static void zloop_rw(struct zloop_cmd *cmd)
sector_t zone_end;
int nr_bvec = 0;
int ret;
+ bool nowait = rq->cmd_flags & REQ_NOWAIT;
+ gfp_t alloc_flags = nowait ? GFP_NOWAIT : GFP_NOIO;
atomic_set(&cmd->ref, 2);
cmd->sector = sector;
@@ -443,9 +445,9 @@ static void zloop_rw(struct zloop_cmd *cmd)
if (rq->bio != rq->biotail) {
struct bio_vec *bvec;
- cmd->bvec = kmalloc_array(nr_bvec, sizeof(*cmd->bvec), GFP_NOIO);
+ cmd->bvec = kmalloc_array(nr_bvec, sizeof(*cmd->bvec), alloc_flags);
if (!cmd->bvec) {
- ret = -EIO;
+ ret = nowait ? -EAGAIN : -ENOMEM;
goto unlock;
}
--
2.40.0
next prev parent reply other threads:[~2025-11-16 2:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-16 2:52 [PATCH 1/2] loop: respect REQ_NOWAIT for memory allocation Chaitanya Kulkarni
2025-11-16 2:52 ` Chaitanya Kulkarni [this message]
2025-11-16 3:44 ` [PATCH 2/2] zloop: " Damien Le Moal
2025-11-16 3:50 ` [PATCH 1/2] loop: " Damien Le Moal
2025-11-16 5:43 ` Chaitanya Kulkarni
2025-11-16 6:26 ` Damien Le Moal
2025-11-18 1:52 ` Chaitanya Kulkarni
2025-11-18 5:21 ` hch
2025-11-18 13:57 ` Jens Axboe
2025-11-19 0:39 ` Chaitanya Kulkarni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251116025229.29136-2-ckulkarnilinux@gmail.com \
--to=ckulkarnilinux@gmail.com \
--cc=axboe@kernel.dk \
--cc=dlemoal@kernel.org \
--cc=hch@lst.de \
--cc=kch@nvidia.com \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox