public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcos Paulo de Souza <mpdesouza@suse.com>
To: Lukas Hruska <lhruska@suse.cz>, Petr Mladek <pmladek@suse.com>,
	Miroslav Benes <mbenes@suse.cz>,
	Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Joe Lawrence <joe.lawrence@redhat.com>,
	live-patching@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-kbuild@vger.kernel.org
Subject: Re: [PATCH v1 5/5] documentation: Update on livepatch elf format
Date: Wed, 10 Jan 2024 16:54:48 -0300	[thread overview]
Message-ID: <3be436cf49b8850b95eb74ce7b7c45e05bc4ad82.camel@suse.com> (raw)
In-Reply-To: <20231106162513.17556-6-lhruska@suse.cz>

On Mon, 2023-11-06 at 17:25 +0100, Lukas Hruska wrote:
> Add a section to Documentation/livepatch/module-elf-format.rst
> describing how klp-convert works for fixing relocations.
> 
> Signed-off-by: Lukas Hruska <lhruska@suse.cz>

Reviewed-by: Marcos Paulo de Souza <mpdesouza@suse.com>

> ---
>  Documentation/livepatch/module-elf-format.rst | 67
> +++++++++++++++++++
>  1 file changed, 67 insertions(+)
> 
> diff --git a/Documentation/livepatch/module-elf-format.rst
> b/Documentation/livepatch/module-elf-format.rst
> index a03ed02ec57e..2aa9b11cd806 100644
> --- a/Documentation/livepatch/module-elf-format.rst
> +++ b/Documentation/livepatch/module-elf-format.rst
> @@ -300,3 +300,70 @@ symbol table, and relocation section indices,
> ELF information is preserved for
>  livepatch modules and is made accessible by the module loader
> through
>  module->klp_info, which is a :c:type:`klp_modinfo` struct. When a
> livepatch module
>  loads, this struct is filled in by the module loader.
> +
> +6. klp-convert tool
> +===================
> +The livepatch relocation sections might be created using
> +scripts/livepatch/klp-convert. It is called automatically during
> +the build as part of a module post processing.
> +
> +The tool is not able to find the symbols and all the metadata
> +automatically. Instead, all needed information must already be
> +part of rela entry for the given symbol. Such a rela can
> +be created easily by using KLP_RELOC_SYMBOL() macro after
> +the symbol declaration.
> +
> +KLP_RELOC_SYMBOL causes that the relocation entries for
> +the given symbol will be created in the following format::
> +
> +  .klp.sym.rela.lp_object.sym_object.sym_name,sympos
> +  ^           ^ ^       ^ ^        ^ ^      ^   ^
> +  |___________| |_______| |________| |______|   |
> +       [A]         [B]        [C]       [D]    [E]
> +
> +[A]
> +  The symbol name is prefixed with the string ".klp.sym.rela."
> +
> +[B]
> +  The name of the object (i.e. "vmlinux" or name of module) which
> +  is livepatched.
> +
> +[C]
> +  The name of the object (i.e. "vmlinux" or name of module) to
> +  which the symbol belongs follows immediately after the prefix.
> +
> +[D]
> +  The actual name of the symbol.
> +
> +[E]
> +  The position of the symbol in the object (as according to
> kallsyms)
> +  This is used to differentiate duplicate symbols within the same
> +  object. The symbol position is expressed numerically (0, 1, 2...).
> +  The symbol position of a unique symbol is 0.
> +
> +Example:
> +--------
> +**Livepatch source code:**
> +
> +::
> +
> +  extern char *saved_command_line \
> +                 KLP_RELOC_SYMBOL(vmlinux, vmlinux,
> saved_command_line, 0);
> +
> +**`readelf -r -W` output of compiled module:**
> +
> +::
> +
> +  Relocation section '.rela.text' at offset 0x32e60 contains 10
> entries:
> +      Offset             Info             Type              
> Symbol's Value  Symbol's Name + Addend
> +  ...
> +  0000000000000068  0000003c00000002 R_X86_64_PC32         
> 0000000000000000 .klp.sym.rela.vmlinux.vmlinux.saved_command_line,0 -
> 4
> +  ...
> +
> +**`readelf -r -W` output of transformed module by klp-convert:**
> +
> +::
> +
> +  Relocation section '.klp.rela.vmlinux.text' at offset 0x5cb60
> contains 1 entry:
> +      Offset             Info             Type              
> Symbol's Value  Symbol's Name + Addend
> +      0000000000000068  0000003c00000002 R_X86_64_PC32         
> 0000000000000000 .klp.sym.vmlinux.saved_command_line,0 - 4


  parent reply	other threads:[~2024-01-10 19:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 16:25 [PATCH v1 0/5] livepatch: klp-convert tool - Minimal version Lukas Hruska
2023-11-06 16:25 ` [PATCH v1 1/5] livepatch: Create and include UAPI headers Lukas Hruska
2024-01-05 10:15   ` Petr Mladek
2024-01-10 13:38   ` Marcos Paulo de Souza
2023-11-06 16:25 ` [PATCH v1 2/5] livepatch: Add klp-convert tool Lukas Hruska
2024-01-05 13:29   ` Petr Mladek
2024-01-10 19:03     ` Marcos Paulo de Souza
2024-01-05 15:01   ` Petr Mladek
2023-11-06 16:25 ` [PATCH v1 3/5] kbuild/modpost: integrate klp-convert Lukas Hruska
2024-01-05 14:03   ` Petr Mladek
2024-01-10 19:37   ` Marcos Paulo de Souza
2024-01-25  9:44   ` Lukas Hruska
2023-11-06 16:25 ` [PATCH v1 4/5] livepatch: Add sample livepatch module Lukas Hruska
2024-01-05 14:14   ` Petr Mladek
2023-11-06 16:25 ` [PATCH v1 5/5] documentation: Update on livepatch elf format Lukas Hruska
2024-01-05 14:16   ` Petr Mladek
2024-01-10 19:54   ` Marcos Paulo de Souza [this message]
2024-04-10 15:32 ` [PATCH v1 0/5] livepatch: klp-convert tool - Minimal version Marcos Paulo de Souza
2024-04-11  6:27   ` Miroslav Benes
2024-04-11 13:58     ` Lukas Hruska

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=3be436cf49b8850b95eb74ce7b7c45e05bc4ad82.camel@suse.com \
    --to=mpdesouza@suse.com \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=lhruska@suse.cz \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=pmladek@suse.com \
    /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