From patchwork Mon Jun 21 23:18:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12336025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3788CC49EA5 for ; Mon, 21 Jun 2021 23:18:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 223496124B for ; Mon, 21 Jun 2021 23:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231788AbhFUXVL (ORCPT ); Mon, 21 Jun 2021 19:21:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231749AbhFUXVK (ORCPT ); Mon, 21 Jun 2021 19:21:10 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 656A1C06175F for ; Mon, 21 Jun 2021 16:18:55 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id b125-20020a3799830000b02903ad1e638ccaso15782131qke.4 for ; Mon, 21 Jun 2021 16:18:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=2N9bjWxC1f9f54oNFWZySIPRwoyseYMLbsiVnq37oAQ=; b=vXVDzsEzurcdRRJt5TZ/exgrf5jWqqP6v6+f4EHT6jni7xg/fCT7hRB0bEFjBHCf1k UQbAMcvlmxB9n0rZNZRgsRFrTm5BkeLenopg1zaZq07ceL0perNNhOj/iZ+iLGHWfqLu zsEzegqhyP5yfaz9CPRcHT2LgIx1Csa4VDTgmNz+Jz0zPPx9NSZpNljvdkMkIRZfY7CQ a/dsR3+I9XJ8sov7Hy7DJRJLboxLkUritm2R/l5OKTIZt8KtDAuiq7OnqVg9qP3y9Qcm SL5In+wgcNf1Jz8tWXabtpxG7NZQ8MCw/7jxGfNWnTAUOT1ZsYO40ygPnUyILdOS3Xsa RCJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=2N9bjWxC1f9f54oNFWZySIPRwoyseYMLbsiVnq37oAQ=; b=Eh+Y1fmhuTp7OLCl5jf2k2n+O+/DkkEzXSvX2qwoAe1fH+Lk1mr8+joa+sTtS69eH3 bPoLzsRzNsmtwssESsSWHCyGRjylUJh6Hxzk0OqWQmTMBOmHCZ0NhP/H8XJKGQBJ3GX8 vjViVpummkVIO7B5zTBNOOdEZVk9sB9/R8NeiG7ac5JtzPfMqk4H8kiHWGBF527vV9RK 5xvynZUQpU8IEsdHxRmL/uYvDIqpr1HEeBi/QYoOh/oo1nl0u1VmWeAywMgaxTJGPR3e Tqn8PottoTBirLAYYPEEStTzva4tXEx6GCSjacNOXYwStX0Rt+Aw2eQ6Oo85oq8a6EvQ iP3w== X-Gm-Message-State: AOAM532yEvzEhqGoXge/SiDI+I5ZBHIE5BrZMc6WPUHkXX96lKwZNGXZ ZlbB4CJ2Pikf9EQxuC2a7qBkjbd4xrUYGmBbEQg= X-Google-Smtp-Source: ABdhPJwjfIQo78aB8H6zV1xNOpuaeWEgoPd6DNwDkvyEKXQKuITcPpo/8OJYzqUHE7GlfjZiG+d9QDZJyQFf8J65NtU= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:dfd:ebf9:4ec7:1783]) (user=ndesaulniers job=sendgmr) by 2002:a25:3626:: with SMTP id d38mr817378yba.338.1624317534496; Mon, 21 Jun 2021 16:18:54 -0700 (PDT) Date: Mon, 21 Jun 2021 16:18:20 -0700 In-Reply-To: <20210621231822.2848305-1-ndesaulniers@google.com> Message-Id: <20210621231822.2848305-2-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210621231822.2848305-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH v2 1/3] compiler_attributes.h: define __no_profile, add to noinstr From: Nick Desaulniers To: Kees Cook Cc: Peter Zijlstra , Bill Wendling , Sami Tolvanen , Peter Oberparleiter , Masahiro Yamada , Miguel Ojeda , Nathan Chancellor , Luc Van Oostenryck , Ard Biesheuvel , Will Deacon , Arnd Bergmann , Andrew Morton , Rasmus Villemoes , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, x86@kernel.org, Borislav Petkov , Martin Liska , Marco Elver , Jonathan Corbet , Fangrui Song , linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, Dmitry Vyukov , johannes.berg@intel.com, linux-toolchains@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Christian Borntraeger , linux-s390@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Nick Desaulniers , Miguel Ojeda Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org noinstr implies that we would like the compiler to avoid instrumenting a function. Add support for the compiler attribute no_profile_instrument_function to compiler_attributes.h, then add __no_profile to the definition of noinstr. Link: https://lore.kernel.org/lkml/20210614162018.GD68749@worktop.programming.kicks-ass.net/ Link: https://reviews.llvm.org/D104257 Link: https://reviews.llvm.org/D104475 Link: https://reviews.llvm.org/D104658 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80223 Reviewed-by: Fangrui Song Reviewed-by: Miguel Ojeda Suggested-by: Peter Zijlstra Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor --- Changes V1 -> V2: * s/no_profile/no_profile_instrument_function/ * fix trailing double underscore on GCC 4 define, as per Fangrui+Miguel. * Pick up Fangrui + Miguel's reviewed-by tag. * Add link to GCC's doc. * Fix clang's doc format; will appear once clang-13 is released. include/linux/compiler_attributes.h | 13 +++++++++++++ include/linux/compiler_types.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index c043b8d2b17b..225511b17223 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -33,6 +33,7 @@ # define __GCC4_has_attribute___externally_visible__ 1 # define __GCC4_has_attribute___no_caller_saved_registers__ 0 # define __GCC4_has_attribute___noclone__ 1 +# define __GCC4_has_attribute___no_profile_instrument_function__ 0 # define __GCC4_has_attribute___nonstring__ 0 # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) # define __GCC4_has_attribute___no_sanitize_undefined__ (__GNUC_MINOR__ >= 9) @@ -237,6 +238,18 @@ # define __nonstring #endif +/* + * Optional: only supported since GCC >= 7.1, clang >= 13.0. + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function + */ +#if __has_attribute(__no_profile_instrument_function__) +# define __no_profile __attribute__((__no_profile_instrument_function__)) +#else +# define __no_profile +#endif + /* * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute * clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index d29bda7f6ebd..d509169860f1 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -210,7 +210,7 @@ struct ftrace_likely_data { /* Section for code which can't be instrumented at all */ #define noinstr \ noinline notrace __attribute((__section__(".noinstr.text"))) \ - __no_kcsan __no_sanitize_address + __no_kcsan __no_sanitize_address __no_profile #endif /* __KERNEL__ */ From patchwork Mon Jun 21 23:18:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12336027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD627C48BC2 for ; Mon, 21 Jun 2021 23:19:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7AD26023D for ; Mon, 21 Jun 2021 23:19:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231907AbhFUXVP (ORCPT ); Mon, 21 Jun 2021 19:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231817AbhFUXVM (ORCPT ); Mon, 21 Jun 2021 19:21:12 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5177C061768 for ; Mon, 21 Jun 2021 16:18:57 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id o14-20020a05620a0d4eb02903a5eee61155so13552684qkl.9 for ; Mon, 21 Jun 2021 16:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=rjB5gl/OyQ1mYdw8idF1qN2FUIQyyWYhNBNVDiw+uvU=; b=Fx/5r3tL8gCFAJtd4rl2DAmVtq/Hcag/FqOXfbZTiumpQvK7IpCiwSoO4s2r3Pg4kG DjgqzwZbw38zdRoLWEIFqajlU0HyzgooEI43aq0nXoB3xcXQkKM3CW4mob90gDiP9WK2 hHrDsQKAVpOhYF9U5V1S3QpzKlSx5rhNkESwPwwewApEl53L6IrVLx7uL19uIuHFuiOo 6lolqnl8of8SHB6qJI16xb6wkcrAAnCL9U5ewHgz0C+f0vibak7dCVxmIJY/mPLRKbjo OXIV6b2Ew6sgl0PP+wDqL797jk1u3lvn2QWTbcBZRMFj+LYkj51nlwS6pHOjBj5NB8Kb CkNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=rjB5gl/OyQ1mYdw8idF1qN2FUIQyyWYhNBNVDiw+uvU=; b=KQOAHujH0InTr7+CBcHrtPEuJOoKW63JKsOmDeIMowl5zxqnXEExcoE2Ja349QCBLp 1ioOspddfjGbI0XYJ5vtC8Ik2aHzhLFYeNLlKld40Wb6rhKpsYHZ5wGw2ZHOV24GYcne 8JUvL9Fpma0PSKMLC1PYBUy/bNp8H3NnQ7t597J6BYelxymsDBHC2xHpbgmX+BbQ8Xuw Y19R0cDv9s2D7TEN7bDBiXKCEYs18RLQYCtmqBtluOiprbFhvFwEExwwwM9FVSJe9Kzp 4F8AGR8y8SIaeepXxzPewZR0P4IRSnwC612R+aDBHOTX/+n5bFvz4tlpoq1YFblB7nqs 0z/Q== X-Gm-Message-State: AOAM530le/PVEJSZRwd+E2O0ySKDYbHUqI4J7dHYb+UXmdNazy8bKWHk 1x2n9HCfrtXo1Qfd077t2gT22rvIz6p8UZcuAw4= X-Google-Smtp-Source: ABdhPJyXTOipiZC/T1Rh2LGkpucm8jFtJ6//dT3xhNEPf1PixdbviPLfrtW8WqYG2ren4BZlrLSA6JcmNbcRdaRhqhk= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:dfd:ebf9:4ec7:1783]) (user=ndesaulniers job=sendgmr) by 2002:a25:aea4:: with SMTP id b36mr794382ybj.428.1624317536807; Mon, 21 Jun 2021 16:18:56 -0700 (PDT) Date: Mon, 21 Jun 2021 16:18:21 -0700 In-Reply-To: <20210621231822.2848305-1-ndesaulniers@google.com> Message-Id: <20210621231822.2848305-3-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210621231822.2848305-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH v2 2/3] compiler_attributes.h: cleanups for GCC 4.9+ From: Nick Desaulniers To: Kees Cook Cc: Peter Zijlstra , Bill Wendling , Sami Tolvanen , Peter Oberparleiter , Masahiro Yamada , Miguel Ojeda , Nathan Chancellor , Luc Van Oostenryck , Ard Biesheuvel , Will Deacon , Arnd Bergmann , Andrew Morton , Rasmus Villemoes , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, x86@kernel.org, Borislav Petkov , Martin Liska , Marco Elver , Jonathan Corbet , Fangrui Song , linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, Dmitry Vyukov , johannes.berg@intel.com, linux-toolchains@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Christian Borntraeger , linux-s390@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Nick Desaulniers , Miguel Ojeda Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Since commit 6ec4476ac825 ("Raise gcc version requirement to 4.9") we no longer support building the kernel with GCC 4.8; drop the preprocess checks for __GNUC_MINOR__ version. It's implied that if __GNUC_MAJOR__ is 4, then the only supported version of __GNUC_MINOR__ left is 9. Cc: Miguel Ojeda Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor --- include/linux/compiler_attributes.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index 225511b17223..84b1c970acb3 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -27,7 +27,7 @@ */ #ifndef __has_attribute # define __has_attribute(x) __GCC4_has_attribute_##x -# define __GCC4_has_attribute___assume_aligned__ (__GNUC_MINOR__ >= 9) +# define __GCC4_has_attribute___assume_aligned__ 1 # define __GCC4_has_attribute___copy__ 0 # define __GCC4_has_attribute___designated_init__ 0 # define __GCC4_has_attribute___externally_visible__ 1 @@ -35,8 +35,8 @@ # define __GCC4_has_attribute___noclone__ 1 # define __GCC4_has_attribute___no_profile_instrument_function__ 0 # define __GCC4_has_attribute___nonstring__ 0 -# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) -# define __GCC4_has_attribute___no_sanitize_undefined__ (__GNUC_MINOR__ >= 9) +# define __GCC4_has_attribute___no_sanitize_address__ 1 +# define __GCC4_has_attribute___no_sanitize_undefined__ 1 # define __GCC4_has_attribute___fallthrough__ 0 #endif From patchwork Mon Jun 21 23:18:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12336029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E9DDC49EA5 for ; Mon, 21 Jun 2021 23:19:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CB456128E for ; Mon, 21 Jun 2021 23:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232002AbhFUXVW (ORCPT ); Mon, 21 Jun 2021 19:21:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFUXVP (ORCPT ); Mon, 21 Jun 2021 19:21:15 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46E53C061760 for ; Mon, 21 Jun 2021 16:19:00 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id q20-20020a0cf5d40000b029027498137223so3731702qvm.15 for ; Mon, 21 Jun 2021 16:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=3H4F55NU/a97Frzuudhi6AfsU/8NQIqR0g56h0PgrJ4=; b=IlT5iHwHkCwvh6uYn+ad+nphzhTgSLGZUawwr+EN3103ID7mRMyLhAB2k37ebexrlg mZ6YADGfLg3RWnh/8J6dPSafdaIxhryorYpO4WZ65kLsEOtEQOTo678Ff0mBKBa92+lm UiPRARdH5oFaJblXeFxxmVtQ8fQLTpbZThalbfLdFxHLa8bgssAoRmkm6lrDVy82h7Rq WKj7ZghR225g7nXWC/K2/Ieyhmp5V3kW22O20xS3cdvW+rgCPxLd1sdehk30r0CHfs/Q cJQhZT8xOpRClWiQW98bNQtt2q3tWBvLd4NJIGEgbUUlNgcdPP7Jmw4+/8Dn+KLVCdPZ J0PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3H4F55NU/a97Frzuudhi6AfsU/8NQIqR0g56h0PgrJ4=; b=EpnOdaUIC32V8zfG9kI/NCFV1EFgbuUHG4uTxG8zU+XrfC4s9ekDfIyIzj+FQibdsT /4wvlVsuKjp5bF3RZ+FFbjmv0J2wAAVQp9GaBkKvRENIbT6S57AQ6KsYCF7F6KUfqhrG gUnThsbV+SCGuGIL+JVshnZ4TwX4n8VOiAe/tKDQjLhBdUdzpmD07tFl56bFyWwoyHB8 NGaLmHtecvZvTJ94LbB6TpufN8x5/qFBSjSGlX7WB4ecjVxKc4/lwaaFYASDWX/PvW18 l91PT0qb4o+ejX8bFKnvm1y1PHpv+EJ8z6+HtIbV1xBh10S/XxWNEZG+JpgzUnSkgQdH 4Grw== X-Gm-Message-State: AOAM532JFAtG5OpxH5mkdmGYG445BPj+fEM21W1RrKTvvw3Iu2JcdjUU GSPhbCj//hFjPIZ8OtoGY1CMyGozymBLshh+Qns= X-Google-Smtp-Source: ABdhPJy/ygCGleZhe+Yae0QNHj25BZbuCifVF1OqrOy3nkTDPiBTaZQUK7dvOsZGIrxFq3N+wJdOoVd1nH+tCsLaVVU= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:dfd:ebf9:4ec7:1783]) (user=ndesaulniers job=sendgmr) by 2002:a25:7a84:: with SMTP id v126mr752893ybc.153.1624317539374; Mon, 21 Jun 2021 16:18:59 -0700 (PDT) Date: Mon, 21 Jun 2021 16:18:22 -0700 In-Reply-To: <20210621231822.2848305-1-ndesaulniers@google.com> Message-Id: <20210621231822.2848305-4-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210621231822.2848305-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH v2 3/3] Kconfig: add ARCH_WANTS_NO_INSTR+CC_HAS_NO_PROFILE_FN_ATTR, depend on for GCOV and PGO From: Nick Desaulniers To: Kees Cook Cc: Peter Zijlstra , Bill Wendling , Sami Tolvanen , Peter Oberparleiter , Masahiro Yamada , Miguel Ojeda , Nathan Chancellor , Luc Van Oostenryck , Ard Biesheuvel , Will Deacon , Arnd Bergmann , Andrew Morton , Rasmus Villemoes , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, x86@kernel.org, Borislav Petkov , Martin Liska , Marco Elver , Jonathan Corbet , Fangrui Song , linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, Dmitry Vyukov , johannes.berg@intel.com, linux-toolchains@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Christian Borntraeger , linux-s390@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Nick Desaulniers Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We don't want compiler instrumentation to touch noinstr functions, which are annotated with the no_profile_instrument_function function attribute. Add a Kconfig test for this and make PGO and GCOV depend on it. If an architecture is using noinstr, it should denote that via this Kconfig value. That makes Kconfigs that depend on noinstr able to express dependencies in an architecturally agnostic way. Cc: Masahiro Yamada Cc: Peter Oberparleiter Link: https://lore.kernel.org/lkml/YMTn9yjuemKFLbws@hirez.programming.kicks-ass.net/ Link: https://lore.kernel.org/lkml/YMcssV%2Fn5IBGv4f0@hirez.programming.kicks-ass.net/ Suggested-by: Nathan Chancellor Suggested-by: Peter Zijlstra Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Acked-by: Mark Rutland Acked-by: Heiko Carstens Reviewed-by: Peter Oberparleiter --- Changes V1 -> V2: * Add ARCH_WANTS_NO_INSTR * Change depdendencies to be !ARCH_WANTS_NO_INSTR || CC_HAS_NO_PROFILE_FN_ATTR rather than list architectures explicitly, as per Nathan. * s/no_profile/no_profile_instrument_function/ arch/Kconfig | 7 +++++++ arch/arm64/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/x86/Kconfig | 1 + init/Kconfig | 3 +++ kernel/gcov/Kconfig | 1 + kernel/pgo/Kconfig | 3 ++- 7 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index 2b4109b0edee..2113c6b3b801 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -285,6 +285,13 @@ config ARCH_THREAD_STACK_ALLOCATOR config ARCH_WANTS_DYNAMIC_TASK_STRUCT bool +config ARCH_WANTS_NO_INSTR + bool + help + An architecure should select this if the noinstr macro is being used on + functions to denote that the toolchain should avoid instrumenting such + functions and is required for correctness. + config ARCH_32BIT_OFF_T bool depends on !64BIT diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9f1d8566bbf9..39bf982b06f8 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -93,6 +93,7 @@ config ARM64 select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANTS_NO_INSTR select ARCH_HAS_UBSAN_SANITIZE_ALL select ARM_AMBA select ARM_ARCH_TIMER diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index b4c7c34069f8..bd60310f33b9 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -117,6 +117,7 @@ config S390 select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF select ARCH_WANTS_DYNAMIC_TASK_STRUCT + select ARCH_WANTS_NO_INSTR select ARCH_WANT_DEFAULT_BPF_JIT select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_TABLE_SORT diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index da43fd046149..7d6a44bb9b0e 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -114,6 +114,7 @@ config X86 select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH select ARCH_WANT_DEFAULT_BPF_JIT if X86_64 select ARCH_WANTS_DYNAMIC_TASK_STRUCT + select ARCH_WANTS_NO_INSTR select ARCH_WANT_HUGE_PMD_SHARE select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANTS_THP_SWAP if X86_64 diff --git a/init/Kconfig b/init/Kconfig index 1ea12c64e4c9..31397a7a45fb 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -83,6 +83,9 @@ config TOOLS_SUPPORT_RELR config CC_HAS_ASM_INLINE def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null) +config CC_HAS_NO_PROFILE_FN_ATTR + def_bool $(success,echo '__attribute__((no_profile_instrument_function)) int x();' | $(CC) -x c - -c -o /dev/null -Werror) + config CONSTRUCTORS bool diff --git a/kernel/gcov/Kconfig b/kernel/gcov/Kconfig index 58f87a3092f3..053447183ac5 100644 --- a/kernel/gcov/Kconfig +++ b/kernel/gcov/Kconfig @@ -5,6 +5,7 @@ config GCOV_KERNEL bool "Enable gcov-based kernel profiling" depends on DEBUG_FS depends on !CC_IS_CLANG || CLANG_VERSION >= 110000 + depends on !ARCH_WANTS_NO_INSTR || CC_HAS_NO_PROFILE_FN_ATTR select CONSTRUCTORS default n help diff --git a/kernel/pgo/Kconfig b/kernel/pgo/Kconfig index d2053df1111c..ce7fe04f303d 100644 --- a/kernel/pgo/Kconfig +++ b/kernel/pgo/Kconfig @@ -8,7 +8,8 @@ config PGO_CLANG bool "Enable clang's PGO-based kernel profiling" depends on DEBUG_FS depends on ARCH_SUPPORTS_PGO_CLANG - depends on CC_IS_CLANG && CLANG_VERSION >= 120000 + depends on CC_IS_CLANG + depends on !ARCH_WANTS_NO_INSTR || CC_HAS_NO_PROFILE_FN_ATTR help This option enables clang's PGO (Profile Guided Optimization) based code profiling to better optimize the kernel.