linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 0/5] arm64: ftrace with regs
@ 2019-02-08 15:08 Torsten Duwe
  2019-02-08 15:10 ` [PATCH v8 1/5] arm64: replace -pg with CC_FLAGS_FTRACE in arm64 Makefiles Torsten Duwe
                   ` (5 more replies)
  0 siblings, 6 replies; 29+ messages in thread
From: Torsten Duwe @ 2019-02-08 15:08 UTC (permalink / raw)
  To: Mark Rutland, Will Deacon, Catalin Marinas, Julien Thierry,
	Steven Rostedt, Josh Poimboeuf, Ingo Molnar, Ard Biesheuvel,
	Arnd Bergmann, AKASHI Takahiro, Amit Daniel Kachhap
  Cc: live-patching, linux-kernel, linux-arm-kernel

Patch series v8, as discussed.
The whole series applies cleanly on 5.0-rc5

---
 arch/arm64/Kconfig                    |    4 +
 arch/arm64/Makefile                   |   10 ++
 arch/arm64/include/asm/ftrace.h       |   16 ++++
 arch/arm64/include/asm/module.h       |    3 
 arch/arm64/kernel/Makefile            |   12 +--
 arch/arm64/kernel/entry-ftrace.S      |  125 ++++++++++++++++++++++++++++++++--
 arch/arm64/kernel/ftrace.c            |  117 ++++++++++++++++++++++++-------
 arch/arm64/kernel/module-plts.c       |    3 
 arch/arm64/kernel/module.c            |    2 
 arch/arm64/lib/Makefile               |    4 -
 drivers/firmware/efi/libstub/Makefile |   12 +--
 include/asm-generic/vmlinux.lds.h     |    2 
 include/linux/compiler_types.h        |    4 +
 kernel/module.c                       |   14 +++
 mm/kasan/Makefile                     |    8 +-
 15 files changed, 281 insertions(+), 55 deletions(-)
---
changes since v7:

* -pg -> $(CC_FLAGS_FTRACE) cleanup now split according to subtree
  maintainership.

* REC_IP_BRANCH_OFFSET is gone, the functionality went into
  ftrace_call_adjust(), where it belongs.

* MOV_X9_X30 macro is gone (why did we argue about its name anyway?);
  it is only used once now in the initial ftrace_make_nop new helper
  function ftrace_setup_lr_saver(), suggested by Julien.

* call site processing was missing for modules. Fixed.

changes since v6:

* change the stack layout once more; I hope I have it the "standard" way now.
  And yes, it looks simpler and cleaner; thanks, Mark, for nagging.

* split out the independent Kconfig and Makefile changes

* fixed style issues

* s/fp/x29/g

* MCOUNT_ADDR is now merely a 64-bit magic, as this is totally sufficient.

* QUICK_LR_SAVE renamed back to MOV_X9_X30.

* place MOV_X9_X30 insns on bootup, and only flip b <-> nop at runtime

* graph tracer "ifdeffery" reshuffle

	Torsten
  

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH v8 1/5] arm64: replace -pg with CC_FLAGS_FTRACE in arm64 Makefiles
  2019-02-08 15:08 [PATCH v8 0/5] arm64: ftrace with regs Torsten Duwe
@ 2019-02-08 15:10 ` Torsten Duwe
  2019-02-11 11:53   ` Mark Rutland
  2019-02-08 15:10 ` [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles Torsten Duwe
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 29+ messages in thread
From: Torsten Duwe @ 2019-02-08 15:10 UTC (permalink / raw)
  To: Mark Rutland, Will Deacon, Catalin Marinas, Julien Thierry,
	Steven Rostedt, Josh Poimboeuf, Ingo Molnar, Ard Biesheuvel,
	Arnd Bergmann, AKASHI Takahiro, Amit Daniel Kachhap
  Cc: live-patching, linux-kernel, linux-arm-kernel

  In preparation for arm64 supporting ftrace built on other compiler
  options, let's have the arm64 makefiles remove the $(CC_FLAGS_FTRACE)
  flags, whatever these may be, rather than assuming '-pg'.

  There should be no functional change as a result of this patch.

Signed-off-by: Torsten Duwe <duwe@suse.de>

---
 arch/arm64/kernel/Makefile |    6 +++---
 arch/arm64/lib/Makefile    |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -7,9 +7,9 @@ CPPFLAGS_vmlinux.lds	:= -DTEXT_OFFSET=$(
 AFLAGS_head.o		:= -DTEXT_OFFSET=$(TEXT_OFFSET)
 CFLAGS_armv8_deprecated.o := -I$(src)
 
-CFLAGS_REMOVE_ftrace.o = -pg
-CFLAGS_REMOVE_insn.o = -pg
-CFLAGS_REMOVE_return_address.o = -pg
+CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_insn.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
 
 # Object file lists.
 obj-y			:= debug-monitors.o entry.o irq.o fpsimd.o		\
--- a/arch/arm64/lib/Makefile
+++ b/arch/arm64/lib/Makefile
@@ -24,7 +24,7 @@ CFLAGS_atomic_ll_sc.o	:= -ffixed-x1 -ffi
 		   -fcall-saved-x10 -fcall-saved-x11 -fcall-saved-x12	\
 		   -fcall-saved-x13 -fcall-saved-x14 -fcall-saved-x15	\
 		   -fcall-saved-x18 -fomit-frame-pointer
-CFLAGS_REMOVE_atomic_ll_sc.o := -pg
+CFLAGS_REMOVE_atomic_ll_sc.o := $(CC_FLAGS_FTRACE)
 GCOV_PROFILE_atomic_ll_sc.o	:= n
 KASAN_SANITIZE_atomic_ll_sc.o	:= n
 KCOV_INSTRUMENT_atomic_ll_sc.o	:= n

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles
  2019-02-08 15:08 [PATCH v8 0/5] arm64: ftrace with regs Torsten Duwe
  2019-02-08 15:10 ` [PATCH v8 1/5] arm64: replace -pg with CC_FLAGS_FTRACE in arm64 Makefiles Torsten Duwe
