Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
authorDavid S. Miller <davem@davemloft.net>
Fri, 27 Apr 2018 01:19:50 +0000 (21:19 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 27 Apr 2018 01:19:50 +0000 (21:19 -0400)
Daniel Borkmann says:

====================
pull-request: bpf-next 2018-04-27

The following pull-request contains BPF updates for your *net-next* tree.

The main changes are:

1) Add extensive BPF helper description into include/uapi/linux/bpf.h
   and a new script bpf_helpers_doc.py which allows for generating a
   man page out of it. Thus, every helper in BPF now comes with proper
   function signature, detailed description and return code explanation,
   from Quentin.

2) Migrate the BPF collect metadata tunnel tests from BPF samples over
   to the BPF selftests and further extend them with v6 vxlan, geneve
   and ipip tests, simplify the ipip tests, improve documentation and
   convert to bpf_ntoh*() / bpf_hton*() api, from William.

3) Currently, helpers that expect ARG_PTR_TO_MAP_{KEY,VALUE} can only
   access stack and packet memory. Extend this to allow such helpers
   to also use map values, which enabled use cases where value from
   a first lookup can be directly used as a key for a second lookup,
   from Paul.

4) Add a new helper bpf_skb_get_xfrm_state() for tc BPF programs in
   order to retrieve XFRM state information containing SPI, peer
   address and reqid values, from Eyal.

5) Various optimizations in nfp driver's BPF JIT in order to turn ADD
   and SUB instructions with negative immediate into the opposite
   operation with a positive immediate such that nfp can better fit
   small immediates into instructions. Savings in instruction count
   up to 4% have been observed, from Jakub.

6) Add the BPF prog's gpl_compatible flag to struct bpf_prog_info
   and add support for dumping this through bpftool, from Jiri.

7) Move the BPF sockmap samples over into BPF selftests instead since
   sockmap was rather a series of tests than sample anyway and this way
   this can be run from automated bots, from John.

8) Follow-up fix for bpf_adjust_tail() helper in order to make it work
   with generic XDP, from Nikita.

9) Some follow-up cleanups to BTF, namely, removing unused defines from
   BTF uapi header and renaming 'name' struct btf_* members into name_off
   to make it more clear they are offsets into string section, from Martin.

10) Remove test_sock_addr from TEST_GEN_PROGS in BPF selftests since
    not run directly but invoked from test_sock_addr.sh, from Yonghong.

11) Remove redundant ret assignment in sample BPF loader, from Wang.

12) Add couple of missing files to BPF selftest's gitignore, from Anders.

There are two trivial merge conflicts while pulling:

  1) Remove samples/sockmap/Makefile since all sockmap tests have been
     moved to selftests.
  2) Add both hunks from tools/testing/selftests/bpf/.gitignore to the
     file since git should ignore all of them.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
1  2 
kernel/bpf/syscall.c
net/core/filter.c
tools/testing/selftests/bpf/.gitignore

diff --combined kernel/bpf/syscall.c
@@@ -260,8 -260,8 +260,8 @@@ static void bpf_map_free_deferred(struc
  static void bpf_map_put_uref(struct bpf_map *map)
  {
        if (atomic_dec_and_test(&map->usercnt)) {
 -              if (map->map_type == BPF_MAP_TYPE_PROG_ARRAY)
 -                      bpf_fd_array_map_clear(map);
 +              if (map->ops->map_release_uref)
 +                      map->ops->map_release_uref(map);
        }
  }
  
@@@ -1914,6 -1914,7 +1914,7 @@@ static int bpf_prog_get_info_by_fd(stru
        info.load_time = prog->aux->load_time;
        info.created_by_uid = from_kuid_munged(current_user_ns(),
                                               prog->aux->user->uid);
+       info.gpl_compatible = prog->gpl_compatible;
  
        memcpy(info.tag, prog->tag, sizeof(prog->tag));
        memcpy(info.name, prog->aux->name, sizeof(prog->aux->name));
diff --combined net/core/filter.c
@@@ -57,6 -57,7 +57,7 @@@
  #include <net/sock_reuseport.h>
  #include <net/busy_poll.h>
  #include <net/tcp.h>
+ #include <net/xfrm.h>
  #include <linux/bpf_trace.h>
  
  /**
@@@ -3280,7 -3281,6 +3281,7 @@@ BPF_CALL_4(bpf_skb_set_tunnel_key, stru
        skb_dst_set(skb, (struct dst_entry *) md);
  
        info = &md->u.tun_info;
 +      memset(info, 0, sizeof(*info));
        info->mode = IP_TUNNEL_INFO_TX;
  
        info->key.tun_flags = TUNNEL_KEY | TUNNEL_CSUM | TUNNEL_NOCACHE;
@@@ -3744,6 -3744,49 +3745,49 @@@ static const struct bpf_func_proto bpf_
        .arg3_type      = ARG_CONST_SIZE,
  };
  
+ #ifdef CONFIG_XFRM
+ BPF_CALL_5(bpf_skb_get_xfrm_state, struct sk_buff *, skb, u32, index,
+          struct bpf_xfrm_state *, to, u32, size, u64, flags)
+ {
+       const struct sec_path *sp = skb_sec_path(skb);
+       const struct xfrm_state *x;
+       if (!sp || unlikely(index >= sp->len || flags))
+               goto err_clear;
+       x = sp->xvec[index];
+       if (unlikely(size != sizeof(struct bpf_xfrm_state)))
+               goto err_clear;
+       to->reqid = x->props.reqid;
+       to->spi = x->id.spi;
+       to->family = x->props.family;
+       if (to->family == AF_INET6) {
+               memcpy(to->remote_ipv6, x->props.saddr.a6,
+                      sizeof(to->remote_ipv6));
+       } else {
+               to->remote_ipv4 = x->props.saddr.a4;
+       }
+       return 0;
+ err_clear:
+       memset(to, 0, size);
+       return -EINVAL;
+ }
+ static const struct bpf_func_proto bpf_skb_get_xfrm_state_proto = {
+       .func           = bpf_skb_get_xfrm_state,
+       .gpl_only       = false,
+       .ret_type       = RET_INTEGER,
+       .arg1_type      = ARG_PTR_TO_CTX,
+       .arg2_type      = ARG_ANYTHING,
+       .arg3_type      = ARG_PTR_TO_UNINIT_MEM,
+       .arg4_type      = ARG_CONST_SIZE,
+       .arg5_type      = ARG_ANYTHING,
+ };
+ #endif
  static const struct bpf_func_proto *
  bpf_base_func_proto(enum bpf_func_id func_id)
  {
@@@ -3885,6 -3928,10 +3929,10 @@@ tc_cls_act_func_proto(enum bpf_func_id 
                return &bpf_get_socket_cookie_proto;
        case BPF_FUNC_get_socket_uid:
                return &bpf_get_socket_uid_proto;
+ #ifdef CONFIG_XFRM
+       case BPF_FUNC_skb_get_xfrm_state:
+               return &bpf_skb_get_xfrm_state_proto;
+ #endif
        default:
                return bpf_base_func_proto(func_id);
        }
@@@ -12,6 -12,4 +12,7 @@@ test_tcpbpf_use
  test_verifier_log
  feature
  test_libbpf_open
 +test_sock
 +test_sock_addr
 +urandom_read
+ test_btf