Skip to contentSkip to conversation

tcp: add tcp_warn_once() common helper

PATCH Superseded Jason Xing 3 participants 8 messages Oct 21, 2024 – Oct 22, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jason Xing

author
#0 lore raw

v2 cover tcp: add tcp_warn_once() common helper

From: Jason Xing <[email protected]>

Paolo Abeni suggested we can introduce a new helper to cover more cases in the future for better debug.

Jason Xing (2):
tcp: add a common helper to debug the underlying issue
tcp: add more warn of socket in tcp_send_loss_probe()

 include/net/tcp.h     | 27 ++++++++++++++++-----------
 net/ipv4/tcp_output.c |  4 +---
 2 files changed, 17 insertions(+), 14 deletions(-)
Signature · 1 line
2.37.3
author
#1 lore raw

PATCH v2 1/2 tcp: add a common helper to debug the underlying issue

From: Jason Xing <[email protected]>

Following the commit c8770db2d544 ("tcp: check skb is non-NULL in tcp_rto_delta_us()"), we decided to add a helper so that it's easier to get verbose warning on either cases.

---
v2

1. fix "break quoted strings at a space character" warning (David Ahern)

---
 include/net/tcp.h | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
include/net/tcp.h +14 -11
index 739a9fb83d0c..8b8d94bb1746 100644
@@ -2430,6 +2430,19 @@ void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
 void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb);
 void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
 
+static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
+{
+	WARN_ONCE(cond,
+		  "%sout:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u advmss:%u mss_cache:%u pmtu:%u\n",
+		  str,
+		  tcp_sk(sk)->packets_out, tcp_sk(sk)->sacked_out,
+		  tcp_sk(sk)->lost_out, tcp_sk(sk)->retrans_out,
+		  tcp_sk(sk)->tlp_high_seq, sk->sk_state,
+		  inet_csk(sk)->icsk_ca_state,
+		  tcp_sk(sk)->advmss, tcp_sk(sk)->mss_cache,
+		  inet_csk(sk)->icsk_pmtu_cookie);
+}
+
 /* At how many usecs into the future should the RTO fire? */
 static inline s64 tcp_rto_delta_us(const struct sock *sk)
 {
@@ -2441,17 +2454,7 @@ static inline s64 tcp_rto_delta_us(const struct sock *sk)
 
 		return rto_time_stamp_us - tcp_sk(sk)->tcp_mstamp;
 	} else {
-		WARN_ONCE(1,
-			"rtx queue empty: "
-			"out:%u sacked:%u lost:%u retrans:%u "
-			"tlp_high_seq:%u sk_state:%u ca_state:%u "
-			"advmss:%u mss_cache:%u pmtu:%u\n",
-			tcp_sk(sk)->packets_out, tcp_sk(sk)->sacked_out,
-			tcp_sk(sk)->lost_out, tcp_sk(sk)->retrans_out,
-			tcp_sk(sk)->tlp_high_seq, sk->sk_state,
-			inet_csk(sk)->icsk_ca_state,
-			tcp_sk(sk)->advmss, tcp_sk(sk)->mss_cache,
-			inet_csk(sk)->icsk_pmtu_cookie);
+		tcp_warn_once(sk, 1, "rtx queue empty: ");
 		return jiffies_to_usecs(rto);
 	}
 
Signature · 1 line
2.37.3
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH net-next v2 1/2] tcp: add a common helper to debug the underlying issue

Quoted 10 lines · Jason Xing

From: Jason Xing <[email protected]>

Following the commit c8770db2d544 ("tcp: check skb is non-NULL in tcp_rto_delta_us()"), we decided to add a helper so that it's easier to get verbose warning on either cases.

Quoted 8 lines

---
v2

1. fix "break quoted strings at a space character" warning (David Ahern)

---
 include/net/tcp.h | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
author
#3 lore raw

PATCH v2 2/2 tcp: add more warn of socket in tcp_send_loss_probe()

In reply to Jason Xing

From: Jason Xing <[email protected]>

Add two fields to print in the helper which here covers tcp_send_loss_probe().

--
v2

