All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix perf-hooks test for sanitizers
@ 2019-07-08 21:59 Numfor Mbiziwo-Tiapo
  2019-07-09  0:49 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Numfor Mbiziwo-Tiapo @ 2019-07-08 21:59 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, namhyung,
	songliubraving, mbd
  Cc: linux-kernel, irogers, eranian, Numfor Mbiziwo-Tiapo

The perf-hooks test fails with Address Sanitizer and Memory
Sanitizer builds because it purposefully generates a segfault.
Checking if these sanitizers are active when running this test
will allow the perf-hooks test to pass.

This can be replicated by running (from the tip directory):

make -C tools/perf USE_CLANG=1 EXTRA_CFLAGS="-fsanitize=address \
-DADDRESS_SANITIZER=1"

then running tools/perf/perf test 55

Fix past to pass:
The raised signal was changed from SIGSEGV to SIGILL to get the test 
to pass on our local machines which use clang 4.

Signed-off-by: Numfor Mbiziwo-Tiapo <nums@google.com>
---
 tools/perf/tests/perf-hooks.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/perf/tests/perf-hooks.c b/tools/perf/tests/perf-hooks.c
index a693bcf017ea..3f5f4b28cf01 100644
--- a/tools/perf/tests/perf-hooks.c
+++ b/tools/perf/tests/perf-hooks.c
@@ -7,7 +7,14 @@
 #include "util.h"
 #include "perf-hooks.h"
 
-static void sigsegv_handler(int sig __maybe_unused)
+#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
+defined(THREAD_SANITIZER) || defined(SAFESTACK_SANITIZER)
+#define USE_SIGNAL 1
+#else
+#define USE_SIGNAL 0
+#endif
+
+static void signal_handler(int sig __maybe_unused)
 {
 	pr_debug("SIGSEGV is observed as expected, try to recover.\n");
 	perf_hooks__recover();
@@ -25,6 +32,9 @@ static void the_hook(void *_hook_flags)
 	*hook_flags = 1234;
 
 	/* Generate a segfault, test perf_hooks__recover */
+#if USE_SIGNAL
+	raise(SIGILL);
+#endif
 	*p = 0;
 }
 
