Skip to content

Commit 6b43537

Browse files
committed
Merge tag 'nvme-6.11-2024-07-08' of git://git.infradead.org/nvme into for-6.11/block
Pull NVMe updates from Keith: "nvme updates for Linux 6.11 - Device initialization memory leak fixes (Keith) - More constants defined (Weiwen) - Target debugfs support (Hannes) - PCIe subsystem reset enhancements (Keith) - Queue-depth multipath policy (Redhat and PureStorage) - Implement get_unique_id (Christoph) - Authentication error fixes (Gaosheng)" * tag 'nvme-6.11-2024-07-08' of git://git.infradead.org/nvme: (21 commits) nvmet-auth: fix nvmet_auth hash error handling nvme: implement ->get_unique_id nvme-multipath: implement "queue-depth" iopolicy nvme-multipath: prepare for "queue-depth" iopolicy nvme-pci: do not directly handle subsys reset fallout lpfc_nvmet: implement 'host_traddr' nvme-fcloop: implement 'host_traddr' nvmet-fc: implement host_traddr() nvmet-rdma: implement host_traddr() nvmet-tcp: implement host_traddr() nvmet: add 'host_traddr' callback for debugfs nvmet: add debugfs support mailmap: add entry for Weiwen Hu nvme: rename CDR/MORE/DNR to NVME_STATUS_* nvme: fix status magic numbers nvme: rename nvme_sc_to_pr_err to nvme_status_to_pr_err nvme: split device add from initialization nvme: fc: split controller bringup handling nvme: rdma: split controller bringup handling nvme: tcp: split controller bringup handling ...
2 parents 09595e0 + 89f58f9 commit 6b43537

36 files changed

+902
-229
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ Vivien Didelot <[email protected]> <[email protected]>
685685
686686
687687
688+
688689
689690
690691

drivers/nvme/host/apple.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,15 +1388,15 @@ static void devm_apple_nvme_mempool_destroy(void *data)
13881388
mempool_destroy(data);
13891389
}
13901390

1391-
static int apple_nvme_probe(struct platform_device *pdev)
1391+
static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev)
13921392
{
13931393
struct device *dev = &pdev->dev;
13941394
struct apple_nvme *anv;
13951395
int ret;
13961396

13971397
anv = devm_kzalloc(dev, sizeof(*anv), GFP_KERNEL);
13981398
if (!anv)
1399-
return -ENOMEM;
1399+
return ERR_PTR(-ENOMEM);
14001400

14011401
anv->dev = get_device(dev);
14021402
anv->adminq.is_adminq = true;
@@ -1516,19 +1516,41 @@ static int apple_nvme_probe(struct platform_device *pdev)
15161516
goto put_dev;
15171517
}
15181518

1519+
return anv;
1520+
put_dev:
1521+
put_device(anv->dev);
1522+
return ERR_PTR(ret);
1523+
}
1524+
1525+
static int apple_nvme_probe(struct platform_device *pdev)
1526+
{
1527+
struct apple_nvme *anv;
1528+
int ret;
1529+
1530+
anv = apple_nvme_alloc(pdev);
1531+
if (IS_ERR(anv))
1532+
return PTR_ERR(anv);
1533+
1534+
ret = nvme_add_ctrl(&anv->ctrl);
1535+
if (ret)
1536+
goto out_put_ctrl;
1537+
15191538
anv->ctrl.admin_q = blk_mq_alloc_queue(&anv->admin_tagset, NULL, NULL);
15201539
if (IS_ERR(anv->ctrl.admin_q)) {
15211540
ret = -ENOMEM;
1522-
goto put_dev;
1541+
anv->ctrl.admin_q = NULL;
1542+
goto out_uninit_ctrl;
15231543
}
15241544

15251545
nvme_reset_ctrl(&anv->ctrl);
15261546
async_schedule(apple_nvme_async_probe, anv);
15271547

15281548
return 0;
15291549

1530-
put_dev:
1531-
put_device(anv->dev);
1550+
out_uninit_ctrl:
1551+
nvme_uninit_ctrl(&anv->ctrl);
1552+
out_put_ctrl:
1553+
nvme_put_ctrl(&anv->ctrl);
15321554
return ret;
15331555
}
15341556

