🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18786

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

#18786
From: Eric Dumazet
Date: Wed, 18 Nov 2026 22:47
64 lines
9739 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 release the driver state and drop the reference of each
  context, as before.

The contexts are on a private list with a reference held, and 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.

Compile tested only, with CONFIG_TLS_DEVICE=y.

Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
 net/tls/tls_device.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index 4cdfbb57ecff0a0ad5589fca4ab6599ab695c913..9c2f57312d14062f453d8b8e316404a3d1b20e0f 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -1349,7 +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)	{
+	list_for_each_entry(ctx, &list, list) {
 		/* Stop offloaded TX and switch to the fallback.
 		 * tls_is_skb_tx_device_offloaded will return false.
 		 */
@@ -1362,13 +1362,16 @@ 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)	{
 		/* 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: <20261118224758.1617869-1-edumazet@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366489-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366489-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next] tls: wait for a single RCU grace period in tls_device_down()
Date: Wed, 18 Nov 2026 23:47:58 +0100
Organization: Usenet Network
Message-ID: <20261118224758.1617869-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2719990"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:OPjLNmvyIWHkNtA9oRmorLaNQCM= sha256:HQJa2LTV3BFilcc23ZAl/fPCgw4wR1HCvJ0Rp2iQVPo=
	sha1:t+Z5EPdUGl4ns2/X8ET2p8o3wks= sha256:8OuEFV8PU8sb+nBVQFmbbYRlqSBFsBsBV6PeCJkihNc=
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 46E121153FB; Thu, 19 Nov 2026 01:48:21 +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 pyn2G4Nnih8f;
	Thu, 19 Nov 2026 01:48:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-366489-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 8973D1153D3; Thu, 19 Nov 2026 01:48:08 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 63CD3661AD; Wed, 18 Nov 2026 22:48:06 +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=1795042084;
	b=2j3nIJjrfjvsWHxesMOPy0B5ZZk+mWpW+Hdcp7BiX64eXiaUou8H+eQcW1io++XqgtVJ
	 k7jHx9pF6FdhZICAgvDudU/lQfGD8TFZBJjNI8afbAfV7hKeQBKgrcRbHxHCHvdFjBaks
	 xAuBDpcUwXLp2IlJtZ+CS1ljg3wA8+qx/iLJ8W1wg3hzgse3VuTN53odUOpR2kYHbvU+S
	 F5SDodSL23npXxVk9htHBjYGDONWtH61cem1t+WrTTZLwEgZYzNDWR5e4rGzuQE8hJjO2
	 pvCUoOFT1lKbiaTFXbQZzj5JZE/ZACoe9kxNfndksOJi3/GIu1f3RyEr3smaQFxMFdQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795042084;
	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=rFVSpkvPQ/mh+EGM/GLGViyhVcWsq85GoWMz9Gq5jt0=;
	b=3xaCZD9hoRniScYdSQOgNzcLo5Hji4s9oEPKpFpd0YRAdqZq1+PHhLehlIXMYJSixTjH
	 +AEilPUjlDn78BZvNsP/Xiw3wmgHdjVyJIIiJtge/wq6JoHYtP2ptCR+MJrsQ3nrUXox1
	 QI4RIFsSYNtbEPR9pgl3Y95eXjtbkT4aQVU7m+1vmtxAvooi9uLBSOz6MddAmXQr5u/0o
	 gYySobN0kXpLNvvRDa/1j17tENhoASq1t0OygBK6UKigIeGForDokYk8gpa7WSflhKORu
	 ESFCYvDi7eJFHln4gIjgOGNVCbDRLb1wuEDdZQBRmbqb8btg8SUdp3yg9Keh56MVoVA==
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=giXBFjD2;
	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 37966606A335;
	Wed, 18 Nov 2026 22:48:04 +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=giXBFjD2
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=1795042083;
	b=AH9BCtpDCoIzS1BdHxbdtARWSYsIzrF49mvWqvJv7w4aU0JkbmpXtMhc9WOR3ZxJycNx
	 rTrbU5s6eI8T+c77Yg2L1gO7mVFKgxqCFtRG4IfzEr63Yg2h6Dn3IR2k8WA2BEbc5wQJX
	 b5sZi0x0SPvrv+8FBgBh7mUjIX7L78RQhmaqJbAvVz39/WdD1XFM6S1UPdcuU5SeVvqCC
	 6tFG40SqsM7ynICAPNLOZLMhRDnL6Z8ADUsSXhNXyE9MJO4HRb72p9NeMDIL7SL1cL0Fx
	 o6AWMDX06VUny4VGbPNnNHHZQmmUFCgs/92vJ1Ut8dnYgPpvjOtxPRXqAVqLCv3ilPQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795042083;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 MIME-Version:Content-Transfer-Encoding;
	bh=rFVSpkvPQ/mh+EGM/GLGViyhVcWsq85GoWMz9Gq5jt0=;
	b=wlxHP/ZnPTNnQNOKiOwVsgMkW8k+GiMWHd0msrMBJxkG1gMEbb70AMkAiK7Rld/K+QMh
	 Pfbrrx8Dv+t5c24XVdfRg+gf8q5UnqVYnJbUO1x3khsiq+YlrS8sB+bXaSXxBfkFwkbfo
	 GxKdKY8osaJ2i3bVBVe1oMM2166dYwZb7TbvApFrtLWdnGEN6QWHUqODOO7Sd1FJ7EuGa
	 zjf/xBFsD4YwJ74bOmSshV4RoeMZk2cAoh5g4m8iSqf8Iyn6XA9yMgR87UTMiebbApJN0
	 72oNqBUr0HS6YfeZ0zrxBXRseXzRZvTcU/lUI025tEzmhQBfeBROP4UtnSB3SS+WKpw==
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=giXBFjD2;
	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 557F9606A325
	for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 22:48:03 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48AEC1F000C4;
	Wed, 18 Nov 2026 22:48:01 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795042083;
	bh=rFVSpkvPQ/mh+EGM/GLGViyhVcWsq85GoWMz9Gq5jt0=;
	h=From:To:Cc:Subject:Date;
	b=giXBFjD2eslVfejiEF2qfMZTgvsAHLpPVQa/8/p89uVfWICMfrdbWLMkpPDjX8EYF
	 kv7ISRi2tMgddp3f2428d9bvp6oLnBEoyt8vf6jMajTp4TXr8sxlGyAWU5EZ+dcX3S
	 1bBrcHXXIFqtcXma3mUqu4sbmAdwQhRyoC1bKAhx8Lxdgv/mSLWv4hlvo2oOKspQeL
	 /xhqokvkrsbE8cZIXS0VutaqwQ9XxrRmKc1zFsE1CLwW2ENeifdWcgdTqOMZkCCzK2
	 VzRM+Lx+1nTSabM+eg5cTzRsB7rpWefL/K6kFcV1+0jOQFPWBDsnsr4A2YPuCKlVu8
	 qB/rAS9vwRVNw==
X-Cc: Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org,
	Eric Dumazet <edumazet@kernel.org>
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