mbox series

[v2,0/2] ftrace: Make ftrace_regs abstract and consolidate code

Message ID 20241008230527.674939311@goodmis.org (mailing list archive)
Headers show
Series ftrace: Make ftrace_regs abstract and consolidate code | expand

Message

Steven Rostedt Oct. 8, 2024, 11:05 p.m. UTC
This is based on:

  https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git/
     ftrace/for-next

ftrace_regs was created to hold registers that store information to save
function parameters, return value and stack. Since it is a subset of
pt_regs, it should only be used by its accessor functions. But because
pt_regs can easily be taken from ftrace_regs (on most archs), it is
tempting to use it directly. But when running on other architectures, it
may fail to build or worse, build but crash the kernel!

Instead, make struct ftrace_regs an empty structure and have the
architectures define __arch_ftrace_regs and all the accessor functions
will typecast to it to get to the actual fields. This will help avoid
usage of ftrace_regs directly.

I again compiled all the affected architectures (except for 32bit ppc).
I got s390 built when disabling bcachefs.

Changes since v1: https://lore.kernel.org/all/20241007204743.41314f1d@gandalf.local.home/

- Moved the non ftrace args code from asm-generic/ftrace.h to linux/ftrace.h
  those archs have their own asm/ftrace.h and are not using asm-generic.
  The default has to be in linux/ftrace.h

- simplified arch_ftrace_get_regs() and made it a static inline function

- Added a second patch that consolidates a lot of the duplicate code
  when an architecture has pt_regs embedded in the ftrace_regs.

Steven Rostedt (2):
      ftrace: Make ftrace_regs abstract from direct use
      ftrace: Consolidate ftrace_regs accessor functions for archs using pt_regs

----
 arch/arm64/include/asm/ftrace.h          | 21 +++++++++--------
 arch/arm64/kernel/asm-offsets.c          | 22 +++++++++---------
 arch/arm64/kernel/ftrace.c               | 10 ++++----
 arch/loongarch/include/asm/ftrace.h      | 29 ++++--------------------
 arch/loongarch/kernel/ftrace_dyn.c       |  2 +-
 arch/powerpc/include/asm/ftrace.h        | 27 +++-------------------
 arch/powerpc/kernel/trace/ftrace.c       |  4 ++--
 arch/powerpc/kernel/trace/ftrace_64_pg.c |  2 +-
 arch/riscv/include/asm/ftrace.h          | 22 ++++++++++--------
 arch/riscv/kernel/asm-offsets.c          | 28 +++++++++++------------
 arch/riscv/kernel/ftrace.c               |  2 +-
 arch/s390/include/asm/ftrace.h           | 29 ++++--------------------
 arch/s390/kernel/asm-offsets.c           |  4 ++--
 arch/s390/kernel/ftrace.c                |  2 +-
 arch/s390/lib/test_unwind.c              |  4 ++--
 arch/x86/include/asm/ftrace.h            | 30 ++++++------------------
 arch/x86/kernel/ftrace.c                 |  2 +-
 include/linux/ftrace.h                   | 39 +++++++++++++++-----------------
 include/linux/ftrace_regs.h              | 36 +++++++++++++++++++++++++++++
 kernel/trace/ftrace.c                    |  2 +-
 20 files changed, 139 insertions(+), 178 deletions(-)
 create mode 100644 include/linux/ftrace_regs.h

Comments

Heiko Carstens Oct. 9, 2024, 9:36 a.m. UTC | #1
On Tue, Oct 08, 2024 at 07:05:27PM -0400, Steven Rostedt wrote:
> 
> This is based on:
> 
>   https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git/
>      ftrace/for-next
> 
> ftrace_regs was created to hold registers that store information to save
> function parameters, return value and stack. Since it is a subset of
> pt_regs, it should only be used by its accessor functions. But because
> pt_regs can easily be taken from ftrace_regs (on most archs), it is
> tempting to use it directly. But when running on other architectures, it
> may fail to build or worse, build but crash the kernel!
> 
> Instead, make struct ftrace_regs an empty structure and have the
> architectures define __arch_ftrace_regs and all the accessor functions
> will typecast to it to get to the actual fields. This will help avoid
> usage of ftrace_regs directly.
> 
> I again compiled all the affected architectures (except for 32bit ppc).
> I got s390 built when disabling bcachefs.

Build fix for this problem is commit 2007d28ec009 ("bcachefs: rename
version -> bversion for big endian builds").