crypto: talitos - fix rename first/last to first_desc/last_desc
Subsystems (2)
PATCH 1/1 crypto: talitos - fix rename first/last to first_desc/last_desc
Hi,
Commit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y with a866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last to last_desc but misses one occurrence which leads to compile errors on mpc85xx
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'struct talitos_ahash_req_ctx' has no member named 'last'
2204 | req_ctx->last = 1;
| ^~4--- drivers/crypto/talitos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/talitos.c +1 -1
@@ -2201,7 +2201,7 @@ static int ahash_digest(struct ahash_request *areq)struct crypto_ahash *ahash =crypto_ahash_reqtfm (areq); ahash->init (areq); - req_ctx->last =1 ; + req_ctx->last_desc =1 ;return ahash_process_req (areq, areq->nbytes); }
Signature · 1 line
2.54.0
Quoted 5 lines · Goetz Goerisch
Hi,
Commit
a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y witha866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last tolast_descbut misses one occurrence which leads to compile errors on mpc85xx
Hi Goetz,
Thank you for the patch. I did not catch that since I worked on a mainline tree, and that specific line was removed in 9826d1d6ed5f ("crypto: talitos - stop using crypto_ahash::init"), which was not backported into the stable tree.
Quoted 16 lines
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'structtalitos_ahash_req_ctx' has no member named 'last'2204 | req_ctx->last = 1; | ^~4Fixes a866e2b1c65e ("crypto: talitos - rename first/last to first_desc/last_desc")Signed-off-by Goetz Goerisch <[email protected]>--- drivers/crypto/talitos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/talitos.c +0
-0
drivers/crypto/talitos.c static int ahash_digest(struct ahash_request *areq) · line 2204
Quoted 5 lines
drivers/crypto/talitos.c +1
-1@@ -2201,7 +2201,7 @@ static int ahash_digest(struct ahash_request *areq)struct crypto_ahash *ahash =crypto_ahash_reqtfm (areq); ahash->init (areq); - req_ctx->last =1 ; + req_ctx->last_desc =1 ;
Instead of renaming req_ctx->last, commit 9826d1d6ed5f8 ("crypto: talitos - stop using crypto_ahash::init") should be applied. Ideally before commit 655ef638a2bc ("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
drivers/crypto/talitos.c static int ahash_digest(struct ahash_request *areq) · line 2207
Quoted 3 lines
drivers/crypto/talitos.c +0
-0return ahash_process_req (areq, areq->nbytes); }
Paul.
Signature · 3 lines
Paul Louvel, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 31 lines · Paul Louvel
Quoted 5 lines · Goetz Goerisch
Hi,
Commit
a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y witha866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last tolast_descbut misses one occurrence which leads to compile errors on mpc85xxHi Goetz,
Thank you for the patch. I did not catch that since I worked on a mainline tree, and that specific line was removed in
9826d1d6ed5f("crypto: talitos - stop usingcrypto_ahash::init"), which was not backported into the stable tree.Quoted 18 lines
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'structtalitos_ahash_req_ctx' has no member named 'last'2204 | req_ctx->last = 1; | ^~4Fixes a866e2b1c65e ("crypto: talitos - rename first/last to first_desc/last_desc")Signed-off-by Goetz Goerisch <[email protected]>--- drivers/crypto/talitos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/talitos.c +0
-0@@ -2201,7 +2201,7 @@ static int ahash_digest(struct ahash_request *areq)struct crypto_ahash *ahash =crypto_ahash_reqtfm (areq);
Quoted 8 lines
drivers/crypto/talitos.c static int ahash_digest(struct ahash_request *areq) · line 2204
Quoted 3 lines
drivers/crypto/talitos.c +1
-1ahash->init (areq); - req_ctx->last =1 ; + req_ctx->last_desc =1 ;Instead of renaming
req_ctx->last, commit9826d1d6ed5f8("crypto: talitos - stop usingcrypto_ahash::init") should be applied. Ideally before commit655ef638a2bc("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
Small correction:
Ideally before commit 00463d5f864a ("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
Quoted 6 lines
drivers/crypto/talitos.c static int ahash_digest(struct ahash_request *areq) · line 2207
Quoted 4 lines
drivers/crypto/talitos.c +0
-0return ahash_process_req (areq, areq->nbytes); }Paul.
Signature · 3 lines
Paul Louvel, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Dear Paul,
Thank you for this review and feedback.
Quoted 10 lines
Quoted 4 lines
Instead of renaming
req_ctx->last, commit9826d1d6ed5f8("crypto: talitos - stop usingcrypto_ahash::init") should be applied. Ideally before commit655ef638a2bc("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.Small correction:
Ideally before commit
00463d5f864a("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
I can confirm your recommendation. Appyling this commit before, fixes the problem. Please disregard my patch.
Greg could you please backport the mentioned commit to 6.6.y in the correct order for the next update?
I have fixed it for our downstream users for now.
Thank you,
Goetz
Greg Kroah-Hartman
maintainerQuoted 11 lines · Goetz Goerisch
Dear Paul,
Thank you for this review and feedback.
Quoted 7 lines
Quoted 4 lines
Instead of renaming
req_ctx->last, commit9826d1d6ed5f8("crypto: talitos - stop usingcrypto_ahash::init") should be applied. Ideally before commit655ef638a2bc("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.Small correction:
Quoted 7 lines
Quoted 3 lines
Ideally before commit
00463d5f864a("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.I can confirm your recommendation. Appyling this commit before, fixes the problem. Please disregard my patch.
Greg could you please backport the mentioned commit to 6.6.y in the correct order for the next update?
Can you send a series of backported patches in the correct order for us to apply, so we know to get them correct? Trying to dig out from an email like this is usually quite easy to get wrong :)
thanks,
greg k-h
cover crypto: talitos - fix rename first/last to first_desc/last_desc
Commit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y with a866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last to last_desc but misses one occurrence which leads to compile errors on mpc85xx
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'struct talitos_ahash_req_ctx' has no member named 'last'
2204 | req_ctx->last = 1;
| ^~~~Instead of renaming req_ctx->last, commit 9826d1d6ed5f8 ("crypto: talitos - stop using crypto_ahash::init") should be applied.
Ideally before commit 00463d5f864a ("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
Quoted 5 lines
Quoted 1 line
Greg could you please backport the mentioned commit to 6.6.y in the correct order for the next update?
Can you send a series of backported patches in the correct order for us to apply, so we know to get them correct? Trying to dig out from an email like this is usually quite easy to get wrong :)
Hope this is correct.
Goetz
Eric Biggers (1):
crypto: talitos - stop using crypto_ahash::init
Goetz Goerisch (2):
Revert "crypto: talitos - rename first/last to first_desc/last_desc" Revert "crypto: talitos - fix SEC1 32k ahash request limitation"
Paul Louvel (2):
crypto: talitos - fix SEC1 32k ahash request limitation
crypto: talitos - rename first/last to first_desc/last_desc
drivers/crypto/talitos.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/5 Revert "crypto: talitos - rename first/last to first_desc/last_desc"
This reverts commit a866e2b1c65edaee2e1bb1024ee2c761ced335f8.
--- drivers/crypto/talitos.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
drivers/crypto/talitos.c +23 -23
@@ -869,8 +869,8 @@ struct talitos_ahash_req_ctx {u8 buf[2 ][HASH_MAX_BLOCK_SIZE ];int buf_idx;unsigned int swinit; -unsigned int first_desc; -unsigned int last_desc; +unsigned int first; +unsigned int last;unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;
@@ -889,8 +889,8 @@ struct talitos_export_state {u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE /sizeof (u32)];u8 buf[HASH_MAX_BLOCK_SIZE ];unsigned int swinit; -unsigned int first_desc; -unsigned int last_desc; +unsigned int first; +unsigned int last;unsigned int to_hash_later;unsigned int nbuf; };
@@ -1722,7 +1722,7 @@ static void common_nonsnoop_hash_unmap(struct device *dev,if (desc->next_desc && desc->ptr[5 ].ptr != desc2->ptr[5 ].ptr)unmap_single_talitos_ptr (dev, &desc2->ptr[5 ],DMA_FROM_DEVICE ); -if (req_ctx->last_desc) +if (req_ctx->last)memcpy (areq->result, req_ctx->hw_context,crypto_ahash_digestsize (tfm));
@@ -1759,7 +1759,7 @@ static void ahash_done(struct device *dev, container_of(desc, struct talitos_edesc, desc);struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -if (!req_ctx->last_desc && req_ctx->to_hash_later) { +if (!req_ctx->last && req_ctx->to_hash_later) {/* Position any partial block for next update/final/finup */ req_ctx->buf_idx = (req_ctx->buf_idx +1 ) &1 ; req_ctx->nbuf = req_ctx->to_hash_later;
@@ -1825,7 +1825,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* first DWORD empty */ /* hash context in */ -if (!req_ctx->first_desc || req_ctx->swinit) { +if (!req_ctx->first || req_ctx->swinit) { map_single_talitos_ptr_nosync(dev, &desc->ptr[1], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1833,7 +1833,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, req_ctx->swinit =0 ; }/* Indicate next op is not the first. */ - req_ctx->first_desc =0 ; + req_ctx->first =0 ;/* HMAC key */ if (ctx->keylen)
@@ -1866,7 +1866,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* fifth DWORD empty */ /* hash/HMAC out -or- hash context out */ -if (req_ctx->last_desc) +if (req_ctx->last)map_single_talitos_ptr (dev, &desc->ptr[5 ],crypto_ahash_digestsize (tfm), req_ctx->hw_context,DMA_FROM_DEVICE );
@@ -1908,7 +1908,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,if (sg_count >1 ) sync_needed = true;copy_talitos_ptr (&desc2->ptr[5 ], &desc->ptr[5 ], is_sec1); -if (req_ctx->last_desc) +if (req_ctx->last) map_single_talitos_ptr_nosync(dev, &desc->ptr[5], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1964,7 +1964,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesbool is_sec1 =has_ftr_sec1 (priv);u8 *ctx_buf = req_ctx->buf[req_ctx->buf_idx]; -if (!req_ctx->last_desc && (nbytes + req_ctx->nbuf <= blocksize)) { +if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {
@@ -1981,7 +1981,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes nbytes_to_hash = nbytes + req_ctx->nbuf; to_hash_later = nbytes_to_hash & (blocksize -1 ); -if (req_ctx->last_desc) +if (req_ctx->last) to_hash_later =0 ;else if (to_hash_later)/* There is a partial block. Hash the full block(s) now */
@@ -2041,19 +2041,19 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes edesc->desc.hdr = ctx->desc_hdr_template;/* On last one, request SEC to pad; otherwise continue */ -if (req_ctx->last_desc) +if (req_ctx->last) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_PAD ;else edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_CONT ;/* request SEC to INIT hash. */ -if (req_ctx->first_desc && !req_ctx->swinit) +if (req_ctx->first && !req_ctx->swinit) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_INIT ;/* When the tfm context has a keylen, it's an HMAC. * A first or last (ie. not middle) descriptor must request HMAC. */ -if (ctx->keylen && (req_ctx->first_desc || req_ctx->last_desc)) +if (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ;return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done);
@@ -2076,7 +2076,7 @@ static void sec1_ahash_process_remaining(struct work_struct *work) req_ctx->remaining_ahash_request_bytes;if (req_ctx->last_request) - req_ctx->last_desc =1 ; + req_ctx->last =1 ; } err = ahash_process_req_one(req_ctx->areq,
@@ -2103,7 +2103,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (nbytes >TALITOS1_MAX_DATA_LEN ) nbytes =TALITOS1_MAX_DATA_LEN ;else if (req_ctx->last_request) - req_ctx->last_desc =1 ; + req_ctx->last =1 ; } req_ctx->current_ahash_request_bytes = nbytes;
@@ -2124,14 +2124,14 @@ static int ahash_init(struct ahash_request *areq)/* Initialize the context */ req_ctx->buf_idx =0 ; req_ctx->nbuf =0 ; - req_ctx->first_desc =1 ;/* first_desc indicates h/w must init its context */ + req_ctx->first =1 ;/* first indicates h/w must init its context */ req_ctx->swinit =0 ;/* assume h/w init of context */ size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; req_ctx->hw_context_size = size; req_ctx->last_request =0 ; - req_ctx->last_desc =0 ; + req_ctx->last =0 ;INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size,
@@ -2223,8 +2223,8 @@ static int ahash_export(struct ahash_request *areq, void *out) req_ctx->hw_context_size);memcpy (export->buf, req_ctx->buf[req_ctx->buf_idx], req_ctx->nbuf); export->swinit = req_ctx->swinit; - export->first_desc = req_ctx->first_desc; - export->last_desc = req_ctx->last_desc; + export->first = req_ctx->first; + export->last = req_ctx->last; export->to_hash_later = req_ctx->to_hash_later; export->nbuf = req_ctx->nbuf;
@@ -2249,8 +2249,8 @@ static int ahash_import(struct ahash_request *areq, const void *in)memcpy (req_ctx->hw_context, export->hw_context, size);memcpy (req_ctx->buf[0 ], export->buf, export->nbuf); req_ctx->swinit = export->swinit; - req_ctx->first_desc = export->first_desc; - req_ctx->last_desc = export->last_desc; + req_ctx->first = export->first; + req_ctx->last = export->last; req_ctx->to_hash_later = export->to_hash_later; req_ctx->nbuf = export->nbuf;
Signature · 1 line
2.54.0
Greg KH
maintainerRe: [PATCH 1/5] Revert "crypto: talitos - rename first/last to first_desc/last_desc"
Quoted 2 lines · Goetz Goerisch
This reverts commit
a866e2b1c65edaee2e1bb1024ee2c761ced335f8.
---
We need a reason for a revert, AND a signed off-by line :(
Please fix that up for the other revert in this series and resend.
thanks,
greg k-h
v2 cover crypto: talitos - fix rename first/last to first_desc/last_desc
Thank you Greg for this feedback.
v2: add reason and SoB to revert commit which was missing.
Commit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y with a866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last to last_desc but misses one occurrence which leads to compile errors on mpc85xx
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'struct talitos_ahash_req_ctx' has no member named 'last'
2204 | req_ctx->last = 1;
| ^~~~Instead of renaming req_ctx->last, commit 9826d1d6ed5f8 ("crypto: talitos - stop using crypto_ahash::init") should be applied.
Ideally before commit 00463d5f864a ("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
Quoted 5 lines
Quoted 1 line
Greg could you please backport the mentioned commit to 6.6.y in the correct order for the next update?
Can you send a series of backported patches in the correct order for us to apply, so we know to get them correct? Trying to dig out from an email like this is usually quite easy to get wrong :)
Hope this is correct.
Goetz
Eric Biggers (1):
crypto: talitos - stop using crypto_ahash::init
Goetz Goerisch (2):
Revert "crypto: talitos - rename first/last to first_desc/last_desc" Revert "crypto: talitos - fix SEC1 32k ahash request limitation"
Paul Louvel (2):
crypto: talitos - fix SEC1 32k ahash request limitation
crypto: talitos - rename first/last to first_desc/last_desc
drivers/crypto/talitos.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/5 Revert "crypto: talitos - rename first/last to first_desc/last_desc"
This reverts commit a866e2b1c65edaee2e1bb1024ee2c761ced335f8.
--- drivers/crypto/talitos.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
drivers/crypto/talitos.c +23 -23
@@ -869,8 +869,8 @@ struct talitos_ahash_req_ctx {u8 buf[2 ][HASH_MAX_BLOCK_SIZE ];int buf_idx;unsigned int swinit; -unsigned int first_desc; -unsigned int last_desc; +unsigned int first; +unsigned int last;unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;
@@ -889,8 +889,8 @@ struct talitos_export_state {u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE /sizeof (u32)];u8 buf[HASH_MAX_BLOCK_SIZE ];unsigned int swinit; -unsigned int first_desc; -unsigned int last_desc; +unsigned int first; +unsigned int last;unsigned int to_hash_later;unsigned int nbuf; };
@@ -1722,7 +1722,7 @@ static void common_nonsnoop_hash_unmap(struct device *dev,if (desc->next_desc && desc->ptr[5 ].ptr != desc2->ptr[5 ].ptr)unmap_single_talitos_ptr (dev, &desc2->ptr[5 ],DMA_FROM_DEVICE ); -if (req_ctx->last_desc) +if (req_ctx->last)memcpy (areq->result, req_ctx->hw_context,crypto_ahash_digestsize (tfm));
@@ -1759,7 +1759,7 @@ static void ahash_done(struct device *dev, container_of(desc, struct talitos_edesc, desc);struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -if (!req_ctx->last_desc && req_ctx->to_hash_later) { +if (!req_ctx->last && req_ctx->to_hash_later) {/* Position any partial block for next update/final/finup */ req_ctx->buf_idx = (req_ctx->buf_idx +1 ) &1 ; req_ctx->nbuf = req_ctx->to_hash_later;
@@ -1825,7 +1825,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* first DWORD empty */ /* hash context in */ -if (!req_ctx->first_desc || req_ctx->swinit) { +if (!req_ctx->first || req_ctx->swinit) { map_single_talitos_ptr_nosync(dev, &desc->ptr[1], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1833,7 +1833,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, req_ctx->swinit =0 ; }/* Indicate next op is not the first. */ - req_ctx->first_desc =0 ; + req_ctx->first =0 ;/* HMAC key */ if (ctx->keylen)
@@ -1866,7 +1866,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* fifth DWORD empty */ /* hash/HMAC out -or- hash context out */ -if (req_ctx->last_desc) +if (req_ctx->last)map_single_talitos_ptr (dev, &desc->ptr[5 ],crypto_ahash_digestsize (tfm), req_ctx->hw_context,DMA_FROM_DEVICE );
@@ -1908,7 +1908,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,if (sg_count >1 ) sync_needed = true;copy_talitos_ptr (&desc2->ptr[5 ], &desc->ptr[5 ], is_sec1); -if (req_ctx->last_desc) +if (req_ctx->last) map_single_talitos_ptr_nosync(dev, &desc->ptr[5], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1964,7 +1964,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesbool is_sec1 =has_ftr_sec1 (priv);u8 *ctx_buf = req_ctx->buf[req_ctx->buf_idx]; -if (!req_ctx->last_desc && (nbytes + req_ctx->nbuf <= blocksize)) { +if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {
@@ -1981,7 +1981,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes nbytes_to_hash = nbytes + req_ctx->nbuf; to_hash_later = nbytes_to_hash & (blocksize -1 ); -if (req_ctx->last_desc) +if (req_ctx->last) to_hash_later =0 ;else if (to_hash_later)/* There is a partial block. Hash the full block(s) now */
@@ -2041,19 +2041,19 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes edesc->desc.hdr = ctx->desc_hdr_template;/* On last one, request SEC to pad; otherwise continue */ -if (req_ctx->last_desc) +if (req_ctx->last) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_PAD ;else edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_CONT ;/* request SEC to INIT hash. */ -if (req_ctx->first_desc && !req_ctx->swinit) +if (req_ctx->first && !req_ctx->swinit) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_INIT ;/* When the tfm context has a keylen, it's an HMAC. * A first or last (ie. not middle) descriptor must request HMAC. */ -if (ctx->keylen && (req_ctx->first_desc || req_ctx->last_desc)) +if (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ;return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done);
@@ -2076,7 +2076,7 @@ static void sec1_ahash_process_remaining(struct work_struct *work) req_ctx->remaining_ahash_request_bytes;if (req_ctx->last_request) - req_ctx->last_desc =1 ; + req_ctx->last =1 ; } err = ahash_process_req_one(req_ctx->areq,
@@ -2103,7 +2103,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (nbytes >TALITOS1_MAX_DATA_LEN ) nbytes =TALITOS1_MAX_DATA_LEN ;else if (req_ctx->last_request) - req_ctx->last_desc =1 ; + req_ctx->last =1 ; } req_ctx->current_ahash_request_bytes = nbytes;
@@ -2124,14 +2124,14 @@ static int ahash_init(struct ahash_request *areq)/* Initialize the context */ req_ctx->buf_idx =0 ; req_ctx->nbuf =0 ; - req_ctx->first_desc =1 ;/* first_desc indicates h/w must init its context */ + req_ctx->first =1 ;/* first indicates h/w must init its context */ req_ctx->swinit =0 ;/* assume h/w init of context */ size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; req_ctx->hw_context_size = size; req_ctx->last_request =0 ; - req_ctx->last_desc =0 ; + req_ctx->last =0 ;INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size,
@@ -2223,8 +2223,8 @@ static int ahash_export(struct ahash_request *areq, void *out) req_ctx->hw_context_size);memcpy (export->buf, req_ctx->buf[req_ctx->buf_idx], req_ctx->nbuf); export->swinit = req_ctx->swinit; - export->first_desc = req_ctx->first_desc; - export->last_desc = req_ctx->last_desc; + export->first = req_ctx->first; + export->last = req_ctx->last; export->to_hash_later = req_ctx->to_hash_later; export->nbuf = req_ctx->nbuf;
@@ -2249,8 +2249,8 @@ static int ahash_import(struct ahash_request *areq, const void *in)memcpy (req_ctx->hw_context, export->hw_context, size);memcpy (req_ctx->buf[0 ], export->buf, export->nbuf); req_ctx->swinit = export->swinit; - req_ctx->first_desc = export->first_desc; - req_ctx->last_desc = export->last_desc; + req_ctx->first = export->first; + req_ctx->last = export->last; req_ctx->to_hash_later = export->to_hash_later; req_ctx->nbuf = export->nbuf;
Signature · 1 line
2.54.0
PATCH 2/5 Revert "crypto: talitos - fix SEC1 32k ahash request limitation"
In reply to Goetz GoerischThis reverts commit 00463d5f864ae28b7938d5acd0ddd800d5457e8b.
--- drivers/crypto/talitos.c | 216 +++++++++++++-------------------------- 1 file changed, 69 insertions(+), 147 deletions(-)
drivers/crypto/talitos.c +69 -147
@@ -12,7 +12,6 @@* All rights reserved. */ -#include <linux/workqueue.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mod_devicetable.h>
@@ -871,18 +870,10 @@ struct talitos_ahash_req_ctx {unsigned int swinit;unsigned int first;unsigned int last; -unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;struct scatterlist bufsl[2 ];struct scatterlist *psrc; - -struct scatterlist request_bufsl[2 ]; -struct ahash_request *areq; -struct scatterlist *request_sl; -unsigned int remaining_ahash_request_bytes; -unsigned int current_ahash_request_bytes; -struct work_struct sec1_ahash_process_remaining; };struct talitos_export_state {
@@ -1768,20 +1759,7 @@ static void ahash_done(struct device *dev,kfree (edesc); -if (err) { -ahash_request_complete (areq, err); -return ; - } - - req_ctx->remaining_ahash_request_bytes -= - req_ctx->current_ahash_request_bytes; - -if (!req_ctx->remaining_ahash_request_bytes) { -ahash_request_complete (areq,0 ); -return ; - } - -schedule_work (&req_ctx->sec1_ahash_process_remaining); +ahash_request_complete (areq, err); }/*
@@ -1947,7 +1925,60 @@ static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, nbytes, 0, 0, 0, areq->base.flags, false); } -static int ahash_process_req_one (struct ahash_request *areq,unsigned int nbytes) +static int ahash_init (struct ahash_request *areq) +{ +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev; +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +unsigned int size; +dma_addr_t dma; + +/* Initialize the context */ + req_ctx->buf_idx =0 ; + req_ctx->nbuf =0 ; + req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->swinit =0 ;/* assume h/w init of context */ + size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) + ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 + :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; + req_ctx->hw_context_size = size; + + dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, +DMA_TO_DEVICE ); +dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); + +return 0 ; +} + +/* +* on h/w without explicit sha224 support, we initialize h/w context +* manually with sha224 constants, and tell it to run sha256. +*/ +static int ahash_init_sha224_swinit (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->hw_context[0 ] =SHA224_H0 ; + req_ctx->hw_context[1 ] =SHA224_H1 ; + req_ctx->hw_context[2 ] =SHA224_H2 ; + req_ctx->hw_context[3 ] =SHA224_H3 ; + req_ctx->hw_context[4 ] =SHA224_H4 ; + req_ctx->hw_context[5 ] =SHA224_H5 ; + req_ctx->hw_context[6 ] =SHA224_H6 ; + req_ctx->hw_context[7 ] =SHA224_H7 ; + +/* init 64-bit count */ + req_ctx->hw_context[8 ] =0 ; + req_ctx->hw_context[9 ] =0 ; + +ahash_init (areq); + req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ + +return 0 ; +} + +static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) {struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq);struct talitos_ctx *ctx =crypto_ahash_ctx (tfm);
@@ -1966,12 +1997,12 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesif (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ - nents =sg_nents_for_len (req_ctx->request_sl, nbytes); + nents =sg_nents_for_len (areq->src, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (req_ctx->request_sl, nents, +sg_copy_to_buffer (areq->src, nents, ctx_buf + req_ctx->nbuf, nbytes); req_ctx->nbuf += nbytes;return 0 ;
@@ -1998,7 +2029,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytessg_init_table (req_ctx->bufsl, nsg);sg_set_buf (req_ctx->bufsl, ctx_buf, req_ctx->nbuf);if (nsg >1 ) -sg_chain (req_ctx->bufsl,2 , req_ctx->request_sl); +sg_chain (req_ctx->bufsl,2 , areq->src); req_ctx->psrc = req_ctx->bufsl; }else if (is_sec1 && req_ctx->nbuf && req_ctx->nbuf < blocksize) {int offset;
@@ -2007,26 +2038,26 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes offset = blocksize - req_ctx->nbuf; else offset = nbytes_to_hash - req_ctx->nbuf; - nents =sg_nents_for_len (req_ctx->request_sl, offset); + nents =sg_nents_for_len (areq->src, offset);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (req_ctx->request_sl, nents, +sg_copy_to_buffer (areq->src, nents, ctx_buf + req_ctx->nbuf, offset); req_ctx->nbuf += offset; - req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, req_ctx->request_sl, + req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, areq->src, offset); }else - req_ctx->psrc = req_ctx->request_sl; + req_ctx->psrc = areq->src;if (to_hash_later) { - nents =sg_nents_for_len (req_ctx->request_sl, nbytes); + nents =sg_nents_for_len (areq->src, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_pcopy_to_buffer (req_ctx->request_sl, nents, +sg_pcopy_to_buffer (areq->src, nents, req_ctx->buf[(req_ctx->buf_idx +1 ) &1 ], to_hash_later, nbytes - to_hash_later);
@@ -2034,7 +2065,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes req_ctx->to_hash_later = to_hash_later;/* Allocate extended descriptor */ - edesc =ahash_edesc_alloc (req_ctx->areq, nbytes_to_hash); + edesc =ahash_edesc_alloc (areq, nbytes_to_hash);if (IS_ERR (edesc))return PTR_ERR (edesc);
@@ -2056,123 +2087,14 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesif (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ; -return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done); -} - -static void sec1_ahash_process_remaining (struct work_struct *work) -{ -struct talitos_ahash_req_ctx *req_ctx = - container_of(work, struct talitos_ahash_req_ctx, - sec1_ahash_process_remaining); -int err =0 ; - - req_ctx->request_sl =scatterwalk_ffwd (req_ctx->request_bufsl, - req_ctx->request_sl,TALITOS1_MAX_DATA_LEN ); - -if (req_ctx->remaining_ahash_request_bytes >TALITOS1_MAX_DATA_LEN ) - req_ctx->current_ahash_request_bytes =TALITOS1_MAX_DATA_LEN ; -else { - req_ctx->current_ahash_request_bytes = - req_ctx->remaining_ahash_request_bytes; - -if (req_ctx->last_request) - req_ctx->last =1 ; - } - - err =ahash_process_req_one (req_ctx->areq, - req_ctx->current_ahash_request_bytes); - -if (err != -EINPROGRESS ) -ahash_request_complete (req_ctx->areq, err); -} - -static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -struct talitos_private *priv =dev_get_drvdata (dev); -bool is_sec1 =has_ftr_sec1 (priv); - - req_ctx->areq = areq; - req_ctx->request_sl = areq->src; - req_ctx->remaining_ahash_request_bytes = nbytes; - -if (is_sec1) { -if (nbytes >TALITOS1_MAX_DATA_LEN ) - nbytes =TALITOS1_MAX_DATA_LEN ; -else if (req_ctx->last_request) - req_ctx->last =1 ; - } - - req_ctx->current_ahash_request_bytes = nbytes; - -return ahash_process_req_one (req_ctx->areq, - req_ctx->current_ahash_request_bytes); -} - -static int ahash_init (struct ahash_request *areq) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -unsigned int size; -dma_addr_t dma; - -/* Initialize the context */ - req_ctx->buf_idx =0 ; - req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ - req_ctx->swinit =0 ;/* assume h/w init of context */ - size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) - ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 - :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; - req_ctx->hw_context_size = size; - req_ctx->last_request =0 ; - req_ctx->last =0 ; -INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); - - dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, -DMA_TO_DEVICE ); -dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); - -return 0 ; -} - -/* -* on h/w without explicit sha224 support, we initialize h/w context -* manually with sha224 constants, and tell it to run sha256. -*/ -static int ahash_init_sha224_swinit (struct ahash_request *areq) -{ -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - - req_ctx->hw_context[0 ] =SHA224_H0 ; - req_ctx->hw_context[1 ] =SHA224_H1 ; - req_ctx->hw_context[2 ] =SHA224_H2 ; - req_ctx->hw_context[3 ] =SHA224_H3 ; - req_ctx->hw_context[4 ] =SHA224_H4 ; - req_ctx->hw_context[5 ] =SHA224_H5 ; - req_ctx->hw_context[6 ] =SHA224_H6 ; - req_ctx->hw_context[7 ] =SHA224_H7 ; - -/* init 64-bit count */ - req_ctx->hw_context[8 ] =0 ; - req_ctx->hw_context[9 ] =0 ; - -ahash_init (areq); - req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ - -return 0 ; +return common_nonsnoop_hash (edesc, areq, nbytes_to_hash, ahash_done); }static int ahash_update (struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =0 ; + req_ctx->last =0 ;return ahash_process_req (areq, areq->nbytes); }
@@ -2181,7 +2103,7 @@ static int ahash_final(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =1 ; + req_ctx->last =1 ;return ahash_process_req (areq,0 ); }
@@ -2190,7 +2112,7 @@ static int ahash_finup(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =1 ; + req_ctx->last =1 ;return ahash_process_req (areq, areq->nbytes); }
Signature · 1 line
2.54.0
PATCH 3/5 crypto: talitos - stop using crypto_ahash::init
In reply to Goetz GoerischFrom: Eric Biggers <[email protected]>
commit 9826d1d6ed5f86cb3d61610b3b1fe31e96a40418 upstream.
The function pointer crypto_ahash::init is an internal implementation detail of the ahash API that exists to help it support both ahash and shash algorithms. With an upcoming refactoring of how the ahash API supports shash algorithms, this field will be removed.
Some drivers are invoking crypto_ahash::init to call into their own code, which is unnecessary and inefficient. The talitos driver is one of those drivers. Make it just call its own code directly.
--- drivers/crypto/talitos.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/crypto/talitos.c +9 -6
@@ -2119,13 +2119,14 @@ static int ahash_finup(struct ahash_request *areq)static int ahash_digest (struct ahash_request *areq) { -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -struct crypto_ahash *ahash =crypto_ahash_reqtfm (areq); - - ahash->init (areq); - req_ctx->last =1 ; +ahash_init (areq); +return ahash_finup (areq); +} -return ahash_process_req (areq, areq->nbytes); +static int ahash_digest_sha224_swinit (struct ahash_request *areq) +{ +ahash_init_sha224_swinit (areq); +return ahash_finup (areq); }static int ahash_export (struct ahash_request *areq,void *out)
@@ -3242,6 +3243,8 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, (!strcmp(alg->cra_name, "sha224") || !strcmp(alg->cra_name, "hmac(sha224)"))) { t_alg->algt.alg.hash.init = ahash_init_sha224_swinit; + t_alg->algt.alg.hash.digest = + ahash_digest_sha224_swinit; t_alg->algt.desc_hdr_template =DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | DESC_HDR_SEL0_MDEUA |
Signature · 1 line
2.54.0
PATCH 4/5 crypto: talitos - fix SEC1 32k ahash request limitation
In reply to Goetz GoerischFrom: Paul Louvel <[email protected]>
commit 655ef638a2bc3cd0a9eff99a02f83cab94a3a917 upstream.
Since commit c662b043cdca ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES"), the crypto core may pass large scatterlists spanning multiple pages to drivers supporting ahash operations. As a result, a driver can now receive large ahash requests.
The SEC1 engine has a limitation where a single descriptor cannot process more than 32k of data. The current implementation attempts to handle the entire request within a single descriptor, which leads to failures raised by the driver:
"length exceeds h/w max limit"
Address this limitation by splitting large ahash requests into multiple descriptors, each respecting the 32k hardware limit. This allows processing arbitrarily large requests.
--- drivers/crypto/talitos.c | 216 ++++++++++++++++++++++++++------------- 1 file changed, 147 insertions(+), 69 deletions(-)
drivers/crypto/talitos.c +147 -69
@@ -12,6 +12,7 @@* All rights reserved. */ +#include <linux/workqueue.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mod_devicetable.h>
@@ -870,10 +871,18 @@ struct talitos_ahash_req_ctx {unsigned int swinit;unsigned int first;unsigned int last; +unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;struct scatterlist bufsl[2 ];struct scatterlist *psrc; + +struct scatterlist request_bufsl[2 ]; +struct ahash_request *areq; +struct scatterlist *request_sl; +unsigned int remaining_ahash_request_bytes; +unsigned int current_ahash_request_bytes; +struct work_struct sec1_ahash_process_remaining; };struct talitos_export_state {
@@ -1759,7 +1768,20 @@ static void ahash_done(struct device *dev,kfree (edesc); -ahash_request_complete (areq, err); +if (err) { +ahash_request_complete (areq, err); +return ; + } + + req_ctx->remaining_ahash_request_bytes -= + req_ctx->current_ahash_request_bytes; + +if (!req_ctx->remaining_ahash_request_bytes) { +ahash_request_complete (areq,0 ); +return ; + } + +schedule_work (&req_ctx->sec1_ahash_process_remaining); }/*
@@ -1925,60 +1947,7 @@ static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, nbytes, 0, 0, 0, areq->base.flags, false); } -static int ahash_init (struct ahash_request *areq) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -unsigned int size; -dma_addr_t dma; - -/* Initialize the context */ - req_ctx->buf_idx =0 ; - req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ - req_ctx->swinit =0 ;/* assume h/w init of context */ - size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) - ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 - :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; - req_ctx->hw_context_size = size; - - dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, -DMA_TO_DEVICE ); -dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); - -return 0 ; -} - -/* -* on h/w without explicit sha224 support, we initialize h/w context -* manually with sha224 constants, and tell it to run sha256. -*/ -static int ahash_init_sha224_swinit (struct ahash_request *areq) -{ -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - - req_ctx->hw_context[0 ] =SHA224_H0 ; - req_ctx->hw_context[1 ] =SHA224_H1 ; - req_ctx->hw_context[2 ] =SHA224_H2 ; - req_ctx->hw_context[3 ] =SHA224_H3 ; - req_ctx->hw_context[4 ] =SHA224_H4 ; - req_ctx->hw_context[5 ] =SHA224_H5 ; - req_ctx->hw_context[6 ] =SHA224_H6 ; - req_ctx->hw_context[7 ] =SHA224_H7 ; - -/* init 64-bit count */ - req_ctx->hw_context[8 ] =0 ; - req_ctx->hw_context[9 ] =0 ; - -ahash_init (areq); - req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ - -return 0 ; -} - -static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) +static int ahash_process_req_one (struct ahash_request *areq,unsigned int nbytes) {struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq);struct talitos_ctx *ctx =crypto_ahash_ctx (tfm);
@@ -1997,12 +1966,12 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ - nents =sg_nents_for_len (areq->src, nbytes); + nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (areq->src, nents, +sg_copy_to_buffer (req_ctx->request_sl, nents, ctx_buf + req_ctx->nbuf, nbytes); req_ctx->nbuf += nbytes;return 0 ;
@@ -2029,7 +1998,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)sg_init_table (req_ctx->bufsl, nsg);sg_set_buf (req_ctx->bufsl, ctx_buf, req_ctx->nbuf);if (nsg >1 ) -sg_chain (req_ctx->bufsl,2 , areq->src); +sg_chain (req_ctx->bufsl,2 , req_ctx->request_sl); req_ctx->psrc = req_ctx->bufsl; }else if (is_sec1 && req_ctx->nbuf && req_ctx->nbuf < blocksize) {int offset;
@@ -2038,26 +2007,26 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) offset = blocksize - req_ctx->nbuf; else offset = nbytes_to_hash - req_ctx->nbuf; - nents =sg_nents_for_len (areq->src, offset); + nents =sg_nents_for_len (req_ctx->request_sl, offset);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (areq->src, nents, +sg_copy_to_buffer (req_ctx->request_sl, nents, ctx_buf + req_ctx->nbuf, offset); req_ctx->nbuf += offset; - req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, areq->src, + req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, req_ctx->request_sl, offset); }else - req_ctx->psrc = areq->src; + req_ctx->psrc = req_ctx->request_sl;if (to_hash_later) { - nents =sg_nents_for_len (areq->src, nbytes); + nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_pcopy_to_buffer (areq->src, nents, +sg_pcopy_to_buffer (req_ctx->request_sl, nents, req_ctx->buf[(req_ctx->buf_idx +1 ) &1 ], to_hash_later, nbytes - to_hash_later);
@@ -2065,7 +2034,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) req_ctx->to_hash_later = to_hash_later;/* Allocate extended descriptor */ - edesc =ahash_edesc_alloc (areq, nbytes_to_hash); + edesc =ahash_edesc_alloc (req_ctx->areq, nbytes_to_hash);if (IS_ERR (edesc))return PTR_ERR (edesc);
@@ -2087,14 +2056,123 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ; -return common_nonsnoop_hash (edesc, areq, nbytes_to_hash, ahash_done); +return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done); } -static int ahash_update (struct ahash_request *areq) +static void sec1_ahash_process_remaining (struct work_struct *work) +{ +struct talitos_ahash_req_ctx *req_ctx = + container_of(work, struct talitos_ahash_req_ctx, + sec1_ahash_process_remaining); +int err =0 ; + + req_ctx->request_sl =scatterwalk_ffwd (req_ctx->request_bufsl, + req_ctx->request_sl,TALITOS1_MAX_DATA_LEN ); + +if (req_ctx->remaining_ahash_request_bytes >TALITOS1_MAX_DATA_LEN ) + req_ctx->current_ahash_request_bytes =TALITOS1_MAX_DATA_LEN ; +else { + req_ctx->current_ahash_request_bytes = + req_ctx->remaining_ahash_request_bytes; + +if (req_ctx->last_request) + req_ctx->last =1 ; + } + + err =ahash_process_req_one (req_ctx->areq, + req_ctx->current_ahash_request_bytes); + +if (err != -EINPROGRESS ) +ahash_request_complete (req_ctx->areq, err); +} + +static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) +{ +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev; +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +struct talitos_private *priv =dev_get_drvdata (dev); +bool is_sec1 =has_ftr_sec1 (priv); + + req_ctx->areq = areq; + req_ctx->request_sl = areq->src; + req_ctx->remaining_ahash_request_bytes = nbytes; + +if (is_sec1) { +if (nbytes >TALITOS1_MAX_DATA_LEN ) + nbytes =TALITOS1_MAX_DATA_LEN ; +else if (req_ctx->last_request) + req_ctx->last =1 ; + } + + req_ctx->current_ahash_request_bytes = nbytes; + +return ahash_process_req_one (req_ctx->areq, + req_ctx->current_ahash_request_bytes); +} + +static int ahash_init (struct ahash_request *areq) { +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev;struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +unsigned int size; +dma_addr_t dma; +/* Initialize the context */ + req_ctx->buf_idx =0 ; + req_ctx->nbuf =0 ; + req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->swinit =0 ;/* assume h/w init of context */ + size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) + ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 + :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; + req_ctx->hw_context_size = size; + req_ctx->last_request =0 ; req_ctx->last =0 ; +INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); + + dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, +DMA_TO_DEVICE ); +dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); + +return 0 ; +} + +/* +* on h/w without explicit sha224 support, we initialize h/w context +* manually with sha224 constants, and tell it to run sha256. +*/ +static int ahash_init_sha224_swinit (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->hw_context[0 ] =SHA224_H0 ; + req_ctx->hw_context[1 ] =SHA224_H1 ; + req_ctx->hw_context[2 ] =SHA224_H2 ; + req_ctx->hw_context[3 ] =SHA224_H3 ; + req_ctx->hw_context[4 ] =SHA224_H4 ; + req_ctx->hw_context[5 ] =SHA224_H5 ; + req_ctx->hw_context[6 ] =SHA224_H6 ; + req_ctx->hw_context[7 ] =SHA224_H7 ; + +/* init 64-bit count */ + req_ctx->hw_context[8 ] =0 ; + req_ctx->hw_context[9 ] =0 ; + +ahash_init (areq); + req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ + +return 0 ; +} + +static int ahash_update (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->last_request =0 ;return ahash_process_req (areq, areq->nbytes); }
@@ -2103,7 +2181,7 @@ static int ahash_final(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last =1 ; + req_ctx->last_request =1 ;return ahash_process_req (areq,0 ); }
@@ -2112,7 +2190,7 @@ static int ahash_finup(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last =1 ; + req_ctx->last_request =1 ;return ahash_process_req (areq, areq->nbytes); }
Signature · 1 line
2.54.0
PATCH 5/5 crypto: talitos - rename first/last to first_desc/last_desc
In reply to Goetz GoerischFrom: Paul Louvel <[email protected]>
commit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae upstream.
Previous commit introduces a new last_request variable in the context structure.
Renaming the first/last existing member variable in the context structure to improve readability.
--- drivers/crypto/talitos.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
drivers/crypto/talitos.c +23 -23
@@ -869,8 +869,8 @@ struct talitos_ahash_req_ctx {u8 buf[2 ][HASH_MAX_BLOCK_SIZE ];int buf_idx;unsigned int swinit; -unsigned int first; -unsigned int last; +unsigned int first_desc; +unsigned int last_desc;unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;
@@ -889,8 +889,8 @@ struct talitos_export_state {u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE /sizeof (u32)];u8 buf[HASH_MAX_BLOCK_SIZE ];unsigned int swinit; -unsigned int first; -unsigned int last; +unsigned int first_desc; +unsigned int last_desc;unsigned int to_hash_later;unsigned int nbuf; };
@@ -1722,7 +1722,7 @@ static void common_nonsnoop_hash_unmap(struct device *dev,if (desc->next_desc && desc->ptr[5 ].ptr != desc2->ptr[5 ].ptr)unmap_single_talitos_ptr (dev, &desc2->ptr[5 ],DMA_FROM_DEVICE ); -if (req_ctx->last) +if (req_ctx->last_desc)memcpy (areq->result, req_ctx->hw_context,crypto_ahash_digestsize (tfm));
@@ -1759,7 +1759,7 @@ static void ahash_done(struct device *dev, container_of(desc, struct talitos_edesc, desc);struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -if (!req_ctx->last && req_ctx->to_hash_later) { +if (!req_ctx->last_desc && req_ctx->to_hash_later) {/* Position any partial block for next update/final/finup */ req_ctx->buf_idx = (req_ctx->buf_idx +1 ) &1 ; req_ctx->nbuf = req_ctx->to_hash_later;
@@ -1825,7 +1825,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* first DWORD empty */ /* hash context in */ -if (!req_ctx->first || req_ctx->swinit) { +if (!req_ctx->first_desc || req_ctx->swinit) { map_single_talitos_ptr_nosync(dev, &desc->ptr[1], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1833,7 +1833,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, req_ctx->swinit =0 ; }/* Indicate next op is not the first. */ - req_ctx->first =0 ; + req_ctx->first_desc =0 ;/* HMAC key */ if (ctx->keylen)
@@ -1866,7 +1866,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* fifth DWORD empty */ /* hash/HMAC out -or- hash context out */ -if (req_ctx->last) +if (req_ctx->last_desc)map_single_talitos_ptr (dev, &desc->ptr[5 ],crypto_ahash_digestsize (tfm), req_ctx->hw_context,DMA_FROM_DEVICE );
@@ -1908,7 +1908,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,if (sg_count >1 ) sync_needed = true;copy_talitos_ptr (&desc2->ptr[5 ], &desc->ptr[5 ], is_sec1); -if (req_ctx->last) +if (req_ctx->last_desc) map_single_talitos_ptr_nosync(dev, &desc->ptr[5], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1964,7 +1964,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesbool is_sec1 =has_ftr_sec1 (priv);u8 *ctx_buf = req_ctx->buf[req_ctx->buf_idx]; -if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) { +if (!req_ctx->last_desc && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {
@@ -1981,7 +1981,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes nbytes_to_hash = nbytes + req_ctx->nbuf; to_hash_later = nbytes_to_hash & (blocksize -1 ); -if (req_ctx->last) +if (req_ctx->last_desc) to_hash_later =0 ;else if (to_hash_later)/* There is a partial block. Hash the full block(s) now */
@@ -2041,19 +2041,19 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes edesc->desc.hdr = ctx->desc_hdr_template;/* On last one, request SEC to pad; otherwise continue */ -if (req_ctx->last) +if (req_ctx->last_desc) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_PAD ;else edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_CONT ;/* request SEC to INIT hash. */ -if (req_ctx->first && !req_ctx->swinit) +if (req_ctx->first_desc && !req_ctx->swinit) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_INIT ;/* When the tfm context has a keylen, it's an HMAC. * A first or last (ie. not middle) descriptor must request HMAC. */ -if (ctx->keylen && (req_ctx->first || req_ctx->last)) +if (ctx->keylen && (req_ctx->first_desc || req_ctx->last_desc)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ;return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done);
@@ -2076,7 +2076,7 @@ static void sec1_ahash_process_remaining(struct work_struct *work) req_ctx->remaining_ahash_request_bytes;if (req_ctx->last_request) - req_ctx->last =1 ; + req_ctx->last_desc =1 ; } err = ahash_process_req_one(req_ctx->areq,
@@ -2103,7 +2103,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (nbytes >TALITOS1_MAX_DATA_LEN ) nbytes =TALITOS1_MAX_DATA_LEN ;else if (req_ctx->last_request) - req_ctx->last =1 ; + req_ctx->last_desc =1 ; } req_ctx->current_ahash_request_bytes = nbytes;
@@ -2124,14 +2124,14 @@ static int ahash_init(struct ahash_request *areq)/* Initialize the context */ req_ctx->buf_idx =0 ; req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->first_desc =1 ;/* first_desc indicates h/w must init its context */ req_ctx->swinit =0 ;/* assume h/w init of context */ size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; req_ctx->hw_context_size = size; req_ctx->last_request =0 ; - req_ctx->last =0 ; + req_ctx->last_desc =0 ;INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size,
@@ -2224,8 +2224,8 @@ static int ahash_export(struct ahash_request *areq, void *out) req_ctx->hw_context_size);memcpy (export->buf, req_ctx->buf[req_ctx->buf_idx], req_ctx->nbuf); export->swinit = req_ctx->swinit; - export->first = req_ctx->first; - export->last = req_ctx->last; + export->first_desc = req_ctx->first_desc; + export->last_desc = req_ctx->last_desc; export->to_hash_later = req_ctx->to_hash_later; export->nbuf = req_ctx->nbuf;
@@ -2250,8 +2250,8 @@ static int ahash_import(struct ahash_request *areq, const void *in)memcpy (req_ctx->hw_context, export->hw_context, size);memcpy (req_ctx->buf[0 ], export->buf, export->nbuf); req_ctx->swinit = export->swinit; - req_ctx->first = export->first; - req_ctx->last = export->last; + req_ctx->first_desc = export->first_desc; + req_ctx->last_desc = export->last_desc; req_ctx->to_hash_later = export->to_hash_later; req_ctx->nbuf = export->nbuf;
Signature · 1 line
2.54.0
v3 cover crypto: talitos - fix rename first/last to first_desc/last_desc
In reply to Greg KHCommit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y with a866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last to last_desc but misses one occurrence which leads to compile errors on mpc85xx
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'struct talitos_ahash_req_ctx' has no member named 'last'
2204 | req_ctx->last = 1;
| ^~~~Instead of renaming req_ctx->last, commit 9826d1d6ed5f8 ("crypto: talitos - stop using crypto_ahash::init") should be applied.
Ideally before commit 00463d5f864a ("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
Quoted 8 lines
Quoted 1 line
Greg could you please backport the mentioned commit to 6.6.y in the correct order for the next update?
Can you send a series of backported patches in the correct order for us to apply, so we know to get them correct? Trying to dig out from an email like this is usually quite easy to get wrong :)
Quoted 2 lines
We need a reason for a revert, AND a signed off-by line :( Please fix that up for the other revert in this series and resend.
Thank you Greg for this feedback.
v2: add reason and SoB to revert commit which was missing.
v3: send correct patch set
Hope this is correct.
Goetz
Eric Biggers (1):
crypto: talitos - stop using crypto_ahash::init
Goetz Goerisch (2):
Revert "crypto: talitos - rename first/last to first_desc/last_desc" Revert "crypto: talitos - fix SEC1 32k ahash request limitation"
Paul Louvel (2):
crypto: talitos - fix SEC1 32k ahash request limitation
crypto: talitos - rename first/last to first_desc/last_desc
drivers/crypto/talitos.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
base-commit: da47cbc254661aa66d61ef061485a7080305c4be
Signature · 1 line
2.55.0
PATCH 1/5 Revert "crypto: talitos - rename first/last to first_desc/last_desc"
This reverts commit a866e2b1c65edaee2e1bb1024ee2c761ced335f8.
Which was backported without applying upstream commit 9826d1d6ed5f86cb3d61610b3b1fe31e96a40418 first.
Commit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y with a866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last to last_desc but misses one occurrence which leads to compile errors on mpc85xx
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'struct talitos_ahash_req_ctx' has no member named 'last'
2204 | req_ctx->last = 1;
| ^~~~Instead of renaming req_ctx->last, commit 9826d1d6ed5f8 ("crypto: talitos - stop using crypto_ahash::init") should be applied.
Ideally before commit 00463d5f864a ("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
Reverting and applying in correct order.
--- drivers/crypto/talitos.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
drivers/crypto/talitos.c +23 -23
@@ -869,8 +869,8 @@ struct talitos_ahash_req_ctx {u8 buf[2 ][HASH_MAX_BLOCK_SIZE ];int buf_idx;unsigned int swinit; -unsigned int first_desc; -unsigned int last_desc; +unsigned int first; +unsigned int last;unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;
@@ -889,8 +889,8 @@ struct talitos_export_state {u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE /sizeof (u32)];u8 buf[HASH_MAX_BLOCK_SIZE ];unsigned int swinit; -unsigned int first_desc; -unsigned int last_desc; +unsigned int first; +unsigned int last;unsigned int to_hash_later;unsigned int nbuf; };
@@ -1722,7 +1722,7 @@ static void common_nonsnoop_hash_unmap(struct device *dev,if (desc->next_desc && desc->ptr[5 ].ptr != desc2->ptr[5 ].ptr)unmap_single_talitos_ptr (dev, &desc2->ptr[5 ],DMA_FROM_DEVICE ); -if (req_ctx->last_desc) +if (req_ctx->last)memcpy (areq->result, req_ctx->hw_context,crypto_ahash_digestsize (tfm));
@@ -1759,7 +1759,7 @@ static void ahash_done(struct device *dev, container_of(desc, struct talitos_edesc, desc);struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -if (!req_ctx->last_desc && req_ctx->to_hash_later) { +if (!req_ctx->last && req_ctx->to_hash_later) {/* Position any partial block for next update/final/finup */ req_ctx->buf_idx = (req_ctx->buf_idx +1 ) &1 ; req_ctx->nbuf = req_ctx->to_hash_later;
@@ -1825,7 +1825,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* first DWORD empty */ /* hash context in */ -if (!req_ctx->first_desc || req_ctx->swinit) { +if (!req_ctx->first || req_ctx->swinit) { map_single_talitos_ptr_nosync(dev, &desc->ptr[1], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1833,7 +1833,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, req_ctx->swinit =0 ; }/* Indicate next op is not the first. */ - req_ctx->first_desc =0 ; + req_ctx->first =0 ;/* HMAC key */ if (ctx->keylen)
@@ -1866,7 +1866,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* fifth DWORD empty */ /* hash/HMAC out -or- hash context out */ -if (req_ctx->last_desc) +if (req_ctx->last)map_single_talitos_ptr (dev, &desc->ptr[5 ],crypto_ahash_digestsize (tfm), req_ctx->hw_context,DMA_FROM_DEVICE );
@@ -1908,7 +1908,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,if (sg_count >1 ) sync_needed = true;copy_talitos_ptr (&desc2->ptr[5 ], &desc->ptr[5 ], is_sec1); -if (req_ctx->last_desc) +if (req_ctx->last) map_single_talitos_ptr_nosync(dev, &desc->ptr[5], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1964,7 +1964,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesbool is_sec1 =has_ftr_sec1 (priv);u8 *ctx_buf = req_ctx->buf[req_ctx->buf_idx]; -if (!req_ctx->last_desc && (nbytes + req_ctx->nbuf <= blocksize)) { +if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {
@@ -1981,7 +1981,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes nbytes_to_hash = nbytes + req_ctx->nbuf; to_hash_later = nbytes_to_hash & (blocksize -1 ); -if (req_ctx->last_desc) +if (req_ctx->last) to_hash_later =0 ;else if (to_hash_later)/* There is a partial block. Hash the full block(s) now */
@@ -2041,19 +2041,19 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes edesc->desc.hdr = ctx->desc_hdr_template;/* On last one, request SEC to pad; otherwise continue */ -if (req_ctx->last_desc) +if (req_ctx->last) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_PAD ;else edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_CONT ;/* request SEC to INIT hash. */ -if (req_ctx->first_desc && !req_ctx->swinit) +if (req_ctx->first && !req_ctx->swinit) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_INIT ;/* When the tfm context has a keylen, it's an HMAC. * A first or last (ie. not middle) descriptor must request HMAC. */ -if (ctx->keylen && (req_ctx->first_desc || req_ctx->last_desc)) +if (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ;return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done);
@@ -2076,7 +2076,7 @@ static void sec1_ahash_process_remaining(struct work_struct *work) req_ctx->remaining_ahash_request_bytes;if (req_ctx->last_request) - req_ctx->last_desc =1 ; + req_ctx->last =1 ; } err = ahash_process_req_one(req_ctx->areq,
@@ -2103,7 +2103,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (nbytes >TALITOS1_MAX_DATA_LEN ) nbytes =TALITOS1_MAX_DATA_LEN ;else if (req_ctx->last_request) - req_ctx->last_desc =1 ; + req_ctx->last =1 ; } req_ctx->current_ahash_request_bytes = nbytes;
@@ -2124,14 +2124,14 @@ static int ahash_init(struct ahash_request *areq)/* Initialize the context */ req_ctx->buf_idx =0 ; req_ctx->nbuf =0 ; - req_ctx->first_desc =1 ;/* first_desc indicates h/w must init its context */ + req_ctx->first =1 ;/* first indicates h/w must init its context */ req_ctx->swinit =0 ;/* assume h/w init of context */ size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; req_ctx->hw_context_size = size; req_ctx->last_request =0 ; - req_ctx->last_desc =0 ; + req_ctx->last =0 ;INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size,
@@ -2223,8 +2223,8 @@ static int ahash_export(struct ahash_request *areq, void *out) req_ctx->hw_context_size);memcpy (export->buf, req_ctx->buf[req_ctx->buf_idx], req_ctx->nbuf); export->swinit = req_ctx->swinit; - export->first_desc = req_ctx->first_desc; - export->last_desc = req_ctx->last_desc; + export->first = req_ctx->first; + export->last = req_ctx->last; export->to_hash_later = req_ctx->to_hash_later; export->nbuf = req_ctx->nbuf;
@@ -2249,8 +2249,8 @@ static int ahash_import(struct ahash_request *areq, const void *in)memcpy (req_ctx->hw_context, export->hw_context, size);memcpy (req_ctx->buf[0 ], export->buf, export->nbuf); req_ctx->swinit = export->swinit; - req_ctx->first_desc = export->first_desc; - req_ctx->last_desc = export->last_desc; + req_ctx->first = export->first; + req_ctx->last = export->last; req_ctx->to_hash_later = export->to_hash_later; req_ctx->nbuf = export->nbuf;
Signature · 1 line
2.55.0
PATCH 2/5 Revert "crypto: talitos - fix SEC1 32k ahash request limitation"
In reply to Goetz GoerischThis reverts commit 00463d5f864ae28b7938d5acd0ddd800d5457e8b. Which was backported without applying upstream commit 9826d1d6ed5f86cb3d61610b3b1fe31e96a40418 first.
Commit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y with a866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last to last_desc but misses one occurrence which leads to compile errors on mpc85xx
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'struct talitos_ahash_req_ctx' has no member named 'last'
2204 | req_ctx->last = 1;
| ^~~~Instead of renaming req_ctx->last, commit 9826d1d6ed5f8 ("crypto: talitos - stop using crypto_ahash::init") should be applied.
Ideally before commit 00463d5f864a ("crypto: talitos - fix SEC1 32k ahash request limitation") to avoid any compilation breakage and ensure correctness of the code.
Reverting and applying in correct order.
--- drivers/crypto/talitos.c | 216 +++++++++++++-------------------------- 1 file changed, 69 insertions(+), 147 deletions(-)
drivers/crypto/talitos.c +69 -147
@@ -12,7 +12,6 @@* All rights reserved. */ -#include <linux/workqueue.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mod_devicetable.h>
@@ -871,18 +870,10 @@ struct talitos_ahash_req_ctx {unsigned int swinit;unsigned int first;unsigned int last; -unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;struct scatterlist bufsl[2 ];struct scatterlist *psrc; - -struct scatterlist request_bufsl[2 ]; -struct ahash_request *areq; -struct scatterlist *request_sl; -unsigned int remaining_ahash_request_bytes; -unsigned int current_ahash_request_bytes; -struct work_struct sec1_ahash_process_remaining; };struct talitos_export_state {
@@ -1768,20 +1759,7 @@ static void ahash_done(struct device *dev,kfree (edesc); -if (err) { -ahash_request_complete (areq, err); -return ; - } - - req_ctx->remaining_ahash_request_bytes -= - req_ctx->current_ahash_request_bytes; - -if (!req_ctx->remaining_ahash_request_bytes) { -ahash_request_complete (areq,0 ); -return ; - } - -schedule_work (&req_ctx->sec1_ahash_process_remaining); +ahash_request_complete (areq, err); }/*
@@ -1947,7 +1925,60 @@ static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, nbytes, 0, 0, 0, areq->base.flags, false); } -static int ahash_process_req_one (struct ahash_request *areq,unsigned int nbytes) +static int ahash_init (struct ahash_request *areq) +{ +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev; +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +unsigned int size; +dma_addr_t dma; + +/* Initialize the context */ + req_ctx->buf_idx =0 ; + req_ctx->nbuf =0 ; + req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->swinit =0 ;/* assume h/w init of context */ + size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) + ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 + :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; + req_ctx->hw_context_size = size; + + dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, +DMA_TO_DEVICE ); +dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); + +return 0 ; +} + +/* +* on h/w without explicit sha224 support, we initialize h/w context +* manually with sha224 constants, and tell it to run sha256. +*/ +static int ahash_init_sha224_swinit (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->hw_context[0 ] =SHA224_H0 ; + req_ctx->hw_context[1 ] =SHA224_H1 ; + req_ctx->hw_context[2 ] =SHA224_H2 ; + req_ctx->hw_context[3 ] =SHA224_H3 ; + req_ctx->hw_context[4 ] =SHA224_H4 ; + req_ctx->hw_context[5 ] =SHA224_H5 ; + req_ctx->hw_context[6 ] =SHA224_H6 ; + req_ctx->hw_context[7 ] =SHA224_H7 ; + +/* init 64-bit count */ + req_ctx->hw_context[8 ] =0 ; + req_ctx->hw_context[9 ] =0 ; + +ahash_init (areq); + req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ + +return 0 ; +} + +static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) {struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq);struct talitos_ctx *ctx =crypto_ahash_ctx (tfm);
@@ -1966,12 +1997,12 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesif (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ - nents =sg_nents_for_len (req_ctx->request_sl, nbytes); + nents =sg_nents_for_len (areq->src, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (req_ctx->request_sl, nents, +sg_copy_to_buffer (areq->src, nents, ctx_buf + req_ctx->nbuf, nbytes); req_ctx->nbuf += nbytes;return 0 ;
@@ -1998,7 +2029,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytessg_init_table (req_ctx->bufsl, nsg);sg_set_buf (req_ctx->bufsl, ctx_buf, req_ctx->nbuf);if (nsg >1 ) -sg_chain (req_ctx->bufsl,2 , req_ctx->request_sl); +sg_chain (req_ctx->bufsl,2 , areq->src); req_ctx->psrc = req_ctx->bufsl; }else if (is_sec1 && req_ctx->nbuf && req_ctx->nbuf < blocksize) {int offset;
@@ -2007,26 +2038,26 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes offset = blocksize - req_ctx->nbuf; else offset = nbytes_to_hash - req_ctx->nbuf; - nents =sg_nents_for_len (req_ctx->request_sl, offset); + nents =sg_nents_for_len (areq->src, offset);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (req_ctx->request_sl, nents, +sg_copy_to_buffer (areq->src, nents, ctx_buf + req_ctx->nbuf, offset); req_ctx->nbuf += offset; - req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, req_ctx->request_sl, + req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, areq->src, offset); }else - req_ctx->psrc = req_ctx->request_sl; + req_ctx->psrc = areq->src;if (to_hash_later) { - nents =sg_nents_for_len (req_ctx->request_sl, nbytes); + nents =sg_nents_for_len (areq->src, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_pcopy_to_buffer (req_ctx->request_sl, nents, +sg_pcopy_to_buffer (areq->src, nents, req_ctx->buf[(req_ctx->buf_idx +1 ) &1 ], to_hash_later, nbytes - to_hash_later);
@@ -2034,7 +2065,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes req_ctx->to_hash_later = to_hash_later;/* Allocate extended descriptor */ - edesc =ahash_edesc_alloc (req_ctx->areq, nbytes_to_hash); + edesc =ahash_edesc_alloc (areq, nbytes_to_hash);if (IS_ERR (edesc))return PTR_ERR (edesc);
@@ -2056,123 +2087,14 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesif (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ; -return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done); -} - -static void sec1_ahash_process_remaining (struct work_struct *work) -{ -struct talitos_ahash_req_ctx *req_ctx = - container_of(work, struct talitos_ahash_req_ctx, - sec1_ahash_process_remaining); -int err =0 ; - - req_ctx->request_sl =scatterwalk_ffwd (req_ctx->request_bufsl, - req_ctx->request_sl,TALITOS1_MAX_DATA_LEN ); - -if (req_ctx->remaining_ahash_request_bytes >TALITOS1_MAX_DATA_LEN ) - req_ctx->current_ahash_request_bytes =TALITOS1_MAX_DATA_LEN ; -else { - req_ctx->current_ahash_request_bytes = - req_ctx->remaining_ahash_request_bytes; - -if (req_ctx->last_request) - req_ctx->last =1 ; - } - - err =ahash_process_req_one (req_ctx->areq, - req_ctx->current_ahash_request_bytes); - -if (err != -EINPROGRESS ) -ahash_request_complete (req_ctx->areq, err); -} - -static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -struct talitos_private *priv =dev_get_drvdata (dev); -bool is_sec1 =has_ftr_sec1 (priv); - - req_ctx->areq = areq; - req_ctx->request_sl = areq->src; - req_ctx->remaining_ahash_request_bytes = nbytes; - -if (is_sec1) { -if (nbytes >TALITOS1_MAX_DATA_LEN ) - nbytes =TALITOS1_MAX_DATA_LEN ; -else if (req_ctx->last_request) - req_ctx->last =1 ; - } - - req_ctx->current_ahash_request_bytes = nbytes; - -return ahash_process_req_one (req_ctx->areq, - req_ctx->current_ahash_request_bytes); -} - -static int ahash_init (struct ahash_request *areq) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -unsigned int size; -dma_addr_t dma; - -/* Initialize the context */ - req_ctx->buf_idx =0 ; - req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ - req_ctx->swinit =0 ;/* assume h/w init of context */ - size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) - ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 - :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; - req_ctx->hw_context_size = size; - req_ctx->last_request =0 ; - req_ctx->last =0 ; -INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); - - dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, -DMA_TO_DEVICE ); -dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); - -return 0 ; -} - -/* -* on h/w without explicit sha224 support, we initialize h/w context -* manually with sha224 constants, and tell it to run sha256. -*/ -static int ahash_init_sha224_swinit (struct ahash_request *areq) -{ -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - - req_ctx->hw_context[0 ] =SHA224_H0 ; - req_ctx->hw_context[1 ] =SHA224_H1 ; - req_ctx->hw_context[2 ] =SHA224_H2 ; - req_ctx->hw_context[3 ] =SHA224_H3 ; - req_ctx->hw_context[4 ] =SHA224_H4 ; - req_ctx->hw_context[5 ] =SHA224_H5 ; - req_ctx->hw_context[6 ] =SHA224_H6 ; - req_ctx->hw_context[7 ] =SHA224_H7 ; - -/* init 64-bit count */ - req_ctx->hw_context[8 ] =0 ; - req_ctx->hw_context[9 ] =0 ; - -ahash_init (areq); - req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ - -return 0 ; +return common_nonsnoop_hash (edesc, areq, nbytes_to_hash, ahash_done); }static int ahash_update (struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =0 ; + req_ctx->last =0 ;return ahash_process_req (areq, areq->nbytes); }
@@ -2181,7 +2103,7 @@ static int ahash_final(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =1 ; + req_ctx->last =1 ;return ahash_process_req (areq,0 ); }
@@ -2190,7 +2112,7 @@ static int ahash_finup(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =1 ; + req_ctx->last =1 ;return ahash_process_req (areq, areq->nbytes); }
Signature · 1 line
2.55.0
PATCH 3/5 crypto: talitos - stop using crypto_ahash::init
In reply to Goetz GoerischFrom: Eric Biggers <[email protected]>
commit 9826d1d6ed5f86cb3d61610b3b1fe31e96a40418 upstream.
The function pointer crypto_ahash::init is an internal implementation detail of the ahash API that exists to help it support both ahash and shash algorithms. With an upcoming refactoring of how the ahash API supports shash algorithms, this field will be removed.
Some drivers are invoking crypto_ahash::init to call into their own code, which is unnecessary and inefficient. The talitos driver is one of those drivers. Make it just call its own code directly.
--- drivers/crypto/talitos.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/crypto/talitos.c +9 -6
@@ -2119,13 +2119,14 @@ static int ahash_finup(struct ahash_request *areq)static int ahash_digest (struct ahash_request *areq) { -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -struct crypto_ahash *ahash =crypto_ahash_reqtfm (areq); - - ahash->init (areq); - req_ctx->last =1 ; +ahash_init (areq); +return ahash_finup (areq); +} -return ahash_process_req (areq, areq->nbytes); +static int ahash_digest_sha224_swinit (struct ahash_request *areq) +{ +ahash_init_sha224_swinit (areq); +return ahash_finup (areq); }static int ahash_export (struct ahash_request *areq,void *out)
@@ -3242,6 +3243,8 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, (!strcmp(alg->cra_name, "sha224") || !strcmp(alg->cra_name, "hmac(sha224)"))) { t_alg->algt.alg.hash.init = ahash_init_sha224_swinit; + t_alg->algt.alg.hash.digest = + ahash_digest_sha224_swinit; t_alg->algt.desc_hdr_template =DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | DESC_HDR_SEL0_MDEUA |
Signature · 1 line
2.55.0
PATCH 4/5 crypto: talitos - fix SEC1 32k ahash request limitation
In reply to Goetz GoerischFrom: Paul Louvel <[email protected]>
commit 655ef638a2bc3cd0a9eff99a02f83cab94a3a917 upstream.
Since commit c662b043cdca ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES"), the crypto core may pass large scatterlists spanning multiple pages to drivers supporting ahash operations. As a result, a driver can now receive large ahash requests.
The SEC1 engine has a limitation where a single descriptor cannot process more than 32k of data. The current implementation attempts to handle the entire request within a single descriptor, which leads to failures raised by the driver:
"length exceeds h/w max limit"
Address this limitation by splitting large ahash requests into multiple descriptors, each respecting the 32k hardware limit. This allows processing arbitrarily large requests.
--- drivers/crypto/talitos.c | 216 ++++++++++++++++++++++++++------------- 1 file changed, 147 insertions(+), 69 deletions(-)
drivers/crypto/talitos.c +147 -69
@@ -12,6 +12,7 @@* All rights reserved. */ +#include <linux/workqueue.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mod_devicetable.h>
@@ -870,10 +871,18 @@ struct talitos_ahash_req_ctx {unsigned int swinit;unsigned int first;unsigned int last; +unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;struct scatterlist bufsl[2 ];struct scatterlist *psrc; + +struct scatterlist request_bufsl[2 ]; +struct ahash_request *areq; +struct scatterlist *request_sl; +unsigned int remaining_ahash_request_bytes; +unsigned int current_ahash_request_bytes; +struct work_struct sec1_ahash_process_remaining; };struct talitos_export_state {
@@ -1759,7 +1768,20 @@ static void ahash_done(struct device *dev,kfree (edesc); -ahash_request_complete (areq, err); +if (err) { +ahash_request_complete (areq, err); +return ; + } + + req_ctx->remaining_ahash_request_bytes -= + req_ctx->current_ahash_request_bytes; + +if (!req_ctx->remaining_ahash_request_bytes) { +ahash_request_complete (areq,0 ); +return ; + } + +schedule_work (&req_ctx->sec1_ahash_process_remaining); }/*
@@ -1925,60 +1947,7 @@ static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, nbytes, 0, 0, 0, areq->base.flags, false); } -static int ahash_init (struct ahash_request *areq) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -unsigned int size; -dma_addr_t dma; - -/* Initialize the context */ - req_ctx->buf_idx =0 ; - req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ - req_ctx->swinit =0 ;/* assume h/w init of context */ - size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) - ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 - :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; - req_ctx->hw_context_size = size; - - dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, -DMA_TO_DEVICE ); -dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); - -return 0 ; -} - -/* -* on h/w without explicit sha224 support, we initialize h/w context -* manually with sha224 constants, and tell it to run sha256. -*/ -static int ahash_init_sha224_swinit (struct ahash_request *areq) -{ -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - - req_ctx->hw_context[0 ] =SHA224_H0 ; - req_ctx->hw_context[1 ] =SHA224_H1 ; - req_ctx->hw_context[2 ] =SHA224_H2 ; - req_ctx->hw_context[3 ] =SHA224_H3 ; - req_ctx->hw_context[4 ] =SHA224_H4 ; - req_ctx->hw_context[5 ] =SHA224_H5 ; - req_ctx->hw_context[6 ] =SHA224_H6 ; - req_ctx->hw_context[7 ] =SHA224_H7 ; - -/* init 64-bit count */ - req_ctx->hw_context[8 ] =0 ; - req_ctx->hw_context[9 ] =0 ; - -ahash_init (areq); - req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ - -return 0 ; -} - -static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) +static int ahash_process_req_one (struct ahash_request *areq,unsigned int nbytes) {struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq);struct talitos_ctx *ctx =crypto_ahash_ctx (tfm);
@@ -1997,12 +1966,12 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ - nents =sg_nents_for_len (areq->src, nbytes); + nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (areq->src, nents, +sg_copy_to_buffer (req_ctx->request_sl, nents, ctx_buf + req_ctx->nbuf, nbytes); req_ctx->nbuf += nbytes;return 0 ;
@@ -2029,7 +1998,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)sg_init_table (req_ctx->bufsl, nsg);sg_set_buf (req_ctx->bufsl, ctx_buf, req_ctx->nbuf);if (nsg >1 ) -sg_chain (req_ctx->bufsl,2 , areq->src); +sg_chain (req_ctx->bufsl,2 , req_ctx->request_sl); req_ctx->psrc = req_ctx->bufsl; }else if (is_sec1 && req_ctx->nbuf && req_ctx->nbuf < blocksize) {int offset;
@@ -2038,26 +2007,26 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) offset = blocksize - req_ctx->nbuf; else offset = nbytes_to_hash - req_ctx->nbuf; - nents =sg_nents_for_len (areq->src, offset); + nents =sg_nents_for_len (req_ctx->request_sl, offset);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (areq->src, nents, +sg_copy_to_buffer (req_ctx->request_sl, nents, ctx_buf + req_ctx->nbuf, offset); req_ctx->nbuf += offset; - req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, areq->src, + req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, req_ctx->request_sl, offset); }else - req_ctx->psrc = areq->src; + req_ctx->psrc = req_ctx->request_sl;if (to_hash_later) { - nents =sg_nents_for_len (areq->src, nbytes); + nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_pcopy_to_buffer (areq->src, nents, +sg_pcopy_to_buffer (req_ctx->request_sl, nents, req_ctx->buf[(req_ctx->buf_idx +1 ) &1 ], to_hash_later, nbytes - to_hash_later);
@@ -2065,7 +2034,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) req_ctx->to_hash_later = to_hash_later;/* Allocate extended descriptor */ - edesc =ahash_edesc_alloc (areq, nbytes_to_hash); + edesc =ahash_edesc_alloc (req_ctx->areq, nbytes_to_hash);if (IS_ERR (edesc))return PTR_ERR (edesc);
@@ -2087,14 +2056,123 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ; -return common_nonsnoop_hash (edesc, areq, nbytes_to_hash, ahash_done); +return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done); } -static int ahash_update (struct ahash_request *areq) +static void sec1_ahash_process_remaining (struct work_struct *work) +{ +struct talitos_ahash_req_ctx *req_ctx = + container_of(work, struct talitos_ahash_req_ctx, + sec1_ahash_process_remaining); +int err =0 ; + + req_ctx->request_sl =scatterwalk_ffwd (req_ctx->request_bufsl, + req_ctx->request_sl,TALITOS1_MAX_DATA_LEN ); + +if (req_ctx->remaining_ahash_request_bytes >TALITOS1_MAX_DATA_LEN ) + req_ctx->current_ahash_request_bytes =TALITOS1_MAX_DATA_LEN ; +else { + req_ctx->current_ahash_request_bytes = + req_ctx->remaining_ahash_request_bytes; + +if (req_ctx->last_request) + req_ctx->last =1 ; + } + + err =ahash_process_req_one (req_ctx->areq, + req_ctx->current_ahash_request_bytes); + +if (err != -EINPROGRESS ) +ahash_request_complete (req_ctx->areq, err); +} + +static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) +{ +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev; +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +struct talitos_private *priv =dev_get_drvdata (dev); +bool is_sec1 =has_ftr_sec1 (priv); + + req_ctx->areq = areq; + req_ctx->request_sl = areq->src; + req_ctx->remaining_ahash_request_bytes = nbytes; + +if (is_sec1) { +if (nbytes >TALITOS1_MAX_DATA_LEN ) + nbytes =TALITOS1_MAX_DATA_LEN ; +else if (req_ctx->last_request) + req_ctx->last =1 ; + } + + req_ctx->current_ahash_request_bytes = nbytes; + +return ahash_process_req_one (req_ctx->areq, + req_ctx->current_ahash_request_bytes); +} + +static int ahash_init (struct ahash_request *areq) { +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev;struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +unsigned int size; +dma_addr_t dma; +/* Initialize the context */ + req_ctx->buf_idx =0 ; + req_ctx->nbuf =0 ; + req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->swinit =0 ;/* assume h/w init of context */ + size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) + ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 + :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; + req_ctx->hw_context_size = size; + req_ctx->last_request =0 ; req_ctx->last =0 ; +INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); + + dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, +DMA_TO_DEVICE ); +dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); + +return 0 ; +} + +/* +* on h/w without explicit sha224 support, we initialize h/w context +* manually with sha224 constants, and tell it to run sha256. +*/ +static int ahash_init_sha224_swinit (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->hw_context[0 ] =SHA224_H0 ; + req_ctx->hw_context[1 ] =SHA224_H1 ; + req_ctx->hw_context[2 ] =SHA224_H2 ; + req_ctx->hw_context[3 ] =SHA224_H3 ; + req_ctx->hw_context[4 ] =SHA224_H4 ; + req_ctx->hw_context[5 ] =SHA224_H5 ; + req_ctx->hw_context[6 ] =SHA224_H6 ; + req_ctx->hw_context[7 ] =SHA224_H7 ; + +/* init 64-bit count */ + req_ctx->hw_context[8 ] =0 ; + req_ctx->hw_context[9 ] =0 ; + +ahash_init (areq); + req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ + +return 0 ; +} + +static int ahash_update (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->last_request =0 ;return ahash_process_req (areq, areq->nbytes); }
@@ -2103,7 +2181,7 @@ static int ahash_final(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last =1 ; + req_ctx->last_request =1 ;return ahash_process_req (areq,0 ); }
@@ -2112,7 +2190,7 @@ static int ahash_finup(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last =1 ; + req_ctx->last_request =1 ;return ahash_process_req (areq, areq->nbytes); }
Signature · 1 line
2.55.0
PATCH 5/5 crypto: talitos - rename first/last to first_desc/last_desc
In reply to Goetz GoerischFrom: Paul Louvel <[email protected]>
commit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae upstream.
Previous commit introduces a new last_request variable in the context structure.
Renaming the first/last existing member variable in the context structure to improve readability.
--- drivers/crypto/talitos.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
drivers/crypto/talitos.c +23 -23
@@ -869,8 +869,8 @@ struct talitos_ahash_req_ctx {u8 buf[2 ][HASH_MAX_BLOCK_SIZE ];int buf_idx;unsigned int swinit; -unsigned int first; -unsigned int last; +unsigned int first_desc; +unsigned int last_desc;unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;
@@ -889,8 +889,8 @@ struct talitos_export_state {u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE /sizeof (u32)];u8 buf[HASH_MAX_BLOCK_SIZE ];unsigned int swinit; -unsigned int first; -unsigned int last; +unsigned int first_desc; +unsigned int last_desc;unsigned int to_hash_later;unsigned int nbuf; };
@@ -1722,7 +1722,7 @@ static void common_nonsnoop_hash_unmap(struct device *dev,if (desc->next_desc && desc->ptr[5 ].ptr != desc2->ptr[5 ].ptr)unmap_single_talitos_ptr (dev, &desc2->ptr[5 ],DMA_FROM_DEVICE ); -if (req_ctx->last) +if (req_ctx->last_desc)memcpy (areq->result, req_ctx->hw_context,crypto_ahash_digestsize (tfm));
@@ -1759,7 +1759,7 @@ static void ahash_done(struct device *dev, container_of(desc, struct talitos_edesc, desc);struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -if (!req_ctx->last && req_ctx->to_hash_later) { +if (!req_ctx->last_desc && req_ctx->to_hash_later) {/* Position any partial block for next update/final/finup */ req_ctx->buf_idx = (req_ctx->buf_idx +1 ) &1 ; req_ctx->nbuf = req_ctx->to_hash_later;
@@ -1825,7 +1825,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* first DWORD empty */ /* hash context in */ -if (!req_ctx->first || req_ctx->swinit) { +if (!req_ctx->first_desc || req_ctx->swinit) { map_single_talitos_ptr_nosync(dev, &desc->ptr[1], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1833,7 +1833,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, req_ctx->swinit =0 ; }/* Indicate next op is not the first. */ - req_ctx->first =0 ; + req_ctx->first_desc =0 ;/* HMAC key */ if (ctx->keylen)
@@ -1866,7 +1866,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* fifth DWORD empty */ /* hash/HMAC out -or- hash context out */ -if (req_ctx->last) +if (req_ctx->last_desc)map_single_talitos_ptr (dev, &desc->ptr[5 ],crypto_ahash_digestsize (tfm), req_ctx->hw_context,DMA_FROM_DEVICE );
@@ -1908,7 +1908,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,if (sg_count >1 ) sync_needed = true;copy_talitos_ptr (&desc2->ptr[5 ], &desc->ptr[5 ], is_sec1); -if (req_ctx->last) +if (req_ctx->last_desc) map_single_talitos_ptr_nosync(dev, &desc->ptr[5], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1964,7 +1964,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesbool is_sec1 =has_ftr_sec1 (priv);u8 *ctx_buf = req_ctx->buf[req_ctx->buf_idx]; -if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) { +if (!req_ctx->last_desc && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {
@@ -1981,7 +1981,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes nbytes_to_hash = nbytes + req_ctx->nbuf; to_hash_later = nbytes_to_hash & (blocksize -1 ); -if (req_ctx->last) +if (req_ctx->last_desc) to_hash_later =0 ;else if (to_hash_later)/* There is a partial block. Hash the full block(s) now */
@@ -2041,19 +2041,19 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes edesc->desc.hdr = ctx->desc_hdr_template;/* On last one, request SEC to pad; otherwise continue */ -if (req_ctx->last) +if (req_ctx->last_desc) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_PAD ;else edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_CONT ;/* request SEC to INIT hash. */ -if (req_ctx->first && !req_ctx->swinit) +if (req_ctx->first_desc && !req_ctx->swinit) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_INIT ;/* When the tfm context has a keylen, it's an HMAC. * A first or last (ie. not middle) descriptor must request HMAC. */ -if (ctx->keylen && (req_ctx->first || req_ctx->last)) +if (ctx->keylen && (req_ctx->first_desc || req_ctx->last_desc)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ;return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done);
@@ -2076,7 +2076,7 @@ static void sec1_ahash_process_remaining(struct work_struct *work) req_ctx->remaining_ahash_request_bytes;if (req_ctx->last_request) - req_ctx->last =1 ; + req_ctx->last_desc =1 ; } err = ahash_process_req_one(req_ctx->areq,
@@ -2103,7 +2103,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (nbytes >TALITOS1_MAX_DATA_LEN ) nbytes =TALITOS1_MAX_DATA_LEN ;else if (req_ctx->last_request) - req_ctx->last =1 ; + req_ctx->last_desc =1 ; } req_ctx->current_ahash_request_bytes = nbytes;
@@ -2124,14 +2124,14 @@ static int ahash_init(struct ahash_request *areq)/* Initialize the context */ req_ctx->buf_idx =0 ; req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->first_desc =1 ;/* first_desc indicates h/w must init its context */ req_ctx->swinit =0 ;/* assume h/w init of context */ size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; req_ctx->hw_context_size = size; req_ctx->last_request =0 ; - req_ctx->last =0 ; + req_ctx->last_desc =0 ;INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size,
@@ -2224,8 +2224,8 @@ static int ahash_export(struct ahash_request *areq, void *out) req_ctx->hw_context_size);memcpy (export->buf, req_ctx->buf[req_ctx->buf_idx], req_ctx->nbuf); export->swinit = req_ctx->swinit; - export->first = req_ctx->first; - export->last = req_ctx->last; + export->first_desc = req_ctx->first_desc; + export->last_desc = req_ctx->last_desc; export->to_hash_later = req_ctx->to_hash_later; export->nbuf = req_ctx->nbuf;
@@ -2250,8 +2250,8 @@ static int ahash_import(struct ahash_request *areq, const void *in)memcpy (req_ctx->hw_context, export->hw_context, size);memcpy (req_ctx->buf[0 ], export->buf, export->nbuf); req_ctx->swinit = export->swinit; - req_ctx->first = export->first; - req_ctx->last = export->last; + req_ctx->first_desc = export->first_desc; + req_ctx->last_desc = export->last_desc; req_ctx->to_hash_later = export->to_hash_later; req_ctx->nbuf = export->nbuf;
Signature · 1 line
2.55.0
Quoted 8 lines · Goetz Goerisch
Commit
a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae
was backported to 6.6.y witha866e2b1c65edaee2e1bb1024ee2c761ced335f8
It renames last tolast_descbut misses one occurrence which leads to compile errors on mpc85xx
drivers/crypto/talitos.c: In function 'ahash_digest':drivers/crypto/talitos.c:2204:16: error: 'structtalitos_ahash_req_ctx' has no member named 'last'2204 | req_ctx->last = 1; | ^~~~
Queued the series for 6.6, thanks.
Signature · 2 lines
Thanks, Sasha
PATCH 2/5 Revert "crypto: talitos - fix SEC1 32k ahash request limitation"
In reply to Goetz GoerischThis reverts commit 00463d5f864ae28b7938d5acd0ddd800d5457e8b.
--- drivers/crypto/talitos.c | 216 +++++++++++++-------------------------- 1 file changed, 69 insertions(+), 147 deletions(-)
drivers/crypto/talitos.c +69 -147
@@ -12,7 +12,6 @@* All rights reserved. */ -#include <linux/workqueue.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mod_devicetable.h>
@@ -871,18 +870,10 @@ struct talitos_ahash_req_ctx {unsigned int swinit;unsigned int first;unsigned int last; -unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;struct scatterlist bufsl[2 ];struct scatterlist *psrc; - -struct scatterlist request_bufsl[2 ]; -struct ahash_request *areq; -struct scatterlist *request_sl; -unsigned int remaining_ahash_request_bytes; -unsigned int current_ahash_request_bytes; -struct work_struct sec1_ahash_process_remaining; };struct talitos_export_state {
@@ -1768,20 +1759,7 @@ static void ahash_done(struct device *dev,kfree (edesc); -if (err) { -ahash_request_complete (areq, err); -return ; - } - - req_ctx->remaining_ahash_request_bytes -= - req_ctx->current_ahash_request_bytes; - -if (!req_ctx->remaining_ahash_request_bytes) { -ahash_request_complete (areq,0 ); -return ; - } - -schedule_work (&req_ctx->sec1_ahash_process_remaining); +ahash_request_complete (areq, err); }/*
@@ -1947,7 +1925,60 @@ static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, nbytes, 0, 0, 0, areq->base.flags, false); } -static int ahash_process_req_one (struct ahash_request *areq,unsigned int nbytes) +static int ahash_init (struct ahash_request *areq) +{ +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev; +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +unsigned int size; +dma_addr_t dma; + +/* Initialize the context */ + req_ctx->buf_idx =0 ; + req_ctx->nbuf =0 ; + req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->swinit =0 ;/* assume h/w init of context */ + size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) + ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 + :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; + req_ctx->hw_context_size = size; + + dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, +DMA_TO_DEVICE ); +dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); + +return 0 ; +} + +/* +* on h/w without explicit sha224 support, we initialize h/w context +* manually with sha224 constants, and tell it to run sha256. +*/ +static int ahash_init_sha224_swinit (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->hw_context[0 ] =SHA224_H0 ; + req_ctx->hw_context[1 ] =SHA224_H1 ; + req_ctx->hw_context[2 ] =SHA224_H2 ; + req_ctx->hw_context[3 ] =SHA224_H3 ; + req_ctx->hw_context[4 ] =SHA224_H4 ; + req_ctx->hw_context[5 ] =SHA224_H5 ; + req_ctx->hw_context[6 ] =SHA224_H6 ; + req_ctx->hw_context[7 ] =SHA224_H7 ; + +/* init 64-bit count */ + req_ctx->hw_context[8 ] =0 ; + req_ctx->hw_context[9 ] =0 ; + +ahash_init (areq); + req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ + +return 0 ; +} + +static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) {struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq);struct talitos_ctx *ctx =crypto_ahash_ctx (tfm);
@@ -1966,12 +1997,12 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesif (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ - nents =sg_nents_for_len (req_ctx->request_sl, nbytes); + nents =sg_nents_for_len (areq->src, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (req_ctx->request_sl, nents, +sg_copy_to_buffer (areq->src, nents, ctx_buf + req_ctx->nbuf, nbytes); req_ctx->nbuf += nbytes;return 0 ;
@@ -1998,7 +2029,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytessg_init_table (req_ctx->bufsl, nsg);sg_set_buf (req_ctx->bufsl, ctx_buf, req_ctx->nbuf);if (nsg >1 ) -sg_chain (req_ctx->bufsl,2 , req_ctx->request_sl); +sg_chain (req_ctx->bufsl,2 , areq->src); req_ctx->psrc = req_ctx->bufsl; }else if (is_sec1 && req_ctx->nbuf && req_ctx->nbuf < blocksize) {int offset;
@@ -2007,26 +2038,26 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes offset = blocksize - req_ctx->nbuf; else offset = nbytes_to_hash - req_ctx->nbuf; - nents =sg_nents_for_len (req_ctx->request_sl, offset); + nents =sg_nents_for_len (areq->src, offset);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (req_ctx->request_sl, nents, +sg_copy_to_buffer (areq->src, nents, ctx_buf + req_ctx->nbuf, offset); req_ctx->nbuf += offset; - req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, req_ctx->request_sl, + req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, areq->src, offset); }else - req_ctx->psrc = req_ctx->request_sl; + req_ctx->psrc = areq->src;if (to_hash_later) { - nents =sg_nents_for_len (req_ctx->request_sl, nbytes); + nents =sg_nents_for_len (areq->src, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_pcopy_to_buffer (req_ctx->request_sl, nents, +sg_pcopy_to_buffer (areq->src, nents, req_ctx->buf[(req_ctx->buf_idx +1 ) &1 ], to_hash_later, nbytes - to_hash_later);
@@ -2034,7 +2065,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes req_ctx->to_hash_later = to_hash_later;/* Allocate extended descriptor */ - edesc =ahash_edesc_alloc (req_ctx->areq, nbytes_to_hash); + edesc =ahash_edesc_alloc (areq, nbytes_to_hash);if (IS_ERR (edesc))return PTR_ERR (edesc);
@@ -2056,123 +2087,14 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesif (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ; -return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done); -} - -static void sec1_ahash_process_remaining (struct work_struct *work) -{ -struct talitos_ahash_req_ctx *req_ctx = - container_of(work, struct talitos_ahash_req_ctx, - sec1_ahash_process_remaining); -int err =0 ; - - req_ctx->request_sl =scatterwalk_ffwd (req_ctx->request_bufsl, - req_ctx->request_sl,TALITOS1_MAX_DATA_LEN ); - -if (req_ctx->remaining_ahash_request_bytes >TALITOS1_MAX_DATA_LEN ) - req_ctx->current_ahash_request_bytes =TALITOS1_MAX_DATA_LEN ; -else { - req_ctx->current_ahash_request_bytes = - req_ctx->remaining_ahash_request_bytes; - -if (req_ctx->last_request) - req_ctx->last =1 ; - } - - err =ahash_process_req_one (req_ctx->areq, - req_ctx->current_ahash_request_bytes); - -if (err != -EINPROGRESS ) -ahash_request_complete (req_ctx->areq, err); -} - -static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -struct talitos_private *priv =dev_get_drvdata (dev); -bool is_sec1 =has_ftr_sec1 (priv); - - req_ctx->areq = areq; - req_ctx->request_sl = areq->src; - req_ctx->remaining_ahash_request_bytes = nbytes; - -if (is_sec1) { -if (nbytes >TALITOS1_MAX_DATA_LEN ) - nbytes =TALITOS1_MAX_DATA_LEN ; -else if (req_ctx->last_request) - req_ctx->last =1 ; - } - - req_ctx->current_ahash_request_bytes = nbytes; - -return ahash_process_req_one (req_ctx->areq, - req_ctx->current_ahash_request_bytes); -} - -static int ahash_init (struct ahash_request *areq) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -unsigned int size; -dma_addr_t dma; - -/* Initialize the context */ - req_ctx->buf_idx =0 ; - req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ - req_ctx->swinit =0 ;/* assume h/w init of context */ - size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) - ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 - :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; - req_ctx->hw_context_size = size; - req_ctx->last_request =0 ; - req_ctx->last =0 ; -INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); - - dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, -DMA_TO_DEVICE ); -dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); - -return 0 ; -} - -/* -* on h/w without explicit sha224 support, we initialize h/w context -* manually with sha224 constants, and tell it to run sha256. -*/ -static int ahash_init_sha224_swinit (struct ahash_request *areq) -{ -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - - req_ctx->hw_context[0 ] =SHA224_H0 ; - req_ctx->hw_context[1 ] =SHA224_H1 ; - req_ctx->hw_context[2 ] =SHA224_H2 ; - req_ctx->hw_context[3 ] =SHA224_H3 ; - req_ctx->hw_context[4 ] =SHA224_H4 ; - req_ctx->hw_context[5 ] =SHA224_H5 ; - req_ctx->hw_context[6 ] =SHA224_H6 ; - req_ctx->hw_context[7 ] =SHA224_H7 ; - -/* init 64-bit count */ - req_ctx->hw_context[8 ] =0 ; - req_ctx->hw_context[9 ] =0 ; - -ahash_init (areq); - req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ - -return 0 ; +return common_nonsnoop_hash (edesc, areq, nbytes_to_hash, ahash_done); }static int ahash_update (struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =0 ; + req_ctx->last =0 ;return ahash_process_req (areq, areq->nbytes); }
@@ -2181,7 +2103,7 @@ static int ahash_final(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =1 ; + req_ctx->last =1 ;return ahash_process_req (areq,0 ); }
@@ -2190,7 +2112,7 @@ static int ahash_finup(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last_request =1 ; + req_ctx->last =1 ;return ahash_process_req (areq, areq->nbytes); }
Signature · 1 line
2.54.0
PATCH 3/5 crypto: talitos - stop using crypto_ahash::init
In reply to Goetz GoerischFrom: Eric Biggers <[email protected]>
commit 9826d1d6ed5f86cb3d61610b3b1fe31e96a40418 upstream.
The function pointer crypto_ahash::init is an internal implementation detail of the ahash API that exists to help it support both ahash and shash algorithms. With an upcoming refactoring of how the ahash API supports shash algorithms, this field will be removed.
Some drivers are invoking crypto_ahash::init to call into their own code, which is unnecessary and inefficient. The talitos driver is one of those drivers. Make it just call its own code directly.
--- drivers/crypto/talitos.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/crypto/talitos.c +9 -6
@@ -2119,13 +2119,14 @@ static int ahash_finup(struct ahash_request *areq)static int ahash_digest (struct ahash_request *areq) { -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -struct crypto_ahash *ahash =crypto_ahash_reqtfm (areq); - - ahash->init (areq); - req_ctx->last =1 ; +ahash_init (areq); +return ahash_finup (areq); +} -return ahash_process_req (areq, areq->nbytes); +static int ahash_digest_sha224_swinit (struct ahash_request *areq) +{ +ahash_init_sha224_swinit (areq); +return ahash_finup (areq); }static int ahash_export (struct ahash_request *areq,void *out)
@@ -3242,6 +3243,8 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, (!strcmp(alg->cra_name, "sha224") || !strcmp(alg->cra_name, "hmac(sha224)"))) { t_alg->algt.alg.hash.init = ahash_init_sha224_swinit; + t_alg->algt.alg.hash.digest = + ahash_digest_sha224_swinit; t_alg->algt.desc_hdr_template =DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | DESC_HDR_SEL0_MDEUA |
Signature · 1 line
2.54.0
PATCH 4/5 crypto: talitos - fix SEC1 32k ahash request limitation
In reply to Goetz GoerischFrom: Paul Louvel <[email protected]>
commit 655ef638a2bc3cd0a9eff99a02f83cab94a3a917 upstream.
Since commit c662b043cdca ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES"), the crypto core may pass large scatterlists spanning multiple pages to drivers supporting ahash operations. As a result, a driver can now receive large ahash requests.
The SEC1 engine has a limitation where a single descriptor cannot process more than 32k of data. The current implementation attempts to handle the entire request within a single descriptor, which leads to failures raised by the driver:
"length exceeds h/w max limit"
Address this limitation by splitting large ahash requests into multiple descriptors, each respecting the 32k hardware limit. This allows processing arbitrarily large requests.
--- drivers/crypto/talitos.c | 216 ++++++++++++++++++++++++++------------- 1 file changed, 147 insertions(+), 69 deletions(-)
drivers/crypto/talitos.c +147 -69
@@ -12,6 +12,7 @@* All rights reserved. */ +#include <linux/workqueue.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mod_devicetable.h>
@@ -870,10 +871,18 @@ struct talitos_ahash_req_ctx {unsigned int swinit;unsigned int first;unsigned int last; +unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;struct scatterlist bufsl[2 ];struct scatterlist *psrc; + +struct scatterlist request_bufsl[2 ]; +struct ahash_request *areq; +struct scatterlist *request_sl; +unsigned int remaining_ahash_request_bytes; +unsigned int current_ahash_request_bytes; +struct work_struct sec1_ahash_process_remaining; };struct talitos_export_state {
@@ -1759,7 +1768,20 @@ static void ahash_done(struct device *dev,kfree (edesc); -ahash_request_complete (areq, err); +if (err) { +ahash_request_complete (areq, err); +return ; + } + + req_ctx->remaining_ahash_request_bytes -= + req_ctx->current_ahash_request_bytes; + +if (!req_ctx->remaining_ahash_request_bytes) { +ahash_request_complete (areq,0 ); +return ; + } + +schedule_work (&req_ctx->sec1_ahash_process_remaining); }/*
@@ -1925,60 +1947,7 @@ static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, nbytes, 0, 0, 0, areq->base.flags, false); } -static int ahash_init (struct ahash_request *areq) -{ -struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); -struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); -struct device *dev = ctx->dev; -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -unsigned int size; -dma_addr_t dma; - -/* Initialize the context */ - req_ctx->buf_idx =0 ; - req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ - req_ctx->swinit =0 ;/* assume h/w init of context */ - size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) - ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 - :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; - req_ctx->hw_context_size = size; - - dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, -DMA_TO_DEVICE ); -dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); - -return 0 ; -} - -/* -* on h/w without explicit sha224 support, we initialize h/w context -* manually with sha224 constants, and tell it to run sha256. -*/ -static int ahash_init_sha224_swinit (struct ahash_request *areq) -{ -struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - - req_ctx->hw_context[0 ] =SHA224_H0 ; - req_ctx->hw_context[1 ] =SHA224_H1 ; - req_ctx->hw_context[2 ] =SHA224_H2 ; - req_ctx->hw_context[3 ] =SHA224_H3 ; - req_ctx->hw_context[4 ] =SHA224_H4 ; - req_ctx->hw_context[5 ] =SHA224_H5 ; - req_ctx->hw_context[6 ] =SHA224_H6 ; - req_ctx->hw_context[7 ] =SHA224_H7 ; - -/* init 64-bit count */ - req_ctx->hw_context[8 ] =0 ; - req_ctx->hw_context[9 ] =0 ; - -ahash_init (areq); - req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ - -return 0 ; -} - -static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) +static int ahash_process_req_one (struct ahash_request *areq,unsigned int nbytes) {struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq);struct talitos_ctx *ctx =crypto_ahash_ctx (tfm);
@@ -1997,12 +1966,12 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ - nents =sg_nents_for_len (areq->src, nbytes); + nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (areq->src, nents, +sg_copy_to_buffer (req_ctx->request_sl, nents, ctx_buf + req_ctx->nbuf, nbytes); req_ctx->nbuf += nbytes;return 0 ;
@@ -2029,7 +1998,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)sg_init_table (req_ctx->bufsl, nsg);sg_set_buf (req_ctx->bufsl, ctx_buf, req_ctx->nbuf);if (nsg >1 ) -sg_chain (req_ctx->bufsl,2 , areq->src); +sg_chain (req_ctx->bufsl,2 , req_ctx->request_sl); req_ctx->psrc = req_ctx->bufsl; }else if (is_sec1 && req_ctx->nbuf && req_ctx->nbuf < blocksize) {int offset;
@@ -2038,26 +2007,26 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) offset = blocksize - req_ctx->nbuf; else offset = nbytes_to_hash - req_ctx->nbuf; - nents =sg_nents_for_len (areq->src, offset); + nents =sg_nents_for_len (req_ctx->request_sl, offset);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_copy_to_buffer (areq->src, nents, +sg_copy_to_buffer (req_ctx->request_sl, nents, ctx_buf + req_ctx->nbuf, offset); req_ctx->nbuf += offset; - req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, areq->src, + req_ctx->psrc =scatterwalk_ffwd (req_ctx->bufsl, req_ctx->request_sl, offset); }else - req_ctx->psrc = areq->src; + req_ctx->psrc = req_ctx->request_sl;if (to_hash_later) { - nents =sg_nents_for_len (areq->src, nbytes); + nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {dev_err (dev,"Invalid number of src SG.\n" );return nents; } -sg_pcopy_to_buffer (areq->src, nents, +sg_pcopy_to_buffer (req_ctx->request_sl, nents, req_ctx->buf[(req_ctx->buf_idx +1 ) &1 ], to_hash_later, nbytes - to_hash_later);
@@ -2065,7 +2034,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) req_ctx->to_hash_later = to_hash_later;/* Allocate extended descriptor */ - edesc =ahash_edesc_alloc (areq, nbytes_to_hash); + edesc =ahash_edesc_alloc (req_ctx->areq, nbytes_to_hash);if (IS_ERR (edesc))return PTR_ERR (edesc);
@@ -2087,14 +2056,123 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (ctx->keylen && (req_ctx->first || req_ctx->last)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ; -return common_nonsnoop_hash (edesc, areq, nbytes_to_hash, ahash_done); +return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done); } -static int ahash_update (struct ahash_request *areq) +static void sec1_ahash_process_remaining (struct work_struct *work) +{ +struct talitos_ahash_req_ctx *req_ctx = + container_of(work, struct talitos_ahash_req_ctx, + sec1_ahash_process_remaining); +int err =0 ; + + req_ctx->request_sl =scatterwalk_ffwd (req_ctx->request_bufsl, + req_ctx->request_sl,TALITOS1_MAX_DATA_LEN ); + +if (req_ctx->remaining_ahash_request_bytes >TALITOS1_MAX_DATA_LEN ) + req_ctx->current_ahash_request_bytes =TALITOS1_MAX_DATA_LEN ; +else { + req_ctx->current_ahash_request_bytes = + req_ctx->remaining_ahash_request_bytes; + +if (req_ctx->last_request) + req_ctx->last =1 ; + } + + err =ahash_process_req_one (req_ctx->areq, + req_ctx->current_ahash_request_bytes); + +if (err != -EINPROGRESS ) +ahash_request_complete (req_ctx->areq, err); +} + +static int ahash_process_req (struct ahash_request *areq,unsigned int nbytes) +{ +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev; +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +struct talitos_private *priv =dev_get_drvdata (dev); +bool is_sec1 =has_ftr_sec1 (priv); + + req_ctx->areq = areq; + req_ctx->request_sl = areq->src; + req_ctx->remaining_ahash_request_bytes = nbytes; + +if (is_sec1) { +if (nbytes >TALITOS1_MAX_DATA_LEN ) + nbytes =TALITOS1_MAX_DATA_LEN ; +else if (req_ctx->last_request) + req_ctx->last =1 ; + } + + req_ctx->current_ahash_request_bytes = nbytes; + +return ahash_process_req_one (req_ctx->areq, + req_ctx->current_ahash_request_bytes); +} + +static int ahash_init (struct ahash_request *areq) { +struct crypto_ahash *tfm =crypto_ahash_reqtfm (areq); +struct talitos_ctx *ctx =crypto_ahash_ctx (tfm); +struct device *dev = ctx->dev;struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); +unsigned int size; +dma_addr_t dma; +/* Initialize the context */ + req_ctx->buf_idx =0 ; + req_ctx->nbuf =0 ; + req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->swinit =0 ;/* assume h/w init of context */ + size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) + ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 + :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; + req_ctx->hw_context_size = size; + req_ctx->last_request =0 ; req_ctx->last =0 ; +INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); + + dma =dma_map_single (dev, req_ctx->hw_context, req_ctx->hw_context_size, +DMA_TO_DEVICE ); +dma_unmap_single (dev, dma, req_ctx->hw_context_size,DMA_TO_DEVICE ); + +return 0 ; +} + +/* +* on h/w without explicit sha224 support, we initialize h/w context +* manually with sha224 constants, and tell it to run sha256. +*/ +static int ahash_init_sha224_swinit (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->hw_context[0 ] =SHA224_H0 ; + req_ctx->hw_context[1 ] =SHA224_H1 ; + req_ctx->hw_context[2 ] =SHA224_H2 ; + req_ctx->hw_context[3 ] =SHA224_H3 ; + req_ctx->hw_context[4 ] =SHA224_H4 ; + req_ctx->hw_context[5 ] =SHA224_H5 ; + req_ctx->hw_context[6 ] =SHA224_H6 ; + req_ctx->hw_context[7 ] =SHA224_H7 ; + +/* init 64-bit count */ + req_ctx->hw_context[8 ] =0 ; + req_ctx->hw_context[9 ] =0 ; + +ahash_init (areq); + req_ctx->swinit =1 ;/* prevent h/w initting context with sha256 values*/ + +return 0 ; +} + +static int ahash_update (struct ahash_request *areq) +{ +struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); + + req_ctx->last_request =0 ;return ahash_process_req (areq, areq->nbytes); }
@@ -2103,7 +2181,7 @@ static int ahash_final(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last =1 ; + req_ctx->last_request =1 ;return ahash_process_req (areq,0 ); }
@@ -2112,7 +2190,7 @@ static int ahash_finup(struct ahash_request *areq) {struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); - req_ctx->last =1 ; + req_ctx->last_request =1 ;return ahash_process_req (areq, areq->nbytes); }
Signature · 1 line
2.54.0
PATCH 5/5 crypto: talitos - rename first/last to first_desc/last_desc
In reply to Goetz GoerischFrom: Paul Louvel <[email protected]>
commit a1b80018b8cec27fc06a8b04a7f8b5f6cfe86eae upstream.
Previous commit introduces a new last_request variable in the context structure.
Renaming the first/last existing member variable in the context structure to improve readability.
--- drivers/crypto/talitos.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
drivers/crypto/talitos.c +23 -23
@@ -869,8 +869,8 @@ struct talitos_ahash_req_ctx {u8 buf[2 ][HASH_MAX_BLOCK_SIZE ];int buf_idx;unsigned int swinit; -unsigned int first; -unsigned int last; +unsigned int first_desc; +unsigned int last_desc;unsigned int last_request;unsigned int to_hash_later;unsigned int nbuf;
@@ -889,8 +889,8 @@ struct talitos_export_state {u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE /sizeof (u32)];u8 buf[HASH_MAX_BLOCK_SIZE ];unsigned int swinit; -unsigned int first; -unsigned int last; +unsigned int first_desc; +unsigned int last_desc;unsigned int to_hash_later;unsigned int nbuf; };
@@ -1722,7 +1722,7 @@ static void common_nonsnoop_hash_unmap(struct device *dev,if (desc->next_desc && desc->ptr[5 ].ptr != desc2->ptr[5 ].ptr)unmap_single_talitos_ptr (dev, &desc2->ptr[5 ],DMA_FROM_DEVICE ); -if (req_ctx->last) +if (req_ctx->last_desc)memcpy (areq->result, req_ctx->hw_context,crypto_ahash_digestsize (tfm));
@@ -1759,7 +1759,7 @@ static void ahash_done(struct device *dev, container_of(desc, struct talitos_edesc, desc);struct talitos_ahash_req_ctx *req_ctx =ahash_request_ctx (areq); -if (!req_ctx->last && req_ctx->to_hash_later) { +if (!req_ctx->last_desc && req_ctx->to_hash_later) {/* Position any partial block for next update/final/finup */ req_ctx->buf_idx = (req_ctx->buf_idx +1 ) &1 ; req_ctx->nbuf = req_ctx->to_hash_later;
@@ -1825,7 +1825,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* first DWORD empty */ /* hash context in */ -if (!req_ctx->first || req_ctx->swinit) { +if (!req_ctx->first_desc || req_ctx->swinit) { map_single_talitos_ptr_nosync(dev, &desc->ptr[1], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1833,7 +1833,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, req_ctx->swinit =0 ; }/* Indicate next op is not the first. */ - req_ctx->first =0 ; + req_ctx->first_desc =0 ;/* HMAC key */ if (ctx->keylen)
@@ -1866,7 +1866,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* fifth DWORD empty */ /* hash/HMAC out -or- hash context out */ -if (req_ctx->last) +if (req_ctx->last_desc)map_single_talitos_ptr (dev, &desc->ptr[5 ],crypto_ahash_digestsize (tfm), req_ctx->hw_context,DMA_FROM_DEVICE );
@@ -1908,7 +1908,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,if (sg_count >1 ) sync_needed = true;copy_talitos_ptr (&desc2->ptr[5 ], &desc->ptr[5 ], is_sec1); -if (req_ctx->last) +if (req_ctx->last_desc) map_single_talitos_ptr_nosync(dev, &desc->ptr[5], req_ctx->hw_context_size, req_ctx->hw_context,
@@ -1964,7 +1964,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytesbool is_sec1 =has_ftr_sec1 (priv);u8 *ctx_buf = req_ctx->buf[req_ctx->buf_idx]; -if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) { +if (!req_ctx->last_desc && (nbytes + req_ctx->nbuf <= blocksize)) {/* Buffer up to one whole block */ nents =sg_nents_for_len (req_ctx->request_sl, nbytes);if (nents <0 ) {
@@ -1981,7 +1981,7 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes nbytes_to_hash = nbytes + req_ctx->nbuf; to_hash_later = nbytes_to_hash & (blocksize -1 ); -if (req_ctx->last) +if (req_ctx->last_desc) to_hash_later =0 ;else if (to_hash_later)/* There is a partial block. Hash the full block(s) now */
@@ -2041,19 +2041,19 @@ static int ahash_process_req_one(struct ahash_request *areq, unsigned int nbytes edesc->desc.hdr = ctx->desc_hdr_template;/* On last one, request SEC to pad; otherwise continue */ -if (req_ctx->last) +if (req_ctx->last_desc) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_PAD ;else edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_CONT ;/* request SEC to INIT hash. */ -if (req_ctx->first && !req_ctx->swinit) +if (req_ctx->first_desc && !req_ctx->swinit) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_INIT ;/* When the tfm context has a keylen, it's an HMAC. * A first or last (ie. not middle) descriptor must request HMAC. */ -if (ctx->keylen && (req_ctx->first || req_ctx->last)) +if (ctx->keylen && (req_ctx->first_desc || req_ctx->last_desc)) edesc->desc.hdr |=DESC_HDR_MODE0_MDEU_HMAC ;return common_nonsnoop_hash (edesc, req_ctx->areq, nbytes_to_hash, ahash_done);
@@ -2076,7 +2076,7 @@ static void sec1_ahash_process_remaining(struct work_struct *work) req_ctx->remaining_ahash_request_bytes;if (req_ctx->last_request) - req_ctx->last =1 ; + req_ctx->last_desc =1 ; } err = ahash_process_req_one(req_ctx->areq,
@@ -2103,7 +2103,7 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)if (nbytes >TALITOS1_MAX_DATA_LEN ) nbytes =TALITOS1_MAX_DATA_LEN ;else if (req_ctx->last_request) - req_ctx->last =1 ; + req_ctx->last_desc =1 ; } req_ctx->current_ahash_request_bytes = nbytes;
@@ -2124,14 +2124,14 @@ static int ahash_init(struct ahash_request *areq)/* Initialize the context */ req_ctx->buf_idx =0 ; req_ctx->nbuf =0 ; - req_ctx->first =1 ;/* first indicates h/w must init its context */ + req_ctx->first_desc =1 ;/* first_desc indicates h/w must init its context */ req_ctx->swinit =0 ;/* assume h/w init of context */ size = (crypto_ahash_digestsize (tfm) <=SHA256_DIGEST_SIZE ) ?TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 :TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 ; req_ctx->hw_context_size = size; req_ctx->last_request =0 ; - req_ctx->last =0 ; + req_ctx->last_desc =0 ;INIT_WORK (&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_remaining); dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size,
@@ -2224,8 +2224,8 @@ static int ahash_export(struct ahash_request *areq, void *out) req_ctx->hw_context_size);memcpy (export->buf, req_ctx->buf[req_ctx->buf_idx], req_ctx->nbuf); export->swinit = req_ctx->swinit; - export->first = req_ctx->first; - export->last = req_ctx->last; + export->first_desc = req_ctx->first_desc; + export->last_desc = req_ctx->last_desc; export->to_hash_later = req_ctx->to_hash_later; export->nbuf = req_ctx->nbuf;
@@ -2250,8 +2250,8 @@ static int ahash_import(struct ahash_request *areq, const void *in)memcpy (req_ctx->hw_context, export->hw_context, size);memcpy (req_ctx->buf[0 ], export->buf, export->nbuf); req_ctx->swinit = export->swinit; - req_ctx->first = export->first; - req_ctx->last = export->last; + req_ctx->first_desc = export->first_desc; + req_ctx->last_desc = export->last_desc; req_ctx->to_hash_later = export->to_hash_later; req_ctx->nbuf = export->nbuf;
Signature · 1 line
2.54.0