Skip to content

Commit c618db2

Browse files
kuba-moodavem330
authored andcommitted
tls: rx: async: hold onto the input skb
Async crypto currently benefits from the fact that we decrypt in place. When we allow input and output to be different skbs we will have to hang onto the input while we move to the next record. Clone the inputs and keep them on a list. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6ececdc commit c618db2

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

include/net/tls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct tls_sw_context_rx {
123123
atomic_t decrypt_pending;
124124
/* protect crypto_wait with decrypt_pending*/
125125
spinlock_t decrypt_compl_lock;
126+
struct sk_buff_head async_hold;
126127
struct wait_queue_head wq;
127128
};
128129

net/tls/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFLAGS_trace.o := -I$(src)
77

88
obj-$(CONFIG_TLS) += tls.o
99

10-
tls-y := tls_main.o tls_sw.o tls_proc.o trace.o
10+
tls-y := tls_main.o tls_sw.o tls_proc.o trace.o tls_strp.o
1111

1212
tls-$(CONFIG_TLS_TOE) += tls_toe.o
1313
tls-$(CONFIG_TLS_DEVICE) += tls_device.o tls_device_fallback.o

net/tls/tls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ int tls_sw_fallback_init(struct sock *sk,
124124
struct tls_offload_context_tx *offload_ctx,
125125
struct tls_crypto_info *crypto_info);
126126

127+
int tls_strp_msg_hold(struct sock *sk, struct sk_buff *skb,
128+
struct sk_buff_head *dst);
129+
127130
static inline struct tls_msg *tls_msg(struct sk_buff *skb)
128131
{
129132
struct sk_skb_cb *scb = (struct sk_skb_cb *)skb->cb;

net/tls/tls_strp.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <linux/skbuff.h>
4+
5+
#include "tls.h"
6+
7+
int tls_strp_msg_hold(struct sock *sk, struct sk_buff *skb,
8+
struct sk_buff_head *dst)
9+
{
10+
struct sk_buff *clone;
11+
12+
clone = skb_clone(skb, sk->sk_allocation);
13+
if (!clone)
14+
return -ENOMEM;
15+
__skb_queue_tail(dst, clone);
16+
return 0;
17+
}

net/tls/tls_sw.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,8 +1535,13 @@ static int tls_decrypt_sg(struct sock *sk, struct iov_iter *out_iov,
15351535
goto exit_free_pages;
15361536

15371537
darg->skb = tls_strp_msg(ctx);
1538-
if (darg->async)
1539-
return 0;
1538+
1539+
if (unlikely(darg->async)) {
1540+
err = tls_strp_msg_hold(sk, skb, &ctx->async_hold);
1541+
if (err)
1542+
__skb_queue_tail(&ctx->async_hold, darg->skb);
1543+
return err;
1544+
}
15401545

15411546
if (prot->tail_size)
15421547
darg->tail = dctx->tail;
@@ -1998,14 +2003,16 @@ int tls_sw_recvmsg(struct sock *sk,
19982003
reinit_completion(&ctx->async_wait.completion);
19992004
pending = atomic_read(&ctx->decrypt_pending);
20002005
spin_unlock_bh(&ctx->decrypt_compl_lock);
2001-
if (pending) {
2006+
ret = 0;
2007+
if (pending)
20022008
ret = crypto_wait_req(-EINPROGRESS, &ctx->async_wait);
2003-
if (ret) {
2004-
if (err >= 0 || err == -EINPROGRESS)
2005-
err = ret;
2006-
decrypted = 0;
2007-
goto end;
2008-
}
2009+
__skb_queue_purge(&ctx->async_hold);
2010+
2011+
if (ret) {
2012+
if (err >= 0 || err == -EINPROGRESS)
2013+
err = ret;
2014+
decrypted = 0;
2015+
goto end;
20092016
}
20102017

20112018
/* Drain records from the rx_list & copy if required */
@@ -2440,6 +2447,7 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
24402447
crypto_info = &ctx->crypto_recv.info;
24412448
cctx = &ctx->rx;
24422449
skb_queue_head_init(&sw_ctx_rx->rx_list);
2450+
skb_queue_head_init(&sw_ctx_rx->async_hold);
24432451
aead = &sw_ctx_rx->aead_recv;
24442452
}
24452453

0 commit comments

Comments
 (0)