Skip to content

Commit 00198da

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Ingo Molnar: "On the kernel side there's two x86 PMU driver fixes and a uprobes fix, plus on the tooling side there's a number of fixes and some late updates" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (36 commits) perf sched timehist: Fix invalid period calculation perf sched timehist: Remove hardcoded 'comm_width' check at print_summary perf sched timehist: Enlarge default 'comm_width' perf sched timehist: Honour 'comm_width' when aligning the headers perf/x86: Fix overlap counter scheduling bug perf/x86/pebs: Fix handling of PEBS buffer overflows samples/bpf: Move open_raw_sock to separate header samples/bpf: Remove perf_event_open() declaration samples/bpf: Be consistent with bpf_load_program bpf_insn parameter tools lib bpf: Add bpf_prog_{attach,detach} samples/bpf: Switch over to libbpf perf diff: Do not overwrite valid build id perf annotate: Don't throw error for zero length symbols perf bench futex: Fix lock-pi help string perf trace: Check if MAP_32BIT is defined (again) samples/bpf: Make perf_event_read() static uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation samples/bpf: Make samples more libbpf-centric tools lib bpf: Add flags to bpf_create_map() tools lib bpf: use __u32 from linux/types.h ...
2 parents 9004fda + 3705b97 commit 00198da

Some content is hidden

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

63 files changed

+1104
-750
lines changed

arch/x86/events/intel/core.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,22 +2110,34 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)
21102110
GLOBAL_STATUS_LBRS_FROZEN);
21112111
if (!status)
21122112
goto done;
2113+
/*
2114+
* In case multiple PEBS events are sampled at the same time,
2115+
* it is possible to have GLOBAL_STATUS bit 62 set indicating
2116+
* PEBS buffer overflow and also seeing at most 3 PEBS counters
2117+
* having their bits set in the status register. This is a sign
2118+
* that there was at least one PEBS record pending at the time
2119+
* of the PMU interrupt. PEBS counters must only be processed
2120+
* via the drain_pebs() calls and not via the regular sample
2121+
* processing loop coming after that the function, otherwise
2122+
* phony regular samples may be generated in the sampling buffer
2123+
* not marked with the EXACT tag. Another possibility is to have
2124+
* one PEBS event and at least one non-PEBS event whic hoverflows
2125+
* while PEBS has armed. In this case, bit 62 of GLOBAL_STATUS will
2126+
* not be set, yet the overflow status bit for the PEBS counter will
2127+
* be on Skylake.
2128+
*
2129+
* To avoid this problem, we systematically ignore the PEBS-enabled
2130+
* counters from the GLOBAL_STATUS mask and we always process PEBS
2131+
* events via drain_pebs().
2132+
*/
2133+
status &= ~cpuc->pebs_enabled;
21132134

21142135
/*
21152136
* PEBS overflow sets bit 62 in the global status register
21162137
*/
21172138
if (__test_and_clear_bit(62, (unsigned long *)&status)) {
21182139
handled++;
21192140
x86_pmu.drain_pebs(regs);
2120-
/*
2121-
* There are cases where, even though, the PEBS ovfl bit is set
2122-
* in GLOBAL_OVF_STATUS, the PEBS events may also have their
2123-
* overflow bits set for their counters. We must clear them
2124-
* here because they have been processed as exact samples in
2125-
* the drain_pebs() routine. They must not be processed again
2126-
* in the for_each_bit_set() loop for regular samples below.
2127-
*/
2128-
status &= ~cpuc->pebs_enabled;
21292141
status &= x86_pmu.intel_ctrl | GLOBAL_STATUS_TRACE_TOPAPMI;
21302142
}
21312143

