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 21 [nvme_cmd_resv_release] = "Reservation Release", 22 22 [nvme_cmd_zone_mgmt_send] = "Zone Management Send", 23 23 [nvme_cmd_zone_mgmt_recv] = "Zone Management Receive", 24 - [nvme_cmd_zone_append] = "Zone Management Append", 24 + [nvme_cmd_zone_append] = "Zone Append", 25 25 }; 26 26 27 27 static const char * const nvme_admin_ops[] = {
+48 -4
drivers/nvme/host/core.c
··· 397 397 trace_nvme_complete_rq(req); 398 398 nvme_cleanup_cmd(req); 399 399 400 - if (ctrl->kas) 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) 401 410 ctrl->comp_seen = true; 402 411 403 412 switch (nvme_decide_disposition(req)) { ··· 1124 1115 } 1125 1116 EXPORT_SYMBOL_NS_GPL(nvme_passthru_start, NVME_TARGET_PASSTHRU); 1126 1117 1127 - void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects, 1118 + void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, 1128 1119 struct nvme_command *cmd, int status) 1129 1120 { 1130 1121 if (effects & NVME_CMD_EFFECTS_CSE_MASK) { ··· 1141 1132 nvme_queue_scan(ctrl); 1142 1133 flush_work(&ctrl->scan_work); 1143 1134 } 1135 + if (ns) 1136 + return; 1144 1137 1145 1138 switch (cmd->common.opcode) { 1146 1139 case nvme_admin_set_features: ··· 1172 1161 * The host should send Keep Alive commands at half of the Keep Alive Timeout 1173 1162 * accounting for transport roundtrip times [..]. 1174 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 + 1175 1179 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) 1176 1180 { 1177 - queue_delayed_work(nvme_wq, &ctrl->ka_work, ctrl->kato * HZ / 2); 1181 + queue_delayed_work(nvme_wq, &ctrl->ka_work, 1182 + nvme_keep_alive_work_period(ctrl)); 1178 1183 } 1179 1184 1180 1185 static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq, ··· 1199 1172 struct nvme_ctrl *ctrl = rq->end_io_data; 1200 1173 unsigned long flags; 1201 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 + } 1202 1189 1203 1190 blk_mq_free_request(rq); 1204 1191 ··· 1223 1182 return RQ_END_IO_NONE; 1224 1183 } 1225 1184 1185 + ctrl->ka_last_check_time = jiffies; 1226 1186 ctrl->comp_seen = false; 1227 1187 spin_lock_irqsave(&ctrl->lock, flags); 1228 1188 if (ctrl->state == NVME_CTRL_LIVE || ··· 1231 1189 startka = true; 1232 1190 spin_unlock_irqrestore(&ctrl->lock, flags); 1233 1191 if (startka) 1234 - nvme_queue_keep_alive_work(ctrl); 1192 + queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); 1235 1193 return RQ_END_IO_NONE; 1236 1194 } 1237 1195 ··· 1241 1199 struct nvme_ctrl, ka_work); 1242 1200 bool comp_seen = ctrl->comp_seen; 1243 1201 struct request *rq; 1202 + 1203 + ctrl->ka_last_check_time = jiffies; 1244 1204 1245 1205 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { 1246 1206 dev_dbg(ctrl->device,
+1 -1
drivers/nvme/host/ioctl.c
··· 254 254 blk_mq_free_request(req); 255 255 256 256 if (effects) 257 - nvme_passthru_end(ctrl, effects, cmd, ret); 257 + nvme_passthru_end(ctrl, ns, effects, cmd, ret); 258 258 259 259 return ret; 260 260 }
+2 -1
drivers/nvme/host/nvme.h
··· 328 328 struct delayed_work ka_work; 329 329 struct delayed_work failfast_work; 330 330 struct nvme_command ka_cmd; 331 + unsigned long ka_last_check_time; 331 332 struct work_struct fw_act_work; 332 333 unsigned long events; 333 334 ··· 1078 1077 u8 opcode); 1079 1078 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode); 1080 1079 int nvme_execute_rq(struct request *rq, bool at_head); 1081 - void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects, 1080 + void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, 1082 1081 struct nvme_command *cmd, int status); 1083 1082 struct nvme_ctrl *nvme_ctrl_from_file(struct file *file); 1084 1083 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
+1 -1
drivers/nvme/target/passthru.c
··· 243 243 blk_mq_free_request(rq); 244 244 245 245 if (effects) 246 - nvme_passthru_end(ctrl, effects, req->cmd, status); 246 + nvme_passthru_end(ctrl, ns, effects, req->cmd, status); 247 247 } 248 248 249 249 static enum rq_end_io_ret nvmet_passthru_req_done(struct request *rq,