Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1432115 > unrolled thread
| Started by | Torsten Duwe <duwe@lst.de> |
|---|---|
| First post | 2016-06-27 17:20 +0200 |
| Last post | 2016-06-27 17:20 +0200 |
| Articles | 2 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH v2 0/2] arm64 live patching Torsten Duwe <duwe@lst.de> - 2016-06-27 17:20 +0200
[PATCH v2 2/2] arm64: implement live patching Torsten Duwe <duwe@lst.de> - 2016-06-27 17:20 +0200
| From | Torsten Duwe <duwe@lst.de> |
|---|---|
| Date | 2016-06-27 17:20 +0200 |
| Subject | [PATCH v2 0/2] arm64 live patching |
| Message-ID | <rOGul-20Y-5@gated-at.bofh.it> |
So here is a slightly updated FTRACE_WITH_REGS plus live patching.
Reminder: make sure you have a prolog-pad gcc, and this in your
top level Makefile:
ifdef CONFIG_LIVEPATCH
KBUILD_CFLAGS += $(call cc-option,-fno-ipa-ra)
endif
Tested with v4.7-rc3 + gcc-6.1
Changes since v1:
* instead of a comment "should be CC_USING_PROLOG_PAD":
do it. CC_FLAGS_FTRACE holds it now, and the IPA
disabler has become a separate issue (see above).
Torsten Duwe (2):
arm64: implement FTRACE_WITH_REGS
arm64: implement live patching
arch/arm64/Kconfig | 4 ++
arch/arm64/Makefile | 4 ++
arch/arm64/include/asm/ftrace.h | 8 +++
arch/arm64/include/asm/livepatch.h | 37 ++++++++++++++
arch/arm64/kernel/Makefile | 6 +--
arch/arm64/kernel/entry-ftrace.S | 102 +++++++++++++++++++++++++++++++++++++
arch/arm64/kernel/ftrace.c | 43 ++++++++++++++--
include/asm-generic/vmlinux.lds.h | 2 +-
include/linux/compiler.h | 4 ++
9 files changed, 203 insertions(+), 7 deletions(-)
create mode 100644 arch/arm64/include/asm/livepatch.h
--
2.6.6
[toc] | [next] | [standalone]
| From | Torsten Duwe <duwe@lst.de> |
|---|---|
| Date | 2016-06-27 17:20 +0200 |
| Subject | [PATCH v2 2/2] arm64: implement live patching |
| Message-ID | <rOGul-20Y-13@gated-at.bofh.it> |
| In reply to | #1432115 |
On top of FTRACE_WITH_REGS and the klp changes that go into v4.7
this is straightforward.
Signed-off-by: Torsten Duwe <duwe@suse.de>
---
arch/arm64/Kconfig | 3 +++
arch/arm64/include/asm/livepatch.h | 37 +++++++++++++++++++++++++++++++++++++
arch/arm64/kernel/entry-ftrace.S | 13 +++++++++++++
3 files changed, 53 insertions(+)
create mode 100644 arch/arm64/include/asm/livepatch.h
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 36a0e26..cb5adf3 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -80,6 +80,7 @@ config ARM64
select HAVE_GENERIC_DMA_COHERENT
select HAVE_HW_BREAKPOINT if PERF_EVENTS
select HAVE_IRQ_TIME_ACCOUNTING
+ select HAVE_LIVEPATCH
select HAVE_MEMBLOCK
select HAVE_MEMBLOCK_NODE_MAP if NUMA
select HAVE_PATA_PLATFORM
@@ -1042,4 +1043,6 @@ if CRYPTO
source "arch/arm64/crypto/Kconfig"
endif
+source "kernel/livepatch/Kconfig"
+
source "lib/Kconfig"
diff --git a/arch/arm64/include/asm/livepatch.h b/arch/arm64/include/asm/livepatch.h
new file mode 100644
index 0000000..6b9a3d1
--- /dev/null
+++ b/arch/arm64/include/asm/livepatch.h
@@ -0,0 +1,37 @@
+/*
+ * livepatch.h - arm64-specific Kernel Live Patching Core
+ *
+ * Copyright (C) 2016 SUSE
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ASM_ARM64_LIVEPATCH_H
+#define _ASM_ARM64_LIVEPATCH_H
+
+#include <linux/module.h>
+#include <linux/ftrace.h>
+
+#ifdef CONFIG_LIVEPATCH
+static inline int klp_check_compiler_support(void)
+{
+ return 0;
+}
+
+static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip)
+{
+ regs->pc = ip;
+}
+#endif /* CONFIG_LIVEPATCH */
+
+#endif /* _ASM_ARM64_LIVEPATCH_H */
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index 3ebe791..b166cbf 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -204,6 +204,9 @@ ENTRY(ftrace_caller)
str x9, [sp, #S_LR]
/* The program counter just after the ftrace call site */
str lr, [sp, #S_PC]
+#if defined(CONFIG_LIVEPATCH) && defined(CONFIG_FUNCTION_GRAPH_TRACER)
+ mov x19,lr /* remember old return address */
+#endif
/* The stack pointer as it was on ftrace_caller entry... */
add x29, sp, #S_FRAME_SIZE+16 /* ...is also our new FP */
str x29, [sp, #S_SP]
@@ -219,6 +222,16 @@ ftrace_call:
bl ftrace_stub
+#if defined(CONFIG_LIVEPATCH) && defined(CONFIG_FUNCTION_GRAPH_TRACER)
+ /* Is the trace function a live patcher an has messed with
+ * the return address?
+ */
+ ldr x9, [sp, #S_PC]
+ cmp x9, x19 /* compare with the value we remembered */
+ /* to not call graph tracer's "call" mechanism twice! */
+ b.eq ftrace_regs_return
+#endif
+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
.global ftrace_graph_call
ftrace_graph_call: // ftrace_graph_caller();
--
2.6.6
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web