Skip to content

Commit 6b2c8e5

Browse files
committed
Merge branch 'nvme-5.3' of git://git.infradead.org/nvme into for-5.3/block
Pull NVMe updates from Christoph: "A large chunk of NVMe updates for 5.3. Highlights: - improved PCIe suspent support (Keith Busch) - error injection support for the admin queue (Akinobu Mita) - Fibre Channel discovery improvements (James Smart) - tracing improvements including nvmetc tracing support (Minwoo Im) - misc fixes and cleanups (Anton Eidelman, Minwoo Im, Chaitanya Kulkarni)" * 'nvme-5.3' of git://git.infradead.org/nvme: (26 commits) Documentation: nvme: add an example for nvme fault injection nvme: enable to inject errors into admin commands nvme: prepare for fault injection into admin commands nvmet: introduce target-side trace nvme-trace: print result and status in hex format nvme-trace: support for fabrics commands in host-side nvme-trace: move opcode symbol print to nvme.h nvme-trace: do not export nvme_trace_disk_name nvme-pci: clean up nvme_remove_dead_ctrl a bit nvme-pci: properly report state change failure in nvme_reset_work nvme-pci: set the errno on ctrl state change error nvme-pci: adjust irq max_vector using num_possible_cpus() nvme-pci: remove queue_count_ops for write_queues and poll_queues nvme-pci: remove unnecessary zero for static var nvme-pci: use host managed power state for suspend nvme: introduce nvme_is_fabrics to check fabrics cmd nvme: export get and set features nvme: fix possible io failures when removing multipathed ns nvme-fc: add message when creating new association lpfc: add sysfs interface to post NVME RSCN ...
2 parents 2f5af4a + 7e31d82 commit 6b2c8e5

29 files changed

+1110
-134
lines changed

Documentation/fault-injection/nvme-fault-injection.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,59 @@ R13: ffff88011a3c9680 R14: 0000000000000000 R15: 0000000000000000
114114
cpu_startup_entry+0x6f/0x80
115115
start_secondary+0x187/0x1e0
116116
secondary_startup_64+0xa5/0xb0
117+
118+
Example 3: Inject an error into the 10th admin command
119+
------------------------------------------------------
120+
121+
echo 100 > /sys/kernel/debug/nvme0/fault_inject/probability
122+
echo 10 > /sys/kernel/debug/nvme0/fault_inject/space
123+
echo 1 > /sys/kernel/debug/nvme0/fault_inject/times
124+
nvme reset /dev/nvme0
125+
126+
Expected Result:
127+
128+
After NVMe controller reset, the reinitialization may or may not succeed.
129+
It depends on which admin command is actually forced to fail.
130+
131+
Message from dmesg:
132+
133+
nvme nvme0: resetting controller
134+
FAULT_INJECTION: forcing a failure.
135+
name fault_inject, interval 1, probability 100, space 1, times 1
136+
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.2.0-rc2+ #2
137+
Hardware name: MSI MS-7A45/B150M MORTAR ARCTIC (MS-7A45), BIOS 1.50 04/25/2017
138+
Call Trace:
139+
<IRQ>
140+
dump_stack+0x63/0x85
141+
should_fail+0x14a/0x170
142+
nvme_should_fail+0x38/0x80 [nvme_core]
143+
nvme_irq+0x129/0x280 [nvme]
144+
? blk_mq_end_request+0xb3/0x120
145+
__handle_irq_event_percpu+0x84/0x1a0
146+
handle_irq_event_percpu+0x32/0x80
147+
handle_irq_event+0x3b/0x60
148+
handle_edge_irq+0x7f/0x1a0
149+
handle_irq+0x20/0x30
150+
do_IRQ+0x4e/0xe0
151+
common_interrupt+0xf/0xf
152+
</IRQ>
153+
RIP: 0010:cpuidle_enter_state+0xc5/0x460
154+
Code: ff e8 8f 5f 86 ff 80 7d c7 00 74 17 9c 58 0f 1f 44 00 00 f6 c4 02 0f 85 69 03 00 00 31 ff e8 62 aa 8c ff fb 66 0f 1f 44 00 00 <45> 85 ed 0f 88 37 03 00 00 4c 8b 45 d0 4c 2b 45 b8 48 ba cf f7 53
155+
RSP: 0018:ffffffff88c03dd0 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffdc
156+
RAX: ffff9dac25a2ac80 RBX: ffffffff88d53760 RCX: 000000000000001f
157+
RDX: 0000000000000000 RSI: 000000002d958403 RDI: 0000000000000000
158+
RBP: ffffffff88c03e18 R08: fffffff75e35ffb7 R09: 00000a49a56c0b48
159+
R10: ffffffff88c03da0 R11: 0000000000001b0c R12: ffff9dac25a34d00
160+
R13: 0000000000000006 R14: 0000000000000006 R15: ffffffff88d53760
161+
cpuidle_enter+0x2e/0x40
162+
call_cpuidle+0x23/0x40
163+
do_idle+0x201/0x280
164+
cpu_startup_entry+0x1d/0x20
165+
rest_init+0xaa/0xb0
166+
arch_call_rest_init+0xe/0x1b
167+
start_kernel+0x51c/0x53b
168+
x86_64_start_reservations+0x24/0x26
169+
x86_64_start_kernel+0x74/0x77
170+
secondary_startup_64+0xa4/0xb0
171+
nvme nvme0: Could not set queue count (16385)
172+
nvme nvme0: IO queues not created

