From: Leo Yan <leo.yan@arm.com>
To: Tomas Glozar <tglozar@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
linux-perf-users@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
Wander Costa <wcosta@redhat.com>
Subject: Re: [BUG] perf segfaults when combining --overwrite and intel_pt event
Date: Mon, 28 Apr 2025 11:12:34 +0100 [thread overview]
Message-ID: <20250428101234.GB551819@e132581.arm.com> (raw)
In-Reply-To: <CAP4=nvTab7BnT4uu0iCuFJpZ-_MdY-MYU+Q25QnpygEZKmsQ8A@mail.gmail.com>
Hi Tomas,
On Mon, Apr 28, 2025 at 11:07:21AM +0200, Tomas Glozar wrote:
> Dear maintainers,
>
> I would like to report a bug in perf I ran into when trying to combine
> --overwrite and intel_pt on latest perf from 6.15-rc4:
> $ perf record --overwrite -a -e intel_pt/cyc,noretcomp/k
> perf: Segmentation fault
[...]
> GDB gives the following backtrace:
>
> (gdb) bt
> #0 0x000000000061bb16 in auxtrace_mmap__mmap (mm=0x7c9fa0,
> mp=0x7fffffff9008, userpg=0x7ffff7cff000, fd=7) at util/auxtrace.c:136
[...]
I can reproduce the issue with Arm CoreSight as well. The cause is
the user page is mapped as read-only (see the mmap_per_evsel() function
in tools/lib/perf/evlist.c), afterwards AUX trace needs to update info
into it.
I would like to suggest a fix blow. For overwrite mode, we need a
fixup to remap the user page with write permission.
Could you confirm if works at you side?
Thanks,
Leo
---8<---
From f969b3a7c3b338f47f271a2ac012813aec76b5a3 Mon Sep 17 00:00:00 2001
From: Leo Yan <leo.yan@arm.com>
Date: Mon, 28 Apr 2025 10:59:28 +0100
Subject: [PATCH] libperf: Grant write permission for user page
When perf runs in overwrite mode, the ring buffer is mapped read-only.
On the other hand, the first page in the ring buffer is for user page,
which is used for exchanging parameters between the kernel and the
userspace. The read-only permission causes Segmentation fault with
command:
$ perf record --overwrite -a -e cs_etm//
perf: Segmentation fault
This patch grants write permission for the mapped user page so the
userspace tool can update info properly.
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/lib/perf/mmap.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c
index c1a51d925e0e..465e12ec5a60 100644
--- a/tools/lib/perf/mmap.c
+++ b/tools/lib/perf/mmap.c
@@ -4,6 +4,7 @@
#include <asm/bug.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
#include <linux/ring_buffer.h>
#include <linux/perf_event.h>
#include <perf/mmap.h>
@@ -36,6 +37,8 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map)
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
int fd, struct perf_cpu cpu)
{
+ const long page_sz = sysconf(_SC_PAGE_SIZE);
+
map->prev = 0;
map->mask = mp->mask;
map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
@@ -45,6 +48,19 @@ int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
return -1;
}
+ /*
+ * In overwrite mode, pages are mapped read-only. Fixup writable
+ * permission for the user page as the tool needs to update info
+ * into it.
+ */
+ if (mp->prot == PROT_READ) {
+ if (mprotect(map->base, page_sz, mp->prot | PROT_WRITE) < 0) {
+ munmap(map->base, perf_mmap__mmap_len(map));
+ map->base = NULL;
+ return -1;
+ }
+ }
+
map->fd = fd;
map->cpu = cpu;
return 0;
--
2.34.1
next prev parent reply other threads:[~2025-04-28 10:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 9:07 Tomas Glozar
2025-04-28 10:12 ` Leo Yan [this message]
2025-04-28 10:45 ` Tomas Glozar
2025-04-28 12:47 ` Leo Yan
2025-04-28 14:16 ` Tomas Glozar
2025-04-29 9:56 ` Leo Yan
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=20250428101234.GB551819@e132581.arm.com \
--to=leo.yan@arm.com \
--cc=acme@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tglozar@redhat.com \
--cc=wcosta@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
all inboxes | Powered by JetHome®