Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4215080pxj; Mon, 21 Jun 2021 16:45:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsfpaL/T9egDeNMgKT8Fv+NC7GdJ4jkHDdbF7BKSPdAGLwI+tRgMc+N69qRAPPWJNoDWFy X-Received: by 2002:a17:906:b141:: with SMTP id bt1mr672179ejb.498.1624319113963; Mon, 21 Jun 2021 16:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624319113; cv=none; d=google.com; s=arc-20160816; b=V7n4R3+kiXU+wxztV9ES7XRsy9xpJw9kgHLNbBs1g8w2uUk6UZDjvluIQyA12C6L35 +w0L7Vkzr5XTNkBvkFuqUXLrk3D3HOzGNs6yDE4uDfw8kU6kUAFUayBXNrAZI7wvsuDB Lo0cYZKQXGHVmEBPho+MmySveKPZKRW9bIhX2UvnSMtRJjg+XEz2F9rVhzYmsR32xypQ xx71uPGA+LPkQHPUKLE5TS11Yq5xIwD2I3c5KRWY30noc99OMILf5dvDLi+1UvyL0cBd CL1PkxVs9yOyBYDTY55Pvnd4IB4Xm0li1TJXAoOeEF9RS6PpuNkcpx44/ZWfVZfTJdUN NwIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=dPwQR5dyH4TwAmp7OvM5meMMdRFLbpwECWIHk5er6vM=; b=sLIA+I57djGIiqeT4GRReHEyc/D09134OOhJ6AYyteIsC500rOvwhOKewPZuVvB+te EGMamhIMCRF1mMyz0x5LCC5znzG6GTTPTISDvF/eInptmRCq96bKs6xv5gKwlqZLJQr6 LGJ43U1rnUA2H145k0ZDpC9TMKS7V1pvrq8Om75xOuMMMlTs+XXryu4M5q+348ahNfJZ 1yIX30ric6ecizMzFuIvOPjou4rKbpBgdM9ftrpSPzlHUvgZKg6qHL41n9p+T8dgWbZX GxCDMXIo3Q5sB0go/1llNqyjwvOzYK/y1KDynygCqe4QKxWKVH5S4jw+AnjiVu8zkP9z faKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aCin44Ts; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v9si11951675ejh.703.2021.06.21.16.44.49; Mon, 21 Jun 2021 16:45:13 -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=@kernel.org header.s=k20201202 header.b=aCin44Ts; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232014AbhFUXnz (ORCPT + 99 others); Mon, 21 Jun 2021 19:43:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:39542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231486AbhFUXnz (ORCPT ); Mon, 21 Jun 2021 19:43:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3D72A611BD; Mon, 21 Jun 2021 23:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624318900; bh=Hjg6nyt/cyl6h5T5XaGtOqKiPNLoKh3rJA7tP4MqZ9w=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=aCin44TsfCj0ZM9GJ2p+p2ho7J4cgUB0AXPwdCaviFwUaAxksUgWB9nLo1t2+AUSv s+xZ8QzmPSlpYD8pe/640JZ0jAQx2v6SfM4ODzadsH+/oIkYBMteNr7srMAcA5G9qx +HwegxokVeKexqN4SdgAuvnFaof/gD8yIpMq2Y2Jm9mujDNzlVSWDSG2bukB2B1g+W N2TQtpLFKyPOwCS/RuLZ0h4wYho9edV77tNgAo+4GmJjz4uLcDdM3yppRb1ciqequ7 ezchoDrHbj3+xF/XET3SO5Q10ZrsBZsKv64CZbMH5xuWqzTlNNjxWv2ANprsI/p35m eHtD02xOLM7yg== Subject: Re: [PATCH v2 1/3] compiler_attributes.h: define __no_profile, add to noinstr To: Nick Desaulniers , Kees Cook Cc: Peter Zijlstra , Bill Wendling , Sami Tolvanen , Peter Oberparleiter , Masahiro Yamada , Miguel Ojeda , 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 , Miguel Ojeda References: <20210621231822.2848305-1-ndesaulniers@google.com> <20210621231822.2848305-2-ndesaulniers@google.com> From: Nathan Chancellor Message-ID: <6ca2bf5a-f0c3-b972-2313-f09c39b67e3b@kernel.org> Date: Mon, 21 Jun 2021 16:41:37 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210621231822.2848305-2-ndesaulniers@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/21/2021 4:18 PM, 'Nick Desaulniers' via Clang Built Linux wrote: > 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__ */ > >