@ 2019-02-08 15:10 ` Torsten Duwe
  2019-02-11 11:59   ` Mark Rutland
  2019-04-08 15:23   ` Mark Rutland
  2019-02-08 15:10 ` [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile Torsten Duwe
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 29+ messages in thread
From: Torsten Duwe @ 2019-02-08 15:10 UTC (permalink / raw)
  To: Mark Rutland, Will Deacon, Catalin Marinas, Julien Thierry,
	Steven Rostedt, Josh Poimboeuf, Ingo Molnar, Ard Biesheuvel,
	Arnd Bergmann, AKASHI Takahiro, Amit Daniel Kachhap
  Cc: live-patching, linux-efi, linux-kernel, linux-arm-kernel

  In preparation for arm64 supporting ftrace built on other compiler
  options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
  flags, whatever these may be, rather than assuming '-pg'.
  While at it, fix arm32 as well.

  There should be no functional change as a result of this patch.

Signed-off-by: Torsten Duwe <duwe@suse.de>

---
 drivers/firmware/efi/libstub/Makefile |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -16,9 +16,9 @@ cflags-$(CONFIG_X86)		+= -m$(BITS) -D__K
 
 # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly
 # disable the stackleak plugin
-cflags-$(CONFIG_ARM64)		:= $(subst -pg,,$(KBUILD_CFLAGS)) -fpie \
-				   $(DISABLE_STACKLEAK_PLUGIN)
-cflags-$(CONFIG_ARM)		:= $(subst -pg,,$(KBUILD_CFLAGS)) \
+cflags-$(CONFIG_ARM64)		:= $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
+				   -fpie $(DISABLE_STACKLEAK_PLUGIN)
+cflags-$(CONFIG_ARM)		:= $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
 				   -fno-builtin -fpic \
 				   $(call cc-option,-mno-single-pic-base)
 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile
  2019-02-08 15:08 [PATCH v8 0/5] arm64: ftrace with regs Torsten Duwe
  2019-02-08 15:10 ` [PATCH v8 1/5] arm64: replace -pg with CC_FLAGS_FTRACE in arm64 Makefiles Torsten Duwe
  2019-02-08 15:10 ` [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles Torsten Duwe
@ 2019-02-08 15:10 ` Torsten Duwe
  2019-02-11 11:55   ` Mark Rutland
                     ` (3 more replies)
  2019-02-08 15:10 ` [PATCH v8 4/5] arm64: implement ftrace with regs Torsten Duwe
                   ` (2 subsequent siblings)
  5 siblings, 4 replies; 29+ messages in thread
From: Torsten Duwe @ 2019-02-08 15:10 UTC (permalink / raw)
  To: Mark Rutland, Will Deacon, Catalin Marinas, Julien Thierry,
	Steven Rostedt, Josh Poimboeuf, Ingo Molnar, Ard Biesheuvel,
	Arnd Bergmann, AKASHI Takahiro, Andrey Ryabinin,
	Alexander Potapenko, Dmitry Vyukov, Amit Daniel Kachhap
  Cc: live-patching, kasan-dev, linux-kernel, linux-arm-kernel

  In preparation for arm64 supporting ftrace built on other compiler
  options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
  flags, whatever these may be, rather than assuming '-pg'.

  There should be no functional change as a result of this patch.

Signed-off-by: Torsten Duwe <duwe@suse.de>

---
 mm/kasan/Makefile |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
--- a/mm/kasan/Makefile
+++ b/mm/kasan/Makefile
@@ -5,8 +5,8 @@ UBSAN_SANITIZE_generic.o := n
 UBSAN_SANITIZE_tags.o := n
 KCOV_INSTRUMENT := n
 
-CFLAGS_REMOVE_common.o = -pg
-CFLAGS_REMOVE_generic.o = -pg
+CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE)
 # Function splitter causes unnecessary splits in __asan_load1/__asan_store1
 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533
 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH v8 4/5] arm64: implement ftrace with regs
  2019-02-08 15:08 [PATCH v8 0/5] arm64: ftrace with regs Torsten Duwe
                   ` (2 preceding siblings ...)
  2019-02-08 15:10 ` [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile Torsten Duwe
@ 2019-02-08 15:10 ` Torsten Duwe
  2019-02-13 10:30   ` Julien Thierry
  2019-02-08 15:10 ` [PATCH v8 5/5] arm64: use -fpatchable-function-entry if available Torsten Duwe
  2019-02-13 11:11 ` [PATCH v8 0/5] arm64: ftrace with regs Julien Thierry
  5 siblings, 1 reply; 29+ messages in thread
From: Torsten Duwe @ 2019-02-08 15:10 UTC (permalink / raw)
  To: Mark Rutland, Will Deacon, Catalin Marinas, Julien Thierry,
	Steven Rostedt, Josh Poimboeuf, Ingo Molnar, Ard Biesheuvel,
	Arnd Bergmann, AKASHI Takahiro, Amit Daniel Kachhap
  Cc: live-patching, linux-kernel, linux-arm-kernel

Implement ftrace with regs, based on the new gcc flag
-fpatchable-function-entry (=2)

Now that gcc8 added 2 NOPs at the beginning of each function, replace
the first NOP thus generated with a quick LR saver (move it to scratch
reg x9), so the 2nd replacement insn, the call to ftrace, does not
clobber the value. Ftrace will then generate the standard stack
frames.

Note that patchable-function-entry in GCC disables IPA-RA, which means
ABI register calling conventions are obeyed and scratch registers such
as x9 are available.

Introduce and handle an ftrace_regs_trampoline for module PLTs, right
after ftrace_trampoline in an ftrace_trampolines[2] array, and double
the size of the corresponding special section.

Signed-off-by: Torsten Duwe <duwe@suse.de>

---
 arch/arm64/include/asm/ftrace.h  |   16 ++++
 arch/arm64/include/asm/module.h  |    3 
 arch/arm64/kernel/entry-ftrace.S |  125 +++++++++++++++++++++++++++++++++++++--
 arch/arm64/kernel/ftrace.c       |  117 ++++++++++++++++++++++++++++--------
 arch/arm64/kernel/module-plts.c  |    3 
 arch/arm64/kernel/module.c       |    2 
 6 files changed, 231 insertions(+), 35 deletions(-)
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -14,9 +14,16 @@
 #include <asm/insn.h>
 
 #define HAVE_FUNCTION_GRAPH_FP_TEST
-#define MCOUNT_ADDR		((unsigned long)_mcount)
 #define MCOUNT_INSN_SIZE	AARCH64_INSN_SIZE
 
+#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
+#define ARCH_SUPPORTS_FTRACE_OPS 1
+/* All we need is some magic value. Simply use "_mCount:" */
+#define MCOUNT_ADDR		(0x5f6d436f756e743a)
+#else
+#define MCOUNT_ADDR		((unsigned long)_mcount)
+#endif
+
 #ifndef __ASSEMBLY__
 #include <linux/compat.h>
 
@@ -34,6 +41,13 @@ extern void return_to_handler(void);
 static inline unsigned long ftrace_call_adjust(unsigned long addr)
 {
 	/*
+	 * For -fpatchable-function-entry=2, there's first the
+	 * LR saver, and only then the actual call insn.
+	 * Advance addr accordingly.
+	 */
+	if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS))
+		return (addr + AARCH64_INSN_SIZE);
+	/*
 	 * addr is the address of the mcount call instruction.
 	 * recordmcount does the necessary offset calculation.
 	 */
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -10,6 +10,7 @@
  */
 
 #include <linux/linkage.h>
+#include <asm/asm-offsets.h>
 #include <asm/assembler.h>
 #include <asm/ftrace.h>
 #include <asm/insn.h>
@@ -124,6 +125,7 @@ EXPORT_SYMBOL(_mcount)
 NOKPROBE(_mcount)
 
 #else /* CONFIG_DYNAMIC_FTRACE */
+#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS
 /*
  * _mcount() is used to build the kernel with -pg option, but all the branch
  * instructions to _mcount() are replaced to NOP initially at kernel start up,
@@ -163,11 +165,6 @@ GLOBAL(ftrace_graph_call)		// ftrace_gra
 
 	mcount_exit
 ENDPROC(ftrace_caller)
-#endif /* CONFIG_DYNAMIC_FTRACE */
-
-ENTRY(ftrace_stub)
-	ret
-ENDPROC(ftrace_stub)
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 /*
@@ -187,7 +184,125 @@ ENTRY(ftrace_graph_caller)
 
 	mcount_exit
 ENDPROC(ftrace_graph_caller)
+#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
+
+#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
+
+	.macro  ftrace_regs_entry, allregs=0
+	/* make room for pt_regs, plus a callee frame */
+	sub	sp, sp, #(S_FRAME_SIZE + 16)
+
+	/* save function arguments */
+	stp	x0, x1, [sp, #S_X0]
+	stp	x2, x3, [sp, #S_X2]
+	stp	x4, x5, [sp, #S_X4]
+	stp	x6, x7, [sp, #S_X6]
+	stp	x8, x9, [sp, #S_X8]
 
+	.if \allregs == 1
+	stp	x10, x11, [sp, #S_X10]
+	stp	x12, x13, [sp, #S_X12]
+	stp	x14, x15, [sp, #S_X14]
+	stp	x16, x17, [sp, #S_X16]
+	stp	x18, x19, [sp, #S_X18]
+	stp	x20, x21, [sp, #S_X20]
+	stp	x22, x23, [sp, #S_X22]
+	stp	x24, x25, [sp, #S_X24]
+	stp	x26, x27, [sp, #S_X26]
+	.endif
+
+	/* Save fp and x28, which is used in this function. */
+	stp	x28, x29, [sp, #S_X28]
+
+	/* The stack pointer as it was on ftrace_caller entry... */
+	add	x28, sp, #(S_FRAME_SIZE + 16)
+	/* ...and the link Register at callee entry */
+	stp	x9, x28, [sp, #S_LR]	/* to pt_regs.r[30] and .sp */
+
+	/* The program counter just after the ftrace call site */
+	str	lr, [sp, #S_PC]
+
+	/* Now fill in callee's preliminary stackframe. */
+	stp	x29, x9, [sp, #S_FRAME_SIZE]
+	/* Let FP point to it. */
+	add	x29, sp, #S_FRAME_SIZE
+
+	/* Our stackframe, stored inside pt_regs. */
+	stp	x29, x30, [sp, #S_STACKFRAME]
+	add	x29, sp, #S_STACKFRAME
+	.endm
+
+ENTRY(ftrace_regs_caller)
+	ftrace_regs_entry	1
+	b	ftrace_common
+ENDPROC(ftrace_regs_caller)
+
+ENTRY(ftrace_caller)
+	ftrace_regs_entry	0
+	b	ftrace_common
+ENDPROC(ftrace_caller)
+
+ENTRY(ftrace_common)
+
+	mov	x3, sp				/* pt_regs are @sp */
+	ldr_l	x2, function_trace_op, x0
+	mov	x1, x9				/* parent IP */
+	sub	x0, lr, #AARCH64_INSN_SIZE
+
+GLOBAL(ftrace_call)
+	bl	ftrace_stub
+
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+GLOBAL(ftrace_graph_call)		// ftrace_graph_caller();
+	nop				// If enabled, this will be replaced
+					// "b ftrace_graph_caller"
+#endif
+
+/*
+ * GCC's patchable-function-entry implicitly disables IPA-RA,
+ * so all non-argument registers are either scratch / dead
+ * or callee-saved (within the ftrace framework). Function
+ * arguments of the call we are intercepting right now however
+ * need to be preserved in any case.
+ */
+ftrace_common_return:
+	/* restore function args */
+	ldp	x0, x1, [sp]
+	ldp	x2, x3, [sp, #S_X2]
+	ldp	x4, x5, [sp, #S_X4]
+	ldp	x6, x7, [sp, #S_X6]
+	ldr	x8, [sp, #S_X8]
+
+	/* restore fp and x28 */
+	ldp	x28, x29, [sp, #S_X28]
+
+	ldr	lr, [sp, #S_LR]
+	ldr	x9, [sp, #S_PC]
+	/* clean up both frames, ours and callee preliminary */
+	add	sp, sp, #S_FRAME_SIZE + 16
+
+	ret	x9
+ENDPROC(ftrace_common)
+
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+ENTRY(ftrace_graph_caller)
+	ldr	x0, [sp, #S_PC]		   /* pc */
+	sub	x0, x0, #AARCH64_INSN_SIZE
+	add	x1, sp, #S_LR		   /* &lr */
+	ldr	x2, [sp, #S_FRAME_SIZE]	   /* fp */
+	bl	prepare_ftrace_return
+	b	ftrace_common_return
+ENDPROC(ftrace_graph_caller)
+#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
+#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
+#endif /* CONFIG_DYNAMIC_FTRACE */
+
+ENTRY(ftrace_stub)
+	ret
+ENDPROC(ftrace_stub)
+
+
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 /*
  * void return_to_handler(void)
  *
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -65,6 +65,40 @@ int ftrace_update_ftrace_func(ftrace_fun
 	return ftrace_modify_code(pc, 0, new, false);
 }
 
+#ifdef CONFIG_ARM64_MODULE_PLTS
+static int install_ftrace_trampoline(struct module *mod, unsigned long *addr)
+{
+	struct plt_entry trampoline, *mod_trampoline;
+
+	/*
+	 * Iterate over
+	 * mod->arch.ftrace_trampolines[MOD_ARCH_NR_FTRACE_TRAMPOLINES]
+	 * The assignment to various ftrace functions happens here.
+	 */
+	if (*addr == FTRACE_ADDR)
+		mod_trampoline = &mod->arch.ftrace_trampolines[0];
+	else if (*addr == FTRACE_REGS_ADDR)
+		mod_trampoline = &mod->arch.ftrace_trampolines[1];
+	else
+		return -EINVAL;
+
+	trampoline = get_plt_entry(*addr, mod_trampoline);
+
+	if (!plt_entries_equal(mod_trampoline, &trampoline)) {
+		/* point the trampoline at our ftrace entry point */
+		module_disable_ro(mod);
+		*mod_trampoline = trampoline;
+		module_enable_ro(mod, true);
+
+		/* update trampoline before patching in the branch */
+		smp_wmb();
+	}
+	*addr = (unsigned long)(void *)mod_trampoline;
+
+	return 0;
+}
+#endif
+
 /*
  * Turn on the call to ftrace_caller() in instrumented function
  */
@@ -76,8 +110,8 @@ int ftrace_make_call(struct dyn_ftrace *
 
 	if (offset < -SZ_128M || offset >= SZ_128M) {
 #ifdef CONFIG_ARM64_MODULE_PLTS
-		struct plt_entry trampoline;
 		struct module *mod;
+		int ret;
 
 		/*
 		 * On kernels that support module PLTs, the offset between the
@@ -96,32 +130,14 @@ int ftrace_make_call(struct dyn_ftrace *
 		if (WARN_ON(!mod))
 			return -EINVAL;
 
-		/*
-		 * There is only one ftrace trampoline per module. For now,
-		 * this is not a problem since on arm64, all dynamic ftrace
-		 * invocations are routed via ftrace_caller(). This will need
-		 * to be revisited if support for multiple ftrace entry points
-		 * is added in the future, but for now, the pr_err() below
-		 * deals with a theoretical issue only.
-		 */
-		trampoline = get_plt_entry(addr, mod->arch.ftrace_trampoline);
-		if (!plt_entries_equal(mod->arch.ftrace_trampoline,
-				       &trampoline)) {
-			if (!plt_entries_equal(mod->arch.ftrace_trampoline,
-					       &(struct plt_entry){})) {
-				pr_err("ftrace: far branches to multiple entry points unsupported inside a single module\n");
-				return -EINVAL;
-			}
-
-			/* point the trampoline to our ftrace entry point */
-			module_disable_ro(mod);
-			*mod->arch.ftrace_trampoline = trampoline;
-			module_enable_ro(mod, true);
+		/* Check against our well-known list of ftrace entry points */
+		if (addr == FTRACE_ADDR || addr == FTRACE_REGS_ADDR) {
+			ret = install_ftrace_trampoline(mod, &addr);
+			if (ret < 0)
+				return ret;
+		} else
+			return -EINVAL;
 
-			/* update trampoline before patching in the branch */
-			smp_wmb();
-		}
-		addr = (unsigned long)(void *)mod->arch.ftrace_trampoline;
 #else /* CONFIG_ARM64_MODULE_PLTS */
 		return -EINVAL;
 #endif /* CONFIG_ARM64_MODULE_PLTS */
@@ -133,6 +149,45 @@ int ftrace_make_call(struct dyn_ftrace *
 	return ftrace_modify_code(pc, old, new, true);
 }
 
+#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
+int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
+			unsigned long addr)
+{
+	unsigned long pc = rec->ip;
+	u32 old, new;
+
+	old = aarch64_insn_gen_branch_imm(pc, old_addr,
+					  AARCH64_INSN_BRANCH_LINK);
+	new = aarch64_insn_gen_branch_imm(pc, addr, AARCH64_INSN_BRANCH_LINK);
+
+	return ftrace_modify_code(pc, old, new, true);
+}
+
+/*
+ * Ftrace with regs generates the tracer calls as close as possible to
+ * the function entry; no stack frame has been set up at that point.
+ * In order to make another call e.g to ftrace_caller, the LR must be
+ * saved from being overwritten.
+ * Between two functions, and with IPA-RA turned off, the scratch registers
+ * are available, so move the LR to x9 before calling into ftrace.
+ *
+ * This function is called once during kernel startup for each call site.
+ * The address passed is that of the actual branch, so patch in the LR saver
+ * just before that.
+ */
+static int ftrace_setup_lr_saver(unsigned long addr)
+{
+	u32 old, new;
+
+	old = aarch64_insn_gen_nop();
+	/* "mov x9, lr" is officially aliased from "orr x9, xzr, lr". */
+	new = aarch64_insn_gen_logical_shifted_reg(AARCH64_INSN_REG_9,
+		AARCH64_INSN_REG_ZR, AARCH64_INSN_REG_LR, 0,
+		AARCH64_INSN_VARIANT_64BIT, AARCH64_INSN_LOGIC_ORR);
+	return ftrace_modify_code(addr - AARCH64_INSN_SIZE, old, new, true);
+}
+#endif
+
 /*
  * Turn off the call to ftrace_caller() in instrumented function
  */
@@ -144,6 +199,16 @@ int ftrace_make_nop(struct module *mod,
 	u32 old = 0, new;
 	long offset = (long)pc - (long)addr;
 
+	/*
+	 * -fpatchable-function-entry= does not generate a profiling call
+	 *  initially; the NOPs are already there. So instead,
+	 *  put the LR saver there ahead of time, in order to avoid
+	 *  any race condition over patching 2 instructions.
+	 */
+	if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) &&
+		addr == MCOUNT_ADDR)
+		return ftrace_setup_lr_saver(pc);
+
 	if (offset < -SZ_128M || offset >= SZ_128M) {
 #ifdef CONFIG_ARM64_MODULE_PLTS
 		u32 replaced;
--- a/arch/arm64/include/asm/module.h
+++ b/arch/arm64/include/asm/module.h
@@ -32,7 +32,8 @@ struct mod_arch_specific {
 	struct mod_plt_sec	init;
 
 	/* for CONFIG_DYNAMIC_FTRACE */
-	struct plt_entry 	*ftrace_trampoline;
+	struct plt_entry	*ftrace_trampolines;
+#define MOD_ARCH_NR_FTRACE_TRAMPOLINES	2
 };
 #endif
 
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -452,7 +452,7 @@ int module_finalize(const Elf_Ehdr *hdr,
 #ifdef CONFIG_ARM64_MODULE_PLTS
 		if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE) &&
 		    !strcmp(".text.ftrace_trampoline", secstrs + s->sh_name))
-			me->arch.ftrace_trampoline = (void *)s->sh_addr;
+			me->arch.ftrace_trampolines = (void *)s->sh_addr;
 #endif
 	}
 
--- a/arch/arm64/kernel/module-plts.c
+++ b/arch/arm64/kernel/module-plts.c
@@ -333,7 +333,8 @@ int module_frob_arch_sections(Elf_Ehdr *
 		tramp->sh_type = SHT_NOBITS;
 		tramp->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
 		tramp->sh_addralign = __alignof__(struct plt_entry);
-		tramp->sh_size = sizeof(struct plt_entry);
+		tramp->sh_size = MOD_ARCH_NR_FTRACE_TRAMPOLINES
+				 * sizeof(struct plt_entry);
 	}
 
 	return 0;

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH v8 5/5] arm64: use -fpatchable-function-entry if available
  2019-02-08 15:08 [PATCH v8 0/5] arm64: ftrace with regs Torsten Duwe
                   ` (3 preceding siblings ...)
  2019-02-08 15:10 ` [PATCH v8 4/5] arm64: implement ftrace with regs Torsten Duwe
@ 2019-02-08 15:10 ` Torsten Duwe
  2019-02-13 11:11 ` [PATCH v8 0/5] arm64: ftrace with regs Julien Thierry
  5 siblings, 0 replies; 29+ messages in thread
From: Torsten Duwe @ 2019-02-08 15:10 UTC (permalink / raw)
  To: Mark Rutland, Will Deacon, Catalin Marinas, Julien Thierry,
	Steven Rostedt, Josh Poimboeuf, Ingo Molnar, Ard Biesheuvel,
	Arnd Bergmann, AKASHI Takahiro, Amit Daniel Kachhap
  Cc: live-patching, linux-kernel, linux-arm-kernel

Test whether gcc supports -fpatchable-function-entry and use it to promote
DYNAMIC_FTRACE to DYNAMIC_FTRACE_WITH_REGS. Amend support for the new
object section that holds the locations (__patchable_function_entries) and
define a proper "notrace" attribute to switch it off.

Signed-off-by: Torsten Duwe <duwe@suse.de>

---
 arch/arm64/Kconfig                |    2 ++
 arch/arm64/Makefile               |    5 +++++
 include/asm-generic/vmlinux.lds.h |    1 +
 include/linux/compiler_types.h    |    2 ++
 kernel/module.c                   |    7 ++++++-
 5 files changed, 16 insertions(+), 1 deletion(-)
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -132,6 +132,8 @@ config ARM64
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_DYNAMIC_FTRACE
+	select HAVE_DYNAMIC_FTRACE_WITH_REGS \
+		if $(cc-option,-fpatchable-function-entry=2)
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_TRACER
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -89,6 +89,11 @@ ifeq ($(CONFIG_ARM64_MODULE_PLTS),y)
 KBUILD_LDFLAGS_MODULE	+= -T $(srctree)/arch/arm64/kernel/module.lds
 endif
 
+ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)
+  KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FENTRY
+  CC_FLAGS_FTRACE := -fpatchable-function-entry=2
+endif
+
 # Default value
 head-y		:= arch/arm64/kernel/head.o
 
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -113,6 +113,7 @@
 #define MCOUNT_REC()	. = ALIGN(8);				\
 			__start_mcount_loc = .;			\
 			KEEP(*(__mcount_loc))			\
+			KEEP(*(__patchable_function_entries))	\
 			__stop_mcount_loc = .;
 #else
 #define MCOUNT_REC()
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -112,6 +112,8 @@ struct ftrace_likely_data {
 
 #if defined(CC_USING_HOTPATCH)
 #define notrace			__attribute__((hotpatch(0, 0)))
+#elif defined(CC_USING_PATCHABLE_FENTRY)
+#define notrace			__attribute__((patchable_function_entry(0)))
 #else
 #define notrace			__attribute__((__no_instrument_function__))
 #endif
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3122,7 +3122,12 @@ static int find_module_sections(struct m
 #endif
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
 	/* sechdrs[0].sh_size is always zero */
-	mod->ftrace_callsites = section_objs(info, "__mcount_loc",
+	mod->ftrace_callsites = section_objs(info,
+#ifdef CC_USING_PATCHABLE_FENTRY
+					     "__patchable_function_entries",
+#else
+					     "__mcount_loc",
+#endif
 					     sizeof(*mod->ftrace_callsites),
 					     &mod->num_ftrace_callsites);
 #endif

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 1/5] arm64: replace -pg with CC_FLAGS_FTRACE in arm64 Makefiles
  2019-02-08 15:10 ` [PATCH v8 1/5] arm64: replace -pg with CC_FLAGS_FTRACE in arm64 Makefiles Torsten Duwe
@ 2019-02-11 11:53   ` Mark Rutland
  0 siblings, 0 replies; 29+ messages in thread
From: Mark Rutland @ 2019-02-11 11:53 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Josh Poimboeuf, Amit Daniel Kachhap, live-patching,
	linux-arm-kernel

On Fri, Feb 08, 2019 at 04:10:07PM +0100, Torsten Duwe wrote:
>   In preparation for arm64 supporting ftrace built on other compiler
>   options, let's have the arm64 makefiles remove the $(CC_FLAGS_FTRACE)
>   flags, whatever these may be, rather than assuming '-pg'.
> 
>   There should be no functional change as a result of this patch.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>

Thanks for splitting this out.

With the indentation removed from the commit text:

Reviewed-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

> 
> ---
>  arch/arm64/kernel/Makefile |    6 +++---
>  arch/arm64/lib/Makefile    |    2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
> --- a/arch/arm64/kernel/Makefile
> +++ b/arch/arm64/kernel/Makefile
> @@ -7,9 +7,9 @@ CPPFLAGS_vmlinux.lds	:= -DTEXT_OFFSET=$(
>  AFLAGS_head.o		:= -DTEXT_OFFSET=$(TEXT_OFFSET)
>  CFLAGS_armv8_deprecated.o := -I$(src)
>  
> -CFLAGS_REMOVE_ftrace.o = -pg
> -CFLAGS_REMOVE_insn.o = -pg
> -CFLAGS_REMOVE_return_address.o = -pg
> +CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
> +CFLAGS_REMOVE_insn.o = $(CC_FLAGS_FTRACE)
> +CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
>  
>  # Object file lists.
>  obj-y			:= debug-monitors.o entry.o irq.o fpsimd.o		\
> --- a/arch/arm64/lib/Makefile
> +++ b/arch/arm64/lib/Makefile
> @@ -24,7 +24,7 @@ CFLAGS_atomic_ll_sc.o	:= -ffixed-x1 -ffi
>  		   -fcall-saved-x10 -fcall-saved-x11 -fcall-saved-x12	\
>  		   -fcall-saved-x13 -fcall-saved-x14 -fcall-saved-x15	\
>  		   -fcall-saved-x18 -fomit-frame-pointer
> -CFLAGS_REMOVE_atomic_ll_sc.o := -pg
> +CFLAGS_REMOVE_atomic_ll_sc.o := $(CC_FLAGS_FTRACE)
>  GCOV_PROFILE_atomic_ll_sc.o	:= n
>  KASAN_SANITIZE_atomic_ll_sc.o	:= n
>  KCOV_INSTRUMENT_atomic_ll_sc.o	:= n

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile
  2019-02-08 15:10 ` [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile Torsten Duwe
@ 2019-02-11 11:55   ` Mark Rutland
  2019-02-11 11:56   ` Mark Rutland
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 29+ messages in thread
From: Mark Rutland @ 2019-02-11 11:55 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, live-patching,
	AKASHI Takahiro, Ingo Molnar, Alexander Potapenko,
	linux-arm-kernel, Josh Poimboeuf, Amit Daniel Kachhap,
	Andrey Ryabinin, kasan-dev, Dmitry Vyukov

On Fri, Feb 08, 2019 at 04:10:14PM +0100, Torsten Duwe wrote:
>   In preparation for arm64 supporting ftrace built on other compiler
>   options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
>   flags, whatever these may be, rather than assuming '-pg'.
> 
>   There should be no functional change as a result of this patch.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>

With the indentation removed from the commit text:

Reviewed-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> 
> ---
>  mm/kasan/Makefile |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> --- a/mm/kasan/Makefile
> +++ b/mm/kasan/Makefile
> @@ -5,8 +5,8 @@ UBSAN_SANITIZE_generic.o := n
>  UBSAN_SANITIZE_tags.o := n
>  KCOV_INSTRUMENT := n
>  
> -CFLAGS_REMOVE_common.o = -pg
> -CFLAGS_REMOVE_generic.o = -pg
> +CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)
> +CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE)
>  # Function splitter causes unnecessary splits in __asan_load1/__asan_store1
>  # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533
>  

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile
  2019-02-08 15:10 ` [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile Torsten Duwe
  2019-02-11 11:55   ` Mark Rutland
@ 2019-02-11 11:56   ` Mark Rutland
  2019-04-08 15:25   ` Mark Rutland
  2019-04-08 15:35   ` Andrey Ryabinin
  3 siblings, 0 replies; 29+ messages in thread
From: Mark Rutland @ 2019-02-11 11:56 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, live-patching,
	AKASHI Takahiro, Ingo Molnar, Alexander Potapenko,
	linux-arm-kernel, Josh Poimboeuf, Amit Daniel Kachhap,
	Andrey Ryabinin, kasan-dev, Dmitry Vyukov

On Fri, Feb 08, 2019 at 04:10:14PM +0100, Torsten Duwe wrote:
>   In preparation for arm64 supporting ftrace built on other compiler
>   options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
>   flags, whatever these may be, rather than assuming '-pg'.
> 
>   There should be no functional change as a result of this patch.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>

With the indentation removed from the commit text:

Reviewed-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> 
> ---
>  mm/kasan/Makefile |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> --- a/mm/kasan/Makefile
> +++ b/mm/kasan/Makefile
> @@ -5,8 +5,8 @@ UBSAN_SANITIZE_generic.o := n
>  UBSAN_SANITIZE_tags.o := n
>  KCOV_INSTRUMENT := n
>  
> -CFLAGS_REMOVE_common.o = -pg
> -CFLAGS_REMOVE_generic.o = -pg
> +CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)
> +CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE)
>  # Function splitter causes unnecessary splits in __asan_load1/__asan_store1
>  # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533
>  

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles
  2019-02-08 15:10 ` [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles Torsten Duwe
@ 2019-02-11 11:59   ` Mark Rutland
  2019-04-08 15:23   ` Mark Rutland
  1 sibling, 0 replies; 29+ messages in thread
From: Mark Rutland @ 2019-02-11 11:59 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: linux-efi, Arnd Bergmann, Julien Thierry, Catalin Marinas,
	Ard Biesheuvel, Will Deacon, linux-kernel, Steven Rostedt,
	AKASHI Takahiro, Ingo Molnar, Josh Poimboeuf,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

On Fri, Feb 08, 2019 at 04:10:11PM +0100, Torsten Duwe wrote:
>   In preparation for arm64 supporting ftrace built on other compiler
>   options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
>   flags, whatever these may be, rather than assuming '-pg'.
>   While at it, fix arm32 as well.
> 
>   There should be no functional change as a result of this patch.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>

With the indentation removed from the commit text:

Reviewed-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> 
> ---
>  drivers/firmware/efi/libstub/Makefile |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -16,9 +16,9 @@ cflags-$(CONFIG_X86)		+= -m$(BITS) -D__K
>  
>  # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly
>  # disable the stackleak plugin
> -cflags-$(CONFIG_ARM64)		:= $(subst -pg,,$(KBUILD_CFLAGS)) -fpie \
> -				   $(DISABLE_STACKLEAK_PLUGIN)
> -cflags-$(CONFIG_ARM)		:= $(subst -pg,,$(KBUILD_CFLAGS)) \
> +cflags-$(CONFIG_ARM64)		:= $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
> +				   -fpie $(DISABLE_STACKLEAK_PLUGIN)
> +cflags-$(CONFIG_ARM)		:= $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
>  				   -fno-builtin -fpic \
>  				   $(call cc-option,-mno-single-pic-base)
>  

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 4/5] arm64: implement ftrace with regs
  2019-02-08 15:10 ` [PATCH v8 4/5] arm64: implement ftrace with regs Torsten Duwe
@ 2019-02-13 10:30   ` Julien Thierry
  0 siblings, 0 replies; 29+ messages in thread
From: Julien Thierry @ 2019-02-13 10:30 UTC (permalink / raw)
  To: Torsten Duwe, Mark Rutland, Will Deacon, Catalin Marinas,
	Steven Rostedt, Josh Poimboeuf, Ingo Molnar, Ard Biesheuvel,
	Arnd Bergmann, AKASHI Takahiro, Amit Daniel Kachhap
  Cc: live-patching, linux-kernel, linux-arm-kernel

Hi Torsten,

On 08/02/2019 15:10, Torsten Duwe wrote:
> Implement ftrace with regs, based on the new gcc flag
> -fpatchable-function-entry (=2)
> 
> Now that gcc8 added 2 NOPs at the beginning of each function, replace
> the first NOP thus generated with a quick LR saver (move it to scratch
> reg x9), so the 2nd replacement insn, the call to ftrace, does not
> clobber the value. Ftrace will then generate the standard stack
> frames.
> 
> Note that patchable-function-entry in GCC disables IPA-RA, which means
> ABI register calling conventions are obeyed and scratch registers such
> as x9 are available.
> 
> Introduce and handle an ftrace_regs_trampoline for module PLTs, right
> after ftrace_trampoline in an ftrace_trampolines[2] array, and double
> the size of the corresponding special section.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>
> 
> ---
>  arch/arm64/include/asm/ftrace.h  |   16 ++++
>  arch/arm64/include/asm/module.h  |    3 
>  arch/arm64/kernel/entry-ftrace.S |  125 +++++++++++++++++++++++++++++++++++++--
>  arch/arm64/kernel/ftrace.c       |  117 ++++++++++++++++++++++++++++--------
>  arch/arm64/kernel/module-plts.c  |    3 
>  arch/arm64/kernel/module.c       |    2 
>  6 files changed, 231 insertions(+), 35 deletions(-)

[...]

> --- a/arch/arm64/include/asm/module.h
> +++ b/arch/arm64/include/asm/module.h
> @@ -32,7 +32,8 @@ struct mod_arch_specific {
>  	struct mod_plt_sec	init;
>  
>  	/* for CONFIG_DYNAMIC_FTRACE */
> -	struct plt_entry 	*ftrace_trampoline;
> +	struct plt_entry	*ftrace_trampolines;
> +#define MOD_ARCH_NR_FTRACE_TRAMPOLINES	2

Nit: I'd define this outside of the struct, just below
MODULE_ARCH_VERMAGIC, and use the prefix "MODULE_ARCH" instead of
"MOD_ARCH" as this seem to be already in use for a few other defines.

Otherwise things look good to me:

Reviewed-by: Julien Thierry <julien.thierry@arm.com>

Cheers,

-- 
Julien Thierry

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-02-08 15:08 [PATCH v8 0/5] arm64: ftrace with regs Torsten Duwe
                   ` (4 preceding siblings ...)
  2019-02-08 15:10 ` [PATCH v8 5/5] arm64: use -fpatchable-function-entry if available Torsten Duwe
@ 2019-02-13 11:11 ` Julien Thierry
  2019-03-11 11:49   ` Torsten Duwe
  5 siblings, 1 reply; 29+ messages in thread
From: Julien Thierry @ 2019-02-13 11:11 UTC (permalink / raw)
  To: Torsten Duwe, Mark Rutland, Will Deacon, Catalin Marinas,
	Steven Rostedt, Josh Poimboeuf, Ingo Molnar, Ard Biesheuvel,
	Arnd Bergmann, AKASHI Takahiro, Amit Daniel Kachhap
  Cc: live-patching, linux-kernel, linux-arm-kernel

Hi Torsten,

On 08/02/2019 15:08, Torsten Duwe wrote:
> Patch series v8, as discussed.
> The whole series applies cleanly on 5.0-rc5
> 

For this series:

Tested-by: Julien Thierry <julien.thierry@arm.com>

> ---
>  arch/arm64/Kconfig                    |    4 +
>  arch/arm64/Makefile                   |   10 ++
>  arch/arm64/include/asm/ftrace.h       |   16 ++++
>  arch/arm64/include/asm/module.h       |    3 
>  arch/arm64/kernel/Makefile            |   12 +--
>  arch/arm64/kernel/entry-ftrace.S      |  125 ++++++++++++++++++++++++++++++++--
>  arch/arm64/kernel/ftrace.c            |  117 ++++++++++++++++++++++++-------
>  arch/arm64/kernel/module-plts.c       |    3 
>  arch/arm64/kernel/module.c            |    2 
>  arch/arm64/lib/Makefile               |    4 -
>  drivers/firmware/efi/libstub/Makefile |   12 +--
>  include/asm-generic/vmlinux.lds.h     |    2 
>  include/linux/compiler_types.h        |    4 +
>  kernel/module.c                       |   14 +++
>  mm/kasan/Makefile                     |    8 +-
>  15 files changed, 281 insertions(+), 55 deletions(-)
> ---
> changes since v7:
> 
> * -pg -> $(CC_FLAGS_FTRACE) cleanup now split according to subtree
>   maintainership.
> 
> * REC_IP_BRANCH_OFFSET is gone, the functionality went into
>   ftrace_call_adjust(), where it belongs.
> 
> * MOV_X9_X30 macro is gone (why did we argue about its name anyway?);
>   it is only used once now in the initial ftrace_make_nop new helper
>   function ftrace_setup_lr_saver(), suggested by Julien.
> 
> * call site processing was missing for modules. Fixed.
> 
> changes since v6:
> 
> * change the stack layout once more; I hope I have it the "standard" way now.
>   And yes, it looks simpler and cleaner; thanks, Mark, for nagging.
> 
> * split out the independent Kconfig and Makefile changes
> 
> * fixed style issues
> 
> * s/fp/x29/g
> 
> * MCOUNT_ADDR is now merely a 64-bit magic, as this is totally sufficient.
> 
> * QUICK_LR_SAVE renamed back to MOV_X9_X30.
> 
> * place MOV_X9_X30 insns on bootup, and only flip b <-> nop at runtime
> 
> * graph tracer "ifdeffery" reshuffle
> 
> 	Torsten
>   
> 

-- 
Julien Thierry

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-02-13 11:11 ` [PATCH v8 0/5] arm64: ftrace with regs Julien Thierry
@ 2019-03-11 11:49   ` Torsten Duwe
  2019-03-11 12:18     ` Mark Rutland
  2019-04-08 15:36     ` Mark Rutland
  0 siblings, 2 replies; 29+ messages in thread
From: Torsten Duwe @ 2019-03-11 11:49 UTC (permalink / raw)
  To: Mark Rutland, Will Deacon, Catalin Marinas, Steven Rostedt
  Cc: Arnd Bergmann, Ard Biesheuvel, Julien Thierry, linux-kernel,
	AKASHI Takahiro, Ingo Molnar, Josh Poimboeuf,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

On Wed, Feb 13, 2019 at 11:11:04AM +0000, Julien Thierry wrote:
> Hi Torsten,
> 
> On 08/02/2019 15:08, Torsten Duwe wrote:
> > Patch series v8, as discussed.
> > The whole series applies cleanly on 5.0-rc5

So what's the status now? Besides debatable minor style
issues there were no more objections to v8. Would this
go through the ARM repo or via the ftrace repo?

	Torsten


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-03-11 11:49   ` Torsten Duwe
@ 2019-03-11 12:18     ` Mark Rutland
  2019-03-29 10:18       ` Torsten Duwe
  2019-04-08 15:36     ` Mark Rutland
  1 sibling, 1 reply; 29+ messages in thread
From: Mark Rutland @ 2019-03-11 12:18 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Josh Poimboeuf, Amit Daniel Kachhap, live-patching,
	linux-arm-kernel

Hi Torsten,

On Mon, Mar 11, 2019 at 12:49:46PM +0100, Torsten Duwe wrote:
> On Wed, Feb 13, 2019 at 11:11:04AM +0000, Julien Thierry wrote:
> > Hi Torsten,
> > 
> > On 08/02/2019 15:08, Torsten Duwe wrote:
> > > Patch series v8, as discussed.
> > > The whole series applies cleanly on 5.0-rc5
> 
> So what's the status now? Besides debatable minor style
> issues there were no more objections to v8. Would this
> go through the ARM repo or via the ftrace repo?

Sorry, I have some half-written review comments that I will clean up and
send shortly.

As commented on prior versions, I'd very much like to see the
MCOUNT_ADDR hack go, by teaching the core ftrace code to not assume that
an mcount symbol exists.

We should be able to do that by separating the notion of NOPing a patch
site from the notion of initializing it for the first time.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-03-11 12:18     ` Mark Rutland
@ 2019-03-29 10:18       ` Torsten Duwe
  0 siblings, 0 replies; 29+ messages in thread
From: Torsten Duwe @ 2019-03-29 10:18 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Arnd Bergmann, Ard Biesheuvel, Catalin Marinas, Julien Thierry,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Josh Poimboeuf, Amit Daniel Kachhap, live-patching,
	linux-arm-kernel

On Mon, Mar 11, 2019 at 12:18:05PM +0000, Mark Rutland wrote:
> Hi Torsten,
> 
> On Mon, Mar 11, 2019 at 12:49:46PM +0100, Torsten Duwe wrote:
> > On Wed, Feb 13, 2019 at 11:11:04AM +0000, Julien Thierry wrote:
> > > Hi Torsten,
> > > 
> > > On 08/02/2019 15:08, Torsten Duwe wrote:
> > > > Patch series v8, as discussed.
> > > > The whole series applies cleanly on 5.0-rc5
> > 
> > So what's the status now? Besides debatable minor style
> > issues there were no more objections to v8. Would this
> > go through the ARM repo or via the ftrace repo?
> 
> Sorry, I have some half-written review comments that I will clean up and
> send shortly.

Ping?

> As commented on prior versions, I'd very much like to see the
> MCOUNT_ADDR hack go, by teaching the core ftrace code to not assume that
> an mcount symbol exists.

> We should be able to do that by separating the notion of NOPing a patch
> site from the notion of initializing it for the first time.

This is generally a good idea, and would affect other architectures as well,
see arch/s390/kernel/ftrace.c ftrace_make_nop(...)

I propose to do this in a second round.

	Torsten

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles
  2019-02-08 15:10 ` [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles Torsten Duwe
  2019-02-11 11:59   ` Mark Rutland
@ 2019-04-08 15:23   ` Mark Rutland
  2019-04-08 20:49     ` Ard Biesheuvel
  1 sibling, 1 reply; 29+ messages in thread
From: Mark Rutland @ 2019-04-08 15:23 UTC (permalink / raw)
  To: Torsten Duwe, Ard Biesheuvel
  Cc: linux-efi, Arnd Bergmann, Julien Thierry, Catalin Marinas,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Josh Poimboeuf, Amit Daniel Kachhap, live-patching,
	linux-arm-kernel

On Fri, Feb 08, 2019 at 04:10:11PM +0100, Torsten Duwe wrote:
>   In preparation for arm64 supporting ftrace built on other compiler
>   options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
>   flags, whatever these may be, rather than assuming '-pg'.
>   While at it, fix arm32 as well.
> 
>   There should be no functional change as a result of this patch.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>

Ard, would you be happy if we were to take this via the arm64 tree?

Assuming so, can we have your ack?

Thanks,
Mark.

> 
> ---
>  drivers/firmware/efi/libstub/Makefile |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -16,9 +16,9 @@ cflags-$(CONFIG_X86)		+= -m$(BITS) -D__K
>  
>  # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly
>  # disable the stackleak plugin
> -cflags-$(CONFIG_ARM64)		:= $(subst -pg,,$(KBUILD_CFLAGS)) -fpie \
> -				   $(DISABLE_STACKLEAK_PLUGIN)
> -cflags-$(CONFIG_ARM)		:= $(subst -pg,,$(KBUILD_CFLAGS)) \
> +cflags-$(CONFIG_ARM64)		:= $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
> +				   -fpie $(DISABLE_STACKLEAK_PLUGIN)
> +cflags-$(CONFIG_ARM)		:= $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
>  				   -fno-builtin -fpic \
>  				   $(call cc-option,-mno-single-pic-base)
>  

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile
  2019-02-08 15:10 ` [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile Torsten Duwe
  2019-02-11 11:55   ` Mark Rutland
  2019-02-11 11:56   ` Mark Rutland
@ 2019-04-08 15:25   ` Mark Rutland
  2019-04-08 15:35   ` Andrey Ryabinin
  3 siblings, 0 replies; 29+ messages in thread
From: Mark Rutland @ 2019-04-08 15:25 UTC (permalink / raw)
  To: Torsten Duwe, Andrey Ryabinin
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Alexander Potapenko, linux-arm-kernel,
	Josh Poimboeuf, Amit Daniel Kachhap, live-patching, kasan-dev,
	Dmitry Vyukov

On Fri, Feb 08, 2019 at 04:10:14PM +0100, Torsten Duwe wrote:
>   In preparation for arm64 supporting ftrace built on other compiler
>   options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
>   flags, whatever these may be, rather than assuming '-pg'.
> 
>   There should be no functional change as a result of this patch.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>

Andrey, would you be happy if we were to take this via the arm64 tree?

Assuming so, could we please have your ack?

Thanks,
Mark.

> 
> ---
>  mm/kasan/Makefile |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> --- a/mm/kasan/Makefile
> +++ b/mm/kasan/Makefile
> @@ -5,8 +5,8 @@ UBSAN_SANITIZE_generic.o := n
>  UBSAN_SANITIZE_tags.o := n
>  KCOV_INSTRUMENT := n
>  
> -CFLAGS_REMOVE_common.o = -pg
> -CFLAGS_REMOVE_generic.o = -pg
> +CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)
> +CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE)
>  # Function splitter causes unnecessary splits in __asan_load1/__asan_store1
>  # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533
>  

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile
  2019-02-08 15:10 ` [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile Torsten Duwe
                     ` (2 preceding siblings ...)
  2019-04-08 15:25   ` Mark Rutland
@ 2019-04-08 15:35   ` Andrey Ryabinin
  3 siblings, 0 replies; 29+ messages in thread
From: Andrey Ryabinin @ 2019-04-08 15:35 UTC (permalink / raw)
  To: Torsten Duwe, Mark Rutland, Will Deacon, Catalin Marinas,
	Julien Thierry, Steven Rostedt, Josh Poimboeuf, Ingo Molnar,
	Ard Biesheuvel, Arnd Bergmann, AKASHI Takahiro,
	Alexander Potapenko, Dmitry Vyukov, Amit Daniel Kachhap
  Cc: live-patching, kasan-dev, linux-kernel, linux-arm-kernel



On 2/8/19 6:10 PM, Torsten Duwe wrote:
>   In preparation for arm64 supporting ftrace built on other compiler
>   options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
>   flags, whatever these may be, rather than assuming '-pg'.
> 
>   There should be no functional change as a result of this patch.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>
> 

Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-03-11 11:49   ` Torsten Duwe
  2019-03-11 12:18     ` Mark Rutland
@ 2019-04-08 15:36     ` Mark Rutland
  2019-04-09 17:52       ` Will Deacon
  1 sibling, 1 reply; 29+ messages in thread
From: Mark Rutland @ 2019-04-08 15:36 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Josh Poimboeuf, Amit Daniel Kachhap, live-patching,
	linux-arm-kernel

On Mon, Mar 11, 2019 at 12:49:46PM +0100, Torsten Duwe wrote:
> On Wed, Feb 13, 2019 at 11:11:04AM +0000, Julien Thierry wrote:
> > Hi Torsten,
> > 
> > On 08/02/2019 15:08, Torsten Duwe wrote:
> > > Patch series v8, as discussed.
> > > The whole series applies cleanly on 5.0-rc5
> 
> So what's the status now? Besides debatable minor style
> issues there were no more objections to v8. Would this
> go through the ARM repo or via the ftrace repo?

Sorry agains for the delay on this. I'm now back in the office and in
front of a computer daily, so I can spend a bit more time on this.

Regardless of anything else, I think that we should queue the first
three patches now. I've poked the relevant maintainers for their acks so
that those can be taken via the arm64 tree.

I'm happy to do the trivial cleanups on the last couple of patches (e.g.
s/lr/x30), and I'm actively looking at the API rework I requested.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles
  2019-04-08 15:23   ` Mark Rutland
@ 2019-04-08 20:49     ` Ard Biesheuvel
  0 siblings, 0 replies; 29+ messages in thread
From: Ard Biesheuvel @ 2019-04-08 20:49 UTC (permalink / raw)
  To: Mark Rutland
  Cc: linux-efi, Arnd Bergmann, Julien Thierry, Catalin Marinas,
	Will Deacon, Linux Kernel Mailing List, Steven Rostedt,
	AKASHI Takahiro, Ingo Molnar, Torsten Duwe, Josh Poimboeuf,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

On Mon, 8 Apr 2019 at 17:23, Mark Rutland <mark.rutland@arm.com> wrote:
>
> On Fri, Feb 08, 2019 at 04:10:11PM +0100, Torsten Duwe wrote:
> >   In preparation for arm64 supporting ftrace built on other compiler
> >   options, let's have makefiles remove the $(CC_FLAGS_FTRACE)
> >   flags, whatever these may be, rather than assuming '-pg'.
> >   While at it, fix arm32 as well.
> >
> >   There should be no functional change as a result of this patch.
> >
> > Signed-off-by: Torsten Duwe <duwe@suse.de>
>
> Ard, would you be happy if we were to take this via the arm64 tree?
>
> Assuming so, can we have your ack?
>

Sure

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-04-08 15:36     ` Mark Rutland
@ 2019-04-09 17:52       ` Will Deacon
  2019-07-10 12:27         ` Ruslan Bilovol
  0 siblings, 1 reply; 29+ messages in thread
From: Will Deacon @ 2019-04-09 17:52 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	linux-kernel, Steven Rostedt, AKASHI Takahiro, Ingo Molnar,
	Torsten Duwe, Josh Poimboeuf, Amit Daniel Kachhap, live-patching,
	linux-arm-kernel

On Mon, Apr 08, 2019 at 04:36:28PM +0100, Mark Rutland wrote:
> On Mon, Mar 11, 2019 at 12:49:46PM +0100, Torsten Duwe wrote:
> > On Wed, Feb 13, 2019 at 11:11:04AM +0000, Julien Thierry wrote:
> > > Hi Torsten,
> > > 
> > > On 08/02/2019 15:08, Torsten Duwe wrote:
> > > > Patch series v8, as discussed.
> > > > The whole series applies cleanly on 5.0-rc5
> > 
> > So what's the status now? Besides debatable minor style
> > issues there were no more objections to v8. Would this
> > go through the ARM repo or via the ftrace repo?
> 
> Sorry agains for the delay on this. I'm now back in the office and in
> front of a computer daily, so I can spend a bit more time on this.
> 
> Regardless of anything else, I think that we should queue the first
> three patches now. I've poked the relevant maintainers for their acks so
> that those can be taken via the arm64 tree.
> 
> I'm happy to do the trivial cleanups on the last couple of patches (e.g.
> s/lr/x30), and I'm actively looking at the API rework I requested.

Ok, I've picked up patches 1-3 and I'll wait for you to spin updates to the
last two.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-04-09 17:52       ` Will Deacon
@ 2019-07-10 12:27         ` Ruslan Bilovol
  2019-07-24 16:15           ` Mark Rutland
  0 siblings, 1 reply; 29+ messages in thread
From: Ruslan Bilovol @ 2019-07-10 12:27 UTC (permalink / raw)
  To: Will Deacon
  Cc: Mark Rutland, Arnd Bergmann, Julien Thierry, Catalin Marinas,
	Ard Biesheuvel, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Torsten Duwe, Josh Poimboeuf, Amit Daniel Kachhap,
	live-patching, linux-arm-kernel

On Tue, Apr 9, 2019 at 8:52 PM Will Deacon <will.deacon@arm.com> wrote:
>
> On Mon, Apr 08, 2019 at 04:36:28PM +0100, Mark Rutland wrote:
> > On Mon, Mar 11, 2019 at 12:49:46PM +0100, Torsten Duwe wrote:
> > > On Wed, Feb 13, 2019 at 11:11:04AM +0000, Julien Thierry wrote:
> > > > Hi Torsten,
> > > >
> > > > On 08/02/2019 15:08, Torsten Duwe wrote:
> > > > > Patch series v8, as discussed.
> > > > > The whole series applies cleanly on 5.0-rc5
> > >
> > > So what's the status now? Besides debatable minor style
> > > issues there were no more objections to v8. Would this
> > > go through the ARM repo or via the ftrace repo?
> >
> > Sorry agains for the delay on this. I'm now back in the office and in
> > front of a computer daily, so I can spend a bit more time on this.
> >
> > Regardless of anything else, I think that we should queue the first
> > three patches now. I've poked the relevant maintainers for their acks so
> > that those can be taken via the arm64 tree.
> >
> > I'm happy to do the trivial cleanups on the last couple of patches (e.g.
> > s/lr/x30), and I'm actively looking at the API rework I requested.
>
> Ok, I've picked up patches 1-3 and I'll wait for you to spin updates to the
> last two.

Ok, I see that patches 1-3 are picked up and are already present in recent
kernels.

Is there any progress on remaining two patches?
Any help required?

Thanks,
Ruslan

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-07-10 12:27         ` Ruslan Bilovol
@ 2019-07-24 16:15           ` Mark Rutland
  2019-10-16 11:42             ` Jiri Kosina
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Rutland @ 2019-07-24 16:15 UTC (permalink / raw)
  To: Ruslan Bilovol
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Torsten Duwe, Josh Poimboeuf, Amit Daniel Kachhap,
	live-patching, linux-arm-kernel

Hi Ruslan,

On Wed, Jul 10, 2019 at 03:27:58PM +0300, Ruslan Bilovol wrote:
> On Tue, Apr 9, 2019 at 8:52 PM Will Deacon <will.deacon@arm.com> wrote:
> >
> > On Mon, Apr 08, 2019 at 04:36:28PM +0100, Mark Rutland wrote:
> > > On Mon, Mar 11, 2019 at 12:49:46PM +0100, Torsten Duwe wrote:
> > > > On Wed, Feb 13, 2019 at 11:11:04AM +0000, Julien Thierry wrote:
> > > > > Hi Torsten,
> > > > >
> > > > > On 08/02/2019 15:08, Torsten Duwe wrote:
> > > > > > Patch series v8, as discussed.
> > > > > > The whole series applies cleanly on 5.0-rc5
> > > >
> > > > So what's the status now? Besides debatable minor style
> > > > issues there were no more objections to v8. Would this
> > > > go through the ARM repo or via the ftrace repo?
> > >
> > > Sorry agains for the delay on this. I'm now back in the office and in
> > > front of a computer daily, so I can spend a bit more time on this.
> > >
> > > Regardless of anything else, I think that we should queue the first
> > > three patches now. I've poked the relevant maintainers for their acks so
> > > that those can be taken via the arm64 tree.
> > >
> > > I'm happy to do the trivial cleanups on the last couple of patches (e.g.
> > > s/lr/x30), and I'm actively looking at the API rework I requested.
> >
> > Ok, I've picked up patches 1-3 and I'll wait for you to spin updates to the
> > last two.
> 
> Ok, I see that patches 1-3 are picked up and are already present in recent
> kernels.
> 
> Is there any progress on remaining two patches?

I'm afraid that I've been distracted on other fronts, so I haven't made
progress there.

> Any help required?

If you'd be happy to look at the cleanup I previously suggested for the
core, that would be great. When I last looked, it was simple to rework
things so that arch code doesn't have to define MCOUNT_ADDR, but I
hadn't figured out exactly how to split the core mcount assumptions from
the important state machine bits.

I'll take another look and see if I can provide more detail. :)

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-07-24 16:15           ` Mark Rutland
@ 2019-10-16 11:42             ` Jiri Kosina
  2019-10-16 17:58               ` Mark Rutland
  0 siblings, 1 reply; 29+ messages in thread
From: Jiri Kosina @ 2019-10-16 11:42 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Torsten Duwe, Ruslan Bilovol, Josh Poimboeuf,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

On Wed, 24 Jul 2019, Mark Rutland wrote:

> > > > > So what's the status now? Besides debatable minor style
> > > > > issues there were no more objections to v8. Would this
> > > > > go through the ARM repo or via the ftrace repo?
> > > >
> > > > Sorry agains for the delay on this. I'm now back in the office and in
> > > > front of a computer daily, so I can spend a bit more time on this.
> > > >
> > > > Regardless of anything else, I think that we should queue the first
> > > > three patches now. I've poked the relevant maintainers for their acks so
> > > > that those can be taken via the arm64 tree.
> > > >
> > > > I'm happy to do the trivial cleanups on the last couple of patches (e.g.
> > > > s/lr/x30), and I'm actively looking at the API rework I requested.
> > >
> > > Ok, I've picked up patches 1-3 and I'll wait for you to spin updates to the
> > > last two.
> > 
> > Ok, I see that patches 1-3 are picked up and are already present in recent
> > kernels.
> > 
> > Is there any progress on remaining two patches?
> 
> I'm afraid that I've been distracted on other fronts, so I haven't made
> progress there.
> 
> > Any help required?
> 
> If you'd be happy to look at the cleanup I previously suggested for the
> core, that would be great. When I last looked, it was simple to rework
> things so that arch code doesn't have to define MCOUNT_ADDR, but I
> hadn't figured out exactly how to split the core mcount assumptions from
> the important state machine bits.
> 
> I'll take another look and see if I can provide more detail. :)

Hi Mark,

has any progress been made on any front? Feels like this got stuck a bit.

Thanks,

-- 
Jiri Kosina
SUSE Labs


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-10-16 11:42             ` Jiri Kosina
@ 2019-10-16 17:58               ` Mark Rutland
  2019-10-18 17:41                 ` Mark Rutland
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Rutland @ 2019-10-16 17:58 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Arnd Bergmann, Julien Thierry, Catalin Marinas, Ard Biesheuvel,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Torsten Duwe, Ruslan Bilovol, Josh Poimboeuf,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

On Wed, Oct 16, 2019 at 01:42:59PM +0200, Jiri Kosina wrote:
> On Wed, 24 Jul 2019, Mark Rutland wrote:
> 
> > > > > > So what's the status now? Besides debatable minor style
> > > > > > issues there were no more objections to v8. Would this
> > > > > > go through the ARM repo or via the ftrace repo?
> > > > >
> > > > > Sorry agains for the delay on this. I'm now back in the office and in
> > > > > front of a computer daily, so I can spend a bit more time on this.
> > > > >
> > > > > Regardless of anything else, I think that we should queue the first
> > > > > three patches now. I've poked the relevant maintainers for their acks so
> > > > > that those can be taken via the arm64 tree.
> > > > >
> > > > > I'm happy to do the trivial cleanups on the last couple of patches (e.g.
> > > > > s/lr/x30), and I'm actively looking at the API rework I requested.
> > > >
> > > > Ok, I've picked up patches 1-3 and I'll wait for you to spin updates to the
> > > > last two.
> > > 
> > > Ok, I see that patches 1-3 are picked up and are already present in recent
> > > kernels.
> > > 
> > > Is there any progress on remaining two patches?
> > 
> > I'm afraid that I've been distracted on other fronts, so I haven't made
> > progress there.
> > 
> > > Any help required?
> > 
> > If you'd be happy to look at the cleanup I previously suggested for the
> > core, that would be great. When I last looked, it was simple to rework
> > things so that arch code doesn't have to define MCOUNT_ADDR, but I
> > hadn't figured out exactly how to split the core mcount assumptions from
> > the important state machine bits.
> > 
> > I'll take another look and see if I can provide more detail. :)
> 
> Hi Mark,

