perf fixes
Subsystems (2)
Linus,
Please pull the latest perf-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf-urgent-for-linus
# HEAD: 8ef9b8455a2a3049efa9e46e8a6402b972a3eb41 perf/x86/intel: Fix PEBSv3 record drain
This contains:
- A set of fixes found by directed-random perf fuzzing efforts by Vince Weaver, Alexander Shishkin and Peter Zijlstra,
- a cqm driver crash fix,
- an AMD uncore driver use after free fix.
Thanks,
Ingo
------------------>
Alexander Shishkin (5):
perf/core: Fix a race between mmap_close() and set_output() of AUX events perf/core: Fix aux_mmap_count vs aux_refcount order perf/x86/intel/bts: Fix confused ordering of PMU callbacks perf/x86/intel/bts: Fix BTS PMI detection perf/x86/intel/bts: Kill a silly warning
Jiri Olsa (1):
perf/x86/intel/cqm: Check cqm/mbm enabled state in event init
Peter Zijlstra (2):
perf/core: Remove WARN from perf_event_read() perf/x86/intel: Fix PEBSv3 record drain
Sebastian Andrzej Siewior (1):
perf/x86/amd/uncore: Prevent use after free
arch/x86/events/amd/uncore.c | 22 ++++++-- arch/x86/events/intel/bts.c | 123 +++++++++++++++++++++++++++++++++---------- arch/x86/events/intel/cqm.c | 9 ++++ arch/x86/events/intel/ds.c | 19 ++++--- kernel/events/core.c | 47 +++++++++++++---- kernel/events/ring_buffer.c | 15 ++++-- 6 files changed, 180 insertions(+), 55 deletions(-)
arch/x86/events/amd/uncore.c +18 -4
@@ -29,6 +29,8 @@#define COUNTER_SHIFT 16 +static HLIST_HEAD (uncore_unused_list); +struct amd_uncore {int id;int refcnt;
@@ -39,7 +41,7 @@ struct amd_uncore {cpumask_t *active_mask;struct pmu *pmu;struct perf_event *events[MAX_COUNTERS ]; -struct amd_uncore *free_when_cpu_online; +struct hlist_node node; };static struct amd_uncore *__percpu *amd_uncore_nb;
@@ -306,6 +308,7 @@ static int amd_uncore_cpu_up_prepare(unsigned int cpu) uncore_nb->msr_base =MSR_F15H_NB_PERF_CTL ; uncore_nb->active_mask = &amd_nb_active_mask; uncore_nb->pmu = &amd_nb_pmu; + uncore_nb->id =-1 ; *per_cpu_ptr (amd_uncore_nb, cpu) = uncore_nb; }
@@ -319,6 +322,7 @@ static int amd_uncore_cpu_up_prepare(unsigned int cpu) uncore_l2->msr_base =MSR_F16H_L2I_PERF_CTL ; uncore_l2->active_mask = &amd_l2_active_mask; uncore_l2->pmu = &amd_l2_pmu; + uncore_l2->id =-1 ; *per_cpu_ptr (amd_uncore_l2, cpu) = uncore_l2; }
@@ -348,7 +352,7 @@ amd_uncore_find_online_sibling(struct amd_uncore *this,continue ;if (this->id == that->id) { - that->free_when_cpu_online = this; +hlist_add_head (&this->node, &uncore_unused_list); this = that;break ; }
@@ -388,13 +392,23 @@ static int amd_uncore_cpu_starting(unsigned int cpu)return 0 ; } +static void uncore_clean_online (void ) +{ +struct amd_uncore *uncore; +struct hlist_node *n; + +hlist_for_each_entry_safe (uncore, n, &uncore_unused_list, node) { +hlist_del (&uncore->node); +kfree (uncore); + } +} +static void uncore_online (unsigned int cpu,struct amd_uncore *__percpu *uncores) {struct amd_uncore *uncore = *per_cpu_ptr (uncores, cpu); -kfree (uncore->free_when_cpu_online); - uncore->free_when_cpu_online =NULL ; +uncore_clean_online ();if (cpu == uncore->cpu)cpumask_set_cpu (cpu, uncore->active_mask);
arch/x86/events/intel/bts.c +94 -29
226 lines not on this page · raw message
arch/x86/events/intel/cqm.c +9 -0
@@ -458,6 +458,11 @@ static void __intel_cqm_event_count(void *info);static void init_mbm_sample (u32 rmid,u32 evt_type);static void __intel_mbm_event_count (void *info); +static bool is_cqm_event (int e) +{ +return (e ==QOS_L3_OCCUP_EVENT_ID ); +} +static bool is_mbm_event (int e) {return (e >=QOS_MBM_TOTAL_EVENT_ID && e <=QOS_MBM_LOCAL_EVENT_ID );
@@ -1366,6 +1371,10 @@ static int intel_cqm_event_init(struct perf_event *event) (event->attr.config > QOS_MBM_LOCAL_EVENT_ID))return -EINVAL ; +if ((is_cqm_event (event->attr.config) && !cqm_enabled) || + (is_mbm_event (event->attr.config) && !mbm_enabled)) +return -EINVAL ; +/* unsupported modes and filters */ if (event->attr.exclude_user || event->attr.exclude_kernel ||
arch/x86/events/intel/ds.c +11 -8
@@ -1274,18 +1274,18 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)struct pebs_record_nhm *p = at;u64 pebs_status; -/* PEBS v3 has accurate status bits */ + pebs_status = p->status & cpuc->pebs_enabled; + pebs_status &= (1ULL << x86_pmu.max_pebs_events) -1 ; + +/* PEBS v3 has more accurate status bits */ if (x86_pmu.intel_cap.pebs_format >=3 ) { -for_each_set_bit (bit, (unsigned long *)&p->status, -MAX_PEBS_EVENTS ) +for_each_set_bit (bit, (unsigned long *)&pebs_status, + x86_pmu.max_pebs_events) counts[bit]++;continue ; } - pebs_status = p->status & cpuc->pebs_enabled; - pebs_status &= (1ULL << x86_pmu.max_pebs_events) -1 ; -/* * On some CPUs the PEBS status can be zero when PEBS is * racing with clearing of GLOBAL_STATUS.
@@ -1333,8 +1333,11 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)continue ; event = cpuc->events[bit]; -WARN_ON_ONCE (!event); -WARN_ON_ONCE (!event->attr.precise_ip); +if (WARN_ON_ONCE (!event)) +continue ; + +if (WARN_ON_ONCE (!event->attr.precise_ip)) +continue ;/* log dropped samples number */ if (error[bit])
kernel/events/core.c +37 -10
92 lines not on this page · raw message
kernel/events/ring_buffer.c +11 -4
@@ -330,15 +330,22 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,if (!rb)return NULL ; -if (!rb_has_aux (rb) || !atomic_inc_not_zero (&rb->aux_refcount)) +if (!rb_has_aux (rb)) goto err;/* -* If rb::aux_mmap_count is zero (and rb_has_aux() above went through), -* the aux buffer is in perf_mmap_close(), about to get freed. +* If aux_mmap_count is zero, the aux buffer is in perf_mmap_close(), +* about to get freed, so we leave immediately. +* +* Checking rb::aux_mmap_count and rb::refcount has to be done in +* the same order, see perf_mmap_close. Otherwise we end up freeing +* aux pages in this path, which is a bug, because in_atomic(). */ if (!atomic_read (&rb->aux_mmap_count)) - goto err_put; + goto err; + +if (!atomic_inc_not_zero (&rb->aux_refcount)) + goto err;/* * Nesting is not supported for AUX area, make sure nested