* [v2 PATCH 0/2] crypto: ahash - Allow async stack requests when specified @ 2025-09-09 5:41 Herbert Xu 2025-09-09 5:41 ` [v2 PATCH 1/2] " Herbert Xu 2025-09-09 5:41 ` [v2 PATCH 2/2] crypto: s390/phmac - Allow stack requests Herbert Xu 0 siblings, 2 replies; 6+ messages in thread From: Herbert Xu @ 2025-09-09 5:41 UTC (permalink / raw) To: Linux Crypto Mailing List; +Cc: Mikulas Patocka v2 fixes the inverted tests that broke everything. This patch series adds support for passing stack requests down to algorithms that do not do DMA on the request context, e.g., phmac. Herbert Xu (2): crypto: ahash - Allow async stack requests when specified crypto: s390/phmac - Allow stack requests arch/s390/crypto/phmac_s390.c | 1 + crypto/ahash.c | 22 ++++++++++++++++++---- include/crypto/internal/hash.h | 3 +++ 3 files changed, 22 insertions(+), 4 deletions(-) -- 2.39.5 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [v2 PATCH 1/2] crypto: ahash - Allow async stack requests when specified 2025-09-09 5:41 [v2 PATCH 0/2] crypto: ahash - Allow async stack requests when specified Herbert Xu @ 2025-09-09 5:41 ` Herbert Xu 2025-09-15 15:06 ` Mikulas Patocka 2025-09-09 5:41 ` [v2 PATCH 2/2] crypto: s390/phmac - Allow stack requests Herbert Xu 1 sibling, 1 reply; 6+ messages in thread From: Herbert Xu @ 2025-09-09 5:41 UTC (permalink / raw) To: Linux Crypto Mailing List; +Cc: Mikulas Patocka As it stands stack requests are forbidden for async algorithms because of the inability to perform DMA on stack memory. However, some async algorithms do not perform DMA and are able to handle stack requests. Allow such uses by addnig a new type bit CRYPTO_AHASH_ALG_STACK_REQ. When it is set on the algorithm stack requests will be allowed even if the algorithm is asynchronous. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> --- crypto/ahash.c | 22 ++++++++++++++++++---- include/crypto/internal/hash.h | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crypto/ahash.c b/crypto/ahash.c index a227793d2c5b..33b2a19169f1 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -49,6 +49,20 @@ static inline bool crypto_ahash_need_fallback(struct crypto_ahash *tfm) CRYPTO_ALG_NEED_FALLBACK; } +static inline bool crypto_ahash_stack_req_ok(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + + if (!ahash_req_on_stack(req)) + return true; + + if (!ahash_is_async(tfm)) + return true; + + return crypto_ahash_alg(tfm)->halg.base.cra_flags & + CRYPTO_AHASH_ALG_STACK_REQ; +} + static inline void ahash_op_done(void *data, int err, int (*finish)(struct ahash_request *, int)) { @@ -376,7 +390,7 @@ int crypto_ahash_init(struct ahash_request *req) return crypto_shash_init(prepare_shash_desc(req, tfm)); if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) return -ENOKEY; - if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + if (!crypto_ahash_stack_req_ok(req)) return -EAGAIN; if (crypto_ahash_block_only(tfm)) { u8 *buf = ahash_request_ctx(req); @@ -451,7 +465,7 @@ int crypto_ahash_update(struct ahash_request *req) if (likely(tfm->using_shash)) return shash_ahash_update(req, ahash_request_ctx(req)); - if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + if (!crypto_ahash_stack_req_ok(req)) return -EAGAIN; if (!crypto_ahash_block_only(tfm)) return ahash_do_req_chain(req, &crypto_ahash_alg(tfm)->update); @@ -531,7 +545,7 @@ int crypto_ahash_finup(struct ahash_request *req) if (likely(tfm->using_shash)) return shash_ahash_finup(req, ahash_request_ctx(req)); - if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + if (!crypto_ahash_stack_req_ok(req)) return -EAGAIN; if (!crypto_ahash_alg(tfm)->finup) return ahash_def_finup(req); @@ -569,7 +583,7 @@ int crypto_ahash_digest(struct ahash_request *req) if (likely(tfm->using_shash)) return shash_ahash_digest(req, prepare_shash_desc(req, tfm)); - if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + if (!crypto_ahash_stack_req_ok(req)) return -EAGAIN; if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) return -ENOKEY; diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 6ec5f2f37ccb..79899d36032b 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h @@ -23,6 +23,9 @@ /* This bit is set by the Crypto API if export_core is not supported. */ #define CRYPTO_AHASH_ALG_NO_EXPORT_CORE 0x08000000 +/* This bit is set by the Crypto API if stack requests are supported. */ +#define CRYPTO_AHASH_ALG_STACK_REQ 0x10000000 + #define HASH_FBREQ_ON_STACK(name, req) \ char __##name##_req[sizeof(struct ahash_request) + \ MAX_SYNC_HASH_REQSIZE] CRYPTO_MINALIGN_ATTR; \ -- 2.39.5 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [v2 PATCH 1/2] crypto: ahash - Allow async stack requests when specified 2025-09-09 5:41 ` [v2 PATCH 1/2] " Herbert Xu @ 2025-09-15 15:06 ` Mikulas Patocka 2025-09-16 3:59 ` Herbert Xu 0 siblings, 1 reply; 6+ messages in thread From: Mikulas Patocka @ 2025-09-15 15:06 UTC (permalink / raw) To: Herbert Xu; +Cc: Linux Crypto Mailing List, dm-devel Hi Would it be possible to export the function crypto_ahash_stack_req_ok, so that I could know up-front whether having a request on the stack will succeed or not? Perhaps the function crypto_ahash_stack_req_ok could take "struct crypto_ahash *" argument rather than "struct ahash_request, *" so that I would know in advance whether it makes sense to try to build the request on the stack or not. Mikulas On Tue, 9 Sep 2025, Herbert Xu wrote: > As it stands stack requests are forbidden for async algorithms > because of the inability to perform DMA on stack memory. > > However, some async algorithms do not perform DMA and are able > to handle stack requests. Allow such uses by addnig a new type > bit CRYPTO_AHASH_ALG_STACK_REQ. When it is set on the algorithm > stack requests will be allowed even if the algorithm is asynchronous. > > Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> > --- > crypto/ahash.c | 22 ++++++++++++++++++---- > include/crypto/internal/hash.h | 3 +++ > 2 files changed, 21 insertions(+), 4 deletions(-) > > diff --git a/crypto/ahash.c b/crypto/ahash.c > index a227793d2c5b..33b2a19169f1 100644 > --- a/crypto/ahash.c > +++ b/crypto/ahash.c > @@ -49,6 +49,20 @@ static inline bool crypto_ahash_need_fallback(struct crypto_ahash *tfm) > CRYPTO_ALG_NEED_FALLBACK; > } > > +static inline bool crypto_ahash_stack_req_ok(struct ahash_request *req) > +{ > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + > + if (!ahash_req_on_stack(req)) > + return true; > + > + if (!ahash_is_async(tfm)) > + return true; > + > + return crypto_ahash_alg(tfm)->halg.base.cra_flags & > + CRYPTO_AHASH_ALG_STACK_REQ; > +} > + > static inline void ahash_op_done(void *data, int err, > int (*finish)(struct ahash_request *, int)) > { > @@ -376,7 +390,7 @@ int crypto_ahash_init(struct ahash_request *req) > return crypto_shash_init(prepare_shash_desc(req, tfm)); > if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) > return -ENOKEY; > - if (ahash_req_on_stack(req) && ahash_is_async(tfm)) > + if (!crypto_ahash_stack_req_ok(req)) > return -EAGAIN; > if (crypto_ahash_block_only(tfm)) { > u8 *buf = ahash_request_ctx(req); > @@ -451,7 +465,7 @@ int crypto_ahash_update(struct ahash_request *req) > > if (likely(tfm->using_shash)) > return shash_ahash_update(req, ahash_request_ctx(req)); > - if (ahash_req_on_stack(req) && ahash_is_async(tfm)) > + if (!crypto_ahash_stack_req_ok(req)) > return -EAGAIN; > if (!crypto_ahash_block_only(tfm)) > return ahash_do_req_chain(req, &crypto_ahash_alg(tfm)->update); > @@ -531,7 +545,7 @@ int crypto_ahash_finup(struct ahash_request *req) > > if (likely(tfm->using_shash)) > return shash_ahash_finup(req, ahash_request_ctx(req)); > - if (ahash_req_on_stack(req) && ahash_is_async(tfm)) > + if (!crypto_ahash_stack_req_ok(req)) > return -EAGAIN; > if (!crypto_ahash_alg(tfm)->finup) > return ahash_def_finup(req); > @@ -569,7 +583,7 @@ int crypto_ahash_digest(struct ahash_request *req) > > if (likely(tfm->using_shash)) > return shash_ahash_digest(req, prepare_shash_desc(req, tfm)); > - if (ahash_req_on_stack(req) && ahash_is_async(tfm)) > + if (!crypto_ahash_stack_req_ok(req)) > return -EAGAIN; > if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) > return -ENOKEY; > diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h > index 6ec5f2f37ccb..79899d36032b 100644 > --- a/include/crypto/internal/hash.h > +++ b/include/crypto/internal/hash.h > @@ -23,6 +23,9 @@ > /* This bit is set by the Crypto API if export_core is not supported. */ > #define CRYPTO_AHASH_ALG_NO_EXPORT_CORE 0x08000000 > > +/* This bit is set by the Crypto API if stack requests are supported. */ > +#define CRYPTO_AHASH_ALG_STACK_REQ 0x10000000 > + > #define HASH_FBREQ_ON_STACK(name, req) \ > char __##name##_req[sizeof(struct ahash_request) + \ > MAX_SYNC_HASH_REQSIZE] CRYPTO_MINALIGN_ATTR; \ > -- > 2.39.5 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [v2 PATCH 1/2] crypto: ahash - Allow async stack requests when specified 2025-09-15 15:06 ` Mikulas Patocka @ 2025-09-16 3:59 ` Herbert Xu 2025-09-16 9:38 ` Mikulas Patocka 0 siblings, 1 reply; 6+ messages in thread From: Herbert Xu @ 2025-09-16 3:59 UTC (permalink / raw) To: Mikulas Patocka; +Cc: Linux Crypto Mailing List, dm-devel On Mon, Sep 15, 2025 at 05:06:51PM +0200, Mikulas Patocka wrote: > > Would it be possible to export the function crypto_ahash_stack_req_ok, so > that I could know up-front whether having a request on the stack will > succeed or not? > > Perhaps the function crypto_ahash_stack_req_ok could take "struct > crypto_ahash *" argument rather than "struct ahash_request, *" so that I > would know in advance whether it makes sense to try to build the request > on the stack or not. I think the pain point is the use of SG lists. If we could convert them to something like iov's then you should be able to supply stack memory unconditionally. Cheers, -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [v2 PATCH 1/2] crypto: ahash - Allow async stack requests when specified 2025-09-16 3:59 ` Herbert Xu @ 2025-09-16 9:38 ` Mikulas Patocka 0 siblings, 0 replies; 6+ messages in thread From: Mikulas Patocka @ 2025-09-16 9:38 UTC (permalink / raw) To: Herbert Xu; +Cc: Linux Crypto Mailing List, dm-devel On Tue, 16 Sep 2025, Herbert Xu wrote: > On Mon, Sep 15, 2025 at 05:06:51PM +0200, Mikulas Patocka wrote: > > > > Would it be possible to export the function crypto_ahash_stack_req_ok, so > > that I could know up-front whether having a request on the stack will > > succeed or not? > > > > Perhaps the function crypto_ahash_stack_req_ok could take "struct > > crypto_ahash *" argument rather than "struct ahash_request, *" so that I > > would know in advance whether it makes sense to try to build the request > > on the stack or not. > > I think the pain point is the use of SG lists. If we could convert > them to something like iov's then you should be able to supply stack > memory unconditionally. > > Cheers, On architectures without automatic DMA/cache coherency, you must make sure that you do not write to a cacheline simultaneously using DMA and CPU. This would be hard to guarantee if the crypto request is on the stack because it may share a cacheline with many other local variables. Mikulas ^ permalink raw reply [flat|nested] 6+ messages in thread
* [v2 PATCH 2/2] crypto: s390/phmac - Allow stack requests 2025-09-09 5:41 [v2 PATCH 0/2] crypto: ahash - Allow async stack requests when specified Herbert Xu 2025-09-09 5:41 ` [v2 PATCH 1/2] " Herbert Xu @ 2025-09-09 5:41 ` Herbert Xu 1 sibling, 0 replies; 6+ messages in thread From: Herbert Xu @ 2025-09-09 5:41 UTC (permalink / raw) To: Linux Crypto Mailing List; +Cc: Mikulas Patocka As phmac does not perform DMA, it can support stack requests. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> --- arch/s390/crypto/phmac_s390.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/s390/crypto/phmac_s390.c b/arch/s390/crypto/phmac_s390.c index 7ecfdc4fba2d..ead4c0d3523e 100644 --- a/arch/s390/crypto/phmac_s390.c +++ b/arch/s390/crypto/phmac_s390.c @@ -932,6 +932,7 @@ static int phmac_do_one_request(struct crypto_engine *engine, void *areq) .cra_blocksize = SHA##x##_BLOCK_SIZE, \ .cra_priority = 400, \ .cra_flags = CRYPTO_ALG_ASYNC | \ + CRYPTO_AHASH_ALG_STACK_REQ |\ CRYPTO_ALG_NO_FALLBACK, \ .cra_ctxsize = sizeof(struct phmac_tfm_ctx), \ .cra_module = THIS_MODULE, \ -- 2.39.5 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-09-16 9:39 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-09-09 5:41 [v2 PATCH 0/2] crypto: ahash - Allow async stack requests when specified Herbert Xu 2025-09-09 5:41 ` [v2 PATCH 1/2] " Herbert Xu 2025-09-15 15:06 ` Mikulas Patocka 2025-09-16 3:59 ` Herbert Xu 2025-09-16 9:38 ` Mikulas Patocka 2025-09-09 5:41 ` [v2 PATCH 2/2] crypto: s390/phmac - Allow stack requests Herbert Xu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).