From: Andrew Kilroy <andrew.kilroy@arm.com>
To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
acme@kernel.org
Cc: Andrew Kilroy <andrew.kilroy@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>, Tom Rix <trix@redhat.com>,
linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
bpf@vger.kernel.org, llvm@lists.linux.dev
Subject: [PATCH 4/8] perf tools: arm64: Read ptrauth data from kernel
Date: Mon, 4 Jul 2022 15:53:28 +0100 [thread overview]
Message-ID: <20220704145333.22557-5-andrew.kilroy@arm.com> (raw)
In-Reply-To: <20220704145333.22557-1-andrew.kilroy@arm.com>
This patch alters the userspace perf program to request the
pointer authentication code masks using the PERF_SAMPLE_ARCH_1 sample
field and write the data to perf.data file.
A subsequent commit will make use of the masks in the data file to do
the unwinding.
Signed-off-by: Andrew Kilroy <andrew.kilroy@arm.com>
---
tools/perf/tests/sample-parsing.c | 2 +-
tools/perf/util/event.h | 8 ++++++
tools/perf/util/evsel.c | 45 +++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c
index 07f2411b0ad4..dd78ca279c01 100644
--- a/tools/perf/tests/sample-parsing.c
+++ b/tools/perf/tests/sample-parsing.c
@@ -381,7 +381,7 @@ static int test__sample_parsing(struct test_suite *test __maybe_unused, int subt
* were added. Please actually update the test rather than just change
* the condition below.
*/
- if (PERF_SAMPLE_MAX > PERF_SAMPLE_WEIGHT_STRUCT << 1) {
+ if (PERF_SAMPLE_MAX > PERF_SAMPLE_ARCH_1 << 1) {
pr_debug("sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating\n");
return -1;
}
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index cdd72e05fd28..b99fc81dd37e 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -128,6 +128,13 @@ struct aux_sample {
void *data;
};
+
+struct ptrauth_info {
+ u64 enabled_keys; // arm64 ptrauth is in use if this is non-zero.
+ u64 insn_mask;
+ u64 data_mask;
+};
+
struct perf_sample {
u64 ip;
u32 pid, tid;
@@ -163,6 +170,7 @@ struct perf_sample {
struct stack_dump user_stack;
struct sample_read read;
struct aux_sample aux_sample;
+ struct ptrauth_info ptrauth;
};
#define PERF_MEM_DATA_SRC_NONE \
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 25d8f804f49a..4627a68a7797 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -887,8 +887,22 @@ static void __evsel__config_callchain(struct evsel *evsel, struct record_opts *o
"Falling back to framepointers.\n");
}
+#if defined(__aarch64__)
+ /*
+ * We need to set ARM64_PTRAUTH in FP mode so that b9f6fbb3b2c2 ("perf arm64: Inject missing
+ * frames when using 'perf record --call-graph=fp'") continues to work in the presence of
+ * PACs.
+ */
+ if (param->record_mode == CALLCHAIN_FP)
+ evsel__set_sample_bit(evsel, ARM64_PTRAUTH);
+
+#endif
+
if (param->record_mode == CALLCHAIN_DWARF) {
if (!function) {
+#if defined(__aarch64__)
+ evsel__set_sample_bit(evsel, ARM64_PTRAUTH);
+#endif
evsel__set_sample_bit(evsel, REGS_USER);
evsel__set_sample_bit(evsel, STACK_USER);
if (opts->sample_user_regs && DWARF_MINIMAL_REGS != PERF_REGS_MASK) {
@@ -2344,6 +2358,17 @@ u64 evsel__bitfield_swap_branch_flags(u64 value)
return new_val;
}
+/*
+ * To return the normalised arch that is recorded in a perf.data file
+ */
+static const char *recorded_normalized_arch(struct evsel *evsel)
+{
+ if (evsel && evsel->evlist && evsel->evlist->env)
+ return perf_env__arch(evsel->evlist->env);
+ else
+ return NULL;
+}
+
int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
struct perf_sample *data)
{
@@ -2681,6 +2706,26 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
array = (void *)array + sz;
}
+ if (type & PERF_SAMPLE_ARCH_1) {
+ const char *normlzd_arch = recorded_normalized_arch(evsel);
+
+ if (normlzd_arch)
+ pr_debug4("PERF_SAMPLE_ARCH_1 is on, detected recorded arch as %s\n", normlzd_arch);
+ else
+ pr_debug4("PERF_SAMPLE_ARCH_1 is on, but arch not detected\n");
+
+ if (normlzd_arch && strcmp(normlzd_arch, "arm64") == 0) {
+ OVERFLOW_CHECK(array, 3 * sizeof(u64), max_size);
+
+ data->ptrauth.enabled_keys = *array;
+ array++;
+ data->ptrauth.insn_mask = *array;
+ array++;
+ data->ptrauth.data_mask = *array;
+ array++;
+ }
+ }
+
return 0;
}
--
2.17.1
next prev parent reply other threads:[~2022-07-04 14:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-04 14:53 [PATCH 0/8] Perf stack unwinding with pointer authentication Andrew Kilroy
2022-07-04 14:53 ` [PATCH 1/8] perf arm64: Send pointer auth masks to ring buffer Andrew Kilroy
2022-08-10 13:23 ` Arnaldo Carvalho de Melo
2022-09-07 15:21 ` James Clark
2022-07-04 14:53 ` [PATCH 2/8] perf evsel: Do not request ptrauth sample field if not supported Andrew Kilroy
2022-07-06 16:01 ` Vince Weaver
2022-07-11 9:25 ` James Clark
2022-07-12 21:30 ` Vince Weaver
2022-07-04 14:53 ` [PATCH 3/8] perf test: Update arm64 tests to expect ptrauth masks Andrew Kilroy
2022-07-04 14:53 ` Andrew Kilroy [this message]
2022-07-04 14:53 ` [PATCH 5/8] perf libunwind: Feature check for libunwind ptrauth callback Andrew Kilroy
2022-07-04 14:53 ` [PATCH 6/8] perf libunwind: arm64 pointer authentication Andrew Kilroy
2022-07-04 14:53 ` [PATCH 7/8] perf tools: Print ptrauth struct in perf report Andrew Kilroy
2022-07-04 14:53 ` [PATCH 8/8] perf test arm64: Test unwinding with PACs on gcc & clang compilers Andrew Kilroy
2022-09-07 15:00 ` [PATCH 0/8] Perf stack unwinding with pointer authentication James Clark
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=20220704145333.22557-5-andrew.kilroy@arm.com \
--to=andrew.kilroy@arm.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=bpf@vger.kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=namhyung@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=trix@redhat.com \
--cc=yhs@fb.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;
as well as URLs for NNTP newsgroup(s).