Skip to content

Commit 64049d1

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: "Misc fixes plus a small hw-enablement patch for Intel IB model 58 uncore events" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/x86/intel/lbr: Demand proper privileges for PERF_SAMPLE_BRANCH_KERNEL perf/x86/intel/lbr: Fix LBR filter perf/x86: Blacklist all MEM_*_RETIRED events for Ivy Bridge perf: Fix vmalloc ring buffer pages handling perf/x86/intel: Fix unintended variable name reuse perf/x86/intel: Add support for IvyBridge model 58 Uncore perf/x86/intel: Fix typo in perf_event_intel_uncore.c x86: Eliminate irq_mis_count counted in arch_irq_stat
2 parents f8ce1fa + 7cc23cd commit 64049d1

5 files changed

Lines changed: 51 additions & 26 deletions

File tree

‎arch/x86/kernel/cpu/perf_event_intel.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,15 @@ static struct event_constraint intel_ivb_event_constraints[] __read_mostly =
128128
INTEL_UEVENT_CONSTRAINT(0x08a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */
129129
INTEL_UEVENT_CONSTRAINT(0x0ca3, 0x4), /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */
130130
INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */
131-
INTEL_EVENT_CONSTRAINT(0xd0, 0xf), /* MEM_UOPS_RETIRED.* */
132-
INTEL_EVENT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
133-
INTEL_EVENT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
134-
INTEL_EVENT_CONSTRAINT(0xd3, 0xf), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */
131+
/*
132+
* Errata BV98 -- MEM_*_RETIRED events can leak between counters of SMT
133+
* siblings; disable these events because they can corrupt unrelated
134+
* counters.
135+
*/
136+
INTEL_EVENT_CONSTRAINT(0xd0, 0x0), /* MEM_UOPS_RETIRED.* */
137+
INTEL_EVENT_CONSTRAINT(0xd1, 0x0), /* MEM_LOAD_UOPS_RETIRED.* */
138+
INTEL_EVENT_CONSTRAINT(0xd2, 0x0), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
139+
INTEL_EVENT_CONSTRAINT(0xd3, 0x0), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */
135140
EVENT_CONSTRAINT_END
136141
};
137142

‎arch/x86/kernel/cpu/perf_event_intel_lbr.c‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,19 @@ void intel_pmu_lbr_read(void)
310310
* - in case there is no HW filter
311311
* - in case the HW filter has errata or limitations
312312
*/
313-
static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
313+
static int intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
314314
{
315315
u64 br_type = event->attr.branch_sample_type;
316316
int mask = 0;
317317

318318
if (br_type & PERF_SAMPLE_BRANCH_USER)
319319
mask |= X86_BR_USER;
320320

321-
if (br_type & PERF_SAMPLE_BRANCH_KERNEL)
321+
if (br_type & PERF_SAMPLE_BRANCH_KERNEL) {
322+
if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN))
323+
return -EACCES;
322324
mask |= X86_BR_KERNEL;
325+
}
323326

324327
/* we ignore BRANCH_HV here */
325328

@@ -339,6 +342,8 @@ static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
339342
* be used by fixup code for some CPU
340343
*/
341344
event->hw.branch_reg.reg = mask;
345+
346+
return 0;
342347
}
343348

344349
/*
@@ -386,7 +391,9 @@ int intel_pmu_setup_lbr_filter(struct perf_event *event)
386391
/*
387392
* setup SW LBR filter
388393
*/
389-
intel_pmu_setup_sw_lbr_filter(event);
394+
ret = intel_pmu_setup_sw_lbr_filter(event);
395+
if (ret)
396+
return ret;
390397

391398
/*
392399
* setup HW LBR filter, if any
@@ -442,8 +449,18 @@ static int branch_type(unsigned long from, unsigned long to)
442449
return X86_BR_NONE;
443450

444451
addr = buf;
445-
} else
446-
addr = (void *)from;
452+
} else {
453+
/*
454+
* The LBR logs any address in the IP, even if the IP just
455+
* faulted. This means userspace can control the from address.
456+
* Ensure we don't blindy read any address by validating it is
457+
* a known text address.
458+
*/
459+
if (kernel_text_address(from))
460+
addr = (void *)from;
461+
else
462+
return X86_BR_NONE;
463+
}
447464

