Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1361981 > unrolled thread
| Started by | Petr Mladek <pmladek@suse.com> |
|---|---|
| First post | 2016-03-21 17:40 +0100 |
| Last post | 2016-03-21 19:10 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH v5 4/6] livepatch: reuse module loader code to write relocations Petr Mladek <pmladek@suse.com> - 2016-03-21 17:40 +0100
Re: [PATCH v5 4/6] livepatch: reuse module loader code to write relocations Josh Poimboeuf <jpoimboe@redhat.com> - 2016-03-21 17:50 +0100
Re: [PATCH v5 4/6] livepatch: reuse module loader code to write relocations Josh Poimboeuf <jpoimboe@redhat.com> - 2016-03-21 18:40 +0100
Re: livepatch: reuse module loader code to write relocations Jessica Yu <jeyu@redhat.com> - 2016-03-21 19:10 +0100
| From | Petr Mladek <pmladek@suse.com> |
|---|---|
| Date | 2016-03-21 17:40 +0100 |
| Subject | Re: [PATCH v5 4/6] livepatch: reuse module loader code to write relocations |
| Message-ID | <rfb21-8iP-1@gated-at.bofh.it> |
On Wed 2016-03-16 15:47:06, Jessica Yu wrote:
> Reuse module loader code to write relocations, thereby eliminating the need
> for architecture specific relocation code in livepatch. Specifically, reuse
> the apply_relocate_add() function in the module loader to write relocations
> instead of duplicating functionality in livepatch's arch-dependent
> klp_write_module_reloc() function.
>
> In order to accomplish this, livepatch modules manage their own relocation
> sections (marked with the SHF_RELA_LIVEPATCH section flag) and
> livepatch-specific symbols (marked with SHN_LIVEPATCH symbol section
> index). To apply livepatch relocation sections, livepatch symbols
> referenced by relocs are resolved and then apply_relocate_add() is called
> to apply those relocations.
>
> In addition, remove x86 livepatch relocation code and the s390
> klp_write_module_reloc() function stub. They are no longer needed since
> relocation work has been offloaded to module loader.
Most of the problems were covered by Mirek and Josh. I agree with
them. Please read two more comments below.
> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index 780f00c..2aa20fa 100644
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> +static int klp_resolve_symbols(Elf_Shdr *relasec, struct module *pmod)
> +{
> + int i, cnt, vmlinux, ret;
> + struct klp_buf bufs = {0};
> + Elf_Rela *relas;
> + Elf_Sym *sym;
> + char *symname;
> + unsigned long sympos;
> +
> + relas = (Elf_Rela *) relasec->sh_addr;
> + /* For each rela in this klp relocation section */
> + for (i = 0; i < relasec->sh_size / sizeof(Elf_Rela); i++) {
> + sym = pmod->core_kallsyms.symtab + ELF_R_SYM(relas[i].r_info);
> + if (sym->st_shndx != SHN_LIVEPATCH)
> + return -EINVAL;
> +
> + klp_clear_buf(&bufs);
> +
> + /* Format: .klp.sym.objname.symbol_name,sympos */
> + symname = pmod->core_kallsyms.strtab + sym->st_name;
> + cnt = sscanf(symname, ".klp.sym.%64[^.].%128[^,],%lu",
> + bufs.objname, bufs.symname, &sympos);
Note that MODULE_NAME_LEN even is not 64. It is defined by:
#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
I strongly suggest to use the proposal from Josh.
> + if (cnt != 3)
> + return -EINVAL;
> +
> + /* klp_find_object_symbol() treats a NULL objname as vmlinux */
> + vmlinux = !strcmp(bufs.objname, "vmlinux");
> + ret = klp_find_object_symbol(vmlinux ? NULL : bufs.objname,
> + bufs.symname, sympos,
> + (unsigned long *) &sym->st_value);
> + if (ret)
> + return ret;
> }
> - preempt_enable();
>
> - /*
> - * Check if it's in another .o within the patch module. This also
> - * checks that the external symbol is unique.
> - */
> - return klp_find_object_symbol(pmod->name, name, 0, addr);
> + return 0;
> }
[...]
> @@ -842,6 +867,9 @@ int klp_register_patch(struct klp_patch *patch)
> {
> int ret;
>
> + if (!is_livepatch_module(patch->mod))
> + return -EINVAL;
> +
This breaks bisectability if livepatch-sample is used. Please, merge
the 5th patch here or move it before this one.
Best Regards,
Petr
[toc] | [next] | [standalone]
| From | Josh Poimboeuf <jpoimboe@redhat.com> |
|---|---|
| Date | 2016-03-21 17:50 +0100 |
| Message-ID | <rfbbH-8nF-7@gated-at.bofh.it> |
| In reply to | #1361981 |
On Mon, Mar 21, 2016 at 05:31:57PM +0100, Petr Mladek wrote:
> > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > index 780f00c..2aa20fa 100644
> > --- a/kernel/livepatch/core.c
> > +++ b/kernel/livepatch/core.c
> > +static int klp_resolve_symbols(Elf_Shdr *relasec, struct module *pmod)
> > +{
> > + int i, cnt, vmlinux, ret;
> > + struct klp_buf bufs = {0};
> > + Elf_Rela *relas;
> > + Elf_Sym *sym;
> > + char *symname;
> > + unsigned long sympos;
> > +
> > + relas = (Elf_Rela *) relasec->sh_addr;
> > + /* For each rela in this klp relocation section */
> > + for (i = 0; i < relasec->sh_size / sizeof(Elf_Rela); i++) {
> > + sym = pmod->core_kallsyms.symtab + ELF_R_SYM(relas[i].r_info);
> > + if (sym->st_shndx != SHN_LIVEPATCH)
> > + return -EINVAL;
> > +
> > + klp_clear_buf(&bufs);
> > +
> > + /* Format: .klp.sym.objname.symbol_name,sympos */
> > + symname = pmod->core_kallsyms.strtab + sym->st_name;
> > + cnt = sscanf(symname, ".klp.sym.%64[^.].%128[^,],%lu",
> > + bufs.objname, bufs.symname, &sympos);
>
> Note that MODULE_NAME_LEN even is not 64. It is defined by:
>
> #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
>
> I strongly suggest to use the proposal from Josh.
Hm, looks like my suggestion to use __stringify(MODULE_NAME_LEN) doesn't
work. It results in the string "MODULE_NAME_LEN". Which surprises me:
isn't is supposed to resolve the macro before applying the '#' operation
to it?
I was going to suggest another idea: hard-code it at 63 and then do
something like
BUILD_BUG_ON(MODULE_NAME_LEN != 64)
But you're right... it's not even 64!
Need to think on this some more...
--
Josh
[toc] | [prev] | [next] | [standalone]
| From | Josh Poimboeuf <jpoimboe@redhat.com> |
|---|---|
| Date | 2016-03-21 18:40 +0100 |
| Message-ID | <rfbY8-vn-39@gated-at.bofh.it> |
| In reply to | #1361990 |
On Mon, Mar 21, 2016 at 11:46:51AM -0500, Josh Poimboeuf wrote:
> On Mon, Mar 21, 2016 at 05:31:57PM +0100, Petr Mladek wrote:
> > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > > index 780f00c..2aa20fa 100644
> > > --- a/kernel/livepatch/core.c
> > > +++ b/kernel/livepatch/core.c
> > > +static int klp_resolve_symbols(Elf_Shdr *relasec, struct module *pmod)
> > > +{
> > > + int i, cnt, vmlinux, ret;
> > > + struct klp_buf bufs = {0};
> > > + Elf_Rela *relas;
> > > + Elf_Sym *sym;
> > > + char *symname;
> > > + unsigned long sympos;
> > > +
> > > + relas = (Elf_Rela *) relasec->sh_addr;
> > > + /* For each rela in this klp relocation section */
> > > + for (i = 0; i < relasec->sh_size / sizeof(Elf_Rela); i++) {
> > > + sym = pmod->core_kallsyms.symtab + ELF_R_SYM(relas[i].r_info);
> > > + if (sym->st_shndx != SHN_LIVEPATCH)
> > > + return -EINVAL;
> > > +
> > > + klp_clear_buf(&bufs);
> > > +
> > > + /* Format: .klp.sym.objname.symbol_name,sympos */
> > > + symname = pmod->core_kallsyms.strtab + sym->st_name;
> > > + cnt = sscanf(symname, ".klp.sym.%64[^.].%128[^,],%lu",
> > > + bufs.objname, bufs.symname, &sympos);
> >
> > Note that MODULE_NAME_LEN even is not 64. It is defined by:
> >
> > #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
> >
> > I strongly suggest to use the proposal from Josh.
>
> Hm, looks like my suggestion to use __stringify(MODULE_NAME_LEN) doesn't
> work. It results in the string "MODULE_NAME_LEN". Which surprises me:
> isn't is supposed to resolve the macro before applying the '#' operation
> to it?
Turns out I hadn't included module.h. When I do so,
__stringify(MODULE_NAME_LEN) becomes "(64 - sizeof(unsigned long))".
Which is still not going to work :-/
> I was going to suggest another idea: hard-code it at 63 and then do
> something like
>
> BUILD_BUG_ON(MODULE_NAME_LEN != 64)
>
> But you're right... it's not even 64!
>
> Need to think on this some more...
--
Josh
[toc] | [prev] | [next] | [standalone]
| From | Jessica Yu <jeyu@redhat.com> |
|---|---|
| Date | 2016-03-21 19:10 +0100 |
| Subject | Re: livepatch: reuse module loader code to write relocations |
| Message-ID | <rfcr8-Wc-15@gated-at.bofh.it> |
| In reply to | #1362039 |
+++ Josh Poimboeuf [21/03/16 12:36 -0500]:
>On Mon, Mar 21, 2016 at 11:46:51AM -0500, Josh Poimboeuf wrote:
>> On Mon, Mar 21, 2016 at 05:31:57PM +0100, Petr Mladek wrote:
>> > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
>> > > index 780f00c..2aa20fa 100644
>> > > --- a/kernel/livepatch/core.c
>> > > +++ b/kernel/livepatch/core.c
>> > > +static int klp_resolve_symbols(Elf_Shdr *relasec, struct module *pmod)
>> > > +{
>> > > + int i, cnt, vmlinux, ret;
>> > > + struct klp_buf bufs = {0};
>> > > + Elf_Rela *relas;
>> > > + Elf_Sym *sym;
>> > > + char *symname;
>> > > + unsigned long sympos;
>> > > +
>> > > + relas = (Elf_Rela *) relasec->sh_addr;
>> > > + /* For each rela in this klp relocation section */
>> > > + for (i = 0; i < relasec->sh_size / sizeof(Elf_Rela); i++) {
>> > > + sym = pmod->core_kallsyms.symtab + ELF_R_SYM(relas[i].r_info);
>> > > + if (sym->st_shndx != SHN_LIVEPATCH)
>> > > + return -EINVAL;
>> > > +
>> > > + klp_clear_buf(&bufs);
>> > > +
>> > > + /* Format: .klp.sym.objname.symbol_name,sympos */
>> > > + symname = pmod->core_kallsyms.strtab + sym->st_name;
>> > > + cnt = sscanf(symname, ".klp.sym.%64[^.].%128[^,],%lu",
>> > > + bufs.objname, bufs.symname, &sympos);
>> >
>> > Note that MODULE_NAME_LEN even is not 64. It is defined by:
>> >
>> > #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
>> >
>> > I strongly suggest to use the proposal from Josh.
>>
>> Hm, looks like my suggestion to use __stringify(MODULE_NAME_LEN) doesn't
>> work. It results in the string "MODULE_NAME_LEN". Which surprises me:
>> isn't is supposed to resolve the macro before applying the '#' operation
>> to it?
>
>Turns out I hadn't included module.h. When I do so,
>__stringify(MODULE_NAME_LEN) becomes "(64 - sizeof(unsigned long))".
>Which is still not going to work :-/
>
Hm, we probably won't be able to make use of preprocessor tricks here,
since I don't think the preprocessor can even evaluate that expression
(esp. with that sizeof there). This might mean building the format
string at runtime, which may be more trouble than it's worth...
>> I was going to suggest another idea: hard-code it at 63 and then do
>> something like
>>
>> BUILD_BUG_ON(MODULE_NAME_LEN != 64)
>>
>> But you're right... it's not even 64!
>>
>> Need to think on this some more...
>
>--
>Josh
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web