@@ -32,7 +42,7 @@ int test__perf_hooks(struct test *test __maybe_unused, int subtest __maybe_unuse
 {
 	int hook_flags = 0;
 
-	signal(SIGSEGV, sigsegv_handler);
+	signal(USE_SIGNAL ? SIGILL : SIGSEGV, signal_handler);
 	perf_hooks__set_hook("test", the_hook, &hook_flags);
 	perf_hooks__invoke_test();
 
-- 
2.22.0.410.gd8fdbe21b5-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix perf-hooks test for sanitizers
  2019-07-08 21:59 [PATCH] Fix perf-hooks test for sanitizers Numfor Mbiziwo-Tiapo
@ 2019-07-09  0:49 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-07-09  0:49 UTC (permalink / raw)
  To: Numfor Mbiziwo-Tiapo
  Cc: peterz, mingo, alexander.shishkin, jolsa, namhyung,
	songliubraving, mbd, linux-kernel, irogers, eranian

Em Mon, Jul 08, 2019 at 02:59:28PM -0700, Numfor Mbiziwo-Tiapo escreveu:
> The perf-hooks test fails with Address Sanitizer and Memory
> Sanitizer builds because it purposefully generates a segfault.
> Checking if these sanitizers are active when running this test
> will allow the perf-hooks test to pass.
> 
> This can be replicated by running (from the tip directory):
> 
> make -C tools/perf USE_CLANG=1 EXTRA_CFLAGS="-fsanitize=address \
> -DADDRESS_SANITIZER=1"
> 
> then running tools/perf/perf test 55
> 
> Fix past to pass:
> The raised signal was changed from SIGSEGV to SIGILL to get the test 
> to pass on our local machines which use clang 4.

We still need a little bit more info, because I couldn't find libasan in
the clang that ships with fedora:30 and not on the selection used to
build from the clang repo in my machine:

[acme@quaco perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@quaco perf]$ make -C tools/perf CC=clang EXTRA_CFLAGS="-fsanitize=address -DADDRESS_SANITIZER=1" O=/tmp/build/perf
make: Entering directory '/home/acme/git/perf/tools/perf'
  BUILD:   Doing 'make -j8' parallel build
  HOSTCC   /tmp/build/perf/fixdep.o
  HOSTLD   /tmp/build/perf/fixdep-in.o
  LINK     /tmp/build/perf/fixdep

Auto-detecting system features:
...                         dwarf: [ OFF ]
...            dwarf_getlocations: [ OFF ]
...                         glibc: [ OFF ]
...                          gtk2: [ OFF ]
...                      libaudit: [ OFF ]
...                        libbfd: [ OFF ]
...                        libelf: [ OFF ]
...                       libnuma: [ OFF ]
...        numa_num_possible_cpus: [ OFF ]
...                       libperl: [ OFF ]
...                     libpython: [ OFF ]
...                     libcrypto: [ OFF ]
...                     libunwind: [ OFF ]
...            libdw-dwarf-unwind: [ OFF ]
...                          zlib: [ OFF ]
...                          lzma: [ OFF ]
...                     get_cpuid: [ OFF ]
...                           bpf: [ OFF ]
...                        libaio: [ OFF ]
...                       libzstd: [ OFF ]
...        disassembler-four-args: [ OFF ]

Makefile.config:368: *** No gnu/libc-version.h found, please install glibc-dev[el].  Stop.
make[1]: *** [Makefile.perf:219: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/home/acme/git/perf/tools/perf'
[acme@quaco perf]$ cat /tmp/build/perf/feature/test-glibc.make.output
/usr/bin/ld: cannot find /opt/llvm/lib/clang/9.0.0/lib/linux/libclang_rt.asan-x86_64.a: No such file or directory
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
[acme@quaco perf]$

So I'll check and select that to get to the set of instructions needed
to use this.

- Arnaldo
 
> Signed-off-by: Numfor Mbiziwo-Tiapo <nums@google.com>
> ---
>  tools/perf/tests/perf-hooks.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/tests/perf-hooks.c b/tools/perf/tests/perf-hooks.c
> index a693bcf017ea..3f5f4b28cf01 100644
> --- a/tools/perf/tests/perf-hooks.c
> +++ b/tools/perf/tests/perf-hooks.c
> @@ -7,7 +7,14 @@
>  #include "util.h"
>  #include "perf-hooks.h"
>  
> -static void sigsegv_handler(int sig __maybe_unused)
> +#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
> +defined(THREAD_SANITIZER) || defined(SAFESTACK_SANITIZER)
> +#define USE_SIGNAL 1
> +#else
> +#define USE_SIGNAL 0
> +#endif
> +
> +static void signal_handler(int sig __maybe_unused)
>  {
>  	pr_debug("SIGSEGV is observed as expected, try to recover.\n");
>  	perf_hooks__recover();
> @@ -25,6 +32,9 @@ static void the_hook(void *_hook_flags)
>  	*hook_flags = 1234;
>  
>  	/* Generate a segfault, test perf_hooks__recover */
> +#if USE_SIGNAL
> +	raise(SIGILL);
> +#endif
>  	*p = 0;
>  }
>  
> @@ -32,7 +42,7 @@ int test__perf_hooks(struct test *test __maybe_unused, int subtest __maybe_unuse
>  {
>  	int hook_flags = 0;
>  
> -	signal(SIGSEGV, sigsegv_handler);
> +	signal(USE_SIGNAL ? SIGILL : SIGSEGV, signal_handler);
>  	perf_hooks__set_hook("test", the_hook, &hook_flags);
>  	perf_hooks__invoke_test();
>  
> -- 
> 2.22.0.410.gd8fdbe21b5-goog

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-09  0:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08 21:59 [PATCH] Fix perf-hooks test for sanitizers Numfor Mbiziwo-Tiapo
2019-07-09  0:49 ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.