Skip to content

Commit b55f009

Browse files
committed
Merge branch 'nvme-5.4' of git://git.infradead.org/nvme into for-linus
Pull NVMe updates from Keith: "This is a collection of bug fixes committed since the previous pull request that address deadlocks, double resets, memory leaks, and other regression." * 'nvme-5.4' of git://git.infradead.org/nvme: nvme-pci: Set the prp2 correctly when using more than 4k page nvme-tcp: fix possible leakage during error flow nvmet-loop: fix possible leakage during error flow nvme-tcp: Initialize sk->sk_ll_usec only with NET_RX_BUSY_POLL nvme: Wait for reset state when required nvme: Prevent resets during paused controller state nvme: Restart request timers in resetting state nvme: Remove ADMIN_ONLY state nvme-pci: Free tagset if no IO queues nvme: retain split access workaround for capability reads nvme: fix possible deadlock when nvme_update_formats fails
2 parents 8b07a65 + a4f4048 commit b55f009

File tree

7 files changed

+144
-64
lines changed

7 files changed

+144
-64
lines changed

drivers/nvme/host/core.c

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,26 @@ static void nvme_queue_scan(struct nvme_ctrl *ctrl)
116116
/*
117117
* Only new queue scan work when admin and IO queues are both alive
118118
*/
119-
if (ctrl->state == NVME_CTRL_LIVE)
119+
if (ctrl->state == NVME_CTRL_LIVE && ctrl->tagset)
120120
queue_work(nvme_wq, &ctrl->scan_work);
121121
}
122122

123+
/*
124+
* Use this function to proceed with scheduling reset_work for a controller
125+
* that had previously been set to the resetting state. This is intended for
126+
* code paths that can't be interrupted by other reset attempts. A hot removal
127+
* may prevent this from succeeding.
128+
*/
129+
int nvme_try_sched_reset(struct nvme_ctrl *ctrl)
130+
{
131+
if (ctrl->state != NVME_CTRL_RESETTING)
132+
return -EBUSY;
133+
if (!queue_work(nvme_reset_wq, &ctrl->reset_work))
134+
return -EBUSY;
135+
return 0;
136+
}
137+
EXPORT_SYMBOL_GPL(nvme_try_sched_reset);
138+
123139
int nvme_reset_ctrl(struct nvme_ctrl *ctrl)
124140
{
125141
if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING))
@@ -137,8 +153,7 @@ int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl)
137153
ret = nvme_reset_ctrl(ctrl);
138154
if (!ret) {
139155
flush_work(&ctrl->reset_work);
140-
if (ctrl->state != NVME_CTRL_LIVE &&
141-
ctrl->state != NVME_CTRL_ADMIN_ONLY)
156+
if (ctrl->state != NVME_CTRL_LIVE)
142157
ret = -ENETRESET;
143158
}
144159

@@ -315,15 +330,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
315330