448465
/*
449466
* decoder needs to know the ABI especially

‎arch/x86/kernel/cpu/perf_event_intel_uncore.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,7 +3093,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
30933093
static int __init uncore_type_init(struct intel_uncore_type *type)
30943094
{
30953095
struct intel_uncore_pmu *pmus;
3096-
struct attribute_group *events_group;
3096+
struct attribute_group *attr_group;
30973097
struct attribute **attrs;
30983098
int i, j;
30993099

@@ -3120,19 +3120,19 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
31203120
while (type->event_descs[i].attr.attr.name)
31213121
i++;
31223122

3123-
events_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
3124-
sizeof(*events_group), GFP_KERNEL);
3125-
if (!events_group)
3123+
attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
3124+
sizeof(*attr_group), GFP_KERNEL);
3125+
if (!attr_group)
31263126
goto fail;
31273127

3128-
attrs = (struct attribute **)(events_group + 1);
3129-
events_group->name = "events";
3130-
events_group->attrs = attrs;
3128+
attrs = (struct attribute **)(attr_group + 1);
3129+
attr_group->name = "events";
3130+
attr_group->attrs = attrs;
31313131

31323132
for (j = 0; j < i; j++)
31333133
attrs[j] = &type->event_descs[j].attr.attr;
31343134

3135-
type->events_group = events_group;
3135+
type->events_group = attr_group;
31363136
}
31373137

31383138
type->pmu_group = &uncore_pmu_attr_group;
@@ -3545,11 +3545,12 @@ static int __init uncore_cpu_init(void)
35453545
msr_uncores = nhm_msr_uncores;
35463546
break;
35473547
case 42: /* Sandy Bridge */
3548+
case 58: /* Ivy Bridge */
35483549
if (snb_uncore_cbox.num_boxes > max_cores)
35493550
snb_uncore_cbox.num_boxes = max_cores;
35503551
msr_uncores = snb_msr_uncores;
35513552
break;
3552-
case 45: /* Sandy Birdge-EP */
3553+
case 45: /* Sandy Bridge-EP */
35533554
if (snbep_uncore_cbox.num_boxes > max_cores)
35543555
snbep_uncore_cbox.num_boxes = max_cores;
35553556
msr_uncores = snbep_msr_uncores;

‎arch/x86/kernel/irq.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
165165
u64 arch_irq_stat(void)
166166
{
167167
u64 sum = atomic_read(&irq_err_count);
168-
169-
#ifdef CONFIG_X86_IO_APIC
170-
sum += atomic_read(&irq_mis_count);
171-
#endif
172168
return sum;
173169
}
174170

‎kernel/events/ring_buffer.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,16 @@ void rb_free(struct ring_buffer *rb)
326326
}
327327

328328
#else
329+
static int data_page_nr(struct ring_buffer *rb)
330+
{
331+
return rb->nr_pages << page_order(rb);
332+
}
329333

330334
struct page *
331335
perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff)
332336
{
333-
if (pgoff > (1UL << page_order(rb)))
337+
/* The '>' counts in the user page. */
338+
if (pgoff > data_page_nr(rb))
334339
return NULL;
335340

336341
return vmalloc_to_page((void *)rb->user_page + pgoff * PAGE_SIZE);
@@ -350,10 +355,11 @@ static void rb_free_work(struct work_struct *work)
350355
int i, nr;
351356

352357
rb = container_of(work, struct ring_buffer, work);
353-
nr = 1 << page_order(rb);
358+
nr = data_page_nr(rb);
354359

355360
base = rb->user_page;
356-
for (i = 0; i < nr + 1; i++)
361+
/* The '<=' counts in the user page. */
362+
for (i = 0; i <= nr; i++)
357363
perf_mmap_unmark_page(base + (i * PAGE_SIZE));
358364

359365
vfree(base);
@@ -387,7 +393,7 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
387393
rb->user_page = all_buf;
388394
rb->data_pages[0] = all_buf + PAGE_SIZE;
389395
rb->page_order = ilog2(nr_pages);
390-
rb->nr_pages = 1;
396+
rb->nr_pages = !!nr_pages;
391397

392398
ring_buffer_init(rb, watermark, flags);
393399

0 commit comments

Comments
 (0)