* nvme fabrics authentication fixups
@ 2022-09-20 17:19 Christoph Hellwig
2022-09-20 17:19 ` [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct Christoph Hellwig
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Christoph Hellwig @ 2022-09-20 17:19 UTC (permalink / raw)
To: Sagi Grimberg, Hannes Reinecke, Chaitanya Kulkarni; +Cc: linux-nvme
Hi all,
this little series fixed a debugobjects complaint with the new
authentication code, and some other bits while looking at it.
Btw: Hannes, can we add you as a co-maintainer for the auth code?
Diffstat:
drivers/nvme/target/core.c | 1 +
drivers/nvme/target/fabrics-cmd-auth.c | 13 ++++---------
drivers/nvme/target/fabrics-cmd.c | 18 ++++++++----------
drivers/nvme/target/nvmet.h | 7 ++++---
include/linux/nvme.h | 4 ++--
5 files changed, 19 insertions(+), 24 deletions(-)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct
2022-09-20 17:19 nvme fabrics authentication fixups Christoph Hellwig
@ 2022-09-20 17:19 ` Christoph Hellwig
2022-09-21 6:15 ` Hannes Reinecke
2022-09-21 9:23 ` Sagi Grimberg
2022-09-20 17:19 ` [PATCH 2/3] nvme: improve the NVME_CONNECT_AUTHREQ* definitions Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 2 replies; 11+ messages in thread
From: Christoph Hellwig @ 2022-09-20 17:19 UTC (permalink / raw)
To: Sagi Grimberg, Hannes Reinecke, Chaitanya Kulkarni; +Cc: linux-nvme
Currently blktests nvme/002 trips up debugobjects if CONFIG_NVME_AUTH is
enabled, but authentication is not on a queue. This is because
nvmet_auth_sq_free cancels sq->auth_expired_work unconditionaly, while
auth_expired_work is only ever initialized if authentication is enabled
for a given controller.
Fix this by calling most of what is nvmet_init_auth unconditionally
when initializing the SQ, and just do the setting of the result
field in the connect command handler.
Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/target/core.c | 1 +
drivers/nvme/target/fabrics-cmd-auth.c | 13 ++++---------
drivers/nvme/target/fabrics-cmd.c | 6 ++++--
drivers/nvme/target/nvmet.h | 7 ++++---
4 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index a1345790005f4..8e3cf0c3588ce 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -830,6 +830,7 @@ int nvmet_sq_init(struct nvmet_sq *sq)
}
init_completion(&sq->free_done);
init_completion(&sq->confirm_done);
+ nvmet_auth_sq_init(sq);
return 0;
}
diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
index 84601e38a335a..7970a7640e585 100644
--- a/drivers/nvme/target/fabrics-cmd-auth.c
+++ b/drivers/nvme/target/fabrics-cmd-auth.c
@@ -23,17 +23,12 @@ static void nvmet_auth_expired_work(struct work_struct *work)
sq->dhchap_tid = -1;
}
-void nvmet_init_auth(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
+void nvmet_auth_sq_init(struct nvmet_sq *sq)
{
- u32 result = le32_to_cpu(req->cqe->result.u32);
-
/* Initialize in-band authentication */
- INIT_DELAYED_WORK(&req->sq->auth_expired_work,
- nvmet_auth_expired_work);
- req->sq->authenticated = false;
- req->sq->dhchap_step = NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE;
- result |= (u32)NVME_CONNECT_AUTHREQ_ATR << 16;
- req->cqe->result.u32 = cpu_to_le32(result);
+ INIT_DELAYED_WORK(&sq->auth_expired_work, nvmet_auth_expired_work);
+ sq->authenticated = false;
+ sq->dhchap_step = NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE;
}
static u16 nvmet_auth_negotiate(struct nvmet_req *req, void *d)
diff --git a/drivers/nvme/target/fabrics-cmd.c b/drivers/nvme/target/fabrics-cmd.c
index c1dfdfb92ebf0..c7e903589d377 100644
--- a/drivers/nvme/target/fabrics-cmd.c
+++ b/drivers/nvme/target/fabrics-cmd.c
@@ -272,7 +272,8 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
req->cqe->result.u16 = cpu_to_le16(ctrl->cntlid);
if (nvmet_has_auth(ctrl))
- nvmet_init_auth(ctrl, req);
+ req->cqe->result.u32 |=
+ cpu_to_le32((u32)NVME_CONNECT_AUTHREQ_ATR << 16);
out:
kfree(d);
complete:
@@ -333,7 +334,8 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)
pr_debug("adding queue %d to ctrl %d.\n", qid, ctrl->cntlid);
if (nvmet_has_auth(ctrl))
- nvmet_init_auth(ctrl, req);
+ req->cqe->result.u32 |=
+ cpu_to_le32((u32)NVME_CONNECT_AUTHREQ_ATR << 16);
out:
kfree(d);
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 6ffeeb0a1c49e..dfe3894205aa7 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -704,7 +704,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
bool set_ctrl);
int nvmet_auth_set_host_hash(struct nvmet_host *host, const char *hash);
int nvmet_setup_auth(struct nvmet_ctrl *ctrl);
-void nvmet_init_auth(struct nvmet_ctrl *ctrl, struct nvmet_req *req);
+void nvmet_auth_sq_init(struct nvmet_sq *sq);
void nvmet_destroy_auth(struct nvmet_ctrl *ctrl);
void nvmet_auth_sq_free(struct nvmet_sq *sq);
int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id);
@@ -726,8 +726,9 @@ static inline int nvmet_setup_auth(struct nvmet_ctrl *ctrl)
{
return 0;
}
-static inline void nvmet_init_auth(struct nvmet_ctrl *ctrl,
- struct nvmet_req *req) {};
+static inline void nvmet_auth_sq_init(struct nvmet_sq *sq)
+{
+}
static inline void nvmet_destroy_auth(struct nvmet_ctrl *ctrl) {};
static inline void nvmet_auth_sq_free(struct nvmet_sq *sq) {};
static inline bool nvmet_check_auth_status(struct nvmet_req *req)
--
2.30.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/3] nvme: improve the NVME_CONNECT_AUTHREQ* definitions
2022-09-20 17:19 nvme fabrics authentication fixups Christoph Hellwig
2022-09-20 17:19 ` [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct Christoph Hellwig
@ 2022-09-20 17:19 ` Christoph Hellwig
2022-09-21 6:13 ` Hannes Reinecke
2022-09-21 9:24 ` Sagi Grimberg
2022-09-20 17:19 ` [PATCH 3/3] nvmet: add helpers to set the result field for connect commands Christoph Hellwig
2022-09-21 6:10 ` nvme fabrics authentication fixups Hannes Reinecke
3 siblings, 2 replies; 11+ messages in thread
From: Christoph Hellwig @ 2022-09-20 17:19 UTC (permalink / raw)
To: Sagi Grimberg, Hannes Reinecke, Chaitanya Kulkarni; +Cc: linux-nvme
Mark them as unsigned so that we don't need extra casts, and define
them relative to cdword0 instead of requiring extra shifts.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/target/fabrics-cmd.c | 6 ++----
include/linux/nvme.h | 4 ++--
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/target/fabrics-cmd.c b/drivers/nvme/target/fabrics-cmd.c
index c7e903589d377..618f7adca70fd 100644
--- a/drivers/nvme/target/fabrics-cmd.c
+++ b/drivers/nvme/target/fabrics-cmd.c
@@ -272,8 +272,7 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
req->cqe->result.u16 = cpu_to_le16(ctrl->cntlid);
if (nvmet_has_auth(ctrl))
- req->cqe->result.u32 |=
- cpu_to_le32((u32)NVME_CONNECT_AUTHREQ_ATR << 16);
+ req->cqe->result.u32 |= cpu_to_le32(NVME_CONNECT_AUTHREQ_ATR);
out:
kfree(d);
complete:
@@ -334,8 +333,7 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)
pr_debug("adding queue %d to ctrl %d.\n", qid, ctrl->cntlid);
if (nvmet_has_auth(ctrl))
- req->cqe->result.u32 |=
- cpu_to_le32((u32)NVME_CONNECT_AUTHREQ_ATR << 16);
+ req->cqe->result.u32 |= cpu_to_le32(NVME_CONNECT_AUTHREQ_ATR);
out:
kfree(d);
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index ae53d74f3696a..050d7d0cd81b0 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -1482,8 +1482,8 @@ struct nvmf_connect_command {
};
enum {
- NVME_CONNECT_AUTHREQ_ASCR = (1 << 2),
- NVME_CONNECT_AUTHREQ_ATR = (1 << 1),
+ NVME_CONNECT_AUTHREQ_ASCR = (1U << 18),
+ NVME_CONNECT_AUTHREQ_ATR = (1U << 17),
};
struct nvmf_connect_data {
--
2.30.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3] nvmet: add helpers to set the result field for connect commands
2022-09-20 17:19 nvme fabrics authentication fixups Christoph Hellwig
2022-09-20 17:19 ` [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct Christoph Hellwig
2022-09-20 17:19 ` [PATCH 2/3] nvme: improve the NVME_CONNECT_AUTHREQ* definitions Christoph Hellwig
@ 2022-09-20 17:19 ` Christoph Hellwig
2022-09-21 6:14 ` Hannes Reinecke
2022-09-21 9:24 ` Sagi Grimberg
2022-09-21 6:10 ` nvme fabrics authentication fixups Hannes Reinecke
3 siblings, 2 replies; 11+ messages in thread
From: Christoph Hellwig @ 2022-09-20 17:19 UTC (permalink / raw)
To: Sagi Grimberg, Hannes Reinecke, Chaitanya Kulkarni; +Cc: linux-nvme
The code to set the result field for the admin and I/O connect commands
is not only verbose and duplicated, but also violates the aliasing
rules as it accesses both the u16 and u32 members in the union.
Add a little helper to sort all that out.
Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/target/fabrics-cmd.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/nvme/target/fabrics-cmd.c b/drivers/nvme/target/fabrics-cmd.c
index 618f7adca70fd..43b5bd8bb6a52 100644
--- a/drivers/nvme/target/fabrics-cmd.c
+++ b/drivers/nvme/target/fabrics-cmd.c
@@ -198,6 +198,12 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
return ret;
}
+static u32 nvmet_connect_result(struct nvmet_ctrl *ctrl)
+{
+ return (u32)ctrl->cntlid |
+ (nvmet_has_auth(ctrl) ? NVME_CONNECT_AUTHREQ_ATR : 0);
+}
+
static void nvmet_execute_admin_connect(struct nvmet_req *req)
{
struct nvmf_connect_command *c = &req->cmd->connect;
@@ -269,10 +275,7 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
ctrl->cntlid, ctrl->subsys->subsysnqn, ctrl->hostnqn,
ctrl->pi_support ? " T10-PI is enabled" : "",
nvmet_has_auth(ctrl) ? " with DH-HMAC-CHAP" : "");
- req->cqe->result.u16 = cpu_to_le16(ctrl->cntlid);
-
- if (nvmet_has_auth(ctrl))
- req->cqe->result.u32 |= cpu_to_le32(NVME_CONNECT_AUTHREQ_ATR);
+ req->cqe->result.u32 = cpu_to_le32(nvmet_connect_result(ctrl));
out:
kfree(d);
complete:
@@ -328,13 +331,8 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)
if (status)
goto out_ctrl_put;
- /* pass back cntlid for successful completion */
- req->cqe->result.u16 = cpu_to_le16(ctrl->cntlid);
-
pr_debug("adding queue %d to ctrl %d.\n", qid, ctrl->cntlid);
- if (nvmet_has_auth(ctrl))
- req->cqe->result.u32 |= cpu_to_le32(NVME_CONNECT_AUTHREQ_ATR);
-
+ req->cqe->result.u32 = cpu_to_le32(nvmet_connect_result(ctrl));
out:
kfree(d);
complete:
--
2.30.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: nvme fabrics authentication fixups
2022-09-20 17:19 nvme fabrics authentication fixups Christoph Hellwig
` (2 preceding siblings ...)
2022-09-20 17:19 ` [PATCH 3/3] nvmet: add helpers to set the result field for connect commands Christoph Hellwig
@ 2022-09-21 6:10 ` Hannes Reinecke
3 siblings, 0 replies; 11+ messages in thread
From: Hannes Reinecke @ 2022-09-21 6:10 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni; +Cc: linux-nvme
On 9/20/22 19:19, Christoph Hellwig wrote:
> Hi all,
>
> this little series fixed a debugobjects complaint with the new
> authentication code, and some other bits while looking at it.
>
> Btw: Hannes, can we add you as a co-maintainer for the auth code?
>
Sure.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] nvme: improve the NVME_CONNECT_AUTHREQ* definitions
2022-09-20 17:19 ` [PATCH 2/3] nvme: improve the NVME_CONNECT_AUTHREQ* definitions Christoph Hellwig
@ 2022-09-21 6:13 ` Hannes Reinecke
2022-09-21 9:24 ` Sagi Grimberg
1 sibling, 0 replies; 11+ messages in thread
From: Hannes Reinecke @ 2022-09-21 6:13 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni; +Cc: linux-nvme
On 9/20/22 19:19, Christoph Hellwig wrote:
> Mark them as unsigned so that we don't need extra casts, and define
> them relative to cdword0 instead of requiring extra shifts.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/nvme/target/fabrics-cmd.c | 6 ++----
> include/linux/nvme.h | 4 ++--
> 2 files changed, 4 insertions(+), 6 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/3] nvmet: add helpers to set the result field for connect commands
2022-09-20 17:19 ` [PATCH 3/3] nvmet: add helpers to set the result field for connect commands Christoph Hellwig
@ 2022-09-21 6:14 ` Hannes Reinecke
2022-09-21 9:24 ` Sagi Grimberg
1 sibling, 0 replies; 11+ messages in thread
From: Hannes Reinecke @ 2022-09-21 6:14 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni; +Cc: linux-nvme
On 9/20/22 19:19, Christoph Hellwig wrote:
> The code to set the result field for the admin and I/O connect commands
> is not only verbose and duplicated, but also violates the aliasing
> rules as it accesses both the u16 and u32 members in the union.
>
> Add a little helper to sort all that out.
>
> Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/nvme/target/fabrics-cmd.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct
2022-09-20 17:19 ` [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct Christoph Hellwig
@ 2022-09-21 6:15 ` Hannes Reinecke
2022-09-21 9:23 ` Sagi Grimberg
1 sibling, 0 replies; 11+ messages in thread
From: Hannes Reinecke @ 2022-09-21 6:15 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni; +Cc: linux-nvme
On 9/20/22 19:19, Christoph Hellwig wrote:
> Currently blktests nvme/002 trips up debugobjects if CONFIG_NVME_AUTH is
> enabled, but authentication is not on a queue. This is because
> nvmet_auth_sq_free cancels sq->auth_expired_work unconditionaly, while
> auth_expired_work is only ever initialized if authentication is enabled
> for a given controller.
>
> Fix this by calling most of what is nvmet_init_auth unconditionally
> when initializing the SQ, and just do the setting of the result
> field in the connect command handler.
>
> Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/nvme/target/core.c | 1 +
> drivers/nvme/target/fabrics-cmd-auth.c | 13 ++++---------
> drivers/nvme/target/fabrics-cmd.c | 6 ++++--
> drivers/nvme/target/nvmet.h | 7 ++++---
> 4 files changed, 13 insertions(+), 14 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct
2022-09-20 17:19 ` [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct Christoph Hellwig
2022-09-21 6:15 ` Hannes Reinecke
@ 2022-09-21 9:23 ` Sagi Grimberg
1 sibling, 0 replies; 11+ messages in thread
From: Sagi Grimberg @ 2022-09-21 9:23 UTC (permalink / raw)
To: Christoph Hellwig, Hannes Reinecke, Chaitanya Kulkarni; +Cc: linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] nvme: improve the NVME_CONNECT_AUTHREQ* definitions
2022-09-20 17:19 ` [PATCH 2/3] nvme: improve the NVME_CONNECT_AUTHREQ* definitions Christoph Hellwig
2022-09-21 6:13 ` Hannes Reinecke
@ 2022-09-21 9:24 ` Sagi Grimberg
1 sibling, 0 replies; 11+ messages in thread
From: Sagi Grimberg @ 2022-09-21 9:24 UTC (permalink / raw)
To: Christoph Hellwig, Hannes Reinecke, Chaitanya Kulkarni; +Cc: linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/3] nvmet: add helpers to set the result field for connect commands
2022-09-20 17:19 ` [PATCH 3/3] nvmet: add helpers to set the result field for connect commands Christoph Hellwig
2022-09-21 6:14 ` Hannes Reinecke
@ 2022-09-21 9:24 ` Sagi Grimberg
1 sibling, 0 replies; 11+ messages in thread
From: Sagi Grimberg @ 2022-09-21 9:24 UTC (permalink / raw)
To: Christoph Hellwig, Hannes Reinecke, Chaitanya Kulkarni; +Cc: linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-09-21 10:31 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-20 17:19 nvme fabrics authentication fixups Christoph Hellwig
2022-09-20 17:19 ` [PATCH 1/3] nvmet-auth: don't try to cancel a non-initialized work_struct Christoph Hellwig
2022-09-21 6:15 ` Hannes Reinecke
2022-09-21 9:23 ` Sagi Grimberg
2022-09-20 17:19 ` [PATCH 2/3] nvme: improve the NVME_CONNECT_AUTHREQ* definitions Christoph Hellwig
2022-09-21 6:13 ` Hannes Reinecke
2022-09-21 9:24 ` Sagi Grimberg
2022-09-20 17:19 ` [PATCH 3/3] nvmet: add helpers to set the result field for connect commands Christoph Hellwig
2022-09-21 6:14 ` Hannes Reinecke
2022-09-21 9:24 ` Sagi Grimberg
2022-09-21 6:10 ` nvme fabrics authentication fixups Hannes Reinecke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox