Skip to content

Commit 242a6df

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Alexei Starovoitov says: ==================== pull-request: bpf 2020-03-12 The following pull-request contains BPF updates for your *net* tree. We've added 12 non-merge commits during the last 8 day(s) which contain a total of 12 files changed, 161 insertions(+), 15 deletions(-). The main changes are: 1) Andrii fixed two bugs in cgroup-bpf. 2) John fixed sockmap. 3) Luke fixed x32 jit. 4) Martin fixed two issues in struct_ops. 5) Yonghong fixed bpf_send_signal. 6) Yoshiki fixed BTF enum. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 0d81a3f + 90db6d7 commit 242a6df

12 files changed

Lines changed: 161 additions & 15 deletions

File tree

‎.mailmap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ Pratyush Anand <pratyush.anand@gmail.com> <pratyush.anand@st.com>
225225
Praveen BP <praveenbp@ti.com>
226226
Punit Agrawal <punitagrawal@gmail.com> <punit.agrawal@arm.com>
227227
Qais Yousef <qsyousef@gmail.com> <qais.yousef@imgtec.com>
228+
Quentin Monnet <quentin@isovalent.com> <quentin.monnet@netronome.com>
228229
Quentin Perret <qperret@qperret.net> <quentin.perret@arm.com>
229230
Rafael J. Wysocki <rjw@rjwysocki.net> <rjw@sisk.pl>
230231
Rajesh Shah <rajesh.shah@intel.com>

‎arch/x86/net/bpf_jit_comp32.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,10 +2039,12 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
20392039
}
20402040
/* and dreg_lo,sreg_lo */
20412041
EMIT2(0x23, add_2reg(0xC0, sreg_lo, dreg_lo));
2042-
/* and dreg_hi,sreg_hi */
2043-
EMIT2(0x23, add_2reg(0xC0, sreg_hi, dreg_hi));
2044-
/* or dreg_lo,dreg_hi */
2045-
EMIT2(0x09, add_2reg(0xC0, dreg_lo, dreg_hi));
2042+
if (is_jmp64) {
2043+
/* and dreg_hi,sreg_hi */
2044+
EMIT2(0x23, add_2reg(0xC0, sreg_hi, dreg_hi));
2045+
/* or dreg_lo,dreg_hi */
2046+
EMIT2(0x09, add_2reg(0xC0, dreg_lo, dreg_hi));
2047+
}
20462048
goto emit_cond_jmp;
20472049
}
20482050
case BPF_JMP | BPF_JSET | BPF_K:

‎kernel/bpf/bpf_struct_ops.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,21 @@ static int bpf_struct_ops_map_delete_elem(struct bpf_map *map, void *key)
482482
prev_state = cmpxchg(&st_map->kvalue.state,
483483
BPF_STRUCT_OPS_STATE_INUSE,
484484
BPF_STRUCT_OPS_STATE_TOBEFREE);
485-
if (prev_state == BPF_STRUCT_OPS_STATE_INUSE) {
485+
switch (prev_state) {
486+
case BPF_STRUCT_OPS_STATE_INUSE:
486487
st_map->st_ops->unreg(&st_map->kvalue.data);
487488
if (refcount_dec_and_test(&st_map->kvalue.refcnt))
488489
bpf_map_put(map);
490+
return 0;
491+
case BPF_STRUCT_OPS_STATE_TOBEFREE:
492+
return -EINPROGRESS;
493+
case BPF_STRUCT_OPS_STATE_INIT:
494+
return -ENOENT;
495+
default:
496+
WARN_ON_ONCE(1);
497+
/* Should never happen. Treat it as not found. */
498+
return -ENOENT;
489499
}
490-
491-
return 0;
492500
}
493501

