🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20847

[PATCH v2 net-next] tls: wait for a single RCU grace period in tls_device_down()

#20847
From: Eric Dumazet
Date: Mon, 23 Nov 2026 09:28
92 lines
11002 bytes
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
Technical Details
Message-ID: <20261123092851.137140-1-edumazet@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369185-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369185-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <20261123092851.137140-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3837971"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:CFd6EWwHl/5zGDmICigXtSGpM9c= sha256:4ec1/c9voDIjrYK+PxIBQ/ZORN+dlXcz6e5v4PVrp/I=
	sha1:ZDh2TIx/cZCF9FfShS2YkJaPFTk= sha256:+YAG2RKAR1kbRGiZq+PKlDywaWOqOFI84z95Hoix5KM=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 80F5D125D96; Mon, 23 Nov 2026 12:29:12 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id doYgE3vfRZWG;
	Mon, 23 Nov 2026 12:29:09 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369185-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id B098F125D95; Mon, 23 Nov 2026 12:29:00 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 56BE4284F8; Mon, 23 Nov 2026 09:28:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795426138;
	b=R/g1FU7/40CxkTEwtfhqKOR48ddfdbkO6uV61bjjU9Cjjm+0ULc0OHyXkNRJCXN3z6nl
	 pAGGsr4RSkW+nbJcy5qa28NmBpxvPxhuB6QLkFWRWPq4frI1yXT7AHHhRnOaVRGu2ZeM6
	 yksUGtMxV1/6nL06G6dh5wl8abfEYVw8g2Rk6aKmuBPQHAM1O1Q/OzzSW2CldY97/S8su
	 ZPE3MP8ZsvT847EY9Pxc8QTxssXug74ZZNe8UODwjsXajJoPsDXZ8kvi7ezWxC8D+WNfT
	 dJ2UnTtKBCwAapzU2BDJ7Sg3amE+REMDjGn8Ovz9cfXnpZlV5A/N2uL9uC5QyIeI8fA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795426138;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=XQ3s/upW/7ozz8AHusZ3fvLJjMDzHSWHY2rf94ibYuc=;
	b=FR1lBWqtac9thLGHZbqLWLjrRfj/ZLmFMTyARcrhFIYK6V1c2QLViZUVdIl7C3tYzKLS
	 QRjkwm/d1V0DdwQAsb5c5mBAUxNRd3aW45fkVYAb6ArrgJ8386ZeS4meO4U+1G4qsV04s
	 vkIFSAZbpPwoJKYsNL8xLAklD3CgHZPmIPRS+cvgm9zhscdiAtuMuGzYafF79i6S9QXWW
	 u1Xp/Bsoyaeg9ruCc85FYZORia/J0TEd1201MT2PmKssWg2EYTQFimlZOjuiUPq/iv9Zj
	 gQwKAkez3ICjrMZeHxO5N5QYwEWQs4H5K4SV2jYxwsrfoSPtqRcKwuLklZDKDu0yfdQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aWb0+3IF;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id E1150606A32E;
	Mon, 23 Nov 2026 09:28:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aWb0+3IF
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795426137;
	b=XUvlwGKGqQGJolUy9lbrtnPcrNreG3wACmPtJlJ4ABqxnJTPHM8qiFSdgdMxPLSidZgY
	 BKKPlKzCUgiEeWfmNf6BTOU/9nGT9O08sr7YwJlKdxt0bg9VzLg3mQdKrwfMG0hNjPvOy
	 MvwFQu2xJxzU6YqCF0hQ88gQVovigspI6yi3OXSPJ2ktmOWzHG8VfcW/LWUohFVRM3ShT
	 IXNLEOZHpbfIDzxkP24bxe3mjP/pZ8dy1H2II8tjUCPfZzsKBhggc3twfWJrAPtJClgRD
	 hFbbrznFKNrudmlHdMzqGmMf6sVOWDBdeyt8+cMJ/WKVBnO9ZJfC7y3GQWQc3vXjbDg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795426137;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 MIME-Version:Content-Transfer-Encoding;
	bh=XQ3s/upW/7ozz8AHusZ3fvLJjMDzHSWHY2rf94ibYuc=;
	b=aCoOFyUPpZn6RjghK8CJ3acMxbvyd/+sE/ztb63hHoGA6jnvadY/K/eMv7yVqjfqWwYf
	 7pZxWhftFQw0DnJq0OPHY3pInHgRkVpQl+G3p5TTRVZ5XgENL4cr3CgDgW9EGd6XFDB15
	 M2zdhW/eJ4yAFUMmIwP62FLNXBLG5C/1wMi+yRDC7q/V9T4lqScmMZZxff0gtgLq0RYv9
	 Nr3SiO8r44P6menOwpool/f+ALKnT7zr0SE1CMwlRntVDTalkPwyCECPZptt85X3s1/3U
	 E8+MH/TmruCx//jJDL8pt/+Q5PaisVMV0bmcYXVoNOlBhSAC7RBBu7KUwE6/991WGcg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aWb0+3IF;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 091EF606A31E
	for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 09:28:56 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C3F61F000E1;
	Mon, 23 Nov 2026 09:28:54 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795426136;
	bh=XQ3s/upW/7ozz8AHusZ3fvLJjMDzHSWHY2rf94ibYuc=;
	h=From:To:Cc:Subject:Date;
	b=aWb0+3IFiV7ax9eBEZa8bJnaClDt7LVeCvcwt7liBITNZVcjzmfZHeAornkRAwY7L
	 UN/iR4XDQzFr/OMZRzpLFq6o+/5AFk9P2rE1E2pcMPU9mdVyUoyYFgxeWFY0VSjtT7
	 81hqeunAKYWLYJUAVI6th8PahAsctPZqiLJQdXuCoIh5pkOPEk01si4QwBjee9XRZz
	 EeRoRb5lGCpYt9KbQTLjIwARQerlsPFUGq/5R2qhNnxJ07plONpG9KaqczTPXOl/r0
	 SDazr53wJ9l2cdBxfWZGATBrzfy6QGl9zSHZu55N9Iu5hEmN4mVdgJHZ9/+kPhlAWx
	 w6FwSysYQHNWg==
X-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>
X-Mailer: git-send-email 2.53.0
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list