History

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

Alexei Starovoitov says: ==================== pull-request: bpf-next 2018-01-26 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) A number of extensions to tcp-bpf, from Lawrence. - direct R or R/W access to many tcp_sock fields via bpf_sock_ops - passing up to 3 arguments to bpf_sock_ops functions - tcp_sock field bpf_sock_ops_cb_flags for controlling callbacks - optionally calling bpf_sock_ops program when RTO fires - optionally calling bpf_sock_ops program when packet is retransmitted - optionally calling bpf_sock_ops program when TCP state changes - access to tclass and sk_txhash - new selftest 2) div/mod exception handling, from Daniel. One of the ugly leftovers from the early eBPF days is that div/mod operations based on registers have a hard-coded src_reg == 0 test in the interpreter as well as in JIT code generators that would return from the BPF program with exit code 0. This was basically adopted from cBPF interpreter for historical reasons. There are multiple reasons why this is very suboptimal and prone to bugs. To name one: the return code mapping for such abnormal program exit of 0 does not always match with a suitable program type's exit code mapping. For example, '0' in tc means action 'ok' where the packet gets passed further up the stack, which is just undesirable for such cases (e.g. when implementing policy) and also does not match with other program types. After considering _four_ different ways to address the problem, we adapt the same behavior as on some major archs like ARMv8: X div 0 results in 0, and X mod 0 results in X. aarch64 and aarch32 ISA do not generate any traps or otherwise aborts of program execution for unsigned divides. Given the options, it seems the most suitable from all of them, also since major archs have similar schemes in place. Given this is all in the realm of undefined behavior, we still have the option to adapt if deemed necessary. 3) sockmap sample refactoring, from John. 4) lpm map get_next_key fixes, from Yonghong. 5) test cleanups, from Alexei and Prashant. ====================

David S. Miller committed 8 years ago

Commit 457740a2 parents 6b2e282 822396737 files · +1969 −378Browse files

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

Unified · Split

include/uapi/linux/bpf.h+81−3
@@ -642,6 +642,14 @@ union bpf_attr { · 641 unmodified lines
642642 * @optlen: length of optval in bytes
643643 * Return: 0 or negative error
644644 *
645+ * int bpf_sock_ops_cb_flags_set(bpf_sock_ops, flags)
646+ * Set callback flags for sock_ops
647+ * @bpf_sock_ops: pointer to bpf_sock_ops_kern struct
648+ * @flags: flags value
649+ * Return: 0 for no error
650+ * -EINVAL if there is no full tcp socket
651+ * bits in flags that are not supported by current kernel
652+ *
645653 * int bpf_skb_adjust_room(skb, len_diff, mode, flags)
646654 * Grow or shrink room in sk_buff.
647655 * @skb: pointer to skb
@@ -748,7 +756,8 @@ union bpf_attr { · 100 unmodified lines
748756 FN(perf_event_read_value), \
749757 FN(perf_prog_read_value), \
750758 FN(getsockopt), \
751− FN(override_return),
759+ FN(override_return), \
760+ FN(sock_ops_cb_flags_set),
752761
753762 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
754763 * function eBPF program intends to call
@@ -952,8 +961,9 @@ struct bpf_map_info { · 197 unmodified lines
952961 struct bpf_sock_ops {
953962 __u32 op;
954963 union {
955− __u32 reply;
956− __u32 replylong[4];
964+ __u32 args[4]; /* Optionally passed to bpf program */
965+ __u32 reply; /* Returned by bpf program */
966+ __u32 replylong[4]; /* Optionally returned by bpf prog */
957967 };
958968 __u32 family;
959969 __u32 remote_ip4; /* Stored in network byte order */
@@ -968,8 +978,39 @@ struct bpf_sock_ops { · 8 unmodified lines
968978 */
969979 __u32 snd_cwnd;
970980 __u32 srtt_us; /* Averaged RTT << 3 in usecs */
981+ __u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
982+ __u32 state;
983+ __u32 rtt_min;
984+ __u32 snd_ssthresh;
985+ __u32 rcv_nxt;
986+ __u32 snd_nxt;
987+ __u32 snd_una;
988+ __u32 mss_cache;
989+ __u32 ecn_flags;
990+ __u32 rate_delivered;
991+ __u32 rate_interval_us;
992+ __u32 packets_out;
993+ __u32 retrans_out;
994+ __u32 total_retrans;
995+ __u32 segs_in;
996+ __u32 data_segs_in;
997+ __u32 segs_out;
998+ __u32 data_segs_out;
999+ __u32 lost_out;
1000+ __u32 sacked_out;
1001+ __u32 sk_txhash;
1002+ __u64 bytes_received;
1003+ __u64 bytes_acked;
9711004 };
9721005
1006+/* Definitions for bpf_sock_ops_cb_flags */
1007+#define BPF_SOCK_OPS_RTO_CB_FLAG (1<<0)
1008+#define BPF_SOCK_OPS_RETRANS_CB_FLAG (1<<1)
1009+#define BPF_SOCK_OPS_STATE_CB_FLAG (1<<2)
1010+#define BPF_SOCK_OPS_ALL_CB_FLAGS 0x7 /* Mask of all currently
1011+ * supported cb flags
1012+ */
1013+
9731014 /* List of known BPF sock_ops operators.
9741015 * New entries can only be added at the end
9751016 */
@@ -1003,6 +1044,43 @@ enum { · 27 unmodified lines
10031044 * a congestion threshold. RTTs above
10041045 * this indicate congestion
10051046 */
1047+ BPF_SOCK_OPS_RTO_CB, /* Called when an RTO has triggered.
1048+ * Arg1: value of icsk_retransmits
1049+ * Arg2: value of icsk_rto
1050+ * Arg3: whether RTO has expired
1051+ */
1052+ BPF_SOCK_OPS_RETRANS_CB, /* Called when skb is retransmitted.
1053+ * Arg1: sequence number of 1st byte
1054+ * Arg2: # segments
1055+ * Arg3: return value of
1056+ * tcp_transmit_skb (0 => success)
1057+ */
1058+ BPF_SOCK_OPS_STATE_CB, /* Called when TCP changes state.
1059+ * Arg1: old_state
1060+ * Arg2: new_state
1061+ */
1062+};
1063+
1064+/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
1065+ * changes between the TCP and BPF versions. Ideally this should never happen.
1066+ * If it does, we need to add code to convert them before calling
1067+ * the BPF sock_ops function.
1068+ */
1069+enum {
1070+ BPF_TCP_ESTABLISHED = 1,
1071+ BPF_TCP_SYN_SENT,
1072+ BPF_TCP_SYN_RECV,
1073+ BPF_TCP_FIN_WAIT1,
1074+ BPF_TCP_FIN_WAIT2,
1075+ BPF_TCP_TIME_WAIT,
1076+ BPF_TCP_CLOSE,
1077+ BPF_TCP_CLOSE_WAIT,
1078+ BPF_TCP_LAST_ACK,
1079+ BPF_TCP_LISTEN,
1080+ BPF_TCP_CLOSING, /* Now a valid state */
1081+ BPF_TCP_NEW_SYN_RECV,
1082+
1083+ BPF_TCP_MAX_STATES /* Leave at the end! */
10061084 };
10071085
10081086 #define TCP_BPF_IW 1001 /* Set TCP initial congestion window */