* [PATCH 0/2] nvme-auth: use SHASH_DESC_ON_STACK
@ 2025-05-07 8:28 Hannes Reinecke
2025-05-07 8:28 ` [PATCH 1/2] " Hannes Reinecke
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Hannes Reinecke @ 2025-05-07 8:28 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Keith Busch, Sagi Grimberg, linux-nvme, Hannes Reinecke
From: Hannes Reinecke <hare@suse.de>
Hi all,
we should be using SHASH_DESC_ON_STACK in the
nvme authentication code to save some memory allocations.
Hannes Reinecke (2):
nvme-auth: use SHASH_DESC_ON_STACK
nvmet-auth: use SHASH_DESC_ON_STACK
drivers/nvme/common/auth.c | 15 ++-------------
drivers/nvme/target/auth.c | 12 ++----------
2 files changed, 4 insertions(+), 23 deletions(-)
--
2.35.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] nvme-auth: use SHASH_DESC_ON_STACK
2025-05-07 8:28 [PATCH 0/2] nvme-auth: use SHASH_DESC_ON_STACK Hannes Reinecke
@ 2025-05-07 8:28 ` Hannes Reinecke
2025-05-07 9:37 ` Damien Le Moal
2025-05-07 8:28 ` [PATCH 2/2] nvmet-auth: " Hannes Reinecke
2025-05-09 5:06 ` [PATCH 0/2] nvme-auth: " Christoph Hellwig
2 siblings, 1 reply; 6+ messages in thread
From: Hannes Reinecke @ 2025-05-07 8:28 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Keith Busch, Sagi Grimberg, linux-nvme, Hannes Reinecke
Use SHASH_DESC_ON_STACK to avoid explicit allocation.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
drivers/nvme/common/auth.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
index 2c092ec8c0a9..3b6d759bcdf2 100644
--- a/drivers/nvme/common/auth.c
+++ b/drivers/nvme/common/auth.c
@@ -242,7 +242,7 @@ struct nvme_dhchap_key *nvme_auth_transform_key(
{
const char *hmac_name;
struct crypto_shash *key_tfm;
- struct shash_desc *shash;
+ SHASH_DESC_ON_STACK(shash, key_tfm);
struct nvme_dhchap_key *transformed_key;
int ret, key_len;
@@ -267,19 +267,11 @@ struct nvme_dhchap_key *nvme_auth_transform_key(
if (IS_ERR(key_tfm))
return ERR_CAST(key_tfm);
- shash = kmalloc(sizeof(struct shash_desc) +
- crypto_shash_descsize(key_tfm),
- GFP_KERNEL);
- if (!shash) {
- ret = -ENOMEM;
- goto out_free_key;
- }
-
key_len = crypto_shash_digestsize(key_tfm);
transformed_key = nvme_auth_alloc_key(key_len, key->hash);
if (!transformed_key) {
ret = -ENOMEM;
- goto out_free_shash;
+ goto out_free_key;
}
shash->tfm = key_tfm;
@@ -299,15 +291,12 @@ struct nvme_dhchap_key *nvme_auth_transform_key(
if (ret < 0)
goto out_free_transformed_key;
- kfree(shash);
crypto_free_shash(key_tfm);
return transformed_key;
out_free_transformed_key:
nvme_auth_free_key(transformed_key);
-out_free_shash:
- kfree(shash);
out_free_key:
crypto_free_shash(key_tfm);
--
2.35.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] nvmet-auth: use SHASH_DESC_ON_STACK
2025-05-07 8:28 [PATCH 0/2] nvme-auth: use SHASH_DESC_ON_STACK Hannes Reinecke
2025-05-07 8:28 ` [PATCH 1/2] " Hannes Reinecke
@ 2025-05-07 8:28 ` Hannes Reinecke
2025-05-07 9:37 ` Damien Le Moal
2025-05-09 5:06 ` [PATCH 0/2] nvme-auth: " Christoph Hellwig
2 siblings, 1 reply; 6+ messages in thread
From: Hannes Reinecke @ 2025-05-07 8:28 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Keith Busch, Sagi Grimberg, linux-nvme, Hannes Reinecke
Use SHASH_DESC_ON_STACK to avoid explicit allocation.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
drivers/nvme/target/auth.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
index cef8d77f477b..5dc9f3097c4c 100644
--- a/drivers/nvme/target/auth.c
+++ b/drivers/nvme/target/auth.c
@@ -290,7 +290,7 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
unsigned int shash_len)
{
struct crypto_shash *shash_tfm;
- struct shash_desc *shash;
+ SHASH_DESC_ON_STACK(shash, shash_tfm);
struct nvmet_ctrl *ctrl = req->sq->ctrl;
const char *hash_name;
u8 *challenge = req->sq->dhchap_c1;
@@ -342,19 +342,13 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
req->sq->dhchap_c1,
challenge, shash_len);
if (ret)
- goto out_free_challenge;
+ goto out;
}
pr_debug("ctrl %d qid %d host response seq %u transaction %d\n",
ctrl->cntlid, req->sq->qid, req->sq->dhchap_s1,
req->sq->dhchap_tid);
- shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(shash_tfm),
- GFP_KERNEL);
- if (!shash) {
- ret = -ENOMEM;
- goto out_free_challenge;
- }
shash->tfm = shash_tfm;
ret = crypto_shash_init(shash);
if (ret)
@@ -389,8 +383,6 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
goto out;
ret = crypto_shash_final(shash, response);
out:
- kfree(shash);
-out_free_challenge:
if (challenge != req->sq->dhchap_c1)
kfree(challenge);
out_free_response:
--
2.35.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] nvme-auth: use SHASH_DESC_ON_STACK
2025-05-07 8:28 ` [PATCH 1/2] " Hannes Reinecke
@ 2025-05-07 9:37 ` Damien Le Moal
0 siblings, 0 replies; 6+ messages in thread
From: Damien Le Moal @ 2025-05-07 9:37 UTC (permalink / raw)
To: Hannes Reinecke, Christoph Hellwig; +Cc: Keith Busch, Sagi Grimberg, linux-nvme
On 5/7/25 5:28 PM, Hannes Reinecke wrote:
> Use SHASH_DESC_ON_STACK to avoid explicit allocation.
>
> Signed-off-by: Hannes Reinecke <hare@kernel.org>
Looks good to me.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] nvmet-auth: use SHASH_DESC_ON_STACK
2025-05-07 8:28 ` [PATCH 2/2] nvmet-auth: " Hannes Reinecke
@ 2025-05-07 9:37 ` Damien Le Moal
0 siblings, 0 replies; 6+ messages in thread
From: Damien Le Moal @ 2025-05-07 9:37 UTC (permalink / raw)
To: Hannes Reinecke, Christoph Hellwig; +Cc: Keith Busch, Sagi Grimberg, linux-nvme
On 5/7/25 5:28 PM, Hannes Reinecke wrote:
> Use SHASH_DESC_ON_STACK to avoid explicit allocation.
>
> Signed-off-by: Hannes Reinecke <hare@kernel.org>
Looks good to me.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] nvme-auth: use SHASH_DESC_ON_STACK
2025-05-07 8:28 [PATCH 0/2] nvme-auth: use SHASH_DESC_ON_STACK Hannes Reinecke
2025-05-07 8:28 ` [PATCH 1/2] " Hannes Reinecke
2025-05-07 8:28 ` [PATCH 2/2] nvmet-auth: " Hannes Reinecke
@ 2025-05-09 5:06 ` Christoph Hellwig
2 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2025-05-09 5:06 UTC (permalink / raw)
To: Hannes Reinecke
Cc: Christoph Hellwig, Keith Busch, Sagi Grimberg, linux-nvme,
Hannes Reinecke
Thanks,
applied to nvme-6.16.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-05-09 5:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-07 8:28 [PATCH 0/2] nvme-auth: use SHASH_DESC_ON_STACK Hannes Reinecke
2025-05-07 8:28 ` [PATCH 1/2] " Hannes Reinecke
2025-05-07 9:37 ` Damien Le Moal
2025-05-07 8:28 ` [PATCH 2/2] nvmet-auth: " Hannes Reinecke
2025-05-07 9:37 ` Damien Le Moal
2025-05-09 5:06 ` [PATCH 0/2] nvme-auth: " Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox