mbox series

[v7,00/17] powerpc: Core ftrace rework, support for ftrace direct and bpf trampolines

Message ID 20241030070850.1361304-1-hbathini@linux.ibm.com (mailing list archive)
Headers show
Series powerpc: Core ftrace rework, support for ftrace direct and bpf trampolines | expand

Message

Hari Bathini Oct. 30, 2024, 7:08 a.m. UTC
This is v7 of the series posted here:
https://lore.kernel.org/all/20241018173632.277333-1-hbathini@linux.ibm.com/

This series reworks core ftrace support on powerpc to have the function
profiling sequence moved out of line. This enables us to have a single
nop at kernel function entry virtually eliminating effect of the
function tracer when it is not enabled. The function profile sequence is
moved out of line and is allocated at two separate places depending on a
new config option.

For 64-bit powerpc, the function profiling sequence is also updated to
include an additional instruction 'mtlr r0' after the usual
two-instruction sequence to fix link stack imbalance (return address
predictor) when ftrace is enabled. This showed an improvement of ~10%
in null_syscall benchmark (NR_LOOPS=10000000) on a Power 10 system
with ftrace enabled.

Finally, support for ftrace direct calls is added based on support for
DYNAMIC_FTRACE_WITH_CALL_OPS. BPF Trampoline support is added atop this.

Support for ftrace direct calls is added for 32-bit powerpc. There is
some code to enable bpf trampolines for 32-bit powerpc, but it is not
complete and will need to be pursued separately.

Patches 1 to 10 are independent of this series and can go in separately
though. Rest of the patches depend on the series from Benjamin Gray
adding support for patch_uint() and patch_ulong():
https://lore.kernel.org/all/172474280311.31690.1489687786264785049.b4-ty@ellerman.id.au/

Changelog v7:
* Changed 'arch_vmlinux_o=""' to 'arch_vmlinux_o='.
* Added Masahiro's Acked-by.
* Added change to avoid ".space repeat count is zero, ignored" warning.
* Fixed PCREL build failure.

Changelog v6:
* Shellcheck warnings fixed for arch/powerpc/tools/ftrace_check.sh
* Masahiro's suggestions incorporated in appropriate patches:
    - https://lore.kernel.org/all/CAK7LNATzqVAJHFg6OyVR1+YgNKo7S=nN1M7w5GJVG1Ygn0QhUA@mail.gmail.com/
* Shellcheck warnings fixed for arch/powerpc/tools/ftrace-gen-ool-stubs.sh
* Fixed https://lore.kernel.org/all/202409170544.6d1odaN2-lkp@intel.com/
* Updated the stale comment describing redzone usage in ppc64 BPF JIT

Changelog v5:
* Intermediate files named .vmlinux.arch.* instead of .arch.vmlinux.*
* Fixed ftrace stack tracer failure due to inadvertent use of
  'add r7, r3, MCOUNT_INSN_SIZE' instruction instead of
  'addi r7, r3, MCOUNT_INSN_SIZE'
* Fixed build error for !CONFIG_MODULES case.
* .vmlinux.arch.* files compiled under arch/powerpc/tools
* Resolved checkpatch.pl warnings.
* Dropped RFC tag.

Changelog v4:
- Patches 1, 10 and 13 are new.
- Address review comments from Nick. Numerous changes throughout the 
  patch series.
- Extend support for ftrace ool to vmlinux text up to 64MB (patch 13).
- Address remaining TODOs in support for BPF Trampolines.
- Update synchronization when patching instructions during trampoline 
  attach/detach.


