linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 5/8] perf libunwind: Feature check for libunwind ptrauth callback
Date: Mon,  4 Jul 2022 15:53:29 +0100	[thread overview]
Message-ID: <20220704145333.22557-6-andrew.kilroy@arm.com> (raw)
In-Reply-To: <20220704145333.22557-1-andrew.kilroy@arm.com>

This patch prepares for a version of libunwind that is capable of
unwinding stacks with pointer authentication.

Without this change, anyone compiling perf would have to depend on a
very new version of libunwind that has the callback to supply it with
pointer authentication masks.

This patch detects if libunwind is recent enough, and if so, sets a
pre-processor flag that will be used in a subsequent commit to call
libunwind appropriately.

If libunwind is not recent enough, the pre-processor flag is not set.

Signed-off-by: Andrew Kilroy <andrew.kilroy@arm.com>
---
 tools/build/Makefile.feature                  |  2 ++
 tools/build/feature/Makefile                  |  4 +++
 tools/build/feature/test-all.c                |  5 ++++
 .../feature/test-libunwind-arm64-ptrauth.c    | 26 +++++++++++++++++++
 tools/perf/Makefile.config                    | 10 +++++++
 5 files changed, 47 insertions(+)
 create mode 100644 tools/build/feature/test-libunwind-arm64-ptrauth.c

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 888a0421d43b..a894101342fc 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -90,6 +90,7 @@ FEATURE_TESTS_EXTRA :=                  \
          libunwind-x86_64               \
          libunwind-arm                  \
          libunwind-aarch64              \
+         libunwind-arm64-ptrauth        \
          libunwind-debug-frame          \
          libunwind-debug-frame-arm      \
          libunwind-debug-frame-aarch64  \
@@ -128,6 +129,7 @@ FEATURE_DISPLAY ?=              \
          libpython              \
          libcrypto              \
          libunwind              \
+         libunwind-arm64-ptrauth\
          libdw-dwarf-unwind     \
          zlib                   \
          lzma                   \
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 7c2a17e23c30..ac23175d5bcb 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -45,6 +45,7 @@ FILES=                                          \
          test-libunwind-aarch64.bin             \
          test-libunwind-debug-frame-arm.bin     \
          test-libunwind-debug-frame-aarch64.bin \
+         test-libunwind-arm64-ptrauth.bin \
          test-pthread-attr-setaffinity-np.bin   \
          test-pthread-barrier.bin		\
          test-stackprotector-all.bin            \
@@ -193,6 +194,9 @@ $(OUTPUT)test-libunwind-debug-frame-arm.bin:
 $(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
 	$(BUILD) -lelf -lunwind-aarch64
 
+$(OUTPUT)test-libunwind-arm64-ptrauth.bin:
+	$(BUILD) # -lunwind provided by $(FEATURE_CHECK_LDFLAGS-libunwind-arm64-ptrauth)
+
 $(OUTPUT)test-libaudit.bin:
 	$(BUILD) -laudit
 
diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c
index 5ffafb967b6e..86780c5c78e5 100644
--- a/tools/build/feature/test-all.c
+++ b/tools/build/feature/test-all.c
@@ -66,6 +66,10 @@
 # include "test-libunwind.c"
 #undef main
 
+#define main main_test_libunwind_arm64_ptrauth
+# include "test-libunwind-arm64-ptrauth.c"
+#undef main
+
 #define main main_test_libslang
 # include "test-libslang.c"
 #undef main
@@ -186,6 +190,7 @@ int main(int argc, char *argv[])
 	main_test_libelf_gelf_getnote();
 	main_test_libelf_getshdrstrndx();
 	main_test_libunwind();
+	main_test_libunwind_arm64_ptrauth();
 	main_test_libslang();
 	main_test_libbfd();
 	main_test_libbfd_buildid();
diff --git a/tools/build/feature/test-libunwind-arm64-ptrauth.c b/tools/build/feature/test-libunwind-arm64-ptrauth.c
new file mode 100644
index 000000000000..51650ceef90e
--- /dev/null
+++ b/tools/build/feature/test-libunwind-arm64-ptrauth.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <libunwind.h>
+
+static unw_word_t get_insn_mask(unw_addr_space_t addr_space, void *unwind_info_ptr)
+{
+	return 0;
+}
+
+// This feature test is intending to check if the version
+// of the available libunwind library is one that has the
+// ptrauth_insn_mask callback function.
+// If it doesn't this feature check should fail to compile.
+static unw_accessors_t accessors = {
+	.ptrauth_insn_mask = get_insn_mask,
+};
+
+int main(void)
+{
+	unw_addr_space_t addr_space = unw_create_addr_space(&accessors, 0);
+
+	if (addr_space)
+		return 0;
+
+	return 0;
+}
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 73e0762092fe..2578b1d1a502 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -133,6 +133,8 @@ FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
+FEATURE_CHECK_CFLAGS-libunwind-arm64-ptrauth = $(LIBUNWIND_CFLAGS)
+FEATURE_CHECK_LDFLAGS-libunwind-arm64-ptrauth = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
 
 FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm
 FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64
@@ -677,6 +679,14 @@ ifndef NO_LIBUNWIND
     $(call detected,CONFIG_LOCAL_LIBUNWIND)
   endif
 
+  ifeq ($(have_libunwind), 1)
+    $(call feature_check,libunwind-arm64-ptrauth)
+    ifneq ($(feature-libunwind-arm64-ptrauth),1)
+      CFLAGS += -DNO_LIBUNWIND_ARM64_PTRAUTH
+      msg := $(warning libunwind cannot produce user stacks in the presence of pointer authentication.);
+    endif
+  endif
+
   ifneq ($(have_libunwind), 1)
     NO_LIBUNWIND := 1
   endif
-- 
2.17.1


  parent reply	other threads:[~2022-07-04 14:56 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 ` [PATCH 4/8] perf tools: arm64: Read ptrauth data from kernel Andrew Kilroy
2022-07-04 14:53 ` Andrew Kilroy [this message]
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-6-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).