From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC3B9C433F5 for ; Mon, 18 Apr 2022 16:54:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346645AbiDRQ5A (ORCPT ); Mon, 18 Apr 2022 12:57:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346630AbiDRQ4k (ORCPT ); Mon, 18 Apr 2022 12:56:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 653B434BB4 for ; Mon, 18 Apr 2022 09:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300733; 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: in-reply-to:in-reply-to:references:references; bh=WHwtgBFXaVRPDxpgXVknAcXgf6im9N3NqhP05P8+ItY=; b=K+tLHQOcqfZJqA82ngLxu9EfYGZvJbRyelKKqYwawmF/hctj9LBgQ042fo11ncrIVdBp/n oerK0SYisg1sIg0vJJb7+OK8H451gp12QjeR/5C3f6oK1a1mhT0GqIb4iDYv1yRYgpnOKC LzMRiVd8AMJ07+eB/vrUy6ew3T0iVJ4= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-359-SHPNHb6tO6mlmiXqA_mGFA-1; Mon, 18 Apr 2022 12:50:54 -0400 X-MC-Unique: SHPNHb6tO6mlmiXqA_mGFA-1 Received: by mail-qv1-f72.google.com with SMTP id eo13-20020ad4594d000000b004466661ece9so1379959qvb.1 for ; Mon, 18 Apr 2022 09:50:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WHwtgBFXaVRPDxpgXVknAcXgf6im9N3NqhP05P8+ItY=; b=Cp20nsAWqDC9+AA2EFTaoLZPerTNyVXB8bMJOyWYrvh2u31x+uxWVTvG5yfNIy/+QQ Tj7z1wD5cihWeMvlTK785KJB4ZGbA5poo8Jlm8MnW+eJU0E09zgyZRgFE5hZeEEyRTTG q6Jf8mgPU/mYiPPE7cab98HXkfMeouDQNIwMW7Gqo3PMIws/kCgYZ+erw4fetIH3CjLU 4Lz71ob4RkW4LTqtkrxv/V8uJRDu/IRENKf6qnEaO7xaqWPM4peG6RmFsjLy/kZqX+vZ dLRqFAJqfXhZWiUf6NoC3iq5MgajX2YLnwG9JgsfIg35xwH8Gb1vEOIx/jbtOdN6EUOv PdIw== X-Gm-Message-State: AOAM532rS29tf7quGAg9RCoD7XLfsxfz6iv4dXZj1WAR7BcLn2c2/iN0 tXXm20r7zdo9lYYJTZT/1Ec4LF2SCr7ptLonHr0+18FthuqhZQGKcdwrTlu6o+WdPId21JmI6Z7 9I2WP4TiPLDr9cVOwN7ujDmCN X-Received: by 2002:a05:620a:6db:b0:69e:84e3:5059 with SMTP id 27-20020a05620a06db00b0069e84e35059mr5494234qky.709.1650300653947; Mon, 18 Apr 2022 09:50:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbWQYYsvn90H1BnF5L8o1UGM3/9JXhiIclvSAkzCGZCOu7kfxyf1pecjQS5e4NPEffWlm8uw== X-Received: by 2002:a05:620a:6db:b0:69e:84e3:5059 with SMTP id 27-20020a05620a06db00b0069e84e35059mr5494227qky.709.1650300653717; Mon, 18 Apr 2022 09:50:53 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:50:53 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 01/25] objtool: Enable unreachable warnings for CLANG LTO Date: Mon, 18 Apr 2022 09:50:20 -0700 Message-Id: <7b12df54bceeb0761fe9fc8269ea0c00501214a9.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With IBT support in, objtool is now fully capable of following vmlinux code flow in LTO mode. Start reporting unreachable warnings for Clang LTO as well. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 9717e6f6fb31..33c1ed581522 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -231,7 +231,7 @@ objtool_args =3D \ $(if $(part-of-module), --module) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 20f44504a644..9361a1ef02c9 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -140,7 +140,7 @@ objtool_link() if ! is_enabled CONFIG_FRAME_POINTER; then objtoolopt=3D"${objtoolopt} --no-fp" fi - if is_enabled CONFIG_GCOV_KERNEL || is_enabled CONFIG_LTO_CLANG; then + if is_enabled CONFIG_GCOV_KERNEL; then objtoolopt=3D"${objtoolopt} --no-unreachable" fi if is_enabled CONFIG_RETPOLINE; then --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CC98C433F5 for ; Mon, 18 Apr 2022 16:51:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346475AbiDRQxo (ORCPT ); Mon, 18 Apr 2022 12:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346454AbiDRQxi (ORCPT ); Mon, 18 Apr 2022 12:53:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 407493191E for ; Mon, 18 Apr 2022 09:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300657; 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: in-reply-to:in-reply-to:references:references; bh=osWjVIWrfBrDOezJiYzosX0/AGt77HLN11DnBu9dxXM=; b=i7VVms6jL6Uy+5pXQROLzlFHRFCfb+fRPrqylv3jTkr4S71WOUXhJjAOc7yVaiLM2qurBS YY8yFXr0E9UfaNhIqd89VOAlLDRYQ6lu6ljhEeT4FqFIbj5eiWvkqFwetLkGqqdCStkc2M iXXVssOvnyx9emvMBXU+ee+WEa7DD+w= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-526-2wAx_jr8NJW8hqmOrG3_DA-1; Mon, 18 Apr 2022 12:50:56 -0400 X-MC-Unique: 2wAx_jr8NJW8hqmOrG3_DA-1 Received: by mail-qk1-f200.google.com with SMTP id t3-20020a05620a034300b0069e60a0760cso5644348qkm.20 for ; Mon, 18 Apr 2022 09:50:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=osWjVIWrfBrDOezJiYzosX0/AGt77HLN11DnBu9dxXM=; b=IdfO3sSsCYCPNqkohlWz4umwaclgRcxQ7xEG/XFiFkf0UtwtqOrnM6ATOOlu64mN/z JUSjnBT7WKwswVKGf1awZD4rqXG9n/9icFcpayCTo0n75cDLyfMbWe4mtL5ooZ3UK5BC pmcde1qtiPeM92GSpqa+K1S9nTL1M9QeNiQWKPQ5bCsDL0HuByc7Va8R6ypwL/6gagEr 9hcnCcLpzZ9Dl9JBDpX98HMxxTGDDyio3UmUmz55gIIrtZtHuWmnhRUS2Nn3QDVTOeef E/xZbfto+ImzequnUIZyJryPfKTbNjzq83HwN6rVCO0hOofCfKlZ7X7RdvOMgKquDyum HxnA== X-Gm-Message-State: AOAM533wkvVVLtkNk7ytnQ4vzQUNvBZ0OinvcPxtVYrWNe0IN7rZWOEg XLMeztJ/wY4eBuP1mW5/OxnUAAPhvKH2Py7tMaZXkLgCHtKvSzRhItiNgFGrKS6RJ/80gR/3FRd cfddrw8wsoXdTXyRIBN2guRlL X-Received: by 2002:a05:6214:2465:b0:446:6211:5ebb with SMTP id im5-20020a056214246500b0044662115ebbmr3361531qvb.56.1650300655567; Mon, 18 Apr 2022 09:50:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVa23kvS7eV3rLCazqxaSIEzbz1+8n7UWX5S6UH77Lfnn2xlvKnBMfjKgC7TKh0tDHy10ooQ== X-Received: by 2002:a05:6214:2465:b0:446:6211:5ebb with SMTP id im5-20020a056214246500b0044662115ebbmr3361515qvb.56.1650300655351; Mon, 18 Apr 2022 09:50:55 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:50:54 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 02/25] libsubcmd: Fix OPTION_GROUP sorting Date: Mon, 18 Apr 2022 09:50:21 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The OPTION_GROUP option type is a way of grouping certain options together in the printed usage text. It happens to be completely broken, thanks to the fact that the subcmd option sorting just sorts everything, without regard for grouping. Luckily, nobody uses this option anyway, though that will change shortly. Fix it by sorting each group individually. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/lib/subcmd/parse-options.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-opti= ons.c index 39ebf6192016..9fa75943f2ed 100644 --- a/tools/lib/subcmd/parse-options.c +++ b/tools/lib/subcmd/parse-options.c @@ -806,9 +806,9 @@ static int option__cmp(const void *va, const void *vb) =20 static struct option *options__order(const struct option *opts) { - int nr_opts =3D 0, len; + int nr_opts =3D 0, nr_group =3D 0, len; const struct option *o =3D opts; - struct option *ordered; + struct option *opt, *ordered, *group; =20 for (o =3D opts; o->type !=3D OPTION_END; o++) ++nr_opts; @@ -819,7 +819,18 @@ static struct option *options__order(const struct opti= on *opts) goto out; memcpy(ordered, opts, len); =20 - qsort(ordered, nr_opts, sizeof(*o), option__cmp); + /* sort each option group individually */ + for (opt =3D group =3D ordered; opt->type !=3D OPTION_END; opt++) { + if (opt->type =3D=3D OPTION_GROUP) { + qsort(group, nr_group, sizeof(*opt), option__cmp); + group =3D opt + 1; + nr_group =3D 0; + continue; + } + nr_group++; + } + qsort(group, nr_group, sizeof(*opt), option__cmp); + out: return ordered; } --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56649C433EF for ; Mon, 18 Apr 2022 16:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346491AbiDRQxq (ORCPT ); Mon, 18 Apr 2022 12:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346448AbiDRQxi (ORCPT ); Mon, 18 Apr 2022 12:53:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8F764D7E for ; Mon, 18 Apr 2022 09:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300658; 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: in-reply-to:in-reply-to:references:references; bh=cFMZBcKeNEtIudKn1NS45Ib5lceaaa4pYmyAHupkw94=; b=RyJOAic0E+rAH89oUoKIq32M11fo+hUY2rueyw6SlunpNA8bhB6+YSYDSR5Xi7A6j2hbX7 8WsGcMiA5K6ap9LuboFEFQKrn1GGBC75wH8nbABw7iWKOz81qHTXfnUAXjgXX4eRxVLhWP hI2/m2ZuqAK9R5lwr+XjI0cqp5z894k= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-GhEKWKr7MbuzRKe-cAa6-Q-1; Mon, 18 Apr 2022 12:50:57 -0400 X-MC-Unique: GhEKWKr7MbuzRKe-cAa6-Q-1 Received: by mail-qk1-f200.google.com with SMTP id i2-20020a05620a248200b0067b51fa1269so10726462qkn.19 for ; Mon, 18 Apr 2022 09:50:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cFMZBcKeNEtIudKn1NS45Ib5lceaaa4pYmyAHupkw94=; b=UEKxDIx1eSGIf3VOoLm+HRZjj5aLBH8YEnvoDU3RHlr6jOpe9B/fKLBicBnydKz2zy Fv+hVuQPrB2UNmi+nNNoJbjFlBLNg8KxPGpuH2ZW8vCEhKDiTL+PTICFHKf0CUN/FQ0f 0pPOMqQnbq1tMuPAafEY2olvATbXx9MXcOP3xJoN/uaXorp1y5rz3qOGhfMj9heM5euc cHEIy8z9tvs63f6Z5rWjJJq2NHcqKgl3d8kw8YxZnOmxKSADN4WPMbsxUll2wl+vp4J9 qJFKTpqZu4+LNQAIdSIBWtei5Y/pw87pt0wxJcZF+ZyTQJ//Zxs4HATPoltPFRoRbeUh /tdA== X-Gm-Message-State: AOAM532n4psaGJkIky6E7txSnyqAdzNWwaVZMVSph4m+mpkFNLC0ffDV 6YOwp6LsvPkLZIoDuZFaNh61Mt4x18f7qhAZkvmAzHNpstph4iqMTM5QSIdhX8UDxsDIssi9cnt eOTHMVs4LHtzni7RSZ3AecobC X-Received: by 2002:a37:a8c2:0:b0:69e:a2cc:4c98 with SMTP id r185-20020a37a8c2000000b0069ea2cc4c98mr2839990qke.498.1650300656843; Mon, 18 Apr 2022 09:50:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl17qN6rHIZYjeLx+PeVfsalj8j7kBxkVuqNIqN0MLchaHBr3kU+kyEb43YUMUGijybavP6Q== X-Received: by 2002:a37:a8c2:0:b0:69e:a2cc:4c98 with SMTP id r185-20020a37a8c2000000b0069ea2cc4c98mr2839978qke.498.1650300656632; Mon, 18 Apr 2022 09:50:56 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:50:56 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 03/25] x86/static_call: Add ANNOTATE_NOENDBR to static call trampoline Date: Mon, 18 Apr 2022 09:50:22 -0700 Message-Id: <1b5b54aad7d81241dabe5e0c9b40dea64b540b00.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The static call trampoline is never indirect-branched to, but is referenced by the static call key. Add ANNOTATE_NOENDBR. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- arch/x86/include/asm/static_call.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/include/asm/static_call.h b/arch/x86/include/asm/stat= ic_call.h index 2455d721503e..2d8dacd02643 100644 --- a/arch/x86/include/asm/static_call.h +++ b/arch/x86/include/asm/static_call.h @@ -26,6 +26,7 @@ ".align 4 \n" \ ".globl " STATIC_CALL_TRAMP_STR(name) " \n" \ STATIC_CALL_TRAMP_STR(name) ": \n" \ + ANNOTATE_NOENDBR \ insns " \n" \ ".byte 0x53, 0x43, 0x54 \n" \ ".type " STATIC_CALL_TRAMP_STR(name) ", @function \n" \ --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35FD1C433F5 for ; Mon, 18 Apr 2022 16:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346500AbiDRQxx (ORCPT ); Mon, 18 Apr 2022 12:53:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346468AbiDRQxj (ORCPT ); Mon, 18 Apr 2022 12:53:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D2F0FD7E for ; Mon, 18 Apr 2022 09:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300660; 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: in-reply-to:in-reply-to:references:references; bh=48jjM5HXT45OIsfY3WrkDs8DADHlQHjvA+yMQTd4lCs=; b=jAYY3hjwxvUIpTHgCcI4+FeXnUDlVDzOGjHB3HwExhb531TM8n66KVNTS68BHHBhRSfBOp EtnLd3ZG+/qUR1PyDvaxcftMG2HDx4nP3SGOUNkJB5kkhc8pvydDul051dvwyWs3bubxYz IVtjn3/6bqDIHy3YGxP6rUaJJ+v+2Q4= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-180-s54vGoitOzq5IX4NAHlpWA-1; Mon, 18 Apr 2022 12:50:59 -0400 X-MC-Unique: s54vGoitOzq5IX4NAHlpWA-1 Received: by mail-qk1-f200.google.com with SMTP id j24-20020a37ef18000000b0069eafae30b1so1254132qkk.8 for ; Mon, 18 Apr 2022 09:50:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=48jjM5HXT45OIsfY3WrkDs8DADHlQHjvA+yMQTd4lCs=; b=gNpZF7WMSU4dIMoKA3DDbymvl7zTsypYHLwD3JF98IZcBCUJONG96IUMLI5YVXW/BH fu6UUCgseOXQ4wAeYl87glpaP5C6FK5YlxYUMU6m8iguBOUmo/02S2ZF8ssIcHs5Gry/ OJ3Wkkz41FfrekLuFG5v5YyOrZixiMfBRO7HrzuFHWhrvXKLX6tE4ZiCtxH8fMMAQ0W1 /DTnE/l+U8qhBWWdEJ12vtURiHDT9APJ2guzVbzlmE64Ygpzj1DqJekHECsT9BB6uau2 xk6ONH37kLlZLM+q8Lm5bH+iKvLCYGLtuPk2ZwPgNPwhj6RwKPHtCwy/qeFFDNfCVTDU FeBw== X-Gm-Message-State: AOAM530k0QAiz7jvEcDc/Z8jKyIgSx9lB3SpabqNxKjaQUT7L3GkmhjL erfrfr57V4SbOmJECK8ndnom33mSSzxzFtJbKQhPkKy/arLiInF5RfdwfBjnpBZog/FfHjYvDqo bJB21pDHqrKf3WPj6/CtQqiLt X-Received: by 2002:a05:6214:21c2:b0:446:529d:fbee with SMTP id d2-20020a05621421c200b00446529dfbeemr5513839qvh.106.1650300658360; Mon, 18 Apr 2022 09:50:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbBZRur0h9SOohoqwsVBNU0gRxrL7hGLYqFSHnRwOPSyIvfl1mNSPBxw8wUo87pNKAl5lhfw== X-Received: by 2002:a05:6214:21c2:b0:446:529d:fbee with SMTP id d2-20020a05621421c200b00446529dfbeemr5513831qvh.106.1650300658137; Mon, 18 Apr 2022 09:50:58 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:50:57 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 04/25] x86/retpoline: Add ANNOTATE_ENDBR for retpolines Date: Mon, 18 Apr 2022 09:50:23 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The retpolines are exported, so they're referenced by ksymtab sections. But they're never indirect-branched to, so add ANNOTATE_ENDBR. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- arch/x86/lib/retpoline.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S index 5f87bab4fb8d..b2b2366885a2 100644 --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -31,6 +31,7 @@ .align RETPOLINE_THUNK_SIZE SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) UNWIND_HINT_EMPTY + ANNOTATE_NOENDBR =20 ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \ __stringify(RETPOLINE \reg), X86_FEATURE_RETPOLINE, \ @@ -55,7 +56,6 @@ SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) =20 .align RETPOLINE_THUNK_SIZE SYM_CODE_START(__x86_indirect_thunk_array) - ANNOTATE_NOENDBR // apply_retpolines =20 #define GEN(reg) THUNK reg #include --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CC95C43219 for ; Mon, 18 Apr 2022 16:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346539AbiDRQx4 (ORCPT ); Mon, 18 Apr 2022 12:53:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346477AbiDRQxo (ORCPT ); Mon, 18 Apr 2022 12:53:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0601F32987 for ; Mon, 18 Apr 2022 09:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300664; 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: in-reply-to:in-reply-to:references:references; bh=+Isq+zk2J624eZUtPJ7xeNC7xKsJH08BlurzTHOz018=; b=dmULEkPXkZ+44rHlwvw+WlRgVYk8tFZPVfkvSb8SWLoiPcBDjtl1lXM6P6N6a4qNdV54x0 irEuQ81UPeL3EjzXX7R526S/qd125Db8vivNvSZok0/gnYHsJRLCReMzVpchu97TcFy2lB xIz+/cGVz0GN6KzLrTs97vL23IXDle0= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-607-s_38F6OSNuet_ZOU4n_sLA-1; Mon, 18 Apr 2022 12:51:00 -0400 X-MC-Unique: s_38F6OSNuet_ZOU4n_sLA-1 Received: by mail-qv1-f70.google.com with SMTP id fw9-20020a056214238900b0043522aa5b81so12520909qvb.21 for ; Mon, 18 Apr 2022 09:51:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Isq+zk2J624eZUtPJ7xeNC7xKsJH08BlurzTHOz018=; b=wV0zMV8BEmbaWSja5p6aPQjW/yaDYD568GkhW/1HzYVf7VK1yVHUwga3KDVFJMeB7y J4nctN4g7zqyyWRtfP11xeRCoHddtx2urFffqUo7qJxzZAOzCtv0JLPBvo0dBulnMZR9 vAPV50KQRInT96FmfAztda/p4sw93x38Zd4LgluvumKeSJmZZP5D7uvIRcZGrqYiBrny HytyAb7GY8ggt5MaeH9YQl+MjLtmyfR2PX5BQqaaiMiR1CG53UvDzxmFAxTPdHzJVAos UrzJHD8iDa2IlKt5vnmK6RNWfCQXEdbIxtpA8bS+KBSljI+OU8McMpOkXbWXPiO9AkCp L41w== X-Gm-Message-State: AOAM531qfaIaaPsQUBWaItv8Kk5l9M0o4IsJwg2g2tnGMhcMQEFMZ+cl 0v/ATPcmo7avTyOCc3NXMdeKpORZeFvG+7x9YSMFeyva+Ixsm/WUhT6YMY86sYNMHGJX+B6p8bZ HoE9pdMir50BnfBj5lVSQekSx X-Received: by 2002:a05:6214:20e5:b0:446:393a:7a92 with SMTP id 5-20020a05621420e500b00446393a7a92mr8548541qvk.28.1650300659848; Mon, 18 Apr 2022 09:50:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYc+FvYh1h+v+kvPfKOugyUq+1wP14a+dUTKuPyQe3QRiLPbOn6dwC9bFi1bx0St6bGBBWkw== X-Received: by 2002:a05:6214:20e5:b0:446:393a:7a92 with SMTP id 5-20020a05621420e500b00446393a7a92mr8548531qvk.28.1650300659602; Mon, 18 Apr 2022 09:50:59 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:50:59 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 05/25] x86/uaccess: Add ENDBR to __put_user_nocheck*() Date: Mon, 18 Apr 2022 09:50:24 -0700 Message-Id: <207f02177a23031091d1a608de6049a9e5e8ff80.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The __put_user_nocheck*() inner labels are exported, so in keeping with the "allow exported functions to be indirectly called" policy, add ENDBR. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- arch/x86/lib/putuser.S | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S index ecb2049c1273..b7dfd60243b7 100644 --- a/arch/x86/lib/putuser.S +++ b/arch/x86/lib/putuser.S @@ -48,6 +48,7 @@ SYM_FUNC_START(__put_user_1) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_1, SYM_L_GLOBAL) + ENDBR ASM_STAC 1: movb %al,(%_ASM_CX) xor %ecx,%ecx @@ -62,6 +63,7 @@ SYM_FUNC_START(__put_user_2) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_2, SYM_L_GLOBAL) + ENDBR ASM_STAC 2: movw %ax,(%_ASM_CX) xor %ecx,%ecx @@ -76,6 +78,7 @@ SYM_FUNC_START(__put_user_4) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_4, SYM_L_GLOBAL) + ENDBR ASM_STAC 3: movl %eax,(%_ASM_CX) xor %ecx,%ecx @@ -90,6 +93,7 @@ SYM_FUNC_START(__put_user_8) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_8, SYM_L_GLOBAL) + ENDBR ASM_STAC 4: mov %_ASM_AX,(%_ASM_CX) #ifdef CONFIG_X86_32 --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1650300701; cv=none; d=zohomail.com; s=zohoarc; b=mM6C+TYmpwwvF+pjt9wHtWzCN0/CALDelHEwPcKTOwvIvVDRTyhSKNsVXst3YovOJlGWlWqOSopMiuSHGiQU5ETt0GNZHw1I8LJu/LTwXfReP0+QWvGiKYjnIdlFeMPBFVVQqaQCFReGyfjrPBAIi1z6qgZtsqhFM1UClUUa99I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650300701; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sKtm4nbSU3FWhhvlPNHt662yt7zgfxklNVpsEjzLR6E=; b=V/GYszDNa/jtpvrQtYfY2Go287nXj/zT8GQQaOqszn/CmEVx/WfDrHAsmV2T0jmAKqXvaJYplcLKZMtNKyjWaG1lnJlKuETm8Tck9sEJpysegcyqObCPpKtm8fcZk14PGaTG9aY0OLOujU2P2wT++SYpqzrg6O79C84Y7W71/aU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1650300701606387.1386184289761; Mon, 18 Apr 2022 09:51:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.307308.522630 (Exim 4.92) (envelope-from ) id 1ngUal-0003bW-T9; Mon, 18 Apr 2022 16:51:11 +0000 Received: by outflank-mailman (output) from mailman id 307308.522630; Mon, 18 Apr 2022 16:51:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngUal-0003bP-QB; Mon, 18 Apr 2022 16:51:11 +0000 Received: by outflank-mailman (input) for mailman id 307308; Mon, 18 Apr 2022 16:51:11 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngUak-0003bJ-RP for xen-devel@lists.xenproject.org; Mon, 18 Apr 2022 16:51:10 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bd02f26e-bf37-11ec-8fbe-03012f2f19d4; Mon, 18 Apr 2022 18:51:06 +0200 (CEST) Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-385-IgKty319Nm2wMqn5SMYLQw-1; Mon, 18 Apr 2022 12:51:02 -0400 Received: by mail-qv1-f71.google.com with SMTP id dd5-20020ad45805000000b004461b16d4caso11286982qvb.16 for ; Mon, 18 Apr 2022 09:51:02 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:00 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bd02f26e-bf37-11ec-8fbe-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300665; 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: in-reply-to:in-reply-to:references:references; bh=sKtm4nbSU3FWhhvlPNHt662yt7zgfxklNVpsEjzLR6E=; b=jJv1fhUJRuWhH5UqA5skXagwnF6IbzWxhH4gUYAJRVJCle4I4H1sOCB4tGSQybfmg9zhD1 MAXm4yBrgVWI1V9vpD0MpQKH8ejU8d40bRkcOtkwr8zyrR1X2pRJ/UWn0BEjVfgIZcG4qK trtF9Ic8om1wCorcJFf08Mks95ctCOM= X-MC-Unique: IgKty319Nm2wMqn5SMYLQw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sKtm4nbSU3FWhhvlPNHt662yt7zgfxklNVpsEjzLR6E=; b=jHoDmafRTgEDH/Ru7RDYo41z5XEDkXGgs7+AFx0x7MqDyz5TIksSb9N90p58i8d+0j DPqmfpdNd6oNyuxaH3nPoLYEeaLclEEgaxxpFNi1zH4sLltuthcR2DEfkyKj9XzF1Ur2 YmuHXV3HtRs7pFudaaG9gEIdX+twDm/cbW8dMRDbb0TFmbvWcCKLv9jpD6sg2V1udvRS AhSVaJras9qtEIHJ0f8TwwEaTD4pefI1a1l2p7Y274WH9+A7VjwBX/X+//wvv+EFj//7 QvZzRs2eFegU7GUxZiQvngT8gkZ5OusDHO9hRnbEjN7PbpW8lmEglm9Mn99YXO8goOIf tJow== X-Gm-Message-State: AOAM532It8Xw5m/m+1jLKjysvRYKtbK0f3pRtzju4RolZcQLe8LysqvC rKW0BDTJDucxhwlaqWe9y+eLznNc4+SRhLpAvLN08G5X12NfOrCD0AS/p8tA7e2ppuxOL4AYEvn EHPWQaJP1SRLPncHBsId0Loqf+hQ= X-Received: by 2002:a05:620a:269a:b0:680:a5c5:954e with SMTP id c26-20020a05620a269a00b00680a5c5954emr7178497qkp.468.1650300661655; Mon, 18 Apr 2022 09:51:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5s03dJEz37yFRd0bt8VJZXKfEi+tgI60K56wnTALH0l5S//HMzNqbEJEbGM7GALoZ4yLkjw== X-Received: by 2002:a05:620a:269a:b0:680:a5c5:954e with SMTP id c26-20020a05620a269a00b00680a5c5954emr7178482qkp.468.1650300661440; Mon, 18 Apr 2022 09:51:01 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , xen-devel@lists.xenproject.org Subject: [PATCH v2 06/25] x86/xen: Add ANNOTATE_ENDBR to startup_xen() Date: Mon, 18 Apr 2022 09:50:25 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jpoimboe@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1650300703466100001 Content-Type: text/plain; charset="utf-8" The startup_xen() kernel entry point is referenced by the ".note.Xen" section, but is presumably not indirect-branched to. Add ANNOTATE_ENDBR to silence future objtool warnings. Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Stefano Stabellini Cc: xen-devel@lists.xenproject.org Signed-off-by: Josh Poimboeuf Reviewed-by: Andrew Cooper Reviewed-by: Miroslav Benes --- arch/x86/xen/xen-head.S | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index ac17196e2518..3a2cd93bf059 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -45,6 +45,7 @@ SYM_CODE_END(hypercall_page) __INIT SYM_CODE_START(startup_xen) UNWIND_HINT_EMPTY + ANNOTATE_NOENDBR cld =20 /* Clear .bss */ --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5D35C433FE for ; Mon, 18 Apr 2022 16:51:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346621AbiDRQyT (ORCPT ); Mon, 18 Apr 2022 12:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346470AbiDRQxx (ORCPT ); Mon, 18 Apr 2022 12:53:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 62D2232ED9 for ; Mon, 18 Apr 2022 09:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300665; 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: in-reply-to:in-reply-to:references:references; bh=lS29uWkkJ8a6EpY+6JJ/EOw00zqkHiPXZ5fHI1M7ja4=; b=gFF9JKEBFDUm8XK3Wf4CWFM5O7A1DSl54vICHRryB5k3DvhYRv41q8UJwgkTIW5CM+4qtr muJauaxpmrin7E9koIidLeuX1s5TsU3tFsPvn1ZII4geh4dKMbukd7QTipk2XvPK6t+VX0 8w5oWcNGqpNOhdBnXsF6Ws8K7xAlWEA= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-144-wG7qLpofPe65Y9egBycQ0A-1; Mon, 18 Apr 2022 12:51:04 -0400 X-MC-Unique: wG7qLpofPe65Y9egBycQ0A-1 Received: by mail-qt1-f198.google.com with SMTP id f22-20020ac840d6000000b002dd4d87de21so8807194qtm.23 for ; Mon, 18 Apr 2022 09:51:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lS29uWkkJ8a6EpY+6JJ/EOw00zqkHiPXZ5fHI1M7ja4=; b=ctX84pv7Ty61Qrz1TYKZBfMMutWsqNVZahgvJBdja226OfxiP3iYiS2t8Sts77+oVG d2w2zeKslh6as2eLy6nnpH/jmVEKJFw8DTQm1G8ktc+w7M372tPuTQzeWEoZQzubmST7 GRupJXWdsrjItyY6IOMnf0dnB9LWZNOMXwpk1/l2Y+uvhJUsIMfKaR0cJe+ksdOgPh1S y0j6sjQ6TviLWb/TRbn9mcUZEsgOJGbDXYsqkuyRmPvXvdIDlqzNkJoPhlPHba+jBvhp jGxdMT2rXcNRtFA9vFszjK4Rv9ujL4dX2CJRtwEKHIo48qDVTL67CncUZnaKZIhZUi7J 3QAg== X-Gm-Message-State: AOAM53138Jiu8iwyDaMtL+uJ52O0m9PQEqBWvIYfg/Yc9IGZE7mMlkO/ hAqJqArhc3uqZ05MbHLEgEIyIFQOKVj7coUug+ruKedvJUHSpqVU1ca0sZ64qDIYTLdEQsaIY3A lfypCRLLWdRHR9O7EOCxwp4vP X-Received: by 2002:a0c:f801:0:b0:427:47d3:3715 with SMTP id r1-20020a0cf801000000b0042747d33715mr8634485qvn.46.1650300663355; Mon, 18 Apr 2022 09:51:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPjMpEsK/2jge3v819fetC16e4+1ODT+QaCIosOViy5rmpqUBD8+swxtOizyDVWKNRoevh+g== X-Received: by 2002:a0c:f801:0:b0:427:47d3:3715 with SMTP id r1-20020a0cf801000000b0042747d33715mr8634466qvn.46.1650300663017; Mon, 18 Apr 2022 09:51:03 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:02 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 07/25] objtool: Reorganize cmdline options Date: Mon, 18 Apr 2022 09:50:26 -0700 Message-Id: <9dcaa752f83aca24b1b21f0b0eeb28a0c181c0b0.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Split the existing options into two groups: actions, which actually do something; and options, which modify the actions in some way. Also there's no need to have short flags for all the non-action options. Reserve short flags for the more important actions. While at it: - change a few of the short flags to be more intuitive - make option descriptions more consistently descriptive - sort options in the source like they are when printed - move options to a global struct Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- scripts/Makefile.build | 10 ++-- scripts/link-vmlinux.sh | 30 +++++++----- tools/objtool/arch/x86/decode.c | 2 +- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/builtin-check.c | 40 ++++++++-------- tools/objtool/check.c | 62 ++++++++++++------------- tools/objtool/elf.c | 8 ++-- tools/objtool/include/objtool/builtin.h | 26 +++++++++-- tools/objtool/objtool.c | 6 +-- 9 files changed, 108 insertions(+), 78 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 33c1ed581522..dd9d582808d6 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -228,14 +228,14 @@ objtool :=3D $(objtree)/tools/objtool/objtool =20 objtool_args =3D \ $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ - $(if $(part-of-module), --module) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ + $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ + $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ - $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ - $(if $(CONFIG_SLS), --sls) + $(if $(part-of-module), --module) \ + $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) =20 cmd_objtool =3D $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep =3D $(if $(objtool-enabled), { echo ; echo '$@: $$(wild= card $(objtool))' ; } >> $(dot-target).cmd) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 9361a1ef02c9..c6e9fef61b11 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -117,8 +117,6 @@ objtool_link() objtoolcmd=3D"orc generate" fi =20 - objtoolopt=3D"${objtoolopt} --lto" - if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt=3D"${objtoolopt} --ibt" fi @@ -126,6 +124,8 @@ objtool_link() if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then objtoolopt=3D"${objtoolopt} --mcount" fi + + objtoolopt=3D"${objtoolopt} --lto" fi =20 if is_enabled CONFIG_VMLINUX_VALIDATION; then @@ -133,25 +133,33 @@ objtool_link() fi =20 if [ -n "${objtoolopt}" ]; then + if [ -z "${objtoolcmd}" ]; then objtoolcmd=3D"check" fi - objtoolopt=3D"${objtoolopt} --vmlinux" - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt=3D"${objtoolopt} --no-fp" - fi - if is_enabled CONFIG_GCOV_KERNEL; then - objtoolopt=3D"${objtoolopt} --no-unreachable" - fi + if is_enabled CONFIG_RETPOLINE; then objtoolopt=3D"${objtoolopt} --retpoline" fi + + if is_enabled CONFIG_SLS; then + objtoolopt=3D"${objtoolopt} --sls" + fi + if is_enabled CONFIG_X86_SMAP; then objtoolopt=3D"${objtoolopt} --uaccess" fi - if is_enabled CONFIG_SLS; then - objtoolopt=3D"${objtoolopt} --sls" + + if ! is_enabled CONFIG_FRAME_POINTER; then + objtoolopt=3D"${objtoolopt} --no-fp" fi + + if is_enabled CONFIG_GCOV_KERNEL; then + objtoolopt=3D"${objtoolopt} --no-unreachable" + fi + + objtoolopt=3D"${objtoolopt} --vmlinux" + info OBJTOOL ${1} tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} fi diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 943cb41cddf7..8b990a52aada 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -581,7 +581,7 @@ int arch_decode_instruction(struct objtool_file *file, = const struct section *sec break; =20 case 0xc7: /* mov imm, r/m */ - if (!noinstr) + if (!opts.noinstr) break; =20 if (insn.length =3D=3D 3+4+4 && !strncmp(sec->name, ".init.text", 10)) { diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index e707d9bcd161..7c97b7391279 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -20,7 +20,7 @@ void arch_handle_alternative(unsigned short feature, stru= ct special_alt *alt) * find paths that see the STAC but take the NOP instead of * CLAC and the other way around. */ - if (uaccess) + if (opts.uaccess) alt->skip_orig =3D true; else alt->skip_alt =3D true; diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index fc6975ab8b06..bc447b3cd9f2 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -19,12 +19,10 @@ #include #include =20 -bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - lto, vmlinux, mcount, noinstr, backup, sls, dryrun, - ibt; +struct opts opts; =20 static const char * const check_usage[] =3D { - "objtool check [] file.o", + "objtool check [] file.o", NULL, }; =20 @@ -34,21 +32,25 @@ static const char * const env_usage[] =3D { }; =20 const struct option check_options[] =3D { - OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"), - OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable in= struction' warnings"), - OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions= "), - OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of= a kernel module"), - OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"), - OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"), - OPT_BOOLEAN('s', "stats", &stats, "print statistics"), - OPT_BOOLEAN(0, "lto", <o, "whole-archive like runs"), - OPT_BOOLEAN('n', "noinstr", &noinstr, "noinstr validation for vmlinux.o"), - OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"), - OPT_BOOLEAN('M', "mcount", &mcount, "generate __mcount_loc"), - OPT_BOOLEAN('B', "backup", &backup, "create .orig files before modificati= on"), - OPT_BOOLEAN('S', "sls", &sls, "validate straight-line-speculation"), - OPT_BOOLEAN(0, "dry-run", &dryrun, "don't write the modifications"), - OPT_BOOLEAN(0, "ibt", &ibt, "validate ENDBR placement"), + OPT_GROUP("Actions:"), + OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), + OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls fo= r ftrace"), + OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), + OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), + OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), + OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), + + OPT_GROUP("Options:"), + OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"), + OPT_BOOLEAN(0, "backup", &opts.backup, "create .orig files before modific= ation"), + OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), + OPT_BOOLEAN(0, "lto", &opts.lto, "whole-archive like runs"), + OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module= "), + OPT_BOOLEAN(0, "no-fp", &opts.no_fp, "skip frame pointer validation"), + OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable= instruction' warnings"), + OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), + OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"), + OPT_END(), }; =20 diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5bd3aa815d51..980f7bb0e954 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -274,7 +274,7 @@ static void init_insn_state(struct insn_state *state, s= truct section *sec) * not correctly determine insn->call_dest->sec (external symbols do * not have a section). */ - if (vmlinux && noinstr && sec) + if (opts.vmlinux && opts.noinstr && sec) state->noinstr =3D sec->noinstr; } =20 @@ -340,7 +340,7 @@ static void *cfi_hash_alloc(unsigned long size) if (cfi_hash =3D=3D (void *)-1L) { WARN("mmap fail cfi_hash"); cfi_hash =3D NULL; - } else if (stats) { + } else if (opts.stats) { printf("cfi_bits: %d\n", cfi_bits); } =20 @@ -435,7 +435,7 @@ static int decode_instructions(struct objtool_file *fil= e) } } =20 - if (stats) + if (opts.stats) printf("nr_insns: %lu\n", nr_insns); =20 return 0; @@ -498,7 +498,7 @@ static int init_pv_ops(struct objtool_file *file) struct symbol *sym; int idx, nr; =20 - if (!noinstr) + if (!opts.noinstr) return 0; =20 file->pv_ops =3D NULL; @@ -669,7 +669,7 @@ static int create_static_call_sections(struct objtool_f= ile *file) =20 key_sym =3D find_symbol_by_name(file->elf, tmp); if (!key_sym) { - if (!module) { + if (!opts.module) { WARN("static_call: can't find static_call_key symbol: %s", tmp); return -1; } @@ -762,7 +762,7 @@ static int create_ibt_endbr_seal_sections(struct objtoo= l_file *file) list_for_each_entry(insn, &file->endbr_list, call_node) idx++; =20 - if (stats) { + if (opts.stats) { printf("ibt: ENDBR at function start: %d\n", file->nr_endbr); printf("ibt: ENDBR inside functions: %d\n", file->nr_endbr_int); printf("ibt: superfluous ENDBR: %d\n", idx); @@ -1029,7 +1029,7 @@ static void add_uaccess_safe(struct objtool_file *fil= e) struct symbol *func; const char **name; =20 - if (!uaccess) + if (!opts.uaccess) return; =20 for (name =3D uaccess_safe_builtin; *name; name++) { @@ -1171,7 +1171,7 @@ static void annotate_call_site(struct objtool_file *f= ile, return; } =20 - if (mcount && sym->fentry) { + if (opts.mcount && sym->fentry) { if (sibling) WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset); =20 @@ -1257,7 +1257,7 @@ static bool is_first_func_insn(struct objtool_file *f= ile, struct instruction *in if (insn->offset =3D=3D insn->func->offset) return true; =20 - if (ibt) { + if (opts.ibt) { struct instruction *prev =3D prev_insn_same_sym(file, insn); =20 if (prev && prev->type =3D=3D INSN_ENDBR && @@ -1700,7 +1700,7 @@ static int add_special_section_alts(struct objtool_fi= le *file) free(special_alt); } =20 - if (stats) { + if (opts.stats) { printf("jl\\\tNOP\tJMP\n"); printf("short:\t%ld\t%ld\n", file->jl_nop_short, file->jl_short); printf("long:\t%ld\t%ld\n", file->jl_nop_long, file->jl_long); @@ -1946,7 +1946,7 @@ static int read_unwind_hints(struct objtool_file *fil= e) =20 insn->hint =3D true; =20 - if (ibt && hint->type =3D=3D UNWIND_HINT_TYPE_REGS_PARTIAL) { + if (opts.ibt && hint->type =3D=3D UNWIND_HINT_TYPE_REGS_PARTIAL) { struct symbol *sym =3D find_symbol_by_offset(insn->sec, insn->offset); =20 if (sym && sym->bind =3D=3D STB_GLOBAL && @@ -2807,7 +2807,7 @@ static int update_cfi_state(struct instruction *insn, } =20 /* detect when asm code uses rbp as a scratch register */ - if (!no_fp && insn->func && op->src.reg =3D=3D CFI_BP && + if (!opts.no_fp && insn->func && op->src.reg =3D=3D CFI_BP && cfa->base !=3D CFI_BP) cfi->bp_scratch =3D true; break; @@ -3365,7 +3365,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, =20 ret =3D validate_branch(file, func, alt->insn, state); if (ret) { - if (backtrace) + if (opts.backtrace) BT_FUNC("(alt)", insn); return ret; } @@ -3381,7 +3381,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, switch (insn->type) { =20 case INSN_RETURN: - if (sls && !insn->retpoline_safe && + if (opts.sls && !insn->retpoline_safe && next_insn && next_insn->type !=3D INSN_TRAP) { WARN_FUNC("missing int3 after ret", insn->sec, insn->offset); @@ -3394,7 +3394,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (ret) return ret; =20 - if (!no_fp && func && !is_fentry_call(insn) && + if (!opts.no_fp && func && !is_fentry_call(insn) && !has_valid_stack_frame(&state)) { WARN_FUNC("call without frame pointer save/setup", sec, insn->offset); @@ -3417,7 +3417,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, ret =3D validate_branch(file, func, insn->jump_dest, state); if (ret) { - if (backtrace) + if (opts.backtrace) BT_FUNC("(branch)", insn); return ret; } @@ -3429,7 +3429,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, break; =20 case INSN_JUMP_DYNAMIC: - if (sls && !insn->retpoline_safe && + if (opts.sls && !insn->retpoline_safe && next_insn && next_insn->type !=3D INSN_TRAP) { WARN_FUNC("missing int3 after indirect jump", insn->sec, insn->offset); @@ -3501,7 +3501,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, break; } =20 - if (ibt) + if (opts.ibt) validate_ibt_insn(file, insn); =20 if (insn->dead_end) @@ -3543,7 +3543,7 @@ static int validate_unwind_hints(struct objtool_file = *file, struct section *sec) while (&insn->list !=3D &file->insn_list && (!sec || insn->sec =3D=3D sec= )) { if (insn->hint && !insn->visited && !insn->ignore) { ret =3D validate_branch(file, insn->func, insn, state); - if (ret && backtrace) + if (ret && opts.backtrace) BT_FUNC("<=3D=3D=3D (hint)", insn); warnings +=3D ret; } @@ -3573,7 +3573,7 @@ static int validate_retpoline(struct objtool_file *fi= le) * loaded late, they very much do need retpoline in their * .init.text */ - if (!strcmp(insn->sec->name, ".init.text") && !module) + if (!strcmp(insn->sec->name, ".init.text") && !opts.module) continue; =20 WARN_FUNC("indirect %s found in RETPOLINE build", @@ -3623,7 +3623,7 @@ static bool ignore_unreachable_insn(struct objtool_fi= le *file, struct instructio * In this case we'll find a piece of code (whole function) that is not * covered by a !section symbol. Ignore them. */ - if (!insn->func && lto) { + if (!insn->func && opts.lto) { int size =3D find_symbol_hole_containing(insn->sec, insn->offset); unsigned long end =3D insn->offset + size; =20 @@ -3730,7 +3730,7 @@ static int validate_symbol(struct objtool_file *file,= struct section *sec, state->uaccess =3D sym->uaccess_safe; =20 ret =3D validate_branch(file, insn->func, insn, *state); - if (ret && backtrace) + if (ret && opts.backtrace) BT_FUNC("<=3D=3D=3D (sym)", insn); return ret; } @@ -3858,12 +3858,12 @@ int check(struct objtool_file *file) { int ret, warnings =3D 0; =20 - if (lto && !(vmlinux || module)) { + if (opts.lto && !(opts.vmlinux || opts.module)) { fprintf(stderr, "--lto requires: --vmlinux or --module\n"); return 1; } =20 - if (ibt && !lto) { + if (opts.ibt && !opts.lto) { fprintf(stderr, "--ibt requires: --lto\n"); return 1; } @@ -3888,7 +3888,7 @@ int check(struct objtool_file *file) if (list_empty(&file->insn_list)) goto out; =20 - if (vmlinux && !lto) { + if (opts.vmlinux && !opts.lto) { ret =3D validate_vmlinux_functions(file); if (ret < 0) goto out; @@ -3897,7 +3897,7 @@ int check(struct objtool_file *file) goto out; } =20 - if (retpoline) { + if (opts.retpoline) { ret =3D validate_retpoline(file); if (ret < 0) return ret; @@ -3914,7 +3914,7 @@ int check(struct objtool_file *file) goto out; warnings +=3D ret; =20 - if (ibt) { + if (opts.ibt) { ret =3D validate_ibt(file); if (ret < 0) goto out; @@ -3933,28 +3933,28 @@ int check(struct objtool_file *file) goto out; warnings +=3D ret; =20 - if (retpoline) { + if (opts.retpoline) { ret =3D create_retpoline_sites_sections(file); if (ret < 0) goto out; warnings +=3D ret; } =20 - if (mcount) { + if (opts.mcount) { ret =3D create_mcount_loc_sections(file); if (ret < 0) goto out; warnings +=3D ret; } =20 - if (ibt) { + if (opts.ibt) { ret =3D create_ibt_endbr_seal_sections(file); if (ret < 0) goto out; warnings +=3D ret; } =20 - if (stats) { + if (opts.stats) { printf("nr_insns_visited: %ld\n", nr_insns_visited); printf("nr_cfi: %ld\n", nr_cfi); printf("nr_cfi_reused: %ld\n", nr_cfi_reused); diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index d7b99a737496..f7b2ad27bb1c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -355,7 +355,7 @@ static int read_sections(struct elf *elf) elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); } =20 - if (stats) { + if (opts.stats) { printf("nr_sections: %lu\n", (unsigned long)sections_nr); printf("section_bits: %d\n", elf->section_bits); } @@ -475,7 +475,7 @@ static int read_symbols(struct elf *elf) elf_add_symbol(elf, sym); } =20 - if (stats) { + if (opts.stats) { printf("nr_symbols: %lu\n", (unsigned long)symbols_nr); printf("symbol_bits: %d\n", elf->symbol_bits); } @@ -700,7 +700,7 @@ static int read_relocs(struct elf *elf) tot_reloc +=3D nr_reloc; } =20 - if (stats) { + if (opts.stats) { printf("max_reloc: %lu\n", max_reloc); printf("tot_reloc: %lu\n", tot_reloc); printf("reloc_bits: %d\n", elf->reloc_bits); @@ -1079,7 +1079,7 @@ int elf_write(struct elf *elf) struct section *sec; Elf_Scn *s; =20 - if (dryrun) + if (opts.dryrun) return 0; =20 /* Update changed relocation sections and section headers: */ diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index c39dbfaef6dc..87c1a7351e3c 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -8,9 +8,29 @@ #include =20 extern const struct option check_options[]; -extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, = stats, - lto, vmlinux, mcount, noinstr, backup, sls, dryrun, - ibt; + +struct opts { + /* actions: */ + bool ibt; + bool mcount; + bool noinstr; + bool retpoline; + bool sls; + bool uaccess; + + /* options: */ + bool backtrace; + bool backup; + bool dryrun; + bool lto; + bool module; + bool no_fp; + bool no_unreachable; + bool stats; + bool vmlinux; +}; + +extern struct opts opts; =20 extern int cmd_parse_options(int argc, const char **argv, const char * con= st usage[]); =20 diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index 843ff3c2f28e..a0f3d3c9558d 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -118,7 +118,7 @@ struct objtool_file *objtool_open_read(const char *_obj= name) if (!file.elf) return NULL; =20 - if (backup && !objtool_create_backup(objname)) { + if (opts.backup && !objtool_create_backup(objname)) { WARN("can't create backup file"); return NULL; } @@ -129,7 +129,7 @@ struct objtool_file *objtool_open_read(const char *_obj= name) INIT_LIST_HEAD(&file.static_call_list); INIT_LIST_HEAD(&file.mcount_loc_list); INIT_LIST_HEAD(&file.endbr_list); - file.ignore_unreachables =3D no_unreachable; + file.ignore_unreachables =3D opts.no_unreachable; file.hints =3D false; =20 return &file; @@ -137,7 +137,7 @@ struct objtool_file *objtool_open_read(const char *_obj= name) =20 void objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func) { - if (!noinstr) + if (!opts.noinstr) return; =20 if (!f->pv_ops) { --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 805CBC43217 for ; Mon, 18 Apr 2022 16:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346586AbiDRQyH (ORCPT ); Mon, 18 Apr 2022 12:54:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346515AbiDRQxy (ORCPT ); Mon, 18 Apr 2022 12:53:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 681C633346 for ; Mon, 18 Apr 2022 09:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300669; 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: in-reply-to:in-reply-to:references:references; bh=kPcSTO2L75d/mmtvNHwlFVfmPWgNWVjCWoBCq3oAX8g=; b=gj7ma+yqaGU6rQaeqGMwWrkGoDoQNUmF8TB9ccqoWPkV7vB03x2foAjXcD63LYFpUkvHBz UoM5cweqFPXF93fptw1uvoe+dkfqOgYDhLxulna4Si2qVDYwBQ8WKvczNyAD3LH2n0AlCJ +12gkCgm4BCjcsKBa9JbpyvN+PguEug= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-439-b957nRZXPyGw5-04ztNieA-1; Mon, 18 Apr 2022 12:51:05 -0400 X-MC-Unique: b957nRZXPyGw5-04ztNieA-1 Received: by mail-qv1-f70.google.com with SMTP id fw9-20020a056214238900b0043522aa5b81so12521053qvb.21 for ; Mon, 18 Apr 2022 09:51:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kPcSTO2L75d/mmtvNHwlFVfmPWgNWVjCWoBCq3oAX8g=; b=r9R1Vi2cEzu0MI1WWS61AOw4BiawbFk2ma1b54QzonfFFXyN2XvHJ0H72Amrq1n/eg ZET8IbLBw4zywhX4edq8P/pVQ+FzXHHx71hRQG6Cm50wXKeUep9dLnzd3a0Lvv4flVuR W6NI+BJYyyFu9wubUiSZ8djZ5M+caDF2XveOrAYjMfBJ5rzMfXfL6WupAbDV21JYQjhZ a+cPCf5BpwOp0PBTMbZcnu2T2MK8RS/rU+JQeKQLXbThvK5ym530G62bLGFiS8BxMnw6 827yC9fwXeEjmvFwcxTiFQhPAN54qMhCg5yRySey7PN140MHluW245FLvCGopss+dvK/ e9VQ== X-Gm-Message-State: AOAM533C3GpD29dYIetg1tatiyEog2cWA99HLRqKDAkMsUW5f4rtqx8d 7W5QsShVmDtUoT/bIRwFQTZ8RRP1NE3Gr67IhU0stpDj+aU5GZrpC4w1MNQdnujGm8BNIIgkYEL srIdVfNHMFu7/0lizzzuRXX5q X-Received: by 2002:ac8:5b15:0:b0:2f2:4529:bdd6 with SMTP id m21-20020ac85b15000000b002f24529bdd6mr1107979qtw.353.1650300664833; Mon, 18 Apr 2022 09:51:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdUI3QGQILoyadpTQ/IG9lo7OSyn8yx2gXRZnKUBaQandZ2vN0uMSfpv+EDNzG0Wg0ZsB9Mg== X-Received: by 2002:ac8:5b15:0:b0:2f2:4529:bdd6 with SMTP id m21-20020ac85b15000000b002f24529bdd6mr1107955qtw.353.1650300664459; Mon, 18 Apr 2022 09:51:04 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:03 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 08/25] objtool: Ditch subcommands Date: Mon, 18 Apr 2022 09:50:27 -0700 Message-Id: <5c61ebf805e90aefc5fa62bc63468ffae53b9df6.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Objtool has a fairly singular focus. It runs on object files and does validations and transformations which can be combined in various ways. The subcommand model has never been a good fit, making it awkward to combine and remove options. Remove the "check" and "orc" subcommands in favor of a more traditional cmdline option model. This makes it much more flexible to use, and easier to port individual features to other arches. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 13 ++-- tools/objtool/Build | 12 ++- tools/objtool/Makefile | 8 +- tools/objtool/builtin-check.c | 56 +++++++++++--- tools/objtool/builtin-orc.c | 73 ------------------- tools/objtool/check.c | 8 ++ tools/objtool/include/objtool/builtin.h | 5 +- tools/objtool/objtool.c | 97 +------------------------ tools/objtool/weak.c | 9 +-- 10 files changed, 72 insertions(+), 211 deletions(-) delete mode 100644 tools/objtool/builtin-orc.c diff --git a/scripts/Makefile.build b/scripts/Makefile.build index dd9d582808d6..116c7272b41c 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -227,9 +227,9 @@ ifdef CONFIG_STACK_VALIDATION objtool :=3D $(objtree)/tools/objtool/objtool =20 objtool_args =3D \ - $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ + $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index c6e9fef61b11..f6db79b11573 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -113,9 +113,6 @@ objtool_link() =20 # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. - if is_enabled CONFIG_UNWINDER_ORC; then - objtoolcmd=3D"orc generate" - fi =20 if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt=3D"${objtoolopt} --ibt" @@ -125,6 +122,10 @@ objtool_link() objtoolopt=3D"${objtoolopt} --mcount" fi =20 + if is_enabled CONFIG_UNWINDER_ORC; then + objtoolopt=3D"${objtoolopt} --orc" + fi + objtoolopt=3D"${objtoolopt} --lto" fi =20 @@ -134,10 +135,6 @@ objtool_link() =20 if [ -n "${objtoolopt}" ]; then =20 - if [ -z "${objtoolcmd}" ]; then - objtoolcmd=3D"check" - fi - if is_enabled CONFIG_RETPOLINE; then objtoolopt=3D"${objtoolopt} --retpoline" fi @@ -161,7 +158,7 @@ objtool_link() objtoolopt=3D"${objtoolopt} --vmlinux" =20 info OBJTOOL ${1} - tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} + tools/objtool/objtool ${objtoolopt} ${1} fi } =20 diff --git a/tools/objtool/Build b/tools/objtool/Build index b7222d5cc7bc..33f2ee5a46d3 100644 --- a/tools/objtool/Build +++ b/tools/objtool/Build @@ -2,17 +2,15 @@ objtool-y +=3D arch/$(SRCARCH)/ =20 objtool-y +=3D weak.o =20 -objtool-$(SUBCMD_CHECK) +=3D check.o -objtool-$(SUBCMD_CHECK) +=3D special.o -objtool-$(SUBCMD_ORC) +=3D check.o -objtool-$(SUBCMD_ORC) +=3D orc_gen.o -objtool-$(SUBCMD_ORC) +=3D orc_dump.o - +objtool-y +=3D check.o +objtool-y +=3D special.o objtool-y +=3D builtin-check.o -objtool-y +=3D builtin-orc.o objtool-y +=3D elf.o objtool-y +=3D objtool.o =20 +objtool-$(BUILD_ORC) +=3D orc_gen.o +objtool-$(BUILD_ORC) +=3D orc_dump.o + objtool-y +=3D libstring.o objtool-y +=3D libctype.o objtool-y +=3D str_error_r.o diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 0dbd397f319d..061cf1cd42c4 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -39,15 +39,13 @@ CFLAGS +=3D $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) =20 AWK =3D awk =20 -SUBCMD_CHECK :=3D n -SUBCMD_ORC :=3D n +BUILD_ORC :=3D n =20 ifeq ($(SRCARCH),x86) - SUBCMD_CHECK :=3D y - SUBCMD_ORC :=3D y + BUILD_ORC :=3D y endif =20 -export SUBCMD_CHECK SUBCMD_ORC +export BUILD_ORC export srctree OUTPUT CFLAGS SRCARCH AWK include $(srctree)/tools/build/Makefile.include =20 diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index bc447b3cd9f2..8c3eed5b67e4 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -3,16 +3,6 @@ * Copyright (C) 2015-2017 Josh Poimboeuf */ =20 -/* - * objtool check: - * - * This command analyzes every .o file and ensures the validity of its sta= ck - * trace metadata. It enforces a set of rules on asm code and C inline - * assembly code so that stack traces can be reliable. - * - * For more information, see tools/objtool/Documentation/stack-validation.= txt. - */ - #include #include #include @@ -22,7 +12,7 @@ struct opts opts; =20 static const char * const check_usage[] =3D { - "objtool check [] file.o", + "objtool [] file.o", NULL, }; =20 @@ -31,14 +21,26 @@ static const char * const env_usage[] =3D { NULL, }; =20 +static int parse_dump(const struct option *opt, const char *str, int unset) +{ + if (!str || !strcmp(str, "orc")) { + opts.dump_orc =3D true; + return 0; + } + + return -1; +} + const struct option check_options[] =3D { OPT_GROUP("Actions:"), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls fo= r ftrace"), OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), + OPT_BOOLEAN('o', "orc", &opts.orc, "generate ORC metadata"), OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), + OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_= dump), =20 OPT_GROUP("Options:"), OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"), @@ -81,7 +83,31 @@ int cmd_parse_options(int argc, const char **argv, const= char * const usage[]) return argc; } =20 -int cmd_check(int argc, const char **argv) +static bool opts_valid(void) +{ + if (opts.ibt || + opts.mcount || + opts.noinstr || + opts.orc || + opts.retpoline || + opts.sls || + opts.uaccess) { + if (opts.dump_orc) { + fprintf(stderr, "--dump can't be combined with other options\n"); + return false; + } + + return true; + } + + if (opts.dump_orc) + return true; + + fprintf(stderr, "At least one command required\n"); + return false; +} + +int objtool_run(int argc, const char **argv) { const char *objname; struct objtool_file *file; @@ -90,6 +116,12 @@ int cmd_check(int argc, const char **argv) argc =3D cmd_parse_options(argc, argv, check_usage); objname =3D argv[0]; =20 + if (!opts_valid()) + return 1; + + if (opts.dump_orc) + return orc_dump(objname); + file =3D objtool_open_read(objname); if (!file) return 1; diff --git a/tools/objtool/builtin-orc.c b/tools/objtool/builtin-orc.c deleted file mode 100644 index 17f8b9307738..000000000000 --- a/tools/objtool/builtin-orc.c +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2017 Josh Poimboeuf - */ - -/* - * objtool orc: - * - * This command analyzes a .o file and adds .orc_unwind and .orc_unwind_ip - * sections to it, which is used by the in-kernel ORC unwinder. - * - * This command is a superset of "objtool check". - */ - -#include -#include -#include - -static const char *orc_usage[] =3D { - "objtool orc generate [] file.o", - "objtool orc dump file.o", - NULL, -}; - -int cmd_orc(int argc, const char **argv) -{ - const char *objname; - - argc--; argv++; - if (argc <=3D 0) - usage_with_options(orc_usage, check_options); - - if (!strncmp(argv[0], "gen", 3)) { - struct objtool_file *file; - int ret; - - argc =3D cmd_parse_options(argc, argv, orc_usage); - objname =3D argv[0]; - - file =3D objtool_open_read(objname); - if (!file) - return 1; - - ret =3D check(file); - if (ret) - return ret; - - if (list_empty(&file->insn_list)) - return 0; - - ret =3D orc_create(file); - if (ret) - return ret; - - if (!file->elf->changed) - return 0; - - return elf_write(file->elf); - } - - if (!strcmp(argv[0], "dump")) { - if (argc !=3D 2) - usage_with_options(orc_usage, check_options); - - objname =3D argv[1]; - - return orc_dump(objname); - } - - usage_with_options(orc_usage, check_options); - - return 0; -} diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 980f7bb0e954..acf26d273e2f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3954,6 +3954,14 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 + if (opts.orc && !list_empty(&file->insn_list)) { + ret =3D orc_create(file); + if (ret < 0) + goto out; + warnings +=3D ret; + } + + if (opts.stats) { printf("nr_insns_visited: %ld\n", nr_insns_visited); printf("nr_cfi: %ld\n", nr_cfi); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 87c1a7351e3c..44548e24473c 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -11,9 +11,11 @@ extern const struct option check_options[]; =20 struct opts { /* actions: */ + bool dump_orc; bool ibt; bool mcount; bool noinstr; + bool orc; bool retpoline; bool sls; bool uaccess; @@ -34,7 +36,6 @@ extern struct opts opts; =20 extern int cmd_parse_options(int argc, const char **argv, const char * con= st usage[]); =20 -extern int cmd_check(int argc, const char **argv); -extern int cmd_orc(int argc, const char **argv); +extern int objtool_run(int argc, const char **argv); =20 #endif /* _BUILTIN_H */ diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index a0f3d3c9558d..512669ce064c 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -3,16 +3,6 @@ * Copyright (C) 2015 Josh Poimboeuf */ =20 -/* - * objtool: - * - * The 'check' subcmd analyzes every .o file and ensures the validity of i= ts - * stack trace metadata. It enforces a set of rules on asm code and C inl= ine - * assembly code so that stack traces can be reliable. - * - * For more information, see tools/objtool/Documentation/stack-validation.= txt. - */ - #include #include #include @@ -26,20 +16,6 @@ #include #include =20 -struct cmd_struct { - const char *name; - int (*fn)(int, const char **); - const char *help; -}; - -static const char objtool_usage_string[] =3D - "objtool COMMAND [ARGS]"; - -static struct cmd_struct objtool_cmds[] =3D { - {"check", cmd_check, "Perform stack metadata validation on an object file= " }, - {"orc", cmd_orc, "Generate in-place ORC unwind tables for an object file= " }, -}; - bool help; =20 const char *objname; @@ -161,70 +137,6 @@ void objtool_pv_add(struct objtool_file *f, int idx, s= truct symbol *func) f->pv_ops[idx].clean =3D false; } =20 -static void cmd_usage(void) -{ - unsigned int i, longest =3D 0; - - printf("\n usage: %s\n\n", objtool_usage_string); - - for (i =3D 0; i < ARRAY_SIZE(objtool_cmds); i++) { - if (longest < strlen(objtool_cmds[i].name)) - longest =3D strlen(objtool_cmds[i].name); - } - - puts(" Commands:"); - for (i =3D 0; i < ARRAY_SIZE(objtool_cmds); i++) { - printf(" %-*s ", longest, objtool_cmds[i].name); - puts(objtool_cmds[i].help); - } - - printf("\n"); - - if (!help) - exit(129); - exit(0); -} - -static void handle_options(int *argc, const char ***argv) -{ - while (*argc > 0) { - const char *cmd =3D (*argv)[0]; - - if (cmd[0] !=3D '-') - break; - - if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h")) { - help =3D true; - break; - } else { - fprintf(stderr, "Unknown option: %s\n", cmd); - cmd_usage(); - } - - (*argv)++; - (*argc)--; - } -} - -static void handle_internal_command(int argc, const char **argv) -{ - const char *cmd =3D argv[0]; - unsigned int i, ret; - - for (i =3D 0; i < ARRAY_SIZE(objtool_cmds); i++) { - struct cmd_struct *p =3D objtool_cmds+i; - - if (strcmp(p->name, cmd)) - continue; - - ret =3D p->fn(argc, argv); - - exit(ret); - } - - cmd_usage(); -} - int main(int argc, const char **argv) { static const char *UNUSED =3D "OBJTOOL_NOT_IMPLEMENTED"; @@ -233,14 +145,7 @@ int main(int argc, const char **argv) exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED); pager_init(UNUSED); =20 - argv++; - argc--; - handle_options(&argc, &argv); - - if (!argc || help) - cmd_usage(); - - handle_internal_command(argc, argv); + objtool_run(argc, argv); =20 return 0; } diff --git a/tools/objtool/weak.c b/tools/objtool/weak.c index 8314e824db4a..d83f607733b0 100644 --- a/tools/objtool/weak.c +++ b/tools/objtool/weak.c @@ -15,17 +15,12 @@ return ENOSYS; \ }) =20 -int __weak check(struct objtool_file *file) -{ - UNSUPPORTED("check subcommand"); -} - int __weak orc_dump(const char *_objname) { - UNSUPPORTED("orc"); + UNSUPPORTED("ORC"); } =20 int __weak orc_create(struct objtool_file *file) { - UNSUPPORTED("orc"); + UNSUPPORTED("ORC"); } --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A9F7C433F5 for ; Mon, 18 Apr 2022 16:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346557AbiDRQyD (ORCPT ); Mon, 18 Apr 2022 12:54:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346504AbiDRQxy (ORCPT ); Mon, 18 Apr 2022 12:53:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8390632EF2 for ; Mon, 18 Apr 2022 09:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300667; 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: in-reply-to:in-reply-to:references:references; bh=+z2MPBv/e2lR6vUSjXOOBYhDsRJwrJcmF+Ul0MgCJ5c=; b=ga8y2jFbwYk4nPuX+BSdq1Fywn5256Jh4DZCvGpcW9jTAolAouBxtAXPymE9MjFLZaTGki hRGNyLGi1XgBSzuIeBwqHlEwcZKqFYTw+Y9M3vULoQrbHm3YbnKeacRi57zZvKIcXNjo+Z 83uZcaBaTyNOiCuZqSBp++NL26e9iGk= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-376-G33F1QaVNnCl9tLKisHn_A-1; Mon, 18 Apr 2022 12:51:06 -0400 X-MC-Unique: G33F1QaVNnCl9tLKisHn_A-1 Received: by mail-qk1-f199.google.com with SMTP id k15-20020a05620a142f00b0069ebc91caa2so452003qkj.21 for ; Mon, 18 Apr 2022 09:51:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+z2MPBv/e2lR6vUSjXOOBYhDsRJwrJcmF+Ul0MgCJ5c=; b=y1m3LL7UZuthdoINHfhWBhPsCuRI/IL0zuzG2Nn2EVWBvzwTn6ooijERz0ZEhyvvTB WvCENuxJ2LCTTo7isIBK4ff+aGqquRAfX++hXcwER0iuNR15PmJAQaekuV4HX4e+Ip5w lKknKXRFk4qUTyBjCXAi81yYCP9ZbZ1slBF4Vo2icMNszuC1gTd22s6lSJX3y8DkwZAB nAd4NX9nLayNk+G3a1QW9v154NLQhsRMoyj5Yy/9+zKruu0CY1sp6NP7HJNQdvGpw03K JXV95LCjDzusqnd+sCplIDiSPqjtxVYN9woZ1V4b/VP9JZlJ14Iiz1A3ybYdn8AVgQbk JFeA== X-Gm-Message-State: AOAM532zbsEB2kaY+/9nDMHkKH7zwZ6shYlC2bUqA3Xkjc7B0ApeT9dp EO2GONZulTIL8+7dHDIcPNm1P769MBmkozUp+kBvawrUM+rBDLGeWtMgKD6Zkqu0Sd3QFBwFzHG 7TYUfRhXOUyvNHvQ16Wnm4cW2 X-Received: by 2002:ac8:59d4:0:b0:2e1:f86d:b38c with SMTP id f20-20020ac859d4000000b002e1f86db38cmr7769236qtf.285.1650300666141; Mon, 18 Apr 2022 09:51:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdVA7/K8OZ0nFQVm4BMkXURcMzdC3LqGe0snrLttVMZreeXixseyMcC6SBMVhvhwGWuymR+Q== X-Received: by 2002:ac8:59d4:0:b0:2e1:f86d:b38c with SMTP id f20-20020ac859d4000000b002e1f86db38cmr7769224qtf.285.1650300665915; Mon, 18 Apr 2022 09:51:05 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:05 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 09/25] objtool: Don't print parentheses in function addresses Date: Mon, 18 Apr 2022 09:50:28 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The parentheses in the "func()+off" address output are inconsistent with how the kernel prints function addresses, breaking Peter's scripts. Remove them. Suggested-by: Peter Zijlstra Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/include/objtool/warn.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index 802cfda0a6f6..c4bde3e2a79c 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -33,11 +33,7 @@ static inline char *offstr(struct section *sec, unsigned= long offset) } =20 str =3D malloc(strlen(name) + 20); - - if (func) - sprintf(str, "%s()+0x%lx", name, name_off); - else - sprintf(str, "%s+0x%lx", name, name_off); + sprintf(str, "%s+0x%lx", name, name_off); =20 return str; } --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 816FDC433F5 for ; Mon, 18 Apr 2022 16:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346598AbiDRQyM (ORCPT ); Mon, 18 Apr 2022 12:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244634AbiDRQxy (ORCPT ); Mon, 18 Apr 2022 12:53:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5D2C633343 for ; Mon, 18 Apr 2022 09:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300669; 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: in-reply-to:in-reply-to:references:references; bh=AYHM3um6vRYLk4H6WX4rdEi004fqzTD7e3vZ1hx8pX0=; b=JMLhdf0ysFjCg/IXPd2xOeP9oecRfNV0oVgEEdkb34GN+GUuf78OlAVThVTSWi22OOL0M1 ybU2UmIAFyTO8qicF0vocreAtmmOw+RALwBsx3g4U8TRdxEPpZWXMPx50wU+ObC5f2Nawu HTZdM+cq071Ck/f0B6XhER7/qhYOY+w= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-221-8x_qrXjpM0-olhG3EbCtKg-1; Mon, 18 Apr 2022 12:51:08 -0400 X-MC-Unique: 8x_qrXjpM0-olhG3EbCtKg-1 Received: by mail-qv1-f69.google.com with SMTP id o1-20020ad44561000000b0044635418a3cso7674253qvu.0 for ; Mon, 18 Apr 2022 09:51:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AYHM3um6vRYLk4H6WX4rdEi004fqzTD7e3vZ1hx8pX0=; b=vvzgrKxSU4g0kebmOtYpYVFRLjj+LEzcnf1PMXLZiHCm2zZYAsqi3rAslnaozxByQ5 Qn02NxqFq87iuERKH2VrccS02dukFlsCzL6XIXow0YyE9Oa1H5IM3xNEDz7Tm/zQTD0d NAwsST2O43BaCSXQeZwTdk+rc7P+YkaqnKfOrI+G2wWOkdfsYHK2JupW/xre2lBK2YdM infaSF6RltPaZbrMngeG+uiglVU74mXgO698XLThY14CjXZXMfZ/0Yu/glWZvJBolsy3 P9sHf+y2vMQ+wVIzMRaZxHh6yjNgqCEoXjHzHUa1pXz5Lqh/bZWM1MIwvBp5E/y0lzp+ FFfA== X-Gm-Message-State: AOAM531P+mnUpnqAgR7dhOQXVDqlIELDXnk5FnRMbC7pRvTZAObbaRtS lbd+hc6LvxGx3iwa4HNuSn70+K7KOmmSuW4cob7/08y5VRn9NOSBWrFTaLpA22iCApsQIMnFmVp zKOBuN+GRk2fPE+8bXTABw/R4 X-Received: by 2002:a05:6214:1d09:b0:446:6786:6d43 with SMTP id e9-20020a0562141d0900b0044667866d43mr2090183qvd.97.1650300667648; Mon, 18 Apr 2022 09:51:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4/OWM3SREH/elaEF+EUpqf1uYOwNTgpuBBVAr2SlDdQqmQcR3jg1W6OV8iuu463jSkvRpWA== X-Received: by 2002:a05:6214:1d09:b0:446:6786:6d43 with SMTP id e9-20020a0562141d0900b0044667866d43mr2090172qvd.97.1650300667394; Mon, 18 Apr 2022 09:51:07 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:06 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 10/25] objtool: Print data address for "!ENDBR" data warnings Date: Mon, 18 Apr 2022 09:50:29 -0700 Message-Id: <762e88d51300e8eaf0f933a5b0feae20ac033bea.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When a "!ENDBR" warning is reported for a data section, objtool just prints the text address of the relocation target twice, without giving any clues about the location of the original data reference: vmlinux.o: warning: objtool: dcbnl_netdevice_event()+0x0: .text+0xb64680:= data relocation to !ENDBR: dcbnl_netdevice_event+0x0 Instead, print the address of the data reference, in addition to the address of the relocation target. vmlinux.o: warning: objtool: dcbnl_nb+0x0: .data..read_mostly+0xe260: dat= a relocation to !ENDBR: dcbnl_netdevice_event+0x0 Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/check.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index acf26d273e2f..97026c1b4bd6 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3825,11 +3825,8 @@ static int validate_ibt(struct objtool_file *file) struct instruction *dest; =20 dest =3D validate_ibt_reloc(file, reloc); - if (is_data && dest && !dest->noendbr) { - warn_noendbr("data ", reloc->sym->sec, - reloc->sym->offset + reloc->addend, - dest); - } + if (is_data && dest && !dest->noendbr) + warn_noendbr("data ", sec, reloc->offset, dest); } } =20 --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF513C433EF for ; Mon, 18 Apr 2022 16:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346633AbiDRQyV (ORCPT ); Mon, 18 Apr 2022 12:54:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346522AbiDRQxy (ORCPT ); Mon, 18 Apr 2022 12:53:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9D6DF33366 for ; Mon, 18 Apr 2022 09:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300671; 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: in-reply-to:in-reply-to:references:references; bh=3Z+DKCRf8I0VDKhczbT7dFWZdHYvbA+t2UZbUuCO6Ts=; b=UyhO7NiyibcT3cmH82cTUJf9Mf8EPjMYuDN3X9KEF4rv134gSVoow15I6nmwllzkXdoYv5 iYAfTTkiPXqu/lDy1OtOaCRUYkjlP5ys5jyF2jO3UkbehOdJ/l2Iv2MKkrXB2VecLXV6NN nGdfq2LKkGFeXbm3x8J7+t1l4ZJYPgs= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-230-ihUzUyyoO-uMBgaYwYy8MA-1; Mon, 18 Apr 2022 12:51:09 -0400 X-MC-Unique: ihUzUyyoO-uMBgaYwYy8MA-1 Received: by mail-qk1-f199.google.com with SMTP id m23-20020a05620a221700b006809e1fa4fdso10733423qkh.6 for ; Mon, 18 Apr 2022 09:51:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3Z+DKCRf8I0VDKhczbT7dFWZdHYvbA+t2UZbUuCO6Ts=; b=qfreXPYYBUCoInA6BVkTsQ901UJ+65Jg995uDeE67XEaIiVG057EYL5WFj6hqepdwZ 2alS7Ges3Vu9vI5QtUDXpGf/gYQPyfFyiSIOa8D50dIfWXiVEsXp/BZZmgGkStpCiBXc 7x7nm3Ht8Qp7/vE0Z3jCt+4IFCecOSQ7lI3XIQ2x7yV6maDVjcT9IxY46224KdjJRiqj DnlgDExcey0thYajgVhVU4chv0Qa/Ka3ZxKF4hnZkPWFCTEYp9WY8WqXHUj9WId6+x3c nMY/jiqiTQwfZnN/PVqcOOeLiIuUjxbX5Ffr1FN+7RCZ/UqzKeEnawLWiQlY3LGZ/kEJ caPA== X-Gm-Message-State: AOAM531xrjDR/2UF3bmnxOmPl9Y8qfVglW5l4SySZR45hO8uyxdf11j1 AsKUI5WsesyEWq8AWqmRvS+7OquReVBU3QnVrSyU25yCuxv+R+AYw3BcspsOIoc+NXK73csUsk4 kIxxrpIRjTu5bL2GqbC/GNwyq X-Received: by 2002:a05:6214:5189:b0:446:5077:7f75 with SMTP id kl9-20020a056214518900b0044650777f75mr6152349qvb.37.1650300669303; Mon, 18 Apr 2022 09:51:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAY8Sj56hJ4OUrUe7do9WO80TQYnEhocgTEB6pUtL57k2idWMkKrSsRT1InFO4PNiKSRCiLQ== X-Received: by 2002:a05:6214:5189:b0:446:5077:7f75 with SMTP id kl9-20020a056214518900b0044650777f75mr6152339qvb.37.1650300669049; Mon, 18 Apr 2022 09:51:09 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:08 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 11/25] objtool: Use offstr() to print address of missing ENDBR Date: Mon, 18 Apr 2022 09:50:30 -0700 Message-Id: <95d12e800c736a3f7d08d61dabb760b2d5251a8e.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/check.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 97026c1b4bd6..49d5f0986a52 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3219,9 +3219,8 @@ validate_ibt_reloc(struct objtool_file *file, struct = reloc *reloc) static void warn_noendbr(const char *msg, struct section *sec, unsigned lo= ng offset, struct instruction *dest) { - WARN_FUNC("%srelocation to !ENDBR: %s+0x%lx", sec, offset, msg, - dest->func ? dest->func->name : dest->sec->name, - dest->func ? dest->offset - dest->func->offset : dest->offset); + WARN_FUNC("%srelocation to !ENDBR: %s", sec, offset, msg, + offstr(dest->sec, dest->offset)); } =20 static void validate_ibt_dest(struct objtool_file *file, struct instructio= n *insn, --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C4AFC433EF for ; Mon, 18 Apr 2022 16:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346485AbiDRQyX (ORCPT ); Mon, 18 Apr 2022 12:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346530AbiDRQxy (ORCPT ); Mon, 18 Apr 2022 12:53:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9686C3337E for ; Mon, 18 Apr 2022 09:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300672; 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: in-reply-to:in-reply-to:references:references; bh=x9Fz+Xc8RoGhISO17r8oqMWhPNYKVczvw/S/wtXruE8=; b=TXc8k1lX28H+jxqwBqEF8/mSreSqlmRKLe0q63WejVhdL59POmuk6zXqJVS2v1k7X4Ld9Q RTRp+fCjfNQgfcovV66hQ9k7jxIoi9TRflhlXfXaZpCqsLBESX8xisnfdtrXiM7C5umCyv PBNeYfBNoB1vo/wGiIo55Mq25Bks9gI= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-58-wk0xCG6vN12dc_HJz4oq4g-1; Mon, 18 Apr 2022 12:51:11 -0400 X-MC-Unique: wk0xCG6vN12dc_HJz4oq4g-1 Received: by mail-qt1-f198.google.com with SMTP id s9-20020ac87589000000b002e1cfb25db9so2060767qtq.1 for ; Mon, 18 Apr 2022 09:51:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x9Fz+Xc8RoGhISO17r8oqMWhPNYKVczvw/S/wtXruE8=; b=dBg39bdWPRQw/BDdgiqX5ye/5CJE7hXFIusVibfirY6o8m/RmqgUSgr+1pfnTvNqQG /gLd0HfMJFaamONYsaWAbDMNql4HMJyf4ajJBR65OJBKHlpyfZZ6wwS5ectxREdrxcXk MzjyDMW5ATTdqKvgh3V5Utw3k0u9ZNZ525idiTGo0E4z2uOQZP+pOW8RQlqKn2lB0qqZ VWLQzH1sSghVcWbvWa1Mbj+WZnCwpmoL7KXBIfPT0+biMk5i+kmlXb+sunvPZHtU/lKS DsTkm2x8ZexUzts7TMmNyD2fw3Bit5xRff3ilHKP5lkTdjC+ct0BlV8oadZQCsCPjE8C gT7w== X-Gm-Message-State: AOAM532zrkULyGltP+F/0F3XRD9lzkcRQRnq6FIRNmvWj8gexyzotFkD ynS+4QXmgWmHRObupEdekRfv5eem+q+yVdHHXlWg0+rVnbYq4kZ60svUFjfdVc5sPWus/+i+kZY GekxS3VqEEDMbKuWDfwtvB3uD X-Received: by 2002:ac8:590e:0:b0:2e1:dcaf:bbb6 with SMTP id 14-20020ac8590e000000b002e1dcafbbb6mr7591137qty.644.1650300670762; Mon, 18 Apr 2022 09:51:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoacZs4E+r8OSfJFZkgztLmXpm2DEK+jp7Kds0Xtg7vwOt61QvoeNvi5Ah8ZbViMiVka4j/g== X-Received: by 2002:ac8:590e:0:b0:2e1:dcaf:bbb6 with SMTP id 14-20020ac8590e000000b002e1dcafbbb6mr7591122qty.644.1650300670509; Mon, 18 Apr 2022 09:51:10 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:10 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes , Nick Desaulniers Subject: [PATCH v2 12/25] objtool: Add option to print section addresses Date: Mon, 18 Apr 2022 09:50:31 -0700 Message-Id: <2cea4d5299d53d1a4c09212a6ad7820aa46fda7a.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" To help prevent objtool users from having to do math to convert function addresses to section addresses, and to help out with finding data addresses reported by IBT validation, add an option to print the section address in addition to the function address. Normal: vmlinux.o: warning: objtool: fixup_exception()+0x2d1: unreachable instruc= tion With '--sec-address': vmlinux.o: warning: objtool: fixup_exception()+0x2d1 (.text+0x76c51): unr= eachable instruction Suggested-by: Nick Desaulniers Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/builtin-check.c | 1 + tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/warn.h | 31 ++++++++++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 8c3eed5b67e4..6acfebd2c6ca 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -50,6 +50,7 @@ const struct option check_options[] =3D { OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module= "), OPT_BOOLEAN(0, "no-fp", &opts.no_fp, "skip frame pointer validation"), OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable= instruction' warnings"), + OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses= in warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"), =20 diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 44548e24473c..e0972fbfa09e 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -28,6 +28,7 @@ struct opts { bool module; bool no_fp; bool no_unreachable; + bool sec_address; bool stats; bool vmlinux; }; diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index c4bde3e2a79c..a3e79ae75f2e 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -11,30 +11,33 @@ #include #include #include +#include #include =20 extern const char *objname; =20 static inline char *offstr(struct section *sec, unsigned long offset) { - struct symbol *func; - char *name, *str; - unsigned long name_off; + bool is_text =3D (sec->sh.sh_flags & SHF_EXECINSTR); + struct symbol *sym =3D NULL; + char *str; + int len; =20 - func =3D find_func_containing(sec, offset); - if (!func) - func =3D find_symbol_containing(sec, offset); - if (func) { - name =3D func->name; - name_off =3D offset - func->offset; + if (is_text) + sym =3D find_func_containing(sec, offset); + if (!sym) + sym =3D find_symbol_containing(sec, offset); + + if (sym) { + str =3D malloc(strlen(sym->name) + strlen(sec->name) + 40); + len =3D sprintf(str, "%s+0x%lx", sym->name, offset - sym->offset); + if (opts.sec_address) + sprintf(str+len, " (%s+0x%lx)", sec->name, offset); } else { - name =3D sec->name; - name_off =3D offset; + str =3D malloc(strlen(sec->name) + 20); + sprintf(str, "%s+0x%lx", sec->name, offset); } =20 - str =3D malloc(strlen(name) + 20); - sprintf(str, "%s+0x%lx", name, name_off); - return str; } =20 --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22EF1C433EF for ; Mon, 18 Apr 2022 16:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346689AbiDRQzX (ORCPT ); Mon, 18 Apr 2022 12:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346503AbiDRQxz (ORCPT ); Mon, 18 Apr 2022 12:53:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1CA863388A for ; Mon, 18 Apr 2022 09:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300674; 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: in-reply-to:in-reply-to:references:references; bh=JBebpsVkjJ1lSSa3e/sJjGT51LMTkXLQURCTyHp5Tag=; b=YxhW9qowef3VrOsmhhk/TUtI36X0oxQWmFoIAakfz1J2/dsIe/ZsAkeBoSj1DVJM3g6kYh V309yypF0zZueXVLoZQrr/mLi0dpbbiNTTJPRBY8NXcFx0Fxsdroip5usEAwuTqGWD5Tux mOVduBEc0kSJBJEiWowpnYWlfBO1AZ0= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-53-j7K3T6i4MMOS4KqbY4YEqQ-1; Mon, 18 Apr 2022 12:51:12 -0400 X-MC-Unique: j7K3T6i4MMOS4KqbY4YEqQ-1 Received: by mail-qt1-f200.google.com with SMTP id x10-20020ac8700a000000b002c3ef8fc44cso8837700qtm.8 for ; Mon, 18 Apr 2022 09:51:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JBebpsVkjJ1lSSa3e/sJjGT51LMTkXLQURCTyHp5Tag=; b=nxI1vAny+DGZvz1FidcaZ/vMy6xUMVlWw8V0RBDQRg0wVjkvgRamnMKyTz7IYl05xM /d3c698WuNNOOJPtjr9K0+mnFas7MA30f0KcP6axWyvonxMIVmdhpZvZb8DQW6t6CAxK DmAZXFnkbOMXE4Gi2JUupW8wOVzEY68S+0p2EL6mDFKGzEPPAspWJGJPsvpvGxnTIEk+ JSoYo7whc1+bB7Zm1XlmBdjl5s8goJIFdmfHHp+RCBnoWKf91m5uBRXaQrgCc650pcKQ K6bUfpBEdghasBYD/qhH2BqWRtCbKOT2Hlu0GyME9sURaXael7eRbL0rP7/WjC3qjZgV E6kg== X-Gm-Message-State: AOAM531cjEiMPkoTwsyzxkDEZ24Uka8o9hHLjRTW1iDs2tbYR+zLT09X w2HlilKV1Nj4iHq3fxrHWO1njsmFqBuUsQskhUeLtYdRhcfRcZe6a87qlGX7QdleNAFhLDwRfCr DsB8Rufu/vrLerA/Mhr5/kjhG X-Received: by 2002:a05:6214:1cc4:b0:431:4cbc:1d91 with SMTP id g4-20020a0562141cc400b004314cbc1d91mr8819870qvd.64.1650300672338; Mon, 18 Apr 2022 09:51:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdHQjzckS1sAzf8DfFbGiChE/dpSmAb18xOXxE4bOzMjLBlU1ffPU/tvpAO7aja87iutMc5g== X-Received: by 2002:a05:6214:1cc4:b0:431:4cbc:1d91 with SMTP id g4-20020a0562141cc400b004314cbc1d91mr8819852qvd.64.1650300672090; Mon, 18 Apr 2022 09:51:12 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:11 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 13/25] scripts: Create objdump-func helper script Date: Mon, 18 Apr 2022 09:50:32 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a simple script which disassembles a single function from an object file. Comes in handy for objtool warnings and kernel stack traces. Originally-by: Peter Zijlstra Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- scripts/objdump-func | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 scripts/objdump-func diff --git a/scripts/objdump-func b/scripts/objdump-func new file mode 100755 index 000000000000..140646c456fc --- /dev/null +++ b/scripts/objdump-func @@ -0,0 +1,18 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Disassemble a single function. +# +# usage: objdump-func + +set -o errexit +set -o nounset + +OBJDUMP=3D"${CROSS_COMPILE:-}objdump" + +command -v awk >/dev/null 2>&1 || die "awk isn't installed" + +OBJ=3D$1; shift +FUNC=3D$1; shift + +${OBJDUMP} -wdr $@ $OBJ | awk "/^\$/ { P=3D0; } /$FUNC[^>]*>:\$/ { P=3D1; = O=3Dstrtonum(\"0x\" \$1); } { if (P) { o=3Dstrtonum(\"0x\" \$1); printf(\"%= 04x \", o-O); print \$0; } }" --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55959C433EF for ; Mon, 18 Apr 2022 16:51:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244619AbiDRQyc (ORCPT ); Mon, 18 Apr 2022 12:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346510AbiDRQxz (ORCPT ); Mon, 18 Apr 2022 12:53:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9067332ED8 for ; Mon, 18 Apr 2022 09:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300675; 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: in-reply-to:in-reply-to:references:references; bh=8a1RSwZRwZa7WB4b2xc1Iz/do+hexW0HjVpkJirC0vM=; b=hCpvN2TEa1Syk4rfjPmynQGpgMRUAfozhFq4u/1A3DOhEquIEkcy1biQOazwkjkOUswqSx VRKhK7E41D6o5fBT6SyCLoxJp12VNmL3pNLLjPNEFJqLDn17Wq03b4PpqNao2pAQjVzR+Z PSx0nbP9LJgiwgkbHaNCkRosREroR1o= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-550-CdS-3ZOBNYWcr4FDV8wx6w-1; Mon, 18 Apr 2022 12:51:14 -0400 X-MC-Unique: CdS-3ZOBNYWcr4FDV8wx6w-1 Received: by mail-qv1-f70.google.com with SMTP id o1-20020ad44561000000b0044635418a3cso7674439qvu.0 for ; Mon, 18 Apr 2022 09:51:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8a1RSwZRwZa7WB4b2xc1Iz/do+hexW0HjVpkJirC0vM=; b=JewRCWKq4qz6Z57YxfnTHZ7xdnUvoIW54CC47QeZVDR/N077i+zRIvioKr5XlaqUAo yQwPoyt2EUHtSd9BH6LUFoFlvhFNHYyUCU9YEWbQNHKIKhTryQsfTe6VS24g4CwUd7bn tbmV7FUt98p6XTrxXEyydw6J9Ai45qQ8taVbVaM/rjcs9TpuIIQPsTtyi8/3dcJO8wsx nB9Tw8AUjlxCyocUdiYmCNFsXmUJTpqkUy73rvTx+go7SijWYrXEsVI48tAuwV+3NoCu BIx4kTv67mgTYMOjIOLGWxCE2ILbKV7fH+MjZuFI1VZY6HVgvWbfka310IMgYPwioPf6 R0Dw== X-Gm-Message-State: AOAM532wrJbFJKhl49PG8QwsJHJk9O7lc7ILyjiFjXSm8B7vOzgFoIS2 H+ZgW3kJoSCMYv0hev3/GcJ/iRGEbOn1l4vH3KDpMMdEtcx6OCOcQVXnZbVMXeNWSmo83w/omLX d8HPNR44eFJRyG9XUpvu2Ul2U X-Received: by 2002:a05:622a:6091:b0:2f1:d379:1973 with SMTP id hf17-20020a05622a609100b002f1d3791973mr7638384qtb.495.1650300673819; Mon, 18 Apr 2022 09:51:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzys19uRmL1M1K12mF9KHOzsp2sgSqgqd9V2D4+Na4KZH0mq+1SWPr+v2QSJjGgPcgLomBrug== X-Received: by 2002:a05:622a:6091:b0:2f1:d379:1973 with SMTP id hf17-20020a05622a609100b002f1d3791973mr7638368qtb.495.1650300673579; Mon, 18 Apr 2022 09:51:13 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:13 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 14/25] objtool: Make stack validation optional Date: Mon, 18 Apr 2022 09:50:33 -0700 Message-Id: <52da143699574d756e65ca4c9d4acaffe9b0fe5f.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make stack validation an explicit cmdline option so that individual objtool features can be enabled individually by other arches. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 ++++ tools/objtool/builtin-check.c | 2 ++ tools/objtool/check.c | 28 +++++++++++++------------ tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 116c7272b41c..d5e15ae29156 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -232,6 +232,7 @@ objtool_args =3D \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ + $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index f6db79b11573..0140bfa32c0c 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -126,6 +126,10 @@ objtool_link() objtoolopt=3D"${objtoolopt} --orc" fi =20 + if is_enabled CONFIG_STACK_VALIDATION; then + objtoolopt=3D"${objtoolopt} --stackval" + fi + objtoolopt=3D"${objtoolopt} --lto" fi =20 diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 6acfebd2c6ca..d4e6930ad0a0 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -39,6 +39,7 @@ const struct option check_options[] =3D { OPT_BOOLEAN('o', "orc", &opts.orc, "generate ORC metadata"), OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), + OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate stack unwinding ru= les"), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_= dump), =20 @@ -92,6 +93,7 @@ static bool opts_valid(void) opts.orc || opts.retpoline || opts.sls || + opts.stackval || opts.uaccess) { if (opts.dump_orc) { fprintf(stderr, "--dump can't be combined with other options\n"); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 49d5f0986a52..8dc6035fabd2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3900,25 +3900,27 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 - ret =3D validate_functions(file); - if (ret < 0) - goto out; - warnings +=3D ret; - - ret =3D validate_unwind_hints(file, NULL); - if (ret < 0) - goto out; - warnings +=3D ret; + if (opts.stackval || opts.orc || opts.uaccess || opts.ibt || opts.sls) { + ret =3D validate_functions(file); + if (ret < 0) + goto out; + warnings +=3D ret; =20 - if (opts.ibt) { - ret =3D validate_ibt(file); + ret =3D validate_unwind_hints(file, NULL); if (ret < 0) goto out; warnings +=3D ret; + + if (!warnings) { + ret =3D validate_reachable_instructions(file); + if (ret < 0) + goto out; + warnings +=3D ret; + } } =20 - if (!warnings) { - ret =3D validate_reachable_instructions(file); + if (opts.ibt) { + ret =3D validate_ibt(file); if (ret < 0) goto out; warnings +=3D ret; diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index e0972fbfa09e..8618585bb742 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -18,6 +18,7 @@ struct opts { bool orc; bool retpoline; bool sls; + bool stackval; bool uaccess; =20 /* options: */ --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47438C433F5 for ; Mon, 18 Apr 2022 16:52:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346665AbiDRQyi (ORCPT ); Mon, 18 Apr 2022 12:54:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346563AbiDRQyE (ORCPT ); Mon, 18 Apr 2022 12:54:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BAE7C32EFB for ; Mon, 18 Apr 2022 09:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300677; 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: in-reply-to:in-reply-to:references:references; bh=eTCVITAKKtT6N+NddgrcMOHAiaBY96wu9WoL+d9zWOY=; b=CJjaF2IveZASyzqcIvER20tzHm6Fa/aFeHvGPUV6KL4WLYlOS7stZUmZ+ywrpniBhVq9At zGFF9KZIUN8wSIMY6C/MICB2tTaRYfO6MFClDfH0LkXNmKnMWCGxRUxE2X3wkOYgcZL46p hKoOot5C53EpzK4Xn5t+1EtEgt09Nag= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-ktr8J5deNOylv8AIyrVk8Q-1; Mon, 18 Apr 2022 12:51:16 -0400 X-MC-Unique: ktr8J5deNOylv8AIyrVk8Q-1 Received: by mail-qv1-f71.google.com with SMTP id e10-20020a0562140d8a00b00443c3595342so12578584qve.8 for ; Mon, 18 Apr 2022 09:51:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eTCVITAKKtT6N+NddgrcMOHAiaBY96wu9WoL+d9zWOY=; b=QBD9BOtarMZ+P4bCjfPIkoXC8tdjrEOQY4Q3pGYvuihQeUkGpUZQ/W1mmcb6/oMt/a w+DvYI/7YZbunOLvsM79HJY6oeLJOpJkRfqP9eWtV9m2LVRFZxFBnLdGLh75/zszNkyl mQ+kTycoYmMYq3iKvcfmAS9kTfL/QpZ9F3GUc26aMJQRy4K0VkNR2dVPgSTv/MN3aE4z gYzkTXLrf3eLD3IGlqcZnelTFoX6qMJJ548NM5d8978kpl9PsDK1eVsDFSCgPp8Jx5Gm guC73sfC8bPbtLFwjN6Z/0pC+P4hnSUNpP+ET6V/vNkqYQcWD46q5X9OjDPF7AZT4cEE YqAA== X-Gm-Message-State: AOAM533Sh0wNjjgwxX4AoDQSmCqVFC2VV4IZ0vfocDTQQ63AFd2OeXcD dr6W/WoD8dwTGZa2oH6o/nF5aFUkP1woCm/OgmtpGHCiQQU+zb4i93h616e7JElGcGHhlEkEjjr z9yy6O4BuS/QVSuf2r4IBV+Qo X-Received: by 2002:a37:6412:0:b0:69e:68cf:d889 with SMTP id y18-20020a376412000000b0069e68cfd889mr6907486qkb.443.1650300675662; Mon, 18 Apr 2022 09:51:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyi4372uUi3iMUh+JmZIfqcTe4cdvzVUtI6fBEr7GxKDJRYwtqZDQxhqW9x/t1/KeArMEo0/g== X-Received: by 2002:a37:6412:0:b0:69e:68cf:d889 with SMTP id y18-20020a376412000000b0069e68cfd889mr6907475qkb.443.1650300675308; Mon, 18 Apr 2022 09:51:15 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:14 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 15/25] objtool: Rework ibt and extricate from stack validation Date: Mon, 18 Apr 2022 09:50:34 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extricate ibt from validate_branch() so they can be executed (or ported) independently from each other. While shuffling code around, simplify and improve the ibt logic: - Ignore an explicit list of known sections which reference functions for reasons other than indirect branching to them. This helps prevent unnnecesary sealing. - Warn on missing !ENDBR for all other sections, not just .data and .rodata. This finds additional warnings, because there are sections other than .[ro]data which reference function pointers. For example, the ksymtab sections which are used for exporting symbols. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/check.c | 280 ++++++++++++++++++++++-------------------- 1 file changed, 147 insertions(+), 133 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 8dc6035fabd2..0059b592195e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3183,114 +3183,6 @@ static struct instruction *next_insn_to_validate(st= ruct objtool_file *file, return next_insn_same_sec(file, insn); } =20 -static struct instruction * -validate_ibt_reloc(struct objtool_file *file, struct reloc *reloc) -{ - struct instruction *dest; - struct section *sec; - unsigned long off; - - sec =3D reloc->sym->sec; - off =3D reloc->sym->offset; - - if ((reloc->sec->base->sh.sh_flags & SHF_EXECINSTR) && - (reloc->type =3D=3D R_X86_64_PC32 || reloc->type =3D=3D R_X86_64_PLT3= 2)) - off +=3D arch_dest_reloc_offset(reloc->addend); - else - off +=3D reloc->addend; - - dest =3D find_insn(file, sec, off); - if (!dest) - return NULL; - - if (dest->type =3D=3D INSN_ENDBR) { - if (!list_empty(&dest->call_node)) - list_del_init(&dest->call_node); - - return NULL; - } - - if (reloc->sym->static_call_tramp) - return NULL; - - return dest; -} - -static void warn_noendbr(const char *msg, struct section *sec, unsigned lo= ng offset, - struct instruction *dest) -{ - WARN_FUNC("%srelocation to !ENDBR: %s", sec, offset, msg, - offstr(dest->sec, dest->offset)); -} - -static void validate_ibt_dest(struct objtool_file *file, struct instructio= n *insn, - struct instruction *dest) -{ - if (dest->func && dest->func =3D=3D insn->func) { - /* - * Anything from->to self is either _THIS_IP_ or IRET-to-self. - * - * There is no sane way to annotate _THIS_IP_ since the compiler treats = the - * relocation as a constant and is happy to fold in offsets, skewing any - * annotation we do, leading to vast amounts of false-positives. - * - * There's also compiler generated _THIS_IP_ through KCOV and - * such which we have no hope of annotating. - * - * As such, blanket accept self-references without issue. - */ - return; - } - - if (dest->noendbr) - return; - - warn_noendbr("", insn->sec, insn->offset, dest); -} - -static void validate_ibt_insn(struct objtool_file *file, struct instructio= n *insn) -{ - struct instruction *dest; - struct reloc *reloc; - - switch (insn->type) { - case INSN_CALL: - case INSN_CALL_DYNAMIC: - case INSN_JUMP_CONDITIONAL: - case INSN_JUMP_UNCONDITIONAL: - case INSN_JUMP_DYNAMIC: - case INSN_JUMP_DYNAMIC_CONDITIONAL: - case INSN_RETURN: - /* - * We're looking for code references setting up indirect code - * flow. As such, ignore direct code flow and the actual - * dynamic branches. - */ - return; - - case INSN_NOP: - /* - * handle_group_alt() will create INSN_NOP instruction that - * don't belong to any section, ignore all NOP since they won't - * carry a (useful) relocation anyway. - */ - return; - - default: - break; - } - - for (reloc =3D insn_reloc(file, insn); - reloc; - reloc =3D find_reloc_by_dest_range(file->elf, insn->sec, - reloc->offset + 1, - (insn->offset + insn->len) - (reloc->offset + 1))) { - dest =3D validate_ibt_reloc(file, reloc); - if (dest) - validate_ibt_dest(file, insn, dest); - } -} - /* * Follow the branch starting at the given instruction, and recursively fo= llow * any other branches (jumps). Meanwhile, track the frame pointer state at @@ -3500,9 +3392,6 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, break; } =20 - if (opts.ibt) - validate_ibt_insn(file, insn); - if (insn->dead_end) return 0; =20 @@ -3788,48 +3677,173 @@ static int validate_functions(struct objtool_file = *file) return warnings; } =20 -static int validate_ibt(struct objtool_file *file) +static void mark_endbr_used(struct instruction *insn) { - struct section *sec; + if (!list_empty(&insn->call_node)) + list_del_init(&insn->call_node); +} + +static int validate_ibt_insn(struct objtool_file *file, struct instruction= *insn) +{ + struct instruction *dest; struct reloc *reloc; + unsigned long off; + int warnings =3D 0; =20 - for_each_sec(file, sec) { - bool is_data; + /* + * Looking for function pointer load relocations. Ignore + * direct/indirect branches: + */ + switch (insn->type) { + case INSN_CALL: + case INSN_CALL_DYNAMIC: + case INSN_JUMP_CONDITIONAL: + case INSN_JUMP_UNCONDITIONAL: + case INSN_JUMP_DYNAMIC: + case INSN_JUMP_DYNAMIC_CONDITIONAL: + case INSN_RETURN: + case INSN_NOP: + return 0; + default: + break; + } =20 - /* already done in validate_branch() */ - if (sec->sh.sh_flags & SHF_EXECINSTR) - continue; + for (reloc =3D insn_reloc(file, insn); + reloc; + reloc =3D find_reloc_by_dest_range(file->elf, insn->sec, + reloc->offset + 1, + (insn->offset + insn->len) - (reloc->offset + 1))) { =20 - if (!sec->reloc) + /* + * static_call_update() references the trampoline, which + * doesn't have (or need) ENDBR. Skip warning in that case. + */ + if (reloc->sym->static_call_tramp) continue; =20 - if (!strncmp(sec->name, ".orc", 4)) + off =3D reloc->sym->offset; + if (reloc->type =3D=3D R_X86_64_PC32 || reloc->type =3D=3D R_X86_64_PLT3= 2) + off +=3D arch_dest_reloc_offset(reloc->addend); + else + off +=3D reloc->addend; + + dest =3D find_insn(file, reloc->sym->sec, off); + if (!dest) continue; =20 - if (!strncmp(sec->name, ".discard", 8)) + if (dest->type =3D=3D INSN_ENDBR) { + mark_endbr_used(dest); continue; + } =20 - if (!strncmp(sec->name, ".debug", 6)) + if (dest->func && dest->func =3D=3D insn->func) { + /* + * Anything from->to self is either _THIS_IP_ or + * IRET-to-self. + * + * There is no sane way to annotate _THIS_IP_ since the + * compiler treats the relocation as a constant and is + * happy to fold in offsets, skewing any annotation we + * do, leading to vast amounts of false-positives. + * + * There's also compiler generated _THIS_IP_ through + * KCOV and such which we have no hope of annotating. + * + * As such, blanket accept self-references without + * issue. + */ continue; + } =20 - if (!strcmp(sec->name, "_error_injection_whitelist")) + if (dest->noendbr) continue; =20 - if (!strcmp(sec->name, "_kprobe_blacklist")) + WARN_FUNC("relocation to !ENDBR: %s", + insn->sec, insn->offset, + offstr(dest->sec, dest->offset)); + + warnings++; + } + + return warnings; +} + +static int validate_ibt_data_reloc(struct objtool_file *file, + struct reloc *reloc) +{ + struct instruction *dest; + + dest =3D find_insn(file, reloc->sym->sec, + reloc->sym->offset + reloc->addend); + if (!dest) + return 0; + + if (dest->type =3D=3D INSN_ENDBR) { + mark_endbr_used(dest); + return 0; + } + + if (dest->noendbr) + return 0; + + WARN_FUNC("data relocation to !ENDBR: %s", + reloc->sec->base, reloc->offset, + offstr(dest->sec, dest->offset)); + + return 1; +} + +/* + * Validate IBT rules and remove used ENDBR instructions from the seal lis= t. + * Unused ENDBR instructions will be annotated for sealing (i.e., replaced= with + * NOPs) later, in create_ibt_endbr_seal_sections(). + */ +static int validate_ibt(struct objtool_file *file) +{ + struct section *sec; + struct reloc *reloc; + struct instruction *insn; + int warnings =3D 0; + + for_each_insn(file, insn) + warnings +=3D validate_ibt_insn(file, insn); + + for_each_sec(file, sec) { + + /* Already done by validate_ibt_insn() */ + if (sec->sh.sh_flags & SHF_EXECINSTR) continue; =20 - is_data =3D strstr(sec->name, ".data") || strstr(sec->name, ".rodata"); + if (!sec->reloc) + continue; =20 - list_for_each_entry(reloc, &sec->reloc->reloc_list, list) { - struct instruction *dest; + /* + * These sections can reference text addresses, but not with + * the intent to indirect branch to them. + */ + if (!strncmp(sec->name, ".discard", 8) || + !strncmp(sec->name, ".debug", 6) || + !strcmp(sec->name, ".altinstructions") || + !strcmp(sec->name, ".ibt_endbr_seal") || + !strcmp(sec->name, ".orc_unwind_ip") || + !strcmp(sec->name, ".parainstructions") || + !strcmp(sec->name, ".retpoline_sites") || + !strcmp(sec->name, ".smp_locks") || + !strcmp(sec->name, ".static_call_sites") || + !strcmp(sec->name, "_error_injection_whitelist") || + !strcmp(sec->name, "_kprobe_blacklist") || + !strcmp(sec->name, "__bug_table") || + !strcmp(sec->name, "__ex_table") || + !strcmp(sec->name, "__jump_table") || + !strcmp(sec->name, "__mcount_loc") || + !strcmp(sec->name, "__tracepoints")) + continue; =20 - dest =3D validate_ibt_reloc(file, reloc); - if (is_data && dest && !dest->noendbr) - warn_noendbr("data ", sec, reloc->offset, dest); - } + list_for_each_entry(reloc, &sec->reloc->reloc_list, list) + warnings +=3D validate_ibt_data_reloc(file, reloc); } =20 - return 0; + return warnings; } =20 static int validate_reachable_instructions(struct objtool_file *file) @@ -3900,7 +3914,7 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 - if (opts.stackval || opts.orc || opts.uaccess || opts.ibt || opts.sls) { + if (opts.stackval || opts.orc || opts.uaccess || opts.sls) { ret =3D validate_functions(file); if (ret < 0) goto out; --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 667B6C433EF for ; Mon, 18 Apr 2022 16:52:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346681AbiDRQzT (ORCPT ); Mon, 18 Apr 2022 12:55:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346566AbiDRQyF (ORCPT ); Mon, 18 Apr 2022 12:54:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4B01D3388F for ; Mon, 18 Apr 2022 09:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300679; 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: in-reply-to:in-reply-to:references:references; bh=RiohTaoM29xhpBRMIpNDadunlIt2skg8irQpa7owkKw=; b=aVCKFaE8mj9GFl79pZvtIjY8NghgcTciwuY2+AbSYHChx51LZrOwgGjlrXfs5jEgoWRH8l r4F0HXnA8nxYwFhDchgckzwgHXpRFj9siv0ODj4/AlbNJH+6R36K1rVEiu5KUo8EpMZlEB lgB9OGZo8+l1WgsHjMRmRBEdkdTM0N4= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-8KqqKwCSO1WZbMhyhHs26g-1; Mon, 18 Apr 2022 12:51:18 -0400 X-MC-Unique: 8KqqKwCSO1WZbMhyhHs26g-1 Received: by mail-qv1-f69.google.com with SMTP id m16-20020ad45050000000b00446393a7a9fso6789927qvq.6 for ; Mon, 18 Apr 2022 09:51:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RiohTaoM29xhpBRMIpNDadunlIt2skg8irQpa7owkKw=; b=2QaaV7DQgVGCBTH1cpah/O/FXAp49Ym0qZNhNcUyiDhmINZByq6AVV7zDhMWpw8Zxg ziDehng+wHWPYEQJlgOuhhqObHLR1jOPKBh/szNMwy+EIw+Zb5MySDZNgCRoWiNmQkjX xKj7U9mcHq8iyz55ZnxYQIQ6q8dGxKJTUZ8zW67dCcyYyP13A1/3yajSvY/FGKFdW7wR IbMK3cb5uBMwnL6YY5GF3OJ4crrRlFarhFRCMwpgNTT+Il2EAWK4RsWDcvto92ULbuJc kLDc1eNX/y2JsV3Y0mFQqouooLKVZdy8B/cRLYCzZn4KtJsth4Q8inFYEtc6NVqeXmGb RnUg== X-Gm-Message-State: AOAM531dmQPiJMIbabfzdsJv7UMGwUemsxmayA+Loy1P1JG1EHMiQOJ1 ll+zTNn/CANgL20WLJw5BzataBxG4/L7utRErtaDjduBzDrC3Kd8f2WxjxBaQy735acsRssiDWU jIkkBzjwK5l3aEYfLfOlqGyY2 X-Received: by 2002:a05:620a:1a17:b0:69c:669c:1032 with SMTP id bk23-20020a05620a1a1700b0069c669c1032mr7128707qkb.377.1650300677045; Mon, 18 Apr 2022 09:51:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSYd5H7IJuluxq9Dum2Jr2Io19JEUswNf7XqXsEBL6n4fxPX1U+iUHwQkwFw/X6SextmnT3A== X-Received: by 2002:a05:620a:1a17:b0:69c:669c:1032 with SMTP id bk23-20020a05620a1a1700b0069c669c1032mr7128698qkb.377.1650300676821; Mon, 18 Apr 2022 09:51:16 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:16 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 16/25] objtool: Extricate sls from stack validation Date: Mon, 18 Apr 2022 09:50:35 -0700 Message-Id: <2545c86ffa5f27497f0d0c542540ad4a4be3c5a5.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extricate sls functionality from validate_branch() so they can be executed (or ported) independently from each other. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/check.c | 56 +++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 0059b592195e..88b527b3eb37 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3272,11 +3272,6 @@ static int validate_branch(struct objtool_file *file= , struct symbol *func, switch (insn->type) { =20 case INSN_RETURN: - if (opts.sls && !insn->retpoline_safe && - next_insn && next_insn->type !=3D INSN_TRAP) { - WARN_FUNC("missing int3 after ret", - insn->sec, insn->offset); - } return validate_return(func, insn, &state); =20 case INSN_CALL: @@ -3320,13 +3315,6 @@ static int validate_branch(struct objtool_file *file= , struct symbol *func, break; =20 case INSN_JUMP_DYNAMIC: - if (opts.sls && !insn->retpoline_safe && - next_insn && next_insn->type !=3D INSN_TRAP) { - WARN_FUNC("missing int3 after indirect jump", - insn->sec, insn->offset); - } - - /* fallthrough */ case INSN_JUMP_DYNAMIC_CONDITIONAL: if (is_sibling_call(insn)) { ret =3D validate_sibling_call(file, insn, &state); @@ -3846,6 +3834,41 @@ static int validate_ibt(struct objtool_file *file) return warnings; } =20 +static int validate_sls(struct objtool_file *file) +{ + struct instruction *insn, *next_insn; + int warnings =3D 0; + + for_each_insn(file, insn) { + next_insn =3D next_insn_same_sec(file, insn); + + if (insn->retpoline_safe) + continue; + + switch (insn->type) { + case INSN_RETURN: + if (!next_insn || next_insn->type !=3D INSN_TRAP) { + WARN_FUNC("missing int3 after ret", + insn->sec, insn->offset); + warnings++; + } + + break; + case INSN_JUMP_DYNAMIC: + if (!next_insn || next_insn->type !=3D INSN_TRAP) { + WARN_FUNC("missing int3 after indirect jump", + insn->sec, insn->offset); + warnings++; + } + break; + default: + break; + } + } + + return warnings; +} + static int validate_reachable_instructions(struct objtool_file *file) { struct instruction *insn; @@ -3914,7 +3937,7 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 - if (opts.stackval || opts.orc || opts.uaccess || opts.sls) { + if (opts.stackval || opts.orc || opts.uaccess) { ret =3D validate_functions(file); if (ret < 0) goto out; @@ -3940,6 +3963,13 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 + if (opts.sls) { + ret =3D validate_sls(file); + if (ret < 0) + goto out; + warnings +=3D ret; + } + ret =3D create_static_call_sections(file); if (ret < 0) goto out; --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C114C433F5 for ; Mon, 18 Apr 2022 16:52:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346670AbiDRQzO (ORCPT ); Mon, 18 Apr 2022 12:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346574AbiDRQyF (ORCPT ); Mon, 18 Apr 2022 12:54:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE45E338B9 for ; Mon, 18 Apr 2022 09:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300680; 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: in-reply-to:in-reply-to:references:references; bh=VyhT3BT6VMq8FLjVnc4agqzIjqfTJuNBZf7A2XDS6Y8=; b=Q8RA3B4T/yKRL08/kN/te9OrI4+Zp1KxHDarOccvdH3SQ330m/gi1yidHxEbft2HHqRzdR hPzb5fjwkleu6iHOi9WvwcXMNqzTs/6vZ3WUuGO+Qu4O3oYRMXFwMCXuoqHse7iDjnEKGQ RZCOHk8qL7dqcOXGJi5uMrf5kqevueU= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-615-2aczuG5XNIWsQcUDegrQGw-1; Mon, 18 Apr 2022 12:51:19 -0400 X-MC-Unique: 2aczuG5XNIWsQcUDegrQGw-1 Received: by mail-qt1-f199.google.com with SMTP id o2-20020ac86982000000b002f1d71c97b8so7377104qtq.2 for ; Mon, 18 Apr 2022 09:51:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VyhT3BT6VMq8FLjVnc4agqzIjqfTJuNBZf7A2XDS6Y8=; b=wht+WyTzLzVAE9mvhmb55tFpTwRW8qC9UvYPy8hIjBeobuLnOr0Tbn0v3MGc11tzTp HW3v24nqYcFnye4t/VCFO1XLWk5WyPJi0toBXgD/3pQ6yg28ZNPjrRK3Qly0DEH+PYWy 5zaAnsHR3REE6WXAk5oKzJKrT5ufRq99FOHLQJqLRuiTds3zm1AB6VpV7yGChMs3ZtUM j5I+Pm1H9sMWJPdb1dnRGfIUXJnoITyudpAa4XywpY2z7e0QLFOaAJrJZgxfh7rX7ZDX 8/8e297FPbYV0Ts+vc2Auxx+cfOlPtpKw1GNU8wqxyW5LL9b/q1IzPNk4GbTY6y4JUW+ jV2A== X-Gm-Message-State: AOAM530rbSNNhqm3BAJ6OvMjKFgKWmit/RSuVLkFRB0g+o/bRGsTdeZm LPNDCSo59C+8lwqrW6tm5aQjMcl4YfiHUnrHrRpoVU2tcRg7F8T1aiq6jZfOYk1dPQwV6EqydnN 0T4SWTgts4XN/dGHvynrDqCVj X-Received: by 2002:a05:620a:198f:b0:69e:953c:1843 with SMTP id bm15-20020a05620a198f00b0069e953c1843mr3914683qkb.209.1650300678692; Mon, 18 Apr 2022 09:51:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiJCmYzapTJreYBz8xSSddqTH05EYtPfLspu0GRfzhkt2ljHtsHkfebiN8H5PJJNe9rNcDqg== X-Received: by 2002:a05:620a:198f:b0:69e:953c:1843 with SMTP id bm15-20020a05620a198f00b0069e953c1843mr3914667qkb.209.1650300678333; Mon, 18 Apr 2022 09:51:18 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:17 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 17/25] objtool: Add CONFIG_OBJTOOL Date: Mon, 18 Apr 2022 09:50:36 -0700 Message-Id: <939bf3d85604b2a126412bf11af6e3bd3b872bcb.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that stack validation is an optional feature of objtool, add CONFIG_OBJTOOL and replace most usages of CONFIG_STACK_VALIDATION with it. CONFIG_STACK_VALIDATION can now be considered to be frame-pointer specific. CONFIG_UNWINDER_ORC is already inherently valid for live patching, so no need to "validate" it. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- Makefile | 2 +- arch/Kconfig | 8 ++++++-- arch/x86/Kconfig | 18 ++++++++++------- arch/x86/Kconfig.debug | 2 +- arch/x86/include/asm/jump_label.h | 6 +++--- arch/x86/kernel/alternative.c | 6 +++--- include/linux/compiler.h | 6 +++--- include/linux/instrumentation.h | 6 +++--- include/linux/objtool.h | 6 +++--- kernel/trace/Kconfig | 1 + lib/Kconfig.debug | 20 ++++++++++--------- lib/Kconfig.kcsan | 3 ++- lib/Kconfig.ubsan | 2 +- scripts/Makefile.build | 4 ++-- scripts/link-vmlinux.sh | 32 +++++++++++++++++-------------- scripts/package/builddeb | 2 +- tools/include/linux/objtool.h | 6 +++--- 17 files changed, 73 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index 29e273d3f8cc..707dfbf643a2 100644 --- a/Makefile +++ b/Makefile @@ -1302,7 +1302,7 @@ install: sub_make_done :=3D # ------------------------------------------------------------------------= --- # Tools =20 -ifdef CONFIG_STACK_VALIDATION +ifdef CONFIG_OBJTOOL prepare: tools/objtool endif =20 diff --git a/arch/Kconfig b/arch/Kconfig index 29b0167c088b..04cdef16db24 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1028,11 +1028,14 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT depends on MMU select ARCH_HAS_ELF_RANDOMIZE =20 +config HAVE_OBJTOOL + bool + config HAVE_STACK_VALIDATION bool help - Architecture supports the 'objtool check' host tool command, which - performs compile-time stack metadata validation. + Architecture supports objtool compile-time frame pointer rule + validation. =20 config HAVE_RELIABLE_STACKTRACE bool @@ -1302,6 +1305,7 @@ config HAVE_STATIC_CALL config HAVE_STATIC_CALL_INLINE bool depends on HAVE_STATIC_CALL + select OBJTOOL =20 config HAVE_PREEMPT_DYNAMIC bool diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index b0142e01002e..bce0c23f3550 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -188,7 +188,7 @@ config X86 select HAVE_CONTEXT_TRACKING if X86_64 select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING select HAVE_C_RECORDMCOUNT - select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION + select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL select HAVE_BUILDTIME_MCOUNT_SORT select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS @@ -231,6 +231,7 @@ config X86 select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_NMI + select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS @@ -239,17 +240,17 @@ config X86 select HAVE_PCI select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT + select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API - select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || = UNWINDER_ORC) && STACK_VALIDATION + select HAVE_RELIABLE_STACKTRACE if UNWINDER_ORC || STACK_VALIDATION select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_SETUP_PER_CPU_AREA select HAVE_SOFTIRQ_ON_OWN_STACK select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR - select HAVE_STACK_VALIDATION if X86_64 + select HAVE_STACK_VALIDATION if HAVE_OBJTOOL select HAVE_STATIC_CALL - select HAVE_STATIC_CALL_INLINE if HAVE_STACK_VALIDATION + select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL select HAVE_PREEMPT_DYNAMIC_CALL select HAVE_RSEQ select HAVE_SYSCALL_TRACEPOINTS @@ -268,7 +269,6 @@ config X86 select RTC_MC146818_LIB select SPARSE_IRQ select SRCU - select STACK_VALIDATION if HAVE_STACK_VALIDATION && (HAVE_STATIC_CALL_I= NLINE || RETPOLINE) select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT @@ -459,6 +459,7 @@ config GOLDFISH =20 config RETPOLINE bool "Avoid speculative indirect branches in kernel" + select OBJTOOL if HAVE_OBJTOOL default y help Compile kernel with the retpoline compiler options to guard against @@ -472,6 +473,7 @@ config CC_HAS_SLS config SLS bool "Mitigate Straight-Line-Speculation" depends on CC_HAS_SLS && X86_64 + select OBJTOOL if HAVE_OBJTOOL default n help Compile the kernel with straight-line-speculation options to guard @@ -1819,6 +1821,7 @@ config ARCH_RANDOM config X86_SMAP def_bool y prompt "Supervisor Mode Access Prevention" if EXPERT + select OBJTOOL if HAVE_OBJTOOL help Supervisor Mode Access Prevention (SMAP) is a security feature in newer Intel processors. There is a small @@ -1855,9 +1858,10 @@ config CC_HAS_IBT config X86_KERNEL_IBT prompt "Indirect Branch Tracking" bool - depends on X86_64 && CC_HAS_IBT && STACK_VALIDATION + depends on X86_64 && CC_HAS_IBT && HAVE_OBJTOOL # https://github.com/llvm/llvm-project/commit/9d7001eba9c4cb311e03cd8cdc2= 31f9e579f2d0f depends on !LD_IS_LLD || LLD_VERSION >=3D 140000 + select OBJTOOL help Build the kernel with support for Indirect Branch Tracking, a hardware support course-grain forward-edge Control Flow Integrity diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index d3a6f74a94bd..d872a7522e55 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug @@ -237,7 +237,7 @@ choice config UNWINDER_ORC bool "ORC unwinder" depends on X86_64 - select STACK_VALIDATION + select OBJTOOL help This option enables the ORC (Oops Rewind Capability) unwinder for unwinding kernel stack traces. It uses a custom data format which is diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_= label.h index 0449b125d27f..3ce0e67c579c 100644 --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -20,7 +20,7 @@ _ASM_PTR "%c0 + %c1 - .\n\t" \ ".popsection \n\t" =20 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL =20 static __always_inline bool arch_static_branch(struct static_key *key, boo= l branch) { @@ -34,7 +34,7 @@ static __always_inline bool arch_static_branch(struct sta= tic_key *key, bool bran return true; } =20 -#else +#else /* !CONFIG_OBJTOOL */ =20 static __always_inline bool arch_static_branch(struct static_key * const k= ey, const bool branch) { @@ -48,7 +48,7 @@ static __always_inline bool arch_static_branch(struct sta= tic_key * const key, co return true; } =20 -#endif /* STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ =20 static __always_inline bool arch_static_branch_jump(struct static_key * co= nst key, const bool branch) { diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index d374cb3cf024..3c66073e7645 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -338,7 +338,7 @@ void __init_or_module noinline apply_alternatives(struc= t alt_instr *start, } } =20 -#if defined(CONFIG_RETPOLINE) && defined(CONFIG_STACK_VALIDATION) +#if defined(CONFIG_RETPOLINE) && defined(CONFIG_OBJTOOL) =20 /* * CALL/JMP *%\reg @@ -507,11 +507,11 @@ void __init_or_module noinline apply_retpolines(s32 *= start, s32 *end) } } =20 -#else /* !RETPOLINES || !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_RETPOLINE || !CONFIG_OBJTOOL */ =20 void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) { } =20 -#endif /* CONFIG_RETPOLINE && CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_RETPOLINE && CONFIG_OBJTOOL */ =20 #ifdef CONFIG_X86_KERNEL_IBT =20 diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 219aa5ddbc73..01ce94b58b42 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -109,7 +109,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f,= int val, #endif =20 /* Unreachable code */ -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL /* * These macros help objtool understand GCC code flow for unreachable code. * The __COUNTER__ based labels are a hack to make each instance of the ma= cros @@ -128,10 +128,10 @@ void ftrace_likely_update(struct ftrace_likely_data *= f, int val, /* Annotate a C jump table to allow objtool to follow the code flow */ #define __annotate_jump_table __section(".rodata..c_jump_table") =20 -#else +#else /* !CONFIG_OBJTOOL */ #define annotate_unreachable() #define __annotate_jump_table -#endif +#endif /* CONFIG_OBJTOOL */ =20 #ifndef unreachable # define unreachable() do { \ diff --git a/include/linux/instrumentation.h b/include/linux/instrumentatio= n.h index 24359b4a9605..9111a3704072 100644 --- a/include/linux/instrumentation.h +++ b/include/linux/instrumentation.h @@ -2,7 +2,7 @@ #ifndef __LINUX_INSTRUMENTATION_H #define __LINUX_INSTRUMENTATION_H =20 -#if defined(CONFIG_DEBUG_ENTRY) && defined(CONFIG_STACK_VALIDATION) +#ifdef CONFIG_VMLINUX_VALIDATION =20 #include =20 @@ -53,9 +53,9 @@ ".popsection\n\t" : : "i" (c)); \ }) #define instrumentation_end() __instrumentation_end(__COUNTER__) -#else +#else /* !CONFIG_VMLINUX_VALIDATION */ # define instrumentation_begin() do { } while(0) # define instrumentation_end() do { } while(0) -#endif +#endif /* CONFIG_VMLINUX_VALIDATION */ =20 #endif /* __LINUX_INSTRUMENTATION_H */ diff --git a/include/linux/objtool.h b/include/linux/objtool.h index 586d35720f13..977d90ba642d 100644 --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -38,7 +38,7 @@ struct unwind_hint { #define UNWIND_HINT_TYPE_REGS_PARTIAL 2 #define UNWIND_HINT_TYPE_FUNC 3 =20 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL =20 #ifndef __ASSEMBLY__ =20 @@ -157,7 +157,7 @@ struct unwind_hint { =20 #endif /* __ASSEMBLY__ */ =20 -#else /* !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_OBJTOOL */ =20 #ifndef __ASSEMBLY__ =20 @@ -179,6 +179,6 @@ struct unwind_hint { .endm #endif =20 -#endif /* CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ =20 #endif /* _LINUX_OBJTOOL_H */ diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 2c43e327a619..2956bc277150 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -728,6 +728,7 @@ config FTRACE_MCOUNT_USE_OBJTOOL depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY depends on !FTRACE_MCOUNT_USE_CC depends on FTRACE_MCOUNT_RECORD + select OBJTOOL =20 config FTRACE_MCOUNT_USE_RECORDMCOUNT def_bool y diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 075cd25363ac..c0e4e47f3ce3 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -485,24 +485,25 @@ config FRAME_POINTER larger and slower, but it gives very useful debugging information in case of kernel bugs. (precise oopses/stacktraces/warnings) =20 +config OBJTOOL + bool + config STACK_VALIDATION bool "Compile-time stack metadata validation" - depends on HAVE_STACK_VALIDATION + depends on HAVE_STACK_VALIDATION && UNWINDER_FRAME_POINTER + select OBJTOOL default n help - Add compile-time checks to validate stack metadata, including frame - pointers (if CONFIG_FRAME_POINTER is enabled). This helps ensure - that runtime stack traces are more reliable. - - This is also a prerequisite for generation of ORC unwind data, which - is needed for CONFIG_UNWINDER_ORC. + Validate frame pointer rules at compile-time. This helps ensure that + runtime stack traces are more reliable. =20 For more information, see tools/objtool/Documentation/stack-validation.txt. =20 config VMLINUX_VALIDATION bool - depends on STACK_VALIDATION && DEBUG_ENTRY + depends on HAVE_OBJTOOL && DEBUG_ENTRY + select OBJTOOL default y =20 config VMLINUX_MAP @@ -2035,10 +2036,11 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS - depends on !ARCH_WANTS_NO_INSTR || STACK_VALIDATION || \ + depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \ GCC_VERSION >=3D 120000 || CLANG_VERSION >=3D 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC + select OBJTOOL if HAVE_OBJTOOL help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing). diff --git a/lib/Kconfig.kcsan b/lib/Kconfig.kcsan index de022445fbba..901c3b509aca 100644 --- a/lib/Kconfig.kcsan +++ b/lib/Kconfig.kcsan @@ -187,7 +187,8 @@ config KCSAN_WEAK_MEMORY # We can either let objtool nop __tsan_func_{entry,exit}() and builtin # atomics instrumentation in .noinstr.text, or use a compiler that can # implement __no_kcsan to really remove all instrumentation. - depends on STACK_VALIDATION || CC_IS_GCC || CLANG_VERSION >=3D 140000 + depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >=3D 140000 + select OBJTOOL if HAVE_OBJTOOL help Enable support for modeling a subset of weak memory, which allows detecting a subset of data races due to missing memory barriers. diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan index f3c57ed51838..c4fe15d38b60 100644 --- a/lib/Kconfig.ubsan +++ b/lib/Kconfig.ubsan @@ -94,7 +94,7 @@ config UBSAN_UNREACHABLE bool "Perform checking for unreachable code" # objtool already handles unreachable checking and gets angry about # seeing UBSan instrumentation located in unreachable places. - depends on !STACK_VALIDATION + depends on !(OBJTOOL && (STACK_VALIDATION || UNWINDER_ORC || X86_SMAP)) depends on $(cc-option,-fsanitize=3Dunreachable) help This option enables -fsanitize=3Dunreachable which checks for control diff --git a/scripts/Makefile.build b/scripts/Makefile.build index d5e15ae29156..0f73e02b7cf1 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -222,7 +222,7 @@ cmd_record_mcount =3D $(if $(findstring $(strip $(CC_FL= AGS_FTRACE)),$(_c_flags)), $(sub_cmd_record_mcount)) endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT =20 -ifdef CONFIG_STACK_VALIDATION +ifdef CONFIG_OBJTOOL =20 objtool :=3D $(objtree)/tools/objtool/objtool =20 @@ -241,7 +241,7 @@ objtool_args =3D \ cmd_objtool =3D $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep =3D $(if $(objtool-enabled), { echo ; echo '$@: $$(wild= card $(objtool))' ; } >> $(dot-target).cmd) =20 -endif # CONFIG_STACK_VALIDATION +endif # CONFIG_OBJTOOL =20 ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) =20 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 0140bfa32c0c..5101a7fbfaaf 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -108,8 +108,11 @@ objtool_link() local objtoolcmd; local objtoolopt; =20 - if is_enabled CONFIG_STACK_VALIDATION && \ - ( is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT ); t= hen + if ! is_enabled CONFIG_OBJTOOL; then + return; + fi + + if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then =20 # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. @@ -126,10 +129,23 @@ objtool_link() objtoolopt=3D"${objtoolopt} --orc" fi =20 + if is_enabled CONFIG_RETPOLINE; then + objtoolopt=3D"${objtoolopt} --retpoline" + fi + + if is_enabled CONFIG_SLS; then + objtoolopt=3D"${objtoolopt} --sls" + fi + if is_enabled CONFIG_STACK_VALIDATION; then objtoolopt=3D"${objtoolopt} --stackval" fi =20 + if is_enabled CONFIG_X86_SMAP; then + objtoolopt=3D"${objtoolopt} --uaccess" + fi + + objtoolopt=3D"${objtoolopt} --lto" fi =20 @@ -139,18 +155,6 @@ objtool_link() =20 if [ -n "${objtoolopt}" ]; then =20 - if is_enabled CONFIG_RETPOLINE; then - objtoolopt=3D"${objtoolopt} --retpoline" - fi - - if is_enabled CONFIG_SLS; then - objtoolopt=3D"${objtoolopt} --sls" - fi - - if is_enabled CONFIG_X86_SMAP; then - objtoolopt=3D"${objtoolopt} --uaccess" - fi - if ! is_enabled CONFIG_FRAME_POINTER; then objtoolopt=3D"${objtoolopt} --no-fp" fi diff --git a/scripts/package/builddeb b/scripts/package/builddeb index 91a502bb97e8..67cd420dcf89 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -67,7 +67,7 @@ deploy_kernel_headers () { ) > debian/hdrsrcfiles =20 { - if is_enabled CONFIG_STACK_VALIDATION; then + if is_enabled CONFIG_OBJTOOL; then echo tools/objtool/objtool fi =20 diff --git a/tools/include/linux/objtool.h b/tools/include/linux/objtool.h index 586d35720f13..977d90ba642d 100644 --- a/tools/include/linux/objtool.h +++ b/tools/include/linux/objtool.h @@ -38,7 +38,7 @@ struct unwind_hint { #define UNWIND_HINT_TYPE_REGS_PARTIAL 2 #define UNWIND_HINT_TYPE_FUNC 3 =20 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL =20 #ifndef __ASSEMBLY__ =20 @@ -157,7 +157,7 @@ struct unwind_hint { =20 #endif /* __ASSEMBLY__ */ =20 -#else /* !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_OBJTOOL */ =20 #ifndef __ASSEMBLY__ =20 @@ -179,6 +179,6 @@ struct unwind_hint { .endm #endif =20 -#endif /* CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ =20 #endif /* _LINUX_OBJTOOL_H */ --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0283CC433EF for ; Mon, 18 Apr 2022 16:52:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344389AbiDRQzE (ORCPT ); Mon, 18 Apr 2022 12:55:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346579AbiDRQyF (ORCPT ); Mon, 18 Apr 2022 12:54:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DD8A933A00 for ; Mon, 18 Apr 2022 09:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300682; 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: in-reply-to:in-reply-to:references:references; bh=su7xnkFX9GDMnGX5AHNxfwzIatMl5dH/eJkyCjImLTE=; b=NRmERpGsjQjP3QxW6Xoy1ZeJY7IkmygqZJ09FPhKyCm26VKhSKQ4KWY9Sb2gEC9BIlWwP8 dY3I9Eue4oRnZXuIL5Y2MEmdtyFJCqjeOZ2x6mUcAnavH9VMOMOepncC++dgGQ98v4hYy9 qFasGqD9zNVhedmOjjcMaXyknpP6EFk= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-423-0PT5eZuqNjGd9T1iCVNUng-1; Mon, 18 Apr 2022 12:51:20 -0400 X-MC-Unique: 0PT5eZuqNjGd9T1iCVNUng-1 Received: by mail-qt1-f198.google.com with SMTP id ay26-20020a05622a229a00b002f20573a0faso994183qtb.13 for ; Mon, 18 Apr 2022 09:51:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=su7xnkFX9GDMnGX5AHNxfwzIatMl5dH/eJkyCjImLTE=; b=XLml2A6pQ9QPsZqK9D5Q+wW13ck5Q7AggCynI9jKvLI6xIECutLPWERd7P0GhrHtj6 NgVrDzMus6hZENWIheVz+J3KOxkCVy0hxHZAlzA2Jr+x6R7NTtxl4tGXN7+JszTDWmCo +JP5Cpdk/z4LYNKIxGfPRI3sYXGm33U5wKgwWj0NmdINs4OtJJbEYGFMKY832MiaJH/E P009CgELGSjss32jHmErentPJzj1HaJkljc8G7zB3tb2uXm9bKVVlxK+PC+ezbtS9XcM 8QCI8nCmhKqjx5y4Ne2xBL04J7tV6tiBQPpMp11lPNTY+pnzFD1ymZwA7C/8Bu/7WbBL 7pwQ== X-Gm-Message-State: AOAM533Dl4MMmazUcAI5p4RL+LitveornGPSnZlG+Ek8xs/jGONgSTdO MyAxeFrPbPsdZy9cNnnARRpgC91cxLU8C97kaZBiOo4c9u5kpS4DkZNx5FGuikK1UijtQhKh9do aYxnzFk4PnjnM8dVJVxdvpghD X-Received: by 2002:a37:b8d:0:b0:69e:870a:e2d5 with SMTP id 135-20020a370b8d000000b0069e870ae2d5mr5354392qkl.657.1650300680135; Mon, 18 Apr 2022 09:51:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjwgVUnEZP7BIGm6tdFBVZf8vJqaL+YIqBVusNg6bbr0Y2zJqwfbkyvMfzeeO9OqP1Nf+3vQ== X-Received: by 2002:a37:b8d:0:b0:69e:870a:e2d5 with SMTP id 135-20020a370b8d000000b0069e870ae2d5mr5354381qkl.657.1650300679874; Mon, 18 Apr 2022 09:51:19 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:19 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 18/25] objtool: Make stack validation frame-pointer-specific Date: Mon, 18 Apr 2022 09:50:37 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that CONFIG_STACK_VALIDATION is frame-pointer specific, do the same for the '--stackval' option. Now the '--no-fp' option is redundant and can be removed. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- scripts/Makefile.build | 1 - scripts/link-vmlinux.sh | 4 ---- tools/objtool/builtin-check.c | 3 +-- tools/objtool/check.c | 4 ++-- tools/objtool/include/objtool/builtin.h | 1 - 5 files changed, 3 insertions(+), 10 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 0f73e02b7cf1..6eb99cb08821 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -235,7 +235,6 @@ objtool_args =3D \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) =20 cmd_objtool =3D $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 5101a7fbfaaf..1be01163a9c5 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -155,10 +155,6 @@ objtool_link() =20 if [ -n "${objtoolopt}" ]; then =20 - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt=3D"${objtoolopt} --no-fp" - fi - if is_enabled CONFIG_GCOV_KERNEL; then objtoolopt=3D"${objtoolopt} --no-unreachable" fi diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index d4e6930ad0a0..30971cc50c63 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -39,7 +39,7 @@ const struct option check_options[] =3D { OPT_BOOLEAN('o', "orc", &opts.orc, "generate ORC metadata"), OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), - OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate stack unwinding ru= les"), + OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate frame pointer rule= s"), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_= dump), =20 @@ -49,7 +49,6 @@ const struct option check_options[] =3D { OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), OPT_BOOLEAN(0, "lto", &opts.lto, "whole-archive like runs"), OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module= "), - OPT_BOOLEAN(0, "no-fp", &opts.no_fp, "skip frame pointer validation"), OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable= instruction' warnings"), OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses= in warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 88b527b3eb37..81688f6c46c0 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2807,7 +2807,7 @@ static int update_cfi_state(struct instruction *insn, } =20 /* detect when asm code uses rbp as a scratch register */ - if (!opts.no_fp && insn->func && op->src.reg =3D=3D CFI_BP && + if (opts.stackval && insn->func && op->src.reg =3D=3D CFI_BP && cfa->base !=3D CFI_BP) cfi->bp_scratch =3D true; break; @@ -3280,7 +3280,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (ret) return ret; =20 - if (!opts.no_fp && func && !is_fentry_call(insn) && + if (opts.stackval && func && !is_fentry_call(insn) && !has_valid_stack_frame(&state)) { WARN_FUNC("call without frame pointer save/setup", sec, insn->offset); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 8618585bb742..24a7ff4f37cc 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -27,7 +27,6 @@ struct opts { bool dryrun; bool lto; bool module; - bool no_fp; bool no_unreachable; bool sec_address; bool stats; --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1317EC433F5 for ; Mon, 18 Apr 2022 16:52:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346658AbiDRQzK (ORCPT ); Mon, 18 Apr 2022 12:55:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346525AbiDRQyF (ORCPT ); Mon, 18 Apr 2022 12:54:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A0B3733A06 for ; Mon, 18 Apr 2022 09:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300683; 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: in-reply-to:in-reply-to:references:references; bh=IQoyovupvdmzpIsOfZKyWaT6DU8UOCQIfFucXJdIDMw=; b=WVhtdQUx7+bldXZTpBBV72jSu5/+cygfj+2aj2J6oOJzGmA9YjM0ut/K9EEESped8piVHy NWVS02mr0+w0rTZVJnW+j/Gjvek/2a8LYHPCB9Y8DdOmgRxR+S5TJDPoOwNoEq2fUuOVQy Dil/T2+B/1ZmIRZznhRb1eCNzIESbxI= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-183-163KuWMqPha-487EadufAw-1; Mon, 18 Apr 2022 12:51:22 -0400 X-MC-Unique: 163KuWMqPha-487EadufAw-1 Received: by mail-qt1-f200.google.com with SMTP id u29-20020a05622a199d00b002e06ae2f56cso8831403qtc.12 for ; Mon, 18 Apr 2022 09:51:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IQoyovupvdmzpIsOfZKyWaT6DU8UOCQIfFucXJdIDMw=; b=u8c4TVn8FX5yjIp0gDiQuDzYSrDhe+0qbP9nFCpvkb+sIe+2DvL3q/OUahlEOG/+85 X7vKznhjnSlaamdoFH6xfV4Vrs3lcComNkbHel5SeJz9QazetwON/3bykFdp02HYvhjN sB2bj/WoJ/6QOumUZ5OvOX6ADQZ9qpAqA2vJ49PnmHirDftFG7feA0aUcnf7NXqlGbhp zmDVhfA3NIPcD9HpppnqVqpNMEqtxZVJYVYRaWaJRyPXN/6WWmP1bJLSgRKsPlq4PCde dOmwOTJSOSpD7MfiaYiBRtwGnIiiLFgt9k3YQqnawKyhGPh/E4JiGnaNJ2MxueyahNDN +Xcg== X-Gm-Message-State: AOAM532qm3wNQCMu2dpZJ1jzUFmLkMVe6qvey2jJPcIAanXNpVXwZe5H M6S+5SuquUnlbiIm/pFWKJ7e1FixnNyl9MI5fUyBlDvBX0xj2D8Qbojk110cUyIHTCqQQGXTSkP 0HshLCPcvQ3MKeh33q3P1KeI2 X-Received: by 2002:a05:620a:270d:b0:69e:bfab:6455 with SMTP id b13-20020a05620a270d00b0069ebfab6455mr90687qkp.360.1650300681662; Mon, 18 Apr 2022 09:51:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw338a2jjmdLrNBnGkKFRTZsAYTOaTkBdyQpiJYOXVUCeuXFusEo9YaO3sdR/Hrd9HvrPVKww== X-Received: by 2002:a05:620a:270d:b0:69e:bfab:6455 with SMTP id b13-20020a05620a270d00b0069ebfab6455mr90673qkp.360.1650300681429; Mon, 18 Apr 2022 09:51:21 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:20 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 19/25] objtool: Make static call annotation optional Date: Mon, 18 Apr 2022 09:50:38 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As part of making objtool more modular, put the existing static call code behind a new '--static-call' option. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 5 ++++- tools/objtool/builtin-check.c | 2 ++ tools/objtool/check.c | 10 ++++++---- tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 6eb99cb08821..3f20d565733c 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -233,6 +233,7 @@ objtool_args =3D \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ + $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 1be01163a9c5..33f14fe1ddde 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -141,11 +141,14 @@ objtool_link() objtoolopt=3D"${objtoolopt} --stackval" fi =20 + if is_enabled CONFIG_HAVE_STATIC_CALL_INLINE; then + objtoolopt=3D"${objtoolopt} --static-call" + fi + if is_enabled CONFIG_X86_SMAP; then objtoolopt=3D"${objtoolopt} --uaccess" fi =20 - objtoolopt=3D"${objtoolopt} --lto" fi =20 diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 30971cc50c63..c8c4d2bab42f 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -40,6 +40,7 @@ const struct option check_options[] =3D { OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate frame pointer rule= s"), + OPT_BOOLEAN('t', "static-call", &opts.static_call, "annotate static calls= "), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_= dump), =20 @@ -93,6 +94,7 @@ static bool opts_valid(void) opts.retpoline || opts.sls || opts.stackval || + opts.static_call || opts.uaccess) { if (opts.dump_orc) { fprintf(stderr, "--dump can't be combined with other options\n"); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 81688f6c46c0..ffb843ef372d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3970,10 +3970,12 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 - ret =3D create_static_call_sections(file); - if (ret < 0) - goto out; - warnings +=3D ret; + if (opts.static_call) { + ret =3D create_static_call_sections(file); + if (ret < 0) + goto out; + warnings +=3D ret; + } =20 if (opts.retpoline) { ret =3D create_retpoline_sites_sections(file); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 24a7ff4f37cc..dc4757205b8d 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -19,6 +19,7 @@ struct opts { bool retpoline; bool sls; bool stackval; + bool static_call; bool uaccess; =20 /* options: */ --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8DE2C433EF for ; Mon, 18 Apr 2022 16:52:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237244AbiDRQyz (ORCPT ); Mon, 18 Apr 2022 12:54:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346581AbiDRQyF (ORCPT ); Mon, 18 Apr 2022 12:54:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 35B0233366 for ; Mon, 18 Apr 2022 09:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300685; 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: in-reply-to:in-reply-to:references:references; bh=877IgX7l5iksJjHrBazlyOLpYNAXfGObg9kksRPUq7I=; b=XZytLI92RrHGELhq/Xa5TFGd5QPVCOxSbVAsn1gVcJcjF8N+zs2vF7Qhbp4PVd0TAutFF2 YQH6b7A10dLRi2HW2gncTL+mEkLXbYj19fNScbG8oW3fvqAXKkoW4h2ZvmC3U6WOZXI1xg 7S8HEGce1/SChDz0YwBn6hzOI0OsE9k= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-399-kVBHnA-GP92Pr3AMDvnNpg-1; Mon, 18 Apr 2022 12:51:23 -0400 X-MC-Unique: kVBHnA-GP92Pr3AMDvnNpg-1 Received: by mail-qk1-f197.google.com with SMTP id bp31-20020a05620a459f00b00699fabcc554so10736339qkb.12 for ; Mon, 18 Apr 2022 09:51:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=877IgX7l5iksJjHrBazlyOLpYNAXfGObg9kksRPUq7I=; b=DvF3J/rwultH+lcSLBmQPuz5hJhGJ+Y1MJJ/6J+SwPlLqIsu1Hq+9OI1I7QVLZ1O9M pnhvWrSMeka9dNfJMcsZVOl/BTIOuCPYK7x3yXl0Gt01K+Eo8h49u6YwCr4hBDflEbu5 7c0j8p+Np5Lz8KYC25TKA0w1Lyv90X4JKTrdzBSUdcvF+sJWcOh5+BwXDK9CjldWl6ho UK3bQTiTHS8JQJrCK8Zl88IvlJx9PETg+gEj/tc3egwM2KR3d0kxhbOv6q4V+tLj9D1/ /+lMIpAXkXl5QcbmUjzL8I9YI5SyyfoNuwLNt/JK6pNWmiWsThPhMsoYGndgPCHtM5WO rVWQ== X-Gm-Message-State: AOAM531+feHMRECEAHg8dpBtiYE/YKHac7RjPUCXhU+F0aBwlsmAyk8f Edo4aQl5xg5wyEyaMXkompus6PUamYTKo7ydfp/QoTisXlikSve1pga+v6O6Tro80UbJZ6mNs41 dhIYTRdxiXL3/utr9YZ3qPjXn X-Received: by 2002:ac8:7d50:0:b0:2f1:f199:3f57 with SMTP id h16-20020ac87d50000000b002f1f1993f57mr7800201qtb.525.1650300683128; Mon, 18 Apr 2022 09:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG4cOq1unS852QsokIDL5Wk7ENznw0SL9ejbz1MC4t6l0hYAeiiN/Lkd74zxCEDVn+HHdT1A== X-Received: by 2002:ac8:7d50:0:b0:2f1:f199:3f57 with SMTP id h16-20020ac87d50000000b002f1f1993f57mr7800191qtb.525.1650300682855; Mon, 18 Apr 2022 09:51:22 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:22 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 20/25] objtool: Make jump label hack optional Date: Mon, 18 Apr 2022 09:50:39 -0700 Message-Id: <3bdcbfdd27ecb01ddec13c04bdf756a583b13d24.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Objtool secretly does a jump label hack to overcome the limitations of the toolchain. Make the hack explicit (and optional for other arches) by turning it into a cmdline option and kernel config option. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- arch/Kconfig | 4 +++ arch/x86/Kconfig | 1 + arch/x86/include/asm/jump_label.h | 6 ++-- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 +++ tools/objtool/builtin-check.c | 37 +++++++++++++++++++------ tools/objtool/check.c | 2 +- tools/objtool/include/objtool/builtin.h | 1 + 8 files changed, 44 insertions(+), 12 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 04cdef16db24..9dce6d6e3bc3 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -46,6 +46,7 @@ config JUMP_LABEL bool "Optimize very unlikely/likely branches" depends on HAVE_ARCH_JUMP_LABEL depends on CC_HAS_ASM_GOTO + select OBJTOOL if HAVE_JUMP_LABEL_HACK help This option enables a transparent branch optimization that makes certain almost-always-true or almost-always-false branch @@ -1031,6 +1032,9 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT config HAVE_OBJTOOL bool =20 +config HAVE_JUMP_LABEL_HACK + bool + config HAVE_STACK_VALIDATION bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index bce0c23f3550..46218967129f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -212,6 +212,7 @@ config X86 select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 select HAVE_IRQ_TIME_ACCOUNTING + select HAVE_JUMP_LABEL_HACK if HAVE_OBJTOOL select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZ4 diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_= label.h index 3ce0e67c579c..071572e23d3a 100644 --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -20,7 +20,7 @@ _ASM_PTR "%c0 + %c1 - .\n\t" \ ".popsection \n\t" =20 -#ifdef CONFIG_OBJTOOL +#ifdef CONFIG_HAVE_JUMP_LABEL_HACK =20 static __always_inline bool arch_static_branch(struct static_key *key, boo= l branch) { @@ -34,7 +34,7 @@ static __always_inline bool arch_static_branch(struct sta= tic_key *key, bool bran return true; } =20 -#else /* !CONFIG_OBJTOOL */ +#else /* !CONFIG_HAVE_JUMP_LABEL_HACK */ =20 static __always_inline bool arch_static_branch(struct static_key * const k= ey, const bool branch) { @@ -48,7 +48,7 @@ static __always_inline bool arch_static_branch(struct sta= tic_key * const key, co return true; } =20 -#endif /* CONFIG_OBJTOOL */ +#endif /* CONFIG_HAVE_JUMP_LABEL_HACK */ =20 static __always_inline bool arch_static_branch_jump(struct static_key * co= nst key, const bool branch) { diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 3f20d565733c..f1d2c2e4f15b 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -227,6 +227,7 @@ ifdef CONFIG_OBJTOOL objtool :=3D $(objtree)/tools/objtool/objtool =20 objtool_args =3D \ + $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=3Djump_label) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 33f14fe1ddde..fa1f16840e76 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -117,6 +117,10 @@ objtool_link() # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. =20 + if is_enabled CONFIG_HAVE_JUMP_LABEL_HACK; then + objtoolopt=3D"${objtoolopt} --hacks=3Djump_label" + fi + if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt=3D"${objtoolopt} --ibt" fi diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index c8c4d2bab42f..b2c626d9e2bf 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -31,8 +31,28 @@ static int parse_dump(const struct option *opt, const ch= ar *str, int unset) return -1; } =20 +static int parse_hacks(const struct option *opt, const char *str, int unse= t) +{ + bool found =3D false; + + /* + * Use strstr() as a lazy method of checking for comma-separated + * options. + * + * No string provided =3D=3D enable all options. + */ + + if (!str || strstr(str, "jump_label")) { + opts.hack_jump_label =3D true; + found =3D true; + } + + return found ? 0 : -1; +} + const struct option check_options[] =3D { OPT_GROUP("Actions:"), + OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label", "patch toolch= ain bugs/limitations", parse_hacks), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls fo= r ftrace"), OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), @@ -87,14 +107,15 @@ int cmd_parse_options(int argc, const char **argv, con= st char * const usage[]) =20 static bool opts_valid(void) { - if (opts.ibt || - opts.mcount || - opts.noinstr || - opts.orc || - opts.retpoline || - opts.sls || - opts.stackval || - opts.static_call || + if (opts.hack_jump_label || + opts.ibt || + opts.mcount || + opts.noinstr || + opts.orc || + opts.retpoline || + opts.sls || + opts.stackval || + opts.static_call || opts.uaccess) { if (opts.dump_orc) { fprintf(stderr, "--dump can't be combined with other options\n"); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index ffb843ef372d..eb3dffab8767 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1593,7 +1593,7 @@ static int handle_jump_alt(struct objtool_file *file, return -1; } =20 - if (special_alt->key_addend & 2) { + if (opts.hack_jump_label && special_alt->key_addend & 2) { struct reloc *reloc =3D insn_reloc(file, orig_insn); =20 if (reloc) { diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index dc4757205b8d..c6acf05ec859 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -12,6 +12,7 @@ extern const struct option check_options[]; struct opts { /* actions: */ bool dump_orc; + bool hack_jump_label; bool ibt; bool mcount; bool noinstr; --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 019C0C433F5 for ; Mon, 18 Apr 2022 16:52:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346666AbiDRQyo (ORCPT ); Mon, 18 Apr 2022 12:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346545AbiDRQyH (ORCPT ); Mon, 18 Apr 2022 12:54:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A06943336B for ; Mon, 18 Apr 2022 09:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300686; 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: in-reply-to:in-reply-to:references:references; bh=uqyyOyU+oF0x6XbbGeKBAVgTXffqShf6wIPFqSB+NZE=; b=Z/86KZVAOPhkm8jlbLW0eAOCU3e6+F+oO/tDnFnUT7iptOF9GU++Sof0wJxNdj4MCUos0x vJdtUbble7xeb/aUGOl+aR5LRC0hHIHxG+6n0XjuyhUmDbr7Fy316kS1qfNo8r7TWWcpnk 5Cs0a04bK2G/PWhpATWqHAVsRS5A97c= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-144-51c0E7QPNkCH86XnfD94GQ-1; Mon, 18 Apr 2022 12:51:25 -0400 X-MC-Unique: 51c0E7QPNkCH86XnfD94GQ-1 Received: by mail-qt1-f198.google.com with SMTP id a25-20020ac844b9000000b002f1f8988487so2465003qto.17 for ; Mon, 18 Apr 2022 09:51:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uqyyOyU+oF0x6XbbGeKBAVgTXffqShf6wIPFqSB+NZE=; b=oxlmJIMixnVfjSy7nDobN9SZMe224wCPzRVtICZPC9ED4awRAOnNtqmjXUxT7pH5IQ +yEp74rVrPKTbiRBeV2CdIgGA8Y6TdJWmlBDPf9NzhiWLmVKWe4tr7zd0OosU7Cc34Oo VrXtuUwvPC1jYYI79ROUQlOFp6gK9rTcu7QzCK2TjjXCjen1pozdyelvsilaeitI/DIs wo5mryP7YXBJFrJJn3tynAHApZIn2Ls4KpmrUccBGhmmJt62F1fkoMX6l2V9PVHL6Ayy omFQ/feUArjcE+wDP6Shhb1DmWRwdhXzHQ5t3R7bGpYH70O6W00QbDWKMrUYXeuX0Vas S5Sg== X-Gm-Message-State: AOAM532XDEGZwmkDc7aRyXTatnT87aWk/8nkQwE1hYnqdVgUamgfQ9L9 sK/2bxcZaagwJz9/3QBpW90SChVorHtmwRMxJcDVWgW3BszMcm+h6fyem2kJhzESZ9+VUS14d8O w32ISF6Aw8N8nkrvPSn0Kog32 X-Received: by 2002:ac8:5a45:0:b0:2e2:27e5:1416 with SMTP id o5-20020ac85a45000000b002e227e51416mr7535514qta.481.1650300684672; Mon, 18 Apr 2022 09:51:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHn2j17gsdewITv0R11ecOMcEfblsLj29W1j/mkPgh7bmqQV4dWr28x/DNR9bsasZbzx1pog== X-Received: by 2002:ac8:5a45:0:b0:2e2:27e5:1416 with SMTP id o5-20020ac85a45000000b002e227e51416mr7535501qta.481.1650300684396; Mon, 18 Apr 2022 09:51:24 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:23 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 21/25] objtool: Make noinstr hacks optional Date: Mon, 18 Apr 2022 09:50:40 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Objtool has some hacks in place to workaround toolchain limitations which otherwise would break no-instrumentation rules. Make the hacks explicit (and optional for other arches) by turning it into a cmdline option and kernel config option. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + lib/Kconfig.debug | 4 ++-- lib/Kconfig.kcsan | 5 +++-- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 ++++ tools/objtool/builtin-check.c | 8 +++++++- tools/objtool/check.c | 2 +- tools/objtool/include/objtool/builtin.h | 1 + 9 files changed, 23 insertions(+), 6 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 9dce6d6e3bc3..6ba6e34db0ea 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1035,6 +1035,9 @@ config HAVE_OBJTOOL config HAVE_JUMP_LABEL_HACK bool =20 +config HAVE_NOINSTR_HACK + bool + config HAVE_STACK_VALIDATION bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 46218967129f..cc7cca041745 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -231,6 +231,7 @@ config X86 select HAVE_MOD_ARCH_SPECIFIC select HAVE_MOVE_PMD select HAVE_MOVE_PUD + select HAVE_NOINSTR_HACK if HAVE_OBJTOOL select HAVE_NMI select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index c0e4e47f3ce3..7d2bbc3e558e 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2036,11 +2036,11 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS - depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \ + depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \ GCC_VERSION >=3D 120000 || CLANG_VERSION >=3D 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC - select OBJTOOL if HAVE_OBJTOOL + select OBJTOOL if HAVE_NOINSTR_HACK help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing). diff --git a/lib/Kconfig.kcsan b/lib/Kconfig.kcsan index 901c3b509aca..47a693c45864 100644 --- a/lib/Kconfig.kcsan +++ b/lib/Kconfig.kcsan @@ -187,8 +187,9 @@ config KCSAN_WEAK_MEMORY # We can either let objtool nop __tsan_func_{entry,exit}() and builtin # atomics instrumentation in .noinstr.text, or use a compiler that can # implement __no_kcsan to really remove all instrumentation. - depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >=3D 140000 - select OBJTOOL if HAVE_OBJTOOL + depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \ + CC_IS_GCC || CLANG_VERSION >=3D 140000 + select OBJTOOL if HAVE_NOINSTR_HACK help Enable support for modeling a subset of weak memory, which allows detecting a subset of data races due to missing memory barriers. diff --git a/scripts/Makefile.build b/scripts/Makefile.build index f1d2c2e4f15b..6c206a1bab97 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -228,6 +228,7 @@ objtool :=3D $(objtree)/tools/objtool/objtool =20 objtool_args =3D \ $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=3Djump_label) \ + $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=3Dnoinstr) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index fa1f16840e76..90c9c4c05d95 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -121,6 +121,10 @@ objtool_link() objtoolopt=3D"${objtoolopt} --hacks=3Djump_label" fi =20 + if is_enabled CONFIG_HAVE_NOINSTR_HACK; then + objtoolopt=3D"${objtoolopt} --hacks=3Dnoinstr" + fi + if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt=3D"${objtoolopt} --ibt" fi diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index b2c626d9e2bf..1803a63147e4 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -47,12 +47,17 @@ static int parse_hacks(const struct option *opt, const = char *str, int unset) found =3D true; } =20 + if (!str || strstr(str, "noinstr")) { + opts.hack_noinstr =3D true; + found =3D true; + } + return found ? 0 : -1; } =20 const struct option check_options[] =3D { OPT_GROUP("Actions:"), - OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label", "patch toolch= ain bugs/limitations", parse_hacks), + OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr", "patc= h toolchain bugs/limitations", parse_hacks), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls fo= r ftrace"), OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), @@ -108,6 +113,7 @@ int cmd_parse_options(int argc, const char **argv, cons= t char * const usage[]) static bool opts_valid(void) { if (opts.hack_jump_label || + opts.hack_noinstr || opts.ibt || opts.mcount || opts.noinstr || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index eb3dffab8767..6a7b5fa3fe1b 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1145,7 +1145,7 @@ static void annotate_call_site(struct objtool_file *f= ile, * attribute so they need a little help, NOP out any such calls from * noinstr text. */ - if (insn->sec->noinstr && sym->profiling_func) { + if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) { if (reloc) { reloc->type =3D R_NONE; elf_write_reloc(file->elf, reloc); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index c6acf05ec859..f3a1a754b5c4 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -13,6 +13,7 @@ struct opts { /* actions: */ bool dump_orc; bool hack_jump_label; + bool hack_noinstr; bool ibt; bool mcount; bool noinstr; --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60471C4332F for ; Mon, 18 Apr 2022 16:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234693AbiDRQyv (ORCPT ); Mon, 18 Apr 2022 12:54:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346591AbiDRQyI (ORCPT ); Mon, 18 Apr 2022 12:54:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EF93A326E6 for ; Mon, 18 Apr 2022 09:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300688; 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: in-reply-to:in-reply-to:references:references; bh=zvi0HZ5G+8+6iQXet7yWC1URq0baxNRF0cauqcyCwY0=; b=JodsQ2lsNZtKwyK5zhR50knRcOFFceANsrfs9cgeoBw5gzmJmNe11+J8RsXhBgTtUeY4EF SIusWnN8F2tqFvyQFGO+Os1u40Z8GFrXdAVO+U1XvkImDi7Hp0mJauX3B5EUPGY31HE18+ fuJGnwF0cgJC2i7Evyro+ydB4E0sIyM= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-600-TJbgYh_jMfGULual1HzXOA-1; Mon, 18 Apr 2022 12:51:26 -0400 X-MC-Unique: TJbgYh_jMfGULual1HzXOA-1 Received: by mail-qv1-f71.google.com with SMTP id kj4-20020a056214528400b0044399a9bb4cso12548251qvb.15 for ; Mon, 18 Apr 2022 09:51:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zvi0HZ5G+8+6iQXet7yWC1URq0baxNRF0cauqcyCwY0=; b=5bPqyw8fEptI6iNR2tnIewJD8Mck8lMesKpfeDmdVd5T6IZJ9IHxizHw2vaG7+KOd/ uZ7cZ9B2u8Qcv4wxMLmQhqdQK44QKnEG0cMTjmSdi1SwCsleLeA2Fq4d5QprO7rDRGLS UVR7eccdI7bCWhbkRn8mF/3wdqjWyWYV8aZ10dcEUraRO9J/aDkBM/1zeXgdjX9HKiul TaJfS3KrL2DaNmHB1F42G81j9+Tr1mm05gwvCYtwcUG06FIliMDb29NxyscJCWhNqPie kKxtGd+hAqaPdMGKcJrWHL0ANPijdmWcf26iLoyF78cbncIsQrNmuqBrje9ldqyQ2Ymm 6OHw== X-Gm-Message-State: AOAM533SDSArNlcxN7GdjNpviY7y01LlTeLtKm8/2STYneefx7WTXK0s vLoaaiLFZa8+ohsGPx0IL3KQ8ysST4lWZFzXZFLqL1s4r9j87Rn7qhge8ipj4mmzX7OScvEiS3X iv+foudYKpgDOV9zEa/tTDZxy X-Received: by 2002:a05:6214:23ce:b0:443:8505:14bb with SMTP id hr14-20020a05621423ce00b00443850514bbmr8499309qvb.25.1650300686343; Mon, 18 Apr 2022 09:51:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZWK9bjOKc9EubcgN4tKUXNN85UhS/aJi2MibvLsXgUNe9zHfgn4PHpOdR3a4YDndtamD6Gw== X-Received: by 2002:a05:6214:23ce:b0:443:8505:14bb with SMTP id hr14-20020a05621423ce00b00443850514bbmr8499295qvb.25.1650300686112; Mon, 18 Apr 2022 09:51:26 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:25 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 22/25] objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION" Date: Mon, 18 Apr 2022 09:50:41 -0700 Message-Id: <173f07e2d6d1afc0874aed975a61783207c6a531.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" CONFIG_VMLINUX_VALIDATION is just the validation of the "noinstr" rules. That name is a misnomer, because now objtool actually does vmlinux validation for other reasons. Rename CONFIG_VMLINUX_VALIDATION to CONFIG_NOINSTR_VALIDATION. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- include/linux/instrumentation.h | 6 +++--- lib/Kconfig.debug | 2 +- scripts/link-vmlinux.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/instrumentation.h b/include/linux/instrumentatio= n.h index 9111a3704072..bc7babe91b2e 100644 --- a/include/linux/instrumentation.h +++ b/include/linux/instrumentation.h @@ -2,7 +2,7 @@ #ifndef __LINUX_INSTRUMENTATION_H #define __LINUX_INSTRUMENTATION_H =20 -#ifdef CONFIG_VMLINUX_VALIDATION +#ifdef CONFIG_NOINSTR_VALIDATION =20 #include =20 @@ -53,9 +53,9 @@ ".popsection\n\t" : : "i" (c)); \ }) #define instrumentation_end() __instrumentation_end(__COUNTER__) -#else /* !CONFIG_VMLINUX_VALIDATION */ +#else /* !CONFIG_NOINSTR_VALIDATION */ # define instrumentation_begin() do { } while(0) # define instrumentation_end() do { } while(0) -#endif /* CONFIG_VMLINUX_VALIDATION */ +#endif /* CONFIG_NOINSTR_VALIDATION */ =20 #endif /* __LINUX_INSTRUMENTATION_H */ diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 7d2bbc3e558e..73359d6cd9a2 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -500,7 +500,7 @@ config STACK_VALIDATION For more information, see tools/objtool/Documentation/stack-validation.txt. =20 -config VMLINUX_VALIDATION +config NOINSTR_VALIDATION bool depends on HAVE_OBJTOOL && DEBUG_ENTRY select OBJTOOL diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 90c9c4c05d95..fce4f41816cd 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -160,7 +160,7 @@ objtool_link() objtoolopt=3D"${objtoolopt} --lto" fi =20 - if is_enabled CONFIG_VMLINUX_VALIDATION; then + if is_enabled CONFIG_NOINSTR_VALIDATION; then objtoolopt=3D"${objtoolopt} --noinstr" fi =20 --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B1ABC433EF for ; Mon, 18 Apr 2022 16:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346758AbiDRQzb (ORCPT ); Mon, 18 Apr 2022 12:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346501AbiDRQyK (ORCPT ); Mon, 18 Apr 2022 12:54:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8CF2232EF3 for ; Mon, 18 Apr 2022 09:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300689; 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: in-reply-to:in-reply-to:references:references; bh=zxjNN+ra2AhCANWxkWyISdn+Fo3V4/vBPneJRjlR5i0=; b=Z1SEElzmm4oAEMzx3yEP4Hz4TnfbiJYezc59JGFm19pcKIz1AYeXbvKehNk2yazaLdwZgJ 2mP/tIdqgb2HP/yoCl+FgCBhnxKGKZxPBEInArxdKT0ptPvlQOxhygyqegiEMK7AAnNVdi mfSiz/uV0FSZXCx7jT5lPhqfSPjX3dE= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-628-Bx8aq9S-OfeV2QedTR9epQ-1; Mon, 18 Apr 2022 12:51:28 -0400 X-MC-Unique: Bx8aq9S-OfeV2QedTR9epQ-1 Received: by mail-qt1-f197.google.com with SMTP id m3-20020ac86883000000b002ed8d29a300so8827198qtq.11 for ; Mon, 18 Apr 2022 09:51:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zxjNN+ra2AhCANWxkWyISdn+Fo3V4/vBPneJRjlR5i0=; b=F/JHv7XN6YpGGQwhTnimKIt9CjC+QNObNzB289zi0lXTFLzX8KqPf72528QZmmpwoD jggDHjFk3OSVDAQyr4KH8nBo2EBpB3q2lIsrINvEjbIFccDfHjjX8vIXtYTxqyTklNwg 9bHzTH+7e9/5glIGVzJy5uitmISQubPxunYppsBydX68C5xG5yDJCLEkH22bkiaKgkUL KKqQI1T+a1X4LkX19B1OxaTuVS8oCEgp0bNeKAzvZyrbItM+XhVZKn72EHntMfRoZffE zghct8cUihCPd7k8O+Xp5euoK5SOaUoS0ATSY0p3Chs4L4Ridbaivr60r8ZXxBgS4bOJ g0Jg== X-Gm-Message-State: AOAM5307Kursr76GEIbc1JAyzC4ZzYLkQ7AspDp0x8NK0JqFM2UcdZ3V t3Sxg7LEAkGoWbMCYvx/Kny3WTOxJFer7FQ49a4UKeoqAdTDJfS64r7fb0q3qX41XmKOaBHkbDr yUj+a5f8zRQ4rZIuGM3Uh9mrI X-Received: by 2002:ac8:7441:0:b0:2f1:d1d4:e4cc with SMTP id h1-20020ac87441000000b002f1d1d4e4ccmr7783520qtr.14.1650300687962; Mon, 18 Apr 2022 09:51:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbMfrsVNOVFQpjjNwLQZ4lN8sU2K+zEnFfnoqBjmhgiVmeevwMGEvg1zKOZ7NvA4Ais+ckJg== X-Received: by 2002:ac8:7441:0:b0:2f1:d1d4:e4cc with SMTP id h1-20020ac87441000000b002f1d1d4e4ccmr7783510qtr.14.1650300687764; Mon, 18 Apr 2022 09:51:27 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:27 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 23/25] objtool: Add HAVE_NOINSTR_VALIDATION Date: Mon, 18 Apr 2022 09:50:42 -0700 Message-Id: <488e94f69db4df154499bc098573d90e5db1c826.1650300597.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove CONFIG_NOINSTR_VALIDATION's dependency on HAVE_OBJTOOL, since other arches might want to implement objtool without it. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + lib/Kconfig.debug | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index 6ba6e34db0ea..1e19da774e55 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1038,6 +1038,9 @@ config HAVE_JUMP_LABEL_HACK config HAVE_NOINSTR_HACK bool =20 +config HAVE_NOINSTR_VALIDATION + bool + config HAVE_STACK_VALIDATION bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index cc7cca041745..c8f560802bf2 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -233,6 +233,7 @@ config X86 select HAVE_MOVE_PUD select HAVE_NOINSTR_HACK if HAVE_OBJTOOL select HAVE_NMI + select HAVE_NOINSTR_VALIDATION if HAVE_OBJTOOL select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES select HAVE_PCSPKR_PLATFORM diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 73359d6cd9a2..55b9acb2f524 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -502,7 +502,7 @@ config STACK_VALIDATION =20 config NOINSTR_VALIDATION bool - depends on HAVE_OBJTOOL && DEBUG_ENTRY + depends on HAVE_NOINSTR_VALIDATION && DEBUG_ENTRY select OBJTOOL default y =20 --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5884C433EF for ; Mon, 18 Apr 2022 16:52:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346701AbiDRQzd (ORCPT ); Mon, 18 Apr 2022 12:55:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346595AbiDRQyM (ORCPT ); Mon, 18 Apr 2022 12:54:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 76FAF33340 for ; Mon, 18 Apr 2022 09:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300691; 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: in-reply-to:in-reply-to:references:references; bh=r7maJXgp62wMR2+BaJIy73ifAiDaDMrmt/iAqLxQ2aM=; b=L7SQgYgGfW6nhKcj8A/D0+Lw1dwL3sTrWbD8uFdxaUj5kD1Ah6VKvwn0aCEbYxxzQoeBtA AVYIQK4IbxKS1agXVXTruyTCOBh99duO10Kt8JcANE/tGuEmVsljfwlpnSTLwAsWVgPuAx iMdsuC4EmzPELyP/UHQ9xt4hy+pkTRs= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-630-vYudvZ7MOmKZrtNkVjUQVg-1; Mon, 18 Apr 2022 12:51:30 -0400 X-MC-Unique: vYudvZ7MOmKZrtNkVjUQVg-1 Received: by mail-qk1-f198.google.com with SMTP id m23-20020a05620a221700b006809e1fa4fdso10733980qkh.6 for ; Mon, 18 Apr 2022 09:51:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r7maJXgp62wMR2+BaJIy73ifAiDaDMrmt/iAqLxQ2aM=; b=CjUl+gnJ9G/QPfjedQayki6QByH3Jd4jewuMobKQ66OVIzkhzICIUdBXwmovTkD9SK XNkTUB5yLypL2NooqkV0ACrC4ewelmmUcAT0K/TLJIZ4K+vjUYOMCA7zFvVrDFQ1iw3l iatXa9ES2tQD5irwBc6ueWAnaCDKGey7S2XYr5x4Y1RBDEj6MxKqIaMUjp3zkBTjUafB tGJuONZ6wyrtkc/SrpjDlvjfX6bmmnUm9vYn/ne6/0PsEbD34cYAginHekWd316gUlwJ HeDmJnjfZ2xxltEPhThYcKU99kplpcoXzTlIu5XtXtBGbbmPn4v3za4twtd4uTZC9cla QNgQ== X-Gm-Message-State: AOAM532SYCe7lC+nav0gVWYoFUc9bjzFw6XHoyRibZeiL3Pa/zLDBCRx M3PngFXXucEX7S0j3xO3rLrwAcfhIuaTg/mJ7lKFfJwk8sF9x61KsQfhXol63W/y6GKO8cK4XnB LIttE5mHgTcGfJwXPgCHHVx7g X-Received: by 2002:a05:620a:404c:b0:69c:10ec:338a with SMTP id i12-20020a05620a404c00b0069c10ec338amr7354248qko.114.1650300689574; Mon, 18 Apr 2022 09:51:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdw0Xrlr89DRCL2uBkbQ77olLLvfIwpy0xao8Wiwwvfo9U2kM8wzxHMxi6K/jjP4pW2rESZA== X-Received: by 2002:a05:620a:404c:b0:69c:10ec:338a with SMTP id i12-20020a05620a404c00b0069c10ec338amr7354234qko.114.1650300689237; Mon, 18 Apr 2022 09:51:29 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:28 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 24/25] objtool: Remove --lto and --vmlinux in favor of --link Date: Mon, 18 Apr 2022 09:50:43 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The '--lto' option is a confusing way of telling objtool to do stack validation despite it being a linked object. It's no longer needed now that an explicit '--stackval' option exists. The '--vmlinux' option is also redundant. Remove both options in favor of a straightforward '--link' option which identifies a linked object. Also, implicitly set '--link' with a warning if the user forgets to do so and we can tell that it's a linked object. This makes it easier for manual vmlinux runs. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- scripts/Makefile.build | 4 ++- scripts/link-vmlinux.sh | 8 ++--- tools/objtool/builtin-check.c | 39 +++++++++++++++++++++--- tools/objtool/check.c | 40 +++++++++---------------- tools/objtool/elf.c | 3 ++ tools/objtool/include/objtool/builtin.h | 3 +- tools/objtool/include/objtool/elf.h | 12 +++++++- 7 files changed, 70 insertions(+), 39 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 6c206a1bab97..ac8167227bc0 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -229,7 +229,7 @@ objtool :=3D $(objtree)/tools/objtool/objtool objtool_args =3D \ $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=3Djump_label) \ $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=3Dnoinstr) \ - $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ + $(if $(CONFIG_X86_KERNEL_IBT), --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ @@ -237,6 +237,7 @@ objtool_args =3D \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ + $(if $(linked-object), --link) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) =20 @@ -306,6 +307,7 @@ quiet_cmd_cc_prelink_modules =3D LD [M] $@ # modules into native code $(obj)/%.prelink.o: objtool-enabled =3D y $(obj)/%.prelink.o: part-of-module :=3D y +$(obj)/%.prelink.o: linked-object :=3D y =20 $(obj)/%.prelink.o: $(obj)/%.o FORCE $(call if_changed,cc_prelink_modules) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index fce4f41816cd..eb9324f07f3d 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -114,8 +114,8 @@ objtool_link() =20 if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then =20 - # Don't perform vmlinux validation unless explicitly requested, - # but run objtool on vmlinux.o now that we have an object file. + # For LTO and IBT, objtool doesn't run on individual + # translation units. Run everything on vmlinux instead. =20 if is_enabled CONFIG_HAVE_JUMP_LABEL_HACK; then objtoolopt=3D"${objtoolopt} --hacks=3Djump_label" @@ -156,8 +156,6 @@ objtool_link() if is_enabled CONFIG_X86_SMAP; then objtoolopt=3D"${objtoolopt} --uaccess" fi - - objtoolopt=3D"${objtoolopt} --lto" fi =20 if is_enabled CONFIG_NOINSTR_VALIDATION; then @@ -170,7 +168,7 @@ objtool_link() objtoolopt=3D"${objtoolopt} --no-unreachable" fi =20 - objtoolopt=3D"${objtoolopt} --vmlinux" + objtoolopt=3D"${objtoolopt} --link" =20 info OBJTOOL ${1} tools/objtool/objtool ${objtoolopt} ${1} diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 1803a63147e4..f4c3a5091737 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -9,6 +9,11 @@ #include #include =20 +#define ERROR(format, ...) \ + fprintf(stderr, \ + "error: objtool: " format "\n", \ + ##__VA_ARGS__) + struct opts opts; =20 static const char * const check_usage[] =3D { @@ -73,12 +78,11 @@ const struct option check_options[] =3D { OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"), OPT_BOOLEAN(0, "backup", &opts.backup, "create .orig files before modific= ation"), OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), - OPT_BOOLEAN(0, "lto", &opts.lto, "whole-archive like runs"), + OPT_BOOLEAN(0, "link", &opts.link, "object is a linked object"), OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module= "), OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable= instruction' warnings"), OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses= in warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), - OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"), =20 OPT_END(), }; @@ -124,7 +128,7 @@ static bool opts_valid(void) opts.static_call || opts.uaccess) { if (opts.dump_orc) { - fprintf(stderr, "--dump can't be combined with other options\n"); + ERROR("--dump can't be combined with other options"); return false; } =20 @@ -134,10 +138,34 @@ static bool opts_valid(void) if (opts.dump_orc) return true; =20 - fprintf(stderr, "At least one command required\n"); + ERROR("At least one command required"); return false; } =20 +static bool link_opts_valid(struct objtool_file *file) +{ + if (opts.link) + return true; + + if (has_multiple_files(file->elf)) { + ERROR("Linked object detected, forcing --link"); + opts.link =3D true; + return true; + } + + if (opts.noinstr) { + ERROR("--noinstr requires --link"); + return false; + } + + if (opts.ibt) { + ERROR("--ibt requires --link"); + return false; + } + + return true; +} + int objtool_run(int argc, const char **argv) { const char *objname; @@ -157,6 +185,9 @@ int objtool_run(int argc, const char **argv) if (!file) return 1; =20 + if (!link_opts_valid(file)) + return 1; + ret =3D check(file); if (ret) return ret; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 6a7b5fa3fe1b..60b6a2a712b5 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -264,7 +264,8 @@ static void init_cfi_state(struct cfi_state *cfi) cfi->drap_offset =3D -1; } =20 -static void init_insn_state(struct insn_state *state, struct section *sec) +static void init_insn_state(struct objtool_file *file, struct insn_state *= state, + struct section *sec) { memset(state, 0, sizeof(*state)); init_cfi_state(&state->cfi); @@ -274,7 +275,7 @@ static void init_insn_state(struct insn_state *state, s= truct section *sec) * not correctly determine insn->call_dest->sec (external symbols do * not have a section). */ - if (opts.vmlinux && opts.noinstr && sec) + if (opts.link && opts.noinstr && sec) state->noinstr =3D sec->noinstr; } =20 @@ -3406,7 +3407,7 @@ static int validate_unwind_hints(struct objtool_file = *file, struct section *sec) if (!file->hints) return 0; =20 - init_insn_state(&state, sec); + init_insn_state(file, &state, sec); =20 if (sec) { insn =3D find_insn(file, sec, 0); @@ -3492,14 +3493,14 @@ static bool ignore_unreachable_insn(struct objtool_= file *file, struct instructio return true; =20 /* - * Whole archive runs might encounder dead code from weak symbols. + * Whole archive runs might encounter dead code from weak symbols. * This is where the linker will have dropped the weak symbol in * favour of a regular symbol, but leaves the code in place. * * In this case we'll find a piece of code (whole function) that is not * covered by a !section symbol. Ignore them. */ - if (!insn->func && opts.lto) { + if (opts.link && !insn->func) { int size =3D find_symbol_hole_containing(insn->sec, insn->offset); unsigned long end =3D insn->offset + size; =20 @@ -3621,7 +3622,7 @@ static int validate_section(struct objtool_file *file= , struct section *sec) if (func->type !=3D STT_FUNC) continue; =20 - init_insn_state(&state, sec); + init_insn_state(file, &state, sec); set_func_state(&state.cfi); =20 warnings +=3D validate_symbol(file, sec, func, &state); @@ -3630,7 +3631,7 @@ static int validate_section(struct objtool_file *file= , struct section *sec) return warnings; } =20 -static int validate_vmlinux_functions(struct objtool_file *file) +static int validate_noinstr_sections(struct objtool_file *file) { struct section *sec; int warnings =3D 0; @@ -3891,16 +3892,6 @@ int check(struct objtool_file *file) { int ret, warnings =3D 0; =20 - if (opts.lto && !(opts.vmlinux || opts.module)) { - fprintf(stderr, "--lto requires: --vmlinux or --module\n"); - return 1; - } - - if (opts.ibt && !opts.lto) { - fprintf(stderr, "--ibt requires: --lto\n"); - return 1; - } - arch_initial_func_cfi_state(&initial_func_cfi); init_cfi_state(&init_cfi); init_cfi_state(&func_cfi); @@ -3921,15 +3912,6 @@ int check(struct objtool_file *file) if (list_empty(&file->insn_list)) goto out; =20 - if (opts.vmlinux && !opts.lto) { - ret =3D validate_vmlinux_functions(file); - if (ret < 0) - goto out; - - warnings +=3D ret; - goto out; - } - if (opts.retpoline) { ret =3D validate_retpoline(file); if (ret < 0) @@ -3954,6 +3936,12 @@ int check(struct objtool_file *file) goto out; warnings +=3D ret; } + + } else if (opts.noinstr) { + ret =3D validate_noinstr_sections(file); + if (ret < 0) + goto out; + warnings +=3D ret; } =20 if (opts.ibt) { diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index f7b2ad27bb1c..41fea838aeba 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -377,6 +377,9 @@ static void elf_add_symbol(struct elf *elf, struct symb= ol *sym) sym->type =3D GELF_ST_TYPE(sym->sym.st_info); sym->bind =3D GELF_ST_BIND(sym->sym.st_info); =20 + if (sym->type =3D=3D STT_FILE) + elf->num_files++; + sym->offset =3D sym->sym.st_value; sym->len =3D sym->sym.st_size; =20 diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index f3a1a754b5c4..280ea18b7f2b 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -28,12 +28,11 @@ struct opts { bool backtrace; bool backup; bool dryrun; - bool lto; + bool link; bool module; bool no_unreachable; bool sec_address; bool stats; - bool vmlinux; }; =20 extern struct opts opts; diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 22ba7e2b816e..9bb1e20c4462 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -86,7 +86,7 @@ struct elf { int fd; bool changed; char *name; - unsigned int text_size; + unsigned int text_size, num_files; struct list_head sections; =20 int symbol_bits; @@ -131,6 +131,16 @@ static inline u32 reloc_hash(struct reloc *reloc) return sec_offset_hash(reloc->sec, reloc->offset); } =20 +/* + * Try to see if it's a whole archive (vmlinux.o or module). + * + * Note this will miss the case where a module only has one source file. + */ +static inline bool has_multiple_files(struct elf *elf) +{ + return elf->num_files > 1; +} + struct elf *elf_open_read(const char *name, int flags); struct section *elf_create_section(struct elf *elf, const char *name, unsi= gned int sh_flags, size_t entsize, int nr); =20 --=20 2.34.1 From nobody Mon May 11 04:51:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD80BC433EF for ; Mon, 18 Apr 2022 16:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346712AbiDRQzg (ORCPT ); Mon, 18 Apr 2022 12:55:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233533AbiDRQyQ (ORCPT ); Mon, 18 Apr 2022 12:54:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3745F3388F for ; Mon, 18 Apr 2022 09:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650300695; 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: in-reply-to:in-reply-to:references:references; bh=ykPgi6kXIPquInV89bqGLiN6dgrVRp+D+st6086CdO8=; b=X0y4YUfm0vndHUJlWcL5Cr7BQRGjpTZZB3nm+SYlX/ijUQ3flaRgE1ZrNeqLb/OSmoMQfq htI/LcEmbaTADMJ2rmvOe9QP7bgjJtaXZ7M+hroWHexxaOUfzi9cpUlAYY4jXzi5n31i6y zGFIIcmkVLYYOzbCZS5u21wB6yTRBaA= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-157-oNhVGS1ROuOdhHYybUsmVQ-1; Mon, 18 Apr 2022 12:51:31 -0400 X-MC-Unique: oNhVGS1ROuOdhHYybUsmVQ-1 Received: by mail-qk1-f199.google.com with SMTP id m23-20020a05620a221700b006809e1fa4fdso10734008qkh.6 for ; Mon, 18 Apr 2022 09:51:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ykPgi6kXIPquInV89bqGLiN6dgrVRp+D+st6086CdO8=; b=f9S5BocIPikdWGe+oB5nDw+3YuNtczx34ycNm3njBa2PZgUPxtmyctH75TI5Inb3yE xcHdge4AGLDAmYRPDDw05hT7SmUUrT3oB0v6JV7iuDb2XuKsPWrVIzUvioE8UsEvqGRj qVfGHp2EyqeVXuS+uuXjbndXOjJofvTLGFMRzPPllrorpRumSFjI4XuF2Y/7DUbZavRQ U8ClJw6Qrp/6jlJdDSjb3sAsidjFAhEIkP8I9/srUcbHMvizhg+EdIsc9ZJxufJmqb2/ 2wqCW6fd74c/Q84Ekv+WCxXJgcSKjTKEV2LLIrEzqNpsMi3ejqeVb2wbjpOKaqAICE+J 0+2Q== X-Gm-Message-State: AOAM533FDFJ1DCs1VIFo2asZM7xCAu+AC1ZgP1aifDHG42LW3UyZnjlF GUXv/Q0BspXDbfvnMhWtPrcImkHO4OmaxY17M8dPrw2RgK6VDPyV2+EbxkpganL4gma2LT0QjHB bc/asAm3WsPa2A5KGd+gX5VGx X-Received: by 2002:a05:6214:1cc4:b0:431:4cbc:1d91 with SMTP id g4-20020a0562141cc400b004314cbc1d91mr8820738qvd.64.1650300690918; Mon, 18 Apr 2022 09:51:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxM2T3tBY0BTRKAmzHF3vf0/f9tMsFpe9hROzKjkbAKMjMk7Z+CVjQrSDXMgrhlw9P3724zIA== X-Received: by 2002:a05:6214:1cc4:b0:431:4cbc:1d91 with SMTP id g4-20020a0562141cc400b004314cbc1d91mr8820723qvd.64.1650300690652; Mon, 18 Apr 2022 09:51:30 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id e15-20020ac8670f000000b002e22d9c756dsm7277059qtp.30.2022.04.18.09.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 09:51:30 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 25/25] objtool: Update documentation Date: Mon, 18 Apr 2022 09:50:44 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The objtool documentation is very stack validation centric. Broaden the documentation and describe all the features objtool supports. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- .../{stack-validation.txt =3D> objtool.txt} | 122 +++++++++++++++--- 1 file changed, 102 insertions(+), 20 deletions(-) rename tools/objtool/Documentation/{stack-validation.txt =3D> objtool.txt}= (80%) diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objto= ol/Documentation/objtool.txt similarity index 80% rename from tools/objtool/Documentation/stack-validation.txt rename to tools/objtool/Documentation/objtool.txt index 30f38fdc0d56..8a671902a187 100644 --- a/tools/objtool/Documentation/stack-validation.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -1,15 +1,103 @@ -Compile-time stack metadata validation -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Objtool +=3D=3D=3D=3D=3D=3D=3D =20 +The kernel CONFIG_OBJTOOL option enables a host tool named 'objtool' +which runs at compile time. It can do various validations and +transformations on .o files. =20 -Overview +Objtool has become an integral part of the x86-64 kernel toolchain. The +kernel depends on it for a variety of security and performance features +(and other types of features as well). + + +Features -------- =20 -The kernel CONFIG_STACK_VALIDATION option enables a host tool named -objtool which runs at compile time. It has a "check" subcommand which -analyzes every .o file and ensures the validity of its stack metadata. -It enforces a set of rules on asm code and C inline assembly code so -that stack traces can be reliable. +Objtool has the following features: + +- Stack unwinding metadata validation -- useful for helping to ensure + stack traces are reliable for live patching + +- ORC unwinder metadata generation -- a faster and more precise + alternative to frame pointer based unwinding + +- Retpoline validation -- ensures that all indirect calls go through + retpoline thunks, for Spectre v2 mitigations + +- Retpoline call site annotation -- annotates all retpoline thunk call + sites, enabling the kernel to patch them inline, to prevent "thunk + funneling" for both security and performance reasons + +- Non-instrumentation validation -- validates non-instrumentable + ("noinstr") code rules, preventing instrumentation in low-level C + entry code + +- Static call annotation -- annotates static call sites, enabling the + kernel to implement inline static calls, a faster alternative to some + indirect branches + +- Uaccess validation -- validates uaccess rules for a proper + implementation of Supervisor Mode Access Protection (SMAP) + +- Straight Line Speculation validation -- validates certain SLS + mitigations + +- Indirect Branch Tracking validation -- validates Intel CET IBT rules + to ensure that all functions referenced by function pointers have + corresponding ENDBR instructions + +- Indirect Branch Tracking annotation -- annotates unused ENDBR + instruction sites, enabling the kernel to "seal" them (replace them + with NOPs) to further harden IBT + +- Function entry annotation -- annotates function entries, enabling + kernel function tracing + +- Other toolchain hacks which will go unmentioned at this time... + +Each feature can be enabled individually or in combination using the +objtool cmdline. + + +Objects +------- + +Typically, objtool runs on every translation unit (TU, aka ".o file") in +the kernel. If a TU is part of a kernel module, the '--module' option +is added. + +However: + +- If noinstr validation is enabled, it also runs on vmlinux.o, with all + options removed and '--noinstr' added. + +- If IBT or LTO is enabled, it doesn't run on TUs at all. Instead it + runs on vmlinux.o and linked modules, with all options. + +In summary: + + A) Legacy mode: + TU: objtool [--module] + vmlinux: N/A + module: N/A + + B) CONFIG_NOINSTR_VALIDATION=3Dy && !(CONFIG_X86_KERNEL_IBT=3Dy || CONFI= G_LTO=3Dy): + TU: objtool [--module] // no --noinstr + vmlinux: objtool --noinstr // other options removed + module: N/A + + C) CONFIG_X86_KERNEL_IBT=3Dy || CONFIG_LTO=3Dy: + TU: N/A + vmlinux: objtool --noinstr + module: objtool --module --noinstr + + +Stack validation +---------------- + +Objtool's stack validation feature analyzes every .o file and ensures +the validity of its stack metadata. It enforces a set of rules on asm +code and C inline assembly code so that stack traces can be reliable. =20 For each function, it recursively follows all possible code paths and validates the correct frame pointer state at each instruction. @@ -20,14 +108,6 @@ alternative execution paths to a given instruction (or = set of instructions). Similarly, it knows how to follow switch statements, for which gcc sometimes uses jump tables. =20 -(Objtool also has an 'orc generate' subcommand which generates debuginfo -for the ORC unwinder. See Documentation/x86/orc-unwinder.rst in the -kernel tree for more details.) - - -Why do we need stack metadata validation? ------------------------------------------ - Here are some of the benefits of validating stack metadata: =20 a) More reliable stack traces for frame pointer enabled kernels @@ -113,9 +193,6 @@ c) Higher live patching compatibility rate For more details, see the livepatch documentation in the Linux kernel source tree at Documentation/livepatch/livepatch.rst. =20 -Rules ------ - To achieve the validation, objtool enforces the following rules: =20 1. Each callable function must be annotated as such with the ELF @@ -177,7 +254,8 @@ Another possible cause for errors in C code is if the M= akefile removes -fno-omit-frame-pointer or adds -fomit-frame-pointer to the gcc options. =20 Here are some examples of common warnings reported by objtool, what -they mean, and suggestions for how to fix them. +they mean, and suggestions for how to fix them. When in doubt, ping +the objtool maintainers. =20 =20 1. file.o: warning: objtool: func()+0x128: call without frame pointer save= /setup @@ -358,3 +436,7 @@ ignore it: OBJECT_FILES_NON_STANDARD :=3D y =20 to the Makefile. + +NOTE: OBJECT_FILES_NON_STANDARD doesn't work for link time validation of +vmlinux.o or a linked module. So it should only be used for files which +aren't linked into vmlinux or a module. --=20 2.34.1