1. use "" instead of NULL in tcp_send_loss_probe()

---
 include/net/tcp.h     | 4 +++-
 net/ipv4/tcp_output.c | 4 +---
 2 files changed, 4 insertions(+), 4 deletions(-)
include/net/tcp.h +3 -1
index 8b8d94bb1746..78158169e944 100644
@@ -2433,12 +2433,14 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
 static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
 {
 	WARN_ONCE(cond,
-		  "%sout:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u advmss:%u mss_cache:%u pmtu:%u\n",
+		  "%scwn:%u out:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u mss:%u advmss:%u mss_cache:%u pmtu:%u\n",
 		  str,
+		  tcp_snd_cwnd(tcp_sk(sk)),
 		  tcp_sk(sk)->packets_out, tcp_sk(sk)->sacked_out,
 		  tcp_sk(sk)->lost_out, tcp_sk(sk)->retrans_out,
 		  tcp_sk(sk)->tlp_high_seq, sk->sk_state,
 		  inet_csk(sk)->icsk_ca_state,
+		  tcp_current_mss((struct sock *)sk),
 		  tcp_sk(sk)->advmss, tcp_sk(sk)->mss_cache,
 		  inet_csk(sk)->icsk_pmtu_cookie);
 }
net/ipv4/tcp_output.c +1 -3
index 054244ce5117..36562b5fe290 100644
@@ -2954,9 +2954,7 @@ void tcp_send_loss_probe(struct sock *sk)
 	}
 	skb = skb_rb_last(&sk->tcp_rtx_queue);
 	if (unlikely(!skb)) {
-		WARN_ONCE(tp->packets_out,
-			  "invalid inflight: %u state %u cwnd %u mss %d\n",
-			  tp->packets_out, sk->sk_state, tcp_snd_cwnd(tp), mss);
+		tcp_warn_once(sk, tp->packets_out, "");
 		smp_store_release(&inet_csk(sk)->icsk_pending, 0);
 		return;
 	}
Signature · 1 line
2.37.3
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH net-next v2 2/2] tcp: add more warn of socket in tcp_send_loss_probe()

Quoted 42 lines · Jason Xing

From: Jason Xing <[email protected]>

Add two fields to print in the helper which here covers tcp_send_loss_probe().

--
v2

1. use "" instead of NULL in tcp_send_loss_probe()

---
 include/net/tcp.h     | 4 +++-
 net/ipv4/tcp_output.c | 4 +---
 2 files changed, 4 insertions(+), 4 deletions(-)
include/net/tcp.h +3 -1
index 8b8d94bb1746..78158169e944 100644
@@ -2433,12 +2433,14 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
 static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
 {
 	WARN_ONCE(cond,
-		  "%sout:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u advmss:%u mss_cache:%u pmtu:%u\n",
+		  "%scwn:%u out:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u mss:%u advmss:%u mss_cache:%u pmtu:%u\n",
 		  str,
+		  tcp_snd_cwnd(tcp_sk(sk)),
 		  tcp_sk(sk)->packets_out, tcp_sk(sk)->sacked_out,
 		  tcp_sk(sk)->lost_out, tcp_sk(sk)->retrans_out,
 		  tcp_sk(sk)->tlp_high_seq, sk->sk_state,
 		  inet_csk(sk)->icsk_ca_state,
+		  tcp_current_mss((struct sock *)sk),
 		  tcp_sk(sk)->advmss, tcp_sk(sk)->mss_cache,
 		  inet_csk(sk)->icsk_pmtu_cookie);
 }
net/ipv4/tcp_output.c +0 -0
index 054244ce5117..36562b5fe290 100644

net/ipv4/tcp_output.c void tcp_send_loss_probe(struct sock *sk) · line 2957