Hi Jiri,

> has any progress been made on any front? Feels like this got stuck a bit.

Sorry about this; I've been a bit distracted.

I've just done the core (non-arm64) bits today, and pushed that out:

  https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=arm64/ftrace-with-regs

... I'll fold the remainging bits of patches 4 and 5 together tomorrow
atop of that.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-10-16 17:58               ` Mark Rutland
@ 2019-10-18 17:41                 ` Mark Rutland
  2019-10-19 11:01                   ` Torsten Duwe
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Rutland @ 2019-10-18 17:41 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Arnd Bergmann, Ard Biesheuvel, Catalin Marinas, Julien Thierry,
	Will Deacon, linux-kernel, Steven Rostedt, AKASHI Takahiro,
	Ingo Molnar, Torsten Duwe, Ruslan Bilovol, Josh Poimboeuf,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

On Wed, Oct 16, 2019 at 06:58:42PM +0100, Mark Rutland wrote:
> I've just done the core (non-arm64) bits today, and pushed that out:
> 
>   https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=arm64/ftrace-with-regs
> 
> ... I'll fold the remainging bits of patches 4 and 5 together tomorrow
> atop of that.

I've just force-pushed an updated version with the actual arm64
FTRACE_WITH_REGS bits. There are a couple of bits I still need to
verify, but I'm hoping that I can send this out for real next week.

In the process of reworking this I spotted some issues that will get in
the way of livepatching. Notably:

* When modules can be loaded far away from the kernel, we'll potentially
  need a PLT for each function within a module, if each can be patched
  to a unique function. Currently we have a fixed number, which is only
  sufficient for the two ftrace entry trampolines.

  IIUC, the new code being patched in is itself a module, in which case
  we'd need a PLT for each function in the main kernel image.

  We have a few options here, e.g. changing which memory size model we
  use, or reserving space for a PLT before each function using
  -f patchable-function-entry=N,M.

* There are windows where backtracing will miss the callsite's caller,
  as its address is not live in the LR or existing chain of frame
  records. Thus we cannot claim to have a reliable stacktrace.

  I suspect we'll have to teach the stacktrace code to handle this as a
  special-case.

  I'll try to write these up, as similar probably applies to other
  architectures with a link register.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-10-18 17:41                 ` Mark Rutland
