From patchwork Sun Apr 21 04:20:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philo Lu X-Patchwork-Id: 13637300 X-Patchwork-Delegate: kuba@kernel.org Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF886205E23; Sun, 21 Apr 2024 04:20:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713673227; cv=none; b=BTd58dghYxu20176OLuak+LC1y15JnPfIZFIUzNWazmKOFlTiZ6WvCOqli4SbiKm9lAjV2ay5JzyNp3tXYzwrsK4/Kyld/p9531ecnxMweXrJWxVWp9MKZwpYsi3PsOZ/kCRVretA9lX5lw57VnRGlNSJd7RBcRQeL4G3KGGRK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713673227; c=relaxed/simple; bh=3CuUe7uL9ymJj/BWja4ZjPVrQ7ZUNi22OJqiT5hei3U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IBPteLTMutBZVTFFvnVcIWGewvxs5WJP3JwpwZC/WCH2cQ/qh6Pr/YwBWU5C5LggPdx5ULNCwsIvi6Xmk1Y+iJUO+xGTi3mbxoNO7pzq5ARhEXxLrgIX1Ms2LcLdXqsTyKQ/69BYkg5LRfZGtHY8E4+zrp+fneszX4a74sPhMCA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=J8w81zC5; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="J8w81zC5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1713673213; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=bO6UyB4BZo2OLU9jk/rODbkslDxInPGNh6ep7lCiazY=; b=J8w81zC5MBbNySJxKipyRF55NLxkWbGK9sXkt5gT2PKbBq3Q00pEpb3KMl8IK3b8qtYcL1rBOnR9Ar4hHCA/Vzt/0kpFKvvZ4eoS3bjQKqvpKrSJT1Cd1kJzIwjdR2L4g7jP0tHuIoIKsMUyFrg9aiWtOYNTpWuiXgdOdi4coJw= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=lulie@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0W4w4xWE_1713673211; Received: from localhost(mailfrom:lulie@linux.alibaba.com fp:SMTPD_---0W4w4xWE_1713673211) by smtp.aliyun-inc.com; Sun, 21 Apr 2024 12:20:12 +0800 From: Philo Lu To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: edumazet@google.com, davem@davemloft.net, martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, xuanzhuo@linux.alibaba.com, fred.cc@alibaba-inc.com Subject: [PATCH net-next 1/2] tcp: move tcp_skb_cb->sacked flags to enum Date: Sun, 21 Apr 2024 12:20:08 +0800 Message-Id: <20240421042009.28046-2-lulie@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240421042009.28046-1-lulie@linux.alibaba.com> References: <20240421042009.28046-1-lulie@linux.alibaba.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Move the flag definitions for tcp_skb_cb->sacked into a new enum named tcp_skb_cb_sacked_flags, then we can get access to them in bpf via vmlinux.h, e.g., in tracepoints. This patch does not change any existing functionality. Signed-off-by: Philo Lu Reviewed-by: Eric Dumazet --- include/net/tcp.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index b935e1ae4caf8..ffc9371fe9dea 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -928,6 +928,19 @@ static inline u32 tcp_rsk_tsval(const struct tcp_request_sock *treq) #define TCPHDR_SYN_ECN (TCPHDR_SYN | TCPHDR_ECE | TCPHDR_CWR) +/* State flags for sacked in struct tcp_skb_cb */ +enum tcp_skb_cb_sacked_flags { + TCPCB_SACKED_ACKED = (1 << 0), /* SKB ACK'd by a SACK block */ + TCPCB_SACKED_RETRANS = (1 << 1), /* SKB retransmitted */ + TCPCB_LOST = (1 << 2), /* SKB is lost */ + TCPCB_TAGBITS = (TCPCB_SACKED_ACKED | TCPCB_SACKED_RETRANS | + TCPCB_LOST), /* All tag bits */ + TCPCB_REPAIRED = (1 << 4), /* SKB repaired (no skb_mstamp_ns) */ + TCPCB_EVER_RETRANS = (1 << 7), /* Ever retransmitted frame */ + TCPCB_RETRANS = (TCPCB_SACKED_RETRANS | TCPCB_EVER_RETRANS | + TCPCB_REPAIRED), +}; + /* This is what the send packet queuing engine uses to pass * TCP per-packet control information to the transmission code. * We also store the host-order sequence numbers in here too. @@ -950,15 +963,6 @@ struct tcp_skb_cb { __u8 tcp_flags; /* TCP header flags. (tcp[13]) */ __u8 sacked; /* State flags for SACK. */ -#define TCPCB_SACKED_ACKED 0x01 /* SKB ACK'd by a SACK block */ -#define TCPCB_SACKED_RETRANS 0x02 /* SKB retransmitted */ -#define TCPCB_LOST 0x04 /* SKB is lost */ -#define TCPCB_TAGBITS 0x07 /* All tag bits */ -#define TCPCB_REPAIRED 0x10 /* SKB repaired (no skb_mstamp_ns) */ -#define TCPCB_EVER_RETRANS 0x80 /* Ever retransmitted frame */ -#define TCPCB_RETRANS (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS| \ - TCPCB_REPAIRED) - __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */ __u8 txstamp_ack:1, /* Record TX timestamp for ack? */ eor:1, /* Is skb MSG_EOR marked? */ From patchwork Sun Apr 21 04:20:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philo Lu X-Patchwork-Id: 13637299 X-Patchwork-Delegate: kuba@kernel.org Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74A4A4431; Sun, 21 Apr 2024 04:20:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713673227; cv=none; b=qqzl0b8oaN5uS9cq7k8HojO10wYUM5jGa6EUNAoBxM5KcJhEPg8yXv4IJTW0tR534MmIKgZ/MWsps6fJAe0B+x208zbYOIrH76XS3EUHZy6ZOMI/zkTjas4orHLpmnfOfauc00WbokgQ2iOqoBNxulIkzqVYWeFYL5xxGLViffQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713673227; c=relaxed/simple; bh=PbyRkYuJytgE5iCU+AC5a5bJtUe0HIu2Mw1mFTE/GVs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JDy3q8BnMekwJ6arVKIyJfHowI4XW1EujUh9bCrElW8SVEnLoI0RnZy5eFpN0y+DuQ1rpkVONI/vMgeJiwWDr/awBP5SQz25TUXdNC+OipQ7y+lxdr9KTb5olzBh6g2UQ28P+Njy5TK3noJeZtBRn36K5dtQIFpJYK764Ws++28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Vz/M4rz0; arc=none smtp.client-ip=115.124.30.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Vz/M4rz0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1713673216; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=3Exkxp2sjjjIWtsxU2G5SREfLgBVMfFhoE2jzGKVPAw=; b=Vz/M4rz04vZbP9HvFikC1UweAKDw1mobOircSi2iYztYNZ9xOnT08FU2y+4N1odAJtQhMquymb+IBbNtsNukY6QF2jDCckVmR7CUd+rfyG4Mp8Md+dgkm7OD3PWYah19mrLvrV841YQIQQWo+rgXNj6ETNMsmzTvIBGJjbCjJi8= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=lulie@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0W4w6o4T_1713673213; Received: from localhost(mailfrom:lulie@linux.alibaba.com fp:SMTPD_---0W4w6o4T_1713673213) by smtp.aliyun-inc.com; Sun, 21 Apr 2024 12:20:14 +0800 From: Philo Lu To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: edumazet@google.com, davem@davemloft.net, martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, xuanzhuo@linux.alibaba.com, fred.cc@alibaba-inc.com Subject: [PATCH net-next 2/2] tcp: update sacked after tracepoint in __tcp_retransmit_skb Date: Sun, 21 Apr 2024 12:20:09 +0800 Message-Id: <20240421042009.28046-3-lulie@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240421042009.28046-1-lulie@linux.alibaba.com> References: <20240421042009.28046-1-lulie@linux.alibaba.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Marking TCP_SKB_CB(skb)->sacked with TCPCB_EVER_RETRANS after the traceopint (trace_tcp_retransmit_skb), then we can get the retransmission efficiency by counting skbs w/ and w/o TCPCB_EVER_RETRANS mark in this tracepoint. We have discussed to achieve this with BPF_SOCK_OPS in [0], and using tracepoint is thought to be a better solution. [0] https://lore.kernel.org/all/20240417124622.35333-1-lulie@linux.alibaba.com/ Signed-off-by: Philo Lu Reviewed-by: Eric Dumazet --- net/ipv4/tcp_output.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 61119d42b0fd2..e19e74e005c1b 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3390,11 +3390,6 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC); } - /* To avoid taking spuriously low RTT samples based on a timestamp - * for a transmit that never happened, always mark EVER_RETRANS - */ - TCP_SKB_CB(skb)->sacked |= TCPCB_EVER_RETRANS; - if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RETRANS_CB_FLAG)) tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RETRANS_CB, TCP_SKB_CB(skb)->seq, segs, err); @@ -3404,6 +3399,12 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) } else if (err != -EBUSY) { NET_ADD_STATS(sock_net(sk), LINUX_MIB_TCPRETRANSFAIL, segs); } + + /* To avoid taking spuriously low RTT samples based on a timestamp + * for a transmit that never happened, always mark EVER_RETRANS + */ + TCP_SKB_CB(skb)->sacked |= TCPCB_EVER_RETRANS; + return err; }