Skip to content

Commit 8590541

Browse files
kuba-moodavem330
authored andcommitted
net: tls: handle backlogging of crypto requests
Since we're setting the CRYPTO_TFM_REQ_MAY_BACKLOG flag on our requests to the crypto API, crypto_aead_{encrypt,decrypt} can return -EBUSY instead of -EINPROGRESS in valid situations. For example, when the cryptd queue for AESNI is full (easy to trigger with an artificially low cryptd.cryptd_max_cpu_qlen), requests will be enqueued to the backlog but still processed. In that case, the async callback will also be called twice: first with err == -EINPROGRESS, which it seems we can just ignore, then with err == 0. Compared to Sabrina's original patch this version uses the new tls_*crypt_async_wait() helpers and converts the EBUSY to EINPROGRESS to avoid having to modify all the error handling paths. The handling is identical. Fixes: a54667f ("tls: Add support for encryption using async offload accelerator") Fixes: 94524d8 ("net/tls: Add support for async decryption of tls records") Co-developed-by: Sabrina Dubroca <[email protected]> Signed-off-by: Sabrina Dubroca <[email protected]> Link: https://lore.kernel.org/netdev/9681d1febfec295449a62300938ed2ae66983f28.1694018970.git.sd@queasysnail.net/ Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e01e393 commit 8590541

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

net/tls/tls_sw.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ static void tls_decrypt_done(void *data, int err)
196196
struct sock *sk;
197197
int aead_size;
198198

199+
/* If requests get too backlogged crypto API returns -EBUSY and calls
200+
* ->complete(-EINPROGRESS) immediately followed by ->complete(0)
201+
* to make waiting for backlog to flush with crypto_wait_req() easier.
202+
* First wait converts -EBUSY -> -EINPROGRESS, and the second one
203+
* -EINPROGRESS -> 0.
204+
* We have a single struct crypto_async_request per direction, this
205+
* scheme doesn't help us, so just ignore the first ->complete().
206+
*/
207+
if (err == -EINPROGRESS)
208+
return;
209+
199210
aead_size = sizeof(*aead_req) + crypto_aead_reqsize(aead);
200211
aead_size = ALIGN(aead_size, __alignof__(*dctx));
201212
dctx = (void *)((u8 *)aead_req + aead_size);
@@ -269,6 +280,10 @@ static int tls_do_decryption(struct sock *sk,
269280
}
270281

271282
ret = crypto_aead_decrypt(aead_req);
283+
if (ret == -EBUSY) {
284+
ret = tls_decrypt_async_wait(ctx);
285+
ret = ret ?: -EINPROGRESS;
286+
}
272287
if (ret == -EINPROGRESS) {
273288
if (darg->async)
274289
return 0;
@@ -449,6 +464,9 @@ static void tls_encrypt_done(void *data, int err)
449464
struct sk_msg *msg_en;
450465
struct sock *sk;
451466

467+
if (err == -EINPROGRESS) /* see the comment in tls_decrypt_done() */
468+
return;
469+
452470
msg_en = &rec->msg_encrypted;
453471

454472
sk = rec->sk;
@@ -553,6 +571,10 @@ static int tls_do_encryption(struct sock *sk,
553571
atomic_inc(&ctx->encrypt_pending);
554572

555573
rc = crypto_aead_encrypt(aead_req);
574+
if (rc == -EBUSY) {
575+
rc = tls_encrypt_async_wait(ctx);
576+
rc = rc ?: -EINPROGRESS;
577+
}
556578
if (!rc || rc != -EINPROGRESS) {
557579
atomic_dec(&ctx->encrypt_pending);
558580
sge->offset -= prot->prepend_size;

0 commit comments

Comments
 (0)