Skip to content

Commit 28f2c36

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2019-09-16 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Now that initial BPF backend for gcc has been merged upstream, enable BPF kselftest suite for bpf-gcc. Also fix a BE issue with access to bpf_sysctl.file_pos, from Ilya. 2) Follow-up fix for link-vmlinux.sh to remove bash-specific extensions related to recent work on exposing BTF info through sysfs, from Andrii. 3) AF_XDP zero copy fixes for i40e and ixgbe driver which caused umem headroom to be added twice, from Ciara. 4) Refactoring work to convert sock opt tests into test_progs framework in BPF kselftests, from Stanislav. 5) Fix a general protection fault in dev_map_hash_update_elem(), from Toke. 6) Cleanup to use BPF_PROG_RUN() macro in KCM, from Sami. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 5f109d4 + d895a0f commit 28f2c36

File tree

21 files changed

+260
-322
lines changed

21 files changed

+260
-322
lines changed

drivers/net/ethernet/intel/i40e/i40e_xsk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ static int i40e_run_xdp_zc(struct i40e_ring *rx_ring, struct xdp_buff *xdp)
197197
{
198198
struct xdp_umem *umem = rx_ring->xsk_umem;
199199
int err, result = I40E_XDP_PASS;
200-
u64 offset = umem->headroom;
201200
struct i40e_ring *xdp_ring;
202201
struct bpf_prog *xdp_prog;
202+
u64 offset;
203203
u32 act;
204204

205205
rcu_read_lock();
@@ -208,7 +208,7 @@ static int i40e_run_xdp_zc(struct i40e_ring *rx_ring, struct xdp_buff *xdp)
208208
*/
209209
xdp_prog = READ_ONCE(rx_ring->xdp_prog);
210210
act = bpf_prog_run_xdp(xdp_prog, xdp);
211-
offset += xdp->data - xdp->data_hard_start;
211+
offset = xdp->data - xdp->data_hard_start;
212212

213213
xdp->handle = xsk_umem_adjust_offset(umem, xdp->handle, offset);
214214

drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ static int ixgbe_run_xdp_zc(struct ixgbe_adapter *adapter,
145145
{
146146
struct xdp_umem *umem = rx_ring->xsk_umem;
147147
int err, result = IXGBE_XDP_PASS;
148-
u64 offset = umem->headroom;
149148
struct bpf_prog *xdp_prog;
150149
struct xdp_frame *xdpf;
150+
u64 offset;
151151
u32 act;
152152

153153
rcu_read_lock();
154154
xdp_prog = READ_ONCE(rx_ring->xdp_prog);
155155
act = bpf_prog_run_xdp(xdp_prog, xdp);
156-
offset += xdp->data - xdp->data_hard_start;
156+
offset = xdp->data - xdp->data_hard_start;
157157

158158
xdp->handle = xsk_umem_adjust_offset(umem, xdp->handle, offset);
159159

include/linux/filter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,14 +749,14 @@ bpf_ctx_narrow_access_ok(u32 off, u32 size, u32 size_default)
749749
}
750750

751751
static inline u8
752-
bpf_ctx_narrow_load_shift(u32 off, u32 size, u32 size_default)
752+
bpf_ctx_narrow_access_offset(u32 off, u32 size, u32 size_default)
753753
{
754-
u8 load_off = off & (size_default - 1);
754+
u8 access_off = off & (size_default - 1);
755755

756756
#ifdef __LITTLE_ENDIAN
757-
return load_off * 8;
757+
return access_off;
758758
#else
759-
return (size_default - (load_off + size)) * 8;
759+
return size_default - (access_off + size);
760760
#endif
761761
}
762762

kernel/bpf/cgroup.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ static u32 sysctl_convert_ctx_access(enum bpf_access_type type,
13341334
struct bpf_prog *prog, u32 *target_size)
13351335
{
13361336
struct bpf_insn *insn = insn_buf;
1337+
u32 read_size;
13371338

13381339
switch (si->off) {
13391340
case offsetof(struct bpf_sysctl, write):
@@ -1365,7 +1366,9 @@ static u32 sysctl_convert_ctx_access(enum bpf_access_type type,
13651366
treg, si->dst_reg,
13661367
offsetof(struct bpf_sysctl_kern, ppos));
13671368
*insn++ = BPF_STX_MEM(
1368-
BPF_SIZEOF(u32), treg, si->src_reg, 0);
1369+
BPF_SIZEOF(u32), treg, si->src_reg,
1370+
bpf_ctx_narrow_access_offset(
1371+
0, sizeof(u32), sizeof(loff_t)));
13691372
*insn++ = BPF_LDX_MEM(
13701373
BPF_DW, treg, si->dst_reg,
13711374
offsetof(struct bpf_sysctl_kern, tmp_reg));
@@ -1374,8 +1377,11 @@ static u32 sysctl_convert_ctx_access(enum bpf_access_type type,
13741377
BPF_FIELD_SIZEOF(struct bpf_sysctl_kern, ppos),
13751378
si->dst_reg, si->src_reg,
13761379
offsetof(struct bpf_sysctl_kern, ppos));
1380+
read_size = bpf_size_to_bytes(BPF_SIZE(si->code));
13771381
*insn++ = BPF_LDX_MEM(
1378-
BPF_SIZE(si->code), si->dst_reg, si->dst_reg, 0);
1382+
BPF_SIZE(si->code), si->dst_reg, si->dst_reg,
1383+
bpf_ctx_narrow_access_offset(
1384+
0, read_size, sizeof(loff_t)));
13791385
}
13801386
*target_size = sizeof(u32);
13811387
break;

kernel/bpf/devmap.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,19 +650,22 @@ static int __dev_map_hash_update_elem(struct net *net, struct bpf_map *map,
650650
u32 ifindex = *(u32 *)value;
651651
u32 idx = *(u32 *)key;
652652
unsigned long flags;
653+
int err = -EEXIST;
653654

654655
if (unlikely(map_flags > BPF_EXIST || !ifindex))
655656
return -EINVAL;
656657

658+
spin_lock_irqsave(&dtab->index_lock, flags);
659+
657660
old_dev = __dev_map_hash_lookup_elem(map, idx);
658661
if (old_dev && (map_flags & BPF_NOEXIST))
659-
return -EEXIST;
662+
goto out_err;
660663

661664
dev = __dev_map_alloc_node(net, dtab, ifindex, idx);
662-
if (IS_ERR(dev))
663-
return PTR_ERR(dev);
664-
665-
spin_lock_irqsave(&dtab->index_lock, flags);
665+
if (IS_ERR(dev)) {
666+
err = PTR_ERR(dev);
667+
goto out_err;
668+
}
666669

667670
if (old_dev) {
668671
hlist_del_rcu(&old_dev->index_hlist);
@@ -683,6 +686,10 @@ static int __dev_map_hash_update_elem(struct net *net, struct bpf_map *map,
683686
call_rcu(&old_dev->rcu, __dev_map_entry_free);
684687

685688
return 0;
689+
690+
out_err:
691+
spin_unlock_irqrestore(&dtab->index_lock, flags);
692+
return err;
686693
}
687694

688695
static int dev_map_hash_update_elem(struct bpf_map *map, void *key, void *value,

kernel/bpf/verifier.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8624,8 +8624,8 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
86248624
}
86258625

86268626
if (is_narrower_load && size < target_size) {
8627-
u8 shift = bpf_ctx_narrow_load_shift(off, size,
8628-
size_default);
8627+
u8 shift = bpf_ctx_narrow_access_offset(
8628+
off, size, size_default) * 8;
86298629
if (ctx_field_size <= 4) {
86308630
if (shift)
86318631
insn_buf[cnt++] = BPF_ALU32_IMM(BPF_RSH,

net/kcm/kcmsock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static int kcm_parse_func_strparser(struct strparser *strp, struct sk_buff *skb)
379379
struct kcm_psock *psock = container_of(strp, struct kcm_psock, strp);
380380
struct bpf_prog *prog = psock->bpf_prog;
381381

382-
return (*prog->bpf_func)(skb, prog->insnsi);
382+
return BPF_PROG_RUN(prog, skb);
383383
}
384384

385385
static int kcm_read_sock_done(struct strparser *strp, int err)

samples/bpf/xdpsock_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ static void l2fwd(struct xsk_socket_info *xsk, struct pollfd *fds)
685685
for (i = 0; i < rcvd; i++) {
686686
u64 addr = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx)->addr;
687687
u32 len = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++)->len;
688-
u64 orig = xsk_umem__extract_addr(addr);
688+
u64 orig = addr;
689689

690690
addr = xsk_umem__add_offset_to_addr(addr);
691691
char *pkt = xsk_umem__get_data(xsk->umem->buffer, addr);

scripts/link-vmlinux.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,27 @@ modpost_link()
5757

5858
# Link of vmlinux
5959
# ${1} - output file
60-
# ${@:2} - optional extra .o files
60+
# ${2}, ${3}, ... - optional extra .o files
6161
vmlinux_link()
6262
{
6363
local lds="${objtree}/${KBUILD_LDS}"
64+
local output=${1}
6465
local objects
6566

67+
# skip output file argument
68+
shift
69+
6670
if [ "${SRCARCH}" != "um" ]; then
6771
objects="--whole-archive \
6872
${KBUILD_VMLINUX_OBJS} \
6973
--no-whole-archive \
7074
--start-group \
7175
${KBUILD_VMLINUX_LIBS} \
7276
--end-group \
73-
${@:2}"
77+
${@}"
7478

75-
${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${1} \
79+
${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \
80+
-o ${output} \
7681
-T ${lds} ${objects}
7782
else
7883
objects="-Wl,--whole-archive \
@@ -81,9 +86,10 @@ vmlinux_link()
8186
-Wl,--start-group \
8287
${KBUILD_VMLINUX_LIBS} \
8388
-Wl,--end-group \
84-
${@:2}"
89+
${@}"
8590

86-
${CC} ${CFLAGS_vmlinux} -o ${1} \
91+
${CC} ${CFLAGS_vmlinux} \
92+
-o ${output} \
8793
-Wl,-T,${lds} \
8894
${objects} \
8995
-lutil -lrt -lpthread

tools/testing/selftests/bpf/.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,3 @@ libbpf.so.*
3939
test_hashmap
4040
test_btf_dump
4141
xdping
42-
test_sockopt
43-
test_sockopt_sk
44-
test_sockopt_multi
45-
test_sockopt_inherit
46-
test_tcp_rtt

0 commit comments

Comments
 (0)