Skip to content

Commit 6bdf2fb

Browse files
committed
Merge tag 'nvme-5.13-2021-05-13' of git://git.infradead.org/nvme into block-5.13
Pull NVMe fixes from Christoph: "nvme fix for Linux 5.13 - correct the check for using the inline bio in nvmet (Chaitanya Kulkarni) - demote unsupported command warnings (Chaitanya Kulkarni) - fix corruption due to double initializing ANA state (me, Hou Pu) - reset ns->file when open fails (Daniel Wagner) - fix a NULL deref when SEND is completed with error in nvmet-rdma (Michal Kalderon)" * tag 'nvme-5.13-2021-05-13' of git://git.infradead.org/nvme: nvmet: use new ana_log_size instead the old one nvmet: seset ns->file when open fails nvmet: demote fabrics cmd parse err msg to debug nvmet: use helper to remove the duplicate code nvmet: demote discovery cmd parse err msg to debug nvmet-rdma: Fix NULL deref when SEND is completed with error nvmet: fix inline bio check for passthru nvmet: fix inline bio check for bdev-ns nvme-multipath: fix double initialization of ANA state
2 parents bedf78c + e181811 commit 6bdf2fb

File tree

11 files changed

+58
-45
lines changed

11 files changed

+58
-45
lines changed

drivers/nvme/host/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2901,7 +2901,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
29012901
ctrl->hmmaxd = le16_to_cpu(id->hmmaxd);
29022902
}
29032903

2904-
ret = nvme_mpath_init(ctrl, id);
2904+
ret = nvme_mpath_init_identify(ctrl, id);
29052905
if (ret < 0)
29062906
goto out_free;
29072907

@@ -4364,6 +4364,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
43644364
min(default_ps_max_latency_us, (unsigned long)S32_MAX));
43654365

43664366
nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device));
4367+
nvme_mpath_init_ctrl(ctrl);
43674368

43684369
return 0;
43694370
out_free_name:

drivers/nvme/host/multipath.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,18 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
781781
put_disk(head->disk);
782782
}
783783

784-
int nvme_mpath_init(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
784+
void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl)
785785
{
786-
int error;
786+
mutex_init(&ctrl->ana_lock);
787+
timer_setup(&ctrl->anatt_timer, nvme_anatt_timeout, 0);
788+
INIT_WORK(&ctrl->ana_work, nvme_ana_work);
789+
}
790+
791+
int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
792+
{
793+
size_t max_transfer_size = ctrl->max_hw_sectors << SECTOR_SHIFT;
794+
size_t ana_log_size;
795+
int error = 0;
787796

788797
/* check if multipath is enabled and we have the capability */
789798
if (!multipath || !ctrl->subsys ||
@@ -795,37 +804,31 @@ int nvme_mpath_init(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
795804
ctrl->nanagrpid = le32_to_cpu(id->nanagrpid);
796805
ctrl->anagrpmax = le32_to_cpu(id->anagrpmax);
797806

798-
mutex_init(&ctrl->ana_lock);
799-
timer_setup(&ctrl->anatt_timer, nvme_anatt_timeout, 0);
800-
ctrl->ana_log_size = sizeof(struct nvme_ana_rsp_hdr) +
801-
ctrl->nanagrpid * sizeof(struct nvme_ana_group_desc);
802-
ctrl->ana_log_size += ctrl->max_namespaces * sizeof(__le32);
803-
804-
if (ctrl->ana_log_size > ctrl->max_hw_sectors << SECTOR_SHIFT) {
807+
ana_log_size = sizeof(struct nvme_ana_rsp_hdr) +
808+
ctrl->nanagrpid * sizeof(struct nvme_ana_group_desc) +
809+
ctrl->max_namespaces * sizeof(__le32);
810+
if (ana_log_size > max_transfer_size) {
805811
dev_err(ctrl->device,
806-
"ANA log page size (%zd) larger than MDTS (%d).\n",
807-
ctrl->ana_log_size,
808-
ctrl->max_hw_sectors << SECTOR_SHIFT);
812+
"ANA log page size (%zd) larger than MDTS (%zd).\n",
813+
ana_log_size, max_transfer_size);
809814
dev_err(ctrl->device, "disabling ANA support.\n");
810-
return 0;
815+
goto out_uninit;
811816
}
812-
813-
INIT_WORK(&ctrl->ana_work, nvme_ana_work);
814-
kfree(ctrl->ana_log_buf);
815-
ctrl->ana_log_buf = kmalloc(ctrl->ana_log_size, GFP_KERNEL);
816-
if (!ctrl->ana_log_buf) {
817-
error = -ENOMEM;
818-
goto out;
817+
if (ana_log_size > ctrl->ana_log_size) {
818+
nvme_mpath_stop(ctrl);
819+
kfree(ctrl->ana_log_buf);
820+
ctrl->ana_log_buf = kmalloc(ana_log_size, GFP_KERNEL);
821+
if (!ctrl->ana_log_buf)
822+
return -ENOMEM;
819823
}
820-
824+
ctrl->ana_log_size = ana_log_size;
821825
error = nvme_read_ana_log(ctrl);
822826
if (error)
823-
goto out_free_ana_log_buf;
827+
goto out_uninit;
824828
return 0;
825-
out_free_ana_log_buf:
826-
kfree(ctrl->ana_log_buf);
827-
ctrl->ana_log_buf = NULL;
828-
out:
829+
830+
out_uninit:
831+
nvme_mpath_uninit(ctrl);
829832
return error;
830833
}
831834

drivers/nvme/host/nvme.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,8 @@ void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
712712
int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head);
713713
void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id);
714714
void nvme_mpath_remove_disk(struct nvme_ns_head *head);
715-
int nvme_mpath_init(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id);
715+
int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id);
716+
void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl);
716717
void nvme_mpath_uninit(struct nvme_ctrl *ctrl);
717718
void nvme_mpath_stop(struct nvme_ctrl *ctrl);
718719
bool nvme_mpath_clear_current_path(struct nvme_ns *ns);
@@ -780,7 +781,10 @@ static inline void nvme_mpath_check_last_path(struct nvme_ns *ns)
780781
static inline void nvme_trace_bio_complete(struct request *req)
781782
{
782783
}
783-
static inline int nvme_mpath_init(struct nvme_ctrl *ctrl,
784+
static inline void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl)
785+
{
786+
}
787+
static inline int nvme_mpath_init_identify(struct nvme_ctrl *ctrl,
784788
struct nvme_id_ctrl *id)
785789
{
786790
if (ctrl->subsys->cmic & NVME_CTRL_CMIC_ANA)

drivers/nvme/target/admin-cmd.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,7 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)
975975
case nvme_admin_keep_alive:
976976
req->execute = nvmet_execute_keep_alive;
977977
return 0;
978+
default:
979+
return nvmet_report_invalid_opcode(req);
978980
}
979-
980-
pr_debug("unhandled cmd %d on qid %d\n", cmd->common.opcode,
981-
req->sq->qid);
982-
req->error_loc = offsetof(struct nvme_common_command, opcode);
983-
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
984981
}

