From patchwork Wed Mar 3 17:09:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Thierry X-Patchwork-Id: 12114579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F474C433E0 for ; Wed, 3 Mar 2021 23:49:25 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 91E4164F1E for ; Wed, 3 Mar 2021 23:49:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 91E4164F1E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=lkf2lJJocwGiDk4xLO21A90wxIO39B+ahPRJf9nsel4=; b=hNQOwLMDGhOgzvXDwjuUvhM2V6 MOAPZpyy2e8KuKhq0RxUla2vUfq42tvHETfHCppBJo0IMhnulyldozy5V3A/CDl2izWpHiKEo53id dpKHhCftMrg6hR9+iewUSryBk8uMovQnCJnLXoik0svnKo7mHU7Kflzl+yHceO5AlCvcyvF/tI/Mg Jsx5ZZZFsAQdMFVSorRqpGeZX4qeZTAiv2RFbpRA6YRwh25+xTddRMywVTOshEA5qCNUylC5ndDcp IoxBplb5zG/UnuC62x07neGaVAPyiElqlf3A6s2KelDX15bVcM0e7O1kxOR5oPEvAC8Gqv2pcDDKb sDyq9AmQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHbAc-0070lf-Vm; Wed, 03 Mar 2021 23:44:53 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHV0H-005jpz-27 for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 17:09:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614791380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AyP7XyWOerV6bQP5NUQox0rNDwSmxoyRKouf6vnaFy4=; b=W8LgH4wgVRlT2Sn3KolIgaPwVQKHK4839h5h8nFC8oDryCduHO6K7T9EHIMq7EC4hrzq25 1IQZ84S7Ar/fKLF8U1DGEqCJpjWQN+jNd5tB6MpQIVVcK69gbCBogaS+Ug9tbjRUIGC76F g+Vvh/3NYUD7qyf7cYJT8Ut0hT54u7w= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-273-rf3TMxSGO76lCIemBQD8Zg-1; Wed, 03 Mar 2021 12:09:36 -0500 X-MC-Unique: rf3TMxSGO76lCIemBQD8Zg-1 Received: by mail-wr1-f71.google.com with SMTP id h21so8606476wrc.19 for ; Wed, 03 Mar 2021 09:09:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AyP7XyWOerV6bQP5NUQox0rNDwSmxoyRKouf6vnaFy4=; b=GLtLn84ERfHqFGF9b5NzoK9AQRYzIdtwQDZOeb+RL1dXVEvqHsHkMpLzmtyznlEXok +7BVCbN007p9nwLtau++0KFYa94lrTgr6Uk5PfmdA3X4o6L4gkr1BmNt2f7ZEE4LNQe2 FgSRW6+y82iF0eq7uDnKw+10mIu1fyKOchIMbVvCN4ziKBmBwnUBIfqKhJp4BFqZhUUJ EMIZyP0WyzU/5vDMnCGoXcotkYvXrHrj2Q+j2rSLFUBI6vmlKiXrPNuBfpG7wYng1yWA vR5Hb/FS7nXV5ka0KyVhC6bjraVgioc1+gp4xxcPnRtciBtWdr2n94FI2iN9ncPiKMRD ohqQ== X-Gm-Message-State: AOAM531u1TbiN7UhTXM3Z+LR61t52R4PUn9HKju3DD8GPl+8imEwCizn 3n6NrjebtlxbtmD3XOjx4CWRhkjEkuD6io3N5Z4IL49lAwyPrapQCLorWRiXSELBts0RGEeqMRg +XisqBrpaAk89BGYT+pMCWS4alELurRO+itc= X-Received: by 2002:a05:600c:22cd:: with SMTP id 13mr46998wmg.90.1614791374931; Wed, 03 Mar 2021 09:09:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNVbYdS11FS37BObPTFWeOE7ivO33aOuZ+b/Rql41/bTfHxHQFbqZa/vdari+l7+Fe6dP5IQ== X-Received: by 2002:a05:600c:22cd:: with SMTP id 13mr46985wmg.90.1614791374797; Wed, 03 Mar 2021 09:09:34 -0800 (PST) Received: from redfedo.redhat.com ([2a01:cb14:499:3d00:cd47:f651:9d80:157a]) by smtp.gmail.com with ESMTPSA id r7sm33066226wre.25.2021.03.03.09.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 09:09:34 -0800 (PST) From: Julien Thierry To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ardb@kernel.org, masahiroy@kernel.org, jpoimboe@redhat.com, peterz@infradead.org, ycote@redhat.com, Julien Thierry Subject: [RFC PATCH v2 00/13] objtool: add base support for arm64 Date: Wed, 3 Mar 2021 18:09:19 +0100 Message-Id: <20210303170932.1838634-1-jthierry@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jthierry@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Hi, This series enables objtool to start doing stack validation on arm64 kernel builds. It relies on the previous series I sent, refactoring the arm64 decoder [1]. First, the aarch64 instruction decoder needed to be made available to code under tools/. This is done in a similar manner to x86 instruction decoded. One limitation I encountered there is that most of aarch64 instruction decoder is __kprobe annotated. To bypass that it remove the kprobe include and had to add an empty __kprobe definition, but I'd welcome a proper solution to that. Then instruction semantics are progressively added so objtool can track the stack state through the execution flow. There are a few things that needed consideration: - Generation of constants within executable sections, these either caused objtool to fail decoding or to wrongly decode constants as jumps or other instructions affecting execution flow and causing confusion. To solve this, tracking locations referenced by instructions using literals was needed. - Jump tables from switch statements in aarch64 don't have enough information to link branches with the branch instruction leading to them. Following suggestions, I've dropped the previously used GCC plugin and instead disabled the generation of jump tables by the compiler. I've not noticed performance deterioration nor concerning Image size increase after doing so. This approach has the benefit of working for both GCC and clang. With those changes, there are still some errors when building with objtool. A number of cleanups/annotations are needed on the arm64, as well as handling SYM_DATA objects in objtool. Those changes can be found on top of this branch here: git clone https://github.com/julien-thierry/linux.git -b objtoolxarm64-latest Changes since v1[2]: - Drop gcc plugin in favor of -fno-jump-tables - miscelaneous fixes and cleanups [1] https://lkml.org/lkml/2021/1/20/791 [2] https://lkml.org/lkml/2021/1/20/923 Thanks, Julien --> Julien Thierry (12): 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 padding in code sections objtool: arm64: Handle supported relocations in alternatives objtool: arm64: Ignore replacement section for alternative callback Raphael Gault (1): objtool: arm64: Enable stack validation for arm64 arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 4 + tools/arch/arm64/include/asm/insn.h | 565 +++++++ tools/arch/arm64/lib/insn.c | 1456 +++++++++++++++++ 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 | 502 ++++++ .../arch/arm64/include/arch/cfi_regs.h | 14 + tools/objtool/arch/arm64/include/arch/elf.h | 6 + .../arch/arm64/include/arch/endianness.h | 9 + .../objtool/arch/arm64/include/arch/special.h | 21 + tools/objtool/arch/arm64/special.c | 37 + tools/objtool/arch/x86/decode.c | 5 + tools/objtool/check.c | 6 + tools/objtool/include/objtool/arch.h | 3 + tools/objtool/sync-check.sh | 5 + 20 files changed, 2720 insertions(+), 5 deletions(-) create mode 100644 tools/arch/arm64/include/asm/insn.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 Acked-by: Peter Zijlstra (Intel) Signed-off-by: Julien Thierry Tested-by: Nick Desaulniers --- 2.25.4