drivers/nvme/host/constants.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static const char * const nvme_statuses[] = {
173173

174174
const char *nvme_get_error_status_str(u16 status)
175175
{
176-
status &= 0x7ff;
176+
status &= NVME_SCT_SC_MASK;
177177
if (status < ARRAY_SIZE(nvme_statuses) && nvme_statuses[status])
178178
return nvme_statuses[status];
179179
return "Unknown";

drivers/nvme/host/core.c

Lines changed: 83 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct workqueue_struct *nvme_delete_wq;
110110
EXPORT_SYMBOL_GPL(nvme_delete_wq);
111111

112112
static LIST_HEAD(nvme_subsystems);
113-
static DEFINE_MUTEX(nvme_subsystems_lock);
113+
DEFINE_MUTEX(nvme_subsystems_lock);
114114

115115
static DEFINE_IDA(nvme_instance_ida);
116116
static dev_t nvme_ctrl_base_chr_devt;
@@ -261,7 +261,7 @@ void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
261261

262262
static blk_status_t nvme_error_status(u16 status)
263263
{
264-
switch (status & 0x7ff) {
264+
switch (status & NVME_SCT_SC_MASK) {
265265
case NVME_SC_SUCCESS:
266266
return BLK_STS_OK;
267267
case NVME_SC_CAP_EXCEEDED:
@@ -307,7 +307,7 @@ static void nvme_retry_req(struct request *req)
307307
u16 crd;
308308

309309
/* The mask and shift result must be <= 3 */
310-
crd = (nvme_req(req)->status & NVME_SC_CRD) >> 11;
310+
crd = (nvme_req(req)->status & NVME_STATUS_CRD) >> 11;
311311
if (crd)
312312
delay = nvme_req(req)->ctrl->crdt[crd - 1] * 100;
313313

@@ -329,10 +329,10 @@ static void nvme_log_error(struct request *req)
329329
nvme_sect_to_lba(ns->head, blk_rq_pos(req)),
330330
blk_rq_bytes(req) >> ns->head->lba_shift,
331331
nvme_get_error_status_str(nr->status),
332-
nr->status >> 8 & 7, /* Status Code Type */
333-
nr->status & 0xff, /* Status Code */
334-
nr->status & NVME_SC_MORE ? "MORE " : "",
335-
nr->status & NVME_SC_DNR ? "DNR " : "");
332+
NVME_SCT(nr->status), /* Status Code Type */
333+
nr->status & NVME_SC_MASK, /* Status Code */
334+
nr->status & NVME_STATUS_MORE ? "MORE " : "",
335+
nr->status & NVME_STATUS_DNR ? "DNR " : "");
336336
return;
337337
}
338338

@@ -341,10 +341,10 @@ static void nvme_log_error(struct request *req)
341341
nvme_get_admin_opcode_str(nr->cmd->common.opcode),
342342
nr->cmd->common.opcode,
343343
nvme_get_error_status_str(nr->status),
344-
nr->status >> 8 & 7, /* Status Code Type */
345-
nr->status & 0xff, /* Status Code */
346-
nr->status & NVME_SC_MORE ? "MORE " : "",
347-
nr->status & NVME_SC_DNR ? "DNR " : "");
344+
NVME_SCT(nr->status), /* Status Code Type */
345+
nr->status & NVME_SC_MASK, /* Status Code */
346+
nr->status & NVME_STATUS_MORE ? "MORE " : "",
347+
nr->status & NVME_STATUS_DNR ? "DNR " : "");
348348
}
349349

350350
static void nvme_log_err_passthru(struct request *req)
@@ -359,10 +359,10 @@ static void nvme_log_err_passthru(struct request *req)
359359
nvme_get_admin_opcode_str(nr->cmd->common.opcode),
360360
nr->cmd->common.opcode,
361361
nvme_get_error_status_str(nr->status),
362-
nr->status >> 8 & 7, /* Status Code Type */
363-
nr->status & 0xff, /* Status Code */
364-
nr->status & NVME_SC_MORE ? "MORE " : "",
365-
nr->status & NVME_SC_DNR ? "DNR " : "",
362+
NVME_SCT(nr->status), /* Status Code Type */
363+
nr->status & NVME_SC_MASK, /* Status Code */
364+
nr->status & NVME_STATUS_MORE ? "MORE " : "",
365+
nr->status & NVME_STATUS_DNR ? "DNR " : "",
366366
nr->cmd->common.cdw10,
367367
nr->cmd->common.cdw11,
368368
nr->cmd->common.cdw12,
@@ -384,11 +384,11 @@ static inline enum nvme_disposition nvme_decide_disposition(struct request *req)
384384
return COMPLETE;
385385

