Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'nvme-5.13-2021-04-06' of git://git.infradead.org/nvme into for-5.13/drivers

Pull NVMe updates from Christoph:

"nvme updates for Linux 5.13

- fix handling of very large MDTS values (Bart Van Assche)
- retrigger ANA log update if group descriptor isn't found
(Hannes Reinecke)
- fix locking contexts in nvme-tcp and nvmet-tcp (Sagi Grimberg)
- return proper error code from discovery ctrl (Hou Pu)
- verify the SGLS field in nvmet-tcp and nvmet-fc (Max Gurtovoy)
- disallow passthru cmd from targeting a nsid != nsid of the block dev
(Niklas Cassel)
- do not allow model_number exceed 40 bytes in nvmet (Noam Gottlieb)
- enable optional queue idle period tracking in nvmet-tcp
(Mark Wunderlich)
- various cleanups and optimizations (Chaitanya Kulkarni, Kanchan Joshi)
- expose fast_io_fail_tmo in sysfs (Daniel Wagner)
- implement non-MDTS command limits (Keith Busch)
- reduce warnings for unhandled command effects (Keith Busch)
- allocate storage for the SQE as part of the nvme_request (Keith Busch)"

* tag 'nvme-5.13-2021-04-06' of git://git.infradead.org/nvme: (33 commits)
nvme: fix handling of large MDTS values
nvme: implement non-mdts command limits
nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
nvme: retrigger ANA log update if group descriptor isn't found
nvme: export fast_io_fail_tmo to sysfs
nvme: remove superfluous else in nvme_ctrl_loss_tmo_store
nvme: use sysfs_emit instead of sprintf
nvme-fc: check sgl supported by target
nvme-tcp: check sgl supported by target
nvmet-tcp: enable optional queue idle period tracking
nvmet-tcp: fix incorrect locking in state_change sk callback
nvme-tcp: block BH in sk state_change sk callback
nvmet: return proper error code from discovery ctrl
nvme: warn of unhandled effects only once
nvme: use driver pdu command for passthrough
nvme-pci: allocate nvme_command within driver pdu
nvmet: do not allow model_number exceed 40 bytes
nvmet: remove unnecessary ctrl parameter
nvmet-fc: update function documentation
nvme-fc: fix the function documentation comment
...

