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
This commit is contained in:
Linus Torvalds 2016-01-08 13:52:59 -08:00
commit 3ab6d1ebd5
5 changed files with 21 additions and 32 deletions

View File

@ -3154,15 +3154,16 @@ static int event_enable_on_exec(struct perf_event *event,
* Enable all of a task's events that have been marked enable-on-exec. * Enable all of a task's events that have been marked enable-on-exec.
* This expects task == current. * This expects task == current.
*/ */
static void perf_event_enable_on_exec(struct perf_event_context *ctx) static void perf_event_enable_on_exec(int ctxn)
{ {
struct perf_event_context *clone_ctx = NULL; struct perf_event_context *ctx, *clone_ctx = NULL;
struct perf_event *event; struct perf_event *event;
unsigned long flags; unsigned long flags;
int enabled = 0; int enabled = 0;
int ret; int ret;
local_irq_save(flags); local_irq_save(flags);
ctx = current->perf_event_ctxp[ctxn];
if (!ctx || !ctx->nr_events) if (!ctx || !ctx->nr_events)
goto out; goto out;
@ -3205,17 +3206,11 @@ out:
void perf_event_exec(void) void perf_event_exec(void)
{ {
struct perf_event_context *ctx;
int ctxn; int ctxn;
rcu_read_lock(); rcu_read_lock();
for_each_task_context_nr(ctxn) { for_each_task_context_nr(ctxn)
ctx = current->perf_event_ctxp[ctxn]; perf_event_enable_on_exec(ctxn);
if (!ctx)
continue;
perf_event_enable_on_exec(ctx);
}
rcu_read_unlock(); rcu_read_unlock();
} }
@ -6493,9 +6488,6 @@ struct swevent_htable {
/* Recursion avoidance in each contexts */ /* Recursion avoidance in each contexts */
int recursion[PERF_NR_CONTEXTS]; int recursion[PERF_NR_CONTEXTS];
/* Keeps track of cpu being initialized/exited */
bool online;
}; };
static DEFINE_PER_CPU(struct swevent_htable, swevent_htable); static DEFINE_PER_CPU(struct swevent_htable, swevent_htable);
@ -6753,14 +6745,8 @@ static int perf_swevent_add(struct perf_event *event, int flags)
hwc->state = !(flags & PERF_EF_START); hwc->state = !(flags & PERF_EF_START);
head = find_swevent_head(swhash, event); head = find_swevent_head(swhash, event);
if (!head) { if (WARN_ON_ONCE(!head))
/*
* We can race with cpu hotplug code. Do not
* WARN if the cpu just got unplugged.
*/
WARN_ON_ONCE(swhash->online);
return -EINVAL; return -EINVAL;
}
hlist_add_head_rcu(&event->hlist_entry, head); hlist_add_head_rcu(&event->hlist_entry, head);
perf_event_update_userpage(event); perf_event_update_userpage(event);
@ -6828,7 +6814,6 @@ static int swevent_hlist_get_cpu(struct perf_event *event, int cpu)
int err = 0; int err = 0;
mutex_lock(&swhash->hlist_mutex); mutex_lock(&swhash->hlist_mutex);
if (!swevent_hlist_deref(swhash) && cpu_online(cpu)) { if (!swevent_hlist_deref(swhash) && cpu_online(cpu)) {
struct swevent_hlist *hlist; struct swevent_hlist *hlist;
@ -9291,7 +9276,6 @@ static void perf_event_init_cpu(int cpu)
struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu); struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
mutex_lock(&swhash->hlist_mutex); mutex_lock(&swhash->hlist_mutex);
swhash->online = true;
if (swhash->hlist_refcount > 0) { if (swhash->hlist_refcount > 0) {
struct swevent_hlist *hlist; struct swevent_hlist *hlist;
@ -9333,14 +9317,7 @@ static void perf_event_exit_cpu_context(int cpu)
static void perf_event_exit_cpu(int cpu) static void perf_event_exit_cpu(int cpu)
{ {
struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
perf_event_exit_cpu_context(cpu); perf_event_exit_cpu_context(cpu);
mutex_lock(&swhash->hlist_mutex);
swhash->online = false;
swevent_hlist_release(swhash);
mutex_unlock(&swhash->hlist_mutex);
} }
#else #else
static inline void perf_event_exit_cpu(int cpu) { } static inline void perf_event_exit_cpu(int cpu) { }

View File

@ -110,7 +110,7 @@ int cmd_buildid_list(int argc, const char **argv,
setup_pager(); setup_pager();
if (show_kernel) if (show_kernel)
return sysfs__fprintf_build_id(stdout); return !(sysfs__fprintf_build_id(stdout) > 0);
return perf_session__list_build_ids(force, with_hits); return perf_session__list_build_ids(force, with_hits);
} }

View File

@ -298,6 +298,9 @@ static bool hist_browser__toggle_fold(struct hist_browser *browser)
struct callchain_list *cl = container_of(ms, struct callchain_list, ms); struct callchain_list *cl = container_of(ms, struct callchain_list, ms);
bool has_children; bool has_children;
if (!he || !ms)
return false;
if (ms == &he->ms) if (ms == &he->ms)
has_children = hist_entry__toggle_fold(he); has_children = hist_entry__toggle_fold(he);
else else
@ -928,6 +931,8 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser)
} }
ui_browser__hists_init_top(browser); ui_browser__hists_init_top(browser);
hb->he_selection = NULL;
hb->selection = NULL;
for (nd = browser->top; nd; nd = rb_next(nd)) { for (nd = browser->top; nd; nd = rb_next(nd)) {
struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 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,
* and stop when we printed enough lines to fill the screen. * and stop when we printed enough lines to fill the screen.
*/ */
do_offset: do_offset:
if (!nd)
return;
if (offset > 0) { if (offset > 0) {
do { do {
h = rb_entry(nd, struct hist_entry, rb_node); h = rb_entry(nd, struct hist_entry, rb_node);

View File

@ -91,7 +91,7 @@ int build_id__sprintf(const u8 *build_id, int len, char *bf)
bid += 2; bid += 2;
} }
return raw - build_id; return (bid - bf) + 1;
} }
int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id) int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)

View File

@ -124,6 +124,10 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = {
.symbol = "dummy", .symbol = "dummy",
.alias = "", .alias = "",
}, },
[PERF_COUNT_SW_BPF_OUTPUT] = {
.symbol = "bpf-output",
.alias = "",
},
}; };
#define __PERF_EVENT_FIELD(config, name) \ #define __PERF_EVENT_FIELD(config, name) \
@ -1879,7 +1883,7 @@ restart:
for (i = 0; i < max; i++, syms++) { for (i = 0; i < max; i++, syms++) {
if (event_glob != NULL && if (event_glob != NULL && syms->symbol != NULL &&
!(strglobmatch(syms->symbol, event_glob) || !(strglobmatch(syms->symbol, event_glob) ||
(syms->alias && strglobmatch(syms->alias, event_glob)))) (syms->alias && strglobmatch(syms->alias, event_glob))))
continue; continue;