From: Jakub Kicinski <kuba@kernel•org>
To: davem@davemloft•net, pabeni@redhat•com
Cc: netdev@vger•kernel.org, borisp@nvidia•com,
john.fastabend@gmail•com, daniel@iogearbox•net,
vfedorenko@novek•ru, Jakub Kicinski <kuba@kernel•org>
Subject: [PATCH net-next 08/10] tls: rx: use async as an in-out argument
Date: Mon, 11 Apr 2022 12:19:15 -0700 [thread overview]
Message-ID: <20220411191917.1240155-9-kuba@kernel.org> (raw)
In-Reply-To: <20220411191917.1240155-1-kuba@kernel.org>
Propagating EINPROGRESS thru multiple layers of functions is
error prone. Use darg->async as an in/out argument, like we
use darg->zc today. On input it tells the code if async is
allowed, on output if it took place.
Signed-off-by: Jakub Kicinski <kuba@kernel•org>
---
net/tls/tls_sw.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index b5d1393aa8d4..6b906b0cb2fd 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -227,7 +227,7 @@ static int tls_do_decryption(struct sock *sk,
char *iv_recv,
size_t data_len,
struct aead_request *aead_req,
- bool async)
+ struct tls_decrypt_arg *darg)
{
struct tls_context *tls_ctx = tls_get_ctx(sk);
struct tls_prot_info *prot = &tls_ctx->prot_info;
@@ -240,7 +240,7 @@ static int tls_do_decryption(struct sock *sk,
data_len + prot->tag_size,
(u8 *)iv_recv);
- if (async) {
+ if (darg->async) {
/* Using skb->sk to push sk through to crypto async callback
* handler. This allows propagating errors up to the socket
* if needed. It _must_ be cleared in the async handler
@@ -260,11 +260,13 @@ static int tls_do_decryption(struct sock *sk,
ret = crypto_aead_decrypt(aead_req);
if (ret == -EINPROGRESS) {
- if (async)
- return ret;
+ if (darg->async)
+ return 0;
ret = crypto_wait_req(ret, &ctx->async_wait);
}
+ darg->async = false;
+
if (ret == -EBADMSG)
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSDECRYPTERROR);
@@ -1536,9 +1538,9 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
/* Prepare and submit AEAD request */
err = tls_do_decryption(sk, skb, sgin, sgout, iv,
- data_len, aead_req, darg->async);
- if (err == -EINPROGRESS)
- return err;
+ data_len, aead_req, darg);
+ if (darg->async)
+ return 0;
/* Release the pages in case iov was mapped to pages */
for (; pages > 0; pages--)
@@ -1575,11 +1577,10 @@ static int decrypt_skb_update(struct sock *sk, struct sk_buff *skb,
}
err = decrypt_internal(sk, skb, dest, NULL, darg);
- if (err < 0) {
- if (err == -EINPROGRESS)
- tls_advance_record_sn(sk, prot, &tls_ctx->rx);
+ if (err < 0)
return err;
- }
+ if (darg->async)
+ goto decrypt_next;
decrypt_done:
pad = padding_length(prot, skb);
@@ -1589,8 +1590,9 @@ static int decrypt_skb_update(struct sock *sk, struct sk_buff *skb,
rxm->full_len -= pad;
rxm->offset += prot->prepend_size;
rxm->full_len -= prot->overhead_size;
- tls_advance_record_sn(sk, prot, &tls_ctx->rx);
tlm->decrypted = 1;
+decrypt_next:
+ tls_advance_record_sn(sk, prot, &tls_ctx->rx);
return 0;
}
@@ -1799,13 +1801,12 @@ int tls_sw_recvmsg(struct sock *sk,
darg.async = false;
err = decrypt_skb_update(sk, skb, &msg->msg_iter, &darg);
- if (err < 0 && err != -EINPROGRESS) {
+ if (err < 0) {
tls_err_abort(sk, -EBADMSG);
goto recv_end;
}
- if (err == -EINPROGRESS)
- async = true;
+ async |= darg.async;
/* If the type of records being processed is not known yet,
* set it to record type just dequeued. If it is already known,
--
2.34.1
next prev parent reply other threads:[~2022-04-11 19:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-11 19:19 [PATCH net-next 00/10] tls: rx: random refactoring part 3 Jakub Kicinski
2022-04-11 19:19 ` [PATCH net-next 01/10] tls: rx: consistently use unlocked accessors for rx_list Jakub Kicinski
2022-04-11 19:19 ` [PATCH net-next 02/10] tls: rx: reuse leave_on_list label for psock Jakub Kicinski
2022-04-11 19:19 ` [PATCH net-next 03/10] tls: rx: move counting TlsDecryptErrors for sync Jakub Kicinski
2022-04-11 19:19 ` [PATCH net-next 04/10] tls: rx: don't handle TLS 1.3 in the async crypto callback Jakub Kicinski
2022-04-11 19:19 ` [PATCH net-next 05/10] tls: rx: assume crypto always calls our callback Jakub Kicinski
2022-04-11 19:19 ` [PATCH net-next 06/10] tls: rx: treat process_rx_list() errors as transient Jakub Kicinski
2022-04-11 19:19 ` [PATCH net-next 07/10] tls: rx: return the already-copied data on crypto error Jakub Kicinski
2022-04-11 19:19 ` Jakub Kicinski [this message]
2022-04-25 7:19 ` [PATCH net-next 08/10] tls: rx: use async as an in-out argument Gal Pressman
2022-04-25 14:54 ` Jakub Kicinski
2022-04-26 6:08 ` Gal Pressman
2022-04-11 19:19 ` [PATCH net-next 09/10] tls: rx: use MAX_IV_SIZE for allocations Jakub Kicinski
2022-04-11 19:19 ` [PATCH net-next 10/10] tls: rx: only copy IV from the packet for TLS 1.2 Jakub Kicinski
2022-04-13 11:00 ` [PATCH net-next 00/10] tls: rx: random refactoring part 3 patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220411191917.1240155-9-kuba@kernel.org \
--to=kuba@kernel$(echo .)org \
--cc=borisp@nvidia$(echo .)com \
--cc=daniel@iogearbox$(echo .)net \
--cc=davem@davemloft$(echo .)net \
--cc=john.fastabend@gmail$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pabeni@redhat$(echo .)com \
--cc=vfedorenko@novek$(echo .)ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox