Skip to content

Commit

Permalink
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…linux/kernel/git/tip/tip

Pull perf fixes from Ingo Molnar:
 "Six fixes for bugs that were found via fuzzing, and a trivial
  hw-enablement patch for AMD Family-17h CPU PMUs"

* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  perf/x86/intel/uncore: Allow only a single PMU/box within an events group
  perf/x86/intel: Cure bogus unwind from PEBS entries
  perf/x86: Restore TASK_SIZE check on frame pointer
  perf/core: Fix address filter parser
  perf/x86: Add perf support for AMD family-17h processors
  perf/x86/uncore: Fix crash by removing bogus event_list[] handling for SNB client uncore IMC
  perf/core: Do not set cpuctx->cgrp for unscheduled cgroups
  • Loading branch information
Linus Torvalds committed Nov 23, 2016
2 parents 23aabe7 + 033ac60 commit ded9b5d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
8 changes: 7 additions & 1 deletion arch/x86/events/amd/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,13 @@ static int __init amd_core_pmu_init(void)
pr_cont("Fam15h ");
x86_pmu.get_event_constraints = amd_get_event_constraints_f15h;
break;

case 0x17:
pr_cont("Fam17h ");
/*
* In family 17h, there are no event constraints in the PMC hardware.
* We fallback to using default amd_get_event_constraints.
*/
break;
default:
pr_err("core perfctr but no constraints; unknown hardware!\n");
return -ENODEV;
Expand Down
10 changes: 2 additions & 8 deletions arch/x86/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,7 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *ent
frame.next_frame = 0;
frame.return_address = 0;

if (!access_ok(VERIFY_READ, fp, 8))
if (!valid_user_frame(fp, sizeof(frame)))
break;

bytes = __copy_from_user_nmi(&frame.next_frame, fp, 4);
Expand All @@ -2362,9 +2362,6 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *ent
if (bytes != 0)
break;

if (!valid_user_frame(fp, sizeof(frame)))
break;

perf_callchain_store(entry, cs_base + frame.return_address);
fp = compat_ptr(ss_base + frame.next_frame);
}
Expand Down Expand Up @@ -2413,7 +2410,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
frame.next_frame = NULL;
frame.return_address = 0;

if (!access_ok(VERIFY_READ, fp, sizeof(*fp) * 2))
if (!valid_user_frame(fp, sizeof(frame)))
break;

bytes = __copy_from_user_nmi(&frame.next_frame, fp, sizeof(*fp));
Expand All @@ -2423,9 +2420,6 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
if (bytes != 0)
break;

if (!valid_user_frame(fp, sizeof(frame)))
break;

perf_callchain_store(entry, frame.return_address);
fp = (void __user *)frame.next_frame;
}
Expand Down
35 changes: 23 additions & 12 deletions arch/x86/events/intel/ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,20 +1108,20 @@ static void setup_pebs_sample_data(struct perf_event *event,
}

/*
* We use the interrupt regs as a base because the PEBS record
* does not contain a full regs set, specifically it seems to
* lack segment descriptors, which get used by things like
* user_mode().
* We use the interrupt regs as a base because the PEBS record does not
* contain a full regs set, specifically it seems to lack segment
* descriptors, which get used by things like user_mode().
*
* In the simple case fix up only the IP and BP,SP regs, for
* PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly.
* A possible PERF_SAMPLE_REGS will have to transfer all regs.
* In the simple case fix up only the IP for PERF_SAMPLE_IP.
*
* We must however always use BP,SP from iregs for the unwinder to stay
* sane; the record BP,SP can point into thin air when the record is
* from a previous PMI context or an (I)RET happend between the record
* and PMI.
*/
*regs = *iregs;
regs->flags = pebs->flags;
set_linear_ip(regs, pebs->ip);
regs->bp = pebs->bp;
regs->sp = pebs->sp;

