public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [PATCH 2/2] perf/x86/intel/bts: Fix the use of page_private()
Date: Thu,  5 Dec 2019 17:28:53 +0300	[thread overview]
Message-ID: <20191205142853.28894-3-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <20191205142853.28894-1-alexander.shishkin@linux.intel.com>

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 <alexander.shishkin@linux.intel.com>
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


  parent reply	other threads:[~2019-12-05 14:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05 14:28 [PATCH 0/2] perf/x86/intel/bts: Small fixes Alexander Shishkin
2019-12-05 14:28 ` [PATCH 1/2] perf/x86/intel/bts: Remove a silly warning Alexander Shishkin
2019-12-10 15:29   ` Peter Zijlstra
2019-12-17 12:39   ` [tip: perf/urgent] perf/x86/intel/bts: Fix the use of page_private() tip-bot2 for Alexander Shishkin
2019-12-05 14:28 ` Alexander Shishkin [this message]
2019-12-10 15:35   ` [PATCH 2/2] " Peter Zijlstra
2019-12-11  0:23   ` Peter Zijlstra
2019-12-11  6:26     ` Alexander Shishkin
2019-12-10 17:40 ` [PATCH 0/2] perf/x86/intel/bts: Small fixes Peter Zijlstra
2019-12-11 11:33   ` Alexander Shishkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191205142853.28894-3-alexander.shishkin@linux.intel.com \
    --to=alexander.shishkin@linux.intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox