Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp98245rwb; Fri, 4 Aug 2023 09:41:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhW/xP5Jb9ZWksetEUU9AjgJBO58Sr2KgIRqfavnpHKS85WniivPsg2WrMFDucdqjCuxqg X-Received: by 2002:a17:902:ec89:b0:1b8:ae12:5610 with SMTP id x9-20020a170902ec8900b001b8ae125610mr2555427plg.7.1691167292681; Fri, 04 Aug 2023 09:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691167292; cv=none; d=google.com; s=arc-20160816; b=WKDhPKZ/0GHMjKxlRj3xc2BVAjSnhpGI+sLdiTjRsngRvGSSPI4SAJR6G73ez4LC7U x3Fsz41loU4pijDkhUAYPxhsiYPDBpXq9dtNoyg3L1HX+EZh10IMStIBE4HMbN/BqdJY L+blPSe0CLtxJ1vgyDiZEqrwGzjt+WUDHFRNK+JuCAGi5Gf5xZ2AVs7iQ8tyjjUNLnsJ Y/7U+Veg9rQVmHHp6yszBqBK09zky9gCHZVWhGg4PGPjBPMsbCUNL29rFLbdXutF2DuQ vx2GLSMeSl80FOK53CDp9OYbj6zw/3vJKbzmzNc3PznFdCHN+yJ1vdPY0L1mEF/c74D3 WAyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=9vhh06R6lQIg/0ACblWsO4Ty8GCvSAXOlNX/NLoKEkM=; fh=zgl4QvCHzZtm0UFkLogCWyFVI2V0Qr2FpX92dqmx0hM=; b=zA31Cy2rtzuSa3G6U8DEnsHSX/r0O2AGnSMkAvedz926xnb5FjIraNbfN4D0KjsGcl LrlPGMeyf7jRmINxWh35y55ROAC8OqwpBGOxLptCiPIzJMgrM5Lr+jim1qjP4HePMzz5 OOGlvhitd8bQN9pnV0Eo+DbN3RjZdA/iQ2FcAgnwvcsqJM9EkA1QGmZJUjy8ImEsnC5v xnXXaKrrue2AxXktCAbTl7454E3MDAnsBg4gFgcH5TO4mzdGlWQfe/2EpFIHPxf/CUhj Z64RGDsHfKT39LtbrXwAg9f6x2UFR5pQrndAp4MexJOkvSQopyaYWdjNbQeOxqz+YlEc w8KA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij23-20020a170902ab5700b001b9d2010b27si287156plb.119.2023.08.04.09.40.54; Fri, 04 Aug 2023 09:41:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229904AbjHDP6v (ORCPT + 99 others); Fri, 4 Aug 2023 11:58:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbjHDP6u (ORCPT ); Fri, 4 Aug 2023 11:58:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3C952D71; Fri, 4 Aug 2023 08:58:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5771D62077; Fri, 4 Aug 2023 15:58:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 275F2C433C7; Fri, 4 Aug 2023 15:58:45 +0000 (UTC) Date: Fri, 4 Aug 2023 11:58:43 -0400 From: Steven Rostedt To: Marco Elver Cc: Andrew Morton , Kees Cook , Guenter Roeck , Peter Zijlstra , Mark Rutland , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Nathan Chancellor , Nick Desaulniers , Tom Rix , Miguel Ojeda , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Dmitry Vyukov , Alexander Potapenko , kasan-dev@googlegroups.com, linux-toolchains@vger.kernel.org Subject: Re: [PATCH v2 1/3] compiler_types: Introduce the Clang __preserve_most function attribute Message-ID: <20230804115843.5be5f2b2@gandalf.local.home> In-Reply-To: <20230804090621.400-1-elver@google.com> References: <20230804090621.400-1-elver@google.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 4 Aug 2023 11:02:56 +0200 Marco Elver wrote: > [1]: "On X86-64 and AArch64 targets, this attribute changes the calling > convention of a function. The preserve_most calling convention attempts > to make the code in the caller as unintrusive as possible. This > convention behaves identically to the C calling convention on how > arguments and return values are passed, but it uses a different set of > caller/callee-saved registers. This alleviates the burden of saving and > recovering a large register set before and after the call in the > caller." > > [1] https://clang.llvm.org/docs/AttributeReference.html#preserve-most > > Introduce the attribute to compiler_types.h as __preserve_most. > > Use of this attribute results in better code generation for calls to > very rarely called functions, such as error-reporting functions, or > rarely executed slow paths. > > Beware that the attribute conflicts with instrumentation calls inserted > on function entry which do not use __preserve_most themselves. Notably, > function tracing which assumes the normal C calling convention for the > given architecture. Where the attribute is supported, __preserve_most > will imply notrace. It is recommended to restrict use of the attribute > to functions that should or already disable tracing. > > Signed-off-by: Marco Elver > --- > v2: > * Imply notrace, to avoid any conflicts with tracing which is inserted > on function entry. See added comments. Acked-by: Steven Rostedt (Google) -- Steve > --- > include/linux/compiler_types.h | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h > index 547ea1ff806e..12c4540335b7 100644 > --- a/include/linux/compiler_types.h > +++ b/include/linux/compiler_types.h > @@ -106,6 +106,33 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } > #define __cold > #endif > > +/* > + * On x86-64 and arm64 targets, __preserve_most changes the calling convention > + * of a function to make the code in the caller as unintrusive as possible. This > + * convention behaves identically to the C calling convention on how arguments > + * and return values are passed, but uses a different set of caller- and callee- > + * saved registers. > + * > + * The purpose is to alleviates the burden of saving and recovering a large > + * register set before and after the call in the caller. This is beneficial for > + * rarely taken slow paths, such as error-reporting functions that may be called > + * from hot paths. > + * > + * Note: This may conflict with instrumentation inserted on function entry which > + * does not use __preserve_most or equivalent convention (if in assembly). Since > + * function tracing assumes the normal C calling convention, where the attribute > + * is supported, __preserve_most implies notrace. > + * > + * Optional: not supported by gcc. > + * > + * clang: https://clang.llvm.org/docs/AttributeReference.html#preserve-most > + */ > +#if __has_attribute(__preserve_most__) > +# define __preserve_most notrace __attribute__((__preserve_most__)) > +#else > +# define __preserve_most > +#endif > + > /* Builtins */ > > /*