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 A3971C001E0 for ; Tue, 15 Aug 2023 18:23:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239018AbjHOSW7 (ORCPT ); Tue, 15 Aug 2023 14:22:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239053AbjHOSWj (ORCPT ); Tue, 15 Aug 2023 14:22:39 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA03B1BC3 for ; Tue, 15 Aug 2023 11:22:37 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fe1a17f983so51721245e9.3 for ; Tue, 15 Aug 2023 11:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692123756; x=1692728556; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rRFUf4dNqMSfHq2+lBU85kOOjIYPLnDmd2dSara3YQ0=; b=B5+dfis4GodiyMswujpdft5yTaiXEq+hCwoLLuJZRiCvztSGpvOULmk8iJEZg0adZH BY8An2LpsxdQEREmqow3gZhdUpFsyxA5U4miqfRxIUa2E7orC7Q7Ko0rzGuYQoBGy3qE uJuL2aJukQjiTszT6TACOaiShD5ikUEvhecLDrbpWvp0vfZwKh8yvRzW81AuKihenO+k gAvQFt9BBsbYBPBrxoO18Y0Bx8A9NLjX4Dppy7CnQFNiNPm0XWjqjxeGhTirjoSgNZrN VA5L9DiSGMhLlpHCXIi62EV9vWnA4wHPi/7SHM9HSJEE9w35I7MEUBr2S7/c/OBIEDC9 TeBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692123756; x=1692728556; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rRFUf4dNqMSfHq2+lBU85kOOjIYPLnDmd2dSara3YQ0=; b=BnwB3T2PPAxDGGUXK3BeCFqMRfG+Cik6udi3nyHEHY7thxGr7lD2uX2RboxuxYwkVT CYje1eV1t7Be51dCdCWmqlVBi8UMZvBpnHqrzTZvmWomF5e4idLrKfgb7nTptv5OnhRv +fmijbwadXvjNFd2hOuIaSSl+lYizKtH6zoXPSXUp4JoEfte8XM+m9FFLbTkkYWonxcr AGGN8NQY38vchgaxwUkC8lr9PV98Y5rA9UB1knHVzAj1He0HARVcdBKGGPoIEcA53ug+ oYFNIExK7HShBKoZwe+oO361rz7xI1BMZSrC3LTFov1dR4gGQ2QWu7+sbMSYb5ldseb3 JPpA== X-Gm-Message-State: AOJu0YxX88D/rg+v3XeizLFFPUIFa3XRxWbSynnBS5C+yrFsFqzIExjI I1t72Mgg9wCAmp/HF3ZK4hdiYVSeUuAu+oiCWcWEBg== X-Google-Smtp-Source: AGHT+IGIPWace5mdmcxiYsdjUOHTOAtdVTz9UvfQVQP31URfweI7ITp2r94AA2XEk86pkT7L3VWHyy8DVHcpStWzCas= X-Received: by 2002:a7b:cd99:0:b0:3fe:14af:ea21 with SMTP id y25-20020a7bcd99000000b003fe14afea21mr10108651wmj.21.1692123756120; Tue, 15 Aug 2023 11:22:36 -0700 (PDT) MIME-Version: 1.0 References: <20230811151847.1594958-1-elver@google.com> <202308141620.E16B93279@keescook> In-Reply-To: <202308141620.E16B93279@keescook> From: Marco Elver Date: Tue, 15 Aug 2023 20:21:59 +0200 Message-ID: Subject: Re: [PATCH v4 1/4] compiler_types: Introduce the Clang __preserve_most function attribute To: Kees Cook 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Tue, 15 Aug 2023 at 01:21, Kees Cook wrote: > > 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? v3 of this series is already in mm-unstable, and has had some -next exposure (which was helpful in uncovering some additional issues). Therefore, I think it's appropriate that it continues in mm and Andrew picks up the latest v4 here. Your official Ack would nevertheless be much appreciated! Thanks, -- Marco