public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Wang Nan <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, lizefan@huawei.com,
	jolsa@kernel.org, acme@redhat.com, mhiramat@kernel.org,
	tglx@linutronix.de, namhyung@kernel.org, wangnan0@huawei.com,
	mingo@kernel.org, hpa@zytor.com, hekuang@huawei.com
Subject: [tip:perf/core] perf evlist: Check 'base' pointer before checking refcnt when put a mmap
Date: Wed, 1 Jun 2016 23:32:53 -0700	[thread overview]
Message-ID: <tip-e10e4ef63b54912feffb1dc48ff7d03d931b1647@git.kernel.org> (raw)
In-Reply-To: <1464183898-174512-2-git-send-email-wangnan0@huawei.com>

Commit-ID:  e10e4ef63b54912feffb1dc48ff7d03d931b1647
Gitweb:     http://git.kernel.org/tip/e10e4ef63b54912feffb1dc48ff7d03d931b1647
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 25 May 2016 13:44:49 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 30 May 2016 12:41:45 -0300

perf evlist: Check 'base' pointer before checking refcnt when put a mmap

evlist->mmap[i]->refcnt could be 0 if an evlist has no evsel or if all
evsels don't match the evlist during mmap. For example, when all evsels
are overwritable but the evlist itself is normal. To avoid crashing,
perf should check 'base' pointer before checking refcnt, and raise bug
only when base is not NULL.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1464183898-174512-2-git-send-email-wangnan0@huawei.com
[ Renamed 'mmap' variable, it is reserved in old distros such as Ubuntu 12.04, breaking the build ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evlist.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 50d7b80..58ede32 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -856,9 +856,11 @@ static void perf_evlist__mmap_get(struct perf_evlist *evlist, int idx)
 
 static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx)
 {
-	BUG_ON(atomic_read(&evlist->mmap[idx].refcnt) == 0);
+	struct perf_mmap *md = &evlist->mmap[idx];
+
+	BUG_ON(md->base && atomic_read(&md->refcnt) == 0);
 
-	if (atomic_dec_and_test(&evlist->mmap[idx].refcnt))
+	if (atomic_dec_and_test(&md->refcnt))
 		__perf_evlist__munmap(evlist, idx);
 }
 

  reply	other threads:[~2016-06-02  6:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-25 13:44 [PATCH v6 00/10] perf tools: Support overwritable ring buffer Wang Nan
2016-05-25 13:44 ` [PATCH v6 01/10] perf tools: Check 'base' pointer before checking refcnt when put a mmap Wang Nan
2016-06-02  6:32   ` tip-bot for Wang Nan [this message]
2016-05-25 13:44 ` [PATCH v6 02/10] perf tools: Choose correct reading direction according to evlist->backward Wang Nan
2016-06-02  6:33   ` [tip:perf/core] perf evlist: " tip-bot for Wang Nan
2016-05-25 13:44 ` [PATCH v6 03/10] perf tests: Add testcase for auxiliary evlist Wang Nan
2016-05-25 13:44 ` [PATCH v6 04/10] perf record: Introduce rec->overwrite_evlist for overwritable events Wang Nan
2016-05-25 13:44 ` [PATCH v6 05/10] perf record: Toggle overwrite ring buffer for reading Wang Nan
2016-05-25 13:44 ` [PATCH v6 06/10] perf tools: Enable overwrite settings Wang Nan
2016-05-25 13:44 ` [PATCH v6 07/10] perf tools: Don't warn about out of order event if write_backward is used Wang Nan
2016-05-25 13:44 ` [PATCH v6 08/10] perf tools: Check write_backward during evlist config Wang Nan
2016-05-25 13:44 ` [PATCH v6 09/10] tools: Pass arg to fdarray__filter's call back function Wang Nan
2016-06-02  6:33   ` [tip:perf/core] " tip-bot for Wang Nan
2016-05-25 13:44 ` [PATCH v6 10/10] perf record: Unmap overwrite evlist when event terminate Wang Nan

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=tip-e10e4ef63b54912feffb1dc48ff7d03d931b1647@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=hekuang@huawei.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wangnan0@huawei.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