@ 2019-10-19 11:01                   ` Torsten Duwe
  2019-10-21 11:37                     ` Mark Rutland
  2019-10-21 13:20                     ` Josh Poimboeuf
  0 siblings, 2 replies; 29+ messages in thread
From: Torsten Duwe @ 2019-10-19 11:01 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Julien Thierry, Arnd Bergmann, Ard Biesheuvel, Catalin Marinas,
	Jiri Kosina, Will Deacon, linux-kernel, Steven Rostedt,
	AKASHI Takahiro, Ingo Molnar, Ruslan Bilovol, Josh Poimboeuf,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

Hi Mark!

On Fri, 18 Oct 2019 18:41:02 +0100 Mark Rutland
<mark.rutland@arm.com> wrote:

> In the process of reworking this I spotted some issues that will get
> in the way of livepatching. Notably:
> 
> * When modules can be loaded far away from the kernel, we'll
> potentially need a PLT for each function within a module, if each can
> be patched to a unique function. Currently we have a fixed number,
> which is only sufficient for the two ftrace entry trampolines.
> 
>   IIUC, the new code being patched in is itself a module, in which
> case we'd need a PLT for each function in the main kernel image.

When no live patching is involved, obviously all cases need to have
been handled so far. And when a live patching module comes in, there
are calls in and out of the new patch code:

Calls going into the live patch are not aware of this. They are caught
by an active ftrace intercept, and the actual call into the LP module
is done in klp_arch_set_pc, by manipulating the intercept (call site)
return address (in case thread lives in the "new world", for
completeness' sake). This is an unsigned long write in C.

All calls going _out_ from the KLP module are newly generated, as part
of the KLP module building process, and are thus aware of them being
"extern" -- a PLT entry should be generated and accounted for in the
KLP module.

>   We have a few options here, e.g. changing which memory size model we
>   use, or reserving space for a PLT before each function using
>   -f patchable-function-entry=N,M.

Nonetheless I'm happy I once added the ,M option here. You never know :)

> * There are windows where backtracing will miss the callsite's caller,
>   as its address is not live in the LR or existing chain of frame
>   records. Thus we cannot claim to have a reliable stacktrace.
> 
>   I suspect we'll have to teach the stacktrace code to handle this as
> a special-case.

Yes, that's where I had to step back. The unwinder needs to stop where
the chain is even questionable. In _all_ cases. Missing only one race
condition means a lurking inconsistency.

OTOH it's not a problem to report "not reliable" when in doubt; the
thread in question will then get woken up and unwind itself.
It is only an optimisation to let all kernel threads which are
guaranteed to not contain any patched functions sleep on.

>   I'll try to write these up, as similar probably applies to other
>   architectures with a link register.

I thought I'd quickly give you my feedback upfront here.

	Torsten


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-10-19 11:01                   ` Torsten Duwe
@ 2019-10-21 11:37                     ` Mark Rutland
  2019-10-21 13:20                     ` Josh Poimboeuf
  1 sibling, 0 replies; 29+ messages in thread
