linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] objtool: Constify most of the instruction decoding loop
@ 2020-04-22 10:32 Ingo Molnar
  2020-04-22 10:32 ` [PATCH 1/3] objtool: Constify 'struct elf *' parameters Ingo Molnar
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Ingo Molnar @ 2020-04-22 10:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, Josh Poimboeuf, Sami Tolvanen, Borislav Petkov,
	Linus Torvalds, Thomas Gleixner

Constify some of the decoding primitives, to ascertain and enforce that
arch_decode_instructions() is a read-only consumer of the various ELF data
structures. (Which it is.)

This is in preparation to parallelize the most expensive parts of objtool,
but makes sense independently as well.

These bits can also be found at:

  git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git WIP.core/objtool

(Subject to rebasing.)

Thanks,

     Ingo

====
Ingo Molnar (3):
  objtool: Constify 'struct elf *' parameters
  objtool: Rename elf_read() to elf_open_read()
  objtool: Constify arch_decode_instruction()

 tools/objtool/arch.h            |  2 +-
 tools/objtool/arch/x86/decode.c |  6 +++---
 tools/objtool/check.c           |  2 +-
 tools/objtool/elf.c             | 12 ++++++------
 tools/objtool/elf.h             | 22 +++++++++++-----------
 5 files changed, 22 insertions(+), 22 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/3] objtool: Constify 'struct elf *' parameters
  2020-04-22 10:32 [PATCH 0/3] objtool: Constify most of the instruction decoding loop Ingo Molnar
@ 2020-04-22 10:32 ` Ingo Molnar
  2020-04-23  7:49   ` [tip: objtool/core] " tip-bot2 for Ingo Molnar
  2020-04-22 10:32 ` [PATCH 2/3] objtool: Rename elf_read() to elf_open_read() Ingo Molnar
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Ingo Molnar @ 2020-04-22 10:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, Josh Poimboeuf, Sami Tolvanen, Borislav Petkov,
	Linus Torvalds, Thomas Gleixner

In preparation to parallelize certain parts of objtool, map out which uses
of various data structures are read-only vs. read-write.

As a first step constify 'struct elf' pointer passing, most of the secondary
uses of it in find_symbol_*() methods are read-only.

Also, while at it, better group the 'struct elf' handling methods in elf.h.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/objtool/elf.c | 10 +++++-----
 tools/objtool/elf.h | 20 ++++++++++----------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index f26bb3e8db7b..fab5534c3365 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -127,7 +127,7 @@ static int symbol_by_offset(const void *key, const struct rb_node *node)
 	return 0;
 }
 
-struct section *find_section_by_name(struct elf *elf, const char *name)
+struct section *find_section_by_name(const struct elf *elf, const char *name)
 {
 	struct section *sec;
 
@@ -217,7 +217,7 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset)
 	return NULL;
 }
 
-struct symbol *find_symbol_by_name(struct elf *elf, const char *name)
+struct symbol *find_symbol_by_name(const struct elf *elf, const char *name)
 {
 	struct symbol *sym;
 
@@ -228,7 +228,7 @@ struct symbol *find_symbol_by_name(struct elf *elf, const char *name)
 	return NULL;
 }
 
