Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp870685ybl; Fri, 16 Aug 2019 05:27:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqySpaVViS0dV8Zs1/k9Ae2daXWnzkwHILEtkN6IdOyeQh7tkwh55PHd8L8ce+Rpnj6b+0Da X-Received: by 2002:aa7:9a86:: with SMTP id w6mr10444785pfi.60.1565958420487; Fri, 16 Aug 2019 05:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565958420; cv=none; d=google.com; s=arc-20160816; b=BHrrmCCw7BIbH4psfFkbi04130D5nCTDjV6YIAHipYv3X7lVtuLit3z7AG5GgiVcHF sUkF4KtYsEOPq+nsXWglzUDAZo26FlPRli4bVXOBtulEiCX85qL7gccCrnKhs7+esjzx DT+XFawe62dujUaUGLyr3V5VmCsluP3dQSbOGI0yBfZY+1bYRr4Dm5LRin91ncWNhXaH UjrPyjctdX7HNZ/iHEFHVKrug4lhqj8YLfGg2042IXeJV3FdqlIN6j006urJWThrJ4pW 0BxEhKZPj26UpzmegX65mnIPxMMuRNJBdtz8Jymd8XWZnP7zYKylW7rejOcWZe2a+jRo 9O4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=GxVmD1Db/d3c17un96SKZ8zW6rb55ypU+VOWh/x52qY=; b=OXyE/8yPcIMbVoiFrAMNtgpCoh4zRptOzUBZCDqE4tubVsNUx6EmhYOOSOIPg017DM pNThAkzZneoWUVNvaeYjESwf7A3HcJWuLpLNWLkozpwxtpUEJdxwmTXIqsqMwrjw1Lp/ k91vabCkC5jIH7ZXrBBT8ZHXb+91Sk6RJ+l1J5ii/zx8RsESe9s1FKVi0d5jjaHezWY7 EKnSP6/E0OCC8+p2JL6SsMGDPu7gXhY5pDQsjdiatWv4ILY1ysC144w+VsJCy/ASJFyw o/Oq0/DO787TbiLHuzO/c6TQcYNfY0kk+a5wELWK2zx2+5E5u5pTbVyxCi+Xjq2Dl/tO qXSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si3960046plz.234.2019.08.16.05.26.42; Fri, 16 Aug 2019 05:27:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727371AbfHPMYx (ORCPT + 99 others); Fri, 16 Aug 2019 08:24:53 -0400 Received: from foss.arm.com ([217.140.110.172]:55808 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727021AbfHPMYu (ORCPT ); Fri, 16 Aug 2019 08:24:50 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F2E4E1597; Fri, 16 Aug 2019 05:24:49 -0700 (PDT) Received: from e121650-lin.cambridge.arm.com (e121650-lin.cambridge.arm.com [10.1.196.120]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B94E03F706; Fri, 16 Aug 2019 05:24:48 -0700 (PDT) From: Raphael Gault To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, jpoimboe@redhat.com Cc: peterz@infradead.org, catalin.marinas@arm.com, will.deacon@arm.com, julien.thierry.kdev@gmail.com, raph.gault+kdev@gmail.com, Raphael Gault Subject: [RFC v4 07/18] objtool: Introduce INSN_UNKNOWN type Date: Fri, 16 Aug 2019 13:23:52 +0100 Message-Id: <20190816122403.14994-8-raphael.gault@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190816122403.14994-1-raphael.gault@arm.com> References: <20190816122403.14994-1-raphael.gault@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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