Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next] tls: wait for a single RCU grace period in tls_device_down()
@ 2026-11-18 22:47 Eric Dumazet
  0 siblings, 0 replies; only message in thread
From: Eric Dumazet @ 2026-11-18 22:47 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni, Willem de Bruijn
  Cc: Simon Horman, netdev, Eric Dumazet

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-18 22:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 22:47 [PATCH net-next] tls: wait for a single RCU grace period in tls_device_down() Eric Dumazet

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