Skip to content

Commit 3735816

Browse files
committed
Merge tag 'nvme-6.8-2024-02-01' of git://git.infradead.org/nvme into block-6.8
Pull NVMe fixes from Keith: "nvme fixes for Linux 6.8 - Remove duplicated enums (Guixen) - Use appropriate controller state accessors (Keith) - Retryable authentication (Hannes) - Add missing module descriptions (Chaitanya) - Fibre-channel fixes for blktests (Daniel) - Various type correctness updates (Caleb) - Improve fabrics connection debugging prints (Nitin) - Passthrough command verbose error logging (Adam)" * tag 'nvme-6.8-2024-02-01' of git://git.infradead.org/nvme: (31 commits) nvme: allow passthru cmd error logging nvme-fc: show hostnqn when connecting to fc target nvme-rdma: show hostnqn when connecting to rdma target nvme-tcp: show hostnqn when connecting to tcp target nvmet-fc: use RCU list iterator for assoc_list nvmet-fc: take ref count on tgtport before delete assoc nvmet-fc: avoid deadlock on delete association path nvmet-fc: abort command when there is no binding nvmet-fc: do not tack refs on tgtports from assoc nvmet-fc: remove null hostport pointer check nvmet-fc: hold reference on hostport match nvmet-fc: free queue and assoc directly nvmet-fc: defer cleanup using RCU properly nvmet-fc: release reference on target port nvmet-fcloop: swap the list_add_tail arguments nvme-fc: do not wait in vain when unloading module nvme-fc: log human-readable opcode on timeout nvme: split out fabrics version of nvme_opcode_str() nvme: take const cmd pointer in read-only helpers nvme: remove redundant status mask ...
2 parents 5af2c3f + 9f079dd commit 3735816

File tree

23 files changed

+380
-236
lines changed

23 files changed

+380
-236
lines changed

drivers/nvme/common/auth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,5 @@ int nvme_auth_generate_key(u8 *secret, struct nvme_dhchap_key **ret_key)
471471
}
472472
EXPORT_SYMBOL_GPL(nvme_auth_generate_key);
473473

474+
MODULE_DESCRIPTION("NVMe Authentication framework");
474475
MODULE_LICENSE("GPL v2");

drivers/nvme/common/keyring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,6 @@ static void __exit nvme_keyring_exit(void)
181181

182182
MODULE_LICENSE("GPL v2");
183183
MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
184+
MODULE_DESCRIPTION("NVMe Keyring implementation");
184185
module_init(nvme_keyring_init);
185186
module_exit(nvme_keyring_exit);

