History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Daniel Borkmann says: ==================== pull-request: bpf-next 2020-10-01 The following pull-request contains BPF updates for your *net-next* tree. We've added 90 non-merge commits during the last 8 day(s) which contain a total of 103 files changed, 7662 insertions(+), 1894 deletions(-). Note that once bpf(/net) tree gets merged into net-next, there will be a small merge conflict in tools/lib/bpf/btf.c between commit 1245008122d7 ("libbpf: Fix native endian assumption when parsing BTF") from the bpf tree and the commit 3289959b97ca ("libbpf: Support BTF loading and raw data output in both endianness") from the bpf-next tree. Correct resolution would be to stick with bpf-next, it should look like: [...] /* check BTF magic */ if (fread(&magic, 1, sizeof(magic), f) < sizeof(magic)) { err = -EIO; goto err_out; } if (magic != BTF_MAGIC && magic != bswap_16(BTF_MAGIC)) { /* definitely not a raw BTF */ err = -EPROTO; goto err_out; } /* get file size */ [...] The main changes are: 1) Add bpf_snprintf_btf() and bpf_seq_printf_btf() helpers to support displaying BTF-based kernel data structures out of BPF programs, from Alan Maguire. 2) Speed up RCU tasks trace grace periods by a factor of 50 & fix a few race conditions exposed by it. It was discussed to take these via BPF and networking tree to get better testing exposure, from Paul E. McKenney. 3) Support multi-attach for freplace programs, needed for incremental attachment of multiple XDP progs using libxdp dispatcher model, from Toke Høiland-Jørgensen. 4) libbpf support for appending new BTF types at the end of BTF object, allowing intrusive changes of prog's BTF (useful for future linking), from Andrii Nakryiko. 5) Several BPF helper improvements e.g. avoid atomic op in cookie generator and add a redirect helper into neighboring subsys, from Daniel Borkmann. 6) Allow map updates on sockmaps from bpf_iter context in order to migrate sockmaps from one to another, from Lorenz Bauer. 7) Fix 32 bit to 64 bit assignment from latest alu32 bounds tracking which caused a verifier issue due to type downgrade to scalar, from John Fastabend. 8) Follow-up on tail-call support in BPF subprogs which optimizes x64 JIT prologue and epilogue sections, from Maciej Fijalkowski. 9) Add an option to perf RB map to improve sharing of event entries by avoiding remove- on-close behavior. Also, add BPF_PROG_TEST_RUN for raw_tracepoint, from Song Liu. 10) Fix a crash in AF_XDP's socket_release when memory allocation for UMEMs fails, from Magnus Karlsson. ====================

David S. Miller committed 6 years ago

Commit 23a1f682 parents 7c89d9d 6208689103 files · +7662 −1894Browse files

Showing the changes to include/uapi/linux (1 of 103 files). Show all

Unified · Split