-struct rela *find_rela_by_dest_range(struct elf *elf, struct section *sec,
+struct rela *find_rela_by_dest_range(const struct elf *elf, struct section *sec,
 				     unsigned long offset, unsigned int len)
 {
 	struct rela *rela, *r = NULL;
@@ -257,7 +257,7 @@ struct rela *find_rela_by_dest_range(struct elf *elf, struct section *sec,
 	return NULL;
 }
 
-struct rela *find_rela_by_dest(struct elf *elf, struct section *sec, unsigned long offset)
+struct rela *find_rela_by_dest(const struct elf *elf, struct section *sec, unsigned long offset)
 {
 	return find_rela_by_dest_range(elf, sec, offset, 1);
 }
@@ -769,7 +769,7 @@ int elf_rebuild_rela_section(struct section *sec)
 	return 0;
 }
 
-int elf_write(struct elf *elf)
+int elf_write(const struct elf *elf)
 {
 	struct section *sec;
 	Elf_Scn *s;
diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
index 2811d04346c9..a55bcde9f1b1 100644
--- a/tools/objtool/elf.h
+++ b/tools/objtool/elf.h
@@ -114,22 +114,22 @@ static inline u32 rela_hash(struct rela *rela)
 }
 
 struct elf *elf_read(const char *name, int flags);
-struct section *find_section_by_name(struct elf *elf, const char *name);
+struct section *elf_create_section(struct elf *elf, const char *name, size_t entsize, int nr);
+struct section *elf_create_rela_section(struct elf *elf, struct section *base);
+void elf_add_rela(struct elf *elf, struct rela *rela);
+int elf_write(const struct elf *elf);
+void elf_close(struct elf *elf);
+
+struct section *find_section_by_name(const struct elf *elf, const char *name);
 struct symbol *find_func_by_offset(struct section *sec, unsigned long offset);
 struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset);
-struct symbol *find_symbol_by_name(struct elf *elf, const char *name);
+struct symbol *find_symbol_by_name(const struct elf *elf, const char *name);
 struct symbol *find_symbol_containing(struct section *sec, unsigned long offset);
-struct rela *find_rela_by_dest(struct elf *elf, struct section *sec, unsigned long offset);
-struct rela *find_rela_by_dest_range(struct elf *elf, struct section *sec,
+struct rela *find_rela_by_dest(const struct elf *elf, struct section *sec, unsigned long offset);
+struct rela *find_rela_by_dest_range(const struct elf *elf, struct section *sec,
 				     unsigned long offset, unsigned int len);
 struct symbol *find_func_containing(struct section *sec, unsigned long offset);
-struct section *elf_create_section(struct elf *elf, const char *name, size_t
-				   entsize, int nr);
-struct section *elf_create_rela_section(struct elf *elf, struct section *base);
 int elf_rebuild_rela_section(struct section *sec);
-int elf_write(struct elf *elf);
-void elf_close(struct elf *elf);
-void elf_add_rela(struct elf *elf, struct rela *rela);
 
 #define for_each_sec(file, sec)						\
 	list_for_each_entry(sec, &file->elf->sections, list)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/3] objtool: Rename elf_read() to elf_open_read()
  2020-04-22 10:32 [PATCH 0/3] objtool: Constify most of the instruction decoding loop Ingo Molnar
  2020-04-22 10:32 ` [PATCH 1/3] objtool: Constify 'struct elf *' parameters Ingo Molnar
@ 2020-04-22 10:32 ` Ingo Molnar
  2020-04-22 11:43   ` Peter Zijlstra
  2020-04-23  7:49   ` [tip: objtool/core] " tip-bot2 for Ingo Molnar
  2020-04-22 10:32 ` [PATCH 3/3] objtool: Constify arch_decode_instruction() Ingo Molnar
  2020-04-22 20:49 ` [PATCH 0/3] objtool: Constify most of the instruction decoding loop Josh Poimboeuf
  3 siblings, 2 replies; 12+ messages in thread
From: Ingo Molnar @ 2020-04-22 10:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, Josh Poimboeuf, Sami Tolvanen, Borislav Petkov,
	Linus Torvalds, Thomas Gleixner

'struct elf *' handling is an open/close paradigm, make sure the naming
matches that:

   elf_open_read()
   elf_write()
   elf_close()

Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/objtool/check.c | 2 +-
 tools/objtool/elf.c   | 2 +-
 tools/objtool/elf.h   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f2a84271e807..12e2aea42bb2 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2614,7 +2614,7 @@ int check(const char *_objname, bool orc)
 
 	objname = _objname;
 
-	file.elf = elf_read(objname, orc ? O_RDWR : O_RDONLY);
+	file.elf = elf_open_read(objname, orc ? O_RDWR : O_RDONLY);
 	if (!file.elf)
 		return 1;
 
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index fab5534c3365..453b723c89d5 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -542,7 +542,7 @@ static int read_relas(struct elf *elf)
 	return 0;
 }
 
