nvme: report capacity 0 for non supported ZNS SSDs
Subsystems (2)
PATCH v2 1/1 nvme: report capacity 0 for non supported ZNS SSDs
Allow ZNS SSDs to be presented to the host even when they implement features that are not supported by the kernel zoned block device.
Instead of rejecting the SSD at the NVMe driver level, deal with this in the block layer by setting capacity to 0, as we do with other things such as unsupported PI configurations. This allows to use standard management tools such as nvme-cli to choose a different format or firmware slot that is compatible with the Linux zoned block device.
Changes since V1:
- Apply feedback from Niklas:
- Use IS_ENABLED() for checking config option
- Use local variable
- Use different variable names
--- drivers/nvme/host/core.c | 3 +++ drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/zns.c | 26 ++++++++++++++------------ 3 files changed, 18 insertions(+), 12 deletions(-)
drivers/nvme/host/core.c +3 -0
@@ -2026,6 +2026,9 @@ static void nvme_update_disk_info(struct gendisk *disk, capacity =0 ; } +if (IS_ENABLED (CONFIG_BLK_DEV_ZONED ) && !ns->zoned_ns_supp) + capacity =0 ; +set_capacity_revalidate_and_notify (disk, capacity, false);nvme_config_discard (disk, ns);
drivers/nvme/host/nvme.h +1 -0
@@ -443,6 +443,7 @@ struct nvme_ns {u8 pi_type;#ifdef CONFIG_BLK_DEV_ZONED u64 zsze; +bool zoned_ns_supp;#endif unsigned long features;unsigned long flags;
drivers/nvme/host/zns.c +14 -12
@@ -42,22 +42,25 @@ int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns,struct request_queue *q = disk->queue;struct nvme_command c = { };struct nvme_id_ns_zns *id; +bool zoned_ns_supp = true;int status;/* Driver requires zone append support */ if (!(le32_to_cpu (log->iocs[nvme_cmd_zone_append]) &NVME_CMD_EFFECTS_CSUPP )) { + zoned_ns_supp = false;dev_warn (ns->ctrl->device,"append not supported for zoned namespace:%d\n" , ns->head->ns_id); -return -EINVAL ; - } - -/* Lazily query controller append limit for the first zoned namespace */ -if (!ns->ctrl->max_zone_append) { - status =nvme_set_max_append (ns->ctrl); -if (status) -return status; + }else { +/* Lazily query controller append limit for the first +* zoned namespace +*/ +if (!ns->ctrl->max_zone_append) { + status =nvme_set_max_append (ns->ctrl); +if (status) +return status; + } } id =kzalloc (sizeof (*id),GFP_KERNEL );
@@ -78,23 +81,22 @@ int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns,* operation characteristics. */ if (id->zoc) { + zoned_ns_supp = false;dev_warn (ns->ctrl->device,"zone operations:%x not supported for namespace:%u\n" ,le16_to_cpu (id->zoc), ns->head->ns_id); - status = -EINVAL ; - goto free_data; } ns->zsze =nvme_lba_to_sect (ns,le64_to_cpu (id->lbafe[lbaf].zsze));if (!is_power_of_2 (ns->zsze)) { + zoned_ns_supp = false;dev_warn (ns->ctrl->device,"invalid zone size:%llu for namespace:%u\n" , ns->zsze, ns->head->ns_id); - status = -EINVAL ; - goto free_data; } q->limits.zoned =BLK_ZONED_HM ; + ns->zoned_ns_supp = zoned_ns_supp;blk_queue_flag_set (QUEUE_FLAG_ZONE_RESETALL , q);blk_queue_max_open_zones (q,le32_to_cpu (id->mor) +1 );blk_queue_max_active_zones (q,le32_to_cpu (id->mar) +1 );
Signature · 1 line
2.17.1
Keith Busch
maintainerQuoted 3 lines · Javier González
Changes since V1:
- Apply feedback from Niklas:
- UseIS_ENABLED()for checking config option
Your v1 was correct. Using IS_ENBALED() attempts to use an undefined symbol when the CONFIG is not enabled:
drivers/nvme/host/core.c: In function ‘nvme_update_disk_info’:
drivers/nvme/host/core.c:2056:45: error: ‘struct nvme_ns’ has no member named ‘zoned_ns_supp’
2056 | if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && !ns->zoned_ns_supp)
| ^~
That said, I don't mind the concept, though I recall Christoph had concerns about the existing 0-capacity namespace used for invalid formats, so I'd like to hear more on that if he has some spare time to comment.