mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/2] net/tls: some optimizations for tls
@ 2022-03-19  3:13 Ziyang Xuan
  2022-03-19  3:14 ` [PATCH net-next v2 1/2] net/tls: remove unnecessary jump instructions in do_tls_setsockopt_conf() Ziyang Xuan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ziyang Xuan @ 2022-03-19  3:13 UTC (permalink / raw)
  To: borisp, john.fastabend, daniel, kuba, netdev; +Cc: davem, pabeni, linux-kernel

Do some small optimizations for tls, including jump instructions
optimization, and judgement processes optimization.

---
v1-v2:
  - Delete a new line before "return rc;" in patch 2.

Ziyang Xuan (2):
  net/tls: remove unnecessary jump instructions in
    do_tls_setsockopt_conf()
  net/tls: optimize judgement processes in tls_set_device_offload()

 net/tls/tls_device.c | 62 ++++++++++++++++++++++----------------------
 net/tls/tls_main.c   | 15 ++++-------
 2 files changed, 36 insertions(+), 41 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next v2 1/2] net/tls: remove unnecessary jump instructions in do_tls_setsockopt_conf()
  2022-03-19  3:13 [PATCH net-next v2 0/2] net/tls: some optimizations for tls Ziyang Xuan
@ 2022-03-19  3:14 ` Ziyang Xuan
  2022-03-19  3:15 ` [PATCH net-next v2 2/2] net/tls: optimize judgement processes in tls_set_device_offload() Ziyang Xuan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ziyang Xuan @ 2022-03-19  3:14 UTC (permalink / raw)
  To: borisp, john.fastabend, daniel, kuba, netdev; +Cc: davem, pabeni, linux-kernel

Avoid using "goto" jump instruction unconditionally when we
can return directly. Remove unnecessary jump instructions in
do_tls_setsockopt_conf().

Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
 net/tls/tls_main.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index 6bc2879ba637..7b2b0e7ffee4 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -553,10 +553,8 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
 	int rc = 0;
 	int conf;
 
-	if (sockptr_is_null(optval) || (optlen < sizeof(*crypto_info))) {
-		rc = -EINVAL;
-		goto out;
-	}
+	if (sockptr_is_null(optval) || (optlen < sizeof(*crypto_info)))
+		return -EINVAL;
 
 	if (tx) {
 		crypto_info = &ctx->crypto_send.info;
@@ -567,10 +565,8 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
 	}
 
 	/* Currently we don't support set crypto info more than one time */
-	if (TLS_CRYPTO_INFO_READY(crypto_info)) {
-		rc = -EBUSY;
-		goto out;
-	}
+	if (TLS_CRYPTO_INFO_READY(crypto_info))
+		return -EBUSY;
 
 	rc = copy_from_sockptr(crypto_info, optval, sizeof(*crypto_info));
 	if (rc) {
@@ -672,11 +668,10 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
 		ctx->sk_write_space = sk->sk_write_space;
 		sk->sk_write_space = tls_write_space;
 	}
-	goto out;
+	return 0;
 
 err_crypto_info:
 	memzero_explicit(crypto_info, sizeof(union tls_crypto_context));
-out:
 	return rc;
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next v2 2/2] net/tls: optimize judgement processes in tls_set_device_offload()
  2022-03-19  3:13 [PATCH net-next v2 0/2] net/tls: some optimizations for tls Ziyang Xuan
  2022-03-19  3:14 ` [PATCH net-next v2 1/2] net/tls: remove unnecessary jump instructions in do_tls_setsockopt_conf() Ziyang Xuan
@ 2022-03-19  3:15 ` Ziyang Xuan
  2022-03-19  4:43 ` [PATCH net-next v2 0/2] net/tls: some optimizations for tls Jakub Kicinski
  2022-03-21 23:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Ziyang Xuan @ 2022-03-19  3:15 UTC (permalink / raw)
  To: borisp, john.fastabend, daniel, kuba, netdev; +Cc: davem, pabeni, linux-kernel

