Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1331373 > unrolled thread
| Started by | Torsten Duwe <duwe@lst.de> |
|---|---|
| First post | 2016-02-10 18:50 +0100 |
| Last post | 2016-02-11 09:40 +0100 |
| Articles | 5 on this page of 25 — 7 participants |
Back to article view | Back to linux.kernel
[PATCH v8 0/8] ftrace with regs + live patching for ppc64 LE (ABI v2) Torsten Duwe <duwe@lst.de> - 2016-02-10 18:50 +0100
[PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Torsten Duwe <duwe@lst.de> - 2016-02-10 18:50 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Balbir Singh <bsingharora@gmail.com> - 2016-02-11 08:50 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> - 2016-02-11 09:50 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Balbir Singh <bsingharora@gmail.com> - 2016-02-11 10:40 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Murali Sampath <MSampath@alphion.com> - 2016-02-11 14:10 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Murali Sampath <MSampath@alphion.com> - 2016-02-11 14:10 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Torsten Duwe <duwe@lst.de> - 2016-02-11 09:50 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Balbir Singh <bsingharora@gmail.com> - 2016-02-11 10:40 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Michael Ellerman <mpe@ellerman.id.au> - 2016-02-15 11:30 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Jiri Kosina <jikos@kernel.org> - 2016-02-15 14:00 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Torsten Duwe <duwe@lst.de> - 2016-02-15 15:10 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Torsten Duwe <duwe@lst.de> - 2016-02-15 23:30 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Balbir Singh <bsingharora@gmail.com> - 2016-02-16 06:00 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Michael Ellerman <mpe@ellerman.id.au> - 2016-02-16 11:20 +0100
Re: [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Torsten Duwe <duwe@lst.de> - 2016-02-16 11:40 +0100
[PATCH v8 3/8] ppc use ftrace_modify_all_code default Torsten Duwe <duwe@lst.de> - 2016-02-10 18:50 +0100
[PATCH v8 1/8] ppc64 (le): prepare for -mprofile-kernel Torsten Duwe <duwe@lst.de> - 2016-02-10 18:50 +0100
Re: [PATCH v8 1/8] ppc64 (le): prepare for -mprofile-kernel Michael Ellerman <mpe@ellerman.id.au> - 2016-02-17 12:00 +0100
Re: [PATCH v8 1/8] ppc64 (le): prepare for -mprofile-kernel Michael Ellerman <mpe@ellerman.id.au> - 2016-02-17 12:40 +0100
Re: [PATCH v8 1/8] ppc64 (le): prepare for -mprofile-kernel Torsten Duwe <duwe@lst.de> - 2016-02-17 12:40 +0100
[PATCH v8 6/8] Implement kernel live patching for ppc64le (ABIv2) Torsten Duwe <duwe@lst.de> - 2016-02-10 18:50 +0100
Re: [PATCH v8 6/8] Implement kernel live patching for ppc64le (ABIv2) Miroslav Benes <mbenes@suse.cz> - 2016-02-11 10:10 +0100
Re: [PATCH v8 0/8] ftrace with regs + live patching for ppc64 LE (ABI v2) Balbir Singh <bsingharora@gmail.com> - 2016-02-11 07:20 +0100
Re: [PATCH v8 0/8] ftrace with regs + live patching for ppc64 LE (ABI v2) Torsten Duwe <duwe@lst.de> - 2016-02-11 09:40 +0100
Page 2 of 2 — ← Prev page 1 [2]
| From | Torsten Duwe <duwe@lst.de> |
|---|---|
| Date | 2016-02-17 12:40 +0100 |
| Subject | Re: [PATCH v8 1/8] ppc64 (le): prepare for -mprofile-kernel |
| Message-ID | <r38CC-5Js-7@gated-at.bofh.it> |
| In reply to | #1336248 |
On Wed, Feb 17, 2016 at 09:55:40PM +1100, Michael Ellerman wrote:
> On Wed, 2016-02-10 at 17:21 +0100, Torsten Duwe wrote:
>
> > --- a/arch/powerpc/kernel/module_64.c
> > +++ b/arch/powerpc/kernel/module_64.c
> > @@ -476,17 +474,44 @@ static unsigned long stub_for_addr(Elf64_Shdr *sechdrs,
> > return (unsigned long)&stubs[i];
> > }
> >
> > +#ifdef CC_USING_MPROFILE_KERNEL
> > +static int is_early_mcount_callsite(u32 *instruction)
> > +{
> > + /* -mprofile-kernel sequence starting with
> > + * mflr r0 and maybe std r0, LRSAVE(r1).
> > + */
> > + if ((instruction[-3] == PPC_INST_MFLR &&
> > + instruction[-2] == PPC_INST_STD_LR) ||
> > + instruction[-2] == PPC_INST_MFLR) {
> > + /* Nothing to be done here, it's an _mcount
> > + * call location and r2 will have to be
> > + * restored in the _mcount function.
> > + */
> > + return 1;
> > + }
> > + return 0;
> > +}
>
> On a kernel built with the 2 instruction version this will fault when the
> function we're looking at is located at the beginning of a page. Because
> instruction[-3] goes off the front of the mapping.
>
> We can probably fix that. But it's still a bit dicey.
Not necessarily. Now that it's a separate function, it can be nested a bit deeper,
so we don't take chances on compiler optimisation:
if (instruction[-2] == PPC_INST_STD_LR) /* where should R0 come from? there must be... */
{
if (instruction[-3] == PPC_INST_MFLR)
return 1;
}
else if (instruction[-2] == PPC_INST_MFLR)
return 1;
return 0;
> I'm wondering if we want to just say we only support the 2 instruction version.
> Currently that means GCC 6 only, or a distro compiler with the backport of
> e95d0248dace. But we could also ask GCC to backport it to 4.9 and 5.
>
> Thoughts?
IMHO that's a too weak reason for a too strong limitation. OTOH getting everyone
to use the 2 insn version sounds appealing...
Is e95d0248dace self-sufficient or does it depend on other improvements?
Torsten
[toc] | [prev] | [next] | [standalone]
| From | Torsten Duwe <duwe@lst.de> |
|---|---|
| Date | 2016-02-10 18:50 +0100 |
| Subject | [PATCH v8 6/8] Implement kernel live patching for ppc64le (ABIv2) |
| Message-ID | <r0H3S-5r5-47@gated-at.bofh.it> |
| In reply to | #1331373 |
* create the appropriate files+functions
arch/powerpc/include/asm/livepatch.h
klp_check_compiler_support,
klp_arch_set_pc
arch/powerpc/kernel/livepatch.c with a stub for
klp_write_module_reloc
This is architecture-independent work in progress.
* introduce a fixup in arch/powerpc/kernel/entry_64.S
for local calls that are becoming global due to live patching.
And of course do the main KLP thing: return to a maybe different
address, possibly altered by the live patching ftrace op.
Signed-off-by: Torsten Duwe <duwe@suse.de>
---
arch/powerpc/include/asm/livepatch.h | 45 +++++++++++++++++++++++++++++++
arch/powerpc/kernel/entry_64.S | 51 +++++++++++++++++++++++++++++++++---
arch/powerpc/kernel/livepatch.c | 38 +++++++++++++++++++++++++++
3 files changed, 130 insertions(+), 4 deletions(-)
create mode 100644 arch/powerpc/include/asm/livepatch.h
create mode 100644 arch/powerpc/kernel/livepatch.c
diff --git a/arch/powerpc/include/asm/livepatch.h b/arch/powerpc/include/asm/livepatch.h
new file mode 100644
index 0000000..44e8a2d
--- /dev/null
+++ b/arch/powerpc/include/asm/livepatch.h
@@ -0,0 +1,45 @@
+/*
+ * livepatch.h - powerpc-specific Kernel Live Patching Core
+ *
+ * Copyright (C) 2015 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_POWERPC64_LIVEPATCH_H
+#define _ASM_POWERPC64_LIVEPATCH_H
+
+#include <linux/module.h>
+#include <linux/ftrace.h>
+
+#ifdef CONFIG_LIVEPATCH
+static inline int klp_check_compiler_support(void)
+{
+#if !defined(_CALL_ELF) || _CALL_ELF != 2 || !defined(CC_USING_MPROFILE_KERNEL)
+ return 1;
+#endif
+ return 0;
+}
+
+extern int klp_write_module_reloc(struct module *mod, unsigned long type,
+ unsigned long loc, unsigned long value);
+
+static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip)
+{
+ regs->nip = ip;
+}
+#else
+#error Live patching support is disabled; check CONFIG_LIVEPATCH
+#endif
+
+#endif /* _ASM_POWERPC64_LIVEPATCH_H */
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index c063564..52c7a15 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -1202,6 +1202,9 @@ _GLOBAL(ftrace_caller)
mflr r3
std r3, _NIP(r1)
std r3, 16(r1)
+#ifdef CONFIG_LIVEPATCH
+ mr r14,r3 /* remember old NIP */
+#endif
subi r3, r3, MCOUNT_INSN_SIZE
mfmsr r4
std r4, _MSR(r1)
@@ -1218,7 +1221,10 @@ ftrace_call:
nop
ld r3, _NIP(r1)
- mtlr r3
+ mtctr r3 /* prepare to jump there */
+#ifdef CONFIG_LIVEPATCH
+ cmpd r14,r3 /* has NIP been altered? */
+#endif
REST_8GPRS(0,r1)
REST_8GPRS(8,r1)
@@ -1231,6 +1237,27 @@ ftrace_call:
mtlr r12
mr r2,r0 /* restore callee's TOC */
+#ifdef CONFIG_LIVEPATCH
+ beq+ 4f /* likely(old_NIP == new_NIP) */
+
+ /* For a local call, restore this TOC after calling the patch function.
+ * For a global call, it does not matter what we restore here,
+ * since the global caller does its own restore right afterwards,
+ * anyway. Just insert a KLP_return_helper frame in any case,
+ * so a patch function can always count on the changed stack offsets.
+ */
+ stdu r1,-32(r1) /* open new mini stack frame */
+ std r0,24(r1) /* save TOC now, unconditionally. */
+ bl 5f
+5: mflr r12
+ addi r12,r12,(KLP_return_helper+4-.)@l
+ std r12,LRSAVE(r1)
+ mtlr r12
+ mfctr r12 /* allow for TOC calculation in newfunc */
+ bctr
+4:
+#endif
+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
stdu r1, -112(r1)
.globl ftrace_graph_call
@@ -1240,15 +1267,31 @@ _GLOBAL(ftrace_graph_stub)
addi r1, r1, 112
#endif
- mflr r0 /* move this LR to CTR */
- mtctr r0
-
ld r0,LRSAVE(r1) /* restore callee's lr at _mcount site */
mtlr r0
bctr /* jump after _mcount site */
#endif /* CC_USING_MPROFILE_KERNEL */
_GLOBAL(ftrace_stub)
blr
+
+#ifdef CONFIG_LIVEPATCH
+/* Helper function for local calls that are becoming global
+ due to live patching.
+ We can't simply patch the NOP after the original call,
+ because, depending on the consistency model, some kernel
+ threads may still have called the original, local function
+ *without* saving their TOC in the respective stack frame slot,
+ so the decision is made per-thread during function return by
+ maybe inserting a KLP_return_helper frame or not.
+*/
+KLP_return_helper:
+ ld r2,24(r1) /* restore TOC (saved by ftrace_caller) */
+ addi r1, r1, 32 /* destroy mini stack frame */
+ ld r0,LRSAVE(r1) /* get the real return address */
+ mtlr r0
+ blr
+#endif
+
#else
_GLOBAL_TOC(_mcount)
/* Taken from output of objdump from lib64/glibc */
diff --git a/arch/powerpc/kernel/livepatch.c b/arch/powerpc/kernel/livepatch.c
new file mode 100644
index 0000000..cdd15f1
--- /dev/null
+++ b/arch/powerpc/kernel/livepatch.c
@@ -0,0 +1,38 @@
+/*
+ * livepatch.c - powerpc-specific Kernel Live Patching Core
+ *
+ * Copyright (C) 2015 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/>.
+ */
+#include <linux/module.h>
+#include <asm/livepatch.h>
+
+/**
+ * klp_write_module_reloc() - write a relocation in a module
+ * @mod: module in which the section to be modified is found
+ * @type: ELF relocation type (see asm/elf.h)
+ * @loc: address that the relocation should be written to
+ * @value: relocation value (sym address + addend)
+ *
+ * This function writes a relocation to the specified location for
+ * a particular module.
+ */
+int klp_write_module_reloc(struct module *mod, unsigned long type,
+ unsigned long loc, unsigned long value)
+{
+ /* This requires infrastructure changes; we need the loadinfos. */
+ pr_err("klp_write_module_reloc not yet supported\n");
+ return -ENOSYS;
+}
--
1.8.5.6
[toc] | [prev] | [next] | [standalone]
| From | Miroslav Benes <mbenes@suse.cz> |
|---|---|
| Date | 2016-02-11 10:10 +0100 |
| Subject | Re: [PATCH v8 6/8] Implement kernel live patching for ppc64le (ABIv2) |
| Message-ID | <r0Vqa-6Fe-13@gated-at.bofh.it> |
| In reply to | #1331382 |
On Wed, 10 Feb 2016, Torsten Duwe wrote:
> diff --git a/arch/powerpc/include/asm/livepatch.h b/arch/powerpc/include/asm/livepatch.h
> new file mode 100644
> index 0000000..44e8a2d
> --- /dev/null
> +++ b/arch/powerpc/include/asm/livepatch.h
> @@ -0,0 +1,45 @@
> +/*
> + * livepatch.h - powerpc-specific Kernel Live Patching Core
> + *
> + * Copyright (C) 2015 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_POWERPC64_LIVEPATCH_H
> +#define _ASM_POWERPC64_LIVEPATCH_H
> +
> +#include <linux/module.h>
> +#include <linux/ftrace.h>
> +
> +#ifdef CONFIG_LIVEPATCH
> +static inline int klp_check_compiler_support(void)
> +{
> +#if !defined(_CALL_ELF) || _CALL_ELF != 2 || !defined(CC_USING_MPROFILE_KERNEL)
> + return 1;
> +#endif
> + return 0;
> +}
> +
> +extern int klp_write_module_reloc(struct module *mod, unsigned long type,
> + unsigned long loc, unsigned long value);
It would be better to make this one static inline and move 'return
-ENOSYS;' here. Thus there would be no arch/powerpc/kernel/livepatch.c.
See s390 code for reference.
> +static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip)
> +{
> + regs->nip = ip;
> +}
> +#else
> +#error Live patching support is disabled; check CONFIG_LIVEPATCH
Change the error to
#error Include linux/livepatch.h, not asm/livepatch.h
please. See 383bf44d1a8b ("livepatch: change the error message in
asm/livepatch.h header files").
Thanks Torsten,
Miroslav
[toc] | [prev] | [next] | [standalone]
| From | Balbir Singh <bsingharora@gmail.com> |
|---|---|
| Date | 2016-02-11 07:20 +0100 |
| Subject | Re: [PATCH v8 0/8] ftrace with regs + live patching for ppc64 LE (ABI v2) |
| Message-ID | <r0SLE-4V0-1@gated-at.bofh.it> |
| In reply to | #1331373 |
On Wed, 2016-02-10 at 18:29 +0100, Torsten Duwe wrote: > Changes since V7: > * drop "notrace" attribute for MMU-aiding functions > and their callees. > * merge "-mprofile-kernel"-stripping patches into one. > > Changes since v6: > * include Petr's patch, on popular demand ;) > * move #ifdefs out of functions for readability; > introduce static helper functions instead. > * No more literal binary instructions in hex, > at least not added by this patch set. > * add compile time checker to detect the presence > of known-good -mprofile-kernel support. > * limit Kconfig / compile to the configurations really supported: > + (static) FTRACE with -pg > + DYNAMIC_FTRACE with -pg with or without -mprofile-kernel > (depending on the compiler) > + DYNAMIC_FTRACE_WITH_REGS only with -mprofile-kernel > (will error out if the compiler is broken) > > Changes since v5: > * extra "std r0,LRSAVE(r1)" for gcc-6 > This makes the code compiler-agnostic. > * Follow Petr Mladek's suggestion to avoid > redefinition of HAVE_LIVEPATCH > > Changes since v4: > * change comment style in entry_64.S to C89 > (nobody is using assembler syntax comments there). > * the bool function restore_r2 shouldn't return 2, > that's a little confusing. > * Test whether the compiler supports -mprofile-kernel > and only then define CC_USING_MPROFILE_KERNEL > * also make the return value of klp_check_compiler_support > depend on that. > > Major changes since v3: > * the graph tracer works now. > It turned out the stack frame it tried to manipulate does not > exist at that point. > * changes only needed in order to support -mprofile-kernel are now > in a separate patch, prepended. > * Kconfig cleanup so this is only selectable on ppc64le. > > Petr Mladek (1): > livepatch: Detect offset for the ftrace location during build > > Torsten Duwe (7): > ppc64 (le): prepare for -mprofile-kernel > ppc64le FTRACE_WITH_REGS implementation > ppc use ftrace_modify_all_code default > ppc64 ftrace_with_regs configuration variables > ppc64 ftrace_with_regs: disable profiling for some files > Implement kernel live patching for ppc64le (ABIv2) > Enable LIVEPATCH to be configured on ppc64le and add livepatch.o if it > is selected > > arch/powerpc/Kconfig | 6 + > arch/powerpc/Makefile | 17 +++ > arch/powerpc/gcc-mprofile-kernel-notrace.sh | 33 ++++++ > arch/powerpc/include/asm/code-patching.h | 24 ++++ > arch/powerpc/include/asm/ftrace.h | 5 + > arch/powerpc/include/asm/livepatch.h | 45 ++++++++ > arch/powerpc/kernel/Makefile | 13 ++- > arch/powerpc/kernel/entry_64.S | 169 > +++++++++++++++++++++++++++- > arch/powerpc/kernel/ftrace.c | 129 ++++++++++++++++----- > arch/powerpc/kernel/livepatch.c | 38 +++++++ > arch/powerpc/kernel/module_64.c | 56 ++++++++- > arch/powerpc/lib/Makefile | 4 +- > arch/s390/Kconfig | 1 + > kernel/livepatch/Makefile | 13 +++ > kernel/livepatch/core.c | 12 +- > kernel/livepatch/ftrace-test.c | 6 + > kernel/trace/Kconfig | 5 + > scripts/recordmcount.c | 6 +- > scripts/recordmcount.h | 17 ++- > 19 files changed, 552 insertions(+), 47 deletions(-) > create mode 100755 arch/powerpc/gcc-mprofile-kernel-notrace.sh > create mode 100644 arch/powerpc/include/asm/livepatch.h > create mode 100644 arch/powerpc/kernel/livepatch.c > create mode 100644 kernel/livepatch/ftrace-test.c > Quick question - I presume these apply on top of 4.5.0-rc2? Balbir Singh.
[toc] | [prev] | [next] | [standalone]
| From | Torsten Duwe <duwe@lst.de> |
|---|---|
| Date | 2016-02-11 09:40 +0100 |
| Subject | Re: [PATCH v8 0/8] ftrace with regs + live patching for ppc64 LE (ABI v2) |
| Message-ID | <r0UX7-6fo-3@gated-at.bofh.it> |
| In reply to | #1331705 |
On Thu, Feb 11, 2016 at 05:18:23PM +1100, Balbir Singh wrote: > > Quick question - I presume these apply on top of 4.5.0-rc2? Yes. Torsten
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | linux.kernel
csiph-web