2022-10-27 09:04:24

by Song Shuai

[permalink] [raw]
Subject: [PATCH] ftrace: fix static function tracer not working

Setting kernel command line parameter ftrace=function shows
nothing on the kernel built with static ftrace.

In static ftrace, ftrace_nodyn_init should be executed before
initializing tracers. While this commit `dbeafd0d6131` brings
the initialization of function tracer forward from core_initcall
where ftrace_nodyn_init still remains.

This patch puts ftrace_nodyn_init and ftrace_init together and
makes function tracer works in static ftrace.

Fixes: dbeafd0d6131 ("ftrace: Have function tracing start in early boot up")
Signed-off-by: Song Shuai <[email protected]>
---
include/linux/ftrace.h | 6 ++++++
init/main.c | 1 +
kernel/trace/ftrace.c | 4 +---
3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 0b61371e287b..4bdab0461b10 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -978,6 +978,12 @@ extern void ftrace_init(void);
static inline void ftrace_init(void) { }
#endif

+
+#ifndef CONFIG_FTRACE_MCOUNT_RECORD
+extern void ftrace_nodyn_init(void);
+#else
+static inline void ftrace_nodyn_init(void) { }
+#endif
/*
* Structure that defines an entry function trace.
* It's already packed but the attribute "packed" is needed
diff --git a/init/main.c b/init/main.c
index 91642a4e69be..ebf8136e828a 100644
--- a/init/main.c
+++ b/init/main.c
@@ -986,6 +986,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
trap_init();
mm_init();

+ ftrace_nodyn_init();
ftrace_init();

/* trace_printk can be enabled here */
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 56b1a42e1937..40325ae575a5 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -7454,12 +7454,10 @@ struct ftrace_ops global_ops = {
FTRACE_OPS_FL_PID,
};

-static int __init ftrace_nodyn_init(void)
+void __init ftrace_nodyn_init(void)
{
ftrace_enabled = 1;
- return 0;
}
-core_initcall(ftrace_nodyn_init);

static inline int ftrace_init_dyn_tracefs(struct dentry *d_tracer) { return 0; }
static inline void ftrace_startup_all(int command) { }
--
2.20.1



2022-10-27 12:28:11

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] ftrace: fix static function tracer not working

Hi Song,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on rostedt-trace/for-next]
[also build test ERROR on linus/master v6.1-rc2 next-20221027]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Song-Shuai/ftrace-fix-static-function-tracer-not-working/20221027-165526
base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next
patch link: https://lore.kernel.org/r/20221027085343.2388485-1-suagrfillet%40gmail.com
patch subject: [PATCH] ftrace: fix static function tracer not working
config: arc-defconfig
compiler: arc-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/44eabe3b35e870ebfd71d4bae0ebe371b305f042
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Song-Shuai/ftrace-fix-static-function-tracer-not-working/20221027-165526
git checkout 44eabe3b35e870ebfd71d4bae0ebe371b305f042
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

arc-elf-ld: init/main.o: in function `start_kernel':
>> main.c:(.init.text+0x7e2): undefined reference to `ftrace_nodyn_init'
>> arc-elf-ld: main.c:(.init.text+0x7e2): undefined reference to `ftrace_nodyn_init'

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (1.95 kB)
config (39.60 kB)
Download all attachments

2022-10-27 14:06:42

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] ftrace: fix static function tracer not working

On Thu, 27 Oct 2022 16:53:43 +0800
Song Shuai <[email protected]> wrote:

> Setting kernel command line parameter ftrace=function shows
> nothing on the kernel built with static ftrace.
>
> In static ftrace, ftrace_nodyn_init should be executed before
> initializing tracers. While this commit `dbeafd0d6131` brings
> the initialization of function tracer forward from core_initcall
> where ftrace_nodyn_init still remains.
>
> This patch puts ftrace_nodyn_init and ftrace_init together and
> makes function tracer works in static ftrace.

Sorry but NACK.

Static ftrace only exists for helping new architectures get dynamic ftrace
working. It is not, and never will be, considered the end product.

Really, I only keep it around as a stepping stone for full dynamic ftrace,
otherwise I would have removed it along time ago.

No generic code should ever be modified to satisfy static ftrace. Please
get dynamic ftrace functional, as that could be used in production
environments.

-- Steve

2022-10-27 16:50:14

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] ftrace: fix static function tracer not working

Hi Song,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on rostedt-trace/for-next]
[also build test ERROR on linus/master v6.1-rc2 next-20221027]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Song-Shuai/ftrace-fix-static-function-tracer-not-working/20221027-165526
base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next
patch link: https://lore.kernel.org/r/20221027085343.2388485-1-suagrfillet%40gmail.com
patch subject: [PATCH] ftrace: fix static function tracer not working
config: csky-randconfig-r026-20221027
compiler: csky-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/44eabe3b35e870ebfd71d4bae0ebe371b305f042
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Song-Shuai/ftrace-fix-static-function-tracer-not-working/20221027-165526
git checkout 44eabe3b35e870ebfd71d4bae0ebe371b305f042
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

csky-linux-ld: csky-linux-ld: DWARF error: could not find abbrev number 10698
init/main.o: in function `start_kernel':
main.c:(.init.text+0x7d6): undefined reference to `ftrace_nodyn_init'
>> csky-linux-ld: main.c:(.init.text+0x9c4): undefined reference to `ftrace_nodyn_init'

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.04 kB)
config (158.58 kB)
Download all attachments

2022-10-31 07:38:50

by Song Shuai

[permalink] [raw]
Subject: Re: [PATCH] ftrace: fix static function tracer not working

Hi, Steve:

Thank you for your time and attention.

The static ftrace is exactly overridden by dynamic ftrace in most architectures
when selecting Kconfig. I'll throw this patch to trash.

BTW, can you help me review this [thread][1] which hasn't been checked for about a week.

[1]: https://lore.kernel.org/linux-kernel/[email protected]/

--
Song Shuai