OpenCloudOS-Kernel/arch/s390
Mark Rutland fee86a4ed5 ftrace: selftest: remove broken trace_direct_tramp
The ftrace selftest code has a trace_direct_tramp() function which it
uses as a direct call trampoline. This happens to work on x86, since the
direct call's return address is in the usual place, and can be returned
to via a RET, but in general the calling convention for direct calls is
different from regular function calls, and requires a trampoline written
in assembly.

On s390, regular function calls place the return address in %r14, and an
ftrace patch-site in an instrumented function places the trampoline's
return address (which is within the instrumented function) in %r0,
preserving the original %r14 value in-place. As a regular C function
will return to the address in %r14, using a C function as the trampoline
results in the trampoline returning to the caller of the instrumented
function, skipping the body of the instrumented function.

Note that the s390 issue is not detcted by the ftrace selftest code, as
the instrumented function is trivial, and returning back into the caller
happens to be equivalent.

On arm64, regular function calls place the return address in x30, and
an ftrace patch-site in an instrumented function saves this into r9
and places the trampoline's return address (within the instrumented
function) in x30. A regular C function will return to the address in
x30, but will not restore x9 into x30. Consequently, using a C function
as the trampoline results in returning to the trampoline's return
address having corrupted x30, such that when the instrumented function
returns, it will return back into itself.

To avoid future issues in this area, remove the trace_direct_tramp()
function, and require that each architecture with direct calls provides
a stub trampoline, named ftrace_stub_direct_tramp. This can be written
to handle the architecture's trampoline calling convention, and in
future could be used elsewhere (e.g. in the ftrace ops sample, to
measure the overhead of direct calls), so we may as well always build it
in.

Link: https://lkml.kernel.org/r/20230321140424.345218-8-revest@chromium.org

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Li Huafei <lihuafei1@huawei.com>
Cc: Xu Kuohai <xukuohai@huawei.com>
Signed-off-by: Florent Revest <revest@chromium.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
2023-03-21 13:59:29 -04:00
..
appldata s390/appldata: remove power management callbacks 2022-12-02 18:25:04 +01:00
boot s390/ipl: add missing intersection check to ipl_report handling 2023-03-13 09:15:11 +01:00
configs s390: update defconfigs 2023-03-13 09:15:11 +01:00
crypto This update includes the following changes: 2023-02-21 18:10:50 -08:00
hypfs s390/hypfs: remove unused info_blk_hdr__pcpus() function 2022-11-23 16:24:07 +01:00
include s390 updates for 6.3 merge window part 2 2023-03-03 09:38:01 -08:00
kernel ftrace: selftest: remove broken trace_direct_tramp 2023-03-21 13:59:29 -04:00
kvm * Two more V!=R patches 2023-02-15 12:35:26 -05:00
lib s390/kprobes: replace kretprobe with rethook 2023-01-22 18:42:35 +01:00
mm s390 updates for 6.3 merge window part 2 2023-03-03 09:38:01 -08:00
net s390/bpf: Implement bpf_jit_supports_kfunc_call() 2023-01-29 19:16:29 -08:00
pci PCI: s390: Fix use-after-free of PCI resources with per-function hotplug 2023-03-13 09:15:11 +01:00
purgatory s390/purgatory: Remove unused '-MD' and unnecessary '-c' flags 2023-01-26 12:43:05 +09:00
tools KVM: s390: Add facility 197 to the allow list 2022-07-13 15:25:25 +02:00
Kbuild kbuild: use more subdir- for visiting subdirectories while cleaning 2021-10-24 13:49:46 +09:00
Kconfig s390 updates for 6.3 merge window part 2 2023-03-03 09:38:01 -08:00
Kconfig.debug s390/Kconfig.debug: fix indentation 2022-06-01 12:03:15 +02:00
Makefile s390: always build relocatable kernel 2022-11-08 19:32:32 +01:00