From: Mark Rutland @ 2019-10-21 11:37 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Julien Thierry, Arnd Bergmann, Ard Biesheuvel, Catalin Marinas,
	Jiri Kosina, Will Deacon, linux-kernel, Steven Rostedt,
	AKASHI Takahiro, Ingo Molnar, Ruslan Bilovol, Josh Poimboeuf,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

On Sat, Oct 19, 2019 at 01:01:35PM +0200, Torsten Duwe wrote:
> Hi Mark!

Hi Torsten!
 
> On Fri, 18 Oct 2019 18:41:02 +0100 Mark Rutland
> <mark.rutland@arm.com> wrote:
> 
> > In the process of reworking this I spotted some issues that will get
> > in the way of livepatching. Notably:
> > 
> > * When modules can be loaded far away from the kernel, we'll
> > potentially need a PLT for each function within a module, if each can
> > be patched to a unique function. Currently we have a fixed number,
> > which is only sufficient for the two ftrace entry trampolines.
> > 
> >   IIUC, the new code being patched in is itself a module, in which
> > case we'd need a PLT for each function in the main kernel image.
> 
> When no live patching is involved, obviously all cases need to have
> been handled so far. And when a live patching module comes in, there
> are calls in and out of the new patch code:
> 
> Calls going into the live patch are not aware of this. They are caught
> by an active ftrace intercept, and the actual call into the LP module
> is done in klp_arch_set_pc, by manipulating the intercept (call site)
> return address (in case thread lives in the "new world", for
> completeness' sake). This is an unsigned long write in C.

I was under the impression that (at some point) the patch site would be
patched to call the LP code directly. From the above I understand that's
not the case, and it will always be directed via the regular ftrace
entry code -- have I got that right?

Assuming that is the case, that sounds fine to me, and sorry for the
noise.

> All calls going _out_ from the KLP module are newly generated, as part
> of the KLP module building process, and are thus aware of them being
> "extern" -- a PLT entry should be generated and accounted for in the
> KLP module.

Yup; understood.

> >   We have a few options here, e.g. changing which memory size model we
> >   use, or reserving space for a PLT before each function using
> >   -f patchable-function-entry=N,M.
> 
> Nonetheless I'm happy I once added the ,M option here. You never know :)

Yup; we may have other reasons to need this in future (and I see parisc
uses this today).

> > * There are windows where backtracing will miss the callsite's caller,
> >   as its address is not live in the LR or existing chain of frame
> >   records. Thus we cannot claim to have a reliable stacktrace.
> > 
> >   I suspect we'll have to teach the stacktrace code to handle this as
> > a special-case.
> 
> Yes, that's where I had to step back. The unwinder needs to stop where
> the chain is even questionable. In _all_ cases. Missing only one race
> condition means a lurking inconsistency.

Sure. I'm calling this out now so that we don't miss this in future.
I've added comments to the ftrace entry asm to this effect for now.

> OTOH it's not a problem to report "not reliable" when in doubt; the
> thread in question will then get woken up and unwind itself.
> It is only an optimisation to let all kernel threads which are
> guaranteed to not contain any patched functions sleep on.

I just want to make it clear that some care will be needed if/when
adding CONFIG_HAVE_RELIABLE_STACKTRACE so that we handle this case
correctly.
 
> >   I'll try to write these up, as similar probably applies to other
> >   architectures with a link register.
> 
> I thought I'd quickly give you my feedback upfront here.

Thanks; it's much appreciated!

Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v8 0/5] arm64: ftrace with regs
  2019-10-19 11:01                   ` Torsten Duwe
  2019-10-21 11:37                     ` Mark Rutland
