public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Raphael Gault <raphael.gault@arm.com>
To: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, jpoimboe@redhat.com
Cc: raph.gault+kdev@gmail.com, peterz@infradead.org,
	catalin.marinas@arm.com, will.deacon@arm.com,
	Raphael Gault <raphael.gault@arm.com>,
	julien.thierry.kdev@gmail.com
Subject: [RFC v4 07/18] objtool: Introduce INSN_UNKNOWN type
Date: Fri, 16 Aug 2019 13:23:52 +0100	[thread overview]
Message-ID: <20190816122403.14994-8-raphael.gault@arm.com> (raw)
In-Reply-To: <20190816122403.14994-1-raphael.gault@arm.com>

On arm64 some object files contain data stored in the .text section.
This data is interpreted by objtool as instruction but can't be
identified as a valid one. In order to keep analysing those files we
introduce INSN_UNKNOWN type. The "unknown instruction" warning will thus
only be raised if such instructions are uncountered while validating an
execution branch.

This change doesn't impact the x86 decoding logic since 0 is still used
as a way to specify an unknown type, raising the "unknown instruction"
warning during the decoding phase still.

Signed-off-by: Raphael Gault <raphael.gault@arm.com>
---
 tools/objtool/arch.h                           |  1 +
 tools/objtool/arch/arm64/decode.c              |  8 ++++----
 tools/objtool/arch/arm64/include/insn_decode.h |  4 ++--
 tools/objtool/check.c                          | 10 +++++++++-
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h
index 68d6371a24a2..9f2590e1df79 100644
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -28,6 +28,7 @@ enum insn_type {
 	INSN_CLAC,
 	INSN_STD,
 	INSN_CLD,
+	INSN_UNKNOWN,
 	INSN_OTHER,
 };
 
