From: Jessica Yu <jeyu@redhat.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Seth Jennings <sjenning@redhat.com>,
Jiri Kosina <jikos@kernel.org>, Vojtech Pavlik <vojtech@suse.com>,
Miroslav Benes <mbenes@suse.cz>,
linux-api@vger.kernel.org, live-patching@vger.kernel.org,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: livepatch: reuse module loader code to write relocations
Date: Wed, 11 Nov 2015 13:27:18 -0500 [thread overview]
Message-ID: <20151111182718.GA30025@packer-debian-8-amd64.digitalocean.com> (raw)
In-Reply-To: <20151111152256.GP2599@pathway.suse.cz>
+++ Petr Mladek [11/11/15 16:22 +0100]:
>On Mon 2015-11-09 23:45:53, Jessica Yu wrote:
>> Reuse module loader code to write relocations, thereby eliminating the
>> need for architecture specific code in livepatch. Namely, we reuse
>> apply_relocate_add() in the module loader to write relocs instead of
>> duplicating functionality in livepatch's klp_write_module_reloc(). To
>> apply relocation sections, remaining SHN_LIVEPATCH symbols referenced by
>> relocs are resolved and then apply_relocate_add() is called to apply
>> those relocations.
>>
>> Signed-off-by: Jessica Yu <jeyu@redhat.com>
>> ---
>> include/linux/livepatch.h | 11 ++++--
>> include/linux/module.h | 6 ++++
>> kernel/livepatch/core.c | 89 +++++++++++++++++++++++++++++------------------
>> 3 files changed, 70 insertions(+), 36 deletions(-)
>>
>> index 087a8c7..26c419f 100644
>> --- a/kernel/livepatch/core.c
>> +++ b/kernel/livepatch/core.c
>> @@ -28,6 +28,8 @@
>> #include <linux/list.h>
>> #include <linux/kallsyms.h>
>> #include <linux/livepatch.h>
>> +#include <linux/elf.h>
>> +#include <asm/cacheflush.h>
>>
>> /**
>> * struct klp_ops - structure for tracking registered ftrace ops structs
>> @@ -281,46 +283,54 @@ static int klp_find_external_symbol(struct module *pmod, const char *name,
>> }
>>
>> static int klp_write_object_relocations(struct module *pmod,
>> - struct klp_object *obj)
>> + struct klp_object *obj,
>> + struct klp_patch *patch)
>> {
>[...]
>
>> +
>> + /* For each __klp_rela section for this object */
>> + list_for_each_entry(reloc_sec, &obj->reloc_secs, list) {
>
>Who, when, and how will define reloc_secs, please?
>
>I guess that it is just an optimization. It helps to avoid going
>through all elf sections of all livepatch modules. Therefore, I think
>that we might fill this when the livepatch module is loaded. But
>I do not see the code for this.
Thanks for bringing this up, I admit that from this patchset it is
unclear where and how the reloc_secs list is built.
Basically, the patch module code is expected to build the reloc_secs
list for each object that is being patched. For example in kpatch, the
patch module generates this list in patch_init(). Like you guessed, it
does go through all the elf sections of the patch module to find the
reloc sections marked SHF_RELA_LIVEPATCH. We are able to access these
sections through module->info, which is set up for livepatch modules
before the module loader calls do_init_module() (and hence before
patch_init(), See patch 2/5).
See below for an example of how the reloc_secs list might be built:
https://github.com/flaming-toast/kpatch/blob/no_dynrela_redux/kmod/patch/livepatch-patch-hook.c#L213
Once the patch module has built this list, it is good to go for use in
livepatch core. All livepatch has to do then is to iterate though the
list, resolve any outstanding symbols, and call apply_relocate_add(),
as shown in this patch.
Miroslav mentioned in another email that we should start thinking
about including documentation about this, including the expected patch
module format. So perhaps v2 should include some documentation about
this whole process somewhere.
Please let me know if anything else is unclear.
Thanks,
Jessica
next prev parent reply other threads:[~2015-11-11 18:27 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-10 4:45 [RFC PATCH 0/5] Arch-independent livepatch Jessica Yu
2015-11-10 4:45 ` [RFC PATCH 1/5] elf: add livepatch-specific elf constants Jessica Yu
2015-11-11 13:58 ` Petr Mladek
2015-11-12 15:33 ` Josh Poimboeuf
2015-11-12 15:45 ` Josh Poimboeuf
2015-11-13 6:49 ` Jessica Yu
2015-11-10 4:45 ` [RFC PATCH 2/5] module: save load_info for livepatch modules Jessica Yu
2015-11-11 8:08 ` Minfei Huang
2015-11-11 14:17 ` Miroslav Benes
2015-11-12 5:33 ` Jessica Yu
2015-11-12 10:24 ` Petr Mladek
2015-11-12 13:22 ` Miroslav Benes
2015-11-12 15:03 ` Petr Mladek
2015-11-12 17:05 ` Josh Poimboeuf
2015-11-12 22:17 ` Jessica Yu
2015-11-13 12:24 ` Miroslav Benes
2015-11-13 12:46 ` Miroslav Benes
2015-11-14 0:36 ` Jessica Yu
2015-11-16 12:12 ` Miroslav Benes
2015-11-13 12:56 ` Miroslav Benes
2015-11-14 2:09 ` Jessica Yu
2015-11-16 12:21 ` Miroslav Benes
2015-11-13 0:25 ` Jessica Yu
2015-11-11 14:31 ` [RFC PATCH 2/5] " Petr Mladek
2015-11-12 4:44 ` Jessica Yu
2015-11-12 10:05 ` Petr Mladek
2015-11-12 14:19 ` Miroslav Benes
2015-11-13 6:35 ` Jessica Yu
2015-11-13 13:07 ` Miroslav Benes
2015-11-13 8:20 ` Jessica Yu
2015-11-12 17:14 ` [RFC PATCH 2/5] " Josh Poimboeuf
2015-11-12 17:21 ` Josh Poimboeuf
2015-11-10 4:45 ` [RFC PATCH 3/5] livepatch: reuse module loader code to write relocations Jessica Yu
2015-11-10 8:13 ` Jiri Slaby
2015-11-11 14:30 ` Miroslav Benes
2015-11-11 20:07 ` Jessica Yu
2015-11-12 15:27 ` Miroslav Benes
2015-11-12 17:40 ` Josh Poimboeuf
2015-11-12 20:22 ` Jessica Yu
2015-11-12 20:32 ` Josh Poimboeuf
2015-11-13 7:15 ` Jessica Yu
2015-11-13 13:51 ` Miroslav Benes
2015-11-12 19:14 ` Jessica Yu
2015-11-12 20:35 ` Jessica Yu
2015-11-11 15:22 ` [RFC PATCH 3/5] " Petr Mladek
2015-11-11 18:27 ` Jessica Yu [this message]
2015-11-12 9:16 ` Petr Mladek
2015-11-12 17:59 ` [RFC PATCH 3/5] " Josh Poimboeuf
2015-11-10 4:45 ` [RFC PATCH 4/5] samples: livepatch: init reloc list and mark as klp module Jessica Yu
2015-11-10 8:15 ` Jiri Slaby
2015-11-10 13:50 ` Josh Poimboeuf
2015-11-10 18:37 ` Jessica Yu
2015-11-11 15:42 ` [RFC PATCH 4/5] " Petr Mladek
2015-11-12 6:02 ` Jessica Yu
2015-11-12 10:44 ` Miroslav Benes
2015-11-10 4:45 ` [RFC PATCH 5/5] livepatch: x86: remove unused relocation code Jessica Yu
2015-11-11 15:48 ` Petr Mladek
2015-11-12 18:01 ` Josh Poimboeuf
2015-11-11 14:00 ` [RFC PATCH 0/5] Arch-independent livepatch Miroslav Benes
2015-11-11 16:28 ` Josh Poimboeuf
2015-12-01 4:21 [RFC PATCH v2 0/6] (mostly) " Jessica Yu
2015-12-01 4:21 ` [RFC PATCH v2 4/6] livepatch: reuse module loader code to write relocations Jessica Yu
2015-12-01 8:43 ` Jessica Yu
2015-12-08 18:38 ` [RFC PATCH v2 4/6] " Josh Poimboeuf
2015-12-09 19:10 ` Jessica Yu
2015-12-10 14:28 ` Josh Poimboeuf
2015-12-10 21:33 ` Jessica Yu
2015-12-10 21:41 ` Josh Poimboeuf
2015-12-10 22:07 ` Jessica Yu
2015-12-16 5:40 ` Jessica Yu
2015-12-16 12:59 ` Miroslav Benes
2015-12-16 19:14 ` Jessica Yu
2015-12-17 15:45 ` Petr Mladek
2015-12-21 5:57 ` Jessica Yu
2016-01-08 19:28 [RFC PATCH v3 0/6] (mostly) Arch-independent livepatch Jessica Yu
2016-01-08 19:28 ` [RFC PATCH v3 4/6] livepatch: reuse module loader code to write relocations Jessica Yu
2016-01-11 21:33 ` Josh Poimboeuf
2016-01-11 22:35 ` Jessica Yu
2016-01-12 3:05 ` Josh Poimboeuf
2016-01-12 9:12 ` Petr Mladek
2016-01-14 5:07 ` Jessica Yu
2016-01-12 16:40 ` [RFC PATCH v3 4/6] " Miroslav Benes
2016-01-14 3:49 ` Jessica Yu
2016-01-14 9:04 ` Miroslav Benes
2016-01-13 9:19 ` [RFC PATCH v3 4/6] " Miroslav Benes
2016-01-13 18:39 ` Jessica Yu
2016-01-14 9:10 ` Miroslav Benes
2016-02-04 1:11 [RFC PATCH v4 0/6] (mostly) Arch-independent livepatch Jessica Yu
2016-02-04 1:11 ` [RFC PATCH v4 4/6] livepatch: reuse module loader code to write relocations Jessica Yu
2016-02-08 20:26 ` Josh Poimboeuf
2016-02-10 0:56 ` Jessica Yu
2016-02-09 14:01 ` [RFC PATCH v4 4/6] " Petr Mladek
2016-02-10 1:21 ` Jessica Yu
2016-03-16 19:47 [PATCH v5 0/6] (mostly) Arch-independent livepatch Jessica Yu
2016-03-16 19:47 ` [PATCH v5 4/6] livepatch: reuse module loader code to write relocations Jessica Yu
2016-03-21 13:55 ` Miroslav Benes
2016-03-21 19:18 ` Jessica Yu
2016-03-21 19:24 ` Josh Poimboeuf
2016-03-21 21:16 ` Jiri Kosina
2016-03-21 21:34 ` Josh Poimboeuf
2016-03-21 22:02 ` Jiri Kosina
2016-03-22 19:00 ` Jessica Yu
2016-03-21 16:31 ` [PATCH v5 4/6] " Petr Mladek
2016-03-21 16:46 ` Josh Poimboeuf
2016-03-21 17:36 ` Josh Poimboeuf
2016-03-21 18:07 ` Jessica Yu
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=20151111182718.GA30025@packer-debian-8-amd64.digitalocean.com \
--to=jeyu@redhat.com \
--cc=jikos@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=rusty@rustcorp.com.au \
--cc=sjenning@redhat.com \
--cc=vojtech@suse.com \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®