Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7029604rwb; Mon, 12 Dec 2022 09:11:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf6KErvcVpjZQzgnpHxHGOHxX5kwcehn/XzcugwWVluOHsOdd/NMYPp2ghVLj3i2EGcOMvFe X-Received: by 2002:a17:906:1b58:b0:7c0:e99a:e353 with SMTP id p24-20020a1709061b5800b007c0e99ae353mr13363570ejg.56.1670865078646; Mon, 12 Dec 2022 09:11:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670865078; cv=none; d=google.com; s=arc-20160816; b=F+SZ14JY8RXZcP7oe+CBk0p8kzxpqQupgx3WrYhsN2bmyYeReMIdZiAxEcO/DXp2HY lcQgC/8OMVyjHWJlwjQhB7lMbWEfxI5J3qGHi5qbxZKQQxJreZW2/XHsQMcsWyNDW12L qdigRWEBq67BiP3+mzzPPX8VT0OtLDFbvXPfukg+vud/4eUdpVtYE1x4WPn3dLqkrX7I dE3fsOyBBeyt3fVELWWJPBl/HtsH9kmm9yU0ugtQJWupXwDDVeV0Q6pbl1CHUmfh6is3 j7tGVKzs2uKU76ryjm1zpFKVLvENZ4lm5r5fq7C+w8+g0nQeU8FPm6Xy7mOFghgW1Tyj oCkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bJ00KdK4nXPp7dXqDQaB4vAfSzMs43EY+9RF4rTRElw=; b=ZfN6fKv+fnyldaz4ACjUzqWOkCxfI472OWNPtnzkU7m7n6ZnbID2dHD5Fhl4G3oM9q 6IpDnhnMA9jNiPCMe5xiSZMu1Tz6AGizrdGmbXbcMWjVsnapJGeotti1l9zkHIvpPLAR 5bUShXbArTMXKFh/2obGorlKBGvqzDetXMSVrWPMkB8jO9nm43KuF7sUFYy9vQ0nFrhh /fTbVFBzdcBIswQgyHFqu14O/NvUuVTOSjChwiSO4u9n/axxiqkiKXOMrECC5qBfJID5 K64IF/Zrwg5BIrE6Hf/zJwlBejNWgI7OCINYmEu1e/+Z7V+fWgMfip/i7RrrOK++yVW0 yV8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Aj6vrtB3; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn35-20020a1709070d2300b007c0969e429bsi7409722ejc.30.2022.12.12.09.10.44; Mon, 12 Dec 2022 09:11:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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=@kernel.org header.s=k20201202 header.b=Aj6vrtB3; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232864AbiLLRFY (ORCPT + 99 others); Mon, 12 Dec 2022 12:05:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232252AbiLLRFG (ORCPT ); Mon, 12 Dec 2022 12:05:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A9510DD; Mon, 12 Dec 2022 09:05:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 67D136115C; Mon, 12 Dec 2022 17:05:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28B21C433F0; Mon, 12 Dec 2022 17:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670864704; bh=KmG4ro7h+VdOXjEslNq+8iBWKBTQ/RA7zskQtxL+RXw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Aj6vrtB3Y2skOx8SKPJd7krfhSKJ/utA+bWT4xTHarHMUD3/lISCtlvJqPHL60pzb gBefVSEqHgMTU2td3vxDOudSSqtIFyGEE3fjACq1ImpoFS6AbTSU4gyoNzKLtYmaUk 8HFKc5bYSKCl0NPKxs5dwH01VjTI/AU8U1qEI6cnPh7ywjBflGg9Adm5tMcwnxVY3Q IzeAVMFpIdKeFQBwv3sUlGm3hpuFpURSm4Di7el+3ELuoTPiN3B+mdwleD0ujL+D77 U47NENYSq9mwaTnfNquImIqO6NV+79DE502FuufTe2OhE4tXY8SzjLVoqYzGx34tUW xOp0Is+zD4lrA== Date: Mon, 12 Dec 2022 10:05:02 -0700 From: Nathan Chancellor To: Masahiro Yamada Cc: Nick Desaulniers , Tom Rix , Nicolas Schier , Sami Tolvanen , Vincent Donnefort , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, patches@lists.linux.dev, Daniel Jordan , Steffen Klassert , linux-crypto@vger.kernel.org Subject: Re: [PATCH v2 1/2] padata: Mark padata_work_init() as __ref Message-ID: References: <20221207191657.2852229-1-nathan@kernel.org> <20221207191657.2852229-2-nathan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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-crypto@vger.kernel.org On Mon, Dec 12, 2022 at 10:07:24PM +0900, Masahiro Yamada wrote: > On Thu, Dec 8, 2022 at 4:17 AM Nathan Chancellor wrote: > > > > When building arm64 allmodconfig + ThinLTO with clang and a proposed > > modpost update to account for -ffuncton-sections, the following warning > > appears: > > > > WARNING: modpost: vmlinux.o: section mismatch in reference: padata_work_init (section: .text.padata_work_init) -> padata_mt_helper (section: .init.text) > > WARNING: modpost: vmlinux.o: section mismatch in reference: padata_work_init (section: .text.padata_work_init) -> padata_mt_helper (section: .init.text) > > > > LLVM has optimized padata_work_init() to include the address of > > padata_mt_helper() directly, which causes modpost to complain since > > padata_work_init() is not __init, whereas padata_mt_helper() is. In > > reality, padata_work_init() is only called with padata_mt_helper() as > > the work_fn argument in code that is __init, so this warning will not > > result in any problems. Silence it with __ref, which makes it clear to > > modpost that padata_work_init() can only use padata_mt_helper() in > > __init code. > > > > Suggested-by: Daniel Jordan > > Signed-off-by: Nathan Chancellor > > --- > > Cc: Steffen Klassert > > Cc: Daniel Jordan > > Cc: linux-crypto@vger.kernel.org > > --- > > kernel/padata.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/padata.c b/kernel/padata.c > > index e5819bb8bd1d..4c3137fe8449 100644 > > --- a/kernel/padata.c > > +++ b/kernel/padata.c > > @@ -83,8 +83,8 @@ static struct padata_work *padata_work_alloc(void) > > return pw; > > } > > > > -static void padata_work_init(struct padata_work *pw, work_func_t work_fn, > > - void *data, int flags) > > +static __ref void padata_work_init(struct padata_work *pw, work_func_t work_fn, > > + void *data, int flags) > > { > > if (flags & PADATA_WORK_ONSTACK) > > INIT_WORK_ONSTACK(&pw->pw_work, work_fn); > > > > base-commit: 76dcd734eca23168cb008912c0f69ff408905235 > > -- > > 2.38.1 > > > > It took me a while to understand why LTO can embed > padata_mt_helper's address into padata_work_init(). Sorry about that, I can try to expand on this in both the commit message and in-code comment if I end up adding it. > There are 3 call-sites to padata_work_init(). > > (1) __init padata_work_alloc_mt() > --> padata_work_init(..., padata_mt_helper, ...) > > (2) padata_do_parallel() > --> padata_work_init(..., padata_parallel_worker, ...) > > (3) __init padata_do_multithreaded() > --> padata_work_init(..., padata_mt_helper, ...) > > > The function call (2) is squashed away. > > > With only (1) and (3) remaining, the 2nd parameter to > padata_work_init() is always padata_mt_helper, > therefore LLVM embeds padata_mt_hlper's address > directly into padata_work_init(). > > I am not sure if the compiler should do this level of optimization > because kernel/padata.c does not seem to be a special case. > Perhaps, we might be hit with more cases that need __ref annotation, > which is only required by LTO. That's possible. I did only see this once instance in all my builds but allmodconfig + ThinLTO might not be too interesting of a case, since the sanitizers will be enabled, which makes optimization more difficult. I could try to enable ThinLTO with some distribution configurations to see if there are any more instances that crop up. > One note is that, we could discard padata_work_init() > because (1) and (3) are both annotated as __init. > So, another way of fixing is > static __always_inline void padata_work_init(...) > because the compiler would determine padata_work_init() > would be small enough if the caller and callee belonged to > the same section. > > I do not have a strong opinion. > Honestly, I do not know what the best approach would be to fix this. Agreed to both points, it is really up to the padata maintainers. > If we go with the __ref annotation, I can pick this, but > at least can you add some comments? > > > include/linux/init.h says: > "optimally document why the __ref is needed and why it's OK" > > > I think this is the case that needs some comments > because LTO optimization looks too tricky to me. Sure thing, I will send a v3 either Tuesday or Wednesday with an updated commit message and code comment if we end up going this route. Thank you for the review! Cheers, Nathan