linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "tip-bot2 for Miroslav Benes" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Julien Thierry <jthierry@redhat.com>,
	Miroslav Benes <mbenes@suse.cz>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>, x86 <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [tip: objtool/core] objtool: Move the IRET hack into the arch decoder
Date: Fri, 01 May 2020 18:22:20 -0000	[thread overview]
Message-ID: <158835734054.8414.7454435298178677103.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20200428191659.913283807@infradead.org>

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

Commit-ID:     b490f45362002fef57996388e395efc974b013f4
Gitweb:        https://git.kernel.org/tip/b490f45362002fef57996388e395efc974b013f4
Author:        Miroslav Benes <mbenes@suse.cz>
AuthorDate:    Fri, 24 Apr 2020 16:30:42 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 30 Apr 2020 20:14:33 +02:00

objtool: Move the IRET hack into the arch decoder

Quoting Julien:

  "And the other suggestion is my other email was that you don't even
  need to add INSN_EXCEPTION_RETURN. You can keep IRET as
  INSN_CONTEXT_SWITCH by default and x86 decoder lookups the symbol
  conaining an iret. If it's a function symbol, it can just set the type
  to INSN_OTHER so that it caries on to the next instruction after
  having handled the stack_op."

Suggested-by: Julien Thierry <jthierry@redhat.com>
Signed-off-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lkml.kernel.org/r/20200428191659.913283807@infradead.org
---
 tools/objtool/arch.h            |  1 -
 tools/objtool/arch/x86/decode.c | 28 ++++++++++++++++++----------
 tools/objtool/check.c           | 11 -----------
 tools/objtool/elf.c             |  4 ++--
 tools/objtool/elf.h             |  2 +-
 5 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h
