* [PATCH v2 01/20] nvme-auth: rename __nvme_auth_[reset|free] to nvme_auth[reset|free]_dhchap
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 3:50 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 02/20] nvme-auth: rename authentication work elements Sagi Grimberg
` (19 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
nvme_auth_[reset|free] operate on the controller while
__nvme_auth_[reset|free] operate on a chap struct (which maps to a queue
context). Rename it for clarity.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index c8a6db7c4498..d45333268fcf 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -654,7 +654,7 @@ static int nvme_auth_dhchap_exponential(struct nvme_ctrl *ctrl,
return 0;
}
-static void __nvme_auth_reset(struct nvme_dhchap_queue_context *chap)
+static void nvme_auth_reset_dhchap(struct nvme_dhchap_queue_context *chap)
{
kfree_sensitive(chap->host_response);
chap->host_response = NULL;
@@ -676,9 +676,9 @@ static void __nvme_auth_reset(struct nvme_dhchap_queue_context *chap)
memset(chap->c2, 0, sizeof(chap->c2));
}
-static void __nvme_auth_free(struct nvme_dhchap_queue_context *chap)
+static void nvme_auth_free_dhchap(struct nvme_dhchap_queue_context *chap)
{
- __nvme_auth_reset(chap);
+ nvme_auth_reset_dhchap(chap);
if (chap->shash_tfm)
crypto_free_shash(chap->shash_tfm);
if (chap->dh_tfm)
@@ -868,7 +868,7 @@ int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid)
dev_dbg(ctrl->device, "qid %d: re-using context\n", qid);
mutex_unlock(&ctrl->dhchap_auth_mutex);
flush_work(&chap->auth_work);
- __nvme_auth_reset(chap);
+ nvme_auth_reset_dhchap(chap);
queue_work(nvme_wq, &chap->auth_work);
return 0;
}
@@ -928,7 +928,7 @@ void nvme_auth_reset(struct nvme_ctrl *ctrl)
list_for_each_entry(chap, &ctrl->dhchap_auth_list, entry) {
mutex_unlock(&ctrl->dhchap_auth_mutex);
flush_work(&chap->auth_work);
- __nvme_auth_reset(chap);
+ nvme_auth_reset_dhchap(chap);
}
mutex_unlock(&ctrl->dhchap_auth_mutex);
}
@@ -1002,7 +1002,7 @@ void nvme_auth_free(struct nvme_ctrl *ctrl)
list_for_each_entry_safe(chap, tmp, &ctrl->dhchap_auth_list, entry) {
list_del_init(&chap->entry);
flush_work(&chap->auth_work);
- __nvme_auth_free(chap);
+ nvme_auth_free_dhchap(chap);
}
mutex_unlock(&ctrl->dhchap_auth_mutex);
if (ctrl->host_key) {
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 02/20] nvme-auth: rename authentication work elements
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
2022-11-13 11:24 ` [PATCH v2 01/20] nvme-auth: rename __nvme_auth_[reset|free] to nvme_auth[reset|free]_dhchap Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-13 13:11 ` Hannes Reinecke
2022-11-15 3:52 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 03/20] nvme-auth: remove symbol export from nvme_auth_reset Sagi Grimberg
` (18 subsequent siblings)
20 siblings, 2 replies; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
Use nvme_ctrl_auth_work and nvme_queue_auth_work for better
readability.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index d45333268fcf..e3e801e2b78d 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -691,7 +691,7 @@ static void nvme_auth_free_dhchap(struct nvme_dhchap_queue_context *chap)
kfree(chap);
}
-static void __nvme_auth_work(struct work_struct *work)
+static void nvme_queue_auth_work(struct work_struct *work)
{
struct nvme_dhchap_queue_context *chap =
container_of(work, struct nvme_dhchap_queue_context, auth_work);
@@ -893,7 +893,7 @@ int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid)
return -ENOMEM;
}
- INIT_WORK(&chap->auth_work, __nvme_auth_work);
+ INIT_WORK(&chap->auth_work, nvme_queue_auth_work);
list_add(&chap->entry, &ctrl->dhchap_auth_list);
mutex_unlock(&ctrl->dhchap_auth_mutex);
queue_work(nvme_wq, &chap->auth_work);
@@ -934,7 +934,7 @@ void nvme_auth_reset(struct nvme_ctrl *ctrl)
}
EXPORT_SYMBOL_GPL(nvme_auth_reset);
-static void nvme_dhchap_auth_work(struct work_struct *work)
+static void nvme_ctrl_auth_work(struct work_struct *work)
{
struct nvme_ctrl *ctrl =
container_of(work, struct nvme_ctrl, dhchap_auth_work);
@@ -973,7 +973,7 @@ static void nvme_dhchap_auth_work(struct work_struct *work)
void nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
{
INIT_LIST_HEAD(&ctrl->dhchap_auth_list);
- INIT_WORK(&ctrl->dhchap_auth_work, nvme_dhchap_auth_work);
+ INIT_WORK(&ctrl->dhchap_auth_work, nvme_ctrl_auth_work);
mutex_init(&ctrl->dhchap_auth_mutex);
if (!ctrl->opts)
return;
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 02/20] nvme-auth: rename authentication work elements
2022-11-13 11:24 ` [PATCH v2 02/20] nvme-auth: rename authentication work elements Sagi Grimberg
@ 2022-11-13 13:11 ` Hannes Reinecke
2022-11-15 3:52 ` Chaitanya Kulkarni
1 sibling, 0 replies; 46+ messages in thread
From: Hannes Reinecke @ 2022-11-13 13:11 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni
On 11/13/22 12:24, Sagi Grimberg wrote:
> Use nvme_ctrl_auth_work and nvme_queue_auth_work for better
> readability.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
> drivers/nvme/host/auth.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 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 GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew
Myers, Andrew McDonald, Martje Boudien Moerman
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v2 02/20] nvme-auth: rename authentication work elements
2022-11-13 11:24 ` [PATCH v2 02/20] nvme-auth: rename authentication work elements Sagi Grimberg
2022-11-13 13:11 ` Hannes Reinecke
@ 2022-11-15 3:52 ` Chaitanya Kulkarni
1 sibling, 0 replies; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 3:52 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Hannes Reinecke,
Chaitanya Kulkarni
On 11/13/22 03:24, Sagi Grimberg wrote:
> Use nvme_ctrl_auth_work and nvme_queue_auth_work for better
> readability.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 03/20] nvme-auth: remove symbol export from nvme_auth_reset
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
2022-11-13 11:24 ` [PATCH v2 01/20] nvme-auth: rename __nvme_auth_[reset|free] to nvme_auth[reset|free]_dhchap Sagi Grimberg
2022-11-13 11:24 ` [PATCH v2 02/20] nvme-auth: rename authentication work elements Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 3:52 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 04/20] nvme-auth: don't re-authenticate if the controller is not LIVE Sagi Grimberg
` (17 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
Only the nvme module calls it.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index e3e801e2b78d..2f823c6b84fd 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -932,7 +932,6 @@ void nvme_auth_reset(struct nvme_ctrl *ctrl)
}
mutex_unlock(&ctrl->dhchap_auth_mutex);
}
-EXPORT_SYMBOL_GPL(nvme_auth_reset);
static void nvme_ctrl_auth_work(struct work_struct *work)
{
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 04/20] nvme-auth: don't re-authenticate if the controller is not LIVE
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (2 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 03/20] nvme-auth: remove symbol export from nvme_auth_reset Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 3:53 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 05/20] nvme-auth: remove redundant buffer deallocations Sagi Grimberg
` (16 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
The connect sequence will re-authenticate.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 2f823c6b84fd..4f2c8d0567bd 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -939,6 +939,13 @@ static void nvme_ctrl_auth_work(struct work_struct *work)
container_of(work, struct nvme_ctrl, dhchap_auth_work);
int ret, q;
+ /*
+ * If the ctrl is no connected, bail as reconnect will handle
+ * authentication.
+ */
+ if (ctrl->state != NVME_CTRL_LIVE)
+ return;
+
/* Authenticate admin queue first */
ret = nvme_auth_negotiate(ctrl, 0);
if (ret) {
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 05/20] nvme-auth: remove redundant buffer deallocations
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (3 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 04/20] nvme-auth: don't re-authenticate if the controller is not LIVE Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 3:54 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 06/20] nvme-auth: don't ignore key generation failures when initializing ctrl keys Sagi Grimberg
` (15 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
host_response, host_key, ctrl_key and sess_key are
freed in nvme_auth_reset_dhchap which is called from
nvme_auth_free_dhchap.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 4f2c8d0567bd..0d0542e33484 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -683,10 +683,6 @@ static void nvme_auth_free_dhchap(struct nvme_dhchap_queue_context *chap)
crypto_free_shash(chap->shash_tfm);
if (chap->dh_tfm)
crypto_free_kpp(chap->dh_tfm);
- kfree_sensitive(chap->ctrl_key);
- kfree_sensitive(chap->host_key);
- kfree_sensitive(chap->sess_key);
- kfree_sensitive(chap->host_response);
kfree(chap->buf);
kfree(chap);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 06/20] nvme-auth: don't ignore key generation failures when initializing ctrl keys
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (4 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 05/20] nvme-auth: remove redundant buffer deallocations Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 3:56 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 07/20] nvme-auth: don't override ctrl keys before validation Sagi Grimberg
` (14 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
nvme_auth_generate_key can fail, don't ignore it upon initialization.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 19 +++++++++++++++----
drivers/nvme/host/core.c | 6 +++++-
drivers/nvme/host/nvme.h | 2 +-
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 0d0542e33484..d62862ef5b3f 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -972,15 +972,26 @@ static void nvme_ctrl_auth_work(struct work_struct *work)
*/
}
-void nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
+int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
{
+ int ret;
+
INIT_LIST_HEAD(&ctrl->dhchap_auth_list);
INIT_WORK(&ctrl->dhchap_auth_work, nvme_ctrl_auth_work);
mutex_init(&ctrl->dhchap_auth_mutex);
if (!ctrl->opts)
- return;
- nvme_auth_generate_key(ctrl->opts->dhchap_secret, &ctrl->host_key);
- nvme_auth_generate_key(ctrl->opts->dhchap_ctrl_secret, &ctrl->ctrl_key);
+ return 0;
+ ret = nvme_auth_generate_key(ctrl->opts->dhchap_secret,
+ &ctrl->host_key);
+ if (ret)
+ return ret;
+ ret = nvme_auth_generate_key(ctrl->opts->dhchap_ctrl_secret,
+ &ctrl->ctrl_key);
+ if (ret) {
+ nvme_auth_free_key(ctrl->host_key);
+ ctrl->host_key = NULL;
+ }
+ return ret;
}
EXPORT_SYMBOL_GPL(nvme_auth_init_ctrl);
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index da55ce45ac70..1f3513938f94 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -5077,9 +5077,13 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device));
nvme_mpath_init_ctrl(ctrl);
- nvme_auth_init_ctrl(ctrl);
+ ret = nvme_auth_init_ctrl(ctrl);
+ if (ret)
+ goto out_free_cdev;
return 0;
+out_free_cdev:
+ cdev_device_del(&ctrl->cdev, ctrl->device);
out_free_name:
nvme_put_ctrl(ctrl);
kfree_const(ctrl->device->kobj.name);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index a29877217ee6..cc314f45ddee 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -1019,7 +1019,7 @@ static inline bool nvme_ctrl_sgl_supported(struct nvme_ctrl *ctrl)
}
#ifdef CONFIG_NVME_AUTH
-void nvme_auth_init_ctrl(struct nvme_ctrl *ctrl);
+int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl);
void nvme_auth_stop(struct nvme_ctrl *ctrl);
int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid);
int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 07/20] nvme-auth: don't override ctrl keys before validation
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (5 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 06/20] nvme-auth: don't ignore key generation failures when initializing ctrl keys Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 3:58 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 08/20] nvme-auth: remove redundant if statement Sagi Grimberg
` (13 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
Replace ctrl ctrl_key/host_key only after nvme_auth_generate_key is successful.
Also, this fixes a bug where the keys are leaked.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/core.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1f3513938f94..f2ae4ae33d68 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3745,13 +3745,17 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
memcpy(dhchap_secret, buf, count);
nvme_auth_stop(ctrl);
if (strcmp(dhchap_secret, opts->dhchap_secret)) {
+ struct nvme_dhchap_key *key, *host_key;
int ret;
- ret = nvme_auth_generate_key(dhchap_secret, &ctrl->host_key);
+ ret = nvme_auth_generate_key(dhchap_secret, &key);
if (ret)
return ret;
kfree(opts->dhchap_secret);
opts->dhchap_secret = dhchap_secret;
+ host_key = ctrl->host_key;
+ ctrl->host_key = key;
+ nvme_auth_free_key(host_key);
/* Key has changed; re-authentication with new key */
nvme_auth_reset(ctrl);
}
@@ -3795,13 +3799,17 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,
memcpy(dhchap_secret, buf, count);
nvme_auth_stop(ctrl);
if (strcmp(dhchap_secret, opts->dhchap_ctrl_secret)) {
+ struct nvme_dhchap_key *key, *ctrl_key;
int ret;
- ret = nvme_auth_generate_key(dhchap_secret, &ctrl->ctrl_key);
+ ret = nvme_auth_generate_key(dhchap_secret, &key);
if (ret)
return ret;
kfree(opts->dhchap_ctrl_secret);
opts->dhchap_ctrl_secret = dhchap_secret;
+ ctrl_key = ctrl->ctrl_key;
+ ctrl->ctrl_key = key;
+ nvme_auth_free_key(ctrl_key);
/* Key has changed; re-authentication with new key */
nvme_auth_reset(ctrl);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 08/20] nvme-auth: remove redundant if statement
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (6 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 07/20] nvme-auth: don't override ctrl keys before validation Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 3:58 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 09/20] nvme-auth: don't keep long lived 4k dhchap buffer Sagi Grimberg
` (12 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
No one passes NVME_QID_ANY to nvme_auth_negotiate.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index d62862ef5b3f..e7e4a00ee37e 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -874,7 +874,7 @@ int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid)
mutex_unlock(&ctrl->dhchap_auth_mutex);
return -ENOMEM;
}
- chap->qid = (qid == NVME_QID_ANY) ? 0 : qid;
+ chap->qid = qid;
chap->ctrl = ctrl;
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 09/20] nvme-auth: don't keep long lived 4k dhchap buffer
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (7 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 08/20] nvme-auth: remove redundant if statement Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 4:01 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 10/20] nvme-auth: guarantee dhchap buffers under memory pressure Sagi Grimberg
` (11 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
dhchap structure is per-queue, it is wasteful to keep it for the entire
lifetime of the queue. Allocate it dynamically and get rid of it after
authentication. We don't need kzalloc because all accessors are clearing
it before writing to it.
Also, remove redundant chap buf_size which is always 4096, use a define
instead.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 45 ++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 23 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index e7e4a00ee37e..4d288333b0fd 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -13,6 +13,8 @@
#include "fabrics.h"
#include <linux/nvme-auth.h>
+#define CHAP_BUF_SIZE 4096
+
struct nvme_dhchap_queue_context {
struct list_head entry;
struct work_struct auth_work;
@@ -20,7 +22,6 @@ struct nvme_dhchap_queue_context {
struct crypto_shash *shash_tfm;
struct crypto_kpp *dh_tfm;
void *buf;
- size_t buf_size;
int qid;
int error;
u32 s1;
@@ -112,7 +113,7 @@ static int nvme_auth_set_dhchap_negotiate_data(struct nvme_ctrl *ctrl,
struct nvmf_auth_dhchap_negotiate_data *data = chap->buf;
size_t size = sizeof(*data) + sizeof(union nvmf_auth_protocol);
- if (chap->buf_size < size) {
+ if (CHAP_BUF_SIZE < size) {
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
return -EINVAL;
}
@@ -147,7 +148,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
const char *gid_name = nvme_auth_dhgroup_name(data->dhgid);
const char *hmac_name, *kpp_name;
- if (chap->buf_size < size) {
+ if (CHAP_BUF_SIZE < size) {
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
return NVME_SC_INVALID_FIELD;
}
@@ -302,7 +303,7 @@ static int nvme_auth_set_dhchap_reply_data(struct nvme_ctrl *ctrl,
if (chap->host_key_len)
size += chap->host_key_len;
- if (chap->buf_size < size) {
+ if (CHAP_BUF_SIZE < size) {
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
return -EINVAL;
}
@@ -347,7 +348,7 @@ static int nvme_auth_process_dhchap_success1(struct nvme_ctrl *ctrl,
if (ctrl->ctrl_key)
size += chap->hash_len;
- if (chap->buf_size < size) {
+ if (CHAP_BUF_SIZE < size) {
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
return NVME_SC_INVALID_FIELD;
}
@@ -674,6 +675,8 @@ static void nvme_auth_reset_dhchap(struct nvme_dhchap_queue_context *chap)
chap->transaction = 0;
memset(chap->c1, 0, sizeof(chap->c1));
memset(chap->c2, 0, sizeof(chap->c2));
+ kfree(chap->buf);
+ chap->buf = NULL;
}
static void nvme_auth_free_dhchap(struct nvme_dhchap_queue_context *chap)
@@ -683,7 +686,6 @@ static void nvme_auth_free_dhchap(struct nvme_dhchap_queue_context *chap)
crypto_free_shash(chap->shash_tfm);
if (chap->dh_tfm)
crypto_free_kpp(chap->dh_tfm);
- kfree(chap->buf);
kfree(chap);
}
@@ -695,6 +697,16 @@ static void nvme_queue_auth_work(struct work_struct *work)
size_t tl;
int ret = 0;
+ /*
+ * Allocate a large enough buffer for the entire negotiation:
+ * 4k is enough to ffdhe8192.
+ */
+ chap->buf = kmalloc(CHAP_BUF_SIZE, GFP_KERNEL);
+ if (!chap->buf) {
+ chap->error = -ENOMEM;
+ return;
+ }
+
chap->transaction = ctrl->transaction++;
/* DH-HMAC-CHAP Step 1: send negotiate */
@@ -716,8 +728,8 @@ static void nvme_queue_auth_work(struct work_struct *work)
dev_dbg(ctrl->device, "%s: qid %d receive challenge\n",
__func__, chap->qid);
- memset(chap->buf, 0, chap->buf_size);
- ret = nvme_auth_submit(ctrl, chap->qid, chap->buf, chap->buf_size, false);
+ memset(chap->buf, 0, CHAP_BUF_SIZE);
+ ret = nvme_auth_submit(ctrl, chap->qid, chap->buf, CHAP_BUF_SIZE, false);
if (ret) {
dev_warn(ctrl->device,
"qid %d failed to receive challenge, %s %d\n",
@@ -779,8 +791,8 @@ static void nvme_queue_auth_work(struct work_struct *work)
dev_dbg(ctrl->device, "%s: qid %d receive success1\n",
__func__, chap->qid);
- memset(chap->buf, 0, chap->buf_size);
- ret = nvme_auth_submit(ctrl, chap->qid, chap->buf, chap->buf_size, false);
+ memset(chap->buf, 0, CHAP_BUF_SIZE);
+ ret = nvme_auth_submit(ctrl, chap->qid, chap->buf, CHAP_BUF_SIZE, false);
if (ret) {
dev_warn(ctrl->device,
"qid %d failed to receive success1, %s %d\n",
@@ -876,19 +888,6 @@ int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid)
}
chap->qid = qid;
chap->ctrl = ctrl;
-
- /*
- * Allocate a large enough buffer for the entire negotiation:
- * 4k should be enough to ffdhe8192.
- */
- chap->buf_size = 4096;
- chap->buf = kzalloc(chap->buf_size, GFP_KERNEL);
- if (!chap->buf) {
- mutex_unlock(&ctrl->dhchap_auth_mutex);
- kfree(chap);
- return -ENOMEM;
- }
-
INIT_WORK(&chap->auth_work, nvme_queue_auth_work);
list_add(&chap->entry, &ctrl->dhchap_auth_list);
mutex_unlock(&ctrl->dhchap_auth_mutex);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 09/20] nvme-auth: don't keep long lived 4k dhchap buffer
2022-11-13 11:24 ` [PATCH v2 09/20] nvme-auth: don't keep long lived 4k dhchap buffer Sagi Grimberg
@ 2022-11-15 4:01 ` Chaitanya Kulkarni
0 siblings, 0 replies; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:01 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
On 11/13/22 03:24, Sagi Grimberg wrote:
> dhchap structure is per-queue, it is wasteful to keep it for the entire
> lifetime of the queue. Allocate it dynamically and get rid of it after
> authentication. We don't need kzalloc because all accessors are clearing
> it before writing to it.
>
> Also, remove redundant chap buf_size which is always 4096, use a define
> instead.
>
> Reviewed-by: Hannes Reinecke <hare@suse.de>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 10/20] nvme-auth: guarantee dhchap buffers under memory pressure
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (8 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 09/20] nvme-auth: don't keep long lived 4k dhchap buffer Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 4:04 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 11/20] nvme-auth: clear sensitive info right after authentication completes Sagi Grimberg
` (10 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
We want to guarantee that we have chap buffers when a controller
reconnects under memory pressure. Add a mempool specifically
for that.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 30 ++++++++++++++++++++++++++++--
drivers/nvme/host/core.c | 6 ++++++
drivers/nvme/host/nvme.h | 7 +++++++
3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 4d288333b0fd..4bfe9ecda12a 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -14,6 +14,8 @@
#include <linux/nvme-auth.h>
#define CHAP_BUF_SIZE 4096
+struct kmem_cache *nvme_chap_buf_cache;
+mempool_t *nvme_chap_buf_pool;
struct nvme_dhchap_queue_context {
struct list_head entry;
@@ -675,7 +677,7 @@ static void nvme_auth_reset_dhchap(struct nvme_dhchap_queue_context *chap)
chap->transaction = 0;
memset(chap->c1, 0, sizeof(chap->c1));
memset(chap->c2, 0, sizeof(chap->c2));
- kfree(chap->buf);
+ mempool_free(chap->buf, nvme_chap_buf_pool);
chap->buf = NULL;
}
@@ -701,7 +703,7 @@ static void nvme_queue_auth_work(struct work_struct *work)
* Allocate a large enough buffer for the entire negotiation:
* 4k is enough to ffdhe8192.
*/
- chap->buf = kmalloc(CHAP_BUF_SIZE, GFP_KERNEL);
+ chap->buf = mempool_alloc(nvme_chap_buf_pool, GFP_KERNEL);
if (!chap->buf) {
chap->error = -ENOMEM;
return;
@@ -1027,3 +1029,27 @@ void nvme_auth_free(struct nvme_ctrl *ctrl)
}
}
EXPORT_SYMBOL_GPL(nvme_auth_free);
+
+int __init nvme_init_auth(void)
+{
+ nvme_chap_buf_cache = kmem_cache_create("nvme-chap-buf-cache",
+ CHAP_BUF_SIZE, 0, SLAB_HWCACHE_ALIGN, NULL);
+ if (!nvme_chap_buf_cache)
+ return -ENOMEM;
+
+ nvme_chap_buf_pool = mempool_create(16, mempool_alloc_slab,
+ mempool_free_slab, nvme_chap_buf_cache);
+ if (!nvme_chap_buf_pool)
+ goto err_destroy_chap_buf_cache;
+
+ return 0;
+err_destroy_chap_buf_cache:
+ kmem_cache_destroy(nvme_chap_buf_cache);
+ return -ENOMEM;
+}
+
+void __exit nvme_exit_auth(void)
+{
+ mempool_destroy(nvme_chap_buf_pool);
+ kmem_cache_destroy(nvme_chap_buf_cache);
+}
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f2ae4ae33d68..b75e8433c3b2 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -5356,8 +5356,13 @@ static int __init nvme_core_init(void)
goto unregister_generic_ns;
}
+ result = nvme_init_auth();
+ if (result)
+ goto destroy_ns_chr;
return 0;
+destroy_ns_chr:
+ class_destroy(nvme_ns_chr_class);
unregister_generic_ns:
unregister_chrdev_region(nvme_ns_chr_devt, NVME_MINORS);
destroy_subsys_class:
@@ -5378,6 +5383,7 @@ static int __init nvme_core_init(void)
static void __exit nvme_core_exit(void)
{
+ nvme_exit_auth();
class_destroy(nvme_ns_chr_class);
class_destroy(nvme_subsys_class);
class_destroy(nvme_class);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index cc314f45ddee..e8eff9edf7f5 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -1019,6 +1019,8 @@ static inline bool nvme_ctrl_sgl_supported(struct nvme_ctrl *ctrl)
}
#ifdef CONFIG_NVME_AUTH
+int __init nvme_init_auth(void);
+void __exit nvme_exit_auth(void);
int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl);
void nvme_auth_stop(struct nvme_ctrl *ctrl);
int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid);
@@ -1026,6 +1028,11 @@ int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid);
void nvme_auth_reset(struct nvme_ctrl *ctrl);
void nvme_auth_free(struct nvme_ctrl *ctrl);
#else
+int __init nvme_init_auth(void)
+{
+ return 0;
+}
+void __exit nvme_exit_auth(void) {};
static inline void nvme_auth_init_ctrl(struct nvme_ctrl *ctrl) {};
static inline void nvme_auth_stop(struct nvme_ctrl *ctrl) {};
static inline int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid)
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 10/20] nvme-auth: guarantee dhchap buffers under memory pressure
2022-11-13 11:24 ` [PATCH v2 10/20] nvme-auth: guarantee dhchap buffers under memory pressure Sagi Grimberg
@ 2022-11-15 4:04 ` Chaitanya Kulkarni
2022-11-15 8:09 ` Sagi Grimberg
0 siblings, 1 reply; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:04 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
On 11/13/22 03:24, Sagi Grimberg wrote:
> We want to guarantee that we have chap buffers when a controller
> reconnects under memory pressure. Add a mempool specifically
> for that.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
> drivers/nvme/host/auth.c | 30 ++++++++++++++++++++++++++++--
> drivers/nvme/host/core.c | 6 ++++++
> drivers/nvme/host/nvme.h | 7 +++++++
> 3 files changed, 41 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
> index 4d288333b0fd..4bfe9ecda12a 100644
> --- a/drivers/nvme/host/auth.c
> +++ b/drivers/nvme/host/auth.c
> @@ -14,6 +14,8 @@
> #include <linux/nvme-auth.h>
>
> #define CHAP_BUF_SIZE 4096
> +struct kmem_cache *nvme_chap_buf_cache;
> +mempool_t *nvme_chap_buf_pool;
>
is there a reason they are not declared as static ?
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v2 10/20] nvme-auth: guarantee dhchap buffers under memory pressure
2022-11-15 4:04 ` Chaitanya Kulkarni
@ 2022-11-15 8:09 ` Sagi Grimberg
0 siblings, 0 replies; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-15 8:09 UTC (permalink / raw)
To: Chaitanya Kulkarni, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
>> We want to guarantee that we have chap buffers when a controller
>> reconnects under memory pressure. Add a mempool specifically
>> for that.
>>
>> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
>> ---
>> drivers/nvme/host/auth.c | 30 ++++++++++++++++++++++++++++--
>> drivers/nvme/host/core.c | 6 ++++++
>> drivers/nvme/host/nvme.h | 7 +++++++
>> 3 files changed, 41 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
>> index 4d288333b0fd..4bfe9ecda12a 100644
>> --- a/drivers/nvme/host/auth.c
>> +++ b/drivers/nvme/host/auth.c
>> @@ -14,6 +14,8 @@
>> #include <linux/nvme-auth.h>
>>
>> #define CHAP_BUF_SIZE 4096
>> +struct kmem_cache *nvme_chap_buf_cache;
>> +mempool_t *nvme_chap_buf_pool;
>>
>
> is there a reason they are not declared as static ?
No reason, they should.
If I post another series, this will be fixed, if not this
can be folded when applying the series...
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 11/20] nvme-auth: clear sensitive info right after authentication completes
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (9 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 10/20] nvme-auth: guarantee dhchap buffers under memory pressure Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 4:06 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 12/20] nvme-auth: remove redundant deallocations Sagi Grimberg
` (9 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
We don't want to keep authentication sensitive info in memory for unlimited
amount of time.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 4bfe9ecda12a..e6f07c7f76d0 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -910,6 +910,8 @@ int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid)
mutex_unlock(&ctrl->dhchap_auth_mutex);
flush_work(&chap->auth_work);
ret = chap->error;
+ /* clear sensitive info */
+ nvme_auth_reset_dhchap(chap);
return ret;
}
mutex_unlock(&ctrl->dhchap_auth_mutex);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 12/20] nvme-auth: remove redundant deallocations
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (10 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 11/20] nvme-auth: clear sensitive info right after authentication completes Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-13 13:11 ` Hannes Reinecke
2022-11-15 4:09 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 13/20] nvme-auth: no need to reset chap contexts on re-authentication Sagi Grimberg
` (8 subsequent siblings)
20 siblings, 2 replies; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
These are now redundant as the dhchap context is
removed after authentication completes.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 20 --------------------
1 file changed, 20 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index e6f07c7f76d0..b1f9883ef8e5 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -200,12 +200,6 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
return NVME_SC_AUTH_REQUIRED;
}
- /* Reset host response if the hash had been changed */
- if (chap->hash_id != data->hashid) {
- kfree(chap->host_response);
- chap->host_response = NULL;
- }
-
chap->hash_id = data->hashid;
chap->hash_len = data->hl;
dev_dbg(ctrl->device, "qid %d: selected hash %s\n",
@@ -222,14 +216,6 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
return NVME_SC_AUTH_REQUIRED;
}
- /* Clear host and controller key to avoid accidental reuse */
- kfree_sensitive(chap->host_key);
- chap->host_key = NULL;
- chap->host_key_len = 0;
- kfree_sensitive(chap->ctrl_key);
- chap->ctrl_key = NULL;
- chap->ctrl_key_len = 0;
-
if (chap->dhgroup_id == data->dhgid &&
(data->dhgid == NVME_AUTH_DHGROUP_NULL || chap->dh_tfm)) {
dev_dbg(ctrl->device,
@@ -624,9 +610,6 @@ static int nvme_auth_dhchap_exponential(struct nvme_ctrl *ctrl,
if (ret) {
dev_dbg(ctrl->device,
"failed to generate public key, error %d\n", ret);
- kfree(chap->host_key);
- chap->host_key = NULL;
- chap->host_key_len = 0;
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
return ret;
}
@@ -646,9 +629,6 @@ static int nvme_auth_dhchap_exponential(struct nvme_ctrl *ctrl,
if (ret) {
dev_dbg(ctrl->device,
"failed to generate shared secret, error %d\n", ret);
- kfree_sensitive(chap->sess_key);
- chap->sess_key = NULL;
- chap->sess_key_len = 0;
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 12/20] nvme-auth: remove redundant deallocations
2022-11-13 11:24 ` [PATCH v2 12/20] nvme-auth: remove redundant deallocations Sagi Grimberg
@ 2022-11-13 13:11 ` Hannes Reinecke
2022-11-15 4:09 ` Chaitanya Kulkarni
1 sibling, 0 replies; 46+ messages in thread
From: Hannes Reinecke @ 2022-11-13 13:11 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni
On 11/13/22 12:24, Sagi Grimberg wrote:
> These are now redundant as the dhchap context is
> removed after authentication completes.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
> drivers/nvme/host/auth.c | 20 --------------------
> 1 file changed, 20 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 GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew
Myers, Andrew McDonald, Martje Boudien Moerman
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v2 12/20] nvme-auth: remove redundant deallocations
2022-11-13 11:24 ` [PATCH v2 12/20] nvme-auth: remove redundant deallocations Sagi Grimberg
2022-11-13 13:11 ` Hannes Reinecke
@ 2022-11-15 4:09 ` Chaitanya Kulkarni
1 sibling, 0 replies; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:09 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
On 11/13/22 03:24, Sagi Grimberg wrote:
> These are now redundant as the dhchap context is
> removed after authentication completes.
>
like some of the patches in this series following preferred ?
These are now redundant as the dhchap context is removed after
authentication completes.
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
> drivers/nvme/host/auth.c | 20 --------------------
> 1 file changed, 20 deletions(-)
>
>
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 13/20] nvme-auth: no need to reset chap contexts on re-authentication
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (11 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 12/20] nvme-auth: remove redundant deallocations Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 4:10 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed Sagi Grimberg
` (7 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
Now that the chap context is reset upon completion, this is no longer
needed. Also remove nvme_auth_reset as no callers are left.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 13 -------------
drivers/nvme/host/core.c | 4 ----
drivers/nvme/host/nvme.h | 1 -
3 files changed, 18 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index b1f9883ef8e5..a502e159e14e 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -899,19 +899,6 @@ int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid)
}
EXPORT_SYMBOL_GPL(nvme_auth_wait);
-void nvme_auth_reset(struct nvme_ctrl *ctrl)
-{
- struct nvme_dhchap_queue_context *chap;
-
- mutex_lock(&ctrl->dhchap_auth_mutex);
- list_for_each_entry(chap, &ctrl->dhchap_auth_list, entry) {
- mutex_unlock(&ctrl->dhchap_auth_mutex);
- flush_work(&chap->auth_work);
- nvme_auth_reset_dhchap(chap);
- }
- mutex_unlock(&ctrl->dhchap_auth_mutex);
-}
-
static void nvme_ctrl_auth_work(struct work_struct *work)
{
struct nvme_ctrl *ctrl =
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index b75e8433c3b2..140e8ca0858a 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3756,8 +3756,6 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
host_key = ctrl->host_key;
ctrl->host_key = key;
nvme_auth_free_key(host_key);
- /* Key has changed; re-authentication with new key */
- nvme_auth_reset(ctrl);
}
/* Start re-authentication */
dev_info(ctrl->device, "re-authenticating controller\n");
@@ -3810,8 +3808,6 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,
ctrl_key = ctrl->ctrl_key;
ctrl->ctrl_key = key;
nvme_auth_free_key(ctrl_key);
- /* Key has changed; re-authentication with new key */
- nvme_auth_reset(ctrl);
}
/* Start re-authentication */
dev_info(ctrl->device, "re-authenticating controller\n");
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index e8eff9edf7f5..136582c80ee8 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -1025,7 +1025,6 @@ int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl);
void nvme_auth_stop(struct nvme_ctrl *ctrl);
int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid);
int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid);
-void nvme_auth_reset(struct nvme_ctrl *ctrl);
void nvme_auth_free(struct nvme_ctrl *ctrl);
#else
int __init nvme_init_auth(void)
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (12 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 13/20] nvme-auth: no need to reset chap contexts on re-authentication Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-13 13:12 ` Hannes Reinecke
` (2 more replies)
2022-11-13 11:24 ` [PATCH v2 15/20] nvme: move nvme_dhchap_queue_context declaration to nvme.h header Sagi Grimberg
` (6 subsequent siblings)
20 siblings, 3 replies; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
ctrl ctrl_key member may be overwritten from a sysfs context driven
by the user. Once a queue local copy was created, use that instead
to minimize checks on a shared resource.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index a502e159e14e..2bcb33c83534 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -333,7 +333,7 @@ static int nvme_auth_process_dhchap_success1(struct nvme_ctrl *ctrl,
struct nvmf_auth_dhchap_success1_data *data = chap->buf;
size_t size = sizeof(*data);
- if (ctrl->ctrl_key)
+ if (chap->ctrl_key)
size += chap->hash_len;
if (CHAP_BUF_SIZE < size) {
@@ -809,7 +809,7 @@ static void nvme_queue_auth_work(struct work_struct *work)
goto fail2;
}
- if (ctrl->ctrl_key) {
+ if (chap->ctrl_key) {
/* DH-HMAC-CHAP Step 5: send success2 */
dev_dbg(ctrl->device, "%s: qid %d send success2\n",
__func__, chap->qid);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed
2022-11-13 11:24 ` [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed Sagi Grimberg
@ 2022-11-13 13:12 ` Hannes Reinecke
2022-11-15 4:13 ` Chaitanya Kulkarni
2022-11-15 4:13 ` Chaitanya Kulkarni
2 siblings, 0 replies; 46+ messages in thread
From: Hannes Reinecke @ 2022-11-13 13:12 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni
On 11/13/22 12:24, Sagi Grimberg wrote:
> ctrl ctrl_key member may be overwritten from a sysfs context driven
> by the user. Once a queue local copy was created, use that instead
> to minimize checks on a shared resource.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
> drivers/nvme/host/auth.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 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 GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew
Myers, Andrew McDonald, Martje Boudien Moerman
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed
2022-11-13 11:24 ` [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed Sagi Grimberg
2022-11-13 13:12 ` Hannes Reinecke
@ 2022-11-15 4:13 ` Chaitanya Kulkarni
2022-11-15 4:13 ` Chaitanya Kulkarni
2 siblings, 0 replies; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:13 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
On 11/13/22 03:24, Sagi Grimberg wrote:
> ctrl ctrl_key member may be overwritten from a sysfs context driven
> by the user. Once a queue local copy was created, use that instead
> to minimize checks on a shared resource.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
Since it is not in a fast path do we really have to care about the
performance impact on the shared resource locks ?
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed
2022-11-13 11:24 ` [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed Sagi Grimberg
2022-11-13 13:12 ` Hannes Reinecke
2022-11-15 4:13 ` Chaitanya Kulkarni
@ 2022-11-15 4:13 ` Chaitanya Kulkarni
2 siblings, 0 replies; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:13 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
On 11/13/22 03:24, Sagi Grimberg wrote:
> ctrl ctrl_key member may be overwritten from a sysfs context driven
> by the user. Once a queue local copy was created, use that instead
> to minimize checks on a shared resource.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 15/20] nvme: move nvme_dhchap_queue_context declaration to nvme.h header
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (13 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 14/20] nvme-auth: check chap ctrl_key once constructed Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 4:20 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 16/20] nvme-auth: convert dhchap_auth_list to an array Sagi Grimberg
` (5 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
We are going to have an array reference from nvme ctrl, and we want
to avoid a casting on reference.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 28 ----------------------------
drivers/nvme/host/nvme.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 2bcb33c83534..5fad1b6f8439 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -17,34 +17,6 @@
struct kmem_cache *nvme_chap_buf_cache;
mempool_t *nvme_chap_buf_pool;
-struct nvme_dhchap_queue_context {
- struct list_head entry;
- struct work_struct auth_work;
- struct nvme_ctrl *ctrl;
- struct crypto_shash *shash_tfm;
- struct crypto_kpp *dh_tfm;
- void *buf;
- int qid;
- int error;
- u32 s1;
- u32 s2;
- u16 transaction;
- u8 status;
- u8 hash_id;
- size_t hash_len;
- u8 dhgroup_id;
- u8 c1[64];
- u8 c2[64];
- u8 response[64];
- u8 *host_response;
- u8 *ctrl_key;
- int ctrl_key_len;
- u8 *host_key;
- int host_key_len;
- u8 *sess_key;
- int sess_key_len;
-};
-
#define nvme_auth_flags_from_qid(qid) \
(qid == 0) ? 0 : BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED
#define nvme_auth_queue_from_qid(ctrl, qid) \
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 136582c80ee8..8bd7554b68a8 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -188,6 +188,37 @@ static inline u16 nvme_req_qid(struct request *req)
return req->mq_hctx->queue_num + 1;
}
+
+#ifdef CONFIG_NVME_AUTH
+struct nvme_dhchap_queue_context {
+ struct list_head entry;
+ struct work_struct auth_work;
+ struct nvme_ctrl *ctrl;
+ struct crypto_shash *shash_tfm;
+ struct crypto_kpp *dh_tfm;
+ void *buf;
+ int qid;
+ int error;
+ u32 s1;
+ u32 s2;
+ u16 transaction;
+ u8 status;
+ u8 hash_id;
+ size_t hash_len;
+ u8 dhgroup_id;
+ u8 c1[64];
+ u8 c2[64];
+ u8 response[64];
+ u8 *host_response;
+ u8 *ctrl_key;
+ int ctrl_key_len;
+ u8 *host_key;
+ int host_key_len;
+ u8 *sess_key;
+ int sess_key_len;
+};
+#endif
+
/* The below value is the specific amount of delay needed before checking
* readiness in case of the PCI_DEVICE(0x1c58, 0x0003), which needs the
* NVME_QUIRK_DELAY_BEFORE_CHK_RDY quirk enabled. The value (in ms) was
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 15/20] nvme: move nvme_dhchap_queue_context declaration to nvme.h header
2022-11-13 11:24 ` [PATCH v2 15/20] nvme: move nvme_dhchap_queue_context declaration to nvme.h header Sagi Grimberg
@ 2022-11-15 4:20 ` Chaitanya Kulkarni
2022-11-15 10:03 ` Christoph Hellwig
0 siblings, 1 reply; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:20 UTC (permalink / raw)
To: linux-nvme@lists.infradead.org
On 11/13/22 03:24, Sagi Grimberg wrote:
> We are going to have an array reference from nvme ctrl, and we want
> to avoid a casting on reference.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
honestly I didn't get the commit description at first glance
maybe that just me ...
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v2 15/20] nvme: move nvme_dhchap_queue_context declaration to nvme.h header
2022-11-15 4:20 ` Chaitanya Kulkarni
@ 2022-11-15 10:03 ` Christoph Hellwig
0 siblings, 0 replies; 46+ messages in thread
From: Christoph Hellwig @ 2022-11-15 10:03 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-nvme@lists.infradead.org
On Tue, Nov 15, 2022 at 04:20:37AM +0000, Chaitanya Kulkarni wrote:
> On 11/13/22 03:24, Sagi Grimberg wrote:
> > We are going to have an array reference from nvme ctrl, and we want
> > to avoid a casting on reference.
> >
> > Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
>
> honestly I didn't get the commit description at first glance
> maybe that just me ...
And there's also no need to move it, we can just use a forward declaration.
I'll fix it up when applying the series.
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 16/20] nvme-auth: convert dhchap_auth_list to an array
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (14 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 15/20] nvme: move nvme_dhchap_queue_context declaration to nvme.h header Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-13 11:24 ` [PATCH v2 17/20] nvme-auth: remove redundant auth_work flush Sagi Grimberg
` (4 subsequent siblings)
20 siblings, 0 replies; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
We know exactly how many dhchap contexts we will need, there is no need
to hold a list that we need to protect with a mutex. Convert to
a dynamically allocated array. And dhchap_context access state is
maintained by the chap itself.
Make dhchap_auth_mutex protect only the ctrl host_key and ctrl_key
in a fine-grained lock such that there is no long lasting acquisition
of the lock and no need to take/release this lock when flushing
authentication works.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 118 +++++++++++++++++++++------------------
drivers/nvme/host/core.c | 4 ++
drivers/nvme/host/nvme.h | 2 +-
3 files changed, 69 insertions(+), 55 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 5fad1b6f8439..eaa294376247 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -22,6 +22,12 @@ mempool_t *nvme_chap_buf_pool;
#define nvme_auth_queue_from_qid(ctrl, qid) \
(qid == 0) ? (ctrl)->fabrics_q : (ctrl)->connect_q
+static inline int ctrl_max_dhchaps(struct nvme_ctrl *ctrl)
+{
+ return ctrl->opts->nr_io_queues + ctrl->opts->nr_write_queues +
+ ctrl->opts->nr_poll_queues + 1;
+}
+
static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
void *data, size_t data_len, bool auth_send)
{
@@ -482,6 +488,7 @@ static int nvme_auth_dhchap_setup_ctrl_response(struct nvme_ctrl *ctrl,
ret = PTR_ERR(ctrl_response);
return ret;
}
+
ret = crypto_shash_setkey(chap->shash_tfm,
ctrl_response, ctrl->ctrl_key->len);
if (ret) {
@@ -640,7 +647,6 @@ static void nvme_auth_free_dhchap(struct nvme_dhchap_queue_context *chap)
crypto_free_shash(chap->shash_tfm);
if (chap->dh_tfm)
crypto_free_kpp(chap->dh_tfm);
- kfree(chap);
}
static void nvme_queue_auth_work(struct work_struct *work)
@@ -719,11 +725,14 @@ static void nvme_queue_auth_work(struct work_struct *work)
dev_dbg(ctrl->device, "%s: qid %d host response\n",
__func__, chap->qid);
+ mutex_lock(&ctrl->dhchap_auth_mutex);
ret = nvme_auth_dhchap_setup_host_response(ctrl, chap);
if (ret) {
+ mutex_unlock(&ctrl->dhchap_auth_mutex);
chap->error = ret;
goto fail2;
}
+ mutex_unlock(&ctrl->dhchap_auth_mutex);
/* DH-HMAC-CHAP Step 3: send reply */
dev_dbg(ctrl->device, "%s: qid %d send reply\n",
@@ -763,16 +772,19 @@ static void nvme_queue_auth_work(struct work_struct *work)
return;
}
+ mutex_lock(&ctrl->dhchap_auth_mutex);
if (ctrl->ctrl_key) {
dev_dbg(ctrl->device,
"%s: qid %d controller response\n",
__func__, chap->qid);
ret = nvme_auth_dhchap_setup_ctrl_response(ctrl, chap);
if (ret) {
+ mutex_unlock(&ctrl->dhchap_auth_mutex);
chap->error = ret;
goto fail2;
}
}
+ mutex_unlock(&ctrl->dhchap_auth_mutex);
ret = nvme_auth_process_dhchap_success1(ctrl, chap);
if (ret) {
@@ -822,29 +834,8 @@ int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid)
return -ENOKEY;
}
- mutex_lock(&ctrl->dhchap_auth_mutex);
- /* Check if the context is already queued */
- list_for_each_entry(chap, &ctrl->dhchap_auth_list, entry) {
- WARN_ON(!chap->buf);
- if (chap->qid == qid) {
- dev_dbg(ctrl->device, "qid %d: re-using context\n", qid);
- mutex_unlock(&ctrl->dhchap_auth_mutex);
- flush_work(&chap->auth_work);
- nvme_auth_reset_dhchap(chap);
- queue_work(nvme_wq, &chap->auth_work);
- return 0;
- }
- }
- chap = kzalloc(sizeof(*chap), GFP_KERNEL);
- if (!chap) {
- mutex_unlock(&ctrl->dhchap_auth_mutex);
- return -ENOMEM;
- }
- chap->qid = qid;
- chap->ctrl = ctrl;
- INIT_WORK(&chap->auth_work, nvme_queue_auth_work);
- list_add(&chap->entry, &ctrl->dhchap_auth_list);
- mutex_unlock(&ctrl->dhchap_auth_mutex);
+ chap = &ctrl->dhchap_ctxs[qid];
+ cancel_work_sync(&chap->auth_work);
queue_work(nvme_wq, &chap->auth_work);
return 0;
}
@@ -855,19 +846,12 @@ int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid)
struct nvme_dhchap_queue_context *chap;
int ret;
- mutex_lock(&ctrl->dhchap_auth_mutex);
- list_for_each_entry(chap, &ctrl->dhchap_auth_list, entry) {
- if (chap->qid != qid)
- continue;
- mutex_unlock(&ctrl->dhchap_auth_mutex);
- flush_work(&chap->auth_work);
- ret = chap->error;
- /* clear sensitive info */
- nvme_auth_reset_dhchap(chap);
- return ret;
- }
- mutex_unlock(&ctrl->dhchap_auth_mutex);
- return -ENXIO;
+ chap = &ctrl->dhchap_ctxs[qid];
+ flush_work(&chap->auth_work);
+ ret = chap->error;
+ /* clear sensitive info */
+ nvme_auth_reset_dhchap(chap);
+ return ret;
}
EXPORT_SYMBOL_GPL(nvme_auth_wait);
@@ -916,11 +900,11 @@ static void nvme_ctrl_auth_work(struct work_struct *work)
int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
{
- int ret;
+ struct nvme_dhchap_queue_context *chap;
+ int i, ret;
- INIT_LIST_HEAD(&ctrl->dhchap_auth_list);
- INIT_WORK(&ctrl->dhchap_auth_work, nvme_ctrl_auth_work);
mutex_init(&ctrl->dhchap_auth_mutex);
+ INIT_WORK(&ctrl->dhchap_auth_work, nvme_ctrl_auth_work);
if (!ctrl->opts)
return 0;
ret = nvme_auth_generate_key(ctrl->opts->dhchap_secret,
@@ -929,37 +913,63 @@ int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
return ret;
ret = nvme_auth_generate_key(ctrl->opts->dhchap_ctrl_secret,
&ctrl->ctrl_key);
- if (ret) {
- nvme_auth_free_key(ctrl->host_key);
- ctrl->host_key = NULL;
+ if (ret)
+ goto err_free_dhchap_secret;
+
+ if (!ctrl->opts->dhchap_secret && !ctrl->opts->dhchap_ctrl_secret)
+ return ret;
+
+ ctrl->dhchap_ctxs = kvcalloc(ctrl_max_dhchaps(ctrl),
+ sizeof(*chap), GFP_KERNEL);
+ if (!ctrl->dhchap_ctxs) {
+ ret = -ENOMEM;
+ goto err_free_dhchap_ctrl_secret;
}
+
+ for (i = 0; i < ctrl_max_dhchaps(ctrl); i++) {
+ chap = &ctrl->dhchap_ctxs[i];
+ chap->qid = i;
+ chap->ctrl = ctrl;
+ INIT_WORK(&chap->auth_work, nvme_queue_auth_work);
+ }
+
+ return 0;
+err_free_dhchap_ctrl_secret:
+ nvme_auth_free_key(ctrl->ctrl_key);
+ ctrl->ctrl_key = NULL;
+err_free_dhchap_secret:
+ nvme_auth_free_key(ctrl->host_key);
+ ctrl->host_key = NULL;
return ret;
}
EXPORT_SYMBOL_GPL(nvme_auth_init_ctrl);
void nvme_auth_stop(struct nvme_ctrl *ctrl)
{
- struct nvme_dhchap_queue_context *chap = NULL, *tmp;
+ struct nvme_dhchap_queue_context *chap;
+ int i;
cancel_work_sync(&ctrl->dhchap_auth_work);
- mutex_lock(&ctrl->dhchap_auth_mutex);
- list_for_each_entry_safe(chap, tmp, &ctrl->dhchap_auth_list, entry)
+ for (i = 0; i < ctrl_max_dhchaps(ctrl); i++) {
+ chap = &ctrl->dhchap_ctxs[i];
cancel_work_sync(&chap->auth_work);
- mutex_unlock(&ctrl->dhchap_auth_mutex);
+ }
}
EXPORT_SYMBOL_GPL(nvme_auth_stop);
void nvme_auth_free(struct nvme_ctrl *ctrl)
{
- struct nvme_dhchap_queue_context *chap = NULL, *tmp;
+ struct nvme_dhchap_queue_context *chap;
+ int i;
- mutex_lock(&ctrl->dhchap_auth_mutex);
- list_for_each_entry_safe(chap, tmp, &ctrl->dhchap_auth_list, entry) {
- list_del_init(&chap->entry);
- flush_work(&chap->auth_work);
- nvme_auth_free_dhchap(chap);
+ if (ctrl->dhchap_ctxs) {
+ for (i = 0; i < ctrl_max_dhchaps(ctrl); i++) {
+ chap = &ctrl->dhchap_ctxs[i];
+ flush_work(&chap->auth_work);
+ nvme_auth_free_dhchap(chap);
+ }
+ kfree(ctrl->dhchap_ctxs);
}
- mutex_unlock(&ctrl->dhchap_auth_mutex);
if (ctrl->host_key) {
nvme_auth_free_key(ctrl->host_key);
ctrl->host_key = NULL;
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 140e8ca0858a..1973686c062b 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3754,7 +3754,9 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
kfree(opts->dhchap_secret);
opts->dhchap_secret = dhchap_secret;
host_key = ctrl->host_key;
+ mutex_lock(&ctrl->dhchap_auth_mutex);
ctrl->host_key = key;
+ mutex_unlock(&ctrl->dhchap_auth_mutex);
nvme_auth_free_key(host_key);
}
/* Start re-authentication */
@@ -3806,7 +3808,9 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,
kfree(opts->dhchap_ctrl_secret);
opts->dhchap_ctrl_secret = dhchap_secret;
ctrl_key = ctrl->ctrl_key;
+ mutex_lock(&ctrl->dhchap_auth_mutex);
ctrl->ctrl_key = key;
+ mutex_unlock(&ctrl->dhchap_auth_mutex);
nvme_auth_free_key(ctrl_key);
}
/* Start re-authentication */
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 8bd7554b68a8..357fa7330bd9 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -367,8 +367,8 @@ struct nvme_ctrl {
#ifdef CONFIG_NVME_AUTH
struct work_struct dhchap_auth_work;
- struct list_head dhchap_auth_list;
struct mutex dhchap_auth_mutex;
+ struct nvme_dhchap_queue_context *dhchap_ctxs;
struct nvme_dhchap_key *host_key;
struct nvme_dhchap_key *ctrl_key;
u16 transaction;
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 17/20] nvme-auth: remove redundant auth_work flush
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (15 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 16/20] nvme-auth: convert dhchap_auth_list to an array Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 4:15 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 18/20] nvme-auth: have dhchap_auth_work wait for queues auth to complete Sagi Grimberg
` (3 subsequent siblings)
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
only ctrl deletion calls nvme_auth_free, which was stopped prior in the
teardown stage, so there is no possibility that it should ever run when
nvme_auth_free is called. As a result, we can remove a local chap pointer
variable.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index eaa294376247..2fd1641b4c67 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -959,15 +959,11 @@ EXPORT_SYMBOL_GPL(nvme_auth_stop);
void nvme_auth_free(struct nvme_ctrl *ctrl)
{
- struct nvme_dhchap_queue_context *chap;
int i;
if (ctrl->dhchap_ctxs) {
- for (i = 0; i < ctrl_max_dhchaps(ctrl); i++) {
- chap = &ctrl->dhchap_ctxs[i];
- flush_work(&chap->auth_work);
- nvme_auth_free_dhchap(chap);
- }
+ for (i = 0; i < ctrl_max_dhchaps(ctrl); i++)
+ nvme_auth_free_dhchap(&ctrl->dhchap_ctxs[i]);
kfree(ctrl->dhchap_ctxs);
}
if (ctrl->host_key) {
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 17/20] nvme-auth: remove redundant auth_work flush
2022-11-13 11:24 ` [PATCH v2 17/20] nvme-auth: remove redundant auth_work flush Sagi Grimberg
@ 2022-11-15 4:15 ` Chaitanya Kulkarni
0 siblings, 0 replies; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:15 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
On 11/13/22 03:24, Sagi Grimberg wrote:
> only ctrl deletion calls nvme_auth_free, which was stopped prior in the
> teardown stage, so there is no possibility that it should ever run when
> nvme_auth_free is called. As a result, we can remove a local chap pointer
> variable.
>
> Reviewed-by: Hannes Reinecke <hare@suse.de>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 18/20] nvme-auth: have dhchap_auth_work wait for queues auth to complete
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (16 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 17/20] nvme-auth: remove redundant auth_work flush Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-13 11:24 ` [PATCH v2 19/20] nvme-tcp: stop auth work after tearing down queues in error recovery Sagi Grimberg
` (2 subsequent siblings)
20 siblings, 0 replies; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
It triggered the queue authentication work elements in parallel, but
the ctrl authentication work itself completes when all of them
completes. Hence wait for queues auth completions.
This also makes nvme_auth_stop simply a sync cancel of ctrl
dhchap_auth_work.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/auth.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 2fd1641b4c67..77555337cfde 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -896,6 +896,12 @@ static void nvme_ctrl_auth_work(struct work_struct *work)
* Failure is a soft-state; credentials remain valid until
* the controller terminates the connection.
*/
+ for (q = 1; q < ctrl->queue_count; q++) {
+ ret = nvme_auth_wait(ctrl, q);
+ if (ret)
+ dev_warn(ctrl->device,
+ "qid %d: authentication failed\n", q);
+ }
}
int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
@@ -946,14 +952,7 @@ EXPORT_SYMBOL_GPL(nvme_auth_init_ctrl);
void nvme_auth_stop(struct nvme_ctrl *ctrl)
{
- struct nvme_dhchap_queue_context *chap;
- int i;
-
cancel_work_sync(&ctrl->dhchap_auth_work);
- for (i = 0; i < ctrl_max_dhchaps(ctrl); i++) {
- chap = &ctrl->dhchap_ctxs[i];
- cancel_work_sync(&chap->auth_work);
- }
}
EXPORT_SYMBOL_GPL(nvme_auth_stop);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* [PATCH v2 19/20] nvme-tcp: stop auth work after tearing down queues in error recovery
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (17 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 18/20] nvme-auth: have dhchap_auth_work wait for queues auth to complete Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 4:18 ` Chaitanya Kulkarni
2022-11-13 11:24 ` [PATCH v2 20/20] nvme-rdma: " Sagi Grimberg
2022-11-15 10:11 ` [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Christoph Hellwig
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
when starting error recovery there might be a authentication work
running, and it involves I/O commands. Given the controller is tearing
down there is no chance for the I/O to complete other than timing out
which may unnecessarily take a full io timeout.
So first tear down the queues, fail/cancel all inflight I/O (including
potentially authentication) and only then stop authentication. This
ensures that failover is not stalled due to blocked authentication I/O.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/tcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 9b47dcb2a7d9..65077da58096 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -2128,7 +2128,6 @@ static void nvme_tcp_error_recovery_work(struct work_struct *work)
struct nvme_tcp_ctrl, err_work);
struct nvme_ctrl *ctrl = &tcp_ctrl->ctrl;
- nvme_auth_stop(ctrl);
nvme_stop_keep_alive(ctrl);
flush_work(&ctrl->async_event_work);
nvme_tcp_teardown_io_queues(ctrl, false);
@@ -2136,6 +2135,7 @@ static void nvme_tcp_error_recovery_work(struct work_struct *work)
nvme_start_queues(ctrl);
nvme_tcp_teardown_admin_queue(ctrl, false);
nvme_start_admin_queue(ctrl);
+ nvme_auth_stop(ctrl);
if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING)) {
/* state change failure is ok if we started ctrl delete */
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 19/20] nvme-tcp: stop auth work after tearing down queues in error recovery
2022-11-13 11:24 ` [PATCH v2 19/20] nvme-tcp: stop auth work after tearing down queues in error recovery Sagi Grimberg
@ 2022-11-15 4:18 ` Chaitanya Kulkarni
0 siblings, 0 replies; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:18 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
On 11/13/22 03:24, Sagi Grimberg wrote:
> when starting error recovery there might be a authentication work
> running, and it involves I/O commands. Given the controller is tearing
> down there is no chance for the I/O to complete other than timing out
> which may unnecessarily take a full io timeout.
>
> So first tear down the queues, fail/cancel all inflight I/O (including
> potentially authentication) and only then stop authentication. This
> ensures that failover is not stalled due to blocked authentication I/O.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
It will be really cool to add error injection knob and with blktest
for this scenario...
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 20/20] nvme-rdma: stop auth work after tearing down queues in error recovery
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (18 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 19/20] nvme-tcp: stop auth work after tearing down queues in error recovery Sagi Grimberg
@ 2022-11-13 11:24 ` Sagi Grimberg
2022-11-15 4:18 ` Chaitanya Kulkarni
2022-11-15 10:11 ` [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Christoph Hellwig
20 siblings, 1 reply; 46+ messages in thread
From: Sagi Grimberg @ 2022-11-13 11:24 UTC (permalink / raw)
To: linux-nvme
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
when starting error recovery there might be a authentication work
running, and it involves I/O commands. Given the controller is tearing
down there is no chance for the I/O to complete other than timing out
which may unnecessarily take a full io timeout.
So first tear down the queues, fail/cancel all inflight I/O (including
potentially authentication) and only then stop authentication. This
ensures that failover is not stalled due to blocked authentication I/O.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/rdma.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 6e079abb22ee..ff1a6924f339 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -1153,13 +1153,13 @@ static void nvme_rdma_error_recovery_work(struct work_struct *work)
struct nvme_rdma_ctrl *ctrl = container_of(work,
struct nvme_rdma_ctrl, err_work);
- nvme_auth_stop(&ctrl->ctrl);
nvme_stop_keep_alive(&ctrl->ctrl);
flush_work(&ctrl->ctrl.async_event_work);
nvme_rdma_teardown_io_queues(ctrl, false);
nvme_start_queues(&ctrl->ctrl);
nvme_rdma_teardown_admin_queue(ctrl, false);
nvme_start_admin_queue(&ctrl->ctrl);
+ nvme_auth_stop(&ctrl->ctrl);
if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {
/* state change failure is ok if we started ctrl delete */
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread* Re: [PATCH v2 20/20] nvme-rdma: stop auth work after tearing down queues in error recovery
2022-11-13 11:24 ` [PATCH v2 20/20] nvme-rdma: " Sagi Grimberg
@ 2022-11-15 4:18 ` Chaitanya Kulkarni
0 siblings, 0 replies; 46+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-15 4:18 UTC (permalink / raw)
To: Sagi Grimberg, linux-nvme@lists.infradead.org
Cc: Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
On 11/13/22 03:24, Sagi Grimberg wrote:
> when starting error recovery there might be a authentication work
> running, and it involves I/O commands. Given the controller is tearing
> down there is no chance for the I/O to complete other than timing out
> which may unnecessarily take a full io timeout.
>
> So first tear down the queues, fail/cancel all inflight I/O (including
> potentially authentication) and only then stop authentication. This
> ensures that failover is not stalled due to blocked authentication I/O.
>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
Same here...
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code
2022-11-13 11:24 [PATCH v2 00/20] nvme: fixes, cleanups and enhancements to the dhchap-auth host code Sagi Grimberg
` (19 preceding siblings ...)
2022-11-13 11:24 ` [PATCH v2 20/20] nvme-rdma: " Sagi Grimberg
@ 2022-11-15 10:11 ` Christoph Hellwig
20 siblings, 0 replies; 46+ messages in thread
From: Christoph Hellwig @ 2022-11-15 10:11 UTC (permalink / raw)
To: Sagi Grimberg
Cc: linux-nvme, Christoph Hellwig, Keith Busch, Chaitanya Kulkarni,
Hannes Reinecke
Thanks, added to nvme-6.2 with the struct move dropped and the
mempool and slab marked static.
^ permalink raw reply [flat|nested] 46+ messages in thread