From: Torsten Duwe <duwe@lst.de>
To: Petr Mladek <pmladek@suse.com>
Cc: linuxppc-dev@ozlabs.org, Balbir Singh <bsingharora@gmail.com>,
linux-kernel@vger.kernel.org, rostedt@goodmis.org,
kamalesh@linux.vnet.ibm.com, jeyu@redhat.com, jkosina@suse.cz,
live-patching@vger.kernel.org, mbenes@suse.cz
Subject: Re: [PATCH][v4] livepatch/ppc: Enable livepatching on powerpc
Date: Fri, 4 Mar 2016 13:42:47 +0100 [thread overview]
Message-ID: <20160304124247.GA20914@lst.de> (raw)
In-Reply-To: <1457023921-2051-1-git-send-email-pmladek@suse.com>
On Thu, Mar 03, 2016 at 05:52:01PM +0100, Petr Mladek wrote:
[...]
> index ec7f8aada697..2d5333c228f1 100644
> --- a/arch/powerpc/kernel/entry_64.S
> +++ b/arch/powerpc/kernel/entry_64.S
> @@ -1265,6 +1271,31 @@ ftrace_call:
> ld r0, LRSAVE(r1)
> mtlr r0
>
> +#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.
> + * The patch introduces a frame such that from the patched function
> + * we return back to klp_return helper. For ABI compliance r12,
> + * lr and LRSAVE(r1) contain the address of klp_return_helper.
> + * We loaded ctr with the address of the patched function earlier
> + */
> + stdu r1, -32(r1) /* open new mini stack frame */
> + std r2, 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
> @@ -1281,6 +1312,25 @@ _GLOBAL(ftrace_graph_stub)
>
> _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 */
We need a caveat here, at least in the comments, even better
in some documentation, that the klp_return_helper shifts the stack layout.
This is relevant for functions with more than 8 fixed integer arguments
or for any varargs creator. As soon as the patch function is to replace
an original with arguments on the stack, the extra stack frame needs to
be accounted for.
Where shall we put this warning?
Torsten
next prev parent reply other threads:[~2016-03-04 12:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-03 16:52 [PATCH][v4] livepatch/ppc: Enable livepatching on powerpc Petr Mladek
2016-03-03 20:43 ` Balbir Singh
2016-03-04 6:08 ` Kamalesh Babulal
2016-03-04 7:58 ` Michael Ellerman
2016-03-04 9:31 ` Miroslav Benes
2016-03-07 3:29 ` Michael Ellerman
2016-03-04 8:06 ` How to merge? (was Re: [PATCH][v4] livepatch/ppc: Enable livepatching on powerpc) Michael Ellerman
2016-03-04 8:56 ` Jiri Kosina
2016-03-07 10:06 ` Michael Ellerman
2016-03-07 22:52 ` Jiri Kosina
2016-03-07 23:20 ` Michael Ellerman
2016-03-08 1:53 ` Steven Rostedt
2016-03-07 23:22 ` Josh Poimboeuf
2016-03-04 12:42 ` Torsten Duwe [this message]
2016-03-04 13:01 ` [PATCH][v4] livepatch/ppc: Enable livepatching on powerpc Petr Mladek
2016-03-04 18:16 ` Torsten Duwe
2016-03-04 19:22 ` Torsten Duwe
2016-03-08 11:14 ` Torsten Duwe
2016-03-06 23:55 ` Balbir Singh
2016-03-04 21:56 ` Josh Poimboeuf
2016-03-08 21:42 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160304124247.GA20914@lst.de \
--to=duwe@lst.de \
--cc=bsingharora@gmail.com \
--cc=jeyu@redhat.com \
--cc=jkosina@suse.cz \
--cc=kamalesh@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).