Merge tag 'nvme-6.4-2023-06-01' of git://git.infradead.org/nvme into block-6.4

Pull NVMe fixes from Keith:

"nvme fixes for Linux 6.4

- Fixes for spurious Keep Alive timeouts (Uday)
- Fix for command type check on passthrough actions (Min)
- Fix for nvme command name for error logging (Christoph)"

* tag 'nvme-6.4-2023-06-01' of git://git.infradead.org/nvme:
nvme: fix the name of Zone Append for verbose logging
nvme: improve handling of long keep alives
nvme: check IO start time when deciding to defer KA
nvme: double KA polling frequency to avoid KATO with TBKAS on
nvme: fix miss command type check

+53 -8
+1 -1
drivers/nvme/host/constants.c
··· 21 [nvme_cmd_resv_release] = "Reservation Release", 22 [nvme_cmd_zone_mgmt_send] = "Zone Management Send", 23 [nvme_cmd_zone_mgmt_recv] = "Zone Management Receive", 24 - [nvme_cmd_zone_append] = "Zone Management Append", 25 }; 26 27 static const char * const nvme_admin_ops[] = {
··· 21 [nvme_cmd_resv_release] = "Reservation Release", 22 [nvme_cmd_zone_mgmt_send] = "Zone Management Send", 23 [nvme_cmd_zone_mgmt_recv] = "Zone Management Receive", 24 + [nvme_cmd_zone_append] = "Zone Append", 25 }; 26 27 static const char * const nvme_admin_ops[] = {
+48 -4
drivers/nvme/host/core.c
··· 397 trace_nvme_complete_rq(req); 398 nvme_cleanup_cmd(req); 399 400 - if (ctrl->kas) 401 ctrl->comp_seen = true; 402 403 switch (nvme_decide_disposition(req)) { ··· 1124 } 1125 EXPORT_SYMBOL_NS_GPL(nvme_passthru_start, NVME_TARGET_PASSTHRU); 1126 1127 - void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects, 1128 struct nvme_command *cmd, int status) 1129 { 1130 if (effects & NVME_CMD_EFFECTS_CSE_MASK) { ··· 1141 nvme_queue_scan(ctrl); 1142 flush_work(&ctrl->scan_work); 1143 } 1144 1145 switch (cmd->common.opcode) { 1146 case nvme_admin_set_features: ··· 1172 * The host should send Keep Alive commands at half of the Keep Alive Timeout 1173 * accounting for transport roundtrip times [..]. 1174 */ 1175 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) 1176 { 1177 - queue_delayed_work(nvme_wq, &ctrl->ka_work, ctrl->kato * HZ / 2); 1178 } 1179 1180 static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq, ··· 1199 struct nvme_ctrl *ctrl = rq->end_io_data; 1200 unsigned long flags; 1201 bool startka = false; 1202 1203 blk_mq_free_request(rq); 1204 ··· 1223 return RQ_END_IO_NONE; 1224 } 1225 1226 ctrl->comp_seen = false; 1227 spin_lock_irqsave(&ctrl->lock, flags); 1228 if (ctrl->state == NVME_CTRL_LIVE || ··· 1231 startka = true; 1232 spin_unlock_irqrestore(&ctrl->lock, flags); 1233 if (startka) 1234 - nvme_queue_keep_alive_work(ctrl); 1235 return RQ_END_IO_NONE; 1236 } 1237 ··· 1241 struct nvme_ctrl, ka_work); 1242 bool comp_seen = ctrl->comp_seen; 1243 struct request *rq; 1244 1245 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { 1246 dev_dbg(ctrl->device,
··· 397 trace_nvme_complete_rq(req); 398 nvme_cleanup_cmd(req); 399 400 + /* 401 + * Completions of long-running commands should not be able to 402 + * defer sending of periodic keep alives, since the controller 403 + * may have completed processing such commands a long time ago 404 + * (arbitrarily close to command submission time). 405 + * req->deadline - req->timeout is the command submission time 406 + * in jiffies. 407 + */ 408 + if (ctrl->kas && 409 + req->deadline - req->timeout >= ctrl->ka_last_check_time) 410 ctrl->comp_seen = true; 411 412 switch (nvme_decide_disposition(req)) { ··· 1115 } 1116 EXPORT_SYMBOL_NS_GPL(nvme_passthru_start, NVME_TARGET_PASSTHRU); 1117 1118 + void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, 1119 struct nvme_command *cmd, int status) 1120 { 1121 if (effects & NVME_CMD_EFFECTS_CSE_MASK) { ··· 1132 nvme_queue_scan(ctrl); 1133 flush_work(&ctrl->scan_work); 1134 } 1135 + if (ns) 1136 + return; 1137 1138 switch (cmd->common.opcode) { 1139 case nvme_admin_set_features: ··· 1161 * The host should send Keep Alive commands at half of the Keep Alive Timeout 1162 * accounting for transport roundtrip times [..]. 1163 */ 1164 + static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl) 1165 + { 1166 + unsigned long delay = ctrl->kato * HZ / 2; 1167 + 1168 + /* 1169 + * When using Traffic Based Keep Alive, we need to run 1170 + * nvme_keep_alive_work at twice the normal frequency, as one 1171 + * command completion can postpone sending a keep alive command 1172 + * by up to twice the delay between runs. 1173 + */ 1174 + if (ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) 1175 + delay /= 2; 1176 + return delay; 1177 + } 1178 + 1179 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) 1180 { 1181 + queue_delayed_work(nvme_wq, &ctrl->ka_work, 1182 + nvme_keep_alive_work_period(ctrl)); 1183 } 1184 1185 static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq, ··· 1172 struct nvme_ctrl *ctrl = rq->end_io_data; 1173 unsigned long flags; 1174 bool startka = false; 1175 + unsigned long rtt = jiffies - (rq->deadline - rq->timeout); 1176 + unsigned long delay = nvme_keep_alive_work_period(ctrl); 1177 + 1178 + /* 1179 + * Subtract off the keepalive RTT so nvme_keep_alive_work runs 1180 + * at the desired frequency. 1181 + */ 1182 + if (rtt <= delay) { 1183 + delay -= rtt; 1184 + } else { 1185 + dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n", 1186 + jiffies_to_msecs(rtt)); 1187 + delay = 0; 1188 + } 1189 1190 blk_mq_free_request(rq); 1191 ··· 1182 return RQ_END_IO_NONE; 1183 } 1184 1185 + ctrl->ka_last_check_time = jiffies; 1186 ctrl->comp_seen = false; 1187 spin_lock_irqsave(&ctrl->lock, flags); 1188 if (ctrl->state == NVME_CTRL_LIVE || ··· 1189 startka = true; 1190 spin_unlock_irqrestore(&ctrl->lock, flags); 1191 if (startka) 1192 + queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); 1193 return RQ_END_IO_NONE; 1194 } 1195 ··· 1199 struct nvme_ctrl, ka_work); 1200 bool comp_seen = ctrl->comp_seen; 1201 struct request *rq; 1202 + 1203 + ctrl->ka_last_check_time = jiffies; 1204 1205 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { 1206 dev_dbg(ctrl->device,
+1 -1
drivers/nvme/host/ioctl.c
··· 254 blk_mq_free_request(req); 255 256 if (effects) 257 - nvme_passthru_end(ctrl, effects, cmd, ret); 258 259 return ret; 260 }
··· 254 blk_mq_free_request(req); 255 256 if (effects) 257 + nvme_passthru_end(ctrl, ns, effects, cmd, ret); 258 259 return ret; 260 }
+2 -1
drivers/nvme/host/nvme.h
··· 328 struct delayed_work ka_work; 329 struct delayed_work failfast_work; 330 struct nvme_command ka_cmd; 331 struct work_struct fw_act_work; 332 unsigned long events; 333 ··· 1078 u8 opcode); 1079 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode); 1080 int nvme_execute_rq(struct request *rq, bool at_head); 1081 - void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects, 1082 struct nvme_command *cmd, int status); 1083 struct nvme_ctrl *nvme_ctrl_from_file(struct file *file); 1084 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
··· 328 struct delayed_work ka_work; 329 struct delayed_work failfast_work; 330 struct nvme_command ka_cmd; 331 + unsigned long ka_last_check_time; 332 struct work_struct fw_act_work; 333 unsigned long events; 334 ··· 1077 u8 opcode); 1078 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode); 1079 int nvme_execute_rq(struct request *rq, bool at_head); 1080 + void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, 1081 struct nvme_command *cmd, int status); 1082 struct nvme_ctrl *nvme_ctrl_from_file(struct file *file); 1083 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
+1 -1
drivers/nvme/target/passthru.c
··· 243 blk_mq_free_request(rq); 244 245 if (effects) 246 - nvme_passthru_end(ctrl, effects, req->cmd, status); 247 } 248 249 static enum rq_end_io_ret nvmet_passthru_req_done(struct request *rq,
··· 243 blk_mq_free_request(rq); 244 245 if (effects) 246 + nvme_passthru_end(ctrl, ns, effects, req->cmd, status); 247 } 248 249 static enum rq_end_io_ret nvmet_passthru_req_done(struct request *rq,