From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_NEOMUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59BF7C282DB for ; Sat, 2 Feb 2019 02:41:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1867021479 for ; Sat, 2 Feb 2019 02:41:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bDc6uLWM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726711AbfBBCiY (ORCPT ); Fri, 1 Feb 2019 21:38:24 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45359 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726486AbfBBCiY (ORCPT ); Fri, 1 Feb 2019 21:38:24 -0500 Received: by mail-pf1-f196.google.com with SMTP id g62so4124687pfd.12 for ; Fri, 01 Feb 2019 18:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=XyM0lf/l0jLycK9VyfFq9RXqccpZijRM3Fa+aPWIIow=; b=bDc6uLWMJAiy1x8QJ8xdcPjCDo1sWErKJQcuvb+vGyyH/LhY+kTQUXLAgLAPTkz0zk 4tpkHYfljmUlna9ZiMAVl727+btloHjlww91Erkoh4HCQoNl1EravGVc+RA6PZM08UTm bFTfWrhQGFKKmkrDoX2g0pLLYqQKX9tU3bYpwTFelfWpmJeXGLvD8EX5vxg9QjfkyegC 3VkhRg1R6Bm/CJBE2glc1Fvb7jEkKE0ruCnVKVO0KI3rxu47zT2V2YKndNetfy9Bdi+n goLzHWQlQY79SkvEs7G+njGKI312Tn4gztbUP5uG4B92expPo8gEMxGv2T1FAWWi1CZJ H98Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=XyM0lf/l0jLycK9VyfFq9RXqccpZijRM3Fa+aPWIIow=; b=bUmtNyZMUegnD9EA4rcp/PTc1HxmrOHn6CFtNtrGdj1MNiAJrPTLwOYUxiUQZJh7j5 f2IvMCHN07tikSNToTAkShHyPesO69mZ+ejc0nTTizZcbo+uu60iZ6c0RSTtASTqWnYC 6STFkJocOV3ZAg3wj5XSsot8qYUzAnM/kUKXZiW8GdexAFYrom//zHjzXCijXM6jOisC i+RmErpBqk4V2CKJCh6LwLw+muGyKSnl4lMu22cO58u9H9z21iJ4/f24aI5bZ3zFf/er U813+70b3tHkhChd8ZOmMNCNdDMIBSkDdN/EK/jMUrkKbL1BjVtWXVO8dymwwSgHQ/D5 G+oA== X-Gm-Message-State: AHQUAuZukWb2IcIi8q+QL+bwmOQgw4oju1shumMkTdV636DgFweg/0zs xCjagHpyveaSa2AShUmoT7s= X-Google-Smtp-Source: AHgI3IZCT5kV/X19GsULVKIBhL4mLVl4aNHhW4C18JB3exf6td+gnVh12iy7FnJNcRS3kzENdD8z7g== X-Received: by 2002:a63:e20a:: with SMTP id q10mr4587344pgh.206.1549075103216; Fri, 01 Feb 2019 18:38:23 -0800 (PST) Received: from ast-mbp ([2620:10d:c090:200::5:85d3]) by smtp.gmail.com with ESMTPSA id o13sm12039841pfk.57.2019.02.01.18.38.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Feb 2019 18:38:22 -0800 (PST) Date: Fri, 1 Feb 2019 18:38:21 -0800 From: Alexei Starovoitov To: Martin KaFai Lau Cc: netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , kernel-team@fb.com, Lawrence Brakmo , joe@wand.net.nz, john.fastabend@gmail.com, willemb@google.com Subject: Re: [PATCH bpf-next 1/6] bpf: Add a bpf_sock pointer to __sk_buff and a bpf_sk_fullsock helper Message-ID: <20190202023819.jbwxhmjgzwcpdkp5@ast-mbp> References: <20190201070356.4148189-1-kafai@fb.com> <20190201070356.4148323-1-kafai@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190201070356.4148323-1-kafai@fb.com> User-Agent: NeoMutt/20180223 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Jan 31, 2019 at 11:03:56PM -0800, Martin KaFai Lau wrote: > In kernel, it is common to check "!skb->sk && sk_fullsock(skb->sk)" > before accessing the fields in sock. For example, in __netdev_pick_tx: > > static u16 __netdev_pick_tx(struct net_device *dev, struct sk_buff *skb, > struct net_device *sb_dev) > { > /* ... */ > > struct sock *sk = skb->sk; > > if (queue_index != new_index && sk && > sk_fullsock(sk) && > rcu_access_pointer(sk->sk_dst_cache)) > sk_tx_queue_set(sk, new_index); > > /* ... */ > > return queue_index; > } > > This patch adds a "struct bpf_sock *sk" pointer to the "struct __sk_buff" ... > Some of the fileds in "bpf_sock" will not be directly > accessible through the "__sk_buff->sk" pointer. ... > The newly added "struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)" > can be used to get a sk with all accessible fields in "bpf_sock". > This helper is added to both cg_skb and sched_(cls|act). > > int cg_skb_foo(struct __sk_buff *skb) { > struct bpf_sock *sk; > __u32 family; > > sk = skb->sk; > if (!sk) > return 1; > > sk = bpf_sk_fullsock(sk); > if (!sk) > return 1; > > if (sk->family != AF_INET6 || sk->protocol != IPPROTO_TCP) > return 1; > > /* some_traffic_shaping(); */ > > return 1; > } > > (1) The sk is read only > > (2) There is no new "struct bpf_sock_common" introduced. > > (3) Future kernel sock's members could be added to bpf_sock only > instead of repeatedly adding at multiple places like currently > in bpf_sock_ops_md, bpf_sock_addr_md, sk_reuseport_md...etc. All, this patchset sets a direction on how access to kernel socket datastructures should be made from bpf programs of networking types. It makes bpf program access to sk_common, sk, tcp_sock fields look and feel like kernel code. We think it's the most flexible and fixes the copy-paste issue of existing api. I wish we thought of it earlier :) Please review. For the patch set: Acked-by: Alexei Starovoitov