-struct elf *elf_read(const char *name, int flags)
+struct elf *elf_open_read(const char *name, int flags)
 {
 	struct elf *elf;
 	Elf_Cmd cmd;
diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
index a55bcde9f1b1..5e76ac38cf99 100644
--- a/tools/objtool/elf.h
+++ b/tools/objtool/elf.h
@@ -113,7 +113,7 @@ static inline u32 rela_hash(struct rela *rela)
 	return sec_offset_hash(rela->sec, rela->offset);
 }
 
-struct elf *elf_read(const char *name, int flags);
+struct elf *elf_open_read(const char *name, int flags);
 struct section *elf_create_section(struct elf *elf, const char *name, size_t entsize, int nr);
 struct section *elf_create_rela_section(struct elf *elf, struct section *base);
 void elf_add_rela(struct elf *elf, struct rela *rela);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/3] objtool: Constify arch_decode_instruction()
  2020-04-22 10:32 [PATCH 0/3] objtool: Constify most of the instruction decoding loop Ingo Molnar
  2020-04-22 10:32 ` [PATCH 1/3] objtool: Constify 'struct elf *' parameters Ingo Molnar
  2020-04-22 10:32 ` [PATCH 2/3] objtool: Rename elf_read() to elf_open_read() Ingo Molnar
@ 2020-04-22 10:32 ` Ingo Molnar
  2020-04-23  7:49   ` [tip: objtool/core] " tip-bot2 for Ingo Molnar
  2020-04-22 20:49 ` [PATCH 0/3] objtool: Constify most of the instruction decoding loop Josh Poimboeuf
  3 siblings, 1 reply; 12+ messages in thread
From: Ingo Molnar @ 2020-04-22 10:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, Josh Poimboeuf, Sami Tolvanen, Borislav Petkov,
	Linus Torvalds, Thomas Gleixner

Mostly straightforward constification, except that WARN_FUNC()
needs a writable pointer while we have read-only pointers,
so deflect this to WARN().

Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/objtool/arch.h            | 2 +-
 tools/objtool/arch/x86/decode.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h
index 561c3162d177..445b8fa73ccb 100644
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -72,7 +72,7 @@ struct instruction;
 
 void arch_initial_func_cfi_state(struct cfi_init_state *state);
 
-int arch_decode_instruction(struct elf *elf, struct section *sec,
+int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 			    unsigned long offset, unsigned int maxlen,
 			    unsigned int *len, enum insn_type *type,
 			    unsigned long *immediate,
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index f0d42ad7d5ff..c45a0b4e0760 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -27,7 +27,7 @@ static unsigned char op_to_cfi_reg[][2] = {
 	{CFI_DI, CFI_R15},
 };
 
-static int is_x86_64(struct elf *elf)
+static int is_x86_64(const struct elf *elf)
 {
 	switch (elf->ehdr.e_machine) {
 	case EM_X86_64:
@@ -77,7 +77,7 @@ unsigned long arch_jump_destination(struct instruction *insn)
 	return insn->offset + insn->len + insn->immediate;
 }
 
-int arch_decode_instruction(struct elf *elf, struct section *sec,
+int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 			    unsigned long offset, unsigned int maxlen,
 			    unsigned int *len, enum insn_type *type,
 			    unsigned long *immediate,
@@ -98,7 +98,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 	insn_get_length(&insn);
 
 	if (!insn_complete(&insn)) {
-		WARN_FUNC("can't decode instruction", sec, offset);
+		WARN("can't decode instruction at %s:0x%lx", sec->name, offset);
 		return -1;
 	}
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] objtool: Rename elf_read() to elf_open_read()
  2020-04-22 10:32 ` [PATCH 2/3] objtool: Rename elf_read() to elf_open_read() Ingo Molnar
