Re: [PATCH net-next] tls: Remove redundant vars from tls record structure

2018-09-29 Thread David Miller
From: Vakul Garg 
Date: Wed, 26 Sep 2018 16:22:08 +0530

> Structure 'tls_rec' contains sg_aead_in and sg_aead_out which point
> to a aad_space and then chain scatterlists sg_plaintext_data,
> sg_encrypted_data respectively. Rather than using chained scatterlists
> for plaintext and encrypted data in aead_req, it is efficient to store
> aad_space in sg_encrypted_data and sg_plaintext_data itself in the
> first index and get rid of sg_aead_in, sg_aead_in and further chaining.
> 
> This requires increasing size of sg_encrypted_data & sg_plaintext_data
> arrarys by 1 to accommodate entry for aad_space. The code which uses
> sg_encrypted_data and sg_plaintext_data has been modified to skip first
> index as it points to aad_space.
> 
> Signed-off-by: Vakul Garg 

Applied, thanks.


[PATCH net-next] tls: Remove redundant vars from tls record structure

2018-09-26 Thread Vakul Garg
Structure 'tls_rec' contains sg_aead_in and sg_aead_out which point
to a aad_space and then chain scatterlists sg_plaintext_data,
sg_encrypted_data respectively. Rather than using chained scatterlists
for plaintext and encrypted data in aead_req, it is efficient to store
aad_space in sg_encrypted_data and sg_plaintext_data itself in the
first index and get rid of sg_aead_in, sg_aead_in and further chaining.

This requires increasing size of sg_encrypted_data & sg_plaintext_data
arrarys by 1 to accommodate entry for aad_space. The code which uses
sg_encrypted_data and sg_plaintext_data has been modified to skip first
index as it points to aad_space.

Signed-off-by: Vakul Garg 
---
 include/net/tls.h |  6 ++--
 net/tls/tls_sw.c  | 92 ++-
 2 files changed, 45 insertions(+), 53 deletions(-)

diff --git a/include/net/tls.h b/include/net/tls.h
index 1615fb5ea114..262420cdad10 100644
--- a/include/net/tls.h
+++ b/include/net/tls.h
@@ -101,13 +101,11 @@ struct tls_rec {
struct list_head list;
int tx_ready;
int tx_flags;
-   struct scatterlist sg_plaintext_data[MAX_SKB_FRAGS];
-   struct scatterlist sg_encrypted_data[MAX_SKB_FRAGS];
 
/* AAD | sg_plaintext_data | sg_tag */
-   struct scatterlist sg_aead_in[2];
+   struct scatterlist sg_plaintext_data[MAX_SKB_FRAGS + 1];
/* AAD | sg_encrypted_data (data contain overhead for hdr) */
-   struct scatterlist sg_aead_out[2];
+   struct scatterlist sg_encrypted_data[MAX_SKB_FRAGS + 1];
 
unsigned int sg_plaintext_size;
unsigned int sg_encrypted_size;
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 4c18b4dba284..8cf7bef7c5a2 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -248,7 +248,7 @@ static void trim_both_sgl(struct sock *sk, int target_size)
struct tls_sw_context_tx *ctx = tls_sw_ctx_tx(tls_ctx);
struct tls_rec *rec = ctx->open_rec;
 
-   trim_sg(sk, rec->sg_plaintext_data,
+   trim_sg(sk, >sg_plaintext_data[1],
>sg_plaintext_num_elem,
>sg_plaintext_size,
target_size);
@@ -256,7 +256,7 @@ static void trim_both_sgl(struct sock *sk, int target_size)
if (target_size > 0)
target_size += tls_ctx->tx.overhead_size;
 
-   trim_sg(sk, rec->sg_encrypted_data,
+   trim_sg(sk, >sg_encrypted_data[1],
>sg_encrypted_num_elem,
>sg_encrypted_size,
target_size);
@@ -270,12 +270,13 @@ static int alloc_encrypted_sg(struct sock *sk, int len)
int rc = 0;
 
rc = sk_alloc_sg(sk, len,
-rec->sg_encrypted_data, 0,
+>sg_encrypted_data[1], 0,
 >sg_encrypted_num_elem,
 >sg_encrypted_size, 0);
 
if (rc == -ENOSPC)
-   rec->sg_encrypted_num_elem = ARRAY_SIZE(rec->sg_encrypted_data);
+   rec->sg_encrypted_num_elem =
+   ARRAY_SIZE(rec->sg_encrypted_data) - 1;
 
return rc;
 }
@@ -287,12 +288,15 @@ static int alloc_plaintext_sg(struct sock *sk, int len)
struct tls_rec *rec = ctx->open_rec;
int rc = 0;
 
-   rc = sk_alloc_sg(sk, len, rec->sg_plaintext_data, 0,
->sg_plaintext_num_elem, >sg_plaintext_size,
+   rc = sk_alloc_sg(sk, len,
+>sg_plaintext_data[1], 0,
+>sg_plaintext_num_elem,
+>sg_plaintext_size,
 tls_ctx->pending_open_record_frags);
 
if (rc == -ENOSPC)
-   rec->sg_plaintext_num_elem = ARRAY_SIZE(rec->sg_plaintext_data);
+   rec->sg_plaintext_num_elem =
+   ARRAY_SIZE(rec->sg_plaintext_data) - 1;
 
return rc;
 }
@@ -320,11 +324,11 @@ static void tls_free_open_rec(struct sock *sk)
if (!rec)
return;
 
-   free_sg(sk, rec->sg_encrypted_data,
+   free_sg(sk, >sg_encrypted_data[1],
>sg_encrypted_num_elem,
>sg_encrypted_size);
 
-   free_sg(sk, rec->sg_plaintext_data,
+   free_sg(sk, >sg_plaintext_data[1],
>sg_plaintext_num_elem,
>sg_plaintext_size);
 
@@ -355,7 +359,7 @@ int tls_tx_records(struct sock *sk, int flags)
 * Remove the head of tx_list
 */
list_del(>list);
-   free_sg(sk, rec->sg_plaintext_data,
+   free_sg(sk, >sg_plaintext_data[1],
>sg_plaintext_num_elem, >sg_plaintext_size);
 
kfree(rec);
@@ -370,13 +374,13 @@ int tls_tx_records(struct sock *sk, int flags)
tx_flags = flags;
 
rc = tls_push_sg(sk, tls_ctx,
->sg_encrypted_data[0],
+>sg_encrypted_data[1],