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 X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9725AC432BE for ; Tue, 17 Aug 2021 09:22:19 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 76F0D60720 for ; Tue, 17 Aug 2021 09:22:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 76F0D60720 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=csgroup.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Gplt02Qqrz3cRN for ; Tue, 17 Aug 2021 19:22:16 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=csgroup.eu (client-ip=93.17.235.10; helo=pegase2.c-s.fr; envelope-from=christophe.leroy@csgroup.eu; receiver=) Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GplsV5plVz2yXy for ; Tue, 17 Aug 2021 19:21:47 +1000 (AEST) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4GplsJ24qlz9sTm; Tue, 17 Aug 2021 11:21:40 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id k7YWyVUjcKY5; Tue, 17 Aug 2021 11:21:40 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4GplsJ0mjqz9sTT; Tue, 17 Aug 2021 11:21:40 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E82168B7A6; Tue, 17 Aug 2021 11:21:39 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id nEYXPrjcp5Y5; Tue, 17 Aug 2021 11:21:39 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4E8A28B765; Tue, 17 Aug 2021 11:21:39 +0200 (CEST) Subject: Re: [PATCH 2/3] powerpc: Fix undefined static key To: Joel Stanley References: <20210816082403.2293846-1-joel@jms.id.au> <20210816082403.2293846-3-joel@jms.id.au> <492edb10-ccef-c6f2-2fd3-71cf8ae54cfc@csgroup.eu> From: Christophe Leroy Message-ID: Date: Tue, 17 Aug 2021 11:21:31 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Neuling , Nicholas Piggin , Paul Mackerras , linuxppc-dev , Daniel Axtens Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Le 17/08/2021 à 04:44, Joel Stanley a écrit : > On Mon, 16 Aug 2021 at 08:39, Christophe Leroy > wrote: >> >> >> >> Le 16/08/2021 à 10:24, Joel Stanley a écrit : >>> When CONFIG_PPC_BARRIER_NOSPEC=n, security.c is not built leading to a >>> missing definition of uaccess_flush_key. >>> >>> LD vmlinux.o >>> MODPOST vmlinux.symvers >>> MODINFO modules.builtin.modinfo >>> GEN modules.builtin >>> LD .tmp_vmlinux.kallsyms1 >>> powerpc64le-linux-gnu-ld: arch/powerpc/kernel/align.o:(.toc+0x0): undefined reference to `uaccess_flush_key' >>> powerpc64le-linux-gnu-ld: arch/powerpc/kernel/signal_64.o:(.toc+0x0): undefined reference to `uaccess_flush_key' >>> powerpc64le-linux-gnu-ld: arch/powerpc/kernel/process.o:(.toc+0x0): undefined reference to `uaccess_flush_key' >>> powerpc64le-linux-gnu-ld: arch/powerpc/kernel/traps.o:(.toc+0x0): undefined reference to `uaccess_flush_key' >>> powerpc64le-linux-gnu-ld: arch/powerpc/kernel/hw_breakpoint_constraints.o:(.toc+0x0): undefined reference to `uaccess_flush_key' >>> powerpc64le-linux-gnu-ld: arch/powerpc/kernel/ptrace/ptrace.o:(.toc+0x0): more undefined references to `uaccess_flush_key' follow >>> make[1]: *** [Makefile:1176: vmlinux] Error 1 >>> >>> Hack one in to fix the build. >>> >>> Signed-off-by: Joel Stanley >>> --- >>> arch/powerpc/include/asm/security_features.h | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/arch/powerpc/include/asm/security_features.h b/arch/powerpc/include/asm/security_features.h >>> index 792eefaf230b..46ade7927a4c 100644 >>> --- a/arch/powerpc/include/asm/security_features.h >>> +++ b/arch/powerpc/include/asm/security_features.h >>> @@ -39,6 +39,9 @@ static inline bool security_ftr_enabled(u64 feature) >>> return !!(powerpc_security_features & feature); >>> } >>> >>> +#ifndef CONFIG_PPC_BARRIER_NOSPEC >>> +DEFINE_STATIC_KEY_FALSE(uaccess_flush_key); >>> +#endif >> >> It will then be re-defined by each file that includes asm/security_features.h .... >> >> You can't use a DEFINE_ in a .h >> >> You have to fix the problem at its source. >> >> Cleanest way I see it to modify asm/book3s/64/kup.h and something like >> >> if (IS_ENABLED(CONFIG_PPC_BARRIER_NOSPEC) && static_branch_unlikely(&uaccess_flush_key) > > This won't work either as there's no declaration for uaccess_flush_key: > > arch/powerpc/include/asm/book3s/64/kup.h:411:78: error: > ‘uaccess_flush_key’ undeclared (first use in this function) I can't understand that. According to your commit message, you have reached linking step. It means that the necessary declarations were present. Adding a condition on IS_ENABLED(CONFIG_PPC_BARRIER_NOSPEC) will get you rid of the code past that condition at compile step, then linking will succeed because the code referencing 'uaccess_flush_key' won't be there anymore when you proceed with linking. > > We could add an extern for it, but that is distasteful as the static > key API suggests using the structs directly is deprecated, and the > macros we're supposed to use perform initialisation. You already have DECLARE_STATIC_KEY_FALSE(uaccess_flush_key); in That doesn't initialise anythink but provides the declaration. > > Could we assume microwatt-like platforms will not gain pkeys support, > and have a stubbed out set of prevent/restore_user_access for systems > that turn off either pkeys or BARRIER_NOSPEC? > > Or do we get rid of PPC_BARRIER_NOSPEC as an option, and have machines > rely on disabling it at runtime? >