Quoted 7 lines
net/ipv4/tcp_output.c +1 -3
@@ -2954,9 +2954,7 @@ void tcp_send_loss_probe(struct sock *sk)
 	}
 	skb = skb_rb_last(&sk->tcp_rtx_queue);
 	if (unlikely(!skb)) {
-		WARN_ONCE(tp->packets_out,
-			  "invalid inflight: %u state %u cwnd %u mss %d\n",
-			  tp->packets_out, sk->sk_state, tcp_snd_cwnd(tp), mss);
+		tcp_warn_once(sk, tp->packets_out, "");

you dropped the "invalid inflight: " string for context.

net/ipv4/tcp_output.c void tcp_send_loss_probe(struct sock *sk) · line 2960

Quoted 3 lines
net/ipv4/tcp_output.c +0 -0
 		smp_store_release(&inet_csk(sk)->icsk_pending, 0);
 		return;
 	}

Besides the nit:

author
#5 lore raw

Re: [PATCH net-next v2 2/2] tcp: add more warn of socket in tcp_send_loss_probe()

Quoted 45 lines · David Ahern
Quoted 43 lines · Jason Xing

From: Jason Xing <[email protected]>

Add two fields to print in the helper which here covers tcp_send_loss_probe().

--
v2

1. use "" instead of NULL in tcp_send_loss_probe()

---
 include/net/tcp.h     | 4 +++-
 net/ipv4/tcp_output.c | 4 +---
 2 files changed, 4 insertions(+), 4 deletions(-)
include/net/tcp.h +3 -1
index 8b8d94bb1746..78158169e944 100644
@@ -2433,12 +2433,14 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
 static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
 {
      WARN_ONCE(cond,
-               "%sout:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u advmss:%u mss_cache:%u pmtu:%u\n",
+               "%scwn:%u out:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u mss:%u advmss:%u mss_cache:%u pmtu:%u\n",
                str,
+               tcp_snd_cwnd(tcp_sk(sk)),
                tcp_sk(sk)->packets_out, tcp_sk(sk)->sacked_out,
                tcp_sk(sk)->lost_out, tcp_sk(sk)->retrans_out,
                tcp_sk(sk)->tlp_high_seq, sk->sk_state,
                inet_csk(sk)->icsk_ca_state,
+               tcp_current_mss((struct sock *)sk),
                tcp_sk(sk)->advmss, tcp_sk(sk)->mss_cache,
                inet_csk(sk)->icsk_pmtu_cookie);
 }
net/ipv4/tcp_output.c +0 -0
index 054244ce5117..36562b5fe290 100644
@@ -2954,9 +2954,7 @@ void tcp_send_loss_probe(struct sock *sk)
      }
Quoted 8 lines

net/ipv4/tcp_output.c void tcp_send_loss_probe(struct sock *sk) · line 2957

Quoted 6 lines
net/ipv4/tcp_output.c +1 -3
      skb = skb_rb_last(&sk->tcp_rtx_queue);
      if (unlikely(!skb)) {
-             WARN_ONCE(tp->packets_out,
-                       "invalid inflight: %u state %u cwnd %u mss %d\n",
-                       tp->packets_out, sk->sk_state, tcp_snd_cwnd(tp), mss);
+             tcp_warn_once(sk, tp->packets_out, "");

you dropped the "invalid inflight: " string for context.

Well, sorry, let me add it back.

Quoted 7 lines

net/ipv4/tcp_output.c void tcp_send_loss_probe(struct sock *sk) · line 2960

Quoted 4 lines
net/ipv4/tcp_output.c +0 -0
              smp_store_release(&inet_csk(sk)->icsk_pending, 0);
              return;
      }

Besides the nit:

Thanks.

#6 lore raw

Re: [PATCH net-next v2 2/2] tcp: add more warn of socket in tcp_send_loss_probe()

In reply to Jason Xing
Quoted 25 lines · Jason Xing

From: Jason Xing <[email protected]>

Add two fields to print in the helper which here covers tcp_send_loss_probe().

--
v2

1. use "" instead of NULL in tcp_send_loss_probe()

---
 include/net/tcp.h     | 4 +++-
 net/ipv4/tcp_output.c | 4 +---
 2 files changed, 4 insertions(+), 4 deletions(-)
include/net/tcp.h +0 -0
index 8b8d94bb1746..78158169e944 100644
@@ -2433,12 +2433,14 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
 static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
 {

include/net/tcp.h void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb); · line 2443