316331
old_state = ctrl->state;
317332
switch (new_state) {
318-
case NVME_CTRL_ADMIN_ONLY:
319-
switch (old_state) {
320-
case NVME_CTRL_CONNECTING:
321-
changed = true;
322-
/* FALLTHRU */
323-
default:
324-
break;
325-
}
326-
break;
327333
case NVME_CTRL_LIVE:
328334
switch (old_state) {
329335
case NVME_CTRL_NEW:
@@ -339,7 +345,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
339345
switch (old_state) {
340346
case NVME_CTRL_NEW:
341347
case NVME_CTRL_LIVE:
342-
case NVME_CTRL_ADMIN_ONLY:
343348
changed = true;
344349
/* FALLTHRU */
345350
default:
@@ -359,7 +364,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
359364
case NVME_CTRL_DELETING:
360365
switch (old_state) {
361366
case NVME_CTRL_LIVE:
362-
case NVME_CTRL_ADMIN_ONLY:
363367
case NVME_CTRL_RESETTING:
364368
case NVME_CTRL_CONNECTING:
365369
changed = true;
@@ -381,8 +385,10 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
381385
break;
382386
}
383387

384-
if (changed)
388+
if (changed) {
385389
ctrl->state = new_state;
390+
wake_up_all(&ctrl->state_wq);
391+
}
386392

387393
spin_unlock_irqrestore(&ctrl->lock, flags);
388394
if (changed && ctrl->state == NVME_CTRL_LIVE)
@@ -391,6 +397,39 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
391397
}
392398
EXPORT_SYMBOL_GPL(nvme_change_ctrl_state);
393399

400+
/*
401+
* Returns true for sink states that can't ever transition back to live.
402+
*/
403+
static bool nvme_state_terminal(struct nvme_ctrl *ctrl)
404+
{
405+
switch (ctrl->state) {
406+
case NVME_CTRL_NEW:
407+
case NVME_CTRL_LIVE:
408+
case NVME_CTRL_RESETTING:
409+
case NVME_CTRL_CONNECTING:
410+
return false;
411+
case NVME_CTRL_DELETING:
412+
case NVME_CTRL_DEAD:
413+
return true;
414+
default:
415+
WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state);
416+
return true;
417+
}
418+
}
419+
420+
/*
421+
* Waits for the controller state to be resetting, or returns false if it is
422+
* not possible to ever transition to that state.
423+
*/
424+
bool nvme_wait_reset(struct nvme_ctrl *ctrl)
425+
{
426+
wait_event(ctrl->state_wq,
427+
nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING) ||
428+
nvme_state_terminal(ctrl));
429+
return ctrl->state == NVME_CTRL_RESETTING;
430+
}
431+
EXPORT_SYMBOL_GPL(nvme_wait_reset);
432+
394433
static void nvme_free_ns_head(struct kref *ref)
395434
{
396435
struct nvme_ns_head *head =
@@ -1306,8 +1345,6 @@ static void nvme_update_formats(struct nvme_ctrl *ctrl)
13061345
if (ns->disk && nvme_revalidate_disk(ns->disk))
13071346
nvme_set_queue_dying(ns);
13081347
up_read(&ctrl->namespaces_rwsem);
1309-
1310-
nvme_remove_invalid_namespaces(ctrl, NVME_NSID_ALL);
13111348
}
13121349

13131350
static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
@@ -1323,6 +1360,7 @@ static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
13231360
nvme_unfreeze(ctrl);
13241361
nvme_mpath_unfreeze(ctrl->subsys);
13251362
mutex_unlock(&ctrl->subsys->lock);
1363+
nvme_remove_invalid_namespaces(ctrl, NVME_NSID_ALL);
13261364
mutex_unlock(&ctrl->scan_lock);
13271365
}
13281366
if (effects & NVME_CMD_EFFECTS_CCC)
@@ -2874,7 +2912,6 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
28742912

28752913
switch (ctrl->state) {
28762914
case NVME_CTRL_LIVE:
2877-
case NVME_CTRL_ADMIN_ONLY:
28782915
break;
28792916
default:
28802917
return -EWOULDBLOCK;
@@ -3168,7 +3205,6 @@ static ssize_t nvme_sysfs_show_state(struct device *dev,
31683205
static const char *const state_name[] = {
31693206
[NVME_CTRL_NEW] = "new",
31703207
[NVME_CTRL_LIVE] = "live",
3171-
[NVME_CTRL_ADMIN_ONLY] = "only-admin",
31723208
[NVME_CTRL_RESETTING] = "resetting",
31733209
[NVME_CTRL_CONNECTING] = "connecting",
31743210
[NVME_CTRL_DELETING] = "deleting",
@@ -3679,11 +3715,10 @@ static void nvme_scan_work(struct work_struct *work)
36793715
struct nvme_id_ctrl *id;
36803716
unsigned nn;
36813717

3682-
if (ctrl->state != NVME_CTRL_LIVE)
3718+
/* No tagset on a live ctrl means IO queues could not created */
3719+
if (ctrl->state != NVME_CTRL_LIVE || !ctrl->tagset)
36833720
return;
36843721

3685-
WARN_ON_ONCE(!ctrl->tagset);
3686-
36873722
if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) {
36883723
dev_info(ctrl->device, "rescanning namespaces.\n");
36893724
nvme_clear_changed_ns_log(ctrl);
@@ -3844,13 +3879,13 @@ static void nvme_fw_act_work(struct work_struct *work)
38443879
if (time_after(jiffies, fw_act_timeout)) {
38453880
dev_warn(ctrl->device,
38463881
"Fw activation timeout, reset controller\n");
3847-
nvme_reset_ctrl(ctrl);
3848-
break;
3882+
nvme_try_sched_reset(ctrl);
3883+
return;
38493884
}
38503885
msleep(100);
38513886
}
38523887

3853-
if (ctrl->state != NVME_CTRL_LIVE)
3888+
if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE))
38543889
return;
38553890