drivers/nvme/host/apple.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ static int apple_nvme_init_request(struct blk_mq_tag_set *set,
797797

798798
static void apple_nvme_disable(struct apple_nvme *anv, bool shutdown)
799799
{
800+
enum nvme_ctrl_state state = nvme_ctrl_state(&anv->ctrl);
800801
u32 csts = readl(anv->mmio_nvme + NVME_REG_CSTS);
801802
bool dead = false, freeze = false;
802803
unsigned long flags;
@@ -808,8 +809,8 @@ static void apple_nvme_disable(struct apple_nvme *anv, bool shutdown)
808809
if (csts & NVME_CSTS_CFS)
809810
dead = true;
810811

811-
if (anv->ctrl.state == NVME_CTRL_LIVE ||
812-
anv->ctrl.state == NVME_CTRL_RESETTING) {
812+
if (state == NVME_CTRL_LIVE ||
813+
state == NVME_CTRL_RESETTING) {
813814
freeze = true;
814815
nvme_start_freeze(&anv->ctrl);
815816
}
@@ -881,7 +882,7 @@ static enum blk_eh_timer_return apple_nvme_timeout(struct request *req)
881882
unsigned long flags;
882883
u32 csts = readl(anv->mmio_nvme + NVME_REG_CSTS);
883884

884-
if (anv->ctrl.state != NVME_CTRL_LIVE) {
885+
if (nvme_ctrl_state(&anv->ctrl) != NVME_CTRL_LIVE) {
885886
/*
886887
* From rdma.c:
887888
* If we are resetting, connecting or deleting we should
@@ -985,10 +986,10 @@ static void apple_nvme_reset_work(struct work_struct *work)
985986
u32 boot_status, aqa;
986987
struct apple_nvme *anv =
987988
container_of(work, struct apple_nvme, ctrl.reset_work);
989+
enum nvme_ctrl_state state = nvme_ctrl_state(&anv->ctrl);
988990

989-
if (anv->ctrl.state != NVME_CTRL_RESETTING) {
990-
dev_warn(anv->dev, "ctrl state %d is not RESETTING\n",
991-
anv->ctrl.state);
991+
if (state != NVME_CTRL_RESETTING) {
992+
dev_warn(anv->dev, "ctrl state %d is not RESETTING\n", state);
992993
ret = -ENODEV;
993994
goto out;
994995
}

drivers/nvme/host/auth.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ struct nvme_dhchap_queue_context {
4848

4949
static struct workqueue_struct *nvme_auth_wq;
5050

51-
#define nvme_auth_flags_from_qid(qid) \
52-
(qid == 0) ? 0 : BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED
53-
#define nvme_auth_queue_from_qid(ctrl, qid) \
54-
(qid == 0) ? (ctrl)->fabrics_q : (ctrl)->connect_q
55-
5651
static inline int ctrl_max_dhchaps(struct nvme_ctrl *ctrl)
5752
{
5853
return ctrl->opts->nr_io_queues + ctrl->opts->nr_write_queues +
@@ -63,10 +58,15 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
6358
void *data, size_t data_len, bool auth_send)
6459
{
6560
struct nvme_command cmd = {};
66-
blk_mq_req_flags_t flags = nvme_auth_flags_from_qid(qid);
67-
struct request_queue *q = nvme_auth_queue_from_qid(ctrl, qid);
61+
nvme_submit_flags_t flags = NVME_SUBMIT_RETRY;
62+
struct request_queue *q = ctrl->fabrics_q;
6863
int ret;
6964

65+
if (qid != 0) {
66+
flags |= NVME_SUBMIT_NOWAIT | NVME_SUBMIT_RESERVED;
67+
q = ctrl->connect_q;
68+
}
69+
7070
cmd.auth_common.opcode = nvme_fabrics_command;
7171
cmd.auth_common.secp = NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER;
7272
cmd.auth_common.spsp0 = 0x01;
@@ -80,8 +80,7 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
8080
}
8181

8282
ret = __nvme_submit_sync_cmd(q, &cmd, NULL, data, data_len,
83-
qid == 0 ? NVME_QID_ANY : qid,
84-
0, flags);
83+
qid == 0 ? NVME_QID_ANY : qid, flags);
8584
if (ret > 0)
8685
dev_warn(ctrl->device,
8786
"qid %d auth_send failed with status %d\n", qid, ret);
@@ -897,7 +896,7 @@ static void nvme_ctrl_auth_work(struct work_struct *work)
897896
* If the ctrl is no connected, bail as reconnect will handle
898897
* authentication.
899898
*/
900-
if (ctrl->state != NVME_CTRL_LIVE)
899+
if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE)
901900
return;
902901

903902
/* Authenticate admin queue first */

drivers/nvme/host/constants.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,31 +171,31 @@ static const char * const nvme_statuses[] = {
171171
[NVME_SC_HOST_ABORTED_CMD] = "Host Aborted Command",
172172
};
173173

174-
const unsigned char *nvme_get_error_status_str(u16 status)
174+
const char *nvme_get_error_status_str(u16 status)
175175
{
176176
status &= 0x7ff;
177177
if (status < ARRAY_SIZE(nvme_statuses) && nvme_statuses[status])
178-
return nvme_statuses[status & 0x7ff];
178+
return nvme_statuses[status];
179179
return "Unknown";
180180
}
181181

182-
const unsigned char *nvme_get_opcode_str(u8 opcode)
182+
const char *nvme_get_opcode_str(u8 opcode)
183183
{
184184
if (opcode < ARRAY_SIZE(nvme_ops) && nvme_ops[opcode])
185185
return nvme_ops[opcode];
186186
return "Unknown";
187187
}
188188
EXPORT_SYMBOL_GPL(nvme_get_opcode_str);
189189

190-
const unsigned char *nvme_get_admin_opcode_str(u8 opcode)
190+
const char *nvme_get_admin_opcode_str(u8 opcode)
191191
{
192192
if (opcode < ARRAY_SIZE(nvme_admin_ops) && nvme_admin_ops[opcode])
193193
return nvme_admin_ops[opcode];
194194
return "Unknown";
195195
}
196196
EXPORT_SYMBOL_GPL(nvme_get_admin_opcode_str);
197197

198-
const unsigned char *nvme_get_fabrics_opcode_str(u8 opcode) {
198+
const char *nvme_get_fabrics_opcode_str(u8 opcode) {
199199
if (opcode < ARRAY_SIZE(nvme_fabrics_ops) && nvme_fabrics_ops[opcode])
200200
return nvme_fabrics_ops[opcode];
201201
return "Unknown";

drivers/nvme/host/core.c

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,30 @@ static void nvme_log_error(struct request *req)
338338
nr->status & NVME_SC_DNR ? "DNR " : "");
339339
}
340340

341+
static void nvme_log_err_passthru(struct request *req)
342+
{
343+
struct nvme_ns *ns = req->q->queuedata;
344+
struct nvme_request *nr = nvme_req(req);
345+
346+
pr_err_ratelimited("%s: %s(0x%x), %s (sct 0x%x / sc 0x%x) %s%s"
347+
"cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\n",
348+
ns ? ns->disk->disk_name : dev_name(nr->ctrl->device),
349+
ns ? nvme_get_opcode_str(nr->cmd->common.opcode) :
350+
nvme_get_admin_opcode_str(nr->cmd->common.opcode),
351+
nr->cmd->common.opcode,
352+
nvme_get_error_status_str(nr->status),
353+
nr->status >> 8 & 7, /* Status Code Type */
354+
nr->status & 0xff, /* Status Code */
355+
nr->status & NVME_SC_MORE ? "MORE " : "",
356+
nr->status & NVME_SC_DNR ? "DNR " : "",
357+
nr->cmd->common.cdw10,
358+
nr->cmd->common.cdw11,
359+
nr->cmd->common.cdw12,
360+
nr->cmd->common.cdw13,
361+
nr->cmd->common.cdw14,
362+
nr->cmd->common.cdw14);
363+
}
364+
341365
enum nvme_disposition {
342366
COMPLETE,
343367
RETRY,
@@ -385,8 +409,12 @@ static inline void nvme_end_req(struct request *req)
385409
{
386410
blk_status_t status = nvme_error_status(nvme_req(req)->status);
387411

388-
if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET)))
389-
nvme_log_error(req);
412+
if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET))) {
413+
if (blk_rq_is_passthrough(req))
414+
nvme_log_err_passthru(req);
415+
else
416+
nvme_log_error(req);
417+
}
390418
nvme_end_req_zoned(req);
391419
nvme_trace_bio_complete(req);
392420
if (req->cmd_flags & REQ_NVME_MPATH)
@@ -679,10 +707,21 @@ static inline void nvme_clear_nvme_request(struct request *req)
679707
/* initialize a passthrough request */
680708
void nvme_init_request(struct request *req, struct nvme_command *cmd)
681709
{
682-
if (req->q->queuedata)
710+
struct nvme_request *nr = nvme_req(req);
711+
bool logging_enabled;
712+
713+
if (req->q->queuedata) {
714+
struct nvme_ns *ns = req->q->disk->private_data;
715+
716+
logging_enabled = ns->passthru_err_log_enabled;
683717
req->timeout = NVME_IO_TIMEOUT;
684-
else /* no queuedata implies admin queue */
718+
} else { /* no queuedata implies admin queue */
719+
logging_enabled = nr->ctrl->passthru_err_log_enabled;
685720
req->timeout = NVME_ADMIN_TIMEOUT;
721+
}
722+
723+
if (!logging_enabled)
724+
req->rq_flags |= RQF_QUIET;
686725

687726
/* passthru commands should let the driver set the SGL flags */
688727
cmd->common.flags &= ~NVME_CMD_SGL_ALL;
@@ -691,8 +730,7 @@ void nvme_init_request(struct request *req, struct nvme_command *cmd)
691730
if (req->mq_hctx->type == HCTX_TYPE_POLL)
692731
req->cmd_flags |= REQ_POLLED;
693732
nvme_clear_nvme_request(req);
694-
req->rq_flags |= RQF_QUIET;
695-
memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd));
733+
memcpy(nr->cmd, cmd, sizeof(*cmd));
696734
}
697735
EXPORT_SYMBOL_GPL(nvme_init_request);
698736

