From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: hare@suse.de, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me,
dwagner@suse.de, kanie@linux.alibaba.com, jmeneghi@redhat.com,
randyj@purestorage.com, martin.petersen@oracle.com,
john.g.garry@oracle.com, gjoyce@linux.ibm.com
Subject: [PATCH v8 03/10] block: support nesting for blk-mq flag QUEUE_FLAG_SAME_FORCE
Date: Sat, 15 Aug 2026 23:04:25 +0530 [thread overview]
Message-ID: <20260815173502.1185929-4-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260815173502.1185929-1-nilay@linux.ibm.com>
QUEUE_FLAG_SAME_FORCE is currently used when setting rq_affinity
through sysfs as well as by UFS mediatek driver while configuring scsi
parameters. A subsequent patch adding a latency-based I/O policy
for NVMe multipath will also use this flag.
With multiple users able to set and clear QUEUE_FLAG_SAME_FORCE, the
flag needs to support nesting so that one user clearing the flag does
not inadvertently disable it for another user.
Add a nesting counter, q->same_force_depth, for QUEUE_FLAG_SAME_FORCE.
The flag is set when the first user acquires it and the nesting counter
is incremented for each subsequent user. Similarly, each user releases
its reference by decrementing the counter. The flag is cleared only
when the last user releases it and the counter reaches zero.
Preserve the existing sysfs rq_affinity semantics with a new
q->same_force_sysfs flag. When userspace enables QUEUE_FLAG_SAME_FORCE
by writing 2 to rq_affinity, mark q->same_force_sysfs as set and
increment q->same_force_depth by one. Subsequent writes of 2 to
rq_affinity while q->same_force_sysfs is already set are ignored, so
repeated writes of 2 from userspace do not increase q->same_force_depth.
Similarly, writing 0 or 1 decrements the q->same_force_depth and if
nesting counter reached to 0 then clears the QUEUE_FLAG_SAME_FORCE.
This ensures that multiple writes of 2 to rq_affinity do not require
multiple writes of 0 or 1.
This change ensures that sysfs interface retains its existing set/clear
semantics while also allowing other kernel users to hold or release
QUEUE_FLAG_SAME_FORCE.
Added two new APIs blk_mq_same_force_set() and blk_mq_same_force_clear()
to set and clear QUEUE_FLAG_SAME_FORCE respectively. Also, updated
existing call paths using these new APIs which toggles
QUEUE_FLAG_SAME_FORCE.
Cc: Peter Wang <peter.wang@mediatek.com>
Cc: Chaotian Jing <chaotian.jing@mediatek.com>
Cc: Stanley Jhu <chu.stanley@gmail.com>
Cc: linux-mediatek@lists.infradead.org
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
block/blk-mq.c | 41 +++++++++++++++++++++++++++++++++
block/blk-sysfs.c | 6 ++---
drivers/ufs/host/ufs-mediatek.c | 2 +-
include/linux/blk-mq.h | 2 ++
include/linux/blkdev.h | 3 +++
5 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 38922209a24f..17e8befb02bc 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -360,6 +360,47 @@ void blk_mq_unquiesce_tagset(struct blk_mq_tag_set *set)
}
EXPORT_SYMBOL_GPL(blk_mq_unquiesce_tagset);
+void blk_mq_same_force_set(struct request_queue *q, bool from_sysfs)
+{
+ unsigned long flags = 0;
+
+ spin_lock_irqsave(&q->queue_lock, flags);
+
+ if (from_sysfs) {
+ if (q->same_force_sysfs)
+ goto unlock;
+ q->same_force_sysfs = true;
+ }
+
+ if (!q->same_force_depth++)
+ blk_queue_flag_set(QUEUE_FLAG_SAME_FORCE, q);
+unlock:
+ spin_unlock_irqrestore(&q->queue_lock, flags);
+}
+EXPORT_SYMBOL_GPL(blk_mq_same_force_set);
+
+void blk_mq_same_force_clear(struct request_queue *q, bool from_sysfs)
+{
+ unsigned long flags = 0;
+
+ spin_lock_irqsave(&q->queue_lock, flags);
+
+ if (from_sysfs) {
+ if (!q->same_force_sysfs)
+ goto unlock;
+ q->same_force_sysfs = false;
+ }
+
+ if (WARN_ON_ONCE(q->same_force_depth <= 0))
+ goto unlock;
+
+ if (!--q->same_force_depth)
+ blk_queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q);
+unlock:
+ spin_unlock_irqrestore(&q->queue_lock, flags);
+}
+EXPORT_SYMBOL_GPL(blk_mq_same_force_clear);
+
void blk_mq_wake_waiters(struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 520972676ab4..a3ec8ffab1ee 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -497,13 +497,13 @@ queue_rq_affinity_store(struct gendisk *disk, const char *page, size_t count)
*/
if (val == 2) {
blk_queue_flag_set(QUEUE_FLAG_SAME_COMP, q);
- blk_queue_flag_set(QUEUE_FLAG_SAME_FORCE, q);
+ blk_mq_same_force_set(q, true);
} else if (val == 1) {
blk_queue_flag_set(QUEUE_FLAG_SAME_COMP, q);
- blk_queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q);
+ blk_mq_same_force_clear(q, true);
} else if (val == 0) {
blk_queue_flag_clear(QUEUE_FLAG_SAME_COMP, q);
- blk_queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q);
+ blk_mq_same_force_clear(q, true);
}
#endif
return ret;
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 3991a51263a6..8d80ac6fb5d2 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -2311,7 +2311,7 @@ static void ufs_mtk_config_scsi_dev(struct scsi_device *sdev)
dev_dbg(hba->dev, "lu %llu scsi device configured", sdev->lun);
if (sdev->lun == 2)
- blk_queue_flag_set(QUEUE_FLAG_SAME_FORCE, sdev->request_queue);
+ blk_mq_same_force_set(sdev->request_queue, false);
}
/*
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 3956909764bf..30be3eb5a37b 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -943,6 +943,8 @@ void blk_mq_wait_quiesce_done(struct blk_mq_tag_set *set);
void blk_mq_quiesce_tagset(struct blk_mq_tag_set *set);
void blk_mq_unquiesce_tagset(struct blk_mq_tag_set *set);
void blk_mq_unquiesce_queue(struct request_queue *q);
+void blk_mq_same_force_set(struct request_queue *q, bool from_sysfs);
+void blk_mq_same_force_clear(struct request_queue *q, bool from_sysfs);
void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs);
void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
void blk_mq_run_hw_queues(struct request_queue *q, bool async);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9213a5716f95..32d0fb47d73c 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -529,6 +529,9 @@ struct request_queue {
int quiesce_depth;
+ int same_force_depth;
+ bool same_force_sysfs;
+
struct gendisk *disk;
/*
--
2.53.0
next prev parent reply other threads:[~2026-08-15 17:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 17:34 [PATCH v8 00/10] nvme-multipath: introduce latency I/O policy Nilay Shroff
2026-08-15 17:34 ` [PATCH v8 01/10] block: expose blk_stat_{enable,disable}_accounting() to drivers Nilay Shroff
2026-08-15 17:34 ` [PATCH v8 02/10] block: record I/O request start time for passthru request Nilay Shroff
2026-08-15 17:34 ` Nilay Shroff [this message]
2026-08-15 17:34 ` [PATCH v8 04/10] nvme-multipath: pass I/O type to nvme_find_path() Nilay Shroff
2026-08-15 17:34 ` [PATCH v8 05/10] nvme-multipath: add support for latency I/O policy Nilay Shroff
2026-08-15 17:34 ` [PATCH v8 06/10] nvme: add generic debugfs support Nilay Shroff
2026-08-15 17:34 ` [PATCH v8 07/10] nvme-multipath: add debugfs attribute latency_ewma_shift Nilay Shroff
2026-08-15 17:34 ` [PATCH v8 08/10] nvme-multipath: add debugfs attribute latency_batch_timeout Nilay Shroff
2026-08-15 17:34 ` [PATCH v8 09/10] nvme-multipath: add debugfs attribute latency_stat Nilay Shroff
2026-08-15 17:34 ` [PATCH v8 10/10] nvme-multipath: add documentation for latency I/O policy Nilay Shroff
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=20260815173502.1185929-4-nilay@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=dwagner@suse.de \
--cc=gjoyce@linux.ibm.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jmeneghi@redhat.com \
--cc=john.g.garry@oracle.com \
--cc=kanie@linux.alibaba.com \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=martin.petersen@oracle.com \
--cc=randyj@purestorage.com \
--cc=sagi@grimberg.me \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.