It is known that priority setting HW offload when set tls TX/RX offload
by setsockopt(). Check netdevice whether support NETIF_F_HW_TLS_TX or
not at the later stages in the whole tls_set_device_offload() process,
some memory allocations have been done before that. We must release those
memory and return error if we judge the netdevice not support
NETIF_F_HW_TLS_TX. It is redundant.

Move NETIF_F_HW_TLS_TX judgement forward, and move start_marker_record
and offload_ctx memory allocation back slightly. Thus, we can get
simpler exception handling process.

Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
 net/tls/tls_device.c | 62 ++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index b932469ee69c..12f7b56771d9 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -1028,20 +1028,21 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
 	if (ctx->priv_ctx_tx)
 		return -EEXIST;
 
-	start_marker_record = kmalloc(sizeof(*start_marker_record), GFP_KERNEL);
-	if (!start_marker_record)
-		return -ENOMEM;
+	netdev = get_netdev_for_sock(sk);
+	if (!netdev) {
+		pr_err_ratelimited("%s: netdev not found\n", __func__);
+		return -EINVAL;
+	}
 
-	offload_ctx = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_TX, GFP_KERNEL);
-	if (!offload_ctx) {
-		rc = -ENOMEM;
-		goto free_marker_record;
+	if (!(netdev->features & NETIF_F_HW_TLS_TX)) {
+		rc = -EOPNOTSUPP;
+		goto release_netdev;
 	}
 
 	crypto_info = &ctx->crypto_send.info;
 	if (crypto_info->version != TLS_1_2_VERSION) {
 		rc = -EOPNOTSUPP;
-		goto free_offload_ctx;
+		goto release_netdev;
 	}
 
 	switch (crypto_info->cipher_type) {
@@ -1057,13 +1058,13 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
 		break;
 	default:
 		rc = -EINVAL;
-		goto free_offload_ctx;
+		goto release_netdev;
 	}
 
 	/* Sanity-check the rec_seq_size for stack allocations */
 	if (rec_seq_size > TLS_MAX_REC_SEQ_SIZE) {
 		rc = -EINVAL;
-		goto free_offload_ctx;
+		goto release_netdev;
 	}
 
 	prot->version = crypto_info->version;
@@ -1077,7 +1078,7 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
 			     GFP_KERNEL);
 	if (!ctx->tx.iv) {
 		rc = -ENOMEM;
-		goto free_offload_ctx;
+		goto release_netdev;
 	}
 
 	memcpy(ctx->tx.iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, iv, iv_size);
@@ -1089,9 +1090,21 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
 		goto free_iv;
 	}
 
+	start_marker_record = kmalloc(sizeof(*start_marker_record), GFP_KERNEL);
+	if (!start_marker_record) {
+		rc = -ENOMEM;
+		goto free_rec_seq;
+	}
+
+	offload_ctx = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_TX, GFP_KERNEL);
+	if (!offload_ctx) {
+		rc = -ENOMEM;
+		goto free_marker_record;
+	}
+
 	rc = tls_sw_fallback_init(sk, offload_ctx, crypto_info);
 	if (rc)
-		goto free_rec_seq;
+		goto free_offload_ctx;
 
 	/* start at rec_seq - 1 to account for the start marker record */
 	memcpy(&rcd_sn, ctx->tx.rec_seq, sizeof(rcd_sn));
@@ -1118,18 +1131,6 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
 	if (skb)
 		TCP_SKB_CB(skb)->eor = 1;
 