@@ -721,7 +759,7 @@ blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
721759
EXPORT_SYMBOL_GPL(nvme_fail_nonready_command);
722760

723761
bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
724-
bool queue_live)
762+
bool queue_live, enum nvme_ctrl_state state)
725763
{
726764
struct nvme_request *req = nvme_req(rq);
727765

@@ -742,7 +780,7 @@ bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
742780
* command, which is require to set the queue live in the
743781
* appropinquate states.
744782
*/
745-
switch (nvme_ctrl_state(ctrl)) {
783+
switch (state) {
746784
case NVME_CTRL_CONNECTING:
747785
if (blk_rq_is_passthrough(rq) && nvme_is_fabrics(req->cmd) &&
748786
(req->cmd->fabrics.fctype == nvme_fabrics_type_connect ||
@@ -1051,28 +1089,35 @@ EXPORT_SYMBOL_NS_GPL(nvme_execute_rq, NVME_TARGET_PASSTHRU);
10511089
*/
10521090
int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
10531091
union nvme_result *result, void *buffer, unsigned bufflen,
1054-
int qid, int at_head, blk_mq_req_flags_t flags)
1092+
int qid, nvme_submit_flags_t flags)
10551093
{
10561094
struct request *req;
10571095
int ret;
1096+
blk_mq_req_flags_t blk_flags = 0;
10581097

1098+
if (flags & NVME_SUBMIT_NOWAIT)
1099+
blk_flags |= BLK_MQ_REQ_NOWAIT;
1100+
if (flags & NVME_SUBMIT_RESERVED)
1101+
blk_flags |= BLK_MQ_REQ_RESERVED;
10591102
if (qid == NVME_QID_ANY)
1060-
req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
1103+
req = blk_mq_alloc_request(q, nvme_req_op(cmd), blk_flags);
10611104
else
1062-
req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
1105+
req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), blk_flags,
10631106
qid - 1);
10641107

10651108
if (IS_ERR(req))
10661109
return PTR_ERR(req);
10671110
nvme_init_request(req, cmd);
1111+
if (flags & NVME_SUBMIT_RETRY)
1112+
req->cmd_flags &= ~REQ_FAILFAST_DRIVER;
10681113

10691114
if (buffer && bufflen) {
10701115
ret = blk_rq_map_kern(q, req, buffer, bufflen, GFP_KERNEL);
10711116
if (ret)
10721117
goto out;
10731118
}
10741119

1075-
ret = nvme_execute_rq(req, at_head);
1120+
ret = nvme_execute_rq(req, flags & NVME_SUBMIT_AT_HEAD);
10761121
if (result && ret >= 0)
10771122
*result = nvme_req(req)->result;
10781123
out:
@@ -1085,7 +1130,7 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
10851130
void *buffer, unsigned bufflen)
10861131
{
10871132
return __nvme_submit_sync_cmd(q, cmd, NULL, buffer, bufflen,
1088-
NVME_QID_ANY, 0, 0);
1133+
NVME_QID_ANY, 0);
10891134
}
10901135
EXPORT_SYMBOL_GPL(nvme_submit_sync_cmd);
10911136

