linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] objtool: Miscellaneous cleanup/fixes
@ 2020-09-15  7:53 Julien Thierry
  2020-09-15  7:53 ` [PATCH 1/3] objtool: check: Remove useless tests Julien Thierry
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Julien Thierry @ 2020-09-15  7:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: jpoimboe, peterz, mbenes, Julien Thierry

Hi,

These patches provide some simple cleanup or lift small limitations
found while working on the arm64 port.

They should apply on current tip/objtool/core branch

Cheers,

Julien

-->

Julien Thierry (3):
  objtool: check: Remove useless tests
  objtool: check: Ignore unreachable fake jumps
  objtool: check: Handle calling non-function symbols in other sections

 tools/objtool/check.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

--
2.21.3


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

* [PATCH 1/3] objtool: check: Remove useless tests
  2020-09-15  7:53 [PATCH 0/3] objtool: Miscellaneous cleanup/fixes Julien Thierry
@ 2020-09-15  7:53 ` Julien Thierry
  2020-09-15  7:53 ` [PATCH 2/3] objtool: check: Ignore unreachable fake jumps Julien Thierry
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Julien Thierry @ 2020-09-15  7:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: jpoimboe, peterz, mbenes, Julien Thierry

save_reg already checks that the register being saved does not already
have a saved state.

Remove redundant checks before processing a register storing operation.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
---
 tools/objtool/check.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 4e2f703b6a25..fd2edab8e672 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2030,7 +2030,7 @@ static int update_cfi_state(struct instruction *insn, struct cfi_state *cfi,
 				/* drap: push %rbp */
 				cfi->stack_size = 0;
 
-			} else if (regs[op->src.reg].base == CFI_UNDEFINED) {
+			} else {
 
 				/* drap: push %reg */
 				save_reg(cfi, op->src.reg, CFI_BP, -cfi->stack_size);
@@ -2059,9 +2059,7 @@ static int update_cfi_state(struct instruction *insn, struct cfi_state *cfi,
 
 				/* save drap offset so we know when to restore it */
 				cfi->drap_offset = op->dest.offset;
-			}
-
-			else if (regs[op->src.reg].base == CFI_UNDEFINED) {
+			} else {
 
 				/* drap: mov reg, disp(%rbp) */
 				save_reg(cfi, op->src.reg, CFI_BP, op->dest.offset);
-- 
2.21.3


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

* [PATCH 2/3] objtool: check: Ignore unreachable fake jumps
  2020-09-15  7:53 [PATCH 0/3] objtool: Miscellaneous cleanup/fixes Julien Thierry
  2020-09-15  7:53 ` [PATCH 1/3] objtool: check: Remove useless tests Julien Thierry
@ 2020-09-15  7:53 ` Julien Thierry
  2020-09-15  7:53 ` [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections Julien Thierry
  2020-09-18 21:47 ` [PATCH 0/3] objtool: Miscellaneous cleanup/fixes Josh Poimboeuf
  3 siblings, 0 replies; 8+ messages in thread
From: Julien Thierry @ 2020-09-15  7:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: jpoimboe, peterz, mbenes, Julien Thierry

It is possible for alternative code to unconditionally jump out of the
alternative region. In such a case, if a fake jump is added at the end
of the alternative instructions, the fake jump will never be reached.
Since the fake jump is just a mean to make sure code validation does not
go beyond the set of alternatives, reaching it is not a requirement.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
---
 tools/objtool/check.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index fd2edab8e672..cd7c6698d316 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2648,6 +2648,9 @@ static bool ignore_unreachable_insn(struct instruction *insn)
 	    !strcmp(insn->sec->name, ".altinstr_aux"))
 		return true;
 
+	if (insn->type == INSN_JUMP_UNCONDITIONAL && insn->offset == FAKE_JUMP_OFFSET)
+		return true;
+
 	if (!insn->func)
 		return false;
 
-- 
2.21.3


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

* [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections
  2020-09-15  7:53 [PATCH 0/3] objtool: Miscellaneous cleanup/fixes Julien Thierry
  2020-09-15  7:53 ` [PATCH 1/3] objtool: check: Remove useless tests Julien Thierry
  2020-09-15  7:53 ` [PATCH 2/3] objtool: check: Ignore unreachable fake jumps Julien Thierry
@ 2020-09-15  7:53 ` Julien Thierry
  2020-09-18 20:07   ` Josh Poimboeuf
  2020-09-18 21:47 ` [PATCH 0/3] objtool: Miscellaneous cleanup/fixes Josh Poimboeuf
  3 siblings, 1 reply; 8+ messages in thread
From: Julien Thierry @ 2020-09-15  7:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: jpoimboe, peterz, mbenes, Julien Thierry

Relocation for a call destination could point to a symbol that has
type STT_NOTYPE.

Lookup such a symbol when no function is available.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
---
 tools/objtool/check.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index cd7c6698d316..500f63b3dcff 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -815,6 +815,17 @@ static void remove_insn_ops(struct instruction *insn)
 	}
 }
 
+static struct symbol *find_call_destination(struct section *sec, unsigned long offset)
+{
+	struct symbol *call_dest;
+
+	call_dest = find_func_by_offset(sec, offset);
+	if (!call_dest)
+		call_dest = find_symbol_by_offset(sec, offset);
+
+	return call_dest;
+}
+
 /*
  * Find the destination instructions for all calls.
  */
