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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F34AC001B0 for ; Mon, 14 Aug 2023 23:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jkf4yOG50OxY6DTtYp2q8db9l698qJn7OYQjFK7gpLc=; b=Y40jY/zltiAKmH mAYXA0+cqG+MJ0PVPkB7ef8gNDsQ1GX1IMML3Yhznjjvj33m8ncwf4gVVHbF7xV+pPpxZA8w8wnMg lcsCBQJOOUDlQQLVg1GW8PD0TSWH/GI3SJ0pwFexhVyEtcL/Dz+mFa2qdhYKx2xaio+PnzMVB9P27 0B77kYhp1thIs3V0Al0pUo8QfCGKiV3jQvH6oGnOrMhn88q4Pd+ryd4H3ubFRTtmruxLqLE/wWpLn uU0OADvjI47B0/zTnMzi7/6VmVWWgMKtvKIgEBpEfjegQ5PQQDg7XBDTY5ftF2ywpPRTCLFjYd6MP grk2Hz3zV51/VUa/WKFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qVgsg-000WjY-0c; Mon, 14 Aug 2023 23:21:50 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qVgsc-000Wip-1e for linux-arm-kernel@lists.infradead.org; Mon, 14 Aug 2023 23:21:48 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bdf7086ae5so3059235ad.0 for ; Mon, 14 Aug 2023 16:21:44 -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=RQuIa7P0N473gmwvVrTRmfPhW1yfbE878EdtrqR343s44BYK9gZMQub81e7ANL1WJL UwPewYkmAOMG6OS6qJkN2GgPDIrlLUu9ZVWn97wikjsgN0fr2lu5u4kecYcjepTBKfQY 0wOaJvK9nlvvsXl5q1hzxetcgf3Z4VFbRnJ4oKymX564KcCNQBLjw3yqeQVFSI2afYe7 36Xz320RTzlH85HW423w6OJSQNI/bnKls+FnYYkmGehwdUw1aVDC/WTguLLua3PnirNl YLcJwom0XYXe3BWwxSFS2gS0k0shKo0zleqn/X5umdgIhXMoi8gSb62CRKMI2MnAc92r PI+g== X-Gm-Message-State: AOJu0YyzHLoCWot5NFrUwoKYKmUkaFxjk6BVCe0qUUstH3PbOHV1e8HI rECJzfkQgD9WSrloe6/jd6uhuw== 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-Disposition: inline In-Reply-To: <20230811151847.1594958-1-elver@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230814_162146_595068_F1C43604 X-CRM114-Status: GOOD ( 26.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel