nvme fixes for Linux 5.13

- fix a memory leak in nvme_cdev_add (Guoqing Jiang)
  - fix inline data size comparison in nvmet_tcp_queue_response (Hou Pu)
  - fix false keep-alive timeout when a controller is torn down
    (Sagi Grimberg)
  - fix a nvme-tcp Kconfig dependency (Sagi Grimberg)
  - short-circuit reconnect retries for FC (Hannes Reinecke)
  - decode host pathing error for connect (Hannes Reinecke)
 -----BEGIN PGP SIGNATURE-----
 
 iQI/BAABCgApFiEEgdbnc3r/njty3Iq9D55TZVIEUYMFAmCviQcLHGhjaEBsc3Qu
 ZGUACgkQD55TZVIEUYOl2BAAsFnUbt+2oYKzNldYHGewAv+v33uwtN88zCChbEXu
 6Saj0M5B4s9LbpyXdz2l8cb8CtmvSnFRjbHpdKny0E0qXGKp1YHbcTlefBiMeDPp
 YME543oAZ1rACafiLFwr/7Ys50Frtel9hNWty2Fgv8Q2eiyQRJnQvJHfwQ/Fk9g2
 swtVLbO83RwAef+kcLZaJojLeBlvW55vl/Srj5qj6tMPNl5DUgjUmioPTnFdo0ty
 6iEyAurXpcdbMIjYdgulbAypyQIvKyzcXgi0BVuxAbCV9DBKdrwP0ob/HDyYsNBX
 8sRUQnIfLketBKsIvuwhVcLr27HYHyDAHiGc70iG1ndrvdfkEKDP5BEwZxkNOA7d
 TbjvFanQIlvxkz419KIZo3SIdrG88DcYz5Ai0MxA8RuiKPJUE+Iksp8aCds/3dLR
 urfXHyHvj/O5US+xej0j5K63oVW7KPri3mbnFgfSHhmpg1KXBTmVk9a2Gz7ZyKIO
 XVHaq1kQHhvE0Kp1juZNqJ/ojd17wQP7bFIBGEHo6IPJtDILa0IQOw1S2aPX+/+q
 45dJqFxndco8oCyl81ynax9n+T3nA4DJs20a6j7fYbQnJpwKBiSKQsUbVWPybKzM
 rq+/7PlsGbjSsQwf1dTvhF04j/5HqTT5A+LUsLR6Jm7sPPYkws36PC7Cqr9sUxPX
 RYo=
 =JT0/
 -----END PGP SIGNATURE-----

Merge tag 'nvme-5.13-2021-05-27' of git://git.infradead.org/nvme into block-5.13

Pull NVMe fixes from Christoph:

"nvme fixes for Linux 5.13

 - fix a memory leak in nvme_cdev_add (Guoqing Jiang)
 - fix inline data size comparison in nvmet_tcp_queue_response (Hou Pu)
 - fix false keep-alive timeout when a controller is torn down
   (Sagi Grimberg)
 - fix a nvme-tcp Kconfig dependency (Sagi Grimberg)
 - short-circuit reconnect retries for FC (Hannes Reinecke)
 - decode host pathing error for connect (Hannes Reinecke)"

* tag 'nvme-5.13-2021-05-27' of git://git.infradead.org/nvme:
  nvmet: fix false keep-alive timeout when a controller is torn down
  nvmet-tcp: fix inline data size comparison in nvmet_tcp_queue_response
  nvme-tcp: remove incorrect Kconfig dep in BLK_DEV_NVME
  nvme-fabrics: decode host pathing error for connect
  nvme-fc: short-circuit reconnect retries
  nvme: fix potential memory leaks in nvme_cdev_add
This commit is contained in:
Jens Axboe 2021-05-27 07:38:12 -06:00
commit a4b58f1721
7 changed files with 40 additions and 16 deletions

View File

@ -71,7 +71,8 @@ config NVME_FC
config NVME_TCP
tristate "NVM Express over Fabrics TCP host driver"
depends on INET
depends on BLK_DEV_NVME
depends on BLOCK
select NVME_CORE
select NVME_FABRICS
select CRYPTO
select CRYPTO_CRC32C

View File

@ -3485,8 +3485,10 @@ int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
cdev_init(cdev, fops);
cdev->owner = owner;
ret = cdev_device_add(cdev, cdev_device);
if (ret)
if (ret) {
put_device(cdev_device);
ida_simple_remove(&nvme_ns_chr_minor_ida, minor);
}
return ret;
}

View File

