Skip to contentSkip to conversation

loop: clear REQ_NOWAIT before workqueue submission

PATCH In review Chaitanya Kulkarni 3 participants 4 messages Nov 19, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 loop: clear REQ_NOWAIT before workqueue submission

loop advertises REQ_NOWAIT support via BLK_FEAT_NOWAIT (set by default for all blk-mq devices), but delegates I/O processing to workqueues where blocking operations are allowed.

Since REQ_NOWAIT is not valid in the workqueue context, clear the REQ_NOWAIT flag before handing the request over to the workqueue. This avoids unnecessary non-blocking constraints in a context where blocking is acceptable.

---

Hi,

Patches are generated on base commit in linux-block/for-next :-

commit 6dbcc40ec7aa17ed3dd1f798e4201e75ab7d7447 (origin/for-next)
Merge: 58625d626327 ba13710ddd1f
Author: Jens Axboe <[email protected]>
Date: Wed Nov 5 18:24:17 2025 -0700

Merge branch 'for-6.19/block' into for-next

* for-6.19/block:
rust: block: update ARef and AlwaysRefCounted imports from sync::aref

-ck

---
 drivers/block/loop.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/loop.c +4 -0
index 13ce229d450c..9d931ff456e7 100644
@@ -797,6 +797,7 @@ static inline int queue_on_root_worker(struct cgroup_subsys_state *css)
 
 static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd)
 {
+	struct request *rq = blk_mq_rq_from_pdu(cmd);
 	struct rb_node **node, *parent = NULL;
 	struct loop_worker *cur_worker, *worker = NULL;
 	struct work_struct *work;
@@ -860,6 +861,9 @@ static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd)
 		work = &lo->rootcg_work;
 		cmd_list = &lo->rootcg_cmd_list;
 	}
+
+	rq->cmd_flags &= ~REQ_NOWAIT;
+
 	list_add_tail(&cmd->list_entry, cmd_list);
 	queue_work(lo->workqueue, work);
 	spin_unlock_irq(&lo->lo_work_lock);
Signature · 1 line
2.40.0
#1 lore raw

PATCH 2/2 zloop: clear REQ_NOWAIT before workqueue submission

zloop advertises REQ_NOWAIT support via BLK_FEAT_NOWAIT (set by default for all blk-mq devices), but delegates I/O processing to workqueues where blocking operations are allowed.

Since REQ_NOWAIT is not valid in the workqueue context, clear the REQ_NOWAIT flag before handing the request over to the workqueue. This avoids unnecessary non-blocking constraints in a context where blocking is acceptable.

---
 drivers/block/zloop.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/block/zloop.c +2 -0
index 92be9f0af00a..22a245259622 100644
@@ -620,6 +620,8 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,
 
 	blk_mq_start_request(rq);
 
+	rq->cmd_flags &= ~REQ_NOWAIT;
+
 	INIT_WORK(&cmd->work, zloop_cmd_workfn);
 	queue_work(zlo->workqueue, &cmd->work);
 
Signature · 1 line
2.40.0
maintainer
#2 lore raw

Re: [PATCH 2/2] zloop: clear REQ_NOWAIT before workqueue submission

Quoted 19 lines · Chaitanya Kulkarni

zloop advertises REQ_NOWAIT support via BLK_FEAT_NOWAIT (set by default for all blk-mq devices), but delegates I/O processing to workqueues where blocking operations are allowed.

Since REQ_NOWAIT is not valid in the workqueue context, clear the REQ_NOWAIT flag before handing the request over to the workqueue. This avoids unnecessary non-blocking constraints in a context where blocking is acceptable.

---
 drivers/block/zloop.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/block/zloop.c +0 -0
index 92be9f0af00a..22a245259622 100644

drivers/block/zloop.c static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx, · line 624

Quoted 5 lines
drivers/block/zloop.c +2 -0
@@ -620,6 +620,8 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,
 
 	blk_mq_start_request(rq);
 
+	rq->cmd_flags &= ~REQ_NOWAIT;
+

To be able to catch any potential issue with this function blocking, I think it is preferable to unset REQ_NOWAIT only once we are in the context of the worker thread.

So something like this:

drivers/block/zloop.c +4 -0
index d6dc672bda5f..9e4256824336 100644
@@ -547,6 +547,10 @@ static void zloop_handle_cmd(struct zloop_cmd *cmd)
        struct request *rq = blk_mq_rq_from_pdu(cmd);
        struct zloop_device *zlo = rq->q->queuedata;
 
+       /* We can block in this context, so ignore REQ_NOWAIT. */
+        if (rq->cmd_flags & REQ_NOWAIT)
+               rq->cmd_flags &= ~REQ_NOWAIT
+
        switch (req_op(rq)) {
        case REQ_OP_READ:
        case REQ_OP_WRITE:

The same comment applies to loop as well. I think it is better to clear REQ_NOWAIT only once the request is owned by the worker thread context.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#3 lore raw

Re: [PATCH 2/2] zloop: clear REQ_NOWAIT before workqueue submission

Quoted 3 lines · Damien Le Moal

To be able to catch any potential issue with this function blocking, I think it is preferable to unset REQ_NOWAIT only once we are in the context of the worker thread.

...

Quoted 2 lines

The same comment applies to loop as well. I think it is better to clear REQ_NOWAIT only once the request is owned by the worker thread context.

Agreed.