Quoted 10 lines
include/net/tcp.h +3 -1
        WARN_ONCE(cond,
-                 "%sout:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u advmss:%u mss_cache:%u pmtu:%u\n",
+                 "%scwn:%u out:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u mss:%u advmss:%u mss_cache:%u pmtu:%u\n",
                  str,
+                 tcp_snd_cwnd(tcp_sk(sk)),
                  tcp_sk(sk)->packets_out, tcp_sk(sk)->sacked_out,
                  tcp_sk(sk)->lost_out, tcp_sk(sk)->retrans_out,
                  tcp_sk(sk)->tlp_high_seq, sk->sk_state,
                  inet_csk(sk)->icsk_ca_state,
+                 tcp_current_mss((struct sock *)sk),

You can not promote to non const, because tcp_current_mss() might change socket state.

If a debug helper changes the socket state, then it is no longer a debug helper.

include/net/tcp.h void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb); · line 2444

Quoted 1 line
include/net/tcp.h +0 -0
                  tcp_sk(sk)->advmss, tcp_sk(sk)->mss_cache,

This was already reported btw.

Quoted 20 lines
include/net/tcp.h +0 -0
                  inet_csk(sk)->icsk_pmtu_cookie);
 }
net/ipv4/tcp_output.c +1 -4
index 054244ce5117..36562b5fe290 100644
@@ -2954,9 +2954,7 @@ void tcp_send_loss_probe(struct sock *sk)
        }
        skb = skb_rb_last(&sk->tcp_rtx_queue);
        if (unlikely(!skb)) {
-               WARN_ONCE(tp->packets_out,
-                         "invalid inflight: %u state %u cwnd %u mss %d\n",
-                         tp->packets_out, sk->sk_state, tcp_snd_cwnd(tp), mss);
+               tcp_warn_once(sk, tp->packets_out, "");
                smp_store_release(&inet_csk(sk)->icsk_pending, 0);
                return;
        }
--

2.37.3

author
#7 lore raw

Re: [PATCH net-next v2 2/2] tcp: add more warn of socket in tcp_send_loss_probe()

Quoted 41 lines · Eric Dumazet
Quoted 25 lines · Jason Xing

From: Jason Xing <[email protected]>

Add two fields to print in the helper which here covers tcp_send_loss_probe().

--
v2

1. use "" instead of NULL in tcp_send_loss_probe()

---
 include/net/tcp.h     | 4 +++-
 net/ipv4/tcp_output.c | 4 +---
 2 files changed, 4 insertions(+), 4 deletions(-)
include/net/tcp.h +0 -0
index 8b8d94bb1746..78158169e944 100644
@@ -2433,12 +2433,14 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
 static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
 {

include/net/tcp.h void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb); · line 2443

Quoted 10 lines
include/net/tcp.h +3 -1
        WARN_ONCE(cond,
-                 "%sout:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u advmss:%u mss_cache:%u pmtu:%u\n",
+                 "%scwn:%u out:%u sacked:%u lost:%u retrans:%u tlp_high_seq:%u sk_state:%u ca_state:%u mss:%u advmss:%u mss_cache:%u pmtu:%u\n",
                  str,
+                 tcp_snd_cwnd(tcp_sk(sk)),
                  tcp_sk(sk)->packets_out, tcp_sk(sk)->sacked_out,
                  tcp_sk(sk)->lost_out, tcp_sk(sk)->retrans_out,
                  tcp_sk(sk)->tlp_high_seq, sk->sk_state,
                  inet_csk(sk)->icsk_ca_state,
+                 tcp_current_mss((struct sock *)sk),

You can not promote to non const, because tcp_current_mss() might change socket state.

Quoted 1 line

If a debug helper changes the socket state, then it is no longer a debug helper.

It does make sense. Thanks.

Quoted 4 lines

include/net/tcp.h void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb); · line 2444

Quoted 2 lines
include/net/tcp.h +0 -0
                  tcp_sk(sk)->advmss, tcp_sk(sk)->mss_cache,

This was already reported btw.

So I'm going to remove this tcp_current_mss() line.

Thanks,
Jason