+336 -178
+195 -103
drivers/nvme/host/core.c
··· 575 575 576 576 static inline void nvme_clear_nvme_request(struct request *req) 577 577 { 578 - if (!(req->rq_flags & RQF_DONTPREP)) { 579 - nvme_req(req)->retries = 0; 580 - nvme_req(req)->flags = 0; 581 - req->rq_flags |= RQF_DONTPREP; 582 - } 578 + struct nvme_command *cmd = nvme_req(req)->cmd; 579 + 580 + memset(cmd, 0, sizeof(*cmd)); 581 + nvme_req(req)->retries = 0; 582 + nvme_req(req)->flags = 0; 583 + req->rq_flags |= RQF_DONTPREP; 583 584 } 584 585 585 586 static inline unsigned int nvme_req_op(struct nvme_command *cmd) ··· 596 595 else /* no queuedata implies admin queue */ 597 596 req->timeout = NVME_ADMIN_TIMEOUT; 598 597 598 + /* passthru commands should let the driver set the SGL flags */ 599 + cmd->common.flags &= ~NVME_CMD_SGL_ALL; 600 + 599 601 req->cmd_flags |= REQ_FAILFAST_DRIVER; 600 602 nvme_clear_nvme_request(req); 601 - nvme_req(req)->cmd = cmd; 603 + memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd)); 602 604 } 603 605 604 606 struct request *nvme_alloc_request(struct request_queue *q, ··· 728 724 729 725 if (streamid < ARRAY_SIZE(req->q->write_hints)) 730 726 req->q->write_hints[streamid] += blk_rq_bytes(req) >> 9; 731 - } 732 - 733 - static void nvme_setup_passthrough(struct request *req, 734 - struct nvme_command *cmd) 735 - { 736 - memcpy(cmd, nvme_req(req)->cmd, sizeof(*cmd)); 737 - /* passthru commands should let the driver set the SGL flags */ 738 - cmd->common.flags &= ~NVME_CMD_SGL_ALL; 739 727 } 740 728 741 729 static inline void nvme_setup_flush(struct nvme_ns *ns, ··· 884 888 } 885 889 EXPORT_SYMBOL_GPL(nvme_cleanup_cmd); 886 890 887 - blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req, 888 - struct nvme_command *cmd) 891 + blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req) 889 892 { 893 + struct nvme_command *cmd = nvme_req(req)->cmd; 890 894 blk_status_t ret = BLK_STS_OK; 891 895 892 - nvme_clear_nvme_request(req); 896 + if (!(req->rq_flags & RQF_DONTPREP)) 897 + nvme_clear_nvme_request(req); 893 898 894 - memset(cmd, 0, sizeof(*cmd)); 895 899 switch (req_op(req)) { 896 900 case REQ_OP_DRV_IN: 897 901 case REQ_OP_DRV_OUT: 898 - nvme_setup_passthrough(req, cmd); 902 + /* these are setup prior to execution in nvme_init_request() */ 899 903 break; 900 904 case REQ_OP_FLUSH: 901 905 nvme_setup_flush(ns, cmd); ··· 1072 1076 if (ns->head->effects) 1073 1077 effects = le32_to_cpu(ns->head->effects->iocs[opcode]); 1074 1078 if (effects & ~(NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC)) 1075 - dev_warn(ctrl->device, 1076 - "IO command:%02x has unhandled effects:%08x\n", 1077 - opcode, effects); 1079 + dev_warn_once(ctrl->device, 1080 + "IO command:%02x has unhandled effects:%08x\n", 1081 + opcode, effects); 1078 1082 return 0; 1079 1083 } 1080 1084 ··· 1116 1120 mutex_unlock(&ctrl->scan_lock); 1117 1121 } 1118 1122 if (effects & NVME_CMD_EFFECTS_CCC) 1119 - nvme_init_identify(ctrl); 1123 + nvme_init_ctrl_finish(ctrl); 1120 1124 if (effects & (NVME_CMD_EFFECTS_NIC | NVME_CMD_EFFECTS_NCC)) { 1121 1125 nvme_queue_scan(ctrl); 1122 1126 flush_work(&ctrl->scan_work); ··· 1133 1137 1134 1138 effects = nvme_passthru_start(ctrl, ns, cmd->common.opcode); 1135 1139 blk_execute_rq(disk, rq, 0); 1136 - nvme_passthru_end(ctrl, effects); 1140 + if (effects) /* nothing to be done for zero cmd effects */ 1141 + nvme_passthru_end(ctrl, effects); 1137 1142 } 1138 1143 EXPORT_SYMBOL_NS_GPL(nvme_execute_passthru_rq, NVME_TARGET_PASSTHRU); 1139 1144 ··· 1632 1635 return -EFAULT; 1633 1636 if (cmd.flags) 1634 1637 return -EINVAL; 1638 + if (ns && cmd.nsid != ns->head->ns_id) { 1639 + dev_err(ctrl->device, 1640 + "%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n", 1641 + current->comm, cmd.nsid, ns->head->ns_id); 1642 + return -EINVAL; 1643 + } 1635 1644 1636 1645 memset(&c, 0, sizeof(c)); 1637 1646 c.common.opcode = cmd.opcode; ··· 1682 1679 return -EFAULT; 1683 1680 if (cmd.flags) 1684 1681 return -EINVAL; 1682 + if (ns && cmd.nsid != ns->head->ns_id) { 1683 + dev_err(ctrl->device, 1684 + "%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n", 1685 + current->comm, cmd.nsid, ns->head->ns_id); 1686 + return -EINVAL; 1687 + } 1685 1688 1686 1689 memset(&c, 0, sizeof(c)); 1687 1690 c.common.opcode = cmd.opcode; ··· 1948 1939 struct request_queue *queue = disk->queue; 1949 1940 u32 size = queue_logical_block_size(queue); 1950 1941 1951 - if (!(ctrl->oncs & NVME_CTRL_ONCS_DSM)) { 1942 + if (ctrl->max_discard_sectors == 0) { 1952 1943 blk_queue_flag_clear(QUEUE_FLAG_DISCARD, queue); 1953 1944 return; 1954 1945 } ··· 1966 1957 if (blk_queue_flag_test_and_set(QUEUE_FLAG_DISCARD, queue)) 1967 1958 return; 1968 1959 1969 - blk_queue_max_discard_sectors(queue, UINT_MAX); 1970 - blk_queue_max_discard_segments(queue, NVME_DSM_MAX_RANGES); 1960 + blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors); 1961 + blk_queue_max_discard_segments(queue, ctrl->max_discard_segments); 1971 1962 1972 1963 if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) 1973 1964 blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); 1974 - } 1975 - 1976 - static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) 1977 - { 1978 - u64 max_blocks; 1979 - 1980 - if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) || 1981 - (ns->ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) 1982 - return; 1983 - /* 1984 - * Even though NVMe spec explicitly states that MDTS is not 1985 - * applicable to the write-zeroes:- "The restriction does not apply to 1986 - * commands that do not transfer data between the host and the 1987 - * controller (e.g., Write Uncorrectable ro Write Zeroes command).". 1988 - * In order to be more cautious use controller's max_hw_sectors value 1989 - * to configure the maximum sectors for the write-zeroes which is 1990 - * configured based on the controller's MDTS field in the 1991 - * nvme_init_identify() if available. 1992 - */ 1993 - if (ns->ctrl->max_hw_sectors == UINT_MAX) 1994 - max_blocks = (u64)USHRT_MAX + 1; 1995 - else 1996 - max_blocks = ns->ctrl->max_hw_sectors + 1; 1997 - 1998 - blk_queue_max_write_zeroes_sectors(disk->queue, 1999 - nvme_lba_to_sect(ns, max_blocks)); 2000 1965 } 2001 1966 2002 1967 static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids) ··· 2142 2159 set_capacity_and_notify(disk, capacity); 2143 2160 2144 2161 nvme_config_discard(disk, ns); 2145 - nvme_config_write_zeroes(disk, ns); 2162 + blk_queue_max_write_zeroes_sectors(disk->queue, 2163 + ns->ctrl->max_zeroes_sectors); 2146 2164 2147 2165 set_disk_ro(disk, (id->nsattr & NVME_NS_ATTR_RO) || 2148 2166 test_bit(NVME_NS_FORCE_RO, &ns->flags)); ··· 2309 2325 enum pr_type type, bool abort) 2310 2326 { 2311 2327 u32 cdw10 = nvme_pr_type(type) << 8 | (abort ? 2 : 1); 2328 + 2312 2329 return nvme_pr_command(bdev, cdw10, old, new, nvme_cmd_resv_acquire); 2313 2330 } 2314 2331 2315 2332 static int nvme_pr_clear(struct block_device *bdev, u64 key) 2316 2333 { 2317 2334 u32 cdw10 = 1 | (key ? 1 << 3 : 0); 2335 + 2318 2336 return nvme_pr_command(bdev, cdw10, key, 0, nvme_cmd_resv_register); 2319 2337 } 2320 2338 2321 2339 static int nvme_pr_release(struct block_device *bdev, u64 key, enum pr_type type) 2322 2340 { 2323 2341 u32 cdw10 = nvme_pr_type(type) << 8 | (key ? 1 << 3 : 0); 2342 + 2324 2343 return nvme_pr_command(bdev, cdw10, key, 0, nvme_cmd_resv_release); 2325 2344 } 2326 2345 ··· 2863 2876 { \ 2864 2877 struct nvme_subsystem *subsys = \ 2865 2878 container_of(dev, struct nvme_subsystem, dev); \ 2866 - return sprintf(buf, "%.*s\n", \ 2867 - (int)sizeof(subsys->field), subsys->field); \ 2879 + return sysfs_emit(buf, "%.*s\n", \ 2880 + (int)sizeof(subsys->field), subsys->field); \ 2868 2881 } \ 2869 2882 static SUBSYS_ATTR_RO(field, S_IRUGO, subsys_##field##_show); 2870 2883 ··· 3047 3060 return 0; 3048 3061 } 3049 3062 3050 - /* 3051 - * Initialize the cached copies of the Identify data and various controller 3052 - * register in our nvme_ctrl structure. This should be called as soon as 3053 - * the admin queue is fully up and running. 3054 - */ 3055 - int nvme_init_identify(struct nvme_ctrl *ctrl) 3063 + static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units) 3064 + { 3065 + u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; 3066 + 3067 + if (check_shl_overflow(1U, units + page_shift - 9, &val)) 3068 + return UINT_MAX; 3069 + return val; 3070 + } 3071 + 3072 + static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) 3073 + { 3074 + struct nvme_command c = { }; 3075 + struct nvme_id_ctrl_nvm *id; 3076 + int ret; 3077 + 3078 + if (ctrl->oncs & NVME_CTRL_ONCS_DSM) { 3079 + ctrl->max_discard_sectors = UINT_MAX; 3080 + ctrl->max_discard_segments = NVME_DSM_MAX_RANGES; 3081 + } else { 3082 + ctrl->max_discard_sectors = 0; 3083 + ctrl->max_discard_segments = 0; 3084 + } 3085 + 3086 + /* 3087 + * Even though NVMe spec explicitly states that MDTS is not applicable 3088 + * to the write-zeroes, we are cautious and limit the size to the 3089 + * controllers max_hw_sectors value, which is based on the MDTS field 3090 + * and possibly other limiting factors. 3091 + */ 3092 + if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && 3093 + !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) 3094 + ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; 3095 + else 3096 + ctrl->max_zeroes_sectors = 0; 3097 + 3098 + if (nvme_ctrl_limited_cns(ctrl)) 3099 + return 0; 3100 + 3101 + id = kzalloc(sizeof(*id), GFP_KERNEL); 3102 + if (!id) 3103 + return 0; 3104 + 3105 + c.identify.opcode = nvme_admin_identify; 3106 + c.identify.cns = NVME_ID_CNS_CS_CTRL; 3107 + c.identify.csi = NVME_CSI_NVM; 3108 + 3109 + ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); 3110 + if (ret) 3111 + goto free_data; 3112 + 3113 + if (id->dmrl) 3114 + ctrl->max_discard_segments = id->dmrl; 3115 + if (id->dmrsl) 3116 + ctrl->max_discard_sectors = le32_to_cpu(id->dmrsl); 3117 + if (id->wzsl) 3118 + ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); 3119 + 3120 + free_data: 3121 + kfree(id); 3122 + return ret; 3123 + } 3124 + 3125 + static int nvme_init_identify(struct nvme_ctrl *ctrl) 3056 3126 { 3057 3127 struct nvme_id_ctrl *id; 3058 - int ret, page_shift; 3059 3128 u32 max_hw_sectors; 3060 3129 bool prev_apst_enabled; 3061 - 3062 - ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); 3063 - if (ret) { 3064 - dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); 3065 - return ret; 3066 - } 3067 - page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12; 3068 - ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); 3069 - 3070 - if (ctrl->vs >= NVME_VS(1, 1, 0)) 3071 - ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); 3130 + int ret; 3072 3131 3073 3132 ret = nvme_identify_ctrl(ctrl, &id); 3074 3133 if (ret) { ··· 3132 3099 ctrl->cntlid = le16_to_cpu(id->cntlid); 3133 3100 3134 3101 if (!ctrl->identified) { 3135 - int i; 3102 + unsigned int i; 3136 3103 3137 3104 ret = nvme_init_subsystem(ctrl, id); 3138 3105 if (ret) ··· 3171 3138 atomic_set(&ctrl->abort_limit, id->acl + 1); 3172 3139 ctrl->vwc = id->vwc; 3173 3140 if (id->mdts) 3174 - max_hw_sectors = 1 << (id->mdts + page_shift - 9); 3141 + max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); 3175 3142 else 3176 3143 max_hw_sectors = UINT_MAX; 3177 3144 ctrl->max_hw_sectors = ··· 3245 3212 } 3246 3213 3247 3214 ret = nvme_mpath_init(ctrl, id); 3248 - kfree(id); 3249 - 3250 3215 if (ret < 0) 3251 - return ret; 3216 + goto out_free; 3252 3217 3253 3218 if (ctrl->apst_enabled && !prev_apst_enabled) 3254 3219 dev_pm_qos_expose_latency_tolerance(ctrl->device); 3255 3220 else if (!ctrl->apst_enabled && prev_apst_enabled) 3256 3221 dev_pm_qos_hide_latency_tolerance(ctrl->device); 3222 + 3223 + out_free: 3224 + kfree(id); 3225 + return ret; 3226 + } 3227 + 3228 + /* 3229 + * Initialize the cached copies of the Identify data and various controller 3230 + * register in our nvme_ctrl structure. This should be called as soon as 3231 + * the admin queue is fully up and running. 3232 + */ 3233 + int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl) 3234 + { 3235 + int ret; 3236 + 3237 + ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); 3238 + if (ret) { 3239 + dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); 3240 + return ret; 3241 + } 3242 + 3243 + ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); 3244 + 3245 + if (ctrl->vs >= NVME_VS(1, 1, 0)) 3246 + ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); 3247 + 3248 + ret = nvme_init_identify(ctrl); 3249 + if (ret) 3250 + return ret; 3251 + 3252 + ret = nvme_init_non_mdts_limits(ctrl); 3253 + if (ret < 0) 3254 + return ret; 3257 3255 3258 3256 ret = nvme_configure_apst(ctrl); 3259 3257 if (ret < 0) ··· 3311 3247 ctrl->identified = true; 3312 3248 3313 3249 return 0; 3314 - 3315 - out_free: 3316 - kfree(id); 3317 - return ret; 3318 3250 } 3319 - EXPORT_SYMBOL_GPL(nvme_init_identify); 3251 + EXPORT_SYMBOL_GPL(nvme_init_ctrl_finish); 3320 3252 3321 3253 static int nvme_dev_open(struct inode *inode, struct file *file) 3322 3254 { ··· 3458 3398 int model_len = sizeof(subsys->model); 3459 3399 3460 3400 if (!uuid_is_null(&ids->uuid)) 3461 - return sprintf(buf, "uuid.%pU\n", &ids->uuid); 3401 + return sysfs_emit(buf, "uuid.%pU\n", &ids->uuid); 3462 3402 3463 3403 if (memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) 3464 - return sprintf(buf, "eui.%16phN\n", ids->nguid); 3404 + return sysfs_emit(buf, "eui.%16phN\n", ids->nguid); 3465 3405 3466 3406 if (memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) 3467 - return sprintf(buf, "eui.%8phN\n", ids->eui64); 3407 + return sysfs_emit(buf, "eui.%8phN\n", ids->eui64); 3468 3408 3469 3409 while (serial_len > 0 && (subsys->serial[serial_len - 1] == ' ' || 3470 3410 subsys->serial[serial_len - 1] == '\0')) ··· 3473 3413 subsys->model[model_len - 1] == '\0')) 3474 3414 model_len--; 3475 3415 3476 - return sprintf(buf, "nvme.%04x-%*phN-%*phN-%08x\n", subsys->vendor_id, 3416 + return sysfs_emit(buf, "nvme.%04x-%*phN-%*phN-%08x\n", subsys->vendor_id, 3477 3417 serial_len, subsys->serial, model_len, subsys->model, 3478 3418 head->ns_id); 3479 3419 } ··· 3482 3422 static ssize_t nguid_show(struct device *dev, struct device_attribute *attr, 3483 3423 char *buf) 3484 3424 { 3485 - return sprintf(buf, "%pU\n", dev_to_ns_head(dev)->ids.nguid); 3425 + return sysfs_emit(buf, "%pU\n", dev_to_ns_head(dev)->ids.nguid); 3486 3426 } 3487 3427 static DEVICE_ATTR_RO(nguid); 3488 3428 ··· 3497 3437 if (uuid_is_null(&ids->uuid)) { 3498 3438 printk_ratelimited(KERN_WARNING 3499 3439 "No UUID available providing old NGUID\n"); 3500 - return sprintf(buf, "%pU\n", ids->nguid); 3440 + return sysfs_emit(buf, "%pU\n", ids->nguid); 3501 3441 } 3502 - return sprintf(buf, "%pU\n", &ids->uuid); 3442 + return sysfs_emit(buf, "%pU\n", &ids->uuid); 3503 3443 } 3504 3444 static DEVICE_ATTR_RO(uuid); 3505 3445 3506 3446 static ssize_t eui_show(struct device *dev, struct device_attribute *attr, 3507 3447 char *buf) 3508 3448 { 3509 - return sprintf(buf, "%8ph\n", dev_to_ns_head(dev)->ids.eui64); 3449 + return sysfs_emit(buf, "%8ph\n", dev_to_ns_head(dev)->ids.eui64); 3510 3450 } 3511 3451 static DEVICE_ATTR_RO(eui); 3512 3452 3513 3453 static ssize_t nsid_show(struct device *dev, struct device_attribute *attr, 3514 3454 char *buf) 3515 3455 { 3516 - return sprintf(buf, "%d\n", dev_to_ns_head(dev)->ns_id); 3456 + return sysfs_emit(buf, "%d\n", dev_to_ns_head(dev)->ns_id); 3517 3457 } 3518 3458 static DEVICE_ATTR_RO(nsid); 3519 3459 ··· 3578 3518 struct device_attribute *attr, char *buf) \ 3579 3519 { \ 3580 3520 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \ 3581 - return sprintf(buf, "%.*s\n", \ 3521 + return sysfs_emit(buf, "%.*s\n", \ 3582 3522 (int)sizeof(ctrl->subsys->field), ctrl->subsys->field); \ 3583 3523 } \ 3584 3524 static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); ··· 3592 3532 struct device_attribute *attr, char *buf) \ 3593 3533 { \ 3594 3534 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \ 3595 - return sprintf(buf, "%d\n", ctrl->field); \ 3535 + return sysfs_emit(buf, "%d\n", ctrl->field); \ 3596 3536 } \ 3597 3537 static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); 3598 3538 ··· 3640 3580 3641 3581 if ((unsigned)ctrl->state < ARRAY_SIZE(state_name) && 3642 3582 state_name[ctrl->state]) 3643 - return sprintf(buf, "%s\n", state_name[ctrl->state]); 3583 + return sysfs_emit(buf, "%s\n", state_name[ctrl->state]); 3644 3584 3645 - return sprintf(buf, "unknown state\n"); 3585 + return sysfs_emit(buf, "unknown state\n"); 3646 3586 } 3647 3587 3648 3588 static DEVICE_ATTR(state, S_IRUGO, nvme_sysfs_show_state, NULL); ··· 3694 3634 struct nvmf_ctrl_options *opts = ctrl->opts; 3695 3635 3696 3636 if (ctrl->opts->max_reconnects == -1) 3697 - return sprintf(buf, "off\n"); 3698 - return sprintf(buf, "%d\n", 3699 - opts->max_reconnects * opts->reconnect_delay); 3637 + return sysfs_emit(buf, "off\n"); 3638 + return sysfs_emit(buf, "%d\n", 3639 + opts->max_reconnects * opts->reconnect_delay); 3700 3640 } 3701 3641 3702 3642 static ssize_t nvme_ctrl_loss_tmo_store(struct device *dev, ··· 3710 3650 if (err) 3711 3651 return -EINVAL; 3712 3652 3713 - else if (ctrl_loss_tmo < 0) 3653 + if (ctrl_loss_tmo < 0) 3714 3654 opts->max_reconnects = -1; 3715 3655 else 3716 3656 opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, ··· 3726 3666 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3727 3667 3728 3668 if (ctrl->opts->reconnect_delay == -1) 3729 - return sprintf(buf, "off\n"); 3730 - return sprintf(buf, "%d\n", ctrl->opts->reconnect_delay); 3669 + return sysfs_emit(buf, "off\n"); 3670 + return sysfs_emit(buf, "%d\n", ctrl->opts->reconnect_delay); 3731 3671 } 3732 3672 3733 3673 static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev, ··· 3746 3686 } 3747 3687 static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR, 3748 3688 nvme_ctrl_reconnect_delay_show, nvme_ctrl_reconnect_delay_store); 3689 + 3690 + static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev, 3691 + struct device_attribute *attr, char *buf) 3692 + { 3693 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3694 + 3695 + if (ctrl->opts->fast_io_fail_tmo == -1) 3696 + return sysfs_emit(buf, "off\n"); 3697 + return sysfs_emit(buf, "%d\n", ctrl->opts->fast_io_fail_tmo); 3698 + } 3699 + 3700 + static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, 3701 + struct device_attribute *attr, const char *buf, size_t count) 3702 + { 3703 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3704 + struct nvmf_ctrl_options *opts = ctrl->opts; 3705 + int fast_io_fail_tmo, err; 3706 + 3707 + err = kstrtoint(buf, 10, &fast_io_fail_tmo); 3708 + if (err) 3709 + return -EINVAL; 3710 + 3711 + if (fast_io_fail_tmo < 0) 3712 + opts->fast_io_fail_tmo = -1; 3713 + else 3714 + opts->fast_io_fail_tmo = fast_io_fail_tmo; 3715 + return count; 3716 + } 3717 + static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR, 3718 + nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store); 3749 3719 3750 3720 static struct attribute *nvme_dev_attrs[] = { 3751 3721 &dev_attr_reset_controller.attr, ··· 3796 3706 &dev_attr_hostid.attr, 3797 3707 &dev_attr_ctrl_loss_tmo.attr, 3798 3708 &dev_attr_reconnect_delay.attr, 3709 + &dev_attr_fast_io_fail_tmo.attr, 3799 3710 NULL 3800 3711 }; 3801 3712 ··· 4847 4756 BUILD_BUG_ON(sizeof(struct nvme_id_ns) != NVME_IDENTIFY_DATA_SIZE); 4848 4757 BUILD_BUG_ON(sizeof(struct nvme_id_ns_zns) != NVME_IDENTIFY_DATA_SIZE); 4849 4758 BUILD_BUG_ON(sizeof(struct nvme_id_ctrl_zns) != NVME_IDENTIFY_DATA_SIZE); 4759 + BUILD_BUG_ON(sizeof(struct nvme_id_ctrl_nvm) != NVME_IDENTIFY_DATA_SIZE); 4850 4760 BUILD_BUG_ON(sizeof(struct nvme_lba_range_type) != 64); 4851 4761 BUILD_BUG_ON(sizeof(struct nvme_smart_log) != 512); 4852 4762 BUILD_BUG_ON(sizeof(struct nvme_dbbuf) != 64);
+9 -5
drivers/nvme/host/fc.c
··· 1708 1708 * 1709 1709 * If this routine returns error, the LLDD should abort the exchange. 1710 1710 * 1711 - * @remoteport: pointer to the (registered) remote port that the LS 1711 + * @portptr: pointer to the (registered) remote port that the LS 1712 1712 * was received from. The remoteport is associated with 1713 1713 * a specific localport. 1714 1714 * @lsrsp: pointer to a nvmefc_ls_rsp response structure to be ··· 2128 2128 op->op.fcp_req.first_sgl = op->sgl; 2129 2129 op->op.fcp_req.private = &op->priv[0]; 2130 2130 nvme_req(rq)->ctrl = &ctrl->ctrl; 2131 + nvme_req(rq)->cmd = &op->op.cmd_iu.sqe; 2131 2132 return res; 2132 2133 } 2133 2134 ··· 2760 2759 struct nvme_fc_ctrl *ctrl = queue->ctrl; 2761 2760 struct request *rq = bd->rq; 2762 2761 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq); 2763 - struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu; 2764 - struct nvme_command *sqe = &cmdiu->sqe; 2765 2762 enum nvmefc_fcp_datadir io_dir; 2766 2763 bool queue_ready = test_bit(NVME_FC_Q_LIVE, &queue->flags); 2767 2764 u32 data_len; ··· 2769 2770 !nvmf_check_ready(&queue->ctrl->ctrl, rq, queue_ready)) 2770 2771 return nvmf_fail_nonready_command(&queue->ctrl->ctrl, rq); 2771 2772 2772 - ret = nvme_setup_cmd(ns, rq, sqe); 2773 + ret = nvme_setup_cmd(ns, rq); 2773 2774 if (ret) 2774 2775 return ret; 2775 2776 ··· 3085 3086 3086 3087 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q); 3087 3088 3088 - ret = nvme_init_identify(&ctrl->ctrl); 3089 + ret = nvme_init_ctrl_finish(&ctrl->ctrl); 3089 3090 if (ret || test_bit(ASSOC_FAILED, &ctrl->flags)) 3090 3091 goto out_disconnect_admin_queue; 3091 3092 ··· 3099 3100 } 3100 3101 3101 3102 /* FC-NVME supports normal SGL Data Block Descriptors */ 3103 + if (!(ctrl->ctrl.sgls & ((1 << 0) | (1 << 1)))) { 3104 + dev_err(ctrl->ctrl.device, 3105 + "Mandatory sgls are not supported!\n"); 3106 + goto out_disconnect_admin_queue; 3107 + } 3102 3108 3103 3109 if (opts->queue_size > ctrl->ctrl.maxcmd) { 3104 3110 /* warn if maxcmd is lower than queue_size */
+8 -4
drivers/nvme/host/multipath.c
··· 602 602 struct nvme_subsystem *subsys = 603 603 container_of(dev, struct nvme_subsystem, dev); 604 604 605 - return sprintf(buf, "%s\n", 606 - nvme_iopolicy_names[READ_ONCE(subsys->iopolicy)]); 605 + return sysfs_emit(buf, "%s\n", 606 + nvme_iopolicy_names[READ_ONCE(subsys->iopolicy)]); 607 607 } 608 608 609 609 static ssize_t nvme_subsys_iopolicy_store(struct device *dev, ··· 628 628 static ssize_t ana_grpid_show(struct device *dev, struct device_attribute *attr, 629 629 char *buf) 630 630 { 631 - return sprintf(buf, "%d\n", nvme_get_ns_from_dev(dev)->ana_grpid); 631 + return sysfs_emit(buf, "%d\n", nvme_get_ns_from_dev(dev)->ana_grpid); 632 632 } 633 633 DEVICE_ATTR_RO(ana_grpid); 634 634 ··· 637 637 { 638 638 struct nvme_ns *ns = nvme_get_ns_from_dev(dev); 639 639 640 - return sprintf(buf, "%s\n", nvme_ana_state_names[ns->ana_state]); 640 + return sysfs_emit(buf, "%s\n", nvme_ana_state_names[ns->ana_state]); 641 641 } 642 642 DEVICE_ATTR_RO(ana_state); 643 643 ··· 668 668 if (desc.state) { 669 669 /* found the group desc: update */ 670 670 nvme_update_ns_ana_state(&desc, ns); 671 + } else { 672 + /* group desc not found: trigger a re-read */ 673 + set_bit(NVME_NS_ANA_PENDING, &ns->flags); 674 + queue_work(nvme_wq, &ns->ctrl->ana_work); 671 675 } 672 676 } else { 673 677 ns->ana_state = NVME_ANA_OPTIMIZED;
+6 -4
drivers/nvme/host/nvme.h
··· 276 276 u32 max_hw_sectors; 277 277 u32 max_segments; 278 278 u32 max_integrity_segments; 279 + u32 max_discard_sectors; 280 + u32 max_discard_segments; 281 + u32 max_zeroes_sectors; 279 282 #ifdef CONFIG_BLK_DEV_ZONED 280 283 u32 max_zone_append; 281 284 #endif ··· 602 599 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl); 603 600 void nvme_start_ctrl(struct nvme_ctrl *ctrl); 604 601 void nvme_stop_ctrl(struct nvme_ctrl *ctrl); 605 - int nvme_init_identify(struct nvme_ctrl *ctrl); 602 + int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl); 606 603 607 604 void nvme_remove_namespaces(struct nvme_ctrl *ctrl); 608 605 ··· 626 623 struct request *nvme_alloc_request(struct request_queue *q, 627 624 struct nvme_command *cmd, blk_mq_req_flags_t flags); 628 625 void nvme_cleanup_cmd(struct request *req); 629 - blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req, 630 - struct nvme_command *cmd); 626 + blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req); 631 627 int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, 632 628 void *buf, unsigned bufflen); 633 629 int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, ··· 747 745 static inline int nvme_mpath_init(struct nvme_ctrl *ctrl, 748 746 struct nvme_id_ctrl *id) 749 747 { 750 - if (ctrl->subsys->cmic & (1 << 3)) 748 + if (ctrl->subsys->cmic & NVME_CTRL_CMIC_ANA) 751 749 dev_warn(ctrl->device, 752 750 "Please enable CONFIG_NVME_MULTIPATH for full support of multi-port devices.\n"); 753 751 return 0;
+10 -16
drivers/nvme/host/pci.c
··· 224 224 */ 225 225 struct nvme_iod { 226 226 struct nvme_request req; 227 + struct nvme_command cmd; 227 228 struct nvme_queue *nvmeq; 228 229 bool use_sgl; 229 230 int aborted; ··· 430 429 iod->nvmeq = nvmeq; 431 430 432 431 nvme_req(req)->ctrl = &dev->ctrl; 432 + nvme_req(req)->cmd = &iod->cmd; 433 433 return 0; 434 434 } 435 435 ··· 919 917 struct nvme_dev *dev = nvmeq->dev; 920 918 struct request *req = bd->rq; 921 919 struct nvme_iod *iod = blk_mq_rq_to_pdu(req); 922 - struct nvme_command cmnd; 920 + struct nvme_command *cmnd = &iod->cmd; 923 921 blk_status_t ret; 924 922 925 923 iod->aborted = 0; ··· 933 931 if (unlikely(!test_bit(NVMEQ_ENABLED, &nvmeq->flags))) 934 932 return BLK_STS_IOERR; 935 933 936 - ret = nvme_setup_cmd(ns, req, &cmnd); 934 + ret = nvme_setup_cmd(ns, req); 937 935 if (ret) 938 936 return ret; 939 937 940 938 if (blk_rq_nr_phys_segments(req)) { 941 - ret = nvme_map_data(dev, req, &cmnd); 939 + ret = nvme_map_data(dev, req, cmnd); 942 940 if (ret) 943 941 goto out_free_cmd; 944 942 } 945 943 946 944 if (blk_integrity_rq(req)) { 947 - ret = nvme_map_metadata(dev, req, &cmnd); 945 + ret = nvme_map_metadata(dev, req, cmnd); 948 946 if (ret) 949 947 goto out_unmap_data; 950 948 } 951 949 952 950 blk_mq_start_request(req); 953 - nvme_submit_cmd(nvmeq, &cmnd, bd->last); 951 + nvme_submit_cmd(nvmeq, cmnd, bd->last); 954 952 return BLK_STS_OK; 955 953 out_unmap_data: 956 954 nvme_unmap_data(dev, req); ··· 1062 1060 static irqreturn_t nvme_irq(int irq, void *data) 1063 1061 { 1064 1062 struct nvme_queue *nvmeq = data; 1065 - irqreturn_t ret = IRQ_NONE; 1066 1063 1067 - /* 1068 - * The rmb/wmb pair ensures we see all updates from a previous run of 1069 - * the irq handler, even if that was on another CPU. 1070 - */ 1071 - rmb(); 1072 1064 if (nvme_process_cq(nvmeq)) 1073 - ret = IRQ_HANDLED; 1074 - wmb(); 1075 - 1076 - return ret; 1065 + return IRQ_HANDLED; 1066 + return IRQ_NONE; 1077 1067 } 1078 1068 1079 1069 static irqreturn_t nvme_irq_check(int irq, void *data) ··· 2647 2653 */ 2648 2654 dev->ctrl.max_integrity_segments = 1; 2649 2655 2650 - result = nvme_init_identify(&dev->ctrl); 2656 + result = nvme_init_ctrl_finish(&dev->ctrl); 2651 2657 if (result) 2652 2658 goto out; 2653 2659
+4 -3
drivers/nvme/host/rdma.c
··· 314 314 NVME_RDMA_DATA_SGL_SIZE; 315 315 316 316 req->queue = queue; 317 + nvme_req(rq)->cmd = req->sqe.data; 317 318 318 319 return 0; 319 320 } ··· 918 917 919 918 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q); 920 919 921 - error = nvme_init_identify(&ctrl->ctrl); 920 + error = nvme_init_ctrl_finish(&ctrl->ctrl); 922 921 if (error) 923 922 goto out_quiesce_queue; 924 923 ··· 2039 2038 struct request *rq = bd->rq; 2040 2039 struct nvme_rdma_request *req = blk_mq_rq_to_pdu(rq); 2041 2040 struct nvme_rdma_qe *sqe = &req->sqe; 2042 - struct nvme_command *c = sqe->data; 2041 + struct nvme_command *c = nvme_req(rq)->cmd; 2043 2042 struct ib_device *dev; 2044 2043 bool queue_ready = test_bit(NVME_RDMA_Q_LIVE, &queue->flags); 2045 2044 blk_status_t ret; ··· 2062 2061 ib_dma_sync_single_for_cpu(dev, sqe->dma, 2063 2062 sizeof(struct nvme_command), DMA_TO_DEVICE); 2064 2063 2065 - ret = nvme_setup_cmd(ns, rq, c); 2064 + ret = nvme_setup_cmd(ns, rq); 2066 2065 if (ret) 2067 2066 goto unmap_qe; 2068 2067
+12 -4
drivers/nvme/host/tcp.c
··· 417 417 { 418 418 struct nvme_tcp_ctrl *ctrl = set->driver_data; 419 419 struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); 420 + struct nvme_tcp_cmd_pdu *pdu; 420 421 int queue_idx = (set == &ctrl->tag_set) ? hctx_idx + 1 : 0; 421 422 struct nvme_tcp_queue *queue = &ctrl->queues[queue_idx]; 422 423 u8 hdgst = nvme_tcp_hdgst_len(queue); ··· 428 427 if (!req->pdu) 429 428 return -ENOMEM; 430 429 430 + pdu = req->pdu; 431 431 req->queue = queue; 432 432 nvme_req(rq)->ctrl = &ctrl->ctrl; 433 + nvme_req(rq)->cmd = &pdu->cmd; 433 434 434 435 return 0; 435 436 } ··· 870 867 { 871 868 struct nvme_tcp_queue *queue; 872 869 873 - read_lock(&sk->sk_callback_lock); 870 + read_lock_bh(&sk->sk_callback_lock); 874 871 queue = sk->sk_user_data; 875 872 if (!queue) 876 873 goto done; ··· 891 888 892 889 queue->state_change(sk); 893 890 done: 894 - read_unlock(&sk->sk_callback_lock); 891 + read_unlock_bh(&sk->sk_callback_lock); 895 892 } 896 893 897 894 static inline bool nvme_tcp_queue_more(struct nvme_tcp_queue *queue) ··· 1878 1875 1879 1876 blk_mq_unquiesce_queue(ctrl->admin_q); 1880 1877 1881 - error = nvme_init_identify(ctrl); 1878 + error = nvme_init_ctrl_finish(ctrl); 1882 1879 if (error) 1883 1880 goto out_quiesce_queue; 1884 1881 ··· 1963 1960 1964 1961 if (ctrl->icdoff) { 1965 1962 dev_err(ctrl->device, "icdoff is not supported!\n"); 1963 + goto destroy_admin; 1964 + } 1965 + 1966 + if (!(ctrl->sgls & ((1 << 0) | (1 << 1)))) { 1967 + dev_err(ctrl->device, "Mandatory sgls are not supported!\n"); 1966 1968 goto destroy_admin; 1967 1969 } 1968 1970 ··· 2267 2259 u8 hdgst = nvme_tcp_hdgst_len(queue), ddgst = 0; 2268 2260 blk_status_t ret; 2269 2261 2270 - ret = nvme_setup_cmd(ns, rq, &pdu->cmd); 2262 + ret = nvme_setup_cmd(ns, rq); 2271 2263 if (ret) 2272 2264 return ret; 2273 2265
+2 -2
drivers/nvme/target/admin-cmd.c
··· 513 513 default: 514 514 id->nuse = id->nsze; 515 515 break; 516 - } 516 + } 517 517 518 518 if (req->ns->bdev) 519 519 nvmet_bdev_set_limits(req->ns->bdev, id); ··· 940 940 if (nvmet_req_subsys(req)->type == NVME_NQN_DISC) 941 941 return nvmet_parse_discovery_cmd(req); 942 942 943 - ret = nvmet_check_ctrl_status(req, cmd); 943 + ret = nvmet_check_ctrl_status(req); 944 944 if (unlikely(ret)) 945 945 return ret; 946 946
+6
drivers/nvme/target/configfs.c
··· 1149 1149 if (!len) 1150 1150 return -EINVAL; 1151 1151 1152 + if (len > NVMET_MN_MAX_SIZE) { 1153 + pr_err("Model nubmer size can not exceed %d Bytes\n", 1154 + NVMET_MN_MAX_SIZE); 1155 + return -EINVAL; 1156 + } 1157 + 1152 1158 for (pos = 0; pos < len; pos++) { 1153 1159 if (!nvmet_is_ascii(page[pos])) 1154 1160 return -EINVAL;
+17 -16
drivers/nvme/target/core.c
··· 864 864 865 865 static u16 nvmet_parse_io_cmd(struct nvmet_req *req) 866 866 { 867 - struct nvme_command *cmd = req->cmd; 868 867 u16 ret; 869 868 870 - ret = nvmet_check_ctrl_status(req, cmd); 869 + ret = nvmet_check_ctrl_status(req); 871 870 if (unlikely(ret)) 872 871 return ret; 873 872 ··· 1178 1179 ctrl->cap |= NVMET_QUEUE_SIZE - 1; 1179 1180 } 1180 1181 1181 - u16 nvmet_ctrl_find_get(const char *subsysnqn, const char *hostnqn, u16 cntlid, 1182 - struct nvmet_req *req, struct nvmet_ctrl **ret) 1182 + struct nvmet_ctrl *nvmet_ctrl_find_get(const char *subsysnqn, 1183 + const char *hostnqn, u16 cntlid, 1184 + struct nvmet_req *req) 1183 1185 { 1186 + struct nvmet_ctrl *ctrl = NULL; 1184 1187 struct nvmet_subsys *subsys; 1185 - struct nvmet_ctrl *ctrl; 1186 - u16 status = 0; 1187 1188 1188 1189 subsys = nvmet_find_get_subsys(req->port, subsysnqn); 1189 1190 if (!subsys) { 1190 1191 pr_warn("connect request for invalid subsystem %s!\n", 1191 1192 subsysnqn); 1192 1193 req->cqe->result.u32 = IPO_IATTR_CONNECT_DATA(subsysnqn); 1193 - return NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR; 1194 + goto out; 1194 1195 } 1195 1196 1196 1197 mutex_lock(&subsys->lock); ··· 1203 1204 if (!kref_get_unless_zero(&ctrl->ref)) 1204 1205 continue; 1205 1206 1206 - *ret = ctrl; 1207 - goto out; 1207 + /* ctrl found */ 1208 + goto found; 1208 1209 } 1209 1210 } 1210 1211 1212 + ctrl = NULL; /* ctrl not found */ 1211 1213 pr_warn("could not find controller %d for subsys %s / host %s\n", 1212 1214 cntlid, subsysnqn, hostnqn); 1213 1215 req->cqe->result.u32 = IPO_IATTR_CONNECT_DATA(cntlid); 1214 - status = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR; 1215 1216 1216 - out: 1217 + found: 1217 1218 mutex_unlock(&subsys->lock); 1218 1219 nvmet_subsys_put(subsys); 1219 - return status; 1220 + out: 1221 + return ctrl; 1220 1222 } 1221 1223 1222 - u16 nvmet_check_ctrl_status(struct nvmet_req *req, struct nvme_command *cmd) 1224 + u16 nvmet_check_ctrl_status(struct nvmet_req *req) 1223 1225 { 1224 1226 if (unlikely(!(req->sq->ctrl->cc & NVME_CC_ENABLE))) { 1225 1227 pr_err("got cmd %d while CC.EN == 0 on qid = %d\n", 1226 - cmd->common.opcode, req->sq->qid); 1228 + req->cmd->common.opcode, req->sq->qid); 1227 1229 return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR; 1228 1230 } 1229 1231 1230 1232 if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) { 1231 1233 pr_err("got cmd %d while CSTS.RDY == 0 on qid = %d\n", 1232 - cmd->common.opcode, req->sq->qid); 1234 + req->cmd->common.opcode, req->sq->qid); 1233 1235 return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR; 1234 1236 } 1235 1237 return 0; ··· 1311 1311 pr_warn("connect request for invalid subsystem %s!\n", 1312 1312 subsysnqn); 1313 1313 req->cqe->result.u32 = IPO_IATTR_CONNECT_DATA(subsysnqn); 1314 + req->error_loc = offsetof(struct nvme_common_command, dptr); 1314 1315 goto out; 1315 1316 } 1316 1317 1317 - status = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR; 1318 1318 down_read(&nvmet_config_sem); 1319 1319 if (!nvmet_host_allowed(subsys, hostnqn)) { 1320 1320 pr_info("connect by host %s for subsystem %s not allowed\n", ··· 1322 1322 req->cqe->result.u32 = IPO_IATTR_CONNECT_DATA(hostnqn); 1323 1323 up_read(&nvmet_config_sem); 1324 1324 status = NVME_SC_CONNECT_INVALID_HOST | NVME_SC_DNR; 1325 + req->error_loc = offsetof(struct nvme_common_command, dptr); 1325 1326 goto out_put_subsystem; 1326 1327 } 1327 1328 up_read(&nvmet_config_sem);
+4 -2
drivers/nvme/target/discovery.c
··· 178 178 if (req->cmd->get_log_page.lid != NVME_LOG_DISC) { 179 179 req->error_loc = 180 180 offsetof(struct nvme_get_log_page_command, lid); 181 - status = NVME_SC_INVALID_OPCODE | NVME_SC_DNR; 181 + status = NVME_SC_INVALID_FIELD | NVME_SC_DNR; 182 182 goto out; 183 183 } 184 184 185 185 /* Spec requires dword aligned offsets */ 186 186 if (offset & 0x3) { 187 + req->error_loc = 188 + offsetof(struct nvme_get_log_page_command, lpo); 187 189 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR; 188 190 goto out; 189 191 } ··· 252 250 253 251 if (req->cmd->identify.cns != NVME_ID_CNS_CTRL) { 254 252 req->error_loc = offsetof(struct nvme_identify, cns); 255 - status = NVME_SC_INVALID_OPCODE | NVME_SC_DNR; 253 + status = NVME_SC_INVALID_FIELD | NVME_SC_DNR; 256 254 goto out; 257 255 } 258 256
+7 -10
drivers/nvme/target/fabrics-cmd.c
··· 190 190 191 191 status = nvmet_alloc_ctrl(d->subsysnqn, d->hostnqn, req, 192 192 le32_to_cpu(c->kato), &ctrl); 193 - if (status) { 194 - if (status == (NVME_SC_INVALID_FIELD | NVME_SC_DNR)) 195 - req->error_loc = 196 - offsetof(struct nvme_common_command, opcode); 193 + if (status) 197 194 goto out; 198 - } 199 195 200 196 ctrl->pi_support = ctrl->port->pi_enable && ctrl->subsys->pi_support; 201 197 ··· 218 222 { 219 223 struct nvmf_connect_command *c = &req->cmd->connect; 220 224 struct nvmf_connect_data *d; 221 - struct nvmet_ctrl *ctrl = NULL; 225 + struct nvmet_ctrl *ctrl; 222 226 u16 qid = le16_to_cpu(c->qid); 223 227 u16 status = 0; 224 228 ··· 245 249 goto out; 246 250 } 247 251 248 - status = nvmet_ctrl_find_get(d->subsysnqn, d->hostnqn, 249 - le16_to_cpu(d->cntlid), 250 - req, &ctrl); 251 - if (status) 252 + ctrl = nvmet_ctrl_find_get(d->subsysnqn, d->hostnqn, 253 + le16_to_cpu(d->cntlid), req); 254 + if (!ctrl) { 255 + status = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR; 252 256 goto out; 257 + } 253 258 254 259 if (unlikely(qid > ctrl->subsys->max_qid)) { 255 260 pr_warn("invalid queue id (%d)\n", qid);
+1
drivers/nvme/target/fc.c
··· 1996 1996 * 1997 1997 * @target_port: pointer to the (registered) target port the LS was 1998 1998 * received on. 1999 + * @hosthandle: pointer to the host specific data, gets stored in iod. 1999 2000 * @lsrsp: pointer to a lsrsp structure to be used to reference 2000 2001 * the exchange corresponding to the LS. 2001 2002 * @lsreqbuf: pointer to the buffer containing the LS Request
+4 -2
drivers/nvme/target/loop.c
··· 141 141 if (!nvmf_check_ready(&queue->ctrl->ctrl, req, queue_ready)) 142 142 return nvmf_fail_nonready_command(&queue->ctrl->ctrl, req); 143 143 144 - ret = nvme_setup_cmd(ns, req, &iod->cmd); 144 + ret = nvme_setup_cmd(ns, req); 145 145 if (ret) 146 146 return ret; 147 147 ··· 205 205 unsigned int numa_node) 206 206 { 207 207 struct nvme_loop_ctrl *ctrl = set->driver_data; 208 + struct nvme_loop_iod *iod = blk_mq_rq_to_pdu(req); 208 209 209 210 nvme_req(req)->ctrl = &ctrl->ctrl; 211 + nvme_req(req)->cmd = &iod->cmd; 210 212 return nvme_loop_init_iod(ctrl, blk_mq_rq_to_pdu(req), 211 213 (set == &ctrl->tag_set) ? hctx_idx + 1 : 0); 212 214 } ··· 398 396 399 397 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q); 400 398 401 - error = nvme_init_identify(&ctrl->ctrl); 399 + error = nvme_init_ctrl_finish(&ctrl->ctrl); 402 400 if (error) 403 401 goto out_cleanup_queue; 404 402
+5 -3
drivers/nvme/target/nvmet.h
··· 27 27 #define NVMET_ERROR_LOG_SLOTS 128 28 28 #define NVMET_NO_ERROR_LOC ((u16)-1) 29 29 #define NVMET_DEFAULT_CTRL_MODEL "Linux" 30 + #define NVMET_MN_MAX_SIZE 40 30 31 31 32 /* 32 33 * Supported optional AENs: ··· 429 428 void nvmet_update_cc(struct nvmet_ctrl *ctrl, u32 new); 430 429 u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, 431 430 struct nvmet_req *req, u32 kato, struct nvmet_ctrl **ctrlp); 432 - u16 nvmet_ctrl_find_get(const char *subsysnqn, const char *hostnqn, u16 cntlid, 433 - struct nvmet_req *req, struct nvmet_ctrl **ret); 431 + struct nvmet_ctrl *nvmet_ctrl_find_get(const char *subsysnqn, 432 + const char *hostnqn, u16 cntlid, 433 + struct nvmet_req *req); 434 434 void nvmet_ctrl_put(struct nvmet_ctrl *ctrl); 435 - u16 nvmet_check_ctrl_status(struct nvmet_req *req, struct nvme_command *cmd); 435 + u16 nvmet_check_ctrl_status(struct nvmet_req *req); 436 436 437 437 struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, 438 438 enum nvme_subsys_type type);
+36 -4
drivers/nvme/target/tcp.c
··· 29 29 module_param(so_priority, int, 0644); 30 30 MODULE_PARM_DESC(so_priority, "nvmet tcp socket optimize priority"); 31 31 32 + /* Define a time period (in usecs) that io_work() shall sample an activated 33 + * queue before determining it to be idle. This optional module behavior 34 + * can enable NIC solutions that support socket optimized packet processing 35 + * using advanced interrupt moderation techniques. 36 + */ 37 + static int idle_poll_period_usecs; 38 + module_param(idle_poll_period_usecs, int, 0644); 39 + MODULE_PARM_DESC(idle_poll_period_usecs, 40 + "nvmet tcp io_work poll till idle time period in usecs"); 41 + 32 42 #define NVMET_TCP_RECV_BUDGET 8 33 43 #define NVMET_TCP_SEND_BUDGET 8 34 44 #define NVMET_TCP_IO_WORK_BUDGET 64 ··· 128 118 bool data_digest; 129 119 struct ahash_request *snd_hash; 130 120 struct ahash_request *rcv_hash; 121 + 122 + unsigned long poll_end; 131 123 132 124 spinlock_t state_lock; 133 125 enum nvmet_tcp_queue_state state; ··· 1228 1216 spin_unlock(&queue->state_lock); 1229 1217 } 1230 1218 1219 + static inline void nvmet_tcp_arm_queue_deadline(struct nvmet_tcp_queue *queue) 1220 + { 1221 + queue->poll_end = jiffies + usecs_to_jiffies(idle_poll_period_usecs); 1222 + } 1223 + 1224 + static bool nvmet_tcp_check_queue_deadline(struct nvmet_tcp_queue *queue, 1225 + int ops) 1226 + { 1227 + if (!idle_poll_period_usecs) 1228 + return false; 1229 + 1230 + if (ops) 1231 + nvmet_tcp_arm_queue_deadline(queue); 1232 + 1233 + return !time_after(jiffies, queue->poll_end); 1234 + } 1235 + 1231 1236 static void nvmet_tcp_io_work(struct work_struct *w) 1232 1237 { 1233 1238 struct nvmet_tcp_queue *queue = ··· 1270 1241 } while (pending && ops < NVMET_TCP_IO_WORK_BUDGET); 1271 1242 1272 1243 /* 1273 - * We exahusted our budget, requeue our selves 1244 + * Requeue the worker if idle deadline period is in progress or any 1245 + * ops activity was recorded during the do-while loop above. 1274 1246 */ 1275 - if (pending) 1247 + if (nvmet_tcp_check_queue_deadline(queue, ops) || pending) 1276 1248 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); 1277 1249 } 1278 1250 ··· 1464 1434 { 1465 1435 struct nvmet_tcp_queue *queue; 1466 1436 1467 - write_lock_bh(&sk->sk_callback_lock); 1437 + read_lock_bh(&sk->sk_callback_lock); 1468 1438 queue = sk->sk_user_data; 1469 1439 if (!queue) 1470 1440 goto done; ··· 1482 1452 queue->idx, sk->sk_state); 1483 1453 } 1484 1454 done: 1485 - write_unlock_bh(&sk->sk_callback_lock); 1455 + read_unlock_bh(&sk->sk_callback_lock); 1486 1456 } 1487 1457 1488 1458 static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) ··· 1531 1501 sock->sk->sk_state_change = nvmet_tcp_state_change; 1532 1502 queue->write_space = sock->sk->sk_write_space; 1533 1503 sock->sk->sk_write_space = nvmet_tcp_write_space; 1504 + if (idle_poll_period_usecs) 1505 + nvmet_tcp_arm_queue_deadline(queue); 1534 1506 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); 1535 1507 } 1536 1508 write_unlock_bh(&sock->sk->sk_callback_lock);
+10
include/linux/nvme.h
··· 405 405 __u8 rsvd1[4095]; 406 406 }; 407 407 408 + struct nvme_id_ctrl_nvm { 409 + __u8 vsl; 410 + __u8 wzsl; 411 + __u8 wusl; 412 + __u8 dmrl; 413 + __le32 dmrsl; 414 + __le64 dmsl; 415 + __u8 rsvd16[4080]; 416 + }; 417 + 408 418 enum { 409 419 NVME_ID_CNS_NS = 0x00, 410 420 NVME_ID_CNS_CTRL = 0x01,