History

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

Alexei Starovoitov says: ==================== pull-request: bpf-next 2020-05-14 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Merged tag 'perf-for-bpf-2020-05-06' from tip tree that includes CAP_PERFMON. 2) support for narrow loads in bpf_sock_addr progs and additional helpers in cg-skb progs, from Andrey. 3) bpf benchmark runner, from Andrii. 4) arm and riscv JIT optimizations, from Luke. 5) bpf iterator infrastructure, from Yonghong. ====================

David S. Miller committed 6 years ago

Commit d00f26b2 parents 9b65d2f b92d44b139 files · +5253 −544Browse files

Showing the changes to include/uapi/linux (2 of 139 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/bpf.h +131 −42
  2. include/uapi/linux/capability.h +7 −1
include/uapi/linux/bpf.h+131−42
@@ -116,6 +116,7 @@ enum bpf_cmd { · 115 unmodified lines
116116 BPF_LINK_GET_FD_BY_ID,
117117 BPF_LINK_GET_NEXT_ID,
118118 BPF_ENABLE_STATS,
119+ BPF_ITER_CREATE,
119120 };
120121
121122 enum bpf_map_type {
@@ -218,6 +219,7 @@ enum bpf_attach_type { · 96 unmodified lines
218219 BPF_TRACE_FEXIT,
219220 BPF_MODIFY_RETURN,
220221 BPF_LSM_MAC,
222+ BPF_TRACE_ITER,
221223 __MAX_BPF_ATTACH_TYPE
222224 };
223225
@@ -228,6 +230,7 @@ enum bpf_link_type { · 4 unmodified lines
228230 BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
229231 BPF_LINK_TYPE_TRACING = 2,
230232 BPF_LINK_TYPE_CGROUP = 3,
233+ BPF_LINK_TYPE_ITER = 4,
231234
232235 MAX_BPF_LINK_TYPE,
233236 };
@@ -612,6 +615,11 @@ union bpf_attr { · 378 unmodified lines
612615 __u32 type;
613616 } enable_stats;
614617
618+ struct { /* struct used by BPF_ITER_CREATE command */
619+ __u32 link_fd;
620+ __u32 flags;
621+ } iter_create;
622+
615623 } __attribute__((aligned(8)));
616624
617625 /* The description below is an attempt at providing documentation to eBPF
@@ -667,8 +675,8 @@ union bpf_attr { · 49 unmodified lines
667675 * For tracing programs, safely attempt to read *size* bytes from
668676 * kernel space address *unsafe_ptr* and store the data in *dst*.
669677 *
670− * Generally, use bpf_probe_read_user() or bpf_probe_read_kernel()
671− * instead.
678+ * Generally, use **bpf_probe_read_user**\ () or
679+ * **bpf_probe_read_kernel**\ () instead.
672680 * Return
673681 * 0 on success, or a negative error in case of failure.
674682 *
@@ -676,7 +684,7 @@ union bpf_attr { · 1 unmodified line
676684 * Description
677685 * Return the time elapsed since system boot, in nanoseconds.
678686 * Does not include time the system was suspended.
679− * See: clock_gettime(CLOCK_MONOTONIC)
687+ * See: **clock_gettime**\ (**CLOCK_MONOTONIC**)
680688 * Return
681689 * Current *ktime*.
682690 *
@@ -1535,11 +1543,11 @@ union bpf_attr { · 852 unmodified lines
15351543 * int bpf_probe_read_str(void *dst, u32 size, const void *unsafe_ptr)
15361544 * Description
15371545 * Copy a NUL terminated string from an unsafe kernel address
1538− * *unsafe_ptr* to *dst*. See bpf_probe_read_kernel_str() for
1546+ * *unsafe_ptr* to *dst*. See **bpf_probe_read_kernel_str**\ () for
15391547 * more details.
15401548 *
1541− * Generally, use bpf_probe_read_user_str() or bpf_probe_read_kernel_str()
1542− * instead.
1549+ * Generally, use **bpf_probe_read_user_str**\ () or
1550+ * **bpf_probe_read_kernel_str**\ () instead.
15431551 * Return
15441552 * On success, the strictly positive length of the string,
15451553 * including the trailing NUL character. On error, a negative
@@ -1567,7 +1575,7 @@ union bpf_attr { · 21 unmodified lines
15671575 *
15681576 * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)
15691577 * Description
1570− * Equivalent to bpf_get_socket_cookie() helper that accepts
1578+ * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
15711579 * *skb*, but gets socket from **struct bpf_sock_ops** context.
15721580 * Return
15731581 * A 8-byte long non-decreasing number.
@@ -1596,6 +1604,7 @@ union bpf_attr { · 22 unmodified lines
15961604 * The option value of length *optlen* is pointed by *optval*.
15971605 *
15981606 * *bpf_socket* should be one of the following:
1607+ *
15991608 * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
16001609 * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
16011610 * and **BPF_CGROUP_INET6_CONNECT**.
@@ -1664,12 +1673,12 @@ union bpf_attr { · 62 unmodified lines
16641673 *
16651674 * The lower two bits of *flags* are used as the return code if
16661675 * the map lookup fails. This is so that the return value can be
1667− * one of the XDP program return codes up to XDP_TX, as chosen by
1668− * the caller. Any higher bits in the *flags* argument must be
1676+ * one of the XDP program return codes up to **XDP_TX**, as chosen
1677+ * by the caller. Any higher bits in the *flags* argument must be
16691678 * unset.
16701679 *
1671− * See also bpf_redirect(), which only supports redirecting to an
1672− * ifindex, but doesn't require a map to do so.
1680+ * See also **bpf_redirect**\ (), which only supports redirecting
1681+ * to an ifindex, but doesn't require a map to do so.
16731682 * Return
16741683 * **XDP_REDIRECT** on success, or the value of the two lower bits
16751684 * of the *flags* argument on error.
@@ -1777,7 +1786,7 @@ union bpf_attr { · 101 unmodified lines
17771786 * the time running for event since last normalization. The
17781787 * enabled and running times are accumulated since the perf event
17791788 * open. To achieve scaling factor between two invocations of an
1780− * eBPF program, users can can use CPU id as the key (which is
1789+ * eBPF program, users can use CPU id as the key (which is
17811790 * typical for perf array usage model) to remember the previous
17821791 * value and do the calculation inside the eBPF program.
17831792 * Return
@@ -1804,6 +1813,7 @@ union bpf_attr { · 20 unmodified lines
18041813 * *opval* and of length *optlen*.
18051814 *
18061815 * *bpf_socket* should be one of the following:
1816+ *
18071817 * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
18081818 * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
18091819 * and **BPF_CGROUP_INET6_CONNECT**.
@@ -1825,7 +1835,7 @@ union bpf_attr { · 15 unmodified lines
18251835 * The first argument is the context *regs* on which the kprobe
18261836 * works.
18271837 *
1828− * This helper works by setting setting the PC (program counter)
1838+ * This helper works by setting the PC (program counter)
18291839 * to an override function which is run in place of the original
18301840 * probed function. This means the probed function is not run at
18311841 * all. The replacement function just returns with the required
@@ -1994,10 +2004,11 @@ union bpf_attr { · 162 unmodified lines
19942004 *
19952005 * This helper works for IPv4 and IPv6, TCP and UDP sockets. The
19962006 * domain (*addr*\ **->sa_family**) must be **AF_INET** (or
1997− * **AF_INET6**). Looking for a free port to bind to can be
1998− * expensive, therefore binding to port is not permitted by the
1999− * helper: *addr*\ **->sin_port** (or **sin6_port**, respectively)
2000− * must be set to zero.
2007+ * **AF_INET6**). It's advised to pass zero port (**sin_port**
2008+ * or **sin6_port**) which triggers IP_BIND_ADDRESS_NO_PORT-like
2009+ * behavior and lets the kernel efficiently pick up an unused
2010+ * port as long as 4-tuple is unique. Passing non-zero port might
2011+ * lead to degraded performance.
20012012 * Return
20022013 * 0 on success, or a negative error in case of failure.
20032014 *
@@ -2291,7 +2302,7 @@ union bpf_attr { · 287 unmodified lines
22912302 * **bpf_rc_keydown**\ () again with the same values, or calling
22922303 * **bpf_rc_repeat**\ ().
22932304 *
2294− * Some protocols include a toggle bit, in case the button was
2305+ * Some protocols include a toggle bit, in case the button was
22952306 * released and pressed again between consecutive scancodes.
22962307 *
22972308 * The *ctx* should point to the lirc sample as passed into
@@ -2637,7 +2648,6 @@ union bpf_attr { · 339 unmodified lines
26372648 *
26382649 * *th* points to the start of the TCP header, while *th_len*
26392650 * contains **sizeof**\ (**struct tcphdr**).
2640− *
26412651 * Return
26422652 * 0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
26432653 * error otherwise.
@@ -2820,7 +2830,6 @@ union bpf_attr { · 176 unmodified lines
28202830 *
28212831 * *th* points to the start of the TCP header, while *th_len*
28222832 * contains the length of the TCP header.
2823− *
28242833 * Return
28252834 * On success, lower 32 bits hold the generated SYN cookie in
28262835 * followed by 16 bits which hold the MSS value for that cookie,
@@ -2903,7 +2912,7 @@ union bpf_attr { · 76 unmodified lines
29032912 * // size, after checking its boundaries.
29042913 * }
29052914 *
2906− * In comparison, using **bpf_probe_read_user()** helper here
2915+ * In comparison, using **bpf_probe_read_user**\ () helper here
29072916 * instead to read the string would require to estimate the length
29082917 * at compile time, and would often result in copying more memory
29092918 * than necessary.
@@ -2921,14 +2930,14 @@ union bpf_attr { · 11 unmodified lines
29212930 * int bpf_probe_read_kernel_str(void *dst, u32 size, const void *unsafe_ptr)
29222931 * Description
29232932 * Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
2924− * to *dst*. Same semantics as with bpf_probe_read_user_str() apply.
2933+ * to *dst*. Same semantics as with **bpf_probe_read_user_str**\ () apply.
29252934 * Return
2926− * On success, the strictly positive length of the string, including
2935+ * On success, the strictly positive length of the string, including
29272936 * the trailing NUL character. On error, a negative value.
29282937 *
29292938 * int bpf_tcp_send_ack(void *tp, u32 rcv_nxt)
29302939 * Description
2931− * Send out a tcp-ack. *tp* is the in-kernel struct tcp_sock.
2940+ * Send out a tcp-ack. *tp* is the in-kernel struct **tcp_sock**.
29322941 * *rcv_nxt* is the ack_seq to be sent out.
29332942 * Return
29342943 * 0 on success, or a negative error in case of failure.
@@ -2956,19 +2965,19 @@ union bpf_attr { · 21 unmodified lines
29562965 * int bpf_read_branch_records(struct bpf_perf_event_data *ctx, void *buf, u32 size, u64 flags)
29572966 * Description
29582967 * For an eBPF program attached to a perf event, retrieve the
2959− * branch records (struct perf_branch_entry) associated to *ctx*
2960− * and store it in the buffer pointed by *buf* up to size
2968+ * branch records (**struct perf_branch_entry**) associated to *ctx*
2969+ * and store it in the buffer pointed by *buf* up to size
29612970 * *size* bytes.
29622971 * Return
29632972 * On success, number of bytes written to *buf*. On error, a
29642973 * negative value.
29652974 *
29662975 * The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to
2967− * instead return the number of bytes required to store all the
2976+ * instead return the number of bytes required to store all the
29682977 * branch entries. If this flag is set, *buf* may be NULL.
29692978 *
29702979 * **-EINVAL** if arguments invalid or **size** not a multiple
2971− * of sizeof(struct perf_branch_entry).
2980+ * of **sizeof**\ (**struct perf_branch_entry**\ ).
29722981 *
29732982 * **-ENOENT** if architecture does not support branch records.
29742983 *
@@ -2976,8 +2985,8 @@ union bpf_attr { · 1 unmodified line
29762985 * Description
29772986 * Returns 0 on success, values for *pid* and *tgid* as seen from the current
29782987 * *namespace* will be returned in *nsdata*.
2979− *
2980− * On failure, the returned value is one of the following:
2988+ * Return
2989+ * 0 on success, or one of the following in case of failure:
29812990 *
29822991 * **-EINVAL** if dev and inum supplied don't match dev_t and inode number
29832992 * with nsfs of current task, or if dev conversion to dev_t lost high bits.
@@ -3016,8 +3025,8 @@ union bpf_attr { · 32 unmodified lines
30163025 * a global identifier that can be assumed unique. If *ctx* is
30173026 * NULL, then the helper returns the cookie for the initial
30183027 * network namespace. The cookie itself is very similar to that
3019− * of bpf_get_socket_cookie() helper, but for network namespaces
3020− * instead of sockets.
3028+ * of **bpf_get_socket_cookie**\ () helper, but for network
3029+ * namespaces instead of sockets.
30213030 * Return
30223031 * A 8-byte long opaque number.
30233032 *
@@ -3052,22 +3061,98 @@ union bpf_attr { · 28 unmodified lines
30523061 *
30533062 * The *flags* argument must be zero.
30543063 * Return
3055− * 0 on success, or a negative errno in case of failure.
3064+ * 0 on success, or a negative error in case of failure:
3065+ *
3066+ * **-EINVAL** if specified *flags* are not supported.
3067+ *
3068+ * **-ENOENT** if the socket is unavailable for assignment.
30563069 *
3057− * * **-EINVAL** Unsupported flags specified.
3058− * * **-ENOENT** Socket is unavailable for assignment.
3059− * * **-ENETUNREACH** Socket is unreachable (wrong netns).
3060− * * **-EOPNOTSUPP** Unsupported operation, for example a
3061− * call from outside of TC ingress.
3062− * * **-ESOCKTNOSUPPORT** Socket type not supported (reuseport).
3070+ * **-ENETUNREACH** if the socket is unreachable (wrong netns).
3071+ *
3072+ * **-EOPNOTSUPP** if the operation is not supported, for example
3073+ * a call from outside of TC ingress.
3074+ *
3075+ * **-ESOCKTNOSUPPORT** if the socket type is not supported
3076+ * (reuseport).
30633077 *
30643078 * u64 bpf_ktime_get_boot_ns(void)
30653079 * Description
30663080 * Return the time elapsed since system boot, in nanoseconds.
30673081 * Does include the time the system was suspended.
3068− * See: clock_gettime(CLOCK_BOOTTIME)
3082+ * See: **clock_gettime**\ (**CLOCK_BOOTTIME**)
30693083 * Return
30703084 * Current *ktime*.
3085+ *
3086+ * int bpf_seq_printf(struct seq_file *m, const char *fmt, u32 fmt_size, const void *data, u32 data_len)
3087+ * Description
3088+ * **bpf_seq_printf**\ () uses seq_file **seq_printf**\ () to print
3089+ * out the format string.
3090+ * The *m* represents the seq_file. The *fmt* and *fmt_size* are for
3091+ * the format string itself. The *data* and *data_len* are format string
3092+ * arguments. The *data* are a **u64** array and corresponding format string
3093+ * values are stored in the array. For strings and pointers where pointees
3094+ * are accessed, only the pointer values are stored in the *data* array.
3095+ * The *data_len* is the size of *data* in bytes.
3096+ *
3097+ * Formats **%s**, **%p{i,I}{4,6}** requires to read kernel memory.
3098+ * Reading kernel memory may fail due to either invalid address or
3099+ * valid address but requiring a major memory fault. If reading kernel memory
3100+ * fails, the string for **%s** will be an empty string, and the ip
3101+ * address for **%p{i,I}{4,6}** will be 0. Not returning error to
3102+ * bpf program is consistent with what **bpf_trace_printk**\ () does for now.
3103+ * Return
3104+ * 0 on success, or a negative error in case of failure:
3105+ *
3106+ * **-EBUSY** if per-CPU memory copy buffer is busy, can try again
3107+ * by returning 1 from bpf program.
3108+ *
3109+ * **-EINVAL** if arguments are invalid, or if *fmt* is invalid/unsupported.
3110+ *
3111+ * **-E2BIG** if *fmt* contains too many format specifiers.
3112+ *
3113+ * **-EOVERFLOW** if an overflow happened: The same object will be tried again.
3114+ *
3115+ * int bpf_seq_write(struct seq_file *m, const void *data, u32 len)
3116+ * Description
3117+ * **bpf_seq_write**\ () uses seq_file **seq_write**\ () to write the data.
3118+ * The *m* represents the seq_file. The *data* and *len* represent the
3119+ * data to write in bytes.
3120+ * Return
3121+ * 0 on success, or a negative error in case of failure:
3122+ *
3123+ * **-EOVERFLOW** if an overflow happened: The same object will be tried again.
3124+ *
3125+ * u64 bpf_sk_cgroup_id(struct bpf_sock *sk)
3126+ * Description
3127+ * Return the cgroup v2 id of the socket *sk*.
3128+ *
3129+ * *sk* must be a non-**NULL** pointer to a full socket, e.g. one
3130+ * returned from **bpf_sk_lookup_xxx**\ (),
3131+ * **bpf_sk_fullsock**\ (), etc. The format of returned id is
3132+ * same as in **bpf_skb_cgroup_id**\ ().
3133+ *
3134+ * This helper is available only if the kernel was compiled with
3135+ * the **CONFIG_SOCK_CGROUP_DATA** configuration option.
3136+ * Return
3137+ * The id is returned or 0 in case the id could not be retrieved.
3138+ *
3139+ * u64 bpf_sk_ancestor_cgroup_id(struct bpf_sock *sk, int ancestor_level)
3140+ * Description
3141+ * Return id of cgroup v2 that is ancestor of cgroup associated
3142+ * with the *sk* at the *ancestor_level*. The root cgroup is at
3143+ * *ancestor_level* zero and each step down the hierarchy
3144+ * increments the level. If *ancestor_level* == level of cgroup
3145+ * associated with *sk*, then return value will be same as that
3146+ * of **bpf_sk_cgroup_id**\ ().
3147+ *
3148+ * The helper is useful to implement policies based on cgroups
3149+ * that are upper in hierarchy than immediate cgroup associated
3150+ * with *sk*.
3151+ *
3152+ * The format of returned id and helper limitations are same as in
3153+ * **bpf_sk_cgroup_id**\ ().
3154+ * Return
3155+ * The id is returned or 0 in case the id could not be retrieved.
30713156 */
30723157 #define __BPF_FUNC_MAPPER(FN) \
30733158 FN(unspec), \
@@ -3195,7 +3280,11 @@ union bpf_attr { · 121 unmodified lines
31953280 FN(get_netns_cookie), \
31963281 FN(get_current_ancestor_cgroup_id), \
31973282 FN(sk_assign), \
3198− FN(ktime_get_boot_ns),
3283+ FN(ktime_get_boot_ns), \
3284+ FN(seq_printf), \
3285+ FN(seq_write), \
3286+ FN(sk_cgroup_id), \
3287+ FN(sk_ancestor_cgroup_id),
31993288
32003289 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
32013290 * function eBPF program intends to call
@@ -3673,7 +3762,7 @@ struct bpf_sock_addr { · 471 unmodified lines
36733762 __u32 user_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.
36743763 * Stored in network byte order.
36753764 */
3676− __u32 user_port; /* Allows 4-byte read and write.
3765+ __u32 user_port; /* Allows 1,2,4-byte read and 4-byte write.
36773766 * Stored in network byte order
36783767 */
36793768 __u32 family; /* Allows 4-byte read, but no write */
include/uapi/linux/capability.h+7−1
@@ -367,8 +367,14 @@ struct vfs_ns_cap_data { · 366 unmodified lines
367367
368368 #define CAP_AUDIT_READ 37
369369
370+/*
371+ * Allow system performance and observability privileged operations
372+ * using perf_events, i915_perf and other kernel subsystems
373+ */
374+
375+#define CAP_PERFMON 38
370376
371−#define CAP_LAST_CAP CAP_AUDIT_READ
377+#define CAP_LAST_CAP CAP_PERFMON
372378
373379 #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
374380