@ 2020-04-22 11:43   ` Peter Zijlstra
  2020-04-22 14:22     ` Ingo Molnar
  2020-04-23  7:49   ` [tip: objtool/core] " tip-bot2 for Ingo Molnar
  1 sibling, 1 reply; 12+ messages in thread
From: Peter Zijlstra @ 2020-04-22 11:43 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Josh Poimboeuf, Sami Tolvanen, Borislav Petkov,
	Linus Torvalds, Thomas Gleixner

On Wed, Apr 22, 2020 at 12:32:04PM +0200, Ingo Molnar wrote:
> 'struct elf *' handling is an open/close paradigm, make sure the naming
> matches that:
> 
>    elf_open_read()
>    elf_write()
>    elf_close()


> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index f2a84271e807..12e2aea42bb2 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -2614,7 +2614,7 @@ int check(const char *_objname, bool orc)
>  
>  	objname = _objname;
>  
> -	file.elf = elf_read(objname, orc ? O_RDWR : O_RDONLY);
> +	file.elf = elf_open_read(objname, orc ? O_RDWR : O_RDONLY);

Note that I have a patch pending that makes that unconditionally O_RDWR,
which sort of seems to suggest elf_open() might be the better name.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] objtool: Rename elf_read() to elf_open_read()
  2020-04-22 11:43   ` Peter Zijlstra
@ 2020-04-22 14:22     ` Ingo Molnar
  2020-04-22 17:00       ` Matt Helsley
  0 siblings, 1 reply; 12+ messages in thread
From: Ingo Molnar @ 2020-04-22 14:22 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, Josh Poimboeuf, Sami Tolvanen, Borislav Petkov,
	Linus Torvalds, Thomas Gleixner


* Peter Zijlstra <peterz@infradead.org> wrote:

> On Wed, Apr 22, 2020 at 12:32:04PM +0200, Ingo Molnar wrote:
> > 'struct elf *' handling is an open/close paradigm, make sure the naming
> > matches that:
> > 
> >    elf_open_read()
> >    elf_write()
> >    elf_close()
> 
> 
> > diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> > index f2a84271e807..12e2aea42bb2 100644
> > --- a/tools/objtool/check.c
> > +++ b/tools/objtool/check.c
> > @@ -2614,7 +2614,7 @@ int check(const char *_objname, bool orc)
> >  
> >  	objname = _objname;
> >  
> > -	file.elf = elf_read(objname, orc ? O_RDWR : O_RDONLY);
> > +	file.elf = elf_open_read(objname, orc ? O_RDWR : O_RDONLY);
> 
> Note that I have a patch pending that makes that unconditionally O_RDWR,
> which sort of seems to suggest elf_open() might be the better name.

Ok, done!

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] objtool: Rename elf_read() to elf_open_read()
  2020-04-22 14:22     ` Ingo Molnar
@ 2020-04-22 17:00       ` Matt Helsley
  2020-04-22 19:22         ` Ingo Molnar
  0 siblings, 1 reply; 12+ messages in thread
From: Matt Helsley @ 2020-04-22 17:00 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Peter Zijlstra, linux-kernel, Josh Poimboeuf, Sami Tolvanen,
	Borislav Petkov, Linus Torvalds, Thomas Gleixner

On Wed, Apr 22, 2020 at 04:22:35PM +0200, Ingo Molnar wrote:
> 
> * Peter Zijlstra <peterz@infradead.org> wrote:
> 
> > On Wed, Apr 22, 2020 at 12:32:04PM +0200, Ingo Molnar wrote:
> > > 'struct elf *' handling is an open/close paradigm, make sure the naming
> > > matches that:
> > > 
> > >    elf_open_read()
> > >    elf_write()
> > >    elf_close()
> > 
> > 
> > > diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> > > index f2a84271e807..12e2aea42bb2 100644
> > > --- a/tools/objtool/check.c
> > > +++ b/tools/objtool/check.c
> > > @@ -2614,7 +2614,7 @@ int check(const char *_objname, bool orc)
> > >  
> > >  	objname = _objname;
> > >  
> > > -	file.elf = elf_read(objname, orc ? O_RDWR : O_RDONLY);
> > > +	file.elf = elf_open_read(objname, orc ? O_RDWR : O_RDONLY);
> > 
> > Note that I have a patch pending that makes that unconditionally O_RDWR,
> > which sort of seems to suggest elf_open() might be the better name.
> 
> Ok, done!

It might be a better name but there could be a problem with it --
see 8e144797f1a67c52e386161863da4614a23ad913
"objtool: Rename elf_open() to prevent conflict with libelf from elftoolchain"

Unless I'm forgetting something I think that'd still be an issue.

Cheers,
	-Matt

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] objtool: Rename elf_read() to elf_open_read()
  2020-04-22 17:00       ` Matt Helsley
