Hi Peter and Ingo,
Here are two small fixes that resulted from running perf_fuzzer on a !KPTI
kernel. One is a misguided and unannotated warning and another is a sketchy
use of page_private(). The choice between deleting the BTS driver and
fixing it is not obvious, though. It may theoretically still have users.
Alexander Shishkin (2):
perf/x86/intel/bts: Remove a silly warning
perf/x86/intel/bts: Fix the use of page_private()
arch/x86/events/intel/bts.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
--
2.24.0
Commit
8062382c8dbe2 ("perf/x86/intel/bts: Add BTS PMU driver")
uses page_private(page) without checking the PagePrivate(page) first,
which seems like a potential bug, considering that page->private aliases
with other stuff in struct page.
Fix this by checking PagePrivate() first.
Signed-off-by: Alexander Shishkin <[email protected]>
Fixes: 8062382c8dbe2 ("perf/x86/intel/bts: Add BTS PMU driver")
---
arch/x86/events/intel/bts.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c
index d53b4fb86d87..9e4da1c5a129 100644
--- a/arch/x86/events/intel/bts.c
+++ b/arch/x86/events/intel/bts.c
@@ -63,9 +63,17 @@ struct bts_buffer {
static struct pmu bts_pmu;
+static int buf_nr_pages(struct page *page)
+{
+ if (!PagePrivate(page))
+ return 1;
+
+ return 1 << page_private(page);
+}
+
static size_t buf_size(struct page *page)
{
- return 1 << (PAGE_SHIFT + page_private(page));
+ return 1 << (PAGE_SHIFT + buf_nr_pages(page));
}
static void *
@@ -83,7 +91,7 @@ bts_buffer_setup_aux(struct perf_event *event, void **pages,
/* count all the high order buffers */
for (pg = 0, nbuf = 0; pg < nr_pages;) {
page = virt_to_page(pages[pg]);
- pg += 1 << page_private(page);
+ pg += buf_nr_pages(page);
nbuf++;
}
@@ -107,7 +115,7 @@ bts_buffer_setup_aux(struct perf_event *event, void **pages,
unsigned int __nr_pages;
page = virt_to_page(pages[pg]);
- __nr_pages = PagePrivate(page) ? 1 << page_private(page) : 1;
+ __nr_pages = buf_nr_pages(page);
buf->buf[nbuf].page = page;
buf->buf[nbuf].offset = offset;
buf->buf[nbuf].displacement = (pad ? BTS_RECORD_SIZE - pad : 0);
--
2.24.0
On Thu, Dec 05, 2019 at 05:28:53PM +0300, Alexander Shishkin wrote:
> Commit
>
> 8062382c8dbe2 ("perf/x86/intel/bts: Add BTS PMU driver")
>
> uses page_private(page) without checking the PagePrivate(page) first,
Well, arguably it did check it, but you didn't like that WARN ;-)
> which seems like a potential bug, considering that page->private aliases
> with other stuff in struct page.
>
> Fix this by checking PagePrivate() first.
>
> Signed-off-by: Alexander Shishkin <[email protected]>
> Fixes: 8062382c8dbe2 ("perf/x86/intel/bts: Add BTS PMU driver")
> ---
> arch/x86/events/intel/bts.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c
> index d53b4fb86d87..9e4da1c5a129 100644
> --- a/arch/x86/events/intel/bts.c
> +++ b/arch/x86/events/intel/bts.c
> @@ -63,9 +63,17 @@ struct bts_buffer {
>
> static struct pmu bts_pmu;
>
> +static int buf_nr_pages(struct page *page)
> +{
> + if (!PagePrivate(page))
> + return 1;
> +
> + return 1 << page_private(page);
> +}
Yes, that seems like a sensible helper.
On Thu, Dec 05, 2019 at 05:28:51PM +0300, Alexander Shishkin wrote:
> Hi Peter and Ingo,
>
> Here are two small fixes that resulted from running perf_fuzzer on a !KPTI
> kernel. One is a misguided and unannotated warning and another is a sketchy
> use of page_private(). The choice between deleting the BTS driver and
> fixing it is not obvious, though. It may theoretically still have users.
>
> Alexander Shishkin (2):
> perf/x86/intel/bts: Remove a silly warning
> perf/x86/intel/bts: Fix the use of page_private()
I'll squash the pair, that makes more sense to me.
On Thu, Dec 05, 2019 at 05:28:53PM +0300, Alexander Shishkin wrote:
> Commit
>
> 8062382c8dbe2 ("perf/x86/intel/bts: Add BTS PMU driver")
>
> uses page_private(page) without checking the PagePrivate(page) first,
> which seems like a potential bug, considering that page->private aliases
> with other stuff in struct page.
>
> Fix this by checking PagePrivate() first.
>
> Signed-off-by: Alexander Shishkin <[email protected]>
> Fixes: 8062382c8dbe2 ("perf/x86/intel/bts: Add BTS PMU driver")
> ---
> arch/x86/events/intel/bts.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c
> index d53b4fb86d87..9e4da1c5a129 100644
> --- a/arch/x86/events/intel/bts.c
> +++ b/arch/x86/events/intel/bts.c
> @@ -63,9 +63,17 @@ struct bts_buffer {
>
> static struct pmu bts_pmu;
>
> +static int buf_nr_pages(struct page *page)
> +{
> + if (!PagePrivate(page))
> + return 1;
> +
> + return 1 << page_private(page);
> +}
> +
> static size_t buf_size(struct page *page)
> {
> - return 1 << (PAGE_SHIFT + page_private(page));
> + return 1 << (PAGE_SHIFT + buf_nr_pages(page));
Hurmph, shouldn't that be:
return buf_nr_pages(page) * PAGE_SIZE;
?
Peter Zijlstra <[email protected]> writes:
>> static size_t buf_size(struct page *page)
>> {
>> - return 1 << (PAGE_SHIFT + page_private(page));
>> + return 1 << (PAGE_SHIFT + buf_nr_pages(page));
>
> Hurmph, shouldn't that be:
>
> return buf_nr_pages(page) * PAGE_SIZE;
>
> ?
True, that one's broken.
Peter Zijlstra <[email protected]> writes:
> On Thu, Dec 05, 2019 at 05:28:51PM +0300, Alexander Shishkin wrote:
>> Hi Peter and Ingo,
>>
>> Here are two small fixes that resulted from running perf_fuzzer on a !KPTI
>> kernel. One is a misguided and unannotated warning and another is a sketchy
>> use of page_private(). The choice between deleting the BTS driver and
>> fixing it is not obvious, though. It may theoretically still have users.
>>
>> Alexander Shishkin (2):
>> perf/x86/intel/bts: Remove a silly warning
>> perf/x86/intel/bts: Fix the use of page_private()
>
> I'll squash the pair, that makes more sense to me.
Thanks!