From patchwork Fri Apr 29 09:43:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Zhongjin X-Patchwork-Id: 12831727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0A43C433FE for ; Fri, 29 Apr 2022 10:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=S8i26q/SJjGmv5Fi94DCAWOaLQMWYZJCyzrXcpR38ug=; b=mwZDbY9fTVZIPd LUTrkOaSx2YUhVVEsBfr3VnV9tKKhE7mHAZt2wEfNH142jwAvjT2QEsjOAwZITBI6GPjg0Lh2z/8q RsaU0t4E68o2O/WEvOP/KffOuUpHGHqC97HqInSY8bUezTM1L5mL7GtcLsPsY0tNIuHL3gMQtLGfV MgpH3d5sgM6QR4WanYN5baLfztdlYDV4SsrPblGE7D6LbXuSjq6CnasLdU0UMX5soIlI2UsZNzIsD jpKOSKYlur6FZa6ncxIF6i3jJfumGqL45dkN6yqMCX3aXxUSna8UH8qRoFg2gD1Cli1th+NaDa59i ujy7tmjuYbhTlAxkx5Tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNZS-00Ae14-HE; Fri, 29 Apr 2022 10:09:54 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNC9-00ATlu-TA for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Apr 2022 09:45:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:Message-ID: Date:Subject:CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=XvFr9bUdv2Dad9bIeKJFdkhZYX3neMP51GoenLDhwEk=; b=HYZN3KyTNBNNXLcycqJlTTLdlf hNOVXy+M296Ac18SVLPpP4RSJYwzSSFJMdAuR0ryvxdQ1fSvwZqlRYcz+k87JgUE+4dYJnSzMeNbv lCzfD6qBstipLMZeNGD8ds/NMkm3idUqFOblAC65Cqa0umjT29OKA+rLETFYdiVUrVy5pdxWZoU9s EF4eQWazd7wOQ/Vh/90WojNWkaJqUi4+KepHAWAqb9dt+9PFeJ41G1qnHIJyrbimK56Dd9dAEmcA+ ErMwlhZBLgzPoKosVOhlXminD379knxtaczmmflbLxFGJUEkRkYBNdB8NrpXIAGYpN4M42ZnpHVzX cpoWhbOA==; Received: from szxga01-in.huawei.com ([45.249.212.187]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNC5-009ZrN-2L for linux-arm-kernel@lists.infradead.org; Fri, 29 Apr 2022 09:45:47 +0000 Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KqSJb5V4tzhYq4; Fri, 29 Apr 2022 17:45:03 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Apr 2022 17:45:09 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Apr 2022 17:45:09 +0800 From: Chen Zhongjin To: , , CC: , , , , , , , , , , , , , , Subject: [RFC PATCH v4 00/37] objtool: add base support for arm64 Date: Fri, 29 Apr 2022 17:43:18 +0800 Message-ID: <20220429094355.122389-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_104545_910378_BB56A236 X-CRM114-Status: GOOD ( 14.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This series enables objtool to start doing stack validation/check on arm64 kernel builds. Gathering Julien's previous work[1][2], now objtool can check build on arm64 build for defconfig and yesconfig, with only few unreachable warning. This series includes objtool part (1-15) and arm64 part (16-37), if necessary it can be taken apart as two series. I'm not sure that UNWIND_HINT added to entry (33-36) is complete and correct, because after Julien finished it there was a refactoring for entry. It will be fully tested after I implement unwinder_orc for arm64. [1] https://lkml.org/lkml/2021/3/3/1135 [2] https://github.com/julien-thierry/linux.git --- Changes v3 -> v4: - [1] fix EX_ENTRY_SIZE from 8 to 12. - [14-37] modify arm64 for supporting objtool, including annotation, asm code modification, ignoring some validation, to make objtool be enable to pass arm64 builds. Changes v2 -> v3: - [04] rebase Julien's version to mainstream and solve conflicts. - [05, 06, 08] Merge dumplicate "*type = INSN_OTHER". - [08, 09, 10] When meeting unrecognized instructions such as datas in .text code or 0x0 padding insns, last version used "loc->ignorable" to mark and remove them from objtool insn list. However there are two problems to do so: 1. when meeting insns can't be decoded or excluded, objtool will just stop. 2. deleting every insn can cause problems in fellow procedure. So I changed "record_invalid_insn" that we can delete one insn or just set it ignored. Now check will throw an error and going on when meeting undecodable instructions. Also, to prevent the confusion between "loc->ignorable" and "insn->ignore" I changed "ignore" to "delete". Changes v1 -> v2: - Drop gcc plugin in favor of -fno-jump-tables - miscelaneous fixes and cleanups ---> Chen Zhongjin (6): arm64: Add annotate_reachable() for objtools arm64: irq-gic: Replace unreachable() with -EINVAL arm64: ftrace: Skip validation of entry-ftrace.o arm64: bpf: Skip validation of ___bpf_prog_run arm64: Annotate ASM symbols with unknown stack state arm64: entry: Align stack size for alternative Julien Thierry (29): tools: Add some generic functions and headers tools: arm64: Make aarch64 instruction decoder available to tools tools: bug: Remove duplicate definition objtool: arm64: Add base definition for arm64 backend objtool: arm64: Decode add/sub instructions objtool: arm64: Decode jump and call related instructions objtool: arm64: Decode other system instructions objtool: arm64: Decode load/store instructions objtool: arm64: Decode LDR instructions objtool: arm64: Accept non-instruction data in code sections objtool: arm64: Handle supported relocations in alternatives objtool: arm64: Ignore replacement section for alternative callback objtool: check: Support data in text section objtool: arm64: Add unwind_hint support arm64: bug: Add reachable annotation to warning macros arm64: kgdb: Mark code following kgdb brk as reachable arm64: Set intra-function call annotations arm64: kernel: Skip validation of proton-pack.c.c and hibernate.c arm64: kernel: Skip validation of sigreturn32.o arm64: crypto: Remove unnecessary stackframe arm64: sleep: Properly set frame pointer before call arm64: Change symbol annotations arm64: efi-header: Mark efi header as data arm64: head: Mark constants as data arm64: proc: Mark constant as data arm64: crypto: Mark data in code sections arm64: entry: Annotate valid stack in kernel entry arm64: entry: Annotate code switching to tasks arm64: kvm: Annotate stack state for guest enter/exit code Raphael Gault (2): objtool: arm64: Enable stack validation for arm64 arm64: kernel: Skip validation of kuser32.o arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 4 + arch/arm64/crypto/aes-neonbs-core.S | 14 +- arch/arm64/crypto/crct10dif-ce-core.S | 5 + arch/arm64/crypto/poly1305-armv8.pl | 4 + arch/arm64/crypto/sha512-armv8.pl | 29 +- arch/arm64/include/asm/assembler.h | 2 + arch/arm64/include/asm/bug.h | 6 +- arch/arm64/include/asm/kgdb.h | 1 + arch/arm64/include/asm/unwind_hints.h | 27 + arch/arm64/kernel/Makefile | 10 + arch/arm64/kernel/cpu-reset.S | 2 + arch/arm64/kernel/efi-entry.S | 2 + arch/arm64/kernel/efi-header.S | 2 + arch/arm64/kernel/entry.S | 29 +- arch/arm64/kernel/head.S | 75 +- arch/arm64/kernel/hibernate-asm.S | 2 + arch/arm64/kernel/hibernate.c | 2 + arch/arm64/kernel/proton-pack.c | 2 + arch/arm64/kernel/relocate_kernel.S | 2 + arch/arm64/kernel/sleep.S | 8 +- arch/arm64/kvm/hyp/entry.S | 7 +- arch/arm64/kvm/hyp/hyp-entry.S | 3 + arch/arm64/kvm/hyp/vgic-v3-sr.c | 7 +- arch/arm64/mm/proc.S | 4 +- drivers/irqchip/irq-gic-v3.c | 2 +- include/linux/compiler.h | 9 + kernel/bpf/core.c | 3 + tools/arch/arm64/include/asm/insn.h | 565 +++++++ tools/arch/arm64/include/asm/unwind_hints.h | 27 + tools/arch/arm64/lib/insn.c | 1464 +++++++++++++++++ tools/include/asm-generic/bitops/__ffs.h | 11 + tools/include/linux/bug.h | 6 +- tools/include/linux/kernel.h | 21 + tools/include/linux/printk.h | 40 + tools/objtool/Makefile | 5 + tools/objtool/arch/arm64/Build | 8 + tools/objtool/arch/arm64/decode.c | 506 ++++++ .../arch/arm64/include/arch/cfi_regs.h | 14 + tools/objtool/arch/arm64/include/arch/elf.h | 8 + .../arch/arm64/include/arch/endianness.h | 9 + .../objtool/arch/arm64/include/arch/special.h | 22 + tools/objtool/arch/arm64/special.c | 36 + tools/objtool/arch/x86/decode.c | 5 + tools/objtool/check.c | 25 +- tools/objtool/elf.c | 14 + tools/objtool/include/objtool/arch.h | 3 + tools/objtool/include/objtool/elf.h | 1 + tools/objtool/sync-check.sh | 5 + 49 files changed, 2985 insertions(+), 74 deletions(-) create mode 100644 arch/arm64/include/asm/unwind_hints.h create mode 100644 tools/arch/arm64/include/asm/insn.h create mode 100644 tools/arch/arm64/include/asm/unwind_hints.h create mode 100644 tools/arch/arm64/lib/insn.c create mode 100644 tools/include/linux/printk.h create mode 100644 tools/objtool/arch/arm64/Build create mode 100644 tools/objtool/arch/arm64/decode.c create mode 100644 tools/objtool/arch/arm64/include/arch/cfi_regs.h create mode 100644 tools/objtool/arch/arm64/include/arch/elf.h create mode 100644 tools/objtool/arch/arm64/include/arch/endianness.h create mode 100644 tools/objtool/arch/arm64/include/arch/special.h create mode 100644 tools/objtool/arch/arm64/special.c