linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* -mprofile-kernel vs. notrace in ppc64(le) Linux kernels
@ 2015-09-26 14:30 Torsten Duwe
  2015-09-26 14:52 ` Segher Boessenkool
  2015-09-28  0:08 ` Stewart Smith
  0 siblings, 2 replies; 5+ messages in thread
From: Torsten Duwe @ 2015-09-26 14:30 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: live-patching

As I mentioned earlier this year, it's a bad idea to call _mcount from
MMU helper functions (e.g. hash_page...), when the profiling/tracing/
live-patching/whatever framewok might in turn cause another such fault.
Jikos suggested to use fine-grained control of these functions with the
"notrace" keyword in the Linux kernel. It is mapped to GCC's (4.8, FWIW)
__attribute__((no_instrument_function)), which, to my surprise, works
for -p and -pg nicely, but does not affect -mprofile-kernel at all!

Should we consider this a bug? IMHO it is. I can see in the GCC sources
that -mprofile-kernel is more like a low-level hack in rs6000.c,
quite far below the RTL code generator, so the no_instrument_function
attribute is probably hard to check for.

What is -mprofile-kernel good for, if it bears such a risk of crashing
the kernel? Is it the right hook for ppc64 live patching? How to protect
those critical functions? Filter -mprofile-kernel for those object files?
Ask the GCC experts to fix this?

Any ideas welcome!

	Torsten

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

* Re: -mprofile-kernel vs. notrace in ppc64(le) Linux kernels
  2015-09-26 14:30 -mprofile-kernel vs. notrace in ppc64(le) Linux kernels Torsten Duwe
@ 2015-09-26 14:52 ` Segher Boessenkool
  2015-09-26 23:03   ` Anton Blanchard
  2015-09-28  0:08 ` Stewart Smith
  1 sibling, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2015-09-26 14:52 UTC (permalink / raw)
  To: Torsten Duwe; +Cc: linuxppc-dev, live-patching

On Sat, Sep 26, 2015 at 04:30:08PM +0200, Torsten Duwe wrote:
> As I mentioned earlier this year, it's a bad idea to call _mcount from
> MMU helper functions (e.g. hash_page...), when the profiling/tracing/
> live-patching/whatever framewok might in turn cause another such fault.
> Jikos suggested to use fine-grained control of these functions with the
> "notrace" keyword in the Linux kernel. It is mapped to GCC's (4.8, FWIW)
> __attribute__((no_instrument_function)), which, to my surprise, works
> for -p and -pg nicely, but does not affect -mprofile-kernel at all!

That is surprising; please file a GCC bug.

> Should we consider this a bug? IMHO it is. I can see in the GCC sources
> that -mprofile-kernel is more like a low-level hack in rs6000.c,
> quite far below the RTL code generator, so the no_instrument_function
> attribute is probably hard to check for.
> 
> What is -mprofile-kernel good for, if it bears such a risk of crashing
> the kernel?

It didn't work when combined with other fringe functionality.  It happens.

> Is it the right hook for ppc64 live patching? How to protect
> those critical functions? Filter -mprofile-kernel for those object files?

That might work.

> Ask the GCC experts to fix this?

Yes please.  You probably need a workaround for released compilers though.


Segher

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

* Re: -mprofile-kernel vs. notrace in ppc64(le) Linux kernels
  2015-09-26 14:52 ` Segher Boessenkool
@ 2015-09-26 23:03   ` Anton Blanchard
  2015-09-27 11:06     ` Torsten Duwe
  0 siblings, 1 reply; 5+ messages in thread
From: Anton Blanchard @ 2015-09-26 23:03 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Torsten Duwe, live-patching, linuxppc-dev

Hi,

> On Sat, Sep 26, 2015 at 04:30:08PM +0200, Torsten Duwe wrote:
> > As I mentioned earlier this year, it's a bad idea to call _mcount
> > from MMU helper functions (e.g. hash_page...), when the
> > profiling/tracing/ live-patching/whatever framewok might in turn
> > cause another such fault. Jikos suggested to use fine-grained
> > control of these functions with the "notrace" keyword in the Linux
> > kernel. It is mapped to GCC's (4.8, FWIW)
> > __attribute__((no_instrument_function)), which, to my surprise,
> > works for -p and -pg nicely, but does not affect -mprofile-kernel
> > at all!
> 
> That is surprising; please file a GCC bug.

This sounds like the issue below, fixed by Pat.

Anton
--

