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
Unified · Split
| @@ -376,7 +376,7 @@ int x86_add_exclusive(unsigned int what) · 375 unmodified lines | ||
| 376 | 376 | * LBR and BTS are still mutually exclusive. |
| 377 | 377 | */ |
| 378 | 378 | if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt) |
| 379 | − return 0; | |
| 379 | + goto out; | |
| 380 | 380 | |
| 381 | 381 | if (!atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what])) { |
| 382 | 382 | mutex_lock(&pmc_reserve_mutex); |
| @@ -388,6 +388,7 @@ int x86_add_exclusive(unsigned int what) · 5 unmodified lines | ||
| 388 | 388 | mutex_unlock(&pmc_reserve_mutex); |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | +out: | |
| 391 | 392 | atomic_inc(&active_events); |
| 392 | 393 | return 0; |
| 393 | 394 | |
| @@ -398,11 +399,15 @@ fail_unlock: · 4 unmodified lines | ||
| 398 | 399 | |
| 399 | 400 | void 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 | 407 | if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt) |
| 402 | 408 | return; |
| 403 | 409 | |
| 404 | 410 | atomic_dec(&x86_pmu.lbr_exclusive[what]); |
| 405 | − atomic_dec(&active_events); | |
| 406 | 411 | } |
| 407 | 412 | |
| 408 | 413 | int 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 | |
| 1643 | 1648 | ssize_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 | 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 | 1657 | /* string trumps id */ |
| 1650 | 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 | 1722 | struct perf_pmu_events_attr *pmu_attr; |
| 1715 | 1723 | |
| 1724 | + if (idx >= x86_pmu.max_events) | |
| 1725 | + return 0; | |
| 1726 | + | |
| 1716 | 1727 | pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr); |
| 1717 | 1728 | /* str trumps id */ |
| 1718 | 1729 | return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0; |
| @@ -63,9 +63,17 @@ struct bts_buffer { · 62 unmodified lines | ||
| 63 | 63 | |
| 64 | 64 | static struct pmu bts_pmu; |
| 65 | 65 | |
| 66 | +static int buf_nr_pages(struct page *page) | |
| 67 | +{ | |
| 68 | + if (!PagePrivate(page)) | |
| 69 | + return 1; | |
| 70 | + | |
| 71 | + return 1 << page_private(page); | |
| 72 | +} | |
| 73 | + | |
| 66 | 74 | static 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 | |
| 71 | 79 | static void * |
| @@ -83,9 +91,7 @@ bts_buffer_setup_aux(struct perf_event *event, void **pages, · 11 unmodified lines | ||
| 83 | 91 | /* count all the high order buffers */ |
| 84 | 92 | for (pg = 0, nbuf = 0; pg < nr_pages;) { |
| 85 | 93 | page = virt_to_page(pages[pg]); |
| 86 | − if (WARN_ON_ONCE(!PagePrivate(page) && nr_pages > 1)) | |
| 87 | − return NULL; | |
| 88 | − pg += 1 << page_private(page); | |
| 94 | + pg += buf_nr_pages(page); | |
| 89 | 95 | nbuf++; |
| 90 | 96 | } |
| 91 | 97 | |
| @@ -109,7 +115,7 @@ bts_buffer_setup_aux(struct perf_event *event, void **pages, · 17 unmodified lines | ||
| 109 | 115 | unsigned int __nr_pages; |
| 110 | 116 | |
| 111 | 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 | 119 | buf->buf[nbuf].page = page; |
| 114 | 120 | buf->buf[nbuf].offset = offset; |
| 115 | 121 | buf->buf[nbuf].displacement = (pad ? BTS_RECORD_SIZE - pad : 0); |
| @@ -10523,7 +10523,7 @@ again: · 10522 unmodified lines | ||
| 10523 | 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 | 10527 | ret = perf_try_init_event(pmu, event); |
| 10528 | 10528 | if (!ret) |
| 10529 | 10529 | goto unlock; |