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 392B6D64086 for ; Sat, 9 Nov 2024 04:33:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Hf7Np0zDw+c48+kdZh45ERQZDZj4qLH0UUo7eRTe2mg=; b=xDQ/OfycVfHlOPBVWP4a2O/DKr Ep3IYTOVqDxVxollnqVrATo/s50KilniRHZe+wmxaR2is/FGvNIZWiyszE3tASSu2ujvP/U7XoBx1 rVztHcenTzkIDsm2LzyyrgsV2/LYYKK0V51pbUb9EZKwRMMtSa2pnhmtxWAD4dnJZDjJngzyaMQe7 11AtXp2ccpvteWZhpTHoFH7tGsgFZW4r8IVEeK9XHPh/MFMLszrSS278DiOdHdnn/W7rO9l9K8CsB BAap6NghdT70ikoG8yA8rV963VFdzUyyhlBmC37KSIjwPI+0LI8az3yvdPskmSVNwLcn8ooMzRGer RNSEKw/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t9dAA-0000000Cef8-1nkO; Sat, 09 Nov 2024 04:33:30 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t9d8P-0000000CebP-48CH for linux-arm-kernel@lists.infradead.org; Sat, 09 Nov 2024 04:31:43 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id F0525A401F7; Sat, 9 Nov 2024 04:29:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF5F9C4CEC6; Sat, 9 Nov 2024 04:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731126700; bh=6P7VTq0iFuBOPj08izo8XoaSip1zS6ftHKfIXdnSoZc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mXSrPL9gP7yTi305m1Lmv3Piv6BOr1R2IpQE/dFq313e8zKv9k0Rq0hf8LGoA01dJ MmvbHeiG9p0b79a+5HqtKFAWVNvBEbCKFJOTTZkvrZzqwcO/JAkNWgEgC57TLQVhYe oFTIPv+zGb8maMiHg7fATs+hI7eJOkOvM8V2r579bwT/E4OhH62SmAvEEQTPddlM4g mpnR2WaDi/5CKdxUNyo+7WxapAhFZ1SlUEbf4cUcyDZMhHGdWeNlvwunIFSvmd6aoR nff3gli1az90++Yb+59o1kIPqi/SVeNXvJeGk6ykKB5RMbpZdWl2LZhIW6n/a9YwPF kpmkfWoQsEXSQ== Date: Fri, 8 Nov 2024 21:31:38 -0700 From: Nathan Chancellor To: Linus Walleij Cc: Russell King , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, kernel test robot Subject: Re: [PATCH] ARM: cfi: Fix compilation corner case Message-ID: <20241109043138.GA1649953@thelio-3990X> References: <20241108-fix-kcfi-bug-v1-1-f8497c4bccae@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241108-fix-kcfi-bug-v1-1-f8497c4bccae@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241108_203142_175319_53DAEF6E X-CRM114-Status: GOOD ( 29.32 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Nov 08, 2024 at 08:37:36AM +0100, Linus Walleij wrote: > When enabling expert mode CONFIG_EXPERT and using that power > user mode to disable the branch prediction hardening > !CONFIG_HARDEN_BRANCH_PREDICTOR, the picky assembly linker > in CLANG notices that some assembly in proc-v7.S does > not have corresponding C call sites, i.e. the prototypes > in proc-v7-bugs.c are enclosed in ifdef > CONFIG_HARDEN_BRANCH_PREDICTOR so this assembly: > > SYM_TYPED_FUNC_START(cpu_v7_smc_switch_mm) > SYM_TYPED_FUNC_START(cpu_v7_hvc_switch_mm) > > Results in: > > ld.lld: error: undefined symbol: __kcfi_typeid_cpu_v7_smc_switch_mm > >>> referenced by proc-v7.S:94 (.../arch/arm/mm/proc-v7.S:94) > >>> arch/arm/mm/proc-v7.o:(.text+0x108) in archive vmlinux.a > > ld.lld: error: undefined symbol: __kcfi_typeid_cpu_v7_hvc_switch_mm > >>> referenced by proc-v7.S:105 (.../arch/arm/mm/proc-v7.S:105) > >>> arch/arm/mm/proc-v7.o:(.text+0x124) in archive vmlinux.a > > Fix this by adding an additional requirement that > CONFIG_HARDEN_BRANCH_PREDICTOR has to be enabled to compile > these assembly calls. > > I suppose it wasn't a problem before because the linker is not > so picky that other assembly symbols are actually being > used. I think this has been a problem since the original CFI change, so I think it is worth dropping this block; it is more likely that CONFIG_HARDEN_BRANCH_PREDICTOR is not often disabled outside of randconfig, so it is hard to hit this issue in practice. As far as I can tell, this is totally expected with the given configuration. SYM_TYPED_FUNC_START makes use of __kcfi_typeid_, which the compiler generates for address-taken function declarations, but in this configuration, cpu_v7_smc_switch_mm() and cpu_v7_hvc_switch_mm() have no actual uses aside from their definition, so the compiler does not generate these symbols, resulting in the link time error above. Perhaps some of this could be encorporated into the beginning of the commit message to make the issue a little more clear and less like the compiler is at fault here ("the picky assembly linker" stands out a bit to me there). > Reported-by: kernel test robot > Closes: https://lore.kernel.org/oe-kbuild-all/202411041456.ZsoEiD7T-lkp@intel.com/ > Signed-off-by: Linus Walleij Regardless of the commit message nits, this seems like the right thing to do. Reviewed-by: Nathan Chancellor > --- > arch/arm/mm/proc-v7.S | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S > index 5fb9a6aecb00..2cd933342679 100644 > --- a/arch/arm/mm/proc-v7.S > +++ b/arch/arm/mm/proc-v7.S > @@ -94,7 +94,7 @@ SYM_TYPED_FUNC_START(cpu_v7_dcache_clean_area) > ret lr > SYM_FUNC_END(cpu_v7_dcache_clean_area) > > -#ifdef CONFIG_ARM_PSCI > +#if defined(CONFIG_ARM_PSCI) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) > .arch_extension sec > SYM_TYPED_FUNC_START(cpu_v7_smc_switch_mm) > stmfd sp!, {r0 - r3} > > --- > base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc > change-id: 20241107-fix-kcfi-bug-ae3b08cbc167 > > Best regards, > -- > Linus Walleij >