@@ -832,9 +843,7 @@ static int add_call_destinations(struct objtool_file *file)
 					       insn->offset, insn->len);
 		if (!reloc) {
 			dest_off = arch_jump_destination(insn);
-			insn->call_dest = find_func_by_offset(insn->sec, dest_off);
-			if (!insn->call_dest)
-				insn->call_dest = find_symbol_by_offset(insn->sec, dest_off);
+			insn->call_dest = find_call_destination(insn->sec, dest_off);
 
 			if (insn->ignore)
 				continue;
@@ -852,8 +861,9 @@ static int add_call_destinations(struct objtool_file *file)
 
 		} else if (reloc->sym->type == STT_SECTION) {
 			dest_off = arch_dest_reloc_offset(reloc->addend);
-			insn->call_dest = find_func_by_offset(reloc->sym->sec,
-							      dest_off);
+			insn->call_dest = find_call_destination(reloc->sym->sec,
+								dest_off);
+
 			if (!insn->call_dest) {
 				WARN_FUNC("can't find call dest symbol at %s+0x%lx",
 					  insn->sec, insn->offset,
-- 
2.21.3


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

* Re: [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections
  2020-09-15  7:53 ` [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections Julien Thierry
@ 2020-09-18 20:07   ` Josh Poimboeuf
  2020-09-21  9:56     ` Julien Thierry
  0 siblings, 1 reply; 8+ messages in thread
From: Josh Poimboeuf @ 2020-09-18 20:07 UTC (permalink / raw)
  To: Julien Thierry; +Cc: linux-kernel, peterz, mbenes

On Tue, Sep 15, 2020 at 08:53:18AM +0100, Julien Thierry wrote:
> Relocation for a call destination could point to a symbol that has
> type STT_NOTYPE.

Then shouldn't the callee be changed to STT_FUNC?

(Apologies if we discussed this one before...)

-- 
Josh


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

* Re: [PATCH 0/3] objtool: Miscellaneous cleanup/fixes
  2020-09-15  7:53 [PATCH 0/3] objtool: Miscellaneous cleanup/fixes Julien Thierry
                   ` (2 preceding siblings ...)
  2020-09-15  7:53 ` [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections Julien Thierry
@ 2020-09-18 21:47 ` Josh Poimboeuf
  3 siblings, 0 replies; 8+ messages in thread
From: Josh Poimboeuf @ 2020-09-18 21:47 UTC (permalink / raw)
  To: Julien Thierry; +Cc: linux-kernel, peterz, mbenes

On Tue, Sep 15, 2020 at 08:53:15AM +0100, Julien Thierry wrote:
> Hi,
> 
> These patches provide some simple cleanup or lift small limitations
> found while working on the arm64 port.
> 
> They should apply on current tip/objtool/core branch

I've got patches 1 & 2 queued up in jpoimboe/objtool/core.

-- 
Josh


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

* Re: [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections
  2020-09-18 20:07   ` Josh Poimboeuf
@ 2020-09-21  9:56     ` Julien Thierry
  2020-09-21 14:40       ` Josh Poimboeuf
  0 siblings, 1 reply; 8+ messages in thread
From: Julien Thierry @ 2020-09-21  9:56 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: linux-kernel, peterz, mbenes



On 9/18/20 9:07 PM, Josh Poimboeuf wrote:
> On Tue, Sep 15, 2020 at 08:53:18AM +0100, Julien Thierry wrote:
>> Relocation for a call destination could point to a symbol that has
>> type STT_NOTYPE.
> 
> Then shouldn't the callee be changed to STT_FUNC?
> 

Not if it's a code symbol that does not follow standard calling convention.

It's really the same case as the !reloc, except this time it's in a 
different .text section. In arm64 there are different sections that are 
used (.text for basic code, .idmap.text for code mapped in a manner 
where virtual address == physical address, .hyp.text for kvm priviledged 
code, .tramp.text for trampolines...). There aren't many cases, but some 
symbols reference symbols in other sections, but the symbol being called 
isn't a proper function.



-- 
Julien Thierry


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

* Re: [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections
  2020-09-21  9:56     ` Julien Thierry
@ 2020-09-21 14:40       ` Josh Poimboeuf
  0 siblings, 0 replies; 8+ messages in thread
From: Josh Poimboeuf @ 2020-09-21 14:40 UTC (permalink / raw)
  To: Julien Thierry; +Cc: linux-kernel, peterz, mbenes

On Mon, Sep 21, 2020 at 10:56:05AM +0100, Julien Thierry wrote:
> 
> 
> On 9/18/20 9:07 PM, Josh Poimboeuf wrote:
> > On Tue, Sep 15, 2020 at 08:53:18AM +0100, Julien Thierry wrote:
> > > Relocation for a call destination could point to a symbol that has
> > > type STT_NOTYPE.
> > 
> > Then shouldn't the callee be changed to STT_FUNC?
> > 
> 
> Not if it's a code symbol that does not follow standard calling convention.
> 
> It's really the same case as the !reloc, except this time it's in a
> different .text section.

Yeah, that makes sense.  I'll take this one as well.

-- 
Josh


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

end of thread, other threads:[~2020-09-21 14:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15  7:53 [PATCH 0/3] objtool: Miscellaneous cleanup/fixes Julien Thierry
2020-09-15  7:53 ` [PATCH 1/3] objtool: check: Remove useless tests Julien Thierry
2020-09-15  7:53 ` [PATCH 2/3] objtool: check: Ignore unreachable fake jumps Julien Thierry
2020-09-15  7:53 ` [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections Julien Thierry
2020-09-18 20:07   ` Josh Poimboeuf
2020-09-21  9:56     ` Julien Thierry
2020-09-21 14:40       ` Josh Poimboeuf
2020-09-18 21:47 ` [PATCH 0/3] objtool: Miscellaneous cleanup/fixes 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).