Skip to contentSkip to conversation

nvme: fixup zns namespace initialisation

PATCH Superseded Hannes Reinecke 2 participants 2 messages May 23, 2024 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: fixup zns namespace initialisation

nvme_set_chunk_sectors() needs to know whether it's a zoned namespace or not, but the information is only set in a later call. So move the calls around and ensure that the namespace is marked as non-zoned initially to avoid calculation errors when trying to derive a non-existing zone geometry.

Fixes c85c9ab926a5 ("nvme: split nvme_update_zone_info")
---
 drivers/nvme/host/core.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +9 -3
index 8324f231b79c..bcb4a1a37d68 100644
@@ -1952,6 +1952,12 @@ static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl,
 	lim->virt_boundary_mask = NVME_CTRL_PAGE_SIZE - 1;
 	lim->max_segment_size = UINT_MAX;
 	lim->dma_alignment = 3;
+	lim->chunk_sectors = 0;
+	lim->zoned = false;
+	lim->max_open_zones = 0;
+	lim->max_active_zones = 0;
+	lim->zone_write_granularity = 0;
+	lim->max_zone_append_sectors = 0;
 }
 
 static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id,
@@ -2115,13 +2121,13 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	lim = queue_limits_start_update(ns->disk->queue);
 	nvme_set_ctrl_limits(ns->ctrl, &lim);
 	nvme_configure_metadata(ns->ctrl, ns->head, id, nvm);
+	if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
+	    ns->head->ids.csi == NVME_CSI_ZNS)
+		nvme_update_zone_info(ns, &lim, &zi);
 	nvme_set_chunk_sectors(ns, id, &lim);
 	if (!nvme_update_disk_info(ns, id, &lim))
 		capacity = 0;
 	nvme_config_discard(ns, &lim);
-	if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
-	    ns->head->ids.csi == NVME_CSI_ZNS)
-		nvme_update_zone_info(ns, &lim, &zi);
 	ret = queue_limits_commit_update(ns->disk->queue, &lim);
 	if (ret) {
 		blk_mq_unfreeze_queue(ns->disk->queue);
Signature · 1 line
2.35.3
#1 lore raw
Quoted 2 lines · Hannes Reinecke

nvme_set_chunk_sectors() needs to know whether it's a zoned namespace or not, but the information is only set in a later call.

Where "needs to know" means the blk_queue_is_zoned check to warn if an I/O boundary is set for a zoned namespaces?

drivers/nvme/host/core.c static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl, · line 1960

Quoted 12 lines
drivers/nvme/host/core.c +6 -0
@@ -1952,6 +1952,12 @@ static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl,
 	lim->virt_boundary_mask = NVME_CTRL_PAGE_SIZE - 1;
 	lim->max_segment_size = UINT_MAX;
 	lim->dma_alignment = 3;
+	lim->chunk_sectors = 0;
+	lim->zoned = false;
+	lim->max_open_zones = 0;
+	lim->max_active_zones = 0;
+	lim->zone_write_granularity = 0;
+	lim->max_zone_append_sectors = 0;

I can't see why we'd need or want this part.

Quoted 5 lines
drivers/nvme/host/core.c +0 -0
 static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id,
@@ -2115,13 +2121,13 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	lim = queue_limits_start_update(ns->disk->queue);
 	nvme_set_ctrl_limits(ns->ctrl, &lim);
 	nvme_configure_metadata(ns->ctrl, ns->head, id, nvm);

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

Quoted 10 lines
drivers/nvme/host/core.c +3 -3
+	if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
+	    ns->head->ids.csi == NVME_CSI_ZNS)
+		nvme_update_zone_info(ns, &lim, &zi);
 	nvme_set_chunk_sectors(ns, id, &lim);
 	if (!nvme_update_disk_info(ns, id, &lim))
 		capacity = 0;
 	nvme_config_discard(ns, &lim);
-	if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
-	    ns->head->ids.csi == NVME_CSI_ZNS)
-		nvme_update_zone_info(ns, &lim, &zi);

This part looks fine, but you probably also want to replace the blk_queue_is_zoned() check with one for lim->zoned for this to actually work..