nvme: enable retries for authentication commands
Subsystems (2)
PATCH v2 1/1 nvme: enable retries for authentication commands
From: Hannes Reinecke <[email protected]>
Authentication commands are normal NVMe commands, and as such can return a status where NVME_SC_DNR is not set, indicating that the command should be retried.
This patch combines the two arguments 'at_head' and 'flags' from __nvme_submit_sync_cmd() into a new 'nvme_submit_flags_t' argument, and enables retries by setting NVME_SUBMIT_RETRY.
--- drivers/nvme/host/auth.c | 8 ++++---- drivers/nvme/host/core.c | 21 ++++++++++++++------- drivers/nvme/host/fabrics.c | 18 +++++++++++------- drivers/nvme/host/nvme.h | 12 ++++++++++-- 4 files changed, 39 insertions(+), 20 deletions(-)
drivers/nvme/host/auth.c +4 -4
@@ -50,7 +50,8 @@ struct nvme_dhchap_queue_context {static struct workqueue_struct *nvme_auth_wq;#define nvme_auth_flags_from_qid (qid) \ - (qid == 0) ? 0 : BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED + (qid == 0) ? NVME_SUBMIT_RETRY : \ + NVME_SUBMIT_RETRY | NVME_SUBMIT_NOWAIT | NVME_SUBMIT_RESERVED#define nvme_auth_queue_from_qid (ctrl, qid) \ (qid == 0) ? (ctrl)->fabrics_q : (ctrl)->connect_q
@@ -64,7 +65,7 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid, void *data, size_t data_len, bool auth_send) { struct nvme_command cmd = {}; -blk_mq_req_flags_t flags =nvme_auth_flags_from_qid (qid); +nvme_submit_flags_t flags =nvme_auth_flags_from_qid (qid);struct request_queue *q =nvme_auth_queue_from_qid (ctrl, qid);int ret;
@@ -81,8 +82,7 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid, } ret =__nvme_submit_sync_cmd (q, &cmd,NULL , data, data_len, - qid ==0 ?NVME_QID_ANY : qid, -0 , flags); + qid ==0 ?NVME_QID_ANY : qid, flags);if (ret >0 )dev_warn (ctrl->device,"qid %d auth_send failed with status %d\n" , qid, ret);
drivers/nvme/host/core.c +14 -7
@@ -1049,20 +1049,27 @@ EXPORT_SYMBOL_NS_GPL(nvme_execute_rq, NVME_TARGET_PASSTHRU);*/ int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,union nvme_result *result,void *buffer,unsigned bufflen, -int qid,int at_head,blk_mq_req_flags_t flags) +int qid,nvme_submit_flags_t flags) {struct request *req;int ret; +blk_mq_req_flags_t blk_flags =0 ; +if (flags &NVME_SUBMIT_NOWAIT ) + blk_flags |=BLK_MQ_REQ_NOWAIT ; +if (flags &NVME_SUBMIT_RESERVED ) + blk_flags |=BLK_MQ_REQ_RESERVED ;if (qid ==NVME_QID_ANY ) - req =blk_mq_alloc_request (q,nvme_req_op (cmd), flags); + req =blk_mq_alloc_request (q,nvme_req_op (cmd), blk_flags);else - req =blk_mq_alloc_request_hctx (q,nvme_req_op (cmd), flags, + req =blk_mq_alloc_request_hctx (q,nvme_req_op (cmd), blk_flags, qid -1 );if (IS_ERR (req))return PTR_ERR (req);nvme_init_request (req, cmd); +if (flags &NVME_SUBMIT_RETRY ) + req->cmd_flags &= ~REQ_FAILFAST_DRIVER ;if (buffer && bufflen) { ret =blk_rq_map_kern (q, req, buffer, bufflen,GFP_KERNEL );
@@ -1070,7 +1077,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, goto out; } - ret =nvme_execute_rq (req, at_head); + ret =nvme_execute_rq (req, flags &NVME_SUBMIT_AT_HEAD );if (result && ret >=0 ) *result =nvme_req (req)->result; out:
@@ -1083,7 +1090,7 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, void *buffer, unsigned bufflen) {return __nvme_submit_sync_cmd (q, cmd,NULL , buffer, bufflen, -NVME_QID_ANY ,0 ,0 ); +NVME_QID_ANY ,0 ); }EXPORT_SYMBOL_GPL (nvme_submit_sync_cmd);
@@ -1547,7 +1554,7 @@ static int nvme_features(struct nvme_ctrl *dev, u8 op, unsigned int fid, c.features.dword11 =cpu_to_le32 (dword11); ret =__nvme_submit_sync_cmd (dev->admin_q, &c, &res, - buffer, buflen,NVME_QID_ANY ,0 ,0 ); + buffer, buflen,NVME_QID_ANY ,NVME_SUBMIT_RETRY );if (ret >=0 && result) *result =le32_to_cpu (res.u32);return ret;
@@ -2149,7 +2156,7 @@ static int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t l cmd.common.cdw11 =cpu_to_le32 (len);return __nvme_submit_sync_cmd (ctrl->admin_q, &cmd,NULL , buffer, len, -NVME_QID_ANY ,1 ,0 ); +NVME_QID_ANY ,NVME_SUBMIT_AT_HEAD ); }static void nvme_configure_opal (struct nvme_ctrl *ctrl,bool was_suspended)
drivers/nvme/host/fabrics.c +11 -7
@@ -180,7 +180,7 @@ int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val) cmd.prop_get.offset =cpu_to_le32 (off); ret =__nvme_submit_sync_cmd (ctrl->fabrics_q, &cmd, &res,NULL ,0 , -NVME_QID_ANY ,0 ,0 ); +NVME_QID_ANY ,0 );if (ret >=0 ) *val =le64_to_cpu (res.u64);
@@ -226,7 +226,7 @@ int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val) cmd.prop_get.offset =cpu_to_le32 (off); ret =__nvme_submit_sync_cmd (ctrl->fabrics_q, &cmd, &res,NULL ,0 , -NVME_QID_ANY ,0 ,0 ); +NVME_QID_ANY ,0 );if (ret >=0 ) *val =le64_to_cpu (res.u64);
@@ -271,7 +271,7 @@ int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val) cmd.prop_set.value =cpu_to_le64 (val); ret =__nvme_submit_sync_cmd (ctrl->fabrics_q, &cmd,NULL ,NULL ,0 , -NVME_QID_ANY ,0 ,0 ); +NVME_QID_ANY ,0 );if (unlikely (ret)) dev_err(ctrl->device, "Property Set error: %d, offset %#x\n",
@@ -450,8 +450,10 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl)return -ENOMEM ; ret =__nvme_submit_sync_cmd (ctrl->fabrics_q, &cmd, &res, - data,sizeof (*data),NVME_QID_ANY ,1 , -BLK_MQ_REQ_RESERVED |BLK_MQ_REQ_NOWAIT ); + data,sizeof (*data),NVME_QID_ANY , +NVME_SUBMIT_AT_HEAD | +NVME_SUBMIT_NOWAIT | +NVME_SUBMIT_RESERVED );if (ret) {nvmf_log_connect_error (ctrl, ret,le32_to_cpu (res.u32), &cmd, data);
@@ -526,8 +528,10 @@ int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid)return -ENOMEM ; ret =__nvme_submit_sync_cmd (ctrl->connect_q, &cmd, &res, - data,sizeof (*data), qid,1 , -BLK_MQ_REQ_RESERVED |BLK_MQ_REQ_NOWAIT ); + data,sizeof (*data), qid, +NVME_SUBMIT_AT_HEAD | +NVME_SUBMIT_RESERVED | +NVME_SUBMIT_NOWAIT );if (ret) {nvmf_log_connect_error (ctrl, ret,le32_to_cpu (res.u32), &cmd, data);
drivers/nvme/host/nvme.h +10 -2
@@ -824,12 +824,20 @@ static inline bool nvme_is_unique_nsid(struct nvme_ctrl *ctrl, (ctrl->ctratt &NVME_CTRL_CTRATT_NVM_SETS ); } +typedef __u32 __bitwise nvme_submit_flags_t ; + +enum { +NVME_SUBMIT_AT_HEAD = (__force nvme_submit_flags_t)(1 <<0 ), +NVME_SUBMIT_NOWAIT = (__force nvme_submit_flags_t)(1 <<1 ), +NVME_SUBMIT_RESERVED = (__force nvme_submit_flags_t)(1 <<2 ), +NVME_SUBMIT_RETRY = (__force nvme_submit_flags_t)(1 <<3 ), +}; +int nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,void *buf,unsigned bufflen);int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,union nvme_result *result,void *buffer,unsigned bufflen, -int qid,int at_head, -blk_mq_req_flags_t flags); +int qid,nvme_submit_flags_t flags);int nvme_set_features (struct nvme_ctrl *dev,unsigned int fid,unsigned int dword11,void *buffer,size_t buflen,u32 *result);
Signature · 1 line
2.35.3
Christoph Hellwig
maintainerdrivers/nvme/host/auth.c struct nvme_dhchap_queue_context { · line 56
Quoted 6 lines · On Fri, Jan 26, 2024 at 07:37:09AM +0100, [email protected] wrote:
#define
nvme_auth_flags_from_qid(qid)\drivers/nvme/host/auth.c +2
-1- (qid == 0) ? 0 : BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED + (qid ==0 ) ?NVME_SUBMIT_RETRY : \ + NVME_SUBMIT_RETRY | NVME_SUBMIT_NOWAIT | NVME_SUBMIT_RESERVED#define nvme_auth_queue_from_qid (ctrl, qid) \ (qid == 0) ? (ctrl)->fabrics_q : (ctrl)->connect_q
Please just open code these two obfuscating macros with a single user each to make the change easily reviewable. That also means after that you only nee to assign NVME_SUBMIT_RETRY once and not in both side of a ternary operator.
drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid, · line 85
Quoted 4 lines
drivers/nvme/host/auth.c +1
-2ret =__nvme_submit_sync_cmd (q, &cmd,NULL , data, data_len, - qid ==0 ?NVME_QID_ANY : qid, -0 , flags); + qid ==0 ?NVME_QID_ANY : qid, flags);
And then split addition the calling convention change for the request submission helpers from the actual behavior change into a well documented prep patch as well.
drivers/nvme/host/nvme.h static inline bool nvme_is_unique_nsid(struct nvme_ctrl *ctrl, · line 833
Quoted 5 lines
drivers/nvme/host/nvme.h +5
-0+enum { +NVME_SUBMIT_AT_HEAD = (__force nvme_submit_flags_t)(1 <<0 ), +NVME_SUBMIT_NOWAIT = (__force nvme_submit_flags_t)(1 <<1 ), +NVME_SUBMIT_RESERVED = (__force nvme_submit_flags_t)(1 <<2 ), +NVME_SUBMIT_RETRY = (__force nvme_submit_flags_t)(1 <<3 ),
Maybe write some comments explaining the semantics while you're at it?
Hannes Reinecke
maintainerQuoted 13 lines · Christoph Hellwig
drivers/nvme/host/auth.c struct nvme_dhchap_queue_context { · line 56
Quoted 6 lines · On Fri, Jan 26, 2024 at 07:37:09AM +0100, [email protected] wrote:
#define nvme_auth_flags_from_qid(qid) \drivers/nvme/host/auth.c +2
-1- (qid == 0) ? 0 : BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED + (qid ==0 ) ?NVME_SUBMIT_RETRY : \ + NVME_SUBMIT_RETRY | NVME_SUBMIT_NOWAIT | NVME_SUBMIT_RESERVED#define nvme_auth_queue_from_qid (ctrl, qid) \ (qid == 0) ? (ctrl)->fabrics_q : (ctrl)->connect_qPlease just open code these two obfuscating macros with a single user each to make the change easily reviewable. That also means after that you only nee to assign
NVME_SUBMIT_RETRYonce and not in both side of a ternary operator.
Ok.
Quoted 9 lines
drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid, · line 85
Quoted 4 lines
ret = __nvme_submit_sync_cmd(q, &cmd, NULL, data,
data_len,drivers/nvme/host/auth.c +1
-2- qid ==0 ?NVME_QID_ANY : qid, - 0, flags); + qid == 0 ? NVME_QID_ANY : qid, flags);And then split addition the calling convention change for the request submission helpers from the actual behavior change into a well documented prep patch as well.
Let's see about the 'well-documented', but I'll try. Ok.
Quoted 8 lines
drivers/nvme/host/nvme.h static inline bool nvme_is_unique_nsid(struct nvme_ctrl *ctrl, · line 833
Quoted 5 lines
drivers/nvme/host/nvme.h +5
-0+enum { +NVME_SUBMIT_AT_HEAD = (__force nvme_submit_flags_t)(1 <<0 ), +NVME_SUBMIT_NOWAIT = (__force nvme_submit_flags_t)(1 <<1 ), +NVME_SUBMIT_RESERVED = (__force nvme_submit_flags_t)(1 <<2 ), +NVME_SUBMIT_RETRY = (__force nvme_submit_flags_t)(1 <<3 ),Maybe write some comments explaining the semantics while you're at it?
Maybe.
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Ivo Totev, Andrew McDonald, Werner Knoblich
Keith Busch
maintainerQuoted 16 lines · On Fri, Jan 26, 2024 at 07:37:09AM +0100, [email protected] wrote:
int __nvme_submit_sync_cmd(struct
request_queue*q, structnvme_command*cmd,drivers/nvme/host/core.c +7
-2union nvme_result *result, void *buffer, unsigned bufflen, - int qid, int at_head, blk_mq_req_flags_t flags) + int qid, nvme_submit_flags_t flags) { struct request *req;int ret; +blk_mq_req_flags_t blk_flags =0 ; +if (flags &NVME_SUBMIT_NOWAIT ) + blk_flags |=BLK_MQ_REQ_NOWAIT ; +if (flags &NVME_SUBMIT_RESERVED ) + blk_flags |=BLK_MQ_REQ_RESERVED ;if (qid ==NVME_QID_ANY ) - req =blk_mq_alloc_request (q,nvme_req_op (cmd), flags); + req =blk_mq_alloc_request (q,nvme_req_op (cmd), blk_flags);
drivers/nvme/host/core.c EXPORT_SYMBOL_NS_GPL(nvme_execute_rq, NVME_TARGET_PASSTHRU); · line 1072
Quoted 10 lines
drivers/nvme/host/core.c +3
-1else - req =blk_mq_alloc_request_hctx (q,nvme_req_op (cmd), flags, + req =blk_mq_alloc_request_hctx (q,nvme_req_op (cmd), blk_flags, qid -1 );if (IS_ERR (req))return PTR_ERR (req);nvme_init_request (req, cmd); +if (flags &NVME_SUBMIT_RETRY ) + req->cmd_flags &= ~REQ_FAILFAST_DRIVER ;
I think it'd be a bit easier to review if you do a prep patch to introduce nvme_submit_flags without adding any new behavior first.