drivers/nvme/host/core.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,15 +1113,15 @@ static struct nvme_id_ns *nvme_identify_ns(struct nvme_ctrl *ctrl,
11131113
return id;
11141114
}
11151115

1116-
static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword11,
1117-
void *buffer, size_t buflen, u32 *result)
1116+
static int nvme_features(struct nvme_ctrl *dev, u8 op, unsigned int fid,
1117+
unsigned int dword11, void *buffer, size_t buflen, u32 *result)
11181118
{
11191119
struct nvme_command c;
11201120
union nvme_result res;
11211121
int ret;
11221122

11231123
memset(&c, 0, sizeof(c));
1124-
c.features.opcode = nvme_admin_set_features;
1124+
c.features.opcode = op;
11251125
c.features.fid = cpu_to_le32(fid);
11261126
c.features.dword11 = cpu_to_le32(dword11);
11271127

@@ -1132,6 +1132,24 @@ static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword
11321132
return ret;
11331133
}
11341134

1135+
int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid,
1136+
unsigned int dword11, void *buffer, size_t buflen,
1137+
u32 *result)
1138+
{
1139+
return nvme_features(dev, nvme_admin_set_features, fid, dword11, buffer,
1140+
buflen, result);
1141+
}
1142+
EXPORT_SYMBOL_GPL(nvme_set_features);
1143+
1144+
int nvme_get_features(struct nvme_ctrl *dev, unsigned int fid,
1145+
unsigned int dword11, void *buffer, size_t buflen,
1146+
u32 *result)
1147+
{
1148+
return nvme_features(dev, nvme_admin_get_features, fid, dword11, buffer,
1149+
buflen, result);
1150+
}
1151+
EXPORT_SYMBOL_GPL(nvme_get_features);
1152+
11351153
int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)
11361154
{
11371155
u32 q_count = (*count - 1) | ((*count - 1) << 16);
@@ -3318,7 +3336,7 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
33183336
device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups);
33193337

33203338
nvme_mpath_add_disk(ns, id);
3321-
nvme_fault_inject_init(ns);
3339+
nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name);
33223340
kfree(id);
33233341

33243342
return 0;
@@ -3343,24 +3361,26 @@ static void nvme_ns_remove(struct nvme_ns *ns)
33433361
if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
33443362
return;
33453363

3346-
nvme_fault_inject_fini(ns);
3364+
nvme_fault_inject_fini(&ns->fault_inject);
3365+
3366+
mutex_lock(&ns->ctrl->subsys->lock);
3367+
list_del_rcu(&ns->siblings);
3368+
mutex_unlock(&ns->ctrl->subsys->lock);
3369+
synchronize_rcu(); /* guarantee not available in head->list */
3370+
nvme_mpath_clear_current_path(ns);
3371+
synchronize_srcu(&ns->head->srcu); /* wait for concurrent submissions */
3372+
33473373
if (ns->disk && ns->disk->flags & GENHD_FL_UP) {
33483374
del_gendisk(ns->disk);
33493375
blk_cleanup_queue(ns->queue);
33503376
if (blk_get_integrity(ns->disk))
33513377
blk_integrity_unregister(ns->disk);
33523378
}
33533379