@ 2020-04-22 19:22         ` Ingo Molnar
  0 siblings, 0 replies; 12+ messages in thread
From: Ingo Molnar @ 2020-04-22 19:22 UTC (permalink / raw)
  To: Matt Helsley, Peter Zijlstra, linux-kernel, Josh Poimboeuf,
	Sami Tolvanen, Borislav Petkov, Linus Torvalds, Thomas Gleixner


* Matt Helsley <mhelsley@vmware.com> wrote:

> On Wed, Apr 22, 2020 at 04:22:35PM +0200, Ingo Molnar wrote:
> > 
> > * Peter Zijlstra <peterz@infradead.org> wrote:
> > 
> > > On Wed, Apr 22, 2020 at 12:32:04PM +0200, Ingo Molnar wrote:
> > > > 'struct elf *' handling is an open/close paradigm, make sure the naming
> > > > matches that:
> > > > 
> > > >    elf_open_read()
> > > >    elf_write()
> > > >    elf_close()
> > > 
> > > 
> > > > diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> > > > index f2a84271e807..12e2aea42bb2 100644
> > > > --- a/tools/objtool/check.c
> > > > +++ b/tools/objtool/check.c
> > > > @@ -2614,7 +2614,7 @@ int check(const char *_objname, bool orc)
> > > >  
> > > >  	objname = _objname;
> > > >  
> > > > -	file.elf = elf_read(objname, orc ? O_RDWR : O_RDONLY);
> > > > +	file.elf = elf_open_read(objname, orc ? O_RDWR : O_RDONLY);
> > > 
> > > Note that I have a patch pending that makes that unconditionally O_RDWR,
> > > which sort of seems to suggest elf_open() might be the better name.
> > 
> > Ok, done!
> 
> It might be a better name but there could be a problem with it --
> see 8e144797f1a67c52e386161863da4614a23ad913
> "objtool: Rename elf_open() to prevent conflict with libelf from elftoolchain"
> 
> Unless I'm forgetting something I think that'd still be an issue.

Indeed, that's a good point - I'll move back to elf_open_read()! :-)

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/3] objtool: Constify most of the instruction decoding loop
  2020-04-22 10:32 [PATCH 0/3] objtool: Constify most of the instruction decoding loop Ingo Molnar
                   ` (2 preceding siblings ...)
  2020-04-22 10:32 ` [PATCH 3/3] objtool: Constify arch_decode_instruction() Ingo Molnar
@ 2020-04-22 20:49 ` Josh Poimboeuf
  3 siblings, 0 replies; 12+ messages in thread
From: Josh Poimboeuf @ 2020-04-22 20:49 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Peter Zijlstra, Sami Tolvanen, Borislav Petkov,
	Linus Torvalds, Thomas Gleixner

On Wed, Apr 22, 2020 at 12:32:02PM +0200, Ingo Molnar wrote:
> Constify some of the decoding primitives, to ascertain and enforce that
> arch_decode_instructions() is a read-only consumer of the various ELF data
> structures. (Which it is.)
> 
> This is in preparation to parallelize the most expensive parts of objtool,
> but makes sense independently as well.
> 
> These bits can also be found at:
> 
>   git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git WIP.core/objtool

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>