Naveen N Rao (17):
  powerpc/trace: Account for -fpatchable-function-entry support by
    toolchain
  powerpc/kprobes: Use ftrace to determine if a probe is at function
    entry
  powerpc64/ftrace: Nop out additional 'std' instruction emitted by gcc
    v5.x
  powerpc32/ftrace: Unify 32-bit and 64-bit ftrace entry code
  powerpc/module_64: Convert #ifdef to IS_ENABLED()
  powerpc/ftrace: Remove pointer to struct module from dyn_arch_ftrace
  powerpc/ftrace: Skip instruction patching if the instructions are the
    same
  powerpc/ftrace: Move ftrace stub used for init text before _einittext
  powerpc64/bpf: Fold bpf_jit_emit_func_call_hlp() into
    bpf_jit_emit_func_call_rel()
  powerpc/ftrace: Add a postlink script to validate function tracer
  kbuild: Add generic hook for architectures to use before the final
    vmlinux link
  powerpc64/ftrace: Move ftrace sequence out of line
  powerpc64/ftrace: Support .text larger than 32MB with out-of-line
    stubs
  powerpc/ftrace: Add support for DYNAMIC_FTRACE_WITH_CALL_OPS
  powerpc/ftrace: Add support for DYNAMIC_FTRACE_WITH_DIRECT_CALLS
  samples/ftrace: Add support for ftrace direct samples on powerpc
  powerpc64/bpf: Add support for bpf trampolines

 arch/Kconfig                                |   6 +
 arch/powerpc/Kbuild                         |   2 +-
 arch/powerpc/Kconfig                        |  22 +-
 arch/powerpc/Makefile                       |   8 +
 arch/powerpc/Makefile.postlink              |   8 +
 arch/powerpc/include/asm/ftrace.h           |  33 +-
 arch/powerpc/include/asm/module.h           |   5 +
 arch/powerpc/include/asm/ppc-opcode.h       |  14 +
 arch/powerpc/kernel/asm-offsets.c           |  11 +
 arch/powerpc/kernel/kprobes.c               |  18 +-
 arch/powerpc/kernel/module_64.c             |  66 +-
 arch/powerpc/kernel/trace/Makefile          |  11 +-
 arch/powerpc/kernel/trace/ftrace.c          | 298 ++++++-
 arch/powerpc/kernel/trace/ftrace_64_pg.c    |  69 +-
 arch/powerpc/kernel/trace/ftrace_entry.S    | 244 ++++--
 arch/powerpc/kernel/vmlinux.lds.S           |   3 +-
 arch/powerpc/net/bpf_jit.h                  |  17 +
 arch/powerpc/net/bpf_jit_comp.c             | 847 +++++++++++++++++++-
 arch/powerpc/net/bpf_jit_comp32.c           |   7 +-
 arch/powerpc/net/bpf_jit_comp64.c           |  72 +-
 arch/powerpc/tools/.gitignore               |   2 +
 arch/powerpc/tools/Makefile                 |  10 +
 arch/powerpc/tools/ftrace-gen-ool-stubs.sh  |  51 ++
 arch/powerpc/tools/ftrace_check.sh          |  50 ++
 samples/ftrace/ftrace-direct-modify.c       |  85 +-
 samples/ftrace/ftrace-direct-multi-modify.c | 101 ++-
 samples/ftrace/ftrace-direct-multi.c        |  79 +-
 samples/ftrace/ftrace-direct-too.c          |  83 +-
 samples/ftrace/ftrace-direct.c              |  69 +-
 scripts/Makefile.vmlinux                    |   7 +
 scripts/link-vmlinux.sh                     |   7 +-
 31 files changed, 2103 insertions(+), 202 deletions(-)
 create mode 100644 arch/powerpc/tools/.gitignore
 create mode 100644 arch/powerpc/tools/Makefile
 create mode 100755 arch/powerpc/tools/ftrace-gen-ool-stubs.sh
 create mode 100755 arch/powerpc/tools/ftrace_check.sh

Comments