arch/x86/events/intel/uncore_snbep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ static struct event_constraint snbep_uncore_cbox_constraints[] = {
669669
UNCORE_EVENT_CONSTRAINT(0x1c, 0xc),
670670
UNCORE_EVENT_CONSTRAINT(0x1d, 0xc),
671671
UNCORE_EVENT_CONSTRAINT(0x1e, 0xc),
672-
EVENT_CONSTRAINT_OVERLAP(0x1f, 0xe, 0xff),
672+
UNCORE_EVENT_CONSTRAINT(0x1f, 0xe),
673673
UNCORE_EVENT_CONSTRAINT(0x21, 0x3),
674674
UNCORE_EVENT_CONSTRAINT(0x23, 0x3),
675675
UNCORE_EVENT_CONSTRAINT(0x31, 0x3),

kernel/events/uprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
11941194
/* Reserve the 1st slot for get_trampoline_vaddr() */
11951195
set_bit(0, area->bitmap);
11961196
atomic_set(&area->slot_count, 1);
1197-
copy_to_page(area->pages[0], 0, &insn, UPROBE_SWBP_INSN_SIZE);
1197+
arch_uprobe_copy_ixol(area->pages[0], 0, &insn, UPROBE_SWBP_INSN_SIZE);
11981198

11991199
if (!xol_add_vma(mm, area))
12001200
return area;

samples/bpf/Makefile

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,43 @@ hostprogs-y += tc_l2_redirect
3535
hostprogs-y += lwt_len_hist
3636
hostprogs-y += xdp_tx_iptunnel
3737

38-
test_lru_dist-objs := test_lru_dist.o libbpf.o
39-
sock_example-objs := sock_example.o libbpf.o
40-
fds_example-objs := bpf_load.o libbpf.o fds_example.o
41-
sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
42-
sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
43-
sockex3-objs := bpf_load.o libbpf.o sockex3_user.o
44-
tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
45-
tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
46-
tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
47-
tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
48-
tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
49-
tracex6-objs := bpf_load.o libbpf.o tracex6_user.o
50-
test_probe_write_user-objs := bpf_load.o libbpf.o test_probe_write_user_user.o
51-
trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
52-
lathist-objs := bpf_load.o libbpf.o lathist_user.o
53-
offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o
54-
spintest-objs := bpf_load.o libbpf.o spintest_user.o
55-
map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o
56-
test_overhead-objs := bpf_load.o libbpf.o test_overhead_user.o
57-
test_cgrp2_array_pin-objs := libbpf.o test_cgrp2_array_pin.o
58-
test_cgrp2_attach-objs := libbpf.o test_cgrp2_attach.o
59-
test_cgrp2_attach2-objs := libbpf.o test_cgrp2_attach2.o cgroup_helpers.o
60-
test_cgrp2_sock-objs := libbpf.o test_cgrp2_sock.o
61-
test_cgrp2_sock2-objs := bpf_load.o libbpf.o test_cgrp2_sock2.o
62-
xdp1-objs := bpf_load.o libbpf.o xdp1_user.o
38+
# Libbpf dependencies
39+
LIBBPF := ../../tools/lib/bpf/bpf.o
40+
41+
test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
42+
sock_example-objs := sock_example.o $(LIBBPF)
43+
fds_example-objs := bpf_load.o $(LIBBPF) fds_example.o
44+
sockex1-objs := bpf_load.o $(LIBBPF) sockex1_user.o
45+
sockex2-objs := bpf_load.o $(LIBBPF) sockex2_user.o
46+
sockex3-objs := bpf_load.o $(LIBBPF) sockex3_user.o
47+
tracex1-objs := bpf_load.o $(LIBBPF) tracex1_user.o
48+
tracex2-objs := bpf_load.o $(LIBBPF) tracex2_user.o
49+
tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
50+
tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
51+
tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
52+
tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
53+
test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
54+
trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o
55+
lathist-objs := bpf_load.o $(LIBBPF) lathist_user.o
56+
offwaketime-objs := bpf_load.o $(LIBBPF) offwaketime_user.o
57+
spintest-objs := bpf_load.o $(LIBBPF) spintest_user.o
58+
map_perf_test-objs := bpf_load.o $(LIBBPF) map_perf_test_user.o
59+
test_overhead-objs := bpf_load.o $(LIBBPF) test_overhead_user.o
60+
test_cgrp2_array_pin-objs := $(LIBBPF) test_cgrp2_array_pin.o
61+
test_cgrp2_attach-objs := $(LIBBPF) test_cgrp2_attach.o
62+
test_cgrp2_attach2-objs := $(LIBBPF) test_cgrp2_attach2.o cgroup_helpers.o
63+
test_cgrp2_sock-objs := $(LIBBPF) test_cgrp2_sock.o
64+
test_cgrp2_sock2-objs := bpf_load.o $(LIBBPF) test_cgrp2_sock2.o
65+
xdp1-objs := bpf_load.o $(LIBBPF) xdp1_user.o
6366
# reuse xdp1 source intentionally
64-
xdp2-objs := bpf_load.o libbpf.o xdp1_user.o
65-
test_current_task_under_cgroup-objs := bpf_load.o libbpf.o cgroup_helpers.o \
67+
xdp2-objs := bpf_load.o $(LIBBPF) xdp1_user.o
68+
test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) cgroup_helpers.o \
6669
test_current_task_under_cgroup_user.o
67-
trace_event-objs := bpf_load.o libbpf.o trace_event_user.o
68-
sampleip-objs := bpf_load.o libbpf.o sampleip_user.o
69-
tc_l2_redirect-objs := bpf_load.o libbpf.o tc_l2_redirect_user.o
70-
lwt_len_hist-objs := bpf_load.o libbpf.o lwt_len_hist_user.o
71-
xdp_tx_iptunnel-objs := bpf_load.o libbpf.o xdp_tx_iptunnel_user.o
70+
trace_event-objs := bpf_load.o $(LIBBPF) trace_event_user.o
71+
sampleip-objs := bpf_load.o $(LIBBPF) sampleip_user.o
72+
tc_l2_redirect-objs := bpf_load.o $(LIBBPF) tc_l2_redirect_user.o
73+
lwt_len_hist-objs := bpf_load.o $(LIBBPF) lwt_len_hist_user.o
74+
xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
7275