@@ -1560,7 +1605,7 @@ static int nvme_features(struct nvme_ctrl *dev, u8 op, unsigned int fid,
15601605
c.features.dword11 = cpu_to_le32(dword11);
15611606

15621607
ret = __nvme_submit_sync_cmd(dev->admin_q, &c, &res,
1563-
buffer, buflen, NVME_QID_ANY, 0, 0);
1608+
buffer, buflen, NVME_QID_ANY, 0);
15641609
if (ret >= 0 && result)
15651610
*result = le32_to_cpu(res.u32);
15661611
return ret;
@@ -2172,7 +2217,7 @@ static int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t l
21722217
cmd.common.cdw11 = cpu_to_le32(len);
21732218

21742219
return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len,
2175-
NVME_QID_ANY, 1, 0);
2220+
NVME_QID_ANY, NVME_SUBMIT_AT_HEAD);
21762221
}
21772222

21782223
static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended)
@@ -3651,6 +3696,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
36513696

36523697
ns->disk = disk;
36533698
ns->queue = disk->queue;
3699+
ns->passthru_err_log_enabled = false;
36543700

36553701
if (ctrl->opts && ctrl->opts->data_digest)
36563702
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, ns->queue);
@@ -3714,6 +3760,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
37143760
nvme_mpath_add_disk(ns, info->anagrpid);
37153761
nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name);
37163762

3763+
/*
3764+
* Set ns->disk->device->driver_data to ns so we can access
3765+
* ns->logging_enabled in nvme_passthru_err_log_enabled_store() and
3766+
* nvme_passthru_err_log_enabled_show().
3767+
*/
3768+
dev_set_drvdata(disk_to_dev(ns->disk), ns);
3769+
37173770
return;
37183771

37193772
out_cleanup_ns_from_list:
@@ -4514,6 +4567,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
45144567
int ret;
45154568

45164569
WRITE_ONCE(ctrl->state, NVME_CTRL_NEW);
4570+
ctrl->passthru_err_log_enabled = false;
45174571
clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags);
45184572
spin_lock_init(&ctrl->lock);
45194573
mutex_init(&ctrl->scan_lock);
@@ -4851,5 +4905,6 @@ static void __exit nvme_core_exit(void)
48514905

48524906
MODULE_LICENSE("GPL");
48534907
MODULE_VERSION("1.0");
4908+
MODULE_DESCRIPTION("NVMe host core framework");
48544909
module_init(nvme_core_init);
48554910
module_exit(nvme_core_exit);

0 commit comments

Comments
 (0)