Skip to content

Commit 8c8f67a

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Daniel Borkmann says: ==================== pull-request: bpf 2017-12-13 The following pull-request contains BPF updates for your *net* tree. The main changes are: 1) Addition of explicit scheduling points to map alloc/free in order to avoid having to hold the CPU for too long, from Eric. 2) Fixing of a corruption in overlapping perf_event_output calls from different BPF prog types on the same CPU out of different contexts, from Daniel. 3) Fallout fixes for recent correction of broken uapi for BPF_PROG_TYPE_PERF_EVENT. um had a missing asm header that needed to be pulled in from asm-generic and for BPF selftests the asm-generic include did not work, so similar asm include scheme was adapted for that problematic header that perf is having with other header files under tools, from Daniel. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents f6e168b + 9147efc commit 8c8f67a

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

arch/um/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
generic-y += barrier.h
2+
generic-y += bpf_perf_event.h
23
generic-y += bug.h
34
generic-y += clkdev.h
45
generic-y += current.h

kernel/bpf/hashtab.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static void htab_free_elems(struct bpf_htab *htab)
114114
pptr = htab_elem_get_ptr(get_htab_elem(htab, i),
115115
htab->map.key_size);
116116
free_percpu(pptr);
117+
cond_resched();
117118
}
118119
free_elems:
119120
bpf_map_area_free(htab->elems);
@@ -159,6 +160,7 @@ static int prealloc_init(struct bpf_htab *htab)
159160
goto free_elems;
160161
htab_elem_set_ptr(get_htab_elem(htab, i), htab->map.key_size,
161162
pptr);
163+
cond_resched();
162164
}
163165

164166
skip_percpu_elems:

kernel/trace/bpf_trace.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,13 @@ static const struct bpf_func_proto bpf_perf_event_read_value_proto = {
343343
.arg4_type = ARG_CONST_SIZE,
344344
};
345345

346-
static DEFINE_PER_CPU(struct perf_sample_data, bpf_sd);
346+
static DEFINE_PER_CPU(struct perf_sample_data, bpf_trace_sd);
347347

348348
static __always_inline u64
349349
__bpf_perf_event_output(struct pt_regs *regs, struct bpf_map *map,
350-
u64 flags, struct perf_raw_record *raw)
350+
u64 flags, struct perf_sample_data *sd)
351351
{
352352
struct bpf_array *array = container_of(map, struct bpf_array, map);
353-
struct perf_sample_data *sd = this_cpu_ptr(&bpf_sd);
354353
unsigned int cpu = smp_processor_id();
355354
u64 index = flags & BPF_F_INDEX_MASK;
356355
struct bpf_event_entry *ee;
@@ -373,15 +372,14 @@ __bpf_perf_event_output(struct pt_regs *regs, struct bpf_map *map,
373372
if (unlikely(event->oncpu != cpu))
374373
return -EOPNOTSUPP;
375374

376-
perf_sample_data_init(sd, 0, 0);
377-
sd->raw = raw;
378375
perf_event_output(event, sd, regs);
379376
return 0;
380377
}
381378

382379
BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
383380
u64, flags, void *, data, u64, size)
384381
{
382+
struct perf_sample_data *sd = this_cpu_ptr(&bpf_trace_sd);
385383
struct perf_raw_record raw = {
386384
.frag = {
387385
.size = size,
@@ -392,7 +390,10 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
392390
if (unlikely(flags & ~(BPF_F_INDEX_MASK)))
393391
return -EINVAL;
394392

395-
return __bpf_perf_event_output(regs, map, flags, &raw);
393+
perf_sample_data_init(sd, 0, 0);
394+
sd->raw = &raw;
395+
396+
return __bpf_perf_event_output(regs, map, flags, sd);
396397
}
397398

398399
static const struct bpf_func_proto bpf_perf_event_output_proto = {
@@ -407,10 +408,12 @@ static const struct bpf_func_proto bpf_perf_event_output_proto = {
407408
};
408409

409410
static DEFINE_PER_CPU(struct pt_regs, bpf_pt_regs);
411+
static DEFINE_PER_CPU(struct perf_sample_data, bpf_misc_sd);
410412

411413
u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
412414
void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy)
413415
{
416+
struct perf_sample_data *sd = this_cpu_ptr(&bpf_misc_sd);
414417
struct pt_regs *regs = this_cpu_ptr(&bpf_pt_regs);
415418
struct perf_raw_frag frag = {
416419
.copy = ctx_copy,
@@ -428,8 +431,10 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
428431
};
429432

430433
perf_fetch_caller_regs(regs);
434+
perf_sample_data_init(sd, 0, 0);
435+
sd->raw = &raw;
431436

432-
return __bpf_perf_event_output(regs, map, flags, &raw);
437+
return __bpf_perf_event_output(regs, map, flags, sd);
433438
}
434439

435440
BPF_CALL_0(bpf_get_current_task)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#if defined(__aarch64__)
2+
#include "../../arch/arm64/include/uapi/asm/bpf_perf_event.h"
3+
#elif defined(__s390__)
4+
#include "../../arch/s390/include/uapi/asm/bpf_perf_event.h"
5+
#else
6+
#include <uapi/asm-generic/bpf_perf_event.h>
7+
#endif

tools/testing/selftests/bpf/Makefile

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3-
ifeq ($(srctree),)
4-
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
5-
srctree := $(patsubst %/,%,$(dir $(srctree)))
6-
srctree := $(patsubst %/,%,$(dir $(srctree)))
7-
srctree := $(patsubst %/,%,$(dir $(srctree)))
8-
endif
9-
include $(srctree)/tools/scripts/Makefile.arch
10-
11-
$(call detected_var,SRCARCH)
12-
133
LIBDIR := ../../../lib
144
BPFDIR := $(LIBDIR)/bpf
155
APIDIR := ../../../include/uapi
16-
ASMDIR:= ../../../arch/$(ARCH)/include/uapi
176
GENDIR := ../../../../include/generated
187
GENHDR := $(GENDIR)/autoconf.h
198

209
ifneq ($(wildcard $(GENHDR)),)
2110
GENFLAGS := -DHAVE_GENHDR
2211
endif
2312

24-
CFLAGS += -Wall -O2 -I$(APIDIR) -I$(ASMDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include
13+
CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include
2514
LDLIBS += -lcap -lelf
2615

2716
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \

0 commit comments

Comments
 (0)