-- 
Josh


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [tip: objtool/core] objtool: Constify arch_decode_instruction()
  2020-04-22 10:32 ` [PATCH 3/3] objtool: Constify arch_decode_instruction() Ingo Molnar
@ 2020-04-23  7:49   ` tip-bot2 for Ingo Molnar
  0 siblings, 0 replies; 12+ messages in thread
From: tip-bot2 for Ingo Molnar @ 2020-04-23  7:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Josh Poimboeuf, Ingo Molnar, Borislav Petkov, Linus Torvalds,
	Peter Zijlstra, Sami Tolvanen, Thomas Gleixner, x86, LKML

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     0c98be8118221a8d3de572740f29dd02ed9686a5
Gitweb:        https://git.kernel.org/tip/0c98be8118221a8d3de572740f29dd02ed9686a5
Author:        Ingo Molnar <mingo@kernel.org>
AuthorDate:    Wed, 22 Apr 2020 12:32:05 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 23 Apr 2020 08:34:18 +02:00

objtool: Constify arch_decode_instruction()

Mostly straightforward constification, except that WARN_FUNC()
needs a writable pointer while we have read-only pointers,
so deflect this to WARN().

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20200422103205.61900-4-mingo@kernel.org
---
 tools/objtool/arch.h            | 2 +-
 tools/objtool/arch/x86/decode.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h
index 561c316..445b8fa 100644
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -72,7 +72,7 @@ struct instruction;
 
 void arch_initial_func_cfi_state(struct cfi_init_state *state);
 
