Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@kernel.org>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>,
	Jiayuan Chen <jiayuan.chen@linux.dev>
Subject: [PATCH v2 net-next] tls: wait for a single RCU grace period in tls_device_down()
Date: Mon, 23 Nov 2026 10:28:51 +0100	[thread overview]
Message-ID: <20261123092851.137140-1-edumazet@kernel.org> (raw)

tls_device_down() calls synchronize_net() for each offloaded context
bound to the device going down. As this runs from the NETDEV_DOWN
notifier, a device with N offloaded sockets waits for N RCU grace
periods while RTNL is held.

Split the loop:

- First stop the offload for all contexts: switch to the software
  fallback, clear ctx->netdev and set TLS_RX_DEV_DEGRADED.

- Then call synchronize_net() once, if there is at least one context.

- Finally, for each context, release the driver state, then move the
  context to tls_device_down_list and drop the reference taken by
  tls_device_down() under tls_device_lock. This part is unchanged.

Between the first and the last step, the contexts sit on a private
list with a reference held. If sk_destruct runs in that window,
tls_device_queue_ctx_destruction() only drops its reference and
returns without touching ctx->list, so the private list can be walked
twice without holding tls_device_lock. The final removal stays
serialized by tls_device_lock in the last step.

The first step only writes to fields of each context. The only change
in behavior is that all contexts stop being offloaded before the
driver state of the first one is released.

Jiayuan Chen tested v1 with the netdevsim TLS offload emulation,
with N sockets having TX and RX offloaded on one port, measuring
"ip link set down" on that port:

sockets    before     after
    100   12.7 ms    8.6 ms
   1000   39.1 ms   11.5 ms
   5000  160.8 ms   19.2 ms
  20000  577.2 ms   44.1 ms

v2 is compile tested only, with CONFIG_TLS_DEVICE=y.

Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
v2: rebase on top of commit 81c8333141b9 ("net/tls: serialize context
    removal in tls_device_down()") which came via net (Jakub).
    Move the free_ctx declaration to the second loop, and expand the
    changelog about the private list.
v1: https://lore.kernel.org/netdev/20261118224758.1617869-1-edumazet@kernel.org/
---
 net/tls/tls_device.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index fa7170cd4fd10f6298ac031ffa824814e592d736..a90ecfce597d23588d3c568ebd6221633531575b 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -1349,9 +1349,7 @@ static int tls_device_down(struct net_device *netdev)
 	}
 	spin_unlock_irqrestore(&tls_device_lock, flags);
 
-	list_for_each_entry_safe(ctx, tmp, &list, list)	{
-		bool free_ctx;
-
+	list_for_each_entry(ctx, &list, list) {
 		/* Stop offloaded TX and switch to the fallback.
 		 * tls_is_skb_tx_device_offloaded will return false.
 		 */
@@ -1364,13 +1362,18 @@ static int tls_device_down(struct net_device *netdev)
 
 		/* Start skipping the RX resync logic completely. */
 		set_bit(TLS_RX_DEV_DEGRADED, &ctx->flags);
+	}
 
-		/* Sync with inflight packets. After this point:
-		 * TX: no non-encrypted packets will be passed to the driver.
-		 * RX: resync requests from the driver will be ignored.
-		 */
+	/* Sync with inflight packets, once for all contexts. After this point:
+	 * TX: no non-encrypted packets will be passed to the driver.
+	 * RX: resync requests from the driver will be ignored.
+	 */
+	if (!list_empty(&list))
 		synchronize_net();
 
+	list_for_each_entry_safe(ctx, tmp, &list, list)	{
+		bool free_ctx;
+
 		/* Release the offload context on the driver side. */
 		if (ctx->tx_conf == TLS_HW)
 			netdev->tlsdev_ops->tls_dev_del(netdev, ctx,
-- 
2.53.0


                 reply	other threads:[~2026-11-23  9:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261123092851.137140-1-edumazet@kernel.org \
    --to=edumazet@kernel.org \
    --cc=davem@davemloft.net \
    --cc=horms@kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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