494502
static void bpf_struct_ops_map_seq_show_elem(struct bpf_map *map, void *key,

‎kernel/bpf/btf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,7 @@ static int btf_enum_check_member(struct btf_verifier_env *env,
24182418

24192419
struct_size = struct_type->size;
24202420
bytes_offset = BITS_ROUNDDOWN_BYTES(struct_bits_off);
2421-
if (struct_size - bytes_offset < sizeof(int)) {
2421+
if (struct_size - bytes_offset < member_type->size) {
24222422
btf_verifier_log_member(env, struct_type, member,
24232423
"Member exceeds struct_size");
24242424
return -EINVAL;

‎kernel/bpf/cgroup.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ int cgroup_bpf_inherit(struct cgroup *cgrp)
227227
for (i = 0; i < NR; i++)
228228
bpf_prog_array_free(arrays[i]);
229229

230+
for (p = cgroup_parent(cgrp); p; p = cgroup_parent(p))
231+
cgroup_bpf_put(p);
232+
230233
percpu_ref_exit(&cgrp->bpf.refcnt);
231234

232235
return -ENOMEM;
@@ -302,8 +305,8 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog,
302305
u32 saved_flags = (flags & (BPF_F_ALLOW_OVERRIDE | BPF_F_ALLOW_MULTI));
303306
struct list_head *progs = &cgrp->bpf.progs[type];
304307
struct bpf_prog *old_prog = NULL;
305-
struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE],
306-
*old_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {NULL};
308+
struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
309+
struct bpf_cgroup_storage *old_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
307310
struct bpf_prog_list *pl, *replace_pl = NULL;
308311
enum bpf_cgroup_storage_type stype;
309312
int err;

‎kernel/bpf/syscall.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,11 @@ static int map_freeze(const union bpf_attr *attr)
15101510
if (IS_ERR(map))
15111511
return PTR_ERR(map);
15121512

1513+
if (map->map_type == BPF_MAP_TYPE_STRUCT_OPS) {
1514+
fdput(f);
1515+
return -ENOTSUPP;
1516+
}
1517+
15131518
mutex_lock(&map->freeze_mutex);
15141519

15151520
if (map->writecnt) {

‎kernel/trace/bpf_trace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type)
732732
if (unlikely(!nmi_uaccess_okay()))
733733
return -EPERM;
734734

735-
if (in_nmi()) {
735+
if (irqs_disabled()) {
736736
/* Do an early check on signal validity. Otherwise,
737737
* the error is lost in deferred irq_work.
738738
*/

‎net/core/sock_map.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,11 @@ static void sock_map_free(struct bpf_map *map)
233233
struct bpf_stab *stab = container_of(map, struct bpf_stab, map);
234234
int i;
235235

236+
/* After the sync no updates or deletes will be in-flight so it
237+
* is safe to walk map and remove entries without risking a race
238+
* in EEXIST update case.
239+
*/
236240
synchronize_rcu();
237-
raw_spin_lock_bh(&stab->lock);
238241
for (i = 0; i < stab->map.max_entries; i++) {
239242
struct sock **psk = &stab->sks[i];
240243
struct sock *sk;
@@ -248,7 +251,6 @@ static void sock_map_free(struct bpf_map *map)
248251
release_sock(sk);
249252
}
250253
}
251-
raw_spin_unlock_bh(&stab->lock);
252254

253255
/* wait for psock readers accessing its map link */
254256
synchronize_rcu();
@@ -863,10 +865,13 @@ static void sock_hash_free(struct bpf_map *map)
863865
struct hlist_node *node;
864866
int i;
865867

868+
/* After the sync no updates or deletes will be in-flight so it
869+
* is safe to walk map and remove entries without risking a race
870+
* in EEXIST update case.
871+
*/
866872
synchronize_rcu();
867873
for (i = 0; i < htab->buckets_num; i++) {
868874
bucket = sock_hash_select_bucket(htab, i);
869-
raw_spin_lock_bh(&bucket->lock);
870875
hlist_for_each_entry_safe(elem, node, &bucket->head, node) {
871876
hlist_del_rcu(&elem->node);
872877
lock_sock(elem->sk);
@@ -875,7 +880,6 @@ static void sock_hash_free(struct bpf_map *map)
875880
rcu_read_unlock();
876881
release_sock(elem->sk);
877882
}
878-
raw_spin_unlock_bh(&bucket->lock);
879883
}
880884

881885
/* wait for psock readers accessing its map link */
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <test_progs.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <sys/mman.h>
6+
#include <pthread.h>
7+
#include <sys/types.h>
8+
#include <sys/stat.h>
9+
#include <fcntl.h>
10+
#include "test_send_signal_kern.skel.h"
11+
12+
static void sigusr1_handler(int signum)
13+
{
14+
}
15+
16+
#define THREAD_COUNT 100
17+
18+
static void *worker(void *p)
19+
{
20+
int i;
21+
22+
for ( i = 0; i < 1000; i++)
23+
usleep(1);
24+
25+
return NULL;
26+
}
27+
28+
void test_send_signal_sched_switch(void)
29+
{
30+
struct test_send_signal_kern *skel;
31+
pthread_t threads[THREAD_COUNT];
32+
u32 duration = 0;
33+
int i, err;
34+
35+
signal(SIGUSR1, sigusr1_handler);
36+
37+
skel = test_send_signal_kern__open_and_load();
38+
if (CHECK(!skel, "skel_open_and_load", "skeleton open_and_load failed\n"))
39+
return;
40+
41+
skel->bss->pid = getpid();
42+
skel->bss->sig = SIGUSR1;
43+
44+
err = test_send_signal_kern__attach(skel);
45+
if (CHECK(err, "skel_attach", "skeleton attach failed\n"))
46+
goto destroy_skel;
47+
48+
for (i = 0; i < THREAD_COUNT; i++) {
49+
err = pthread_create(threads + i, NULL, worker, NULL);
50+
if (CHECK(err, "pthread_create", "Error creating thread, %s\n",
51+
strerror(errno)))
52+
goto destroy_skel;
53+
}
54+
55+
for (i = 0; i < THREAD_COUNT; i++)
56+
pthread_join(threads[i], NULL);
57+
58+
destroy_skel:
59+
test_send_signal_kern__destroy(skel);
60+
}

‎tools/testing/selftests/bpf/progs/test_send_signal_kern.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ int send_signal_tp(void *ctx)
3131
return bpf_send_signal_test(ctx);
3232
}
3333

34+
SEC("tracepoint/sched/sched_switch")
35+
int send_signal_tp_sched(void *ctx)
36+
{
37+
return bpf_send_signal_test(ctx);
38+
}
39+
3440
SEC("perf_event")
3541
int send_signal_perf(void *ctx)
3642
{

0 commit comments

Comments
 (0)