History

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: a BTS fix, a PT NMI handling fix, a PMU sysfs fix and an SRCU annotation" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/core: Add SRCU annotation for pmus list walk perf/x86/intel: Fix PT PMI handling perf/x86/intel/bts: Fix the use of page_private() perf/x86: Fix potential out-of-bounds access

Linus Torvalds committed 6 years ago

Commit c4ff10e2 parents 6c1c79a 9f0bff13 files · +27 −10Browse files

Unified · Split

3 files
  1. arch/x86/events/core.c +15 −4
  2. arch/x86/events/intel/bts.c +11 −5
  3. kernel/events/core.c +1 −1
arch/x86/events/core.c+15−4
@@ -376,7 +376,7 @@ int x86_add_exclusive(unsigned int what) · 375 unmodified lines
376 * LBR and BTS are still mutually exclusive.376 * LBR and BTS are still mutually exclusive.
377 */377 */
378 if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt)378 if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt)
379 return 0;379 goto out;
380 380
381 if (!atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what])) {381 if (!atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what])) {
382 mutex_lock(&pmc_reserve_mutex);382 mutex_lock(&pmc_reserve_mutex);
@@ -388,6 +388,7 @@ int x86_add_exclusive(unsigned int what) · 5 unmodified lines
388 mutex_unlock(&pmc_reserve_mutex);388 mutex_unlock(&pmc_reserve_mutex);
389 }389 }
390 390
391out:
391 atomic_inc(&active_events);392 atomic_inc(&active_events);
392 return 0;393 return 0;
393 394
@@ -398,11 +399,15 @@ fail_unlock: · 4 unmodified lines
398 399
399void x86_del_exclusive(unsigned int what)400void x86_del_exclusive(unsigned int what)
400{401{
402 atomic_dec(&active_events);
403
404 /*
405 * See the comment in x86_add_exclusive().
406 */
401 if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt)407 if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt)
402 return;408 return;
403 409
404 atomic_dec(&x86_pmu.lbr_exclusive[what]);410 atomic_dec(&x86_pmu.lbr_exclusive[what]);
405 atomic_dec(&active_events);
406}411}
407 412
408int x86_setup_perfctr(struct perf_event *event)413int x86_setup_perfctr(struct perf_event *event)
@@ -1642,9 +1647,12 @@ static struct attribute_group x86_pmu_format_group __ro_after_init = { · 1233 unmodified lines
1642 1647
1643ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page)1648ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page)
1644{1649{
1645 struct perf_pmu_events_attr *pmu_attr = \1650 struct perf_pmu_events_attr *pmu_attr =
1646 container_of(attr, struct perf_pmu_events_attr, attr);1651 container_of(attr, struct perf_pmu_events_attr, attr);
1647 u64 config = x86_pmu.event_map(pmu_attr->id);1652 u64 config = 0;
1653
1654 if (pmu_attr->id < x86_pmu.max_events)
1655 config = x86_pmu.event_map(pmu_attr->id);
1648 1656
1649 /* string trumps id */1657 /* string trumps id */
1650 if (pmu_attr->event_str)1658 if (pmu_attr->event_str)
@@ -1713,6 +1721,9 @@ is_visible(struct kobject *kobj, struct attribute *attr, int idx) · 62 unmodified lines
1713{1721{
1714 struct perf_pmu_events_attr *pmu_attr;1722 struct perf_pmu_events_attr *pmu_attr;
1715 1723
1724 if (idx >= x86_pmu.max_events)
1725 return 0;
1726
1716 pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr);1727 pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr);
1717 /* str trumps id */1728 /* str trumps id */
1718 return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0;1729 return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0;
arch/x86/events/intel/bts.c+11−5
@@ -63,9 +63,17 @@ struct bts_buffer { · 62 unmodified lines
63 63
64static struct pmu bts_pmu;64static struct pmu bts_pmu;
65 65
66static int buf_nr_pages(struct page *page)
67{
68 if (!PagePrivate(page))
69 return 1;
70
71 return 1 << page_private(page);
72}
73
66static size_t buf_size(struct page *page)74static size_t buf_size(struct page *page)
67{75{
68 return 1 << (PAGE_SHIFT + page_private(page));76 return buf_nr_pages(page) * PAGE_SIZE;
69}77}
70 78
71static void *79static void *
@@ -83,9 +91,7 @@ bts_buffer_setup_aux(struct perf_event *event, void **pages, · 11 unmodified lines
83 /* count all the high order buffers */91 /* count all the high order buffers */
84 for (pg = 0, nbuf = 0; pg < nr_pages;) {92 for (pg = 0, nbuf = 0; pg < nr_pages;) {
85 page = virt_to_page(pages[pg]);93 page = virt_to_page(pages[pg]);
86 if (WARN_ON_ONCE(!PagePrivate(page) && nr_pages > 1))94 pg += buf_nr_pages(page);
87 return NULL;
88 pg += 1 << page_private(page);
89 nbuf++;95 nbuf++;
90 }96 }
91 97
@@ -109,7 +115,7 @@ bts_buffer_setup_aux(struct perf_event *event, void **pages, · 17 unmodified lines
109 unsigned int __nr_pages;115 unsigned int __nr_pages;
110 116
111 page = virt_to_page(pages[pg]);117 page = virt_to_page(pages[pg]);
112 __nr_pages = PagePrivate(page) ? 1 << page_private(page) : 1;118 __nr_pages = buf_nr_pages(page);
113 buf->buf[nbuf].page = page;119 buf->buf[nbuf].page = page;
114 buf->buf[nbuf].offset = offset;120 buf->buf[nbuf].offset = offset;
115 buf->buf[nbuf].displacement = (pad ? BTS_RECORD_SIZE - pad : 0);121 buf->buf[nbuf].displacement = (pad ? BTS_RECORD_SIZE - pad : 0);
kernel/events/core.c+1−1
@@ -10523,7 +10523,7 @@ again: · 10522 unmodified lines
10523 goto unlock;10523 goto unlock;
10524 }10524 }
10525 10525
10526 list_for_each_entry_rcu(pmu, &pmus, entry) {10526 list_for_each_entry_rcu(pmu, &pmus, entry, lockdep_is_held(&pmus_srcu)) {
10527 ret = perf_try_init_event(pmu, event);10527 ret = perf_try_init_event(pmu, event);
10528 if (!ret)10528 if (!ret)
10529 goto unlock;10529 goto unlock;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t