commit ccebc2aad32917f3371ae6d5774f689c86ace0b2
Author: pthaugen <pthaugen@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Jan 15 23:48:12 2014 +0000

    	* config/rs6000/rs6000.c (rs6000_output_function_prologue): Check if
    	current procedure should be profiled.
    
    
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@206650 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2781bd0..0788036 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2014-01-15  Pat Haugen  <pthaugen@us.ibm.com>
+
+	* config/rs6000/rs6000.c (rs6000_output_function_prologue): Check if
+	current procedure should be profiled.
+
 2014-01-15  Andrew Pinski  <apinski@cavium.com>
 
 	* config/aarch64/aarch64.c (aarch64_register_move_cost): Correct cost
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 289b52c..a479219 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -23198,7 +23198,7 @@ rs6000_output_function_prologue (FILE *file,
   /* Output -mprofile-kernel code.  This needs to be done here instead of
      in output_function_profile since it must go after the ELFv2 ABI
      local entry point.  */
-  if (TARGET_PROFILE_KERNEL)
+  if (TARGET_PROFILE_KERNEL && crtl->profile)
     {
       gcc_assert (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2);
       gcc_assert (!TARGET_32BIT);

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

* Re: -mprofile-kernel vs. notrace in ppc64(le) Linux kernels
  2015-09-26 23:03   ` Anton Blanchard
@ 2015-09-27 11:06     ` Torsten Duwe
  0 siblings, 0 replies; 5+ messages in thread
From: Torsten Duwe @ 2015-09-27 11:06 UTC (permalink / raw)
  To: Anton Blanchard; +Cc: Segher Boessenkool, live-patching, linuxppc-dev

On Sun, Sep 27, 2015 at 09:03:48AM +1000, Anton Blanchard wrote:
> > On Sat, Sep 26, 2015 at 04:30:08PM +0200, Torsten Duwe wrote:
> > > kernel. It is mapped to GCC's (4.8, FWIW)
> > > __attribute__((no_instrument_function)), which, to my surprise,
> > > works for -p and -pg nicely, but does not affect -mprofile-kernel
> > > at all!
> 
> This sounds like the issue below, fixed by Pat.
> 
> diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
> index 289b52c..a479219 100644
> --- a/gcc/config/rs6000/rs6000.c
> +++ b/gcc/config/rs6000/rs6000.c
> @@ -23198,7 +23198,7 @@ rs6000_output_function_prologue (FILE *file,
>    /* Output -mprofile-kernel code.  This needs to be done here instead of
>       in output_function_profile since it must go after the ELFv2 ABI
>       local entry point.  */
> -  if (TARGET_PROFILE_KERNEL)
> +  if (TARGET_PROFILE_KERNEL && crtl->profile)
>      {
>        gcc_assert (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2);
>        gcc_assert (!TARGET_32BIT);

Yes, indeed!
I can see the fix in the 4.9 branch, it's in 5.x and 6.x, but _not_ in 4.8.5 :(
That's what you get when you use "stable" distributions.

Thanks a lot for the pointer!

	Torsten

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

* Re: -mprofile-kernel vs. notrace in ppc64(le) Linux kernels
  2015-09-26 14:30 -mprofile-kernel vs. notrace in ppc64(le) Linux kernels Torsten Duwe
  2015-09-26 14:52 ` Segher Boessenkool
@ 2015-09-28  0:08 ` Stewart Smith
  1 sibling, 0 replies; 5+ messages in thread
From: Stewart Smith @ 2015-09-28  0:08 UTC (permalink / raw)
  To: Torsten Duwe, linuxppc-dev; +Cc: live-patching

Torsten Duwe <duwe@lst.de> writes:
> As I mentioned earlier this year, it's a bad idea to call _mcount from
> MMU helper functions (e.g. hash_page...), when the profiling/tracing/
> live-patching/whatever framewok might in turn cause another such fault.
> Jikos suggested to use fine-grained control of these functions with the
> "notrace" keyword in the Linux kernel. It is mapped to GCC's (4.8, FWIW)
> __attribute__((no_instrument_function)), which, to my surprise, works
> for -p and -pg nicely, but does not affect -mprofile-kernel at all!

IIRC from when I was working on GCOV support in OPAL firmware (skiboot),
this doesn't affect the code generated by -fprofile-arcs, so may not
completely do what you want.

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

end of thread, other threads:[~2015-09-28  0:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-26 14:30 -mprofile-kernel vs. notrace in ppc64(le) Linux kernels Torsten Duwe
2015-09-26 14:52 ` Segher Boessenkool
2015-09-26 23:03   ` Anton Blanchard
2015-09-27 11:06     ` Torsten Duwe
2015-09-28  0:08 ` Stewart Smith

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).