7376
# Tell kbuild to always build the programs
7477
always := $(hostprogs-y)
@@ -104,7 +107,10 @@ always += lwt_len_hist_kern.o
104107
always += xdp_tx_iptunnel_kern.o
105108

106109
HOSTCFLAGS += -I$(objtree)/usr/include
110+
HOSTCFLAGS += -I$(srctree)/tools/lib/
107111
HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
112+
HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
113+
HOSTCFLAGS += -I$(srctree)/tools/perf
108114

109115
HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
110116
HOSTLOADLIBES_fds_example += -lelf

samples/bpf/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
eBPF sample programs
22
====================
33

4-
This directory contains a mini eBPF library, test stubs, verifier
5-
test-suite and examples for using eBPF.
4+
This directory contains a test stubs, verifier test-suite and examples
5+
for using eBPF. The examples use libbpf from tools/lib/bpf.
66

77
Build dependencies
88
==================

samples/bpf/bpf_load.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,34 @@
2222
#include <poll.h>
2323
#include <ctype.h>
2424
#include "libbpf.h"
25-
#include "bpf_helpers.h"
2625
#include "bpf_load.h"
26+
#include "perf-sys.h"
2727

2828
#define DEBUGFS "/sys/kernel/debug/tracing/"
2929

3030
static char license[128];
3131
static int kern_version;
3232
static bool processed_sec[128];
33+
char bpf_log_buf[BPF_LOG_BUF_SIZE];
3334
int map_fd[MAX_MAPS];
3435
int prog_fd[MAX_PROGS];
3536
int event_fd[MAX_PROGS];
3637
int prog_cnt;
3738
int prog_array_fd = -1;
3839

