Commit d4e5db64 authored by Jakub Kicinski's avatar Jakub Kicinski

tls: rx: device: keep the zero copy status with offload

The non-zero-copy path assumes a full skb with decrypted contents.
This means the device offload would have to CoW the data. Try
to keep the zero-copy status instead, copy the data to user space.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent b93f5700
...@@ -127,6 +127,7 @@ int tls_sw_fallback_init(struct sock *sk, ...@@ -127,6 +127,7 @@ int tls_sw_fallback_init(struct sock *sk,
struct tls_offload_context_tx *offload_ctx, struct tls_offload_context_tx *offload_ctx,
struct tls_crypto_info *crypto_info); struct tls_crypto_info *crypto_info);
struct sk_buff *tls_strp_msg_detach(struct tls_sw_context_rx *ctx);
int tls_strp_msg_hold(struct sock *sk, struct sk_buff *skb, int tls_strp_msg_hold(struct sock *sk, struct sk_buff *skb,
struct sk_buff_head *dst); struct sk_buff_head *dst);
......
...@@ -4,6 +4,15 @@ ...@@ -4,6 +4,15 @@
#include "tls.h" #include "tls.h"
struct sk_buff *tls_strp_msg_detach(struct tls_sw_context_rx *ctx)
{
struct sk_buff *skb;
skb = ctx->recv_pkt;
ctx->recv_pkt = NULL;
return skb;
}
int tls_strp_msg_hold(struct sock *sk, struct sk_buff *skb, int tls_strp_msg_hold(struct sock *sk, struct sk_buff *skb,
struct sk_buff_head *dst) struct sk_buff_head *dst)
{ {
......
...@@ -1631,8 +1631,8 @@ tls_decrypt_sw(struct sock *sk, struct tls_context *tls_ctx, ...@@ -1631,8 +1631,8 @@ tls_decrypt_sw(struct sock *sk, struct tls_context *tls_ctx,
} }
static int static int
tls_decrypt_device(struct sock *sk, struct tls_context *tls_ctx, tls_decrypt_device(struct sock *sk, struct msghdr *msg,
struct tls_decrypt_arg *darg) struct tls_context *tls_ctx, struct tls_decrypt_arg *darg)
{ {
struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx); struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);
struct tls_prot_info *prot = &tls_ctx->prot_info; struct tls_prot_info *prot = &tls_ctx->prot_info;
...@@ -1650,13 +1650,33 @@ tls_decrypt_device(struct sock *sk, struct tls_context *tls_ctx, ...@@ -1650,13 +1650,33 @@ tls_decrypt_device(struct sock *sk, struct tls_context *tls_ctx,
if (pad < 0) if (pad < 0)
return pad; return pad;
darg->zc = false;
darg->async = false; darg->async = false;
darg->skb = tls_strp_msg(ctx); darg->skb = tls_strp_msg(ctx);
ctx->recv_pkt = NULL; /* ->zc downgrade check, in case TLS 1.3 gets here */
darg->zc &= !(prot->version == TLS_1_3_VERSION &&
tls_msg(darg->skb)->control != TLS_RECORD_TYPE_DATA);
rxm = strp_msg(darg->skb); rxm = strp_msg(darg->skb);
rxm->full_len -= pad; rxm->full_len -= pad;
if (!darg->zc) {
/* Non-ZC case needs a real skb */
darg->skb = tls_strp_msg_detach(ctx);
if (!darg->skb)
return -ENOMEM;
} else {
unsigned int off, len;
/* In ZC case nobody cares about the output skb.
* Just copy the data here. Note the skb is not fully trimmed.
*/
off = rxm->offset + prot->prepend_size;
len = rxm->full_len - prot->overhead_size;
err = skb_copy_datagram_msg(darg->skb, off, msg, len);
if (err)
return err;
}
return 1; return 1;
} }
...@@ -1668,7 +1688,7 @@ static int tls_rx_one_record(struct sock *sk, struct msghdr *msg, ...@@ -1668,7 +1688,7 @@ static int tls_rx_one_record(struct sock *sk, struct msghdr *msg,
struct strp_msg *rxm; struct strp_msg *rxm;
int err; int err;
err = tls_decrypt_device(sk, tls_ctx, darg); err = tls_decrypt_device(sk, msg, tls_ctx, darg);
if (!err) if (!err)
err = tls_decrypt_sw(sk, tls_ctx, msg, darg); err = tls_decrypt_sw(sk, tls_ctx, msg, darg);
if (err < 0) if (err < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment