Skip to content

Commit df84a4f

Browse files
nvme: fix atomic write size validation
JIRA: https://issues.redhat.com/browse/RHEL-114502 Don't mix the namespace and controller values, and validate the per-controller limit when probing the controller. This avoid spurious failures for controllers with namespaces that have different namespaces with different logical block sizes, or report the per-namespace values only for some namespaces. It also fixes a missing queue_limits_cancel_update in an error path by removing that error path. Fixes: 8695f06 ("nvme: all namespaces in a subsystem must adhere to a common atomic write size") Reported-by: Yi Zhang <yi.zhang@redhat.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: John Garry <john.g.garry@oracle.com> Tested-by: Yi Zhang <yi.zhang@redhat.com> (cherry picked from commit f46d273) Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
1 parent 8348552 commit df84a4f

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

drivers/nvme/host/core.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,17 +2056,7 @@ static u32 nvme_configure_atomic_write(struct nvme_ns *ns,
20562056
* no clear language in the specification prohibiting different
20572057
* values for different controllers in the subsystem.
20582058
*/
2059-
atomic_bs = (1 + ns->ctrl->awupf) * bs;
2060-
}
2061-
2062-
if (!ns->ctrl->subsys->atomic_bs) {
2063-
ns->ctrl->subsys->atomic_bs = atomic_bs;
2064-
} else if (ns->ctrl->subsys->atomic_bs != atomic_bs) {
2065-
dev_err_ratelimited(ns->ctrl->device,
2066-
"%s: Inconsistent Atomic Write Size, Namespace will not be added: Subsystem=%d bytes, Controller/Namespace=%d bytes\n",
2067-
ns->disk ? ns->disk->disk_name : "?",
2068-
ns->ctrl->subsys->atomic_bs,
2069-
atomic_bs);
2059+
atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs;
20702060
}
20712061

20722062
lim->atomic_write_hw_max = atomic_bs;
@@ -2401,16 +2391,6 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
24012391
if (!nvme_update_disk_info(ns, id, &lim))
24022392
capacity = 0;
24032393

2404-
/*
2405-
* Validate the max atomic write size fits within the subsystem's
2406-
* atomic write capabilities.
2407-
*/
2408-
if (lim.atomic_write_hw_max > ns->ctrl->subsys->atomic_bs) {
2409-
blk_mq_unfreeze_queue(ns->disk->queue, memflags);
2410-
ret = -ENXIO;
2411-
goto out;
2412-
}
2413-
24142394
nvme_config_discard(ns, &lim);
24152395
if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
24162396
ns->head->ids.csi == NVME_CSI_ZNS)
@@ -3234,6 +3214,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
32343214
memcpy(subsys->model, id->mn, sizeof(subsys->model));
32353215
subsys->vendor_id = le16_to_cpu(id->vid);
32363216
subsys->cmic = id->cmic;
3217+
subsys->awupf = le16_to_cpu(id->awupf);
32373218

32383219
/* Versions prior to 1.4 don't necessarily report a valid type */
32393220
if (id->cntrltype == NVME_CTRL_DISC ||
@@ -3571,6 +3552,15 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
35713552
if (ret)
35723553
goto out_free;
35733554
}
3555+
3556+
if (le16_to_cpu(id->awupf) != ctrl->subsys->awupf) {
3557+
dev_err_ratelimited(ctrl->device,
3558+
"inconsistent AWUPF, controller not added (%u/%u).\n",
3559+
le16_to_cpu(id->awupf), ctrl->subsys->awupf);
3560+
ret = -EINVAL;
3561+
goto out_free;
3562+
}
3563+
35743564
memcpy(ctrl->subsys->firmware_rev, id->fr,
35753565
sizeof(ctrl->subsys->firmware_rev));
35763566

@@ -3666,7 +3656,6 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
36663656
dev_pm_qos_expose_latency_tolerance(ctrl->device);
36673657
else if (!ctrl->apst_enabled && prev_apst_enabled)
36683658
dev_pm_qos_hide_latency_tolerance(ctrl->device);
3669-
ctrl->awupf = le16_to_cpu(id->awupf);
36703659
out_free:
36713660
kfree(id);
36723661
return ret;

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ struct nvme_ctrl {
411411

412412
enum nvme_ctrl_type cntrltype;
413413
enum nvme_dctype dctype;
414-
u16 awupf; /* 0's based value. */
415414
};
416415

417416
static inline enum nvme_ctrl_state nvme_ctrl_state(struct nvme_ctrl *ctrl)
@@ -444,11 +443,11 @@ struct nvme_subsystem {
444443
u8 cmic;
445444
enum nvme_subsys_type subtype;
446445
u16 vendor_id;
446+
u16 awupf; /* 0's based value. */
447447
struct ida ns_ida;
448448
#ifdef CONFIG_NVME_MULTIPATH
449449
enum nvme_iopolicy iopolicy;
450450
#endif
451-
u32 atomic_bs;
452451
};
453452

454453
/*

0 commit comments

Comments
 (0)