40+
struct bpf_map_def {
41+
unsigned int type;
42+
unsigned int key_size;
43+
unsigned int value_size;
44+
unsigned int max_entries;
45+
unsigned int map_flags;
46+
};
47+
3948
static int populate_prog_array(const char *event, int prog_fd)
4049
{
4150
int ind = atoi(event), err;
4251

43-
err = bpf_update_elem(prog_array_fd, &ind, &prog_fd, BPF_ANY);
52+
err = bpf_map_update_elem(prog_array_fd, &ind, &prog_fd, BPF_ANY);
4453
if (err < 0) {
4554
printf("failed to store prog_fd in prog_array\n");
4655
return -1;
@@ -58,6 +67,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
5867
bool is_perf_event = strncmp(event, "perf_event", 10) == 0;
5968
bool is_cgroup_skb = strncmp(event, "cgroup/skb", 10) == 0;
6069
bool is_cgroup_sk = strncmp(event, "cgroup/sock", 11) == 0;
70+
size_t insns_cnt = size / sizeof(struct bpf_insn);
6171
enum bpf_prog_type prog_type;
6272
char buf[256];
6373
int fd, efd, err, id;
@@ -87,9 +97,10 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
8797
return -1;
8898
}
8999

90-
fd = bpf_prog_load(prog_type, prog, size, license, kern_version);
100+
fd = bpf_load_program(prog_type, prog, insns_cnt, license, kern_version,
101+
bpf_log_buf, BPF_LOG_BUF_SIZE);
91102
if (fd < 0) {
92-
printf("bpf_prog_load() err=%d\n%s", errno, bpf_log_buf);
103+
printf("bpf_load_program() err=%d\n%s", errno, bpf_log_buf);
93104
return -1;
94105
}
95106

@@ -169,7 +180,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
169180
id = atoi(buf);
170181
attr.config = id;
171182

172-
efd = perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
183+
efd = sys_perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
173184
if (efd < 0) {
174185
printf("event %d fd %d err %s\n", id, efd, strerror(errno));
175186
return -1;

samples/bpf/bpf_load.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#ifndef __BPF_LOAD_H
22
#define __BPF_LOAD_H
33

4+
#include "libbpf.h"
5+
46
#define MAX_MAPS 32
57
#define MAX_PROGS 32
68

79
extern int map_fd[MAX_MAPS];
810
extern int prog_fd[MAX_PROGS];
911
extern int event_fd[MAX_PROGS];
12+
extern char bpf_log_buf[BPF_LOG_BUF_SIZE];
1013
extern int prog_cnt;
1114

1215
/* parses elf file compiled by llvm .c->.o

samples/bpf/fds_example.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "bpf_load.h"
1616
#include "libbpf.h"
17+
#include "sock_example.h"
1718

1819
#define BPF_F_PIN (1 << 0)
1920
#define BPF_F_GET (1 << 1)
@@ -49,17 +50,19 @@ static int bpf_map_create(void)
4950

5051
static int bpf_prog_create(const char *object)
5152
{
52-
static const struct bpf_insn insns[] = {
53+
static struct bpf_insn insns[] = {
5354
BPF_MOV64_IMM(BPF_REG_0, 1),
5455
BPF_EXIT_INSN(),
5556
};
57+
size_t insns_cnt = sizeof(insns) / sizeof(struct bpf_insn);
5658

5759
if (object) {
5860
assert(!load_bpf_file((char *)object));
5961
return prog_fd[0];
6062
} else {
61-
return bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER,
62-
insns, sizeof(insns), "GPL", 0);
63+
return bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER,
64+
insns, insns_cnt, "GPL", 0,
65+
bpf_log_buf, BPF_LOG_BUF_SIZE);
6366
}
6467
}
6568

@@ -83,12 +86,12 @@ static int bpf_do_map(const char *file, uint32_t flags, uint32_t key,
8386
}
8487

8588
if ((flags & BPF_F_KEY_VAL) == BPF_F_KEY_VAL) {
86-
ret = bpf_update_elem(fd, &key, &value, 0);
89+
ret = bpf_map_update_elem(fd, &key, &value, 0);
8790
printf("bpf: fd:%d u->(%u:%u) ret:(%d,%s)\n", fd, key, value,
8891
ret, strerror(errno));
8992
assert(ret == 0);
9093
} else if (flags & BPF_F_KEY) {
91-
ret = bpf_lookup_elem(fd, &key, &value);
94+
ret = bpf_map_lookup_elem(fd, &key, &value);
9295
printf("bpf: fd:%d l->(%u):%u ret:(%d,%s)\n", fd, key, value,
9396
ret, strerror(errno));
9497
assert(ret == 0);

samples/bpf/lathist_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void get_data(int fd)
7373
for (c = 0; c < MAX_CPU; c++) {
7474
for (i = 0; i < MAX_ENTRIES; i++) {
7575
key = c * MAX_ENTRIES + i;
76-
bpf_lookup_elem(fd, &key, &value);
76+
bpf_map_lookup_elem(fd, &key, &value);
7777

7878
cpu_hist[c].data[i] = value;
7979
if (value > cpu_hist[c].max)

0 commit comments

Comments
 (0)