3354-
mutex_lock(&ns->ctrl->subsys->lock);
3355-
list_del_rcu(&ns->siblings);
3356-
nvme_mpath_clear_current_path(ns);
3357-
mutex_unlock(&ns->ctrl->subsys->lock);
3358-
33593380
down_write(&ns->ctrl->namespaces_rwsem);
33603381
list_del_init(&ns->list);
33613382
up_write(&ns->ctrl->namespaces_rwsem);
33623383

3363-
synchronize_srcu(&ns->head->srcu);
33643384
nvme_mpath_check_last_path(ns);
33653385
nvme_put_ns(ns);
33663386
}
@@ -3702,6 +3722,7 @@ EXPORT_SYMBOL_GPL(nvme_start_ctrl);
37023722

37033723
void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
37043724
{
3725+
nvme_fault_inject_fini(&ctrl->fault_inject);
37053726
dev_pm_qos_hide_latency_tolerance(ctrl->device);
37063727
cdev_device_del(&ctrl->cdev, ctrl->device);
37073728
}
@@ -3797,6 +3818,8 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
37973818
dev_pm_qos_update_user_latency_tolerance(ctrl->device,
37983819
min(default_ps_max_latency_us, (unsigned long)S32_MAX));
37993820

3821+
nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device));
3822+
38003823
return 0;
38013824
out_free_name:
38023825
kfree_const(ctrl->device->kobj.name);

drivers/nvme/host/fabrics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
578578
switch (ctrl->state) {
579579
case NVME_CTRL_NEW:
580580
case NVME_CTRL_CONNECTING:
581-
if (req->cmd->common.opcode == nvme_fabrics_command &&
581+
if (nvme_is_fabrics(req->cmd) &&
582582
req->cmd->fabrics.fctype == nvme_fabrics_type_connect)
583583
return true;
584584
break;

drivers/nvme/host/fault_inject.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,31 @@ static DECLARE_FAULT_ATTR(fail_default_attr);
1515
static char *fail_request;
1616
module_param(fail_request, charp, 0000);
1717

18-
void nvme_fault_inject_init(struct nvme_ns *ns)
18+
void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
19+
const char *dev_name)
1920
{
2021
struct dentry *dir, *parent;
21-
char *name = ns->disk->disk_name;
22-
struct nvme_fault_inject *fault_inj = &ns->fault_inject;
2322
struct fault_attr *attr = &fault_inj->attr;
2423

2524
/* set default fault injection attribute */
2625
if (fail_request)
2726
setup_fault_attr(&fail_default_attr, fail_request);
2827

2928
/* create debugfs directory and attribute */
30-
parent = debugfs_create_dir(name, NULL);
29+
parent = debugfs_create_dir(dev_name, NULL);
3130
if (!parent) {
32-
pr_warn("%s: failed to create debugfs directory\n", name);
31+
pr_warn("%s: failed to create debugfs directory\n", dev_name);
3332
return;
3433
}
3534

3635
*attr = fail_default_attr;
3736
dir = fault_create_debugfs_attr("fault_inject", parent, attr);
3837
if (IS_ERR(dir)) {
39-
pr_warn("%s: failed to create debugfs attr\n", name);
38+
pr_warn("%s: failed to create debugfs attr\n", dev_name);
4039
debugfs_remove_recursive(parent);
4140
return;
4241
}
43-
ns->fault_inject.parent = parent;
42+
fault_inj->parent = parent;
4443

4544
/* create debugfs for status code and dont_retry */
4645
fault_inj->status = NVME_SC_INVALID_OPCODE;
@@ -49,29 +48,33 @@ void nvme_fault_inject_init(struct nvme_ns *ns)
4948
debugfs_create_bool("dont_retry", 0600, dir, &fault_inj->dont_retry);
5049
}
5150

52-
void nvme_fault_inject_fini(struct nvme_ns *ns)
51+
void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject)
5352
{
5453
/* remove debugfs directories */
55-
debugfs_remove_recursive(ns->fault_inject.parent);
54+
debugfs_remove_recursive(fault_inject->parent);
5655
}
5756

