Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2305525rdb; Wed, 21 Feb 2024 03:43:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUxqLhulMcXufHayFkN0CCAUo2Zvp8m7U716fJpM2YS9OacOz0c0lhJNZS/d0uU+OaIYL6rGuPu9JZmn6sbiMcQAMdzpU2EI2CEhNibKA== X-Google-Smtp-Source: AGHT+IFFALbpGX7v0HaxNvjGcJTCbfqzE/QYaJSh+DIIPNy9owQzwgaATsrei0u2KS8XU1Dg3XIF X-Received: by 2002:a17:902:e789:b0:1db:fa84:9be3 with SMTP id cp9-20020a170902e78900b001dbfa849be3mr7140510plb.8.1708515819347; Wed, 21 Feb 2024 03:43:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708515819; cv=pass; d=google.com; s=arc-20160816; b=H4f1Ij2L8NKyBCRWe0hk4BkTFScJWhdYPVHdwbCk8/AtzlaqnQTK8DQk+PZHts9MZC HBH65livp5ZPZh0AvHXoXEmPeTIwUWlwbaaOeYQG3C8/fUCtA27SPD4BOJ9chkegMyz0 /mrzP5Pq2Y3boKsXfN3wKdFnFh37iy5mUx2vLFt46/WJM/Mn/ukYFdxBm1pnT7/k2dV1 8Pm8uzEVGNjQqAkhOowkKB/olNWy/pH4IJMZ5CPmkwjgyNqRpqeGn1LMP7H7aRmCuxHx ++FJnJqSE6tkDnrLm1aWdToqsO3azNEFOS/F6FpAvpxymRpIgNOuie9puGc2JFdPcmCo F3Zg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=puf0ehbUJ1l2vvmDvMl1RbndEbS00JmFo/d5xisKF4I=; fh=Nz/4An3JUTmIoyQBA71S7vu+r+PGMQLWUvvx8PmX6gc=; b=0766Iby6nF5v+24YmEstd+xSLAlbXMtHnRcBcnKwTtvAQDOpemVJOm50dkFRRGFmND up1TfbvOhKjHq04R63nVSKVfIW1isApj57yqCJRjp0MBLwPoGU67RanT0YEi4NT8/Bjb GWwtc0fewdtpGU6rjrbE77zcSJI4Zs/eiG1KuXle2y6tLULKNblC0N5MaA+FdCwD69FB EpgqpN62B8UZgMAn7BPJE5p01C8mdmPand5WIP02akuTNVZrNtu2tUDsSTXlqmEoBQjr 222Mla1bj/o1GWdwX+r2AXb2X8hLQYXL4UGmiNHbOTn8TAsRYUsSTfqpLqcvQmw8gnH/ qYLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QmozKRwe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-74649-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74649-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c8-20020a170903234800b001d904d7c449si8095031plh.271.2024.02.21.03.43.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 03:43:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74649-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QmozKRwe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-74649-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74649-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9A6F3B22603 for ; Wed, 21 Feb 2024 11:41:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DF4A46420; Wed, 21 Feb 2024 11:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QmozKRwe" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 814CF4176B; Wed, 21 Feb 2024 11:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515527; cv=none; b=sm6YQ9atwaNVDxCljAG3Nq8WLhQCufapOu23rdl/nUmFwo1mgs1wiVFL0E7sq8ULLBAoyTsjCaTEdgSYhOBw8utIIE6XM4dvPgVlX1WANw67gpk7obkqHO2FR6T5oSB4CmIxPWjow+moIspR0a+oKKXLalsmHlA6Dm3XvuQtqBU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515527; c=relaxed/simple; bh=xdNI4R/LUMaT7y3fB8rVKOoA4uG+WYub0HPf2OBgjcs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=iirjeq1SFn7dz+yiwU/kUpvLNiQ0OZzef9PHhZ3hIdvTwhz0UfHzUh8IUXv8O80bU1928JHdfsCgoMU3gvqd/6ijK3Z6VrjuAi66h71q0x/lHH6fqtDEcGdvMUe6/5jkpKVeBq+XHuSipLWFMSyRompnm0pSf8j/gz2XCeoJGtE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QmozKRwe; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6F3CC433F1; Wed, 21 Feb 2024 11:38:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708515526; bh=xdNI4R/LUMaT7y3fB8rVKOoA4uG+WYub0HPf2OBgjcs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QmozKRwecaa1zNsQX36rVltHFrFiA93Pf5f7cUvkXCorawxiMezPx9U0wlR/PlxE1 XlLuXhozAcz1wjKycYYhwTTX2D9qfmTlDLsRWLArEiYgYx4coaNIL117XzczJ4fetx 8B+VDyE70pHDALoql3EpP5xSOGhOduvIDXvtlUDa+k4lxlHg35IBqL7JmZa84srtmm 2IheknnnODcaBCqBUp9V4DT24L5fyn/ICwUOqsEZLVlRhoK9v5kgD0m6Q+riLEiggN D2DYlEAHJTbaUXH0+UxdLXz8MZHPnkJB8isaPkNeecc8DE88FCSOyBEjpcxBlH0Onu O5dtefz0mRZZw== Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d208d0b282so87131971fa.0; Wed, 21 Feb 2024 03:38:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU0QHlU8ZJ66fzUm3nWqDzTjiOIU4p1qtZf7D4ZQxJhMAfm0iI3Xy+ahj2KB84r8yDOa+uzidhrEYz1bMudX7SIMo5dS0uRHmYsd9trdTbx09Y5NKQpNYd53jFd5JNHuniZJTrJnXje395U X-Gm-Message-State: AOJu0YyhYU6kkceOkx7Xbln8yaGD4adHPMSQKn0UCCs23G7UjhBeBpj8 bc+1fr+RyHDX/7dLCS4FnjHVejG3ekHOuX3b7nBv5xx4snatwYMb8HGYNaaOWoqT1H7OcBcQto0 emWzYy5sReIqfBQylKtcxQio0pLM= X-Received: by 2002:a05:651c:1507:b0:2d2:4471:c9c8 with SMTP id e7-20020a05651c150700b002d24471c9c8mr4977958ljf.16.1708515525406; Wed, 21 Feb 2024 03:38:45 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240215151642.8970-1-petr.pavlu@suse.com> <9b067ec7-34e2-437b-a41b-319aaee4c7e6@suse.com> In-Reply-To: <9b067ec7-34e2-437b-a41b-319aaee4c7e6@suse.com> From: Masahiro Yamada Date: Wed, 21 Feb 2024 20:38:08 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] kbuild: Use -fmin-function-alignment when available To: Petr Pavlu Cc: nathan@kernel.org, nicolas@fjasle.eu, mark.rutland@arm.com, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 21, 2024 at 7:38=E2=80=AFPM Petr Pavlu wr= ote: > > On 2/20/24 14:39, Masahiro Yamada wrote: > > On Fri, Feb 16, 2024 at 12:16=E2=80=AFAM Petr Pavlu wrote: > >> > >> GCC recently added option -fmin-function-alignment, which should appea= r > >> in GCC 14. Unlike -falign-functions, this option causes all functions = to > >> be aligned at the specified value, including the cold ones. > >> > >> Detect availability of -fmin-function-alignment and use it instead of > >> -falign-functions when present. Introduce CC_HAS_SANE_FUNCTION_ALIGNME= NT > >> and make the workarounds for the broken function alignment conditional > >> on this setting. > >> > >> Signed-off-by: Petr Pavlu > >> --- > > > > [snip] > > > >> index dfb963d2f862..5a6fed4ad3df 100644 > >> --- a/kernel/exit.c > >> +++ b/kernel/exit.c > >> @@ -1920,7 +1920,10 @@ EXPORT_SYMBOL(thread_group_exited); > >> * > >> * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D88345#c11 > >> */ > >> -__weak __function_aligned void abort(void) > >> +#ifndef CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT > >> +__function_aligned > >> +#endif > >> +__weak void abort(void) > >> { > >> BUG(); > > > > > > > > > > > > __function_aligned is conditionally defined in > > include/linux/compiler_types.h, and then it is > > conditionally used in kernel/exit.c > > > > This is unreadable. > > > > > > > > > > You may want to move CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT > > to include/linux/compiler_types.h, as this is more > > aligned with what you did for __cold. > > > > > > > > if !defined(CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT) && \ > > CONFIG_FUNCTION_ALIGNMENT > 0 > > #define __function_aligned __aligned(CONFIG_FUNCTION_ALIGNMENT) > > #else > > #define __function_aligned > > #endif > > > > > > > > > > > > However, an even more elegant approach is to unify > > the two #ifdef blocks because __cold and __function_aligned > > are related to each other. > > > > > > > > #if defined(CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT) || \ > > (CONFIG_FUNCTION_ALIGNMENT =3D=3D 0) > > #define __cold __attribute__((__cold__)) > > #define __function_aligned > > #else > > #define __cold > > #define __function_aligned __aligned(CONFIG_FUNCTION_ALIGNMENT) > > #endif > > I didn't want to make __function_aligned conditional on > CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT because the macro has a fairly > general name. One could decide to mark a variable as __function_aligned > and with the above code, it would no longer produce an expected result > when -fmin-function-alignment is available. > > __function_aligned was introduced c27cd083cfb9 ("Compiler attributes: > GCC cold function alignment workarounds") only for aligning the abort() > function and has not been so far used anywhere else. > > If the above unification is preferred, I think it would be good to > additionally rename the macro in order to prevent the mentioned misuse, > perhaps to __force_function_alignment. > > #if defined(CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT) || \ > (CONFIG_FUNCTION_ALIGNMENT =3D=3D 0) > #define __cold __attribute__((__cold__)) > #define __force_function_alignment > #else > #define __cold > #define __force_function_alignment __aligned(CONFIG_FUNCTION_ALIGNME= NT) > #endif > > Would this be ok? Or, you can always add __function_aligned to abort() whether CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT is y or n. I think you did not need to modify kernel/exit.c -- Best Regards Masahiro Yamada