Skip to content

Commit dca73a6

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Alexei Starovoitov says: ==================== pull-request: bpf-next 2019-06-19 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) new SO_REUSEPORT_DETACH_BPF setsocktopt, from Martin. 2) BTF based map definition, from Andrii. 3) support bpf_map_lookup_elem for xskmap, from Jonathan. 4) bounded loops and scalar precision logic in the verifier, from Alexei. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 497ad9f + 94079b6 commit dca73a6

101 files changed

Lines changed: 4048 additions & 860 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/alpha/include/uapi/asm/socket.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
#define SO_RCVTIMEO_NEW 66
123123
#define SO_SNDTIMEO_NEW 67
124124

125+
#define SO_DETACH_REUSEPORT_BPF 68
126+
125127
#if !defined(__KERNEL__)
126128

127129
#if __BITS_PER_LONG == 64

‎arch/mips/include/uapi/asm/socket.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
#define SO_RCVTIMEO_NEW 66
134134
#define SO_SNDTIMEO_NEW 67
135135

136+
#define SO_DETACH_REUSEPORT_BPF 68
137+
136138
#if !defined(__KERNEL__)
137139

138140
#if __BITS_PER_LONG == 64

‎arch/parisc/include/uapi/asm/socket.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
#define SO_RCVTIMEO_NEW 0x4040
115115
#define SO_SNDTIMEO_NEW 0x4041
116116

117+
#define SO_DETACH_REUSEPORT_BPF 0x4042
118+
117119
#if !defined(__KERNEL__)
118120

119121
#if __BITS_PER_LONG == 64

‎arch/sparc/include/uapi/asm/socket.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@
115115
#define SO_RCVTIMEO_NEW 0x0044
116116
#define SO_SNDTIMEO_NEW 0x0045
117117

118+
#define SO_DETACH_REUSEPORT_BPF 0x0047
119+
118120
#if !defined(__KERNEL__)
119121

120122

‎include/linux/bpf.h‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ enum bpf_reg_type {
277277
PTR_TO_TCP_SOCK, /* reg points to struct tcp_sock */
278278
PTR_TO_TCP_SOCK_OR_NULL, /* reg points to struct tcp_sock or NULL */
279279
PTR_TO_TP_BUFFER, /* reg points to a writable raw tp's buffer */
280+
PTR_TO_XDP_SOCK, /* reg points to struct xdp_sock */
280281
};
281282

282283
/* The information passed from prog-specific *_is_valid_access
@@ -1098,6 +1099,15 @@ u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,
10981099
struct bpf_insn *insn_buf,
10991100
struct bpf_prog *prog,
11001101
u32 *target_size);
1102+
1103+
bool bpf_xdp_sock_is_valid_access(int off, int size, enum bpf_access_type type,
1104+
struct bpf_insn_access_aux *info);
1105+
1106+
u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,
1107+
const struct bpf_insn *si,
1108+
struct bpf_insn *insn_buf,
1109+
struct bpf_prog *prog,
1110+
u32 *target_size);
11011111
#else
11021112
static inline bool bpf_tcp_sock_is_valid_access(int off, int size,
11031113
enum bpf_access_type type,
@@ -1114,6 +1124,21 @@ static inline u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,
11141124
{
11151125
return 0;
11161126
}
1127+
static inline bool bpf_xdp_sock_is_valid_access(int off, int size,
1128+
enum bpf_access_type type,
1129+
struct bpf_insn_access_aux *info)
1130+
{
1131+
return false;
1132+
}
1133+
1134+
static inline u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,
1135+
const struct bpf_insn *si,
1136+
struct bpf_insn *insn_buf,
1137+
struct bpf_prog *prog,
1138+
u32 *target_size)
1139+
{
1140+
return 0;
1141+
}
11171142
#endif /* CONFIG_INET */
11181143

11191144
#endif /* _LINUX_BPF_H */

‎include/linux/bpf_verifier.h‎

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ struct bpf_reg_state {
136136
*/
137137
s32 subreg_def;
138138
enum bpf_reg_liveness live;
139+
/* if (!precise && SCALAR_VALUE) min/max/tnum don't affect safety */
140+
bool precise;
139141
};
140142