5857
void nvme_should_fail(struct request *req)
5958
{
6059
struct gendisk *disk = req->rq_disk;
61-
struct nvme_ns *ns = NULL;
60+
struct nvme_fault_inject *fault_inject = NULL;
6261
u16 status;
6362

64-
/*
65-
* make sure this request is coming from a valid namespace
66-
*/
67-
if (!disk)
68-
return;
63+
if (disk) {
64+
struct nvme_ns *ns = disk->private_data;
65+
66+
if (ns)
67+
fault_inject = &ns->fault_inject;
68+
else
69+
WARN_ONCE(1, "No namespace found for request\n");
70+
} else {
71+
fault_inject = &nvme_req(req)->ctrl->fault_inject;
72+
}
6973

70-
ns = disk->private_data;
71-
if (ns && should_fail(&ns->fault_inject.attr, 1)) {
74+
if (fault_inject && should_fail(&fault_inject->attr, 1)) {
7275
/* inject status code and DNR bit */
73-
status = ns->fault_inject.status;
74-
if (ns->fault_inject.dont_retry)
76+
status = fault_inject->status;
77+
if (fault_inject->dont_retry)
7578
status |= NVME_SC_DNR;
7679
nvme_req(req)->status = status;
7780
}

drivers/nvme/host/fc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,6 +2607,12 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
26072607
if (nvme_fc_ctlr_active_on_rport(ctrl))
26082608
return -ENOTUNIQ;
26092609

2610+
dev_info(ctrl->ctrl.device,
2611+
"NVME-FC{%d}: create association : host wwpn 0x%016llx "
2612+
" rport wwpn 0x%016llx: NQN \"%s\"\n",
2613+
ctrl->cnum, ctrl->lport->localport.port_name,
2614+
ctrl->rport->remoteport.port_name, ctrl->ctrl.opts->subsysnqn);
2615+
26102616
/*
26112617
* Create the admin queue
26122618
*/

drivers/nvme/host/nvme.h

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ enum nvme_ctrl_state {
146146
NVME_CTRL_DEAD,
147147
};
148148

149+
struct nvme_fault_inject {
150+
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
151+
struct fault_attr attr;
152+
struct dentry *parent;
153+
bool dont_retry; /* DNR, do not retry */
154+
u16 status; /* status code */
155+
#endif
156+
};
157+
149158
struct nvme_ctrl {
150159
bool comp_seen;
151160
enum nvme_ctrl_state state;
@@ -247,6 +256,8 @@ struct nvme_ctrl {
247256

248257
struct page *discard_page;
249258
unsigned long discard_page_busy;
259+
260+
struct nvme_fault_inject fault_inject;
250261
};
251262

252263
enum nvme_iopolicy {
@@ -313,15 +324,6 @@ struct nvme_ns_head {
313324
#endif
314325
};
315326

316-
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
317-
struct nvme_fault_inject {
318-
struct fault_attr attr;
319-
struct dentry *parent;
320-
bool dont_retry; /* DNR, do not retry */
321-
u16 status; /* status code */
322-
};
323-
#endif
324-
325327
struct nvme_ns {
326328
struct list_head list;
327329

@@ -349,9 +351,7 @@ struct nvme_ns {
349351
#define NVME_NS_ANA_PENDING 2
350352
u16 noiob;
351353

352-
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
353354
struct nvme_fault_inject fault_inject;
354-
#endif
355355

356356
};
357357

@@ -372,12 +372,18 @@ struct nvme_ctrl_ops {
372372
};
373373

374374
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
375-
void nvme_fault_inject_init(struct nvme_ns *ns);
376-
void nvme_fault_inject_fini(struct nvme_ns *ns);
375+
void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
376+
const char *dev_name);
377+
void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject);
377378
void nvme_should_fail(struct request *req);
378379
#else
379-
static inline void nvme_fault_inject_init(struct nvme_ns *ns) {}
380-
static inline void nvme_fault_inject_fini(struct nvme_ns *ns) {}
380+
static inline void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
381+
const char *dev_name)
382+
{
383+
}
384+
static inline void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inj)
385+
{
386+
}
381387
static inline void nvme_should_fail(struct request *req) {}
382388
#endif
383389

@@ -459,6 +465,12 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
459465
union nvme_result *result, void *buffer, unsigned bufflen,
460466
unsigned timeout, int qid, int at_head,
461467
blk_mq_req_flags_t flags, bool poll);
468+
int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid,
469+
unsigned int dword11, void *buffer, size_t buflen,
470+
u32 *result);
471+
int nvme_get_features(struct nvme_ctrl *dev, unsigned int fid,
472+
unsigned int dword11, void *buffer, size_t buflen,
473+
u32 *result);
462474
int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count);
463475
void nvme_stop_keep_alive(struct nvme_ctrl *ctrl);
464476
int nvme_reset_ctrl(struct nvme_ctrl *ctrl);

0 commit comments

Comments
 (0)