386386
if (blk_noretry_request(req) ||
387-
(nvme_req(req)->status & NVME_SC_DNR) ||
387+
(nvme_req(req)->status & NVME_STATUS_DNR) ||
388388
nvme_req(req)->retries >= nvme_max_retries)
389389
return COMPLETE;
390390

391-
if ((nvme_req(req)->status & 0x7ff) == NVME_SC_AUTH_REQUIRED)
391+
if ((nvme_req(req)->status & NVME_SCT_SC_MASK) == NVME_SC_AUTH_REQUIRED)
392392
return AUTHENTICATE;
393393

394394
if (req->cmd_flags & REQ_NVME_MPATH) {
@@ -1256,7 +1256,7 @@ EXPORT_SYMBOL_NS_GPL(nvme_passthru_end, NVME_TARGET_PASSTHRU);
12561256

12571257
/*
12581258
* Recommended frequency for KATO commands per NVMe 1.4 section 7.12.1:
1259-
*
1259+
*
12601260
* The host should send Keep Alive commands at half of the Keep Alive Timeout
12611261
* accounting for transport roundtrip times [..].
12621262
*/
@@ -2286,6 +2286,32 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)
22862286
return ret;
22872287
}
22882288

2289+
int nvme_ns_get_unique_id(struct nvme_ns *ns, u8 id[16],
2290+
enum blk_unique_id type)
2291+
{
2292+
struct nvme_ns_ids *ids = &ns->head->ids;
2293+
2294+
if (type != BLK_UID_EUI64)
2295+
return -EINVAL;
2296+
2297+
if (memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) {
2298+
memcpy(id, &ids->nguid, sizeof(ids->nguid));
2299+
return sizeof(ids->nguid);
2300+
}
2301+
if (memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) {
2302+
memcpy(id, &ids->eui64, sizeof(ids->eui64));
2303+
return sizeof(ids->eui64);
2304+
}
2305+
2306+
return -EINVAL;
2307+
}
2308+
2309+
static int nvme_get_unique_id(struct gendisk *disk, u8 id[16],
2310+
enum blk_unique_id type)
2311+
{
2312+
return nvme_ns_get_unique_id(disk->private_data, id, type);
2313+
}
2314+
22892315
#ifdef CONFIG_BLK_SED_OPAL
22902316
static int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
22912317
bool send)
@@ -2341,6 +2367,7 @@ const struct block_device_operations nvme_bdev_ops = {
23412367
.open = nvme_open,
23422368
.release = nvme_release,
23432369
.getgeo = nvme_getgeo,
2370+
.get_unique_id = nvme_get_unique_id,
23442371
.report_zones = nvme_report_zones,
23452372
.pr_ops = &nvme_pr_ops,
23462373
};
@@ -3941,7 +3968,7 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)
39413968

39423969
static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info)
39433970
{
3944-
int ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
3971+
int ret = NVME_SC_INVALID_NS | NVME_STATUS_DNR;
39453972

39463973
if (!nvme_ns_ids_equal(&ns->head->ids, &info->ids)) {
39473974
dev_err(ns->ctrl->device,
@@ -3957,7 +3984,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info)
39573984
*
39583985
* TODO: we should probably schedule a delayed retry here.
39593986
*/
3960-
if (ret > 0 && (ret & NVME_SC_DNR))
3987+
if (ret > 0 && (ret & NVME_STATUS_DNR))
39613988
nvme_ns_remove(ns);
39623989
}
39633990

@@ -4148,7 +4175,7 @@ static void nvme_scan_work(struct work_struct *work)
41484175
* they report) but don't actually support it.
41494176
*/
41504177
ret = nvme_scan_ns_list(ctrl);
4151-
if (ret > 0 && ret & NVME_SC_DNR)
4178+
if (ret > 0 && ret & NVME_STATUS_DNR)
41524179
nvme_scan_ns_sequential(ctrl);
41534180
}
41544181
mutex_unlock(&ctrl->scan_lock);
@@ -4668,6 +4695,9 @@ static void nvme_free_ctrl(struct device *dev)
46684695
* Initialize a NVMe controller structures. This needs to be called during
46694696
* earliest initialization so that we have the initialized structured around
46704697
* during probing.
4698+
*
4699+
* On success, the caller must use the nvme_put_ctrl() to release this when
4700+
* needed, which also invokes the ops->free_ctrl() callback.
46714701
*/
46724702
int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
46734703
const struct nvme_ctrl_ops *ops, unsigned long quirks)
@@ -4716,6 +4746,12 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
47164746
goto out;
47174747
ctrl->instance = ret;
47184748