38563891
nvme_start_queues(ctrl);
@@ -3870,7 +3905,13 @@ static void nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result)
38703905
nvme_queue_scan(ctrl);
38713906
break;
38723907
case NVME_AER_NOTICE_FW_ACT_STARTING:
3873-
queue_work(nvme_wq, &ctrl->fw_act_work);
3908+
/*
3909+
* We are (ab)using the RESETTING state to prevent subsequent
3910+
* recovery actions from interfering with the controller's
3911+
* firmware activation.
3912+
*/
3913+
if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING))
3914+
queue_work(nvme_wq, &ctrl->fw_act_work);
38743915
break;
38753916
#ifdef CONFIG_NVME_MULTIPATH
38763917
case NVME_AER_NOTICE_ANA:
@@ -3993,6 +4034,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
39934034
INIT_WORK(&ctrl->async_event_work, nvme_async_event_work);
39944035
INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work);
39954036
INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work);
4037+
init_waitqueue_head(&ctrl->state_wq);
39964038

39974039
INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work);
39984040
memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd));

drivers/nvme/host/fabrics.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
182182
static inline bool nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
183183
bool queue_live)
184184
{
185-
if (likely(ctrl->state == NVME_CTRL_LIVE ||
186-
ctrl->state == NVME_CTRL_ADMIN_ONLY))
185+
if (likely(ctrl->state == NVME_CTRL_LIVE))
187186
return true;
188187
return __nvmf_check_ready(ctrl, rq, queue_live);
189188
}

drivers/nvme/host/nvme.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/sed-opal.h>
1616
#include <linux/fault-inject.h>
1717
#include <linux/rcupdate.h>
18+
#include <linux/wait.h>
1819

1920
#include <trace/events/block.h>
2021

@@ -161,7 +162,6 @@ static inline u16 nvme_req_qid(struct request *req)
161162
enum nvme_ctrl_state {
162163
NVME_CTRL_NEW,
163164
NVME_CTRL_LIVE,
164-
NVME_CTRL_ADMIN_ONLY, /* Only admin queue live */
165165
NVME_CTRL_RESETTING,
166166
NVME_CTRL_CONNECTING,
167167
NVME_CTRL_DELETING,
@@ -199,6 +199,7 @@ struct nvme_ctrl {
199199
struct cdev cdev;
200200
struct work_struct reset_work;
201201
struct work_struct delete_work;
202+
wait_queue_head_t state_wq;
202203

203204
struct nvme_subsystem *subsys;
204205
struct list_head subsys_entry;
@@ -449,6 +450,7 @@ void nvme_complete_rq(struct request *req);
449450
bool nvme_cancel_request(struct request *req, void *data, bool reserved);
450451
bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
451452
enum nvme_ctrl_state new_state);
453+
bool nvme_wait_reset(struct nvme_ctrl *ctrl);
452454
int nvme_disable_ctrl(struct nvme_ctrl *ctrl);
453455
int nvme_enable_ctrl(struct nvme_ctrl *ctrl);
454456
int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl);
@@ -499,6 +501,7 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count);
499501
void nvme_stop_keep_alive(struct nvme_ctrl *ctrl);
500502
int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
501503
int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl);
504+
int nvme_try_sched_reset(struct nvme_ctrl *ctrl);
502505
int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
503506

504507
int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp,

0 commit comments

Comments
 (0)