public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf test: Fix signal test inline assembly
@ 2020-09-11 13:00 Jiri Olsa
  2020-09-14 21:28 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Jiri Olsa @ 2020-09-11 13:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Wang Nan, lkml, Peter Zijlstra, Ingo Molnar, Namhyung Kim,
	Alexander Shishkin, Michael Petlan

When compiling with DEBUG=1 on Fedora 32 I'm getting crash for
'perf test signal':

  Program received signal SIGSEGV, Segmentation fault.
  0x0000000000c68548 in __test_function ()
  (gdb) bt
  #0  0x0000000000c68548 in __test_function ()
  #1  0x00000000004d62e9 in test_function () at tests/bp_signal.c:61
  #2  0x00000000004d689a in test__bp_signal (test=0xa8e280 <generic_ ...
  #3  0x00000000004b7d49 in run_test (test=0xa8e280 <generic_tests+1 ...
  #4  0x00000000004b7e7f in test_and_print (t=0xa8e280 <generic_test ...
  #5  0x00000000004b8927 in __cmd_test (argc=1, argv=0x7fffffffdce0, ...
  ...

It's caused by __test_function being in .bss section:

  $ readelf -a ./perf | less
    [Nr] Name              Type             Address           Offset
         Size              EntSize          Flags  Link  Info  Align
    ...
    [28] .bss              NOBITS           0000000000c356a0  008346a0
         00000000000511f8  0000000000000000  WA       0     0     32

  $ nm perf | grep __test_function
  0000000000c68548 B __test_function

I guess most of the time we're just lucky the inline asm ended up
in .text section, so making it specific explicit with push and pop
section cluases.

  $ readelf -a ./perf | less
    [Nr] Name              Type             Address           Offset
         Size              EntSize          Flags  Link  Info  Align
    ...
    [13] .text             PROGBITS         0000000000431240  00031240
         0000000000306faa  0000000000000000  AX       0     0     16

  $ nm perf | grep __test_function
  00000000004d62c8 T __test_function

Cc: Wang Nan <wangnan0@huawei.com>
Fixes: 8fd34e1cce18 ("perf test: Improve bp_signal")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/tests/bp_signal.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c
index da8ec1e8e064..cc9fbcedb364 100644
--- a/tools/perf/tests/bp_signal.c
+++ b/tools/perf/tests/bp_signal.c
@@ -45,10 +45,13 @@ volatile long the_var;
 #if defined (__x86_64__)
 extern void __test_function(volatile long *ptr);
 asm (
+	".pushsection .text;"
 	".globl __test_function\n"
+	".type __test_function, @function;"
 	"__test_function:\n"
 	"incq (%rdi)\n"
-	"ret\n");
+	"ret\n"
+	".popsection\n");
 #else
 static void __test_function(volatile long *ptr)
 {
-- 
2.26.2


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

* Re: [PATCH] perf test: Fix signal test inline assembly
  2020-09-11 13:00 [PATCH] perf test: Fix signal test inline assembly Jiri Olsa
@ 2020-09-14 21:28 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-09-14 21:28 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Wang Nan, lkml, Peter Zijlstra, Ingo Molnar, Namhyung Kim,
	Alexander Shishkin, Michael Petlan

Em Fri, Sep 11, 2020 at 03:00:05PM +0200, Jiri Olsa escreveu:
> When compiling with DEBUG=1 on Fedora 32 I'm getting crash for
> 'perf test signal':
> 
>   Program received signal SIGSEGV, Segmentation fault.
>   0x0000000000c68548 in __test_function ()
>   (gdb) bt
>   #0  0x0000000000c68548 in __test_function ()
>   #1  0x00000000004d62e9 in test_function () at tests/bp_signal.c:61
>   #2  0x00000000004d689a in test__bp_signal (test=0xa8e280 <generic_ ...
>   #3  0x00000000004b7d49 in run_test (test=0xa8e280 <generic_tests+1 ...
>   #4  0x00000000004b7e7f in test_and_print (t=0xa8e280 <generic_test ...
>   #5  0x00000000004b8927 in __cmd_test (argc=1, argv=0x7fffffffdce0, ...
>   ...
> 
> It's caused by __test_function being in .bss section:
> 
>   $ readelf -a ./perf | less
>     [Nr] Name              Type             Address           Offset
>          Size              EntSize          Flags  Link  Info  Align
>     ...
>     [28] .bss              NOBITS           0000000000c356a0  008346a0
>          00000000000511f8  0000000000000000  WA       0     0     32
> 
>   $ nm perf | grep __test_function
>   0000000000c68548 B __test_function
> 
> I guess most of the time we're just lucky the inline asm ended up
> in .text section, so making it specific explicit with push and pop
> section cluases.
> 
>   $ readelf -a ./perf | less
>     [Nr] Name              Type             Address           Offset
>          Size              EntSize          Flags  Link  Info  Align
>     ...
>     [13] .text             PROGBITS         0000000000431240  00031240
>          0000000000306faa  0000000000000000  AX       0     0     16
> 
>   $ nm perf | grep __test_function
>   00000000004d62c8 T __test_function

Thanks, tested and applied.

- Arnaldo
 
> Cc: Wang Nan <wangnan0@huawei.com>
> Fixes: 8fd34e1cce18 ("perf test: Improve bp_signal")
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/tests/bp_signal.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c
> index da8ec1e8e064..cc9fbcedb364 100644
> --- a/tools/perf/tests/bp_signal.c
> +++ b/tools/perf/tests/bp_signal.c
> @@ -45,10 +45,13 @@ volatile long the_var;
>  #if defined (__x86_64__)
>  extern void __test_function(volatile long *ptr);
>  asm (
> +	".pushsection .text;"
>  	".globl __test_function\n"
> +	".type __test_function, @function;"
>  	"__test_function:\n"
>  	"incq (%rdi)\n"
> -	"ret\n");
> +	"ret\n"
> +	".popsection\n");
>  #else
>  static void __test_function(volatile long *ptr)
>  {
> -- 
> 2.26.2
> 

-- 

- Arnaldo

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

end of thread, other threads:[~2020-09-14 21:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-11 13:00 [PATCH] perf test: Fix signal test inline assembly Jiri Olsa
2020-09-14 21:28 ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox