Skip to contentSkip to conversation

tcp: tcp_gro_dev_warn() cleanup

PATCH Applied Eric Dumazet 2 participants 2 messages Nov 30, 2023 – Dec 2, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: tcp_gro_dev_warn() cleanup

Use DO_ONCE_LITE_IF() and __cold attribute to put tcp_gro_dev_warn() out of line.

This also allows the message to be printed again after a "echo 1 > /sys/kernel/debug/clear_warn_once"

Also add a READ_ONCE() when reading device mtu, as it could be changed concurrently.

---
 net/ipv4/tcp_input.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
net/ipv4/tcp_input.c +10 -17
index bcb55d98004c5213f0095613124d5193b15b2793..cd57c2552ac7d5ed799f06e2241691c36da5022e 100644
@@ -202,23 +202,17 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,
 }
 #endif
 
-static void tcp_gro_dev_warn(struct sock *sk, const struct sk_buff *skb,
+static __cold void tcp_gro_dev_warn(const struct sock *sk, const struct sk_buff *skb,
 			     unsigned int len)
 {
-	static bool __once __read_mostly;
+	struct net_device *dev;
 
-	if (!__once) {
-		struct net_device *dev;
-
-		__once = true;
-
-		rcu_read_lock();
-		dev = dev_get_by_index_rcu(sock_net(sk), skb->skb_iif);
-		if (!dev || len >= dev->mtu)
-			pr_warn("%s: Driver has suspect GRO implementation, TCP performance may be compromised.\n",
-				dev ? dev->name : "Unknown driver");
-		rcu_read_unlock();
-	}
+	rcu_read_lock();
+	dev = dev_get_by_index_rcu(sock_net(sk), skb->skb_iif);
+	if (!dev || len >= READ_ONCE(dev->mtu))
+		pr_warn("%s: Driver has suspect GRO implementation, TCP performance may be compromised.\n",
+			dev ? dev->name : "Unknown driver");
+	rcu_read_unlock();
 }
 
 /* Adapt the MSS value used to make delayed ack decision to the
@@ -250,9 +244,8 @@ static void tcp_measure_rcv_mss(struct sock *sk, const struct sk_buff *skb)
 		icsk->icsk_ack.rcv_mss = min_t(unsigned int, len,
 					       tcp_sk(sk)->advmss);
 		/* Account for possibly-removed options */
-		if (unlikely(len > icsk->icsk_ack.rcv_mss +
-				   MAX_TCP_OPTION_SPACE))
-			tcp_gro_dev_warn(sk, skb, len);
+		DO_ONCE_LITE_IF(len > icsk->icsk_ack.rcv_mss + MAX_TCP_OPTION_SPACE,
+				tcp_gro_dev_warn, sk, skb, len);
 		/* If the skb has a len of exactly 1*MSS and has the PSH bit
 		 * set then it is likely the end of an application write. So
 		 * more data may not be arriving soon, and yet the data sender
Signature · 1 line
2.43.0.rc1.413.gea7ed67945-goog
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Thu, 30 Nov 2023 18:41:35 +0000 you wrote:

Use DO_ONCE_LITE_IF() and __cold attribute to put tcp_gro_dev_warn() out of line.

This also allows the message to be printed again after a "echo 1 > /sys/kernel/debug/clear_warn_once"

Also add a READ_ONCE() when reading device mtu, as it could be changed concurrently.

[...]

Here is the summary with links:
- [net-next] tcp: tcp_gro_dev_warn() cleanup

    https://git.kernel.org/netdev/net-next/c/b32e8fbeace6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html