Skip to content

Commit 9a5a908

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2020-06-02 The following pull-request contains BPF _fixes-only_ for your *net-next* tree. We've added 10 non-merge commits during the last 1 day(s) which contain a total of 15 files changed, 229 insertions(+), 74 deletions(-). The main changes are: 1) Several fixes to s390 BPF JIT e.g. fixing kernel panic when BPF stack is not 8-byte aligned, from Ilya Leoshkevich. 2) Fix bpf_skb_adjust_room() helper's CHECKSUM_UNNECESSARY handling which was wrongly bypassing TCP checksum verification, from Daniel Borkmann. 3) Fix tools/bpf/ build under MAKEFLAGS=rR which causes built-in CXX and others vars to be undefined, also from Ilya Leoshkevich. 4) Fix BPF ringbuf's selftest shared sample_cnt variable to avoid compiler optimizations on it, from Andrii Nakryiko. 5) Fix up test_verifier selftest due to addition of rx_queue_mapping to the bpf_sock structure, from Alexei Starovoitov. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 9a25c1d + e7ad28e commit 9a5a908

File tree

15 files changed

+229
-74
lines changed

15 files changed

+229
-74
lines changed

arch/s390/net/bpf_jit_comp.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ static void bpf_jit_prologue(struct bpf_jit *jit, u32 stack_depth)
503503
} else {
504504
/* j tail_call_start: NOP if no tail calls are used */
505505
EMIT4_PCREL(0xa7f40000, 6);
506-
_EMIT2(0);
506+
/* bcr 0,%0 */
507+
EMIT2(0x0700, 0, REG_0);
507508
}
508509
/* Tail calls have to skip above initialization */
509510
jit->tail_call_start = jit->prg;
@@ -594,7 +595,7 @@ static void bpf_jit_epilogue(struct bpf_jit *jit, u32 stack_depth)
594595
* stack space for the large switch statement.
595596
*/
596597
static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
597-
int i, bool extra_pass)
598+
int i, bool extra_pass, u32 stack_depth)
598599
{
599600
struct bpf_insn *insn = &fp->insnsi[i];
600601
u32 dst_reg = insn->dst_reg;
@@ -1207,7 +1208,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
12071208
*/
12081209

12091210
if (jit->seen & SEEN_STACK)
1210-
off = STK_OFF_TCCNT + STK_OFF + fp->aux->stack_depth;
1211+
off = STK_OFF_TCCNT + STK_OFF + stack_depth;
12111212
else
12121213
off = STK_OFF_TCCNT;
12131214
/* lhi %w0,1 */
@@ -1249,7 +1250,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
12491250
/*
12501251
* Restore registers before calling function
12511252
*/
1252-
save_restore_regs(jit, REGS_RESTORE, fp->aux->stack_depth);
1253+
save_restore_regs(jit, REGS_RESTORE, stack_depth);
12531254

12541255
/*
12551256
* goto *(prog->bpf_func + tail_call_start);
@@ -1519,26 +1520,26 @@ static int bpf_set_addr(struct bpf_jit *jit, int i)
15191520
* Compile eBPF program into s390x code
15201521
*/
15211522
static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp,
1522-
bool extra_pass)
1523+
bool extra_pass, u32 stack_depth)
15231524
{
15241525
int i, insn_count, lit32_size, lit64_size;
15251526

15261527
jit->lit32 = jit->lit32_start;
15271528
jit->lit64 = jit->lit64_start;
15281529
jit->prg = 0;
15291530

1530-
bpf_jit_prologue(jit, fp->aux->stack_depth);
1531+
bpf_jit_prologue(jit, stack_depth);
15311532
if (bpf_set_addr(jit, 0) < 0)
15321533
return -1;
15331534
for (i = 0; i < fp->len; i += insn_count) {
1534-
insn_count = bpf_jit_insn(jit, fp, i, extra_pass);
1535+
insn_count = bpf_jit_insn(jit, fp, i, extra_pass, stack_depth);
15351536
if (insn_count < 0)
15361537
return -1;
15371538
/* Next instruction address */
15381539
if (bpf_set_addr(jit, i + insn_count) < 0)
15391540
return -1;
15401541
}
1541-
bpf_jit_epilogue(jit, fp->aux->stack_depth);
1542+
bpf_jit_epilogue(jit, stack_depth);
15421543

15431544
lit32_size = jit->lit32 - jit->lit32_start;
15441545
lit64_size = jit->lit64 - jit->lit64_start;
@@ -1569,6 +1570,7 @@ struct s390_jit_data {
15691570
*/
15701571
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
15711572
{
1573+
u32 stack_depth = round_up(fp->aux->stack_depth, 8);
15721574
struct bpf_prog *tmp, *orig_fp = fp;
15731575
struct bpf_binary_header *header;
15741576
struct s390_jit_data *jit_data;
@@ -1621,7 +1623,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
16211623
* - 3: Calculate program size and addrs arrray
16221624
*/
16231625
for (pass = 1; pass <= 3; pass++) {
1624-
if (bpf_jit_prog(&jit, fp, extra_pass)) {
1626+
if (bpf_jit_prog(&jit, fp, extra_pass, stack_depth)) {
16251627
fp = orig_fp;
16261628
goto free_addrs;
16271629
}
@@ -1635,7 +1637,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
16351637
goto free_addrs;
16361638
}
16371639
skip_init_ctx:
1638-
if (bpf_jit_prog(&jit, fp, extra_pass)) {
1640+
if (bpf_jit_prog(&jit, fp, extra_pass, stack_depth)) {
16391641
bpf_jit_binary_free(header);
16401642
fp = orig_fp;
16411643
goto free_addrs;

include/linux/skbuff.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3919,6 +3919,14 @@ static inline void __skb_incr_checksum_unnecessary(struct sk_buff *skb)
39193919
}
39203920
}
39213921

3922+
static inline void __skb_reset_checksum_unnecessary(struct sk_buff *skb)
3923+
{
3924+
if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
3925+
skb->ip_summed = CHECKSUM_NONE;
3926+
skb->csum_level = 0;
3927+
}
3928+
}
3929+
39223930
/* Check if we need to perform checksum complete validation.
39233931
*
39243932
* Returns true if checksum complete is needed, false otherwise

include/uapi/linux/bpf.h

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,13 @@ union bpf_attr {
16351635
* Grow or shrink the room for data in the packet associated to
16361636
* *skb* by *len_diff*, and according to the selected *mode*.
16371637
*
1638+
* By default, the helper will reset any offloaded checksum
1639+
* indicator of the skb to CHECKSUM_NONE. This can be avoided
1640+
* by the following flag:
1641+
*
1642+
* * **BPF_F_ADJ_ROOM_NO_CSUM_RESET**: Do not reset offloaded
1643+
* checksum data of the skb to CHECKSUM_NONE.
1644+
*
16381645
* There are two supported modes at this time:
16391646
*
16401647
* * **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
@@ -3213,6 +3220,38 @@ union bpf_attr {
32133220
* calculation.
32143221
* Return
32153222
* Requested value, or 0, if flags are not recognized.
3223+
*
3224+
* int bpf_csum_level(struct sk_buff *skb, u64 level)
3225+
* Description
3226+
* Change the skbs checksum level by one layer up or down, or
3227+
* reset it entirely to none in order to have the stack perform
3228+
* checksum validation. The level is applicable to the following
3229+
* protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of
3230+
* | ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |
3231+
* through **bpf_skb_adjust_room**\ () helper with passing in
3232+
* **BPF_F_ADJ_ROOM_NO_CSUM_RESET** flag would require one call
3233+
* to **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_DEC** since
3234+
* the UDP header is removed. Similarly, an encap of the latter
3235+
* into the former could be accompanied by a helper call to
3236+
* **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_INC** if the
3237+
* skb is still intended to be processed in higher layers of the
3238+
* stack instead of just egressing at tc.
3239+
*
3240+
* There are three supported level settings at this time:
3241+
*
3242+
* * **BPF_CSUM_LEVEL_INC**: Increases skb->csum_level for skbs
3243+
* with CHECKSUM_UNNECESSARY.
3244+
* * **BPF_CSUM_LEVEL_DEC**: Decreases skb->csum_level for skbs
3245+
* with CHECKSUM_UNNECESSARY.
3246+
* * **BPF_CSUM_LEVEL_RESET**: Resets skb->csum_level to 0 and
3247+
* sets CHECKSUM_NONE to force checksum validation by the stack.
3248+
* * **BPF_CSUM_LEVEL_QUERY**: No-op, returns the current
3249+
* skb->csum_level.
3250+
* Return
3251+
* 0 on success, or a negative error in case of failure. In the
3252+
* case of **BPF_CSUM_LEVEL_QUERY**, the current skb->csum_level
3253+
* is returned or the error code -EACCES in case the skb is not
3254+
* subject to CHECKSUM_UNNECESSARY.
32163255
*/
32173256
#define __BPF_FUNC_MAPPER(FN) \
32183257
FN(unspec), \
@@ -3349,7 +3388,8 @@ union bpf_attr {
33493388
FN(ringbuf_reserve), \
33503389
FN(ringbuf_submit), \
33513390
FN(ringbuf_discard), \
3352-
FN(ringbuf_query),
3391+
FN(ringbuf_query), \
3392+
FN(csum_level),
33533393

33543394
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
33553395
* function eBPF program intends to call
@@ -3426,13 +3466,22 @@ enum {
34263466
BPF_F_CURRENT_NETNS = (-1L),
34273467
};
34283468

3469+
/* BPF_FUNC_csum_level level values. */
3470+
enum {
3471+
BPF_CSUM_LEVEL_QUERY,
3472+
BPF_CSUM_LEVEL_INC,
3473+
BPF_CSUM_LEVEL_DEC,
3474+
BPF_CSUM_LEVEL_RESET,
3475+
};
3476+
34293477
/* BPF_FUNC_skb_adjust_room flags. */
34303478
enum {
34313479
BPF_F_ADJ_ROOM_FIXED_GSO = (1ULL << 0),
34323480
BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 = (1ULL << 1),
34333481
BPF_F_ADJ_ROOM_ENCAP_L3_IPV6 = (1ULL << 2),
34343482
BPF_F_ADJ_ROOM_ENCAP_L4_GRE = (1ULL << 3),
34353483
BPF_F_ADJ_ROOM_ENCAP_L4_UDP = (1ULL << 4),
3484+
BPF_F_ADJ_ROOM_NO_CSUM_RESET = (1ULL << 5),
34363485
};
34373486

34383487
enum {

net/core/filter.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,40 @@ static const struct bpf_func_proto bpf_csum_update_proto = {
20152015
.arg2_type = ARG_ANYTHING,
20162016
};
20172017

2018+
BPF_CALL_2(bpf_csum_level, struct sk_buff *, skb, u64, level)
2019+
{
2020+
/* The interface is to be used in combination with bpf_skb_adjust_room()
2021+
* for encap/decap of packet headers when BPF_F_ADJ_ROOM_NO_CSUM_RESET
2022+
* is passed as flags, for example.
2023+
*/
2024+
switch (level) {
2025+
case BPF_CSUM_LEVEL_INC:
2026+
__skb_incr_checksum_unnecessary(skb);
2027+
break;
2028+
case BPF_CSUM_LEVEL_DEC:
2029+
__skb_decr_checksum_unnecessary(skb);
2030+
break;
2031+
case BPF_CSUM_LEVEL_RESET:
2032+
__skb_reset_checksum_unnecessary(skb);
2033+
break;
2034+
case BPF_CSUM_LEVEL_QUERY:
2035+
return skb->ip_summed == CHECKSUM_UNNECESSARY ?
2036+
skb->csum_level : -EACCES;
2037+
default:
2038+
return -EINVAL;
2039+
}
2040+
2041+
return 0;
2042+
}
2043+
2044+
static const struct bpf_func_proto bpf_csum_level_proto = {
2045+
.func = bpf_csum_level,
2046+
.gpl_only = false,
2047+
.ret_type = RET_INTEGER,
2048+
.arg1_type = ARG_PTR_TO_CTX,
2049+
.arg2_type = ARG_ANYTHING,
2050+
};
2051+
20182052
static inline int __bpf_rx_skb(struct net_device *dev, struct sk_buff *skb)
20192053
{
20202054
return dev_forward_skb(dev, skb);
@@ -3113,7 +3147,8 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff,
31133147
{
31143148
int ret;
31153149

3116-
if (flags & ~BPF_F_ADJ_ROOM_FIXED_GSO)
3150+
if (unlikely(flags & ~(BPF_F_ADJ_ROOM_FIXED_GSO |
3151+
BPF_F_ADJ_ROOM_NO_CSUM_RESET)))
31173152
return -EINVAL;
31183153

31193154
if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) {
@@ -3163,7 +3198,8 @@ BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *, skb, s32, len_diff,
31633198
u32 off;
31643199
int ret;
31653200

3166-
if (unlikely(flags & ~BPF_F_ADJ_ROOM_MASK))
3201+
if (unlikely(flags & ~(BPF_F_ADJ_ROOM_MASK |
3202+
BPF_F_ADJ_ROOM_NO_CSUM_RESET)))
31673203
return -EINVAL;
31683204
if (unlikely(len_diff_abs > 0xfffU))
31693205
return -EFAULT;
@@ -3191,6 +3227,8 @@ BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *, skb, s32, len_diff,
31913227

31923228
ret = shrink ? bpf_skb_net_shrink(skb, off, len_diff_abs, flags) :
31933229
bpf_skb_net_grow(skb, off, len_diff_abs, flags);
3230+
if (!ret && !(flags & BPF_F_ADJ_ROOM_NO_CSUM_RESET))
3231+
__skb_reset_checksum_unnecessary(skb);
31943232

31953233
bpf_compute_data_pointers(skb);
31963234
return ret;
@@ -6276,6 +6314,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
62766314
return &bpf_csum_diff_proto;
62776315
case BPF_FUNC_csum_update:
62786316
return &bpf_csum_update_proto;
6317+
case BPF_FUNC_csum_level:
6318+
return &bpf_csum_level_proto;
62796319
case BPF_FUNC_l3_csum_replace:
62806320
return &bpf_l3_csum_replace_proto;
62816321
case BPF_FUNC_l4_csum_replace:
@@ -6609,6 +6649,8 @@ lwt_xmit_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
66096649
return &bpf_skb_store_bytes_proto;
66106650
case BPF_FUNC_csum_update:
66116651
return &bpf_csum_update_proto;
6652+
case BPF_FUNC_csum_level:
6653+
return &bpf_csum_level_proto;
66126654
case BPF_FUNC_l3_csum_replace:
66136655
return &bpf_l3_csum_replace_proto;
66146656
case BPF_FUNC_l4_csum_replace:

tools/bpf/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
6464
$(QUIET_FLEX)$(LEX) -o $@ $<
6565

6666
$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
67-
$(QUIET_CC)$(COMPILE.c) -o $@ $<
67+
$(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
6868

6969
$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
70-
$(QUIET_CC)$(COMPILE.c) -o $@ $<
70+
$(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
7171
$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
72-
$(QUIET_CC)$(COMPILE.c) -o $@ $<
72+
$(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
7373

7474
PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
7575

tools/bpf/bpftool/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ else
126126
endif
127127

128128
$(OUTPUT)_prog.o: prog.c
129-
$(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $<
129+
$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $<
130130

131131
$(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF)
132132
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS)
@@ -141,18 +141,18 @@ profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o
141141
$(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@
142142

143143
$(OUTPUT)prog.o: prog.c profiler.skel.h
144-
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
144+
$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
145145

146146
$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
147-
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
147+
$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
148148

149149
$(OUTPUT)feature.o: | zdep
150150

151151
$(OUTPUT)bpftool: $(__OBJS) $(LIBBPF)
152152
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(__OBJS) $(LIBS)
153153

154154
$(OUTPUT)%.o: %.c
155-
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
155+
$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
156156

157157
clean: $(LIBBPF)-clean
158158
$(call QUIET_CLEAN, bpftool)

0 commit comments

Comments
 (0)