4749+
ret = nvme_auth_init_ctrl(ctrl);
4750+
if (ret)
4751+
goto out_release_instance;
4752+
4753+
nvme_mpath_init_ctrl(ctrl);
4754+
47194755
device_initialize(&ctrl->ctrl_device);
47204756
ctrl->device = &ctrl->ctrl_device;
47214757
ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt),
@@ -4728,16 +4764,36 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
47284764
ctrl->device->groups = nvme_dev_attr_groups;
47294765
ctrl->device->release = nvme_free_ctrl;
47304766
dev_set_drvdata(ctrl->device, ctrl);
4767+
4768+
return ret;
4769+
4770+
out_release_instance:
4771+
ida_free(&nvme_instance_ida, ctrl->instance);
4772+
out:
4773+
if (ctrl->discard_page)
4774+
__free_page(ctrl->discard_page);
4775+
cleanup_srcu_struct(&ctrl->srcu);
4776+
return ret;
4777+
}
4778+
EXPORT_SYMBOL_GPL(nvme_init_ctrl);
4779+
4780+
/*
4781+
* On success, returns with an elevated controller reference and caller must
4782+
* use nvme_uninit_ctrl() to properly free resources associated with the ctrl.
4783+
*/
4784+
int nvme_add_ctrl(struct nvme_ctrl *ctrl)
4785+
{
4786+
int ret;
4787+
47314788
ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance);
47324789
if (ret)
4733-
goto out_release_instance;
4790+
return ret;
47344791

4735-
nvme_get_ctrl(ctrl);
47364792
cdev_init(&ctrl->cdev, &nvme_dev_fops);
4737-
ctrl->cdev.owner = ops->module;
4793+
ctrl->cdev.owner = ctrl->ops->module;
47384794
ret = cdev_device_add(&ctrl->cdev, ctrl->device);
47394795
if (ret)
4740-
goto out_free_name;
4796+
return ret;
47414797

47424798
/*
47434799
* Initialize latency tolerance controls. The sysfs files won't
@@ -4748,28 +4804,11 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
47484804
min(default_ps_max_latency_us, (unsigned long)S32_MAX));
47494805

47504806
nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device));
4751-
nvme_mpath_init_ctrl(ctrl);
4752-
ret = nvme_auth_init_ctrl(ctrl);
4753-
if (ret)
4754-
goto out_free_cdev;
4807+
nvme_get_ctrl(ctrl);
47554808

47564809
return 0;
4757-
out_free_cdev:
4758-
nvme_fault_inject_fini(&ctrl->fault_inject);
4759-
dev_pm_qos_hide_latency_tolerance(ctrl->device);
4760-
cdev_device_del(&ctrl->cdev, ctrl->device);
4761-
out_free_name:
4762-
nvme_put_ctrl(ctrl);
4763-
kfree_const(ctrl->device->kobj.name);
4764-
out_release_instance:
4765-
ida_free(&nvme_instance_ida, ctrl->instance);
4766-
out:
4767-
if (ctrl->discard_page)
4768-
__free_page(ctrl->discard_page);
4769-
cleanup_srcu_struct(&ctrl->srcu);
4770-
return ret;
47714810
}
4772-
EXPORT_SYMBOL_GPL(nvme_init_ctrl);
4811+
EXPORT_SYMBOL_GPL(nvme_add_ctrl);
47734812

47744813
/* let I/O to all namespaces fail in preparation for surprise removal */
47754814
void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl)

0 commit comments

Comments
 (0)