All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Chris J Arges <chris.j.arges@canonical.com>,
	live-patching@vger.kernel.org, jeyu@redhat.com,
	Seth Jennings <sjenning@redhat.com>,
	Jiri Kosina <jikos@kernel.org>, Vojtech Pavlik <vojtech@suse.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3 v4] livepatch: add old_sympos as disambiguator field to klp_reloc
Date: Thu, 12 Nov 2015 15:31:58 +0100	[thread overview]
Message-ID: <20151112143157.GS2599@pathway.suse.cz> (raw)
In-Reply-To: <20151111175731.GF5331@treble.redhat.com>

On Wed 2015-11-11 11:57:31, Josh Poimboeuf wrote:
> On Wed, Nov 11, 2015 at 10:29:00AM -0600, Chris J Arges wrote:
> > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > index 26f9778..4eb8691 100644
> > --- a/kernel/livepatch/core.c
> > +++ b/kernel/livepatch/core.c
> > @@ -261,7 +222,7 @@ static int klp_find_verify_func_addr(struct klp_object *obj,
> >   * object is either vmlinux or the kmod being patched).
> >   */
> >  static int klp_find_external_symbol(struct module *pmod, const char *name,
> > -				    unsigned long *addr)
> > +				    unsigned long *addr, unsigned long sympos)
> >  {
> >  	const struct kernel_symbol *sym;
> >  
> 
> For "external" symbols, the object isn't specified by the user, and
> since sympos is per-object, the value of sympos is undefined.   Instead
> I think it should always pass 0 to klp_find_object_symbol() below.

Heh, I always had troubles to understand the meaning of
this external stuff.

> In line with that, since reloc->external and reloc->sympos don't mix,
> maybe klp_write_object_relocations() should return -EINVAL if external
> is set and sympos is non-zero.
> 
> > @@ -276,7 +237,7 @@ static int klp_find_external_symbol(struct module *pmod, const char *name,
> >  	preempt_enable();
> >  
> >  	/* otherwise check if it's in another .o within the patch module */
> > -	return klp_find_object_symbol(pmod->name, name, addr, 0);
> > +	return klp_find_object_symbol(pmod->name, name, addr, sympos);
> >  }

Please, do you have an example when this code will be used?
Do we really need to relocate symbols within the patch module this
way?

My understanding is that it would be used to relocate symbols
between various .o files that are used to produce the patch module.
IMHO, the only situation is that you want to access a static
symbol from another .o file. But this is not used in normal modules.
It does not look like a real life scenario.

It is indepednt on this patch set but it might make it easier.
What about doing this cleaup, first?


>From 095f74fb92205177b138bb6215e4e5fd59dca8db Mon Sep 17 00:00:00 2001
From: Petr Mladek <pmladek@suse.com>
Date: Thu, 12 Nov 2015 15:11:00 +0100
Subject: [PATCH] livepatch: Simplify code for relocated external symbols

The livepatch module might be linked from several .o files.
All symbols that need to be shared between these .o files
should be exported. This is a normal programming practice.
I do not see any reason to access static symbols between
these .o files.

This patch removes the search for the static symbols within
the livepatch module. It makes it easier to understand
the meaning of the external flag and klp_find_external_symbol()
function.

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 include/linux/livepatch.h |  3 ++-
 kernel/livepatch/core.c   | 12 +++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index 31db7a05dd36..77b84732ee05 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -71,7 +71,8 @@ struct klp_func {
  * @type:	ELF relocation type
  * @name:	name of the referenced symbol (for lookup/verification)
  * @addend:	offset from the referenced symbol
- * @external:	symbol is either exported or within the live patch module itself
+ * @external:	set for external symbols that are accessed from this object
+ *		but defined outside; they must be exported
  */
 struct klp_reloc {
 	unsigned long loc;
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 6e5344112419..138f11420883 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -258,26 +258,24 @@ static int klp_find_verify_func_addr(struct klp_object *obj,
 }
 
 /*
- * external symbols are located outside the parent object (where the parent
- * object is either vmlinux or the kmod being patched).
+ * External symbols are exported symbols that are defined outside both
+ * the patched object and the patch.
  */
 static int klp_find_external_symbol(struct module *pmod, const char *name,
 				    unsigned long *addr)
 {
 	const struct kernel_symbol *sym;
+	int ret = -EINVAL;
 
-	/* first, check if it's an exported symbol */
 	preempt_disable();
 	sym = find_symbol(name, NULL, NULL, true, true);
 	if (sym) {
 		*addr = sym->value;
-		preempt_enable();
-		return 0;
+		ret = 0;
 	}
 	preempt_enable();
 
-	/* otherwise check if it's in another .o within the patch module */
-	return klp_find_object_symbol(pmod->name, name, addr);
+	return ret;
 }
 
 static int klp_write_object_relocations(struct module *pmod,
-- 
1.8.5.6


  reply	other threads:[~2015-11-12 14:32 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02 17:58 [PATCH] livepatch: old_name.number scheme in livepatch sysfs directory Chris J Arges
2015-11-02 17:58 ` Chris J Arges
2015-11-02 19:15 ` Jessica Yu
2015-11-02 19:52 ` [PATCH] " Josh Poimboeuf
2015-11-02 19:52   ` Josh Poimboeuf
2015-11-02 20:16   ` Chris J Arges
2015-11-02 20:32     ` Josh Poimboeuf
2015-11-02 22:59       ` [PATCH v2] " Chris J Arges
2015-11-02 22:59         ` Chris J Arges
2015-11-03  9:50         ` Miroslav Benes
2015-11-03 15:03           ` Josh Poimboeuf
2015-11-03 10:52         ` Miroslav Benes
2015-11-03 10:52           ` Miroslav Benes
2015-11-03 12:44           ` Petr Mladek
2015-11-03 12:44             ` Petr Mladek
2015-11-03 15:03             ` Josh Poimboeuf
2015-11-03 15:03               ` Josh Poimboeuf
2015-11-03 19:57             ` Jiri Kosina
2015-11-03 19:57               ` Jiri Kosina
2015-11-03 20:06               ` Josh Poimboeuf
2015-11-03 20:06                 ` Josh Poimboeuf
     [not found]                 ` <1447259366-7055-1-git-send-email-chris.j.arges@canonical.com>
2015-11-11 16:28                   ` [PATCH 1/3 v4] livepatch: add old_sympos as disambiguator field to klp_func Chris J Arges
2015-11-11 17:43                     ` Josh Poimboeuf
2015-11-12 10:22                     ` Miroslav Benes
2015-11-11 16:29                   ` [PATCH 2/3 v4] livepatch: add old_sympos as disambiguator field to klp_reloc Chris J Arges
2015-11-11 16:39                     ` Chris J Arges
2015-11-11 17:57                     ` Josh Poimboeuf
2015-11-12 14:31                       ` Petr Mladek [this message]
2015-11-12 19:19                         ` Josh Poimboeuf
2015-11-13 13:54                           ` Petr Mladek
2015-11-13 16:59                             ` Josh Poimboeuf
2015-11-16 12:11                               ` Petr Mladek
2015-11-12 10:23                     ` Miroslav Benes
2015-11-11 16:29                   ` [PATCH 3/3 v4] livepatch: old_name,number scheme in livepatch sysfs directory Chris J Arges
2015-11-11 18:01                     ` Josh Poimboeuf
2015-11-11 18:01                       ` Josh Poimboeuf
     [not found]                   ` <1447347595-30728-1-git-send-email-chris.j.arges@canonical.com>
2015-11-12 16:59                     ` [PATCH 1/4 v5] livepatch: add old_sympos as disambiguator field to klp_func Chris J Arges
2015-11-12 19:45                       ` Josh Poimboeuf
2015-11-13  9:56                       ` Jiri Kosina
2015-11-13 10:14                       ` Miroslav Benes
2015-11-13 16:27                       ` Petr Mladek
2015-11-12 16:59                     ` [PATCH 2/4 v5] livepatch: Simplify code for relocated external symbols Chris J Arges
2015-11-13 10:24                       ` Miroslav Benes
2015-11-13 13:55                         ` Petr Mladek
2015-11-12 16:59                     ` [PATCH 3/4 v5] livepatch: add sympos as disambiguator field to klp_reloc Chris J Arges
2015-11-12 19:50                       ` Josh Poimboeuf
2015-11-13 16:42                       ` Petr Mladek
2015-11-12 16:59                     ` [PATCH 4/4 v5] livepatch: function,sympos scheme in livepatch sysfs directory Chris J Arges
     [not found]                     ` <1447431804-18786-1-git-send-email-chris.j.arges@canonical.com>
2015-11-13 16:23                       ` [PATCH 1/3 v6] livepatch: add old_sympos as disambiguator field to klp_func Chris J Arges
2015-11-13 16:23                       ` [PATCH 2/3 v6] livepatch: add sympos as disambiguator field to klp_reloc Chris J Arges
2015-11-13 16:23                       ` [PATCH 3/3 v6] livepatch: function,sympos scheme in livepatch sysfs directory Chris J Arges
     [not found]                       ` <1447693391-10065-1-git-send-email-chris.j.arges@canonical.com>
2015-11-16 17:03                         ` [PATCH 1/3 v7] livepatch: add old_sympos as disambiguator field to klp_func Chris J Arges
2015-11-16 21:59                           ` Jiri Kosina
2015-11-17 14:29                             ` Chris J Arges
2015-11-19 10:02                               ` Jiri Kosina
2015-11-16 17:03                         ` [PATCH 2/3 v7] livepatch: add sympos as disambiguator field to klp_reloc Chris J Arges
2015-11-18  9:56                           ` Miroslav Benes
2015-11-18 14:01                             ` Josh Poimboeuf
2015-11-18 16:47                               ` Petr Mladek
2015-11-18 16:37                           ` Petr Mladek
2015-11-18 16:39                             ` Chris J Arges
2015-11-18 16:55                               ` Petr Mladek
2015-11-18 20:34                                 ` Jiri Kosina
2015-11-16 17:03                         ` [PATCH 3/3 v7] livepatch: function,sympos scheme in livepatch sysfs directory Chris J Arges
2015-11-20 17:25                         ` [PATCH 0/3 v8] livepatch: disambiguate symbols with the same name Chris J Arges
2015-11-20 17:25                           ` [PATCH 1/3 v8] livepatch: add old_sympos as disambiguator field to klp_func Chris J Arges
2015-11-23  9:47                             ` Miroslav Benes
2015-11-20 17:25                           ` [PATCH 2/3 v8] livepatch: add sympos as disambiguator field to klp_reloc Chris J Arges
2015-11-23  9:52                             ` Miroslav Benes
2015-11-30 20:46                               ` Chris J Arges
2015-12-01  1:17                                 ` Josh Poimboeuf
2015-11-20 17:25                           ` [PATCH 3/3 v8] livepatch: function,sympos scheme in livepatch sysfs directory Chris J Arges
2015-11-23  9:47                             ` Miroslav Benes
2015-12-02  2:40                           ` [PATCH 0/3 v9] livepatch: disambiguate symbols with the same name Chris J Arges
2015-12-02  2:40                             ` [PATCH 1/3 v9] livepatch: add old_sympos as disambiguator field to klp_func Chris J Arges
2015-12-02  2:40                             ` [PATCH 2/3 v9] livepatch: add sympos as disambiguator field to klp_reloc Chris J Arges
2015-12-14 12:45                               ` Miroslav Benes
2015-12-02  2:40                             ` [PATCH 3/3 v9] livepatch: function,sympos scheme in livepatch sysfs directory Chris J Arges
2015-12-02 15:28                             ` [PATCH 0/3 v9] livepatch: disambiguate symbols with the same name Petr Mladek
2015-12-03 17:59                             ` Josh Poimboeuf
2015-12-03 22:04                             ` Jiri Kosina
2015-11-03 14:58           ` [PATCH v2] livepatch: old_name.number scheme in livepatch sysfs directory Josh Poimboeuf
2015-11-03 16:09             ` Miroslav Benes
2015-11-03 16:50               ` Josh Poimboeuf
2015-11-03 20:42                 ` Chris J Arges
2015-11-03 20:42                   ` Chris J Arges
2015-11-04  9:52                 ` Miroslav Benes
2015-11-04  9:52                   ` Miroslav Benes
2015-11-04 16:03                   ` Josh Poimboeuf
2015-11-04 16:17                     ` Chris J Arges
2015-11-04 16:17                       ` Chris J Arges
2015-11-05 15:18                     ` Miroslav Benes
2015-11-05 15:56                       ` Josh Poimboeuf
2015-11-05 16:07                         ` Chris J Arges
2015-11-09 16:16                         ` [PATCH v3] livepatch: old_name,number " Chris J Arges
2015-11-09 16:16                           ` Chris J Arges
2015-11-09 20:56                           ` Josh Poimboeuf
2015-11-09 23:01                             ` Chris J Arges
2015-11-09 23:01                               ` Chris J Arges
2015-11-10  4:54                               ` Josh Poimboeuf
2015-11-10  8:49                                 ` Miroslav Benes
2015-11-10 13:40                                   ` Josh Poimboeuf
2015-11-10 13:40                                     ` Josh Poimboeuf
2015-11-10  9:02                           ` Miroslav Benes

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=20151112143157.GS2599@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=chris.j.arges@canonical.com \
    --cc=jeyu@redhat.com \
    --cc=jikos@kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=sjenning@redhat.com \
    --cc=vojtech@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.