@ 2019-10-21 13:20                     ` Josh Poimboeuf
  1 sibling, 0 replies; 29+ messages in thread
From: Josh Poimboeuf @ 2019-10-21 13:20 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Mark Rutland, Julien Thierry, Arnd Bergmann, Ard Biesheuvel,
	Catalin Marinas, Jiri Kosina, Will Deacon, linux-kernel,
	Steven Rostedt, AKASHI Takahiro, Ingo Molnar, Ruslan Bilovol,
	Amit Daniel Kachhap, live-patching, linux-arm-kernel

On Sat, Oct 19, 2019 at 01:01:35PM +0200, Torsten Duwe wrote:
> All calls going _out_ from the KLP module are newly generated, as part
> of the KLP module building process, and are thus aware of them being
> "extern" -- a PLT entry should be generated and accounted for in the
> KLP module.

Hm... for kpatch-build I assume we may need a GCC plugin to convert
local calls to global somehow?

-- 
Josh


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2019-10-21 13:21 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-08 15:08 [PATCH v8 0/5] arm64: ftrace with regs Torsten Duwe
2019-02-08 15:10 ` [PATCH v8 1/5] arm64: replace -pg with CC_FLAGS_FTRACE in arm64 Makefiles Torsten Duwe
2019-02-11 11:53   ` Mark Rutland
2019-02-08 15:10 ` [PATCH v8 2/5] arm64: replace -pg with CC_FLAGS_FTRACE in efi Makefiles Torsten Duwe
2019-02-11 11:59   ` Mark Rutland
2019-04-08 15:23   ` Mark Rutland
2019-04-08 20:49     ` Ard Biesheuvel
2019-02-08 15:10 ` [PATCH v8 3/5] arm64: replace -pg with CC_FLAGS_FTRACE in mm/kasan Makefile Torsten Duwe
2019-02-11 11:55   ` Mark Rutland
2019-02-11 11:56   ` Mark Rutland
2019-04-08 15:25   ` Mark Rutland
2019-04-08 15:35   ` Andrey Ryabinin
2019-02-08 15:10 ` [PATCH v8 4/5] arm64: implement ftrace with regs Torsten Duwe
2019-02-13 10:30   ` Julien Thierry
2019-02-08 15:10 ` [PATCH v8 5/5] arm64: use -fpatchable-function-entry if available Torsten Duwe
2019-02-13 11:11 ` [PATCH v8 0/5] arm64: ftrace with regs Julien Thierry
2019-03-11 11:49   ` Torsten Duwe
2019-03-11 12:18     ` Mark Rutland
2019-03-29 10:18       ` Torsten Duwe
2019-04-08 15:36     ` Mark Rutland
2019-04-09 17:52       ` Will Deacon
2019-07-10 12:27         ` Ruslan Bilovol
2019-07-24 16:15           ` Mark Rutland
2019-10-16 11:42             ` Jiri Kosina
2019-10-16 17:58               ` Mark Rutland
2019-10-18 17:41                 ` Mark Rutland
2019-10-19 11:01                   ` Torsten Duwe
2019-10-21 11:37                     ` Mark Rutland
2019-10-21 13:20                     ` Josh Poimboeuf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).