Skip to contentSkip to conversation

block: add a helper to cancel atomic queue limit updates

PATCH In review Christoph Hellwig 3 participants 4 messages Mar 27, 2024 – Mar 28, 2024

Subsystems (2)
lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/2 block: add a helper to cancel atomic queue limit updates

Drivers might have to perform complex actions to determine queue limits, and those might fail. Add a helper to cancel a queue limit update that can be called in those cases.

---
 include/linux/blkdev.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
include/linux/blkdev.h +13 -0
index f9b87c39cab047..39fedc8ef9c41f 100644
@@ -892,6 +892,19 @@ int queue_limits_commit_update(struct request_queue *q,
 		struct queue_limits *lim);
 int queue_limits_set(struct request_queue *q, struct queue_limits *lim);
 
+/**
+ * queue_limits_cancel_update - cancel an atomic update of queue limits
+ * @q:		queue to update
+ *
+ * This functions cancels an atomic update of the queue limits started by
+ * queue_limits_start_update() and should be used when an error occurs after
+ * starting update.
+ */
+static inline void queue_limits_cancel_update(struct request_queue *q)
+{
+	mutex_lock(&q->limits_lock);
+}
+
 /*
  * Access functions for manipulating queue properties
  */
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 2/2 nvme: cancel the queue limit update when nvme_update_zone_info fails

Starting an atomic queue limits update takes a mutex and thus needs to be finished, or with the newly added helper, canceled to not leak the lock critical section.

Fixes 9b130d681443 ("nvme: use the atomic queue limits update API")
---
 drivers/nvme/host/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvme/host/core.c +1 -0
index 943d72bdd794ca..f8a9565bee41d2 100644
@@ -2115,6 +2115,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	    ns->head->ids.csi == NVME_CSI_ZNS) {
 		ret = nvme_update_zone_info(ns, lbaf, &lim);
 		if (ret) {
+			queue_limits_cancel_update(ns->disk->queue);
 			blk_mq_unfreeze_queue(ns->disk->queue);
 			goto out;
 		}
Signature · 1 line
2.39.2
maintainer
#2 lore raw

Re: [PATCH 2/2] nvme: cancel the queue limit update when nvme_update_zone_info fails

drivers/nvme/host/core.c static int nvme_update_ns_info_block(struct nvme_ns *ns, · line 2118

Quoted 5 lines · Christoph Hellwig
drivers/nvme/host/core.c +1 -0
@@ -2115,6 +2115,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	    ns->head->ids.csi == NVME_CSI_ZNS) {
 		ret = nvme_update_zone_info(ns, lbaf, &lim);
 		if (ret) {
+			queue_limits_cancel_update(ns->disk->queue);

Could you instead move nvme_update_zone_info() outside the queue_limits_start_update()? That way we wouldn't need to "cancel" the update. You'd just need to save a copy of "mor" and "mar" in the ns instead of writing these directly to the queue_limits.

#3 lore raw
In reply to Christoph Hellwig
Quoted 18 lines · Christoph Hellwig

Drivers might have to perform complex actions to determine queue limits, and those might fail. Add a helper to cancel a queue limit update that can be called in those cases.

---
  include/linux/blkdev.h | 13 +++++++++++++
  1 file changed, 13 insertions(+)
include/linux/blkdev.h +1 -0
index f9b87c39cab047..39fedc8ef9c41f 100644
@@ -892,6 +892,19 @@ int queue_limits_commit_update(struct request_queue *q,
  		struct queue_limits *lim);
  int queue_limits_set(struct request_queue *q, struct queue_limits *lim);
 
+/**

include/linux/blkdev.h int queue_limits_commit_update(struct request_queue *q, · line 905

Quoted 10 lines
include/linux/blkdev.h +10 -0
+ * queue_limits_cancel_update - cancel an atomic update of queue limits
+ * @q:		queue to update
+ *
+ * This functions cancels an atomic update of the queue limits started by
+ * queue_limits_start_update() and should be used when an error occurs after
+ * starting update.
+ */
+static inline void queue_limits_cancel_update(struct request_queue *q)
+{
+	mutex_lock(&q->limits_lock);

mutex_unlock is needed here.