diff --git a/tools/objtool/arch/arm64/decode.c b/tools/objtool/arch/arm64/decode.c
index be3d2eb10227..4cb9402d6fe1 100644
--- a/tools/objtool/arch/arm64/decode.c
+++ b/tools/objtool/arch/arm64/decode.c
@@ -37,9 +37,9 @@
  */
 static arm_decode_class aarch64_insn_class_decode_table[] = {
 	[INSN_RESERVED]			= arm_decode_reserved,
-	[INSN_UNKNOWN]			= arm_decode_unknown,
+	[INSN_UNALLOC_1]		= arm_decode_unknown,
 	[INSN_SVE_ENC]			= arm_decode_sve_encoding,
-	[INSN_UNALLOC]			= arm_decode_unknown,
+	[INSN_UNALLOC_2]		= arm_decode_unknown,
 	[INSN_LD_ST_4]			= arm_decode_ld_st,
 	[INSN_DP_REG_5]			= arm_decode_dp_reg,
 	[INSN_LD_ST_6]			= arm_decode_ld_st,
@@ -191,7 +191,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 int arm_decode_unknown(u32 instr, unsigned char *type,
 		       unsigned long *immediate, struct stack_op *op)
 {
-	*type = 0;
+	*type = INSN_UNKNOWN;
 	return 0;
 }
 
@@ -206,7 +206,7 @@ int arm_decode_reserved(u32 instr, unsigned char *type,
 			unsigned long *immediate, struct stack_op *op)
 {
 	*immediate = instr & ONES(16);
-	*type = INSN_BUG;
+	*type = INSN_UNKNOWN;
 	return 0;
 }
 
diff --git a/tools/objtool/arch/arm64/include/insn_decode.h b/tools/objtool/arch/arm64/include/insn_decode.h
index eb54fc39dca5..a01d76306749 100644
--- a/tools/objtool/arch/arm64/include/insn_decode.h
+++ b/tools/objtool/arch/arm64/include/insn_decode.h
@@ -20,9 +20,9 @@
 #include "../../../arch.h"
 
 #define INSN_RESERVED	0b0000
-#define INSN_UNKNOWN	0b0001
+#define INSN_UNALLOC_1	0b0001
 #define INSN_SVE_ENC	0b0010
-#define INSN_UNALLOC	0b0011
+#define INSN_UNALLOC_2	0b0011
 #define INSN_DP_IMM	0b1001	//0x100x
 #define INSN_BRANCH	0b1011	//0x101x
 #define INSN_LD_ST_4	0b0100	//0bx1x0
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 519569b0329f..baa6a93f37cd 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1981,6 +1981,13 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
 	while (1) {
 		next_insn = next_insn_same_sec(file, insn);
 
+		if (insn->type == INSN_UNKNOWN) {
+			WARN("%s+0x%lx unknown instruction type, should never be reached",
+			     insn->sec->name,
+			     insn->offset);
+			return 1;
+		}
+
 		if (file->c_file && func && insn->func && func != insn->func->pfunc) {
 			WARN("%s() falls through to next function %s()",
 			     func->name, insn->func->name);
@@ -2414,7 +2421,8 @@ static int validate_reachable_instructions(struct objtool_file *file)
 		return 0;
 
 	for_each_insn(file, insn) {
-		if (insn->visited || ignore_unreachable_insn(insn))
+		if (insn->visited || ignore_unreachable_insn(insn) ||
+		    insn->type == INSN_UNKNOWN)
 			continue;
 
 		WARN_FUNC("unreachable instruction", insn->sec, insn->offset);
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-08-16 12:27 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16 12:23 [RFC v4 00/18] objtool: Add support for arm64 Raphael Gault
2019-08-16 12:23 ` [RFC v4 01/18] objtool: Add abstraction for computation of symbols offsets Raphael Gault
2019-08-22 16:30   ` Julien
2019-08-22 19:57   ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 02/18] objtool: orc: Refactor ORC API for other architectures to implement Raphael Gault
2019-08-22 19:59   ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 03/18] objtool: Move registers and control flow to arch-dependent code Raphael Gault
2019-08-22 20:00   ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 04/18] objtool: arm64: Add required implementation for supporting the aarch64 architecture in objtool Raphael Gault
2019-08-22 20:00   ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 05/18] objtool: special: Adapt special section handling Raphael Gault
2019-08-22 20:02   ` Josh Poimboeuf
2019-08-22 20:18   ` Julien
2019-08-16 12:23 ` [RFC v4 06/18] objtool: arm64: Adapt the stack frame checks for arm architecture Raphael Gault
2019-08-22 20:03   ` Josh Poimboeuf
2019-08-16 12:23 ` Raphael Gault [this message]
2019-08-22 20:04   ` [RFC v4 07/18] objtool: Introduce INSN_UNKNOWN type Josh Poimboeuf
2019-08-22 20:45     ` Julien
2019-08-22 21:51       ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 08/18] objtool: Refactor switch-tables code to support other architectures Raphael Gault
2019-08-22 20:04   ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 09/18] gcc-plugins: objtool: Add plugin to detect switch table on arm64 Raphael Gault
2019-08-22 20:05   ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 10/18] objtool: arm64: Implement functions to add switch tables alternatives Raphael Gault
2019-08-23 16:35   ` Julien
2019-08-16 12:23 ` [RFC v4 11/18] arm64: alternative: Mark .altinstr_replacement as containing executable instructions Raphael Gault
2019-08-16 12:23 ` [RFC v4 12/18] arm64: assembler: Add macro to annotate asm function having non standard stack-frame Raphael Gault
2019-08-22 20:10   ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 13/18] arm64: sleep: Prevent stack frame warnings from objtool Raphael Gault
2019-08-22 20:16   ` Josh Poimboeuf
2019-08-16 12:23 ` [RFC v4 14/18] arm64: kvm: Annotate non-standard stack frame functions Raphael Gault
2019-08-16 12:24 ` [RFC v4 15/18] arm64: kernel: Add exception on kuser32 to prevent stack analysis Raphael Gault
2019-08-16 12:24 ` [RFC v4 16/18] arm64: crypto: Add exceptions for crypto object " Raphael Gault
2019-08-22 20:19   ` Josh Poimboeuf
2019-08-16 12:24 ` [RFC v4 17/18] arm64: kernel: Annotate non-standard stack frame functions Raphael Gault
2019-08-16 12:24 ` [RFC v4 18/18] objtool: arm64: Enable stack validation for arm64 Raphael Gault
2019-08-22 19:56 ` [RFC v4 00/18] objtool: Add support " Josh Poimboeuf
2019-08-23 12:00   ` Raphael Gault
2019-10-14  8:37 ` Julien Thierry
2019-10-14 13:27   ` Raphaël Gault

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=20190816122403.14994-8-raphael.gault@arm.com \
    --to=raphael.gault@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=jpoimboe@redhat.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=raph.gault+kdev@gmail.com \
    --cc=will.deacon@arm.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