Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4201288pxj; Mon, 21 Jun 2021 16:20:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvF/LY2aTA/De7gpsEKo3v6F97mwTkKVxvCsqnaRbrNMFONZXw43K8jeJmGQuGnRAjHNXo X-Received: by 2002:a92:690d:: with SMTP id e13mr470044ilc.257.1624317615487; Mon, 21 Jun 2021 16:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624317615; cv=none; d=google.com; s=arc-20160816; b=LDThE1AynlHscwQdoWHzqU0IPxJsCA5QdhXxV7yeJOQIQvrkk8hSRbHnb6DnVN5BF7 HmFjfg89vmtCHl4UPvFsx57LxrYyf79RVGNcpWF9nLuv/PTzS8UhhyWsYtIHew3inkqM HA7vICQBOC4L1aYSxyvodyXqLHSpNY2TPuypxbHDNIfamYV+SawKJg7x06on7+QbOt2x R1M4oLAjJFW59r8OtkV3kqePp5UbW1D7xv2FW9PYqK6AMPQf30UTGcf6Fi9PP98AInj8 llcASlw82n7guMFPCJYopEYicJlKUuNQqJ1VuL48MWwGk4Ns2Mm2O9VLBYG6nfPYHgco FrgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=2N9bjWxC1f9f54oNFWZySIPRwoyseYMLbsiVnq37oAQ=; b=tQmPMYnCDIDZn5d7SZ+pSJneomN5lnQgFuH+F57p5UBkQr3sc1UJxrz3fz+Kcwb7UR z/9y/pxdzkKUT1/7Z4BOq1+vqCSB5GF4AoREXAcffvBDO01uHA3cWyf2gZo0JKqHxmSD ynRqTeXzEDEo9ESCdVAe9M5odOgsr4D3awfiEI9sryuctBlrTikTvMSv/KrhdoYNDCT3 hQ0PLgMsUwkHYg/8m/kX2QiY6BgWpfUb8wwJpfW4wI1ZPZcOeOTI2/ZMGgfVpX4M8PYZ nti6qOMWVNs9gWwDlOU7CgajY08a4qpJs+bSDmSEvIgBOZhS2kNpx6ku4jIR0ALiqb4U TeJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vXVDzsEz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d187si3011392iog.56.2021.06.21.16.20.03; Mon, 21 Jun 2021 16:20:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vXVDzsEz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231790AbhFUXVM (ORCPT + 99 others); Mon, 21 Jun 2021 19:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbhFUXVK (ORCPT ); Mon, 21 Jun 2021 19:21:10 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63731C061574 for ; Mon, 21 Jun 2021 16:18:55 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id e13-20020a37e50d0000b02903ad5730c883so3244919qkg.22 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=XVBzsvxmqo2lniQ6nw7RYJ1Y2CGVWxNwO5/C8sxyH0ngnI6IvoVBc2RbUTztESA8sN OeM4RsVFzp9Wda714Sp2KoYS+GxV/I18+NdyCAbIzWWOrUC/dMK+2qL0AeXv9TsA9bVE vYizviVcWeJNmwciJWdwUwNE38jRY28afK8pgrL0uF1bCiSul56n6xlnpuFWt2fr+7Gq 1/pUyG6kuckZm9s3Ocjv0hurjsYxhN/226YWOmNvNULKhw5yC5HbqYwNb4IoGKbNjUmY QjUAFELfyETy6Kvjm8J4pqlACEamkvCqc4ev0KlMlGB0xxI5w2Z6M/nNcX5izztNATtx Wmew== X-Gm-Message-State: AOAM533llMtWgKkr8EGZ9IFR9WSMro6dmfnoiOdC7WzpJ079Ne/hHNps TRyyXPDApIrr03xLPF9trGOYe/AkRlbslJ0wLno= 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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__ */ -- 2.32.0.288.g62a8d224e6-goog