From mboxrd@z Thu Jan 1 00:00:00 1970 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 9AC28C41513 for ; Mon, 14 Aug 2023 23:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233454AbjHNXWN (ORCPT ); Mon, 14 Aug 2023 19:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233460AbjHNXVq (ORCPT ); Mon, 14 Aug 2023 19:21:46 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A49C1710 for ; Mon, 14 Aug 2023 16:21:45 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bdb801c667so29152265ad.1 for ; Mon, 14 Aug 2023 16:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692055304; x=1692660104; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zDgteNssk7bldWg1S9G58zrFCCsMMUu+wXIpurB+HOk=; b=f0Ak5IcltrDFdkQCDY8pIN2Q+ApDStplykSnlDyPTlJ5hOzrqc9PWJCJjuzY2a8RJ+ g8xVrAL3nMB+kfcdXe60p9qKEe3GlaSBVzwWcARsfm76j54TnQAq99JEPb1dmu6zAVNx W/EJPZgrIcJBBWdgJxFVqDLwjpYw5EdzIukns= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692055304; x=1692660104; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zDgteNssk7bldWg1S9G58zrFCCsMMUu+wXIpurB+HOk=; b=ZAc+rbIsxeo5i+KJYhMi9BT1RXJPwBfHoVBU9NR3cyAKu2gTUBAt7Q7VmJFj9mpCZk vniVunCFWf5QiwMiNP45igFoKZtgfOkyS6+QxMnN2AoBUHgh1n9XKxsw9EljRfYhF+6n DjoXCjoRtIHtwsMVjMbeUJFtAT2l/0VCXxs0D+edwKbijWu/OHggY58OKkka1vg3pPe+ XMZZxVCOqlkk8prmINnYmesAHHT60WSBHvBXg+UKNQdqPXeySpVUniMR8OAaD7BcbPFQ Z/yRxlWVQO1lH6E00k+89ah2L9myT0WQqlWFbEexsiC4YBBWLATQWPKBkC+kfVs9Bpux Irew== X-Gm-Message-State: AOJu0YxMzAVxu7jT+bpKOTjqYG9UO16pn9a7Da+kiRSvlQ2/cOpyZrnC WVgaRagsKZEEE59WLv9AdYHNcQ== X-Google-Smtp-Source: AGHT+IHSGL8C59m4WskNFhunf6W+tABRL2W8v1BYu6fmf1+j7vX3+mrOp1twYX7SxuE7dHDeO2B60Q== X-Received: by 2002:a17:902:e802:b0:1bc:422a:b9fd with SMTP id u2-20020a170902e80200b001bc422ab9fdmr13245083plg.13.1692055304507; Mon, 14 Aug 2023 16:21:44 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id c13-20020a170902d48d00b001bdcd4b1616sm5310621plg.260.2023.08.14.16.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 16:21:43 -0700 (PDT) Date: Mon, 14 Aug 2023 16:21:43 -0700 From: Kees Cook To: Marco Elver Cc: Andrew Morton , Guenter Roeck , Peter Zijlstra , Mark Rutland , Steven Rostedt , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Arnd Bergmann , Greg Kroah-Hartman , Paul Moore , James Morris , "Serge E. Hallyn" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Miguel Ojeda , Sami Tolvanen , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, llvm@lists.linux.dev, Dmitry Vyukov , Alexander Potapenko , kasan-dev@googlegroups.com, linux-toolchains@vger.kernel.org Subject: Re: [PATCH v4 1/4] compiler_types: Introduce the Clang __preserve_most function attribute Message-ID: <202308141620.E16B93279@keescook> References: <20230811151847.1594958-1-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230811151847.1594958-1-elver@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Fri, Aug 11, 2023 at 05:18:38PM +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. > If the arguments are passed in callee-saved registers, then they will be > preserved by the callee across the call. This doesn't apply for values > returned in callee-saved registers. > > * On X86-64 the callee preserves all general purpose registers, except > for R11. R11 can be used as a scratch register. Floating-point > registers (XMMs/YMMs) are not preserved and need to be saved by the > caller. > > * On AArch64 the callee preserve all general purpose registers, except > x0-X8 and X16-X18." > > [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. > > Note: The additional preprocessor check against architecture should not > be necessary if __has_attribute() only returns true where supported; > also see https://github.com/ClangBuiltLinux/linux/issues/1908. But until > __has_attribute() does the right thing, we also guard by known-supported > architectures to avoid build warnings on other architectures. > > The attribute may be supported by a future GCC version (see > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110899). > > Signed-off-by: Marco Elver > Reviewed-by: Miguel Ojeda > Reviewed-by: Nick Desaulniers > Acked-by: Steven Rostedt (Google) > Acked-by: Mark Rutland Should this go via -mm, the hardening tree, or something else? I'm happy to carry it if no one else wants it? -Kees -- Kees Cook