Michael Ellerman Nov. 17, 2024, 12:09 p.m. UTC | #1
On Wed, 30 Oct 2024 12:38:33 +0530, Hari Bathini wrote:
> This is v7 of the series posted here:
> https://lore.kernel.org/all/20241018173632.277333-1-hbathini@linux.ibm.com/
> 
> This series reworks core ftrace support on powerpc to have the function
> profiling sequence moved out of line. This enables us to have a single
> nop at kernel function entry virtually eliminating effect of the
> function tracer when it is not enabled. The function profile sequence is
> moved out of line and is allocated at two separate places depending on a
> new config option.
> 
> [...]

Applied to powerpc/next.

[01/17] powerpc/trace: Account for -fpatchable-function-entry support by toolchain
        https://git.kernel.org/powerpc/c/0b9846529e29ba988ce88b98df633de79675fcb3
[02/17] powerpc/kprobes: Use ftrace to determine if a probe is at function entry
        https://git.kernel.org/powerpc/c/be87d713eaddf0421ccd61cc060c4c29bc36fc9b
[03/17] powerpc64/ftrace: Nop out additional 'std' instruction emitted by gcc v5.x
        https://git.kernel.org/powerpc/c/161d62c2b067c4071cb515efe16475171e1c051e
[04/17] powerpc32/ftrace: Unify 32-bit and 64-bit ftrace entry code
        https://git.kernel.org/powerpc/c/654b3fa61b817a46037197b73a7ac6d36d01df7e
[05/17] powerpc/module_64: Convert #ifdef to IS_ENABLED()
        https://git.kernel.org/powerpc/c/c12cfe9dee077763708e0a5cf3aca02a85b1e8ba
[06/17] powerpc/ftrace: Remove pointer to struct module from dyn_arch_ftrace
        https://git.kernel.org/powerpc/c/8b0dc1305ea0bbb015b560193cdd76fd4100f062
[07/17] powerpc/ftrace: Skip instruction patching if the instructions are the same
        https://git.kernel.org/powerpc/c/1d59bd2fc07f0b2e643b2a07405cf0717b93984f
[08/17] powerpc/ftrace: Move ftrace stub used for init text before _einittext
        https://git.kernel.org/powerpc/c/ed6144656bb1ea29ad83671b48a21c89e7873b8a
[09/17] powerpc64/bpf: Fold bpf_jit_emit_func_call_hlp() into bpf_jit_emit_func_call_rel()
        https://git.kernel.org/powerpc/c/9670f6d2097c4f97e15c67920dfddc664d7ee91c
[10/17] powerpc/ftrace: Add a postlink script to validate function tracer
        https://git.kernel.org/powerpc/c/782f46cbce5328da9380f166bd31cd17a04a7b10
[11/17] kbuild: Add generic hook for architectures to use before the final vmlinux link
        https://git.kernel.org/powerpc/c/1198c9c689cfdaa2d08eb508c13ff116043f07b7
[12/17] powerpc64/ftrace: Move ftrace sequence out of line
        https://git.kernel.org/powerpc/c/eec37961a56aa4f3fe1c33ffd48eec7d1bb0c009
[13/17] powerpc64/ftrace: Support .text larger than 32MB with out-of-line stubs
        https://git.kernel.org/powerpc/c/cf9bc0efcce2c324314cf7f5138c08f85ef7b5eb
[14/17] powerpc/ftrace: Add support for DYNAMIC_FTRACE_WITH_CALL_OPS
        https://git.kernel.org/powerpc/c/e717754f0bb5c5347aac82232691340955735ce1
[15/17] powerpc/ftrace: Add support for DYNAMIC_FTRACE_WITH_DIRECT_CALLS
        https://git.kernel.org/powerpc/c/a52f6043a2238d656ddd23ce0499cf4f12645faa
[16/17] samples/ftrace: Add support for ftrace direct samples on powerpc
        https://git.kernel.org/powerpc/c/71db948b9d2744e92124720f682ed2c26f0de75b
[17/17] powerpc64/bpf: Add support for bpf trampolines
        https://git.kernel.org/powerpc/c/d243b62b7bd3d5314382d3b54e4992226245e936

cheers