Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752911AbdLDRub (ORCPT ); Mon, 4 Dec 2017 12:50:31 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:54122 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752214AbdLDRu1 (ORCPT ); Mon, 4 Dec 2017 12:50:27 -0500 From: Song Liu To: Yafang Shao CC: David Miller , "kuznet@ms2.inr.ac.ru" , "yoshfuji@linux-ipv6.org" , Steven Rostedt , Brendan Gregg , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2 net-next] net/tcp: trace all TCP/IP state transition with tcp_set_state tracepoint Thread-Topic: [PATCH v2 net-next] net/tcp: trace all TCP/IP state transition with tcp_set_state tracepoint Thread-Index: AQHTa1EgP0D+iiqvPEyCFT4Hbba4i6MzeeqA Date: Mon, 4 Dec 2017 17:49:48 +0000 Message-ID: References: <1512207401-3154-1-git-send-email-laoar.shao@gmail.com> In-Reply-To: <1512207401-3154-1-git-send-email-laoar.shao@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3273) x-originating-ip: [2620:10d:c090:200::6:3732] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY4PR15MB1511;20:VJxas/fOskYzlcAQBwhZH/Q72tnszTMkjiozKRZSi+dfB2PBMuUXzZGQ6ZqHKsGL4rv2KyA4jOq4QRGtpACWbp/oHBMomKYW80D833fw7n14t/HRKeoXIFYgI7HkCGDUqWnsY5lteUKHsq1XOzf3IsfqY0BcarafUoC3NoAplIo= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: e20b30a0-77fe-492e-70a0-08d53b3f69ec x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603286);SRVR:CY4PR15MB1511; x-ms-traffictypediagnostic: CY4PR15MB1511: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(67672495146484); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(11241501159)(6040450)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231022)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(20161123562025)(20161123560025)(20161123564025)(6072148)(201708071742011);SRVR:CY4PR15MB1511;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY4PR15MB1511; x-forefront-prvs: 051158ECBB x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(366004)(376002)(346002)(24454002)(199003)(189002)(36756003)(316002)(33656002)(6116002)(189998001)(83716003)(53546010)(54906003)(3280700002)(57306001)(2906002)(6436002)(68736007)(77096006)(6486002)(6916009)(2950100002)(53936002)(5660300001)(6512007)(101416001)(86362001)(82746002)(25786009)(229853002)(3660700001)(97736004)(50226002)(7736002)(305945005)(6506006)(14454004)(2900100001)(4326008)(39060400002)(99286004)(8936002)(81166006)(81156014)(76176011)(102836003)(105586002)(8676002)(6246003)(106356001)(478600001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR15MB1511;H:CY4PR15MB1512.namprd15.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: <4714BF005A7D0040A5279D4B5B837915@namprd15.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: e20b30a0-77fe-492e-70a0-08d53b3f69ec X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Dec 2017 17:49:48.6687 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1511 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-04_06:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id vB4HoYMx008906 Content-Length: 3677 Lines: 110 > On Dec 2, 2017, at 1:36 AM, Yafang Shao wrote: > > The TCP/IP transition from TCP_LISTEN to TCP_SYN_RECV and some other > transitions are not traced with tcp_set_state tracepoint. > > In order to trace the whole tcp lifespans, two helpers are introduced, > void __tcp_set_state(struct sock *sk, int state) > void __sk_state_store(struct sock *sk, int newstate) > > When do TCP/IP state transition, we should use these two helpers or use > tcp_set_state() other than assigning a value to sk_state directly. > > Signed-off-by: Yafang Shao > > --- > v2: test > --- > include/net/tcp.h | 2 ++ > net/ipv4/inet_connection_sock.c | 6 +++--- > net/ipv4/inet_hashtables.c | 2 +- > net/ipv4/tcp.c | 12 ++++++++++++ > 4 files changed, 18 insertions(+), 4 deletions(-) > > diff --git a/include/net/tcp.h b/include/net/tcp.h > index 85ea578..4f2d015 100644 > --- a/include/net/tcp.h > +++ b/include/net/tcp.h > @@ -1247,6 +1247,8 @@ static inline bool tcp_checksum_complete(struct sk_buff *skb) > "Close Wait","Last ACK","Listen","Closing" > }; > #endif > +void __sk_state_store(struct sock *sk, int newstate); > +void __tcp_set_state(struct sock *sk, int state); > void tcp_set_state(struct sock *sk, int state); > > void tcp_done(struct sock *sk); > diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c > index 4ca46dc..f3967f1 100644 > --- a/net/ipv4/inet_connection_sock.c > +++ b/net/ipv4/inet_connection_sock.c > @@ -783,7 +783,7 @@ struct sock *inet_csk_clone_lock(const struct sock *sk, > if (newsk) { > struct inet_connection_sock *newicsk = inet_csk(newsk); > > - newsk->sk_state = TCP_SYN_RECV; > + __tcp_set_state(newsk, TCP_SYN_RECV); > newicsk->icsk_bind_hash = NULL; > > inet_sk(newsk)->inet_dport = inet_rsk(req)->ir_rmt_port; > @@ -877,7 +877,7 @@ int inet_csk_listen_start(struct sock *sk, int backlog) > * It is OK, because this socket enters to hash table only > * after validation is complete. > */ > - sk_state_store(sk, TCP_LISTEN); > + __sk_state_store(sk, TCP_LISTEN); > if (!sk->sk_prot->get_port(sk, inet->inet_num)) { > inet->inet_sport = htons(inet->inet_num); > > @@ -888,7 +888,7 @@ int inet_csk_listen_start(struct sock *sk, int backlog) > return 0; > } > > - sk->sk_state = TCP_CLOSE; > + __tcp_set_state(sk, TCP_CLOSE); > return err; > } > EXPORT_SYMBOL_GPL(inet_csk_listen_start); > diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c > index e7d15fb..72c15b6 100644 > --- a/net/ipv4/inet_hashtables.c > +++ b/net/ipv4/inet_hashtables.c > @@ -430,7 +430,7 @@ bool inet_ehash_nolisten(struct sock *sk, struct sock *osk) > sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); > } else { > percpu_counter_inc(sk->sk_prot->orphan_count); > - sk->sk_state = TCP_CLOSE; > + __tcp_set_state(sk, TCP_CLOSE); > sock_set_flag(sk, SOCK_DEAD); > inet_csk_destroy_sock(sk); > } > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c > index bf97317..2bc7e04 100644 > --- a/net/ipv4/tcp.c > +++ b/net/ipv4/tcp.c > @@ -2036,6 +2036,18 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, > } > EXPORT_SYMBOL(tcp_recvmsg); > > +void __sk_state_store(struct sock *sk, int newstate) > +{ > + trace_tcp_set_state(sk, sk->sk_state, newstate); > + sk_state_store(sk, newstate); > +} > + > +void __tcp_set_state(struct sock *sk, int state) > +{ > + trace_tcp_set_state(sk, sk->sk_state, state); > + sk->sk_state = state; > +} > + > void tcp_set_state(struct sock *sk, int state) > { > int oldstate = sk->sk_state; > -- > 1.8.3.1 > Asked-by: Song Liu