Skip to content

Commit 3ab6d1e

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: "Two core subsystem fixes, plus a handful of tooling fixes" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf: Fix race in swevent hash perf: Fix race in perf_event_exec() perf list: Robustify event printing routine perf list: Add support for PERF_COUNT_SW_BPF_OUT perf hists browser: Fix segfault if use symbol filter in cmdline perf hists browser: Reset selection when refresh perf hists browser: Add NULL pointer check to prevent crash perf buildid-list: Fix return value of perf buildid-list -k perf buildid-list: Show running kernel build id fix
2 parents ea83ae2 + 12ca6ad commit 3ab6d1e

File tree

5 files changed

+21
-32
lines changed

5 files changed

+21
-32
lines changed

kernel/events/core.c

+6-29
Original file line numberDiff line numberDiff line change
@@ -3154,15 +3154,16 @@ static int event_enable_on_exec(struct perf_event *event,
31543154
* Enable all of a task's events that have been marked enable-on-exec.
31553155
* This expects task == current.
31563156
*/
3157-
static void perf_event_enable_on_exec(struct perf_event_context *ctx)
3157+
static void perf_event_enable_on_exec(int ctxn)
31583158
{
3159-
struct perf_event_context *clone_ctx = NULL;
3159+
struct perf_event_context *ctx, *clone_ctx = NULL;
31603160
struct perf_event *event;
31613161
unsigned long flags;
31623162
int enabled = 0;
31633163
int ret;
31643164

31653165
local_irq_save(flags);
3166+
ctx = current->perf_event_ctxp[ctxn];
31663167
if (!ctx || !ctx->nr_events)
31673168
goto out;
31683169

@@ -3205,17 +3206,11 @@ static void perf_event_enable_on_exec(struct perf_event_context *ctx)
32053206

32063207
void perf_event_exec(void)
32073208
{
3208-
struct perf_event_context *ctx;
32093209
int ctxn;
32103210

32113211
rcu_read_lock();
3212-
for_each_task_context_nr(ctxn) {
3213-
ctx = current->perf_event_ctxp[ctxn];
3214-
if (!ctx)
3215-
continue;
3216-
3217-
perf_event_enable_on_exec(ctx);
3218-
}
3212+
for_each_task_context_nr(ctxn)
3213+
perf_event_enable_on_exec(ctxn);
32193214
rcu_read_unlock();
32203215
}
32213216

@@ -6493,9 +6488,6 @@ struct swevent_htable {
64936488

64946489
/* Recursion avoidance in each contexts */
64956490
int recursion[PERF_NR_CONTEXTS];
6496-
6497-
/* Keeps track of cpu being initialized/exited */
6498-
bool online;
64996491
};
65006492

65016493
static DEFINE_PER_CPU(struct swevent_htable, swevent_htable);
@@ -6753,14 +6745,8 @@ static int perf_swevent_add(struct perf_event *event, int flags)
67536745
hwc->state = !(flags & PERF_EF_START);
67546746

67556747
head = find_swevent_head(swhash, event);
6756-
if (!head) {
6757-
/*
6758-
* We can race with cpu hotplug code. Do not
6759-
* WARN if the cpu just got unplugged.
6760-
*/
6761-
WARN_ON_ONCE(swhash->online);
6748+
if (WARN_ON_ONCE(!head))
67626749
return -EINVAL;
6763-
}
67646750

67656751
hlist_add_head_rcu(&event->hlist_entry, head);
67666752
perf_event_update_userpage(event);
@@ -6828,7 +6814,6 @@ static int swevent_hlist_get_cpu(struct perf_event *event, int cpu)
68286814
int err = 0;
68296815

68306816
mutex_lock(&swhash->hlist_mutex);
6831-
68326817
if (!swevent_hlist_deref(swhash) && cpu_online(cpu)) {
68336818
struct swevent_hlist *hlist;
68346819

@@ -9291,7 +9276,6 @@ static void perf_event_init_cpu(int cpu)
92919276
struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
92929277

92939278
mutex_lock(&swhash->hlist_mutex);
9294-
swhash->online = true;
92959279
if (swhash->hlist_refcount > 0) {
92969280
struct swevent_hlist *hlist;
92979281

@@ -9333,14 +9317,7 @@ static void perf_event_exit_cpu_context(int cpu)
93339317

93349318
static void perf_event_exit_cpu(int cpu)
93359319
{
9336-
struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
9337-
93389320
perf_event_exit_cpu_context(cpu);
9339-
9340-
mutex_lock(&swhash->hlist_mutex);
9341-
swhash->online = false;
9342-
swevent_hlist_release(swhash);
9343-
mutex_unlock(&swhash->hlist_mutex);
93449321
}
93459322
#else
93469323
static inline void perf_event_exit_cpu(int cpu) { }

tools/perf/builtin-buildid-list.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int cmd_buildid_list(int argc, const char **argv,
110110
setup_pager();
111111

112112
if (show_kernel)
113-
return sysfs__fprintf_build_id(stdout);
113+
return !(sysfs__fprintf_build_id(stdout) > 0);
114114

115115
return perf_session__list_build_ids(force, with_hits);
116116
}

tools/perf/ui/browsers/hists.c

+8
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ static bool hist_browser__toggle_fold(struct hist_browser *browser)
298298
struct callchain_list *cl = container_of(ms, struct callchain_list, ms);
299299
bool has_children;
300300

301+
if (!he || !ms)
302+
return false;
303+
301304
if (ms == &he->ms)
302305
has_children = hist_entry__toggle_fold(he);
303306
else
@@ -928,6 +931,8 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser)
928931
}
929932

930933
ui_browser__hists_init_top(browser);
934+
hb->he_selection = NULL;
935+
hb->selection = NULL;
931936

932937
for (nd = browser->top; nd; nd = rb_next(nd)) {
933938
struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
@@ -1033,6 +1038,9 @@ static void ui_browser__hists_seek(struct ui_browser *browser,
10331038
* and stop when we printed enough lines to fill the screen.
10341039
*/
10351040
do_offset:
1041+
if (!nd)
1042+
return;
1043+
10361044
if (offset > 0) {
10371045
do {
10381046
h = rb_entry(nd, struct hist_entry, rb_node);

tools/perf/util/build-id.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int build_id__sprintf(const u8 *build_id, int len, char *bf)
9191
bid += 2;
9292
}
9393

94-
return raw - build_id;
94+
return (bid - bf) + 1;
9595
}
9696

9797
int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)

tools/perf/util/parse-events.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = {
124124
.symbol = "dummy",
125125
.alias = "",
126126
},
127+
[PERF_COUNT_SW_BPF_OUTPUT] = {
128+
.symbol = "bpf-output",
129+
.alias = "",
130+
},
127131
};
128132

129133
#define __PERF_EVENT_FIELD(config, name) \
@@ -1879,7 +1883,7 @@ void print_symbol_events(const char *event_glob, unsigned type,
18791883

18801884
for (i = 0; i < max; i++, syms++) {
18811885

1882-
if (event_glob != NULL &&
1886+
if (event_glob != NULL && syms->symbol != NULL &&
18831887
!(strglobmatch(syms->symbol, event_glob) ||
18841888
(syms->alias && strglobmatch(syms->alias, event_glob))))
18851889
continue;

0 commit comments

Comments
 (0)