if (sample_type & PERF_SAMPLE_REGS_INTR) {
regs->ax = pebs->ax;
Expand All @@ -1130,10 +1130,21 @@ static void setup_pebs_sample_data(struct perf_event *event,
regs->dx = pebs->dx;
regs->si = pebs->si;
regs->di = pebs->di;
regs->bp = pebs->bp;
regs->sp = pebs->sp;

regs->flags = pebs->flags;
/*
* Per the above; only set BP,SP if we don't need callchains.
*
* XXX: does this make sense?
*/
if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
regs->bp = pebs->bp;
regs->sp = pebs->sp;
}

/*
* Preserve PERF_EFLAGS_VM from set_linear_ip().
*/
regs->flags = pebs->flags | (regs->flags & PERF_EFLAGS_VM);
#ifndef CONFIG_X86_32
regs->r8 = pebs->r8;
regs->r9 = pebs->r9;
Expand Down
8 changes: 4 additions & 4 deletions arch/x86/events/intel/uncore.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ static struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type,
*/
static int uncore_pmu_event_init(struct perf_event *event);

static bool is_uncore_event(struct perf_event *event)
static bool is_box_event(struct intel_uncore_box *box, struct perf_event *event)
{
return event->pmu->event_init == uncore_pmu_event_init;
return &box->pmu->pmu == event->pmu;
}

static int
Expand All @@ -340,7 +340,7 @@ uncore_collect_events(struct intel_uncore_box *box, struct perf_event *leader,

n = box->n_events;

if (is_uncore_event(leader)) {
if (is_box_event(box, leader)) {
box->event_list[n] = leader;
n++;
}
Expand All @@ -349,7 +349,7 @@ uncore_collect_events(struct intel_uncore_box *box, struct perf_event *leader,
return n;

list_for_each_entry(event, &leader->sibling_list, group_entry) {
if (!is_uncore_event(event) ||
if (!is_box_event(box, event) ||
event->state <= PERF_EVENT_STATE_OFF)
continue;

Expand Down
12 changes: 0 additions & 12 deletions arch/x86/events/intel/uncore_snb.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,24 +490,12 @@ static int snb_uncore_imc_event_add(struct perf_event *event, int flags)

snb_uncore_imc_event_start(event, 0);

box->n_events++;

return 0;
}

static void snb_uncore_imc_event_del(struct perf_event *event, int flags)
{
struct intel_uncore_box *box = uncore_event_to_box(event);
int i;

snb_uncore_imc_event_stop(event, PERF_EF_UPDATE);

for (i = 0; i < box->n_events; i++) {
if (event == box->event_list[i]) {
--box->n_events;
break;
}
}
}

int snb_pci2phy_map_init(int devid)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/events/perf_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct debug_store {
* Per register state.
*/
struct er_account {
raw_spinlock_t lock; /* per-core: protect structure */
raw_spinlock_t lock; /* per-core: protect structure */
u64 config; /* extra MSR config */
u64 reg; /* extra MSR number */
atomic_t ref; /* reference count */
Expand Down
13 changes: 13 additions & 0 deletions kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,17 @@ list_update_cgroup_event(struct perf_event *event,
* this will always be called from the right CPU.
*/
cpuctx = __get_cpu_context(ctx);

/* Only set/clear cpuctx->cgrp if current task uses event->cgrp. */
if (perf_cgroup_from_task(current, ctx) != event->cgrp) {
/*
* We are removing the last cpu event in this context.
* If that event is not active in this cpu, cpuctx->cgrp
* should've been cleared by perf_cgroup_switch.
*/
WARN_ON_ONCE(!add && cpuctx->cgrp);
return;
}
cpuctx->cgrp = add ? event->cgrp : NULL;
}

Expand Down Expand Up @@ -8018,6 +8029,7 @@ static void perf_event_addr_filters_apply(struct perf_event *event)
* if <size> is not specified, the range is treated as a single address.
*/
enum {
IF_ACT_NONE = -1,
IF_ACT_FILTER,
IF_ACT_START,
IF_ACT_STOP,
Expand All @@ -8041,6 +8053,7 @@ static const match_table_t if_tokens = {
{ IF_SRC_KERNEL, "%u/%u" },
{ IF_SRC_FILEADDR, "%u@%s" },
{ IF_SRC_KERNELADDR, "%u" },
{ IF_ACT_NONE, NULL },
};

/*
Expand Down

0 comments on commit ded9b5d

Please sign in to comment.