-int arch_decode_instruction(struct elf *elf, struct section *sec,
+int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 			    unsigned long offset, unsigned int maxlen,
 			    unsigned int *len, enum insn_type *type,
 			    unsigned long *immediate,
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index f0d42ad..c45a0b4 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -27,7 +27,7 @@ static unsigned char op_to_cfi_reg[][2] = {
 	{CFI_DI, CFI_R15},
 };
 
-static int is_x86_64(struct elf *elf)
+static int is_x86_64(const struct elf *elf)
 {
 	switch (elf->ehdr.e_machine) {
 	case EM_X86_64:
@@ -77,7 +77,7 @@ unsigned long arch_jump_destination(struct instruction *insn)
 	return insn->offset + insn->len + insn->immediate;
 }
 
-int arch_decode_instruction(struct elf *elf, struct section *sec,
+int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 			    unsigned long offset, unsigned int maxlen,
 			    unsigned int *len, enum insn_type *type,
 			    unsigned long *immediate,
@@ -98,7 +98,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 	insn_get_length(&insn);
 
 	if (!insn_complete(&insn)) {
-		WARN_FUNC("can't decode instruction", sec, offset);
+		WARN("can't decode instruction at %s:0x%lx", sec->name, offset);
 		return -1;
 	}
 

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [tip: objtool/core] objtool: Rename elf_read() to elf_open_read()
  2020-04-22 10:32 ` [PATCH 2/3] objtool: Rename elf_read() to elf_open_read() Ingo Molnar
  2020-04-22 11:43   ` Peter Zijlstra
@ 2020-04-23  7:49   ` tip-bot2 for Ingo Molnar
  1 sibling, 0 replies; 12+ messages in thread
From: tip-bot2 for Ingo Molnar @ 2020-04-23  7:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Josh Poimboeuf, Ingo Molnar, Borislav Petkov, Linus Torvalds,
	Peter Zijlstra, Sami Tolvanen, Thomas Gleixner, x86, LKML

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     bc359ff2f6f3e8a9df38c39017e269bc442357c7
Gitweb:        https://git.kernel.org/tip/bc359ff2f6f3e8a9df38c39017e269bc442357c7
Author:        Ingo Molnar <mingo@kernel.org>
AuthorDate:    Wed, 22 Apr 2020 12:32:04 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 23 Apr 2020 08:34:18 +02:00

objtool: Rename elf_read() to elf_open_read()

'struct elf *' handling is an open/close paradigm, make sure the naming
matches that:

   elf_open_read()
   elf_write()
   elf_close()

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20200422103205.61900-3-mingo@kernel.org
---
 tools/objtool/check.c | 2 +-
 tools/objtool/elf.c   | 2 +-
 tools/objtool/elf.h   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f2a8427..12e2aea 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2614,7 +2614,7 @@ int check(const char *_objname, bool orc)
 
 	objname = _objname;
 
-	file.elf = elf_read(objname, orc ? O_RDWR : O_RDONLY);
+	file.elf = elf_open_read(objname, orc ? O_RDWR : O_RDONLY);
 	if (!file.elf)
 		return 1;
 
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index fab5534..453b723 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -542,7 +542,7 @@ static int read_relas(struct elf *elf)
 	return 0;
 }
 
-struct elf *elf_read(const char *name, int flags)
+struct elf *elf_open_read(const char *name, int flags)
 {
 	struct elf *elf;
 	Elf_Cmd cmd;
diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
index a55bcde..5e76ac3 100644
--- a/tools/objtool/elf.h
+++ b/tools/objtool/elf.h
@@ -113,7 +113,7 @@ static inline u32 rela_hash(struct rela *rela)
 	return sec_offset_hash(rela->sec, rela->offset);
 }
 
-struct elf *elf_read(const char *name, int flags);
+struct elf *elf_open_read(const char *name, int flags);
 struct section *elf_create_section(struct elf *elf, const char *name, size_t entsize, int nr);
 struct section *elf_create_rela_section(struct elf *elf, struct section *base);
 void elf_add_rela(struct elf *elf, struct rela *rela);

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [tip: objtool/core] objtool: Constify 'struct elf *' parameters
  2020-04-22 10:32 ` [PATCH 1/3] objtool: Constify 'struct elf *' parameters Ingo Molnar
@ 2020-04-23  7:49   ` tip-bot2 for Ingo Molnar
  0 siblings, 0 replies; 12+ messages in thread
From: tip-bot2 for Ingo Molnar @ 2020-04-23  7:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Josh Poimboeuf, Ingo Molnar, Borislav Petkov, Linus Torvalds,
	Peter Zijlstra, Sami Tolvanen, Thomas Gleixner, x86, LKML

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     894e48cada64ec384873fad4fe1b0d0c7de31a29
Gitweb:        https://git.kernel.org/tip/894e48cada64ec384873fad4fe1b0d0c7de31a29
Author:        Ingo Molnar <mingo@kernel.org>
AuthorDate:    Wed, 22 Apr 2020 12:32:03 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 23 Apr 2020 08:34:18 +02:00

objtool: Constify 'struct elf *' parameters

In preparation to parallelize certain parts of objtool, map out which uses
of various data structures are read-only vs. read-write.

As a first step constify 'struct elf' pointer passing, most of the secondary
uses of it in find_symbol_*() methods are read-only.

Also, while at it, better group the 'struct elf' handling methods in elf.h.

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20200422103205.61900-2-mingo@kernel.org
---
 tools/objtool/elf.c | 10 +++++-----
 tools/objtool/elf.h | 20 ++++++++++----------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index f26bb3e..fab5534 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -127,7 +127,7 @@ static int symbol_by_offset(const void *key, const struct rb_node *node)
 	return 0;
 }
 
-struct section *find_section_by_name(struct elf *elf, const char *name)
+struct section *find_section_by_name(const struct elf *elf, const char *name)
 {
 	struct section *sec;
 
@@ -217,7 +217,7 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset)
 	return NULL;
 }
 
-struct symbol *find_symbol_by_name(struct elf *elf, const char *name)
+struct symbol *find_symbol_by_name(const struct elf *elf, const char *name)
 {
 	struct symbol *sym;
 
@@ -228,7 +228,7 @@ struct symbol *find_symbol_by_name(struct elf *elf, const char *name)
 	return NULL;
 }
 
-struct rela *find_rela_by_dest_range(struct elf *elf, struct section *sec,
+struct rela *find_rela_by_dest_range(const struct elf *elf, struct section *sec,
 				     unsigned long offset, unsigned int len)
 {
 	struct rela *rela, *r = NULL;
@@ -257,7 +257,7 @@ struct rela *find_rela_by_dest_range(struct elf *elf, struct section *sec,
 	return NULL;
 }
 
-struct rela *find_rela_by_dest(struct elf *elf, struct section *sec, unsigned long offset)
+struct rela *find_rela_by_dest(const struct elf *elf, struct section *sec, unsigned long offset)
 {
 	return find_rela_by_dest_range(elf, sec, offset, 1);
 }
@@ -769,7 +769,7 @@ int elf_rebuild_rela_section(struct section *sec)
 	return 0;
 }
 
-int elf_write(struct elf *elf)
+int elf_write(const struct elf *elf)
 {
 	struct section *sec;
 	Elf_Scn *s;
diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
index 2811d04..a55bcde 100644
--- a/tools/objtool/elf.h
+++ b/tools/objtool/elf.h
@@ -114,22 +114,22 @@ static inline u32 rela_hash(struct rela *rela)
 }
 
 struct elf *elf_read(const char *name, int flags);
-struct section *find_section_by_name(struct elf *elf, const char *name);
+struct section *elf_create_section(struct elf *elf, const char *name, size_t entsize, int nr);
+struct section *elf_create_rela_section(struct elf *elf, struct section *base);
+void elf_add_rela(struct elf *elf, struct rela *rela);
+int elf_write(const struct elf *elf);
+void elf_close(struct elf *elf);
+
+struct section *find_section_by_name(const struct elf *elf, const char *name);
 struct symbol *find_func_by_offset(struct section *sec, unsigned long offset);
 struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset);
-struct symbol *find_symbol_by_name(struct elf *elf, const char *name);
+struct symbol *find_symbol_by_name(const struct elf *elf, const char *name);
 struct symbol *find_symbol_containing(struct section *sec, unsigned long offset);
-struct rela *find_rela_by_dest(struct elf *elf, struct section *sec, unsigned long offset);
-struct rela *find_rela_by_dest_range(struct elf *elf, struct section *sec,
+struct rela *find_rela_by_dest(const struct elf *elf, struct section *sec, unsigned long offset);
+struct rela *find_rela_by_dest_range(const struct elf *elf, struct section *sec,
 				     unsigned long offset, unsigned int len);
 struct symbol *find_func_containing(struct section *sec, unsigned long offset);
-struct section *elf_create_section(struct elf *elf, const char *name, size_t
-				   entsize, int nr);
-struct section *elf_create_rela_section(struct elf *elf, struct section *base);
 int elf_rebuild_rela_section(struct section *sec);
-int elf_write(struct elf *elf);
-void elf_close(struct elf *elf);
-void elf_add_rela(struct elf *elf, struct rela *rela);
 
 #define for_each_sec(file, sec)						\
 	list_for_each_entry(sec, &file->elf->sections, list)

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-04-23  7:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-22 10:32 [PATCH 0/3] objtool: Constify most of the instruction decoding loop Ingo Molnar
2020-04-22 10:32 ` [PATCH 1/3] objtool: Constify 'struct elf *' parameters Ingo Molnar
2020-04-23  7:49   ` [tip: objtool/core] " tip-bot2 for Ingo Molnar
2020-04-22 10:32 ` [PATCH 2/3] objtool: Rename elf_read() to elf_open_read() Ingo Molnar
2020-04-22 11:43   ` Peter Zijlstra
2020-04-22 14:22     ` Ingo Molnar
2020-04-22 17:00       ` Matt Helsley
2020-04-22 19:22         ` Ingo Molnar
2020-04-23  7:49   ` [tip: objtool/core] " tip-bot2 for Ingo Molnar
2020-04-22 10:32 ` [PATCH 3/3] objtool: Constify arch_decode_instruction() Ingo Molnar
2020-04-23  7:49   ` [tip: objtool/core] " tip-bot2 for Ingo Molnar
2020-04-22 20:49 ` [PATCH 0/3] objtool: Constify most of the instruction decoding loop Josh Poimboeuf

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).