Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3028043rwb; Mon, 7 Aug 2023 07:14:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmlfg7bx8oBzV+14dS+MRTeTdsQiJgFrYuZ19mCBc1xfp8HdW3yeDMUMnnaPNVo1uLYu8N X-Received: by 2002:a17:90b:214:b0:268:78ab:e8c1 with SMTP id fy20-20020a17090b021400b0026878abe8c1mr6942748pjb.19.1691417698886; Mon, 07 Aug 2023 07:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691417698; cv=none; d=google.com; s=arc-20160816; b=H0yRy8Ajvn36LBeTGDHAcN1aN219m51YJ3FcPPKe/r6k60AUsPfUL7batg2JIw/kr5 5SMjL4Y2JG+Cmm9HZ7L4OiyqCUX8bwshIk8fHkQXzoIaWaevynAgx9y0b6wJv3e2P2ee Mxa02/lDDxKVB2SH24DZFGz3aR8EGGCJ+9mFsy9nFW4XfADBB0bSnUZt1vKjt0yqJuV0 VxfxYAleaIv34GDFuJIdxptNHZmJuIbvYrfDBUckAgguD8a2xK1ae2QLeebMxUTKKmdS EPJqR6YlQ6IiMZb8GrMkBxLFJMRMWlf5g9rQavILn3n0zIcdzZGa9C7rHxJTmau41saM ISCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=fsP5nkPghUp19sfWVmpj073CCh46k2F98rtPHNJSKVE=; fh=VfFMGhjO+6FaJXNGtdRcycTOiKXgCawKFW/Q7I8tcFQ=; b=NcQ4DeBve8fCWOb4V6YqiOzPE4qWFx0erh0U0A4evrzZ4unI3QOPQSg7MdOUx9TnOi DK+QnDWhuds6cioGb2CYtx7D7Dw4OKJ450BOY+RJ9d6yG3iCryWQ8cc7+HahUAP+L2ZD +o7d3nrIq7N8LTBE19K6d3bRa2WjYxNWPRE+gtp8VAuCGkI4mkGCAYhFRPJPPF5dvIJp tbdyCbUPUGcnFEPG2ySdgSr15ormyAZO0SSkEsGT4gJON/xJZxPskzr47041eEFnfswr cgdSuPpiXh5eb+pdP0BFkvMCdJfgh5ZoDdKqTpfQP20z9U7MKOD9dSq1cMt5/ZewHlJW OhoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=HCbP5hja; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a17090a6e0200b0026803b4ddfcsi5957457pjk.103.2023.08.07.07.14.46; Mon, 07 Aug 2023 07:14:58 -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; dkim=pass header.i=@google.com header.s=20221208 header.b=HCbP5hja; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233442AbjHGMZM (ORCPT + 99 others); Mon, 7 Aug 2023 08:25:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233430AbjHGMZG (ORCPT ); Mon, 7 Aug 2023 08:25:06 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F9A8128 for ; Mon, 7 Aug 2023 05:25:04 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fe32016bc8so37531045e9.1 for ; Mon, 07 Aug 2023 05:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691411103; x=1692015903; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fsP5nkPghUp19sfWVmpj073CCh46k2F98rtPHNJSKVE=; b=HCbP5hjavSOBpxbGA+3+VYKzXpS4H7ymx4XR1LfBAYF16hB5A60P/4lgvu/hlStE5x XCCUrDeOttgSewGGrBWzV2ziExaEA9G6mDSgoQhJadBJN4drjZK7qBKf0fKZAh+PnliW 9juWbu9vE9KrTBTJ9+gtYcNx6Jsx9FT6V9pKUXGIcxINseiGmqfZNKmbvQsZXkIGF1am iq4ns7vUvfllyChtK+eZExZJHznzI9FXeWjyebx9Ao1qWVzJsko2eN9kbVmNE7qSJO8j s+R8Ruqmt0Dpu8uXWhAKmqkzUjVNyAU3Xev7Coz+RqjQnJKeKomKnh8TWQNDiw1gldSc TL0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691411103; x=1692015903; h=content-transfer-encoding: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=fsP5nkPghUp19sfWVmpj073CCh46k2F98rtPHNJSKVE=; b=EVFa4PPwDyq5NXdRgowqv6qkDfmy7zsRffB33NIHNArU5Xw8nw7QBNMtqX9NSWZEGI CcJ8o0ItQ7ZkIHHc0UHZa3W4E10BJcWjv+hxsuY/h9xFJ4HrdR1jjnAZXnwtNiiVraY+ nS7jOEBl/yCKEOrghjGe7nFlN8sn65Iype5F1MRlVDQAvtvAAa/DJjF4VdGOPbfTngvK SpwgaSvyskXGEFIYoHbyrWcX0r06gvnnF1ozrYagFgdCbCP9fD5sYPkbOmRKrWx/RTbi GvbL+QRH70KHkicO03lk50fr2PfIBMfzHtCkdt/ID8QyHkqKtxbAWLFthzPfe1zi79cB 0zXg== X-Gm-Message-State: AOJu0Yy617ul39rvUoTG1BhHld8Z+6tuPf97UM1DS1ymIIuaskHEGkY4 jZY8gbvzdWhL9l/CsiKX2Q9V0st3d3h8pjQ6mQiEtA== X-Received: by 2002:a7b:cd94:0:b0:3fe:3521:d9ca with SMTP id y20-20020a7bcd94000000b003fe3521d9camr5908666wmj.3.1691411102967; Mon, 07 Aug 2023 05:25:02 -0700 (PDT) MIME-Version: 1.0 References: <20230804090621.400-1-elver@google.com> <87il9rgjvw.fsf@oldenburg.str.redhat.com> In-Reply-To: <87il9rgjvw.fsf@oldenburg.str.redhat.com> From: Marco Elver Date: Mon, 7 Aug 2023 14:24:26 +0200 Message-ID: Subject: Re: [PATCH v2 1/3] compiler_types: Introduce the Clang __preserve_most function attribute To: Florian Weimer Cc: Andrew Morton , Kees Cook , Guenter Roeck , Peter Zijlstra , Mark Rutland , Steven Rostedt , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Mon, 7 Aug 2023 at 13:41, Florian Weimer wrote: > > * Marco Elver: > > > [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 > > You dropped the interesting part: I will add it back for the kernel documentation. > | If the arguments are passed in callee-saved registers, then they will > | be preserved by the callee across the call. This doesn=E2=80=99t apply = for > | values returned in callee-saved registers. > | > | =C2=B7 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. > | > | =C2=B7 On AArch64 the callee preserve all general purpose registers, = except > | X0-X8 and X16-X18. > > Ideally, this would be documented in the respective psABI supplement. > I filled in some gaps and filed: > > Document the ABI for __preserve_most__ function calls > Good idea. I had already created https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110899, and we need better spec to proceed for GCC anyway. > Doesn't this change impact the kernel module ABI? > > I would really expect a check here > > > +#if __has_attribute(__preserve_most__) > > +# define __preserve_most notrace __attribute__((__preserve_most__)) > > +#else > > +# define __preserve_most > > +#endif > > that this is not a compilation for a module. Otherwise modules built > with a compiler with __preserve_most__ attribute support are > incompatible with kernels built with a compiler without that attribute. That's true, but is it a real problem? Isn't it known that trying to make kernel modules built for a kernel with a different config (incl. compiler) is not guaranteed to work? See IBT, CFI schemes, kernel sanitizers, etc? If we were to start trying to introduce some kind of minimal kernel to module ABI so that modules and kernels built with different toolchains keep working together, we'd need a mechanism to guarantee this minimal ABI or prohibit incompatible modules and kernels somehow. Is there a precedence for this somewhere?