include/uapi/linux/bpf.h+125−9
@@ -414,6 +414,9 @@ enum { · 413 unmodified lines
414414
415415 /* Enable memory-mapping BPF map */
416416 BPF_F_MMAPABLE = (1U << 10),
417+
418+/* Share perf_event among processes */
419+ BPF_F_PRESERVE_ELEMS = (1U << 11),
417420 };
418421
419422 /* Flags for BPF_PROG_QUERY. */
@@ -424,6 +427,11 @@ enum { · 4 unmodified lines
424427 */
425428 #define BPF_F_QUERY_EFFECTIVE (1U << 0)
426429
430+/* Flags for BPF_PROG_TEST_RUN */
431+
432+/* If set, run the test on the cpu specified by bpf_attr.test.cpu */
433+#define BPF_F_TEST_RUN_ON_CPU (1U << 0)
434+
427435 /* type for BPF_ENABLE_STATS */
428436 enum bpf_stats_type {
429437 /* enabled run_time_ns and run_cnt */
@@ -566,6 +574,8 @@ union bpf_attr { · 136 unmodified lines
566574 */
567575 __aligned_u64 ctx_in;
568576 __aligned_u64 ctx_out;
577+ __u32 flags;
578+ __u32 cpu;
569579 } test;
570580
571581 struct { /* anonymous struct used by BPF_*_GET_*_ID */
@@ -632,8 +642,13 @@ union bpf_attr { · 60 unmodified lines
632642 };
633643 __u32 attach_type; /* attach type */
634644 __u32 flags; /* extra flags */
635− __aligned_u64 iter_info; /* extra bpf_iter_link_info */
636− __u32 iter_info_len; /* iter_info length */
645+ union {
646+ __u32 target_btf_id; /* btf_id of target to attach to */
647+ struct {
648+ __aligned_u64 iter_info; /* extra bpf_iter_link_info */
649+ __u32 iter_info_len; /* iter_info length */
650+ };
651+ };
637652 } link_create;
638653
639654 struct { /* struct used by BPF_LINK_UPDATE command */
@@ -2512,7 +2527,7 @@ union bpf_attr { · 1872 unmodified lines
25122527 * result is from *reuse*\ **->socks**\ [] using the hash of the
25132528 * tuple.
25142529 *
2515− * long bpf_sk_release(struct bpf_sock *sock)
2530+ * long bpf_sk_release(void *sock)
25162531 * Description
25172532 * Release the reference held by *sock*. *sock* must be a
25182533 * non-**NULL** pointer that was returned from
@@ -2692,7 +2707,7 @@ union bpf_attr { · 173 unmodified lines
26922707 * result is from *reuse*\ **->socks**\ [] using the hash of the
26932708 * tuple.
26942709 *
2695− * long bpf_tcp_check_syncookie(struct bpf_sock *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
2710+ * long bpf_tcp_check_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
26962711 * Description
26972712 * Check whether *iph* and *th* contain a valid SYN cookie ACK for
26982713 * the listening socket in *sk*.
@@ -2861,6 +2876,7 @@ union bpf_attr { · 162 unmodified lines
28612876 * 0 on success.
28622877 *
28632878 * **-ENOENT** if the bpf-local-storage cannot be found.
2879+ * **-EINVAL** if sk is not a fullsock (e.g. a request_sock).
28642880 *
28652881 * long bpf_send_signal(u32 sig)
28662882 * Description
@@ -2877,7 +2893,7 @@ union bpf_attr { · 10 unmodified lines
28772893 *
28782894 * **-EAGAIN** if bpf program can try again.
28792895 *
2880− * s64 bpf_tcp_gen_syncookie(struct bpf_sock *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
2896+ * s64 bpf_tcp_gen_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
28812897 * Description
28822898 * Try to issue a SYN cookie for the packet with corresponding
28832899 * IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.
@@ -3106,7 +3122,7 @@ union bpf_attr { · 222 unmodified lines
31063122 * Return
31073123 * The id is returned or 0 in case the id could not be retrieved.
31083124 *
3109− * long bpf_sk_assign(struct sk_buff *skb, struct bpf_sock *sk, u64 flags)
3125+ * long bpf_sk_assign(struct sk_buff *skb, void *sk, u64 flags)
31103126 * Description
31113127 * Helper is overloaded depending on BPF program type. This
31123128 * description applies to **BPF_PROG_TYPE_SCHED_CLS** and
@@ -3234,11 +3250,11 @@ union bpf_attr { · 121 unmodified lines
32343250 *
32353251 * **-EOVERFLOW** if an overflow happened: The same object will be tried again.
32363252 *
3237− * u64 bpf_sk_cgroup_id(struct bpf_sock *sk)
3253+ * u64 bpf_sk_cgroup_id(void *sk)
32383254 * Description
32393255 * Return the cgroup v2 id of the socket *sk*.
32403256 *
3241− * *sk* must be a non-**NULL** pointer to a full socket, e.g. one
3257+ * *sk* must be a non-**NULL** pointer to a socket, e.g. one
32423258 * returned from **bpf_sk_lookup_xxx**\ (),
32433259 * **bpf_sk_fullsock**\ (), etc. The format of returned id is
32443260 * same as in **bpf_skb_cgroup_id**\ ().
@@ -3248,7 +3264,7 @@ union bpf_attr { · 3 unmodified lines
32483264 * Return
32493265 * The id is returned or 0 in case the id could not be retrieved.
32503266 *
3251− * u64 bpf_sk_ancestor_cgroup_id(struct bpf_sock *sk, int ancestor_level)
3267+ * u64 bpf_sk_ancestor_cgroup_id(void *sk, int ancestor_level)
32523268 * Description
32533269 * Return id of cgroup v2 that is ancestor of cgroup associated
32543270 * with the *sk* at the *ancestor_level*. The root cgroup is at
@@ -3586,6 +3602,72 @@ union bpf_attr { · 331 unmodified lines
35863602 * the data in *dst*. This is a wrapper of **copy_from_user**\ ().
35873603 * Return
35883604 * 0 on success, or a negative error in case of failure.
3605+ *
3606+ * long bpf_snprintf_btf(char *str, u32 str_size, struct btf_ptr *ptr, u32 btf_ptr_size, u64 flags)
3607+ * Description
3608+ * Use BTF to store a string representation of *ptr*->ptr in *str*,
3609+ * using *ptr*->type_id. This value should specify the type
3610+ * that *ptr*->ptr points to. LLVM __builtin_btf_type_id(type, 1)
3611+ * can be used to look up vmlinux BTF type ids. Traversing the
3612+ * data structure using BTF, the type information and values are
3613+ * stored in the first *str_size* - 1 bytes of *str*. Safe copy of
3614+ * the pointer data is carried out to avoid kernel crashes during
3615+ * operation. Smaller types can use string space on the stack;
3616+ * larger programs can use map data to store the string
3617+ * representation.
3618+ *
3619+ * The string can be subsequently shared with userspace via
3620+ * bpf_perf_event_output() or ring buffer interfaces.
3621+ * bpf_trace_printk() is to be avoided as it places too small
3622+ * a limit on string size to be useful.
3623+ *
3624+ * *flags* is a combination of
3625+ *
3626+ * **BTF_F_COMPACT**
3627+ * no formatting around type information
3628+ * **BTF_F_NONAME**
3629+ * no struct/union member names/types
3630+ * **BTF_F_PTR_RAW**
3631+ * show raw (unobfuscated) pointer values;
3632+ * equivalent to printk specifier %px.
3633+ * **BTF_F_ZERO**
3634+ * show zero-valued struct/union members; they
3635+ * are not displayed by default
3636+ *
3637+ * Return
3638+ * The number of bytes that were written (or would have been
3639+ * written if output had to be truncated due to string size),
3640+ * or a negative error in cases of failure.
3641+ *
3642+ * long bpf_seq_printf_btf(struct seq_file *m, struct btf_ptr *ptr, u32 ptr_size, u64 flags)
3643+ * Description
3644+ * Use BTF to write to seq_write a string representation of
3645+ * *ptr*->ptr, using *ptr*->type_id as per bpf_snprintf_btf().
3646+ * *flags* are identical to those used for bpf_snprintf_btf.
3647+ * Return
3648+ * 0 on success or a negative error in case of failure.
3649+ *
3650+ * u64 bpf_skb_cgroup_classid(struct sk_buff *skb)
3651+ * Description
3652+ * See **bpf_get_cgroup_classid**\ () for the main description.
3653+ * This helper differs from **bpf_get_cgroup_classid**\ () in that
3654+ * the cgroup v1 net_cls class is retrieved only from the *skb*'s
3655+ * associated socket instead of the current process.
3656+ * Return
3657+ * The id is returned or 0 in case the id could not be retrieved.
3658+ *
3659+ * long bpf_redirect_neigh(u32 ifindex, u64 flags)
3660+ * Description
3661+ * Redirect the packet to another net device of index *ifindex*
3662+ * and fill in L2 addresses from neighboring subsystem. This helper
3663+ * is somewhat similar to **bpf_redirect**\ (), except that it
3664+ * fills in e.g. MAC addresses based on the L3 information from
3665+ * the packet. This helper is supported for IPv4 and IPv6 protocols.
3666+ * The *flags* argument is reserved and must be 0. The helper is
3667+ * currently only supported for tc BPF program types.
3668+ * Return
3669+ * The helper returns **TC_ACT_REDIRECT** on success or
3670+ * **TC_ACT_SHOT** on error.
35893671 */
35903672 #define __BPF_FUNC_MAPPER(FN) \
35913673 FN(unspec), \
@@ -3737,6 +3819,10 @@ union bpf_attr { · 145 unmodified lines
37373819 FN(inode_storage_delete), \
37383820 FN(d_path), \
37393821 FN(copy_from_user), \
3822+ FN(snprintf_btf), \
3823+ FN(seq_printf_btf), \
3824+ FN(skb_cgroup_classid), \
3825+ FN(redirect_neigh), \
37403826 /* */
37413827
37423828 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
@@ -4845,4 +4931,34 @@ struct bpf_sk_lookup { · 1102 unmodified lines
48454931 __u32 local_port; /* Host byte order */
48464932 };
48474933
4934+/*
4935+ * struct btf_ptr is used for typed pointer representation; the
4936+ * type id is used to render the pointer data as the appropriate type
4937+ * via the bpf_snprintf_btf() helper described above. A flags field -
4938+ * potentially to specify additional details about the BTF pointer
4939+ * (rather than its mode of display) - is included for future use.
4940+ * Display flags - BTF_F_* - are passed to bpf_snprintf_btf separately.
4941+ */
4942+struct btf_ptr {
4943+ void *ptr;
4944+ __u32 type_id;
4945+ __u32 flags; /* BTF ptr flags; unused at present. */
4946+};
4947+
4948+/*
4949+ * Flags to control bpf_snprintf_btf() behaviour.
4950+ * - BTF_F_COMPACT: no formatting around type information
4951+ * - BTF_F_NONAME: no struct/union member names/types
4952+ * - BTF_F_PTR_RAW: show raw (unobfuscated) pointer values;
4953+ * equivalent to %px.
4954+ * - BTF_F_ZERO: show zero-valued struct/union members; they
4955+ * are not displayed by default
4956+ */
4957+enum {
4958+ BTF_F_COMPACT = (1ULL << 0),
4959+ BTF_F_NONAME = (1ULL << 1),
4960+ BTF_F_PTR_RAW = (1ULL << 2),
4961+ BTF_F_ZERO = (1ULL << 3),
4962+};
4963+
48484964 #endif /* _UAPI__LINUX_BPF_H__ */