Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp362064lqs; Thu, 13 Jun 2024 12:09:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU79hVGEKogeiw1VpPp94DQhwYzA16weN81PE+iNb/qaAsjxnCX9auJvdxsK14SOoQAWp33PZ7pQqd+Cl2sCzB40VMLGaQDTwJLoShQ2A== X-Google-Smtp-Source: AGHT+IHaw2Ta6BrW9cAv+FGg7/dSikRmALNGAN7bRkwYj9CwXz/FXQle5s/6pH0+Zq1iuiZT1bZS X-Received: by 2002:a17:902:ec91:b0:1f8:55d8:ded4 with SMTP id d9443c01a7336-1f8625d50f8mr6661775ad.6.1718305770217; Thu, 13 Jun 2024 12:09:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718305770; cv=pass; d=google.com; s=arc-20160816; b=l6CZKrBo9ys8Sq1HjhYSHCHG63Jdvl75AGWqSOQQGqQMOVkV6AglpOf5eDTWWPX1LL l+U9OfYE3bo33Rd2E0AFuN4m3o7Y00fe5XXUVRj4DjbKEFgI4cIlOuzHT1g+RZWdliC5 i3thaei8dR5USHPqC/6P4wRUWU36U92e9QpL+tU0huTcKbyBbehH8uUFF6yhXo5WvHLM K1YLCpb0+bwVTV4skET+MBUT3eYV75k5048a3VaGnmmW+Zj0mgpsFs8T/yQw3/M7dlwe wnQVoKleS2SbVbnbRa1r7Wg6mwgctvLxFJESvgWMlRBnQ9iggqKxJJIsbPsMRuDgZWxV IpOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=KdianrVuVvACdHPrqMMdopiLQN2ovZwDiFHxFAorMv4=; fh=lQ2f8nyihSMfnzZ9geaqI9Qf3aAbeQ1m1lOZ4lWTLuk=; b=hVZswmuov+77YHsE90ZOmRPOX0QRTcZN5EnrAIonXAS2Rda/NE0XthfxeAXaW0mma0 Ehb//LMzuNtx+BiR30/h3n8uySq99M3biJyqCioNvpOGWNNuMNQOKvY7FjgNkieB3KXv 4X93KXPc3FVF198H7K+niE9E0qdomIzRq2m/C7xSh0gdfVSH4oujwFT81O+HKWqUyVnY Qr8Yv19ugMnL4pcWaLfKaELItmXq0AdjjlfEilTJEKqzdbpnWvig//2EvJ7m2PuUvIyQ V0iYpxuw1x+r2ZtSi6F32xilVP8vBVj0QNmfFxwVk02eMFhGG02AROdliRSlHUfm1ZV1 3zMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r15KrCdS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-213888-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213888-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f855ee1aa7si18643845ad.360.2024.06.13.12.09.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 12:09:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213888-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r15KrCdS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-213888-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213888-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C9622286AA7 for ; Thu, 13 Jun 2024 19:09:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8FA514B075; Thu, 13 Jun 2024 19:09:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r15KrCdS" 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 DB509137C20; Thu, 13 Jun 2024 19:09:23 +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=1718305764; cv=none; b=DWYbhgdpZS/HCD7O8CddL//tSVedSGYcROmijJ/R/uP7PmNNPR6cQUVT3g5TvdT5soTPM41UsD+bzza0MVOx39Zppmlz3ab++gRldO5pBMZA6FQ22E2IeMovZw0ukGtdOryCk5bAgH2lOEB9zwxlyFWgKhA+WDN/2SPYmzsV7x8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718305764; c=relaxed/simple; bh=HFWyWh6KpryPRqXeZqS8bpwy4cpqT7565JH13UCYe8Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=URFTR3E1b82UiJldQXEDSVB+81XT14dvazmUnQ1xmmWrPkqxJ60oAQQPTip+jCV0NBpHp9mABL8MVyAZTINsOAaRb3IFKvGZgU9l67xF22UpQckhVG0beTo9YiduTZZ1cNngRDusphIOUkyTc+s2YcFxHggYNIASFngZtR4na0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r15KrCdS; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C484C2BBFC; Thu, 13 Jun 2024 19:09:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718305763; bh=HFWyWh6KpryPRqXeZqS8bpwy4cpqT7565JH13UCYe8Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r15KrCdS9IdIHad1rdEnJ2d8ckWytMU6LKbZHtECfabZeOOL5NeBLIxxPBq3z0zys 3slzhtA9cdHuWZnGZHDV5NLs2bTHbBZynuD7Q8DQOxVA09rVcITHteKZ+9+HgLXR5M HdoVCKVKrpzgEk2cSlL6jYQ71DUrUvpCH8y/LyXJsqZGTYjaU0YmUIsxGTKPGUwrAM uV1gBh1sR/ghA14TJc9M7AyHJIwf42TPHHmnNcaLCqawQObi8CV5wvWxi8CbRIG6cM TBm0dJY8W1NUsdLFkBf/mQlzHFacpAS20ZjS1cela3jB5ird9bozLTcvGNoQEx+Z3j J9N0ANl5gHr0g== Date: Thu, 13 Jun 2024 12:09:20 -0700 From: Nathan Chancellor To: Andy Chiu Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Zong Li , Steven Rostedt , Masami Hiramatsu , Mark Rutland , Nick Desaulniers , Bill Wendling , Justin Stitt , Puranjay Mohan , Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, llvm@lists.linux.dev, Evgenii Shatokhin Subject: Re: [PATCH 4/8] riscv: ftrace: align patchable functions to 4 Byte boundary Message-ID: <20240613190920.GB1272931@thelio-3990X> References: <20240613-dev-andyc-dyn-ftrace-v4-v1-0-1a538e12c01e@sifive.com> <20240613-dev-andyc-dyn-ftrace-v4-v1-4-1a538e12c01e@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240613-dev-andyc-dyn-ftrace-v4-v1-4-1a538e12c01e@sifive.com> Hi Andy, On Thu, Jun 13, 2024 at 03:11:09PM +0800, Andy Chiu wrote: > We are changing ftrace code patching in order to remove dependency from > stop_machine() and enable kernel preemption. This requires us to align > functions entry at a 4-B align address. > > However, -falign-functions on older versions of GCC alone was not strong > enoungh to align all functions. In fact, cold functions are not aligned > after turning on optimizations. We consider this is a bug in GCC and > turn off guess-branch-probility as a workaround to align all functions. > > GCC bug id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345 > > The option -fmin-function-alignment is able to align all functions > properly on newer versions of gcc. So, we add a cc-option to test if > the toolchain supports it. > > Suggested-by: Evgenii Shatokhin > Signed-off-by: Andy Chiu > --- > arch/riscv/Kconfig | 1 + > arch/riscv/Makefile | 7 ++++++- > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index b94176e25be1..80b8d48e1e46 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -203,6 +203,7 @@ config CLANG_SUPPORTS_DYNAMIC_FTRACE > config GCC_SUPPORTS_DYNAMIC_FTRACE > def_bool CC_IS_GCC > depends on $(cc-option,-fpatchable-function-entry=8) > + depends on $(cc-option,-fmin-function-alignment=4) || !RISCV_ISA_C Please use CC_HAS_MIN_FUNCTION_ALIGNMENT (from arch/Kconfig), which already checks for support for this option. > config HAVE_SHADOW_CALL_STACK > def_bool $(cc-option,-fsanitize=shadow-call-stack) > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > index 06de9d365088..74628ad8dcf8 100644 > --- a/arch/riscv/Makefile > +++ b/arch/riscv/Makefile > @@ -14,8 +14,13 @@ endif > ifeq ($(CONFIG_DYNAMIC_FTRACE),y) > LDFLAGS_vmlinux += --no-relax > KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY > +ifeq ($(CONFIG_CC_IS_CLANG),y) Same here, please invert this and use ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT like the main Makefile does. > + cflags_ftrace_align := -falign-functions=4 > +else > + cflags_ftrace_align := -fmin-function-alignment=4 > +endif > ifeq ($(CONFIG_RISCV_ISA_C),y) > - CC_FLAGS_FTRACE := -fpatchable-function-entry=4 > + CC_FLAGS_FTRACE := -fpatchable-function-entry=4 $(cflags_ftrace_align) > else > CC_FLAGS_FTRACE := -fpatchable-function-entry=2 > endif > > -- > 2.43.0 > >