@ -336,6 +336,11 @@ static void nvmf_log_connect_error(struct nvme_ctrl *ctrl,
cmd->connect.recfmt);
break;
case NVME_SC_HOST_PATH_ERROR:
dev_err(ctrl->device,
"Connect command failed: host path error\n");
break;
default:
dev_err(ctrl->device,
"Connect command failed, error wo/DNR bit: %d\n",

View File

@ -3107,6 +3107,7 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
if (ctrl->ctrl.icdoff) {
dev_err(ctrl->ctrl.device, "icdoff %d is not supported!\n",
ctrl->ctrl.icdoff);
ret = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
goto out_disconnect_admin_queue;
}
@ -3114,6 +3115,7 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
if (!(ctrl->ctrl.sgls & ((1 << 0) | (1 << 1)))) {
dev_err(ctrl->ctrl.device,
"Mandatory sgls are not supported!\n");
ret = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
goto out_disconnect_admin_queue;
}
@ -3280,11 +3282,13 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)
if (ctrl->ctrl.state != NVME_CTRL_CONNECTING)
return;
if (portptr->port_state == FC_OBJSTATE_ONLINE)
if (portptr->port_state == FC_OBJSTATE_ONLINE) {
dev_info(ctrl->ctrl.device,
"NVME-FC{%d}: reset: Reconnect attempt failed (%d)\n",
ctrl->cnum, status);
else if (time_after_eq(jiffies, rport->dev_loss_end))
if (status > 0 && (status & NVME_SC_DNR))
recon = false;
} else if (time_after_eq(jiffies, rport->dev_loss_end))
recon = false;
if (recon && nvmf_should_reconnect(&ctrl->ctrl)) {
@ -3298,12 +3302,17 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)
queue_delayed_work(nvme_wq, &ctrl->connect_work, recon_delay);
} else {
if (portptr->port_state == FC_OBJSTATE_ONLINE)
dev_warn(ctrl->ctrl.device,
"NVME-FC{%d}: Max reconnect attempts (%d) "
"reached.\n",
ctrl->cnum, ctrl->ctrl.nr_reconnects);
else
if (portptr->port_state == FC_OBJSTATE_ONLINE) {
if (status > 0 && (status & NVME_SC_DNR))
dev_warn(ctrl->ctrl.device,
"NVME-FC{%d}: reconnect failure\n",
ctrl->cnum);
else
dev_warn(ctrl->ctrl.device,
"NVME-FC{%d}: Max reconnect attempts "
"(%d) reached.\n",
ctrl->cnum, ctrl->ctrl.nr_reconnects);
} else
dev_warn(ctrl->ctrl.device,
"NVME-FC{%d}: dev_loss_tmo (%d) expired "
"while waiting for remoteport connectivity.\n",

View File

@ -388,10 +388,10 @@ static void nvmet_keep_alive_timer(struct work_struct *work)
{
struct nvmet_ctrl *ctrl = container_of(to_delayed_work(work),
struct nvmet_ctrl, ka_work);
bool cmd_seen = ctrl->cmd_seen;
bool reset_tbkas = ctrl->reset_tbkas;
ctrl->cmd_seen = false;
if (cmd_seen) {
ctrl->reset_tbkas = false;
if (reset_tbkas) {
pr_debug("ctrl %d reschedule traffic based keep-alive timer\n",
ctrl->cntlid);
schedule_delayed_work(&ctrl->ka_work, ctrl->kato * HZ);
@ -804,6 +804,13 @@ void nvmet_sq_destroy(struct nvmet_sq *sq)
percpu_ref_exit(&sq->ref);
if (ctrl) {
/*
* The teardown flow may take some time, and the host may not
* send us keep-alive during this period, hence reset the
* traffic based keep-alive timer so we don't trigger a
* controller teardown as a result of a keep-alive expiration.
*/
ctrl->reset_tbkas = true;
nvmet_ctrl_put(ctrl);
sq->ctrl = NULL; /* allows reusing the queue later */
}
@ -952,7 +959,7 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
}
if (sq->ctrl)
sq->ctrl->cmd_seen = true;
sq->ctrl->reset_tbkas = true;
return true;

View File

@ -167,7 +167,7 @@ struct nvmet_ctrl {
struct nvmet_subsys *subsys;
struct nvmet_sq **sqs;
bool cmd_seen;
bool reset_tbkas;
struct mutex lock;
u64 cap;

View File

@ -550,7 +550,7 @@ static void nvmet_tcp_queue_response(struct nvmet_req *req)
* nvmet_req_init is completed.
*/
if (queue->rcv_state == NVMET_TCP_RECV_PDU &&
len && len < cmd->req.port->inline_data_size &&
len && len <= cmd->req.port->inline_data_size &&
nvme_is_write(cmd->req.cmd))
return;
}