index 25dd4a9..cd118eb 100644
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -19,7 +19,6 @@ enum insn_type {
 	INSN_CALL,
 	INSN_CALL_DYNAMIC,
 	INSN_RETURN,
-	INSN_EXCEPTION_RETURN,
 	INSN_CONTEXT_SWITCH,
 	INSN_BUG,
 	INSN_NOP,
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index e26bedb..d7b5d10 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -94,6 +94,7 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 		      rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0,
 		      modrm_reg = 0, sib = 0;
 	struct stack_op *op = NULL;
+	struct symbol *sym;
 
 	x86_64 = is_x86_64(elf);
 	if (x86_64 == -1)
@@ -469,17 +470,24 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 		break;
 
 	case 0xcf: /* iret */
-		*type = INSN_EXCEPTION_RETURN;
-
-		ADD_OP(op) {
-			/* add $40, %rsp */
-			op->src.type = OP_SRC_ADD;
-			op->src.reg = CFI_SP;
-			op->src.offset = 5*8;
-			op->dest.type = OP_DEST_REG;
-			op->dest.reg = CFI_SP;
+		/*
+		 * Handle sync_core(), which has an IRET to self.
+		 * All other IRET are in STT_NONE entry code.
+		 */
+		sym = find_symbol_containing(sec, offset);
+		if (sym && sym->type == STT_FUNC) {
+			ADD_OP(op) {
+				/* add $40, %rsp */
+				op->src.type = OP_SRC_ADD;
+				op->src.reg = CFI_SP;
+				op->src.offset = 5*8;
+				op->dest.type = OP_DEST_REG;
+				op->dest.reg = CFI_SP;
+			}
+			break;
 		}
-		break;
+
+		/* fallthrough */
 
 	case 0xca: /* retf */
 	case 0xcb: /* retf */
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 4f3db2f..d822858 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2320,17 +2320,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
 
 			break;
 
-		case INSN_EXCEPTION_RETURN:
-			/*
-			 * This handles x86's sync_core() case, where we use an
-			 * IRET to self. All 'normal' IRET instructions are in
-			 * STT_NOTYPE entry symbols.
-			 */
-			if (func)
-				break;
-
-			return 0;
-
 		case INSN_CONTEXT_SWITCH:
 			if (func && (!next_insn || !next_insn->hint)) {
 				WARN_FUNC("unsupported instruction in callable function",
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 453b723..b6349ca 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -61,7 +61,7 @@ static void rb_add(struct rb_root *tree, struct rb_node *node,
 	rb_insert_color(node, tree);
 }
 
-static struct rb_node *rb_find_first(struct rb_root *tree, const void *key,
+static struct rb_node *rb_find_first(const struct rb_root *tree, const void *key,
 			       int (*cmp)(const void *key, const struct rb_node *))
 {
 	struct rb_node *node = tree->rb_node;
@@ -189,7 +189,7 @@ struct symbol *find_func_by_offset(struct section *sec, unsigned long offset)
 	return NULL;
 }
 
-struct symbol *find_symbol_containing(struct section *sec, unsigned long offset)
+struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset)
 {
 	struct rb_node *node;
 
diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
index 5e76ac3..9d6bb07 100644
--- a/tools/objtool/elf.h
+++ b/tools/objtool/elf.h
@@ -124,7 +124,7 @@ 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(const struct elf *elf, const char *name);
-struct symbol *find_symbol_containing(struct section *sec, unsigned long offset);
+struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset);
 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);

  reply	other threads:[~2020-05-01 18:22 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28 19:11 [PATCH v2 00/14] objtool vs retpoline Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 01/14] objtool: Allow branches within the same alternative Peter Zijlstra
2020-04-28 19:53   ` Josh Poimboeuf
2020-04-28 19:11 ` [PATCH v2 02/14] objtool: Fix ORC vs alternatives Peter Zijlstra
2020-04-28 19:55   ` Josh Poimboeuf
2020-04-29 14:33   ` Miroslav Benes
2020-04-29 15:51     ` Peter Zijlstra
2020-04-29 16:41       ` Miroslav Benes
2020-05-01 18:22   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 03/14] x86,smap: Fix smap_{save,restore}() alternatives Peter Zijlstra
2020-04-29  0:54   ` Brian Gerst
2020-04-29  8:30     ` Peter Zijlstra
2020-04-29 10:18       ` Peter Zijlstra
2020-04-29 12:12         ` Brian Gerst
2020-05-01 18:22         ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 04/14] objtool: is_fentry_call() crashes if call has no destination Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 05/14] objtool: UNWIND_HINT_RET_OFFSET should not check registers Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 06/14] objtool: Rework allocating stack_ops on decode Peter Zijlstra
2020-05-01 18:22   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 07/14] objtool: Make handle_insn_ops() unconditional Peter Zijlstra
2020-05-01 18:22   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-05-07 12:38     ` Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 08/14] objtool: Remove INSN_STACK Peter Zijlstra
2020-05-01 18:22   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 09/14] objtool: Move the IRET hack into the arch decoder Peter Zijlstra
2020-05-01 18:22   ` tip-bot2 for Miroslav Benes [this message]
2020-04-28 19:11 ` [PATCH v2 10/14] objtool: Add support for intra-function calls Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 11/14] x86/speculation: Change FILL_RETURN_BUFFER to work with objtool Peter Zijlstra
2020-05-01 18:22   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 12/14] x86: Simplify retpoline declaration Peter Zijlstra
2020-05-01 18:22   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 13/14] x86: Change {JMP,CALL}_NOSPEC argument Peter Zijlstra
2020-05-01 18:22   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-04-28 19:11 ` [PATCH v2 14/14] x86/retpoline: Fix retpoline unwind Peter Zijlstra
2020-05-01 18:22   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2020-04-28 20:17 ` [PATCH v2 00/14] objtool vs retpoline Josh Poimboeuf
2020-04-29 10:19 ` [PATCH v2.1 01-A/14] objtool: Remove check preventing branches within alternative Peter Zijlstra
2020-04-29 10:21 ` [PATCH v2.1 01-B/14] objtool: Uniquely identify alternative instruction groups Peter Zijlstra
2020-04-29 16:46 ` [PATCH v2 00/14] objtool vs retpoline 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=158835734054.8414.7454435298178677103.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=jpoimboe@redhat.com \
    --cc=jthierry@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).