drivers/nvme/target/discovery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)
379379
req->execute = nvmet_execute_disc_identify;
380380
return 0;
381381
default:
382-
pr_err("unhandled cmd %d\n", cmd->common.opcode);
382+
pr_debug("unhandled cmd %d\n", cmd->common.opcode);
383383
req->error_loc = offsetof(struct nvme_common_command, opcode);
384384
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
385385
}

drivers/nvme/target/fabrics-cmd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ u16 nvmet_parse_fabrics_cmd(struct nvmet_req *req)
9494
req->execute = nvmet_execute_prop_get;
9595
break;
9696
default:
97-
pr_err("received unknown capsule type 0x%x\n",
97+
pr_debug("received unknown capsule type 0x%x\n",
9898
cmd->fabrics.fctype);
9999
req->error_loc = offsetof(struct nvmf_common_command, fctype);
100100
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
@@ -284,13 +284,13 @@ u16 nvmet_parse_connect_cmd(struct nvmet_req *req)
284284
struct nvme_command *cmd = req->cmd;
285285

286286
if (!nvme_is_fabrics(cmd)) {
287-
pr_err("invalid command 0x%x on unconnected queue.\n",
287+
pr_debug("invalid command 0x%x on unconnected queue.\n",
288288
cmd->fabrics.opcode);
289289
req->error_loc = offsetof(struct nvme_common_command, opcode);
290290
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
291291
}
292292
if (cmd->fabrics.fctype != nvme_fabrics_type_connect) {
293-
pr_err("invalid capsule type 0x%x on unconnected queue.\n",
293+
pr_debug("invalid capsule type 0x%x on unconnected queue.\n",
294294
cmd->fabrics.fctype);
295295
req->error_loc = offsetof(struct nvmf_common_command, fctype);
296296
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;

drivers/nvme/target/io-cmd-bdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
258258

259259
sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba);
260260

261-
if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) {
261+
if (nvmet_use_inline_bvec(req)) {
262262
bio = &req->b.inline_bio;
263263
bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec));
264264
} else {

drivers/nvme/target/io-cmd-file.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
4949

5050
ns->file = filp_open(ns->device_path, flags, 0);
5151
if (IS_ERR(ns->file)) {
52-
pr_err("failed to open file %s: (%ld)\n",
53-
ns->device_path, PTR_ERR(ns->file));
54-
return PTR_ERR(ns->file);
52+
ret = PTR_ERR(ns->file);
53+
pr_err("failed to open file %s: (%d)\n",
54+
ns->device_path, ret);
55+
ns->file = NULL;
56+
return ret;
5557
}
5658

5759
ret = nvmet_file_ns_revalidate(ns);

drivers/nvme/target/nvmet.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,10 @@ static inline sector_t nvmet_lba_to_sect(struct nvmet_ns *ns, __le64 lba)
616616
return le64_to_cpu(lba) << (ns->blksize_shift - SECTOR_SHIFT);
617617
}
618618

619+
static inline bool nvmet_use_inline_bvec(struct nvmet_req *req)
620+
{
621+
return req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN &&
622+
req->sg_cnt <= NVMET_MAX_INLINE_BIOVEC;
623+
}
624+
619625
#endif /* _NVMET_H */

drivers/nvme/target/passthru.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
194194
if (req->sg_cnt > BIO_MAX_VECS)
195195
return -EINVAL;
196196

197-
if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) {
197+
if (nvmet_use_inline_bvec(req)) {
198198
bio = &req->p.inline_bio;
199199
bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec));
200200
} else {

0 commit comments

Comments
 (0)