-	netdev = get_netdev_for_sock(sk);
-	if (!netdev) {
-		pr_err_ratelimited("%s: netdev not found\n", __func__);
-		rc = -EINVAL;
-		goto disable_cad;
-	}
-
-	if (!(netdev->features & NETIF_F_HW_TLS_TX)) {
-		rc = -EOPNOTSUPP;
-		goto release_netdev;
-	}
-
 	/* Avoid offloading if the device is down
 	 * We don't want to offload new flows after
 	 * the NETDEV_DOWN event
@@ -1167,20 +1168,19 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
 
 release_lock:
 	up_read(&device_offload_lock);
-release_netdev:
-	dev_put(netdev);
-disable_cad:
 	clean_acked_data_disable(inet_csk(sk));
 	crypto_free_aead(offload_ctx->aead_send);
-free_rec_seq:
-	kfree(ctx->tx.rec_seq);
-free_iv:
-	kfree(ctx->tx.iv);
 free_offload_ctx:
 	kfree(offload_ctx);
 	ctx->priv_ctx_tx = NULL;
 free_marker_record:
 	kfree(start_marker_record);
+free_rec_seq:
+	kfree(ctx->tx.rec_seq);
+free_iv:
+	kfree(ctx->tx.iv);
+release_netdev:
+	dev_put(netdev);
 	return rc;
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2 0/2] net/tls: some optimizations for tls
  2022-03-19  3:13 [PATCH net-next v2 0/2] net/tls: some optimizations for tls Ziyang Xuan
  2022-03-19  3:14 ` [PATCH net-next v2 1/2] net/tls: remove unnecessary jump instructions in do_tls_setsockopt_conf() Ziyang Xuan
  2022-03-19  3:15 ` [PATCH net-next v2 2/2] net/tls: optimize judgement processes in tls_set_device_offload() Ziyang Xuan
@ 2022-03-19  4:43 ` Jakub Kicinski
  2022-03-21 23:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2022-03-19  4:43 UTC (permalink / raw)
  To: Ziyang Xuan
  Cc: borisp, john.fastabend, daniel, netdev, davem, pabeni, linux-kernel

On Sat, 19 Mar 2022 11:13:34 +0800 Ziyang Xuan wrote:
> Do some small optimizations for tls, including jump instructions
> optimization, and judgement processes optimization.

Acked-by: Jakub Kicinski <kuba@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2 0/2] net/tls: some optimizations for tls
  2022-03-19  3:13 [PATCH net-next v2 0/2] net/tls: some optimizations for tls Ziyang Xuan
                   ` (2 preceding siblings ...)
  2022-03-19  4:43 ` [PATCH net-next v2 0/2] net/tls: some optimizations for tls Jakub Kicinski
@ 2022-03-21 23:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-21 23:00 UTC (permalink / raw)
  To: Ziyang Xuan
  Cc: borisp, john.fastabend, daniel, kuba, netdev, davem, pabeni,
	linux-kernel

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Sat, 19 Mar 2022 11:13:34 +0800 you wrote:
> Do some small optimizations for tls, including jump instructions
> optimization, and judgement processes optimization.
> 
> ---
> v1-v2:
>   - Delete a new line before "return rc;" in patch 2.
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/2] net/tls: remove unnecessary jump instructions in do_tls_setsockopt_conf()
    https://git.kernel.org/netdev/net-next/c/1ddcbfbf9dc9
  - [net-next,v2,2/2] net/tls: optimize judgement processes in tls_set_device_offload()
    https://git.kernel.org/netdev/net-next/c/b1a6f56b6506

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-21 23:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-19  3:13 [PATCH net-next v2 0/2] net/tls: some optimizations for tls Ziyang Xuan
2022-03-19  3:14 ` [PATCH net-next v2 1/2] net/tls: remove unnecessary jump instructions in do_tls_setsockopt_conf() Ziyang Xuan
2022-03-19  3:15 ` [PATCH net-next v2 2/2] net/tls: optimize judgement processes in tls_set_device_offload() Ziyang Xuan
2022-03-19  4:43 ` [PATCH net-next v2 0/2] net/tls: some optimizations for tls Jakub Kicinski
2022-03-21 23:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®