s390/ftrace: add HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALL support
authorHeiko Carstens <hca@linux.ibm.com>
Tue, 12 Oct 2021 13:37:59 +0000 (15:37 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Tue, 19 Oct 2021 13:39:53 +0000 (15:39 +0200)
This is the s390 variant of commit 562955fe6a55 ("ftrace/x86: Add
register_ftrace_direct() for custom trampolines").

Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://lore.kernel.org/r/20211012133802.2460757-2-hca@linux.ibm.com
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/Kconfig
arch/s390/include/asm/ftrace.h
arch/s390/kernel/mcount.S

index c35c98e515a2400ee5d9b49b9d41a36fbcbfe830..c4b53c7313a720b723b0a74bbe4d425239047f67 100644 (file)
@@ -154,6 +154,7 @@ config S390
        select HAVE_DMA_CONTIGUOUS
        select HAVE_DYNAMIC_FTRACE
        select HAVE_DYNAMIC_FTRACE_WITH_ARGS
+       select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
        select HAVE_DYNAMIC_FTRACE_WITH_REGS
        select HAVE_EBPF_JIT if PACK_STACK && HAVE_MARCH_Z196_FEATURES
        select HAVE_EFFICIENT_UNALIGNED_ACCESS
index 4a721b44d4f406e5f9fca5b227a2614384232c28..267f70f4393f7650abb919831c4e32dd0610d1ad 100644 (file)
@@ -58,6 +58,18 @@ static __always_inline void ftrace_instruction_pointer_set(struct ftrace_regs *f
        regs->psw.addr = ip;
 }
 
+/*
+ * When an ftrace registered caller is tracing a function that is
+ * also set by a register_ftrace_direct() call, it needs to be
+ * differentiated in the ftrace_caller trampoline. To do this,
+ * place the direct caller in the ORIG_GPR2 part of pt_regs. This
+ * tells the ftrace_caller that there's a direct caller.
+ */
+static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
+{
+       regs->orig_gpr2 = addr;
+}
+
 /*
  * Even though the system call numbers are identical for s390/s390x a
  * different system call table is used for compat tasks. This may lead
index cc25fbd75ea9ba6fecbf3dfc9b3c4f4a32bc7b42..39bcc0e39a10d7d0e63ec3a5dd0921a9d8fd9941 100644 (file)
@@ -22,10 +22,11 @@ ENTRY(ftrace_stub)
        BR_EX   %r14
 ENDPROC(ftrace_stub)
 
-#define STACK_FRAME_SIZE  (STACK_FRAME_OVERHEAD + __PT_SIZE)
-#define STACK_PTREGS     (STACK_FRAME_OVERHEAD)
-#define STACK_PTREGS_GPRS (STACK_PTREGS + __PT_GPRS)
-#define STACK_PTREGS_PSW  (STACK_PTREGS + __PT_PSW)
+#define STACK_FRAME_SIZE       (STACK_FRAME_OVERHEAD + __PT_SIZE)
+#define STACK_PTREGS           (STACK_FRAME_OVERHEAD)
+#define STACK_PTREGS_GPRS      (STACK_PTREGS + __PT_GPRS)
+#define STACK_PTREGS_PSW       (STACK_PTREGS + __PT_PSW)
+#define STACK_PTREGS_ORIG_GPR2 (STACK_PTREGS + __PT_ORIG_GPR2)
 #ifdef __PACK_STACK
 /* allocate just enough for r14, r15 and backchain */
 #define TRACED_FUNC_FRAME_SIZE 24
@@ -51,6 +52,7 @@ ENDPROC(ftrace_stub)
        # allocate pt_regs and stack frame for ftrace_trace_function
        aghi    %r15,-STACK_FRAME_SIZE
        stg     %r1,(STACK_PTREGS_GPRS+15*8)(%r15)
+       xc      STACK_PTREGS_ORIG_GPR2(8,%r15),STACK_PTREGS_ORIG_GPR2(%r15)
 
        .if \allregs == 1
        stg     %r14,(STACK_PTREGS_PSW)(%r15)
@@ -101,8 +103,17 @@ SYM_INNER_LABEL(ftrace_graph_caller, SYM_L_GLOBAL)
        stg     %r2,(STACK_PTREGS_GPRS+14*8)(%r15)
 .Lftrace_graph_caller_end:
 #endif
-       lg      %r1,(STACK_PTREGS_PSW+8)(%r15)
-       lmg     %r2,%r15,(STACK_PTREGS_GPRS+2*8)(%r15)
+       lg      %r0,(STACK_PTREGS_PSW+8)(%r15)
+#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
+       ltg     %r1,STACK_PTREGS_ORIG_GPR2(%r15)
+       locgrz  %r1,%r0
+#else
+       lg      %r1,STACK_PTREGS_ORIG_GPR2(%r15)
+       ltgr    %r1,%r1
+       jnz     0f
+       lgr     %r1,%r0
+#endif
+0:     lmg     %r2,%r15,(STACK_PTREGS_GPRS+2*8)(%r15)
        BR_EX   %r1
 SYM_CODE_END(ftrace_common)