141143
enum bpf_stack_slot_type {
@@ -187,14 +189,77 @@ struct bpf_func_state {
187189
struct bpf_stack_state *stack;
188190
};
189191

192+
struct bpf_idx_pair {
193+
u32 prev_idx;
194+
u32 idx;
195+
};
196+
190197
#define MAX_CALL_FRAMES 8
191198
struct bpf_verifier_state {
192199
/* call stack tracking */
193200
struct bpf_func_state *frame[MAX_CALL_FRAMES];
201+
struct bpf_verifier_state *parent;
202+
/*
203+
* 'branches' field is the number of branches left to explore:
204+
* 0 - all possible paths from this state reached bpf_exit or
205+
* were safely pruned
206+
* 1 - at least one path is being explored.
207+
* This state hasn't reached bpf_exit
208+
* 2 - at least two paths are being explored.
209+
* This state is an immediate parent of two children.
210+
* One is fallthrough branch with branches==1 and another
211+
* state is pushed into stack (to be explored later) also with
212+
* branches==1. The parent of this state has branches==1.
213+
* The verifier state tree connected via 'parent' pointer looks like:
214+
* 1
215+
* 1
216+
* 2 -> 1 (first 'if' pushed into stack)
217+
* 1
218+
* 2 -> 1 (second 'if' pushed into stack)
219+
* 1
220+
* 1
221+
* 1 bpf_exit.
222+
*
223+
* Once do_check() reaches bpf_exit, it calls update_branch_counts()
224+
* and the verifier state tree will look:
225+
* 1
226+
* 1
227+
* 2 -> 1 (first 'if' pushed into stack)
228+
* 1
229+
* 1 -> 1 (second 'if' pushed into stack)
230+
* 0
231+
* 0
232+
* 0 bpf_exit.
233+
* After pop_stack() the do_check() will resume at second 'if'.
234+
*
235+
* If is_state_visited() sees a state with branches > 0 it means
236+
* there is a loop. If such state is exactly equal to the current state
237+
* it's an infinite loop. Note states_equal() checks for states
238+
* equvalency, so two states being 'states_equal' does not mean
239+
* infinite loop. The exact comparison is provided by
240+
* states_maybe_looping() function. It's a stronger pre-check and
241+
* much faster than states_equal().
242+
*
243+
* This algorithm may not find all possible infinite loops or
244+
* loop iteration count may be too high.
245+
* In such cases BPF_COMPLEXITY_LIMIT_INSNS limit kicks in.
246+
*/
247+
u32 branches;
194248
u32 insn_idx;
195249
u32 curframe;
196250
u32 active_spin_lock;
197251
bool speculative;
252+
253+
/* first and last insn idx of this verifier state */
254+
u32 first_insn_idx;
255+
u32 last_insn_idx;
256+
/* jmp history recorded from first to last.
257+
* backtracking is using it to go from last to first.
258+
* For most states jmp_history_cnt is [0-3].
259+
* For loops can go up to ~40.
260+
*/
261+
struct bpf_idx_pair *jmp_history;
262+
u32 jmp_history_cnt;
198263
};
199264

200265
#define bpf_get_spilled_reg(slot, frame) \
@@ -309,7 +374,9 @@ struct bpf_verifier_env {
309374
} cfg;
310375
u32 subprog_cnt;
311376
/* number of instructions analyzed by the verifier */
312-
u32 insn_processed;
377+
u32 prev_insn_processed, insn_processed;
378+
/* number of jmps, calls, exits analyzed so far */
379+
u32 prev_jmps_processed, jmps_processed;
313380
/* total verification time */
314381
u64 verification_time;
315382
/* maximum number of verifier states kept in 'branching' instructions */

‎include/net/sock_reuseport.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extern struct sock *reuseport_select_sock(struct sock *sk,
3535
struct sk_buff *skb,
3636
int hdr_len);
3737
extern int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog);
38+
extern int reuseport_detach_prog(struct sock *sk);
39+
3840
int reuseport_get_id(struct sock_reuseport *reuse);
3941

4042
#endif /* _SOCK_REUSEPORT_H */

‎include/net/xdp_sock.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ struct xdp_sock {
5858
struct xdp_umem *umem;
5959
struct list_head flush_node;
6060
u16 queue_id;
61-
struct xsk_queue *tx ____cacheline_aligned_in_smp;
62-
struct list_head list;
6361
bool zc;
6462
/* Protects multiple processes in the control path */
6563
struct mutex mutex;
64+
struct xsk_queue *tx ____cacheline_aligned_in_smp;
65+
struct list_head list;
6666
/* Mutual exclusion of NAPI TX thread and sendmsg error paths
6767
* in the SKB destructor callback.
6868
*/

‎include/uapi/asm-generic/socket.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
#define SO_RCVTIMEO_NEW 66
118118
#define SO_SNDTIMEO_NEW 67
119119

120+
#define SO_DETACH_REUSEPORT_BPF 68
121+
120122
#if !defined(__KERNEL__)
121123

122124
#if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))

‎include/uapi/linux/bpf.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,6 +3085,10 @@ struct bpf_sock_tuple {
30853085
};
30863086
};
30873087

3088+
struct bpf_xdp_sock {
3089+
__u32 queue_id;
3090+
};
3091+
30883092
#define XDP_PACKET_HEADROOM 256
30893093

30903094
/* User return codes for XDP prog type.
@@ -3245,6 +3249,7 @@ struct bpf_sock_addr {
32453249
__u32 msg_src_ip6[4]; /* Allows 1,2,4-byte read an 4-byte write.
32463250
* Stored in network byte order.
32473251
*/
3252+
__bpf_md_ptr(struct bpf_sock *, sk);
32483253
};
32493254

32503255
/* User bpf_sock_ops struct to access socket values and specify request ops
@@ -3296,6 +3301,7 @@ struct bpf_sock_ops {
32963301
__u32 sk_txhash;
32973302
__u64 bytes_received;
32983303
__u64 bytes_acked;
3304+
__bpf_md_ptr(struct bpf_sock *, sk);
32993305
};
33003306

33013307
/* Definitions for bpf_sock_ops_cb_flags */

0 commit comments

Comments
 (0)