Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4530653imj; Tue, 12 Feb 2019 18:39:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IYeXCDC+Kv4uKgbUSA4QO+XZaqIZsU90tl/yFjrUegzOdzEhD+Dlq5lAO8t4LQa+o4jEvuj X-Received: by 2002:a63:1723:: with SMTP id x35mr6495865pgl.364.1550025587853; Tue, 12 Feb 2019 18:39:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550025587; cv=none; d=google.com; s=arc-20160816; b=iMGYuY8hpJZs/E11jf1xVOdUWRMO1r6kUyiP//ZqMBmAtzaXnrhC/sepLXkR2T4TK4 KVnliGLYY3X7mQ99OiRpjcCo5VSDE6UoKo4jJa5rrlyfvjOhnpr2QWljbljgulBf3TAQ xPJW3fqovT4SiIAoKJnVRD478Umknn9+/Vmg9A4QK7n29URimrffEmpGQnLazIrxWSdd h/vwDNmYM55pSWrBVIF30yhkiBsnkcKyf4/eN/IeYyiHk13w2E6gDsoVArpkSAmwSTsi TToY1l6HCGh5NDRSOxvXK3MY2bWnkUYMMD0eu+UuZp9ZDEXDgKrflPD5ZKEUxpjTpm11 JHOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=YpkFz2HVFPSa5xUUdLR+xspfaVBy2yEf82R/gJRvdt8=; b=ZyrMOJJ09vtAHsgGi9XzhFNJPwg1Eb1/ycVGdZhten3BtLNWz/qfclsSaxcVkUWK7C 8XowhNe75SFUY+bi51HhPl2Mo42Qo/XRMaYdiiQTujEVLwcEItxzTrnWCS2Che2h68MN bPeoGBMtEYCbkD5YzHRFStEH3bVCAE30JNeOepuCkfw+EaQ0nXf7kkE3vl1d7roSrUcz X1Y/oiWd5WZXw+aSOsNmUfDXV6AOB69jypgDGfnTYrKIihqnQTOfu8HSF3KwLjsi+xM2 jfGyEBesdP2tN0NBlbnYZxZcKB8XC9U9V3FJggUlO7EcB/MT8vAzq3RjfKfDurMW5oRF +tpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cr6lsDy3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i20si14312484pgh.187.2019.02.12.18.39.31; Tue, 12 Feb 2019 18:39:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cr6lsDy3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730219AbfBMCL2 (ORCPT + 99 others); Tue, 12 Feb 2019 21:11:28 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:53580 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727346AbfBMCL1 (ORCPT ); Tue, 12 Feb 2019 21:11:27 -0500 Received: by mail-it1-f196.google.com with SMTP id x131so756658itc.3; Tue, 12 Feb 2019 18:11:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YpkFz2HVFPSa5xUUdLR+xspfaVBy2yEf82R/gJRvdt8=; b=cr6lsDy3UG0ZFUwa1U4dIaFS9orOfwVbiwqqePkvHUZpnE+W3Eiz1z0mRgPHzz4cRI m1cr+hUW5yybymHhQRtF09WYyv0R73ISndwxAQg+j1fkokaRanq14iui5Gm9NpTeh+yM jD44vuBmIjJSEvSmXOqRgQOsE3DnAvZB5qvqXB+PumZhQtKVJ2aWSc/HxfSJXkBPEoji Oe/ZZqw/zA0e7Tq4xHr/kwKCFIfh2ELEp500GQpUZ9AOWVoR7Rw+PS1N3YhHlzxmklCs RWSaoWb3Pz8I/G3H+xweSGsx256T0ZD6VvsMdI+FOop4+VV5SrRV8QdpG9X+72UfdrX+ SjqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YpkFz2HVFPSa5xUUdLR+xspfaVBy2yEf82R/gJRvdt8=; b=oNowIJ2FtiJ3jGqvvoDMubrW6i4wiTDFA2/FSbYc4aiEiRwoHR6nt8UGnOurqTlYsL kgh+WPw8uwjhyzm/leJwfal8KVxzCmv0MohykotVYjW4rm+zWoPyOQI0j9pWysi/J3jx y7lbCXp/TqcPApf+JWfijO61oszy/7Rf0vLkbq7WL9n7N3T5WJzqkwo3RM/TBSKEixql SVbLHQ1cHx1OaKDtLfmECgcJpLoREuBhW/H09tqKs4/mUik7wwhM+Y9PW956MDNaGf7x FGijdKiWWKPhrwHXJbuNtLsXwCvGj5bp91mVO5y+gGQYDDMXkeUkYsbtMlJQqFn0i7HO qkgg== X-Gm-Message-State: AHQUAuYsS46Py4OqNZGXBXttCuSAAc2Hrb8GTlLc12iMEkXrTGUq9+C9 r6ZldnlaTeVqGE48Onv/hGDOST8sYjLf20TsEE8= X-Received: by 2002:a02:13c6:: with SMTP id 189mr3676420jaz.117.1550023886717; Tue, 12 Feb 2019 18:11:26 -0800 (PST) MIME-Version: 1.0 References: <1549971097-12627-1-git-send-email-laoar.shao@gmail.com> <1549971097-12627-3-git-send-email-laoar.shao@gmail.com> In-Reply-To: From: Yafang Shao Date: Wed, 13 Feb 2019 10:10:50 +0800 Message-ID: Subject: Re: [bpf-next 2/2] bpf: add BPF_SOCK_OPS_STATS_CB for tcp_stats() To: Eric Dumazet Cc: Daniel Borkmann , ast@kernel.org, Yonghong Song , brakmo@fb.com, Eric Dumazet , David Miller , netdev , LKML , shaoyafang@didiglobal.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 12, 2019 at 11:11 PM Eric Dumazet wrote: > > > > On 02/12/2019 03:31 AM, Yafang Shao wrote: > > Introuce this new op BPF_SOCK_OPS_STATS_CB for tcp_stats() such that it > > can be traced via BPF on a per socket basis. > > There's one argument in BPF_SOCK_OPS_STATS_CB, which is Linux MIB index > > LINUX_MIB_* to indicate the TCP event. > > All these Linux MIBs are defined in include/uapi/linux/snmp.h. > > > > Signed-off-by: Yafang Shao > > --- > > include/uapi/linux/bpf.h | 5 +++++ > > net/ipv4/tcp_input.c | 1 + > > 2 files changed, 6 insertions(+) > > > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > index 1777fa0..0314ddd 100644 > > --- a/include/uapi/linux/bpf.h > > +++ b/include/uapi/linux/bpf.h > > @@ -2894,6 +2894,11 @@ enum { > > BPF_SOCK_OPS_TCP_LISTEN_CB, /* Called on listen(2), right after > > * socket transition to LISTEN state. > > */ > > + BPF_SOCK_OPS_STATS_CB, /* > > + * Called on tcp_stats(). > > + * Arg1: Linux MIB index > > + * LINUX_MIB_* > > + */ > > }; > > > > /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect > > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c > > index 88deb1f..4acf458 100644 > > --- a/net/ipv4/tcp_input.c > > +++ b/net/ipv4/tcp_input.c > > @@ -3557,6 +3557,7 @@ static u32 tcp_newly_delivered(struct sock *sk, u32 prior_delivered, int flag) > > static void tcp_stats(struct sock *sk, int mib_idx) > > { > > NET_INC_STATS(sock_net(sk), mib_idx); > > + tcp_call_bpf(sk, BPF_SOCK_OPS_STATS_CB, 1, &mib_idx); > > } > > > > /* This routine deals with incoming acks, but not outgoing ones. */ > > > > If the plan is to add to all NET_INC_STATS() calls in TCP an additional tcp_call_bpf() > I will say no. > I have no plan to place it in fast path. Because what I concerned is the TCP abnomal events, which should be not in the fast path. However if we want to place it in the fast path, the code should be as bellow, if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_STATS_CB_FLAG)) tcp_call_bpf(sk, BPF_SOCK_OPS_STATS_CB, 1, &mib_idx); > So far, tcp_call_bpf() has not been used in fast path. > That's why I do it like this. Thanks Yafang