Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2746045rwd; Mon, 22 May 2023 03:52:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zjtDv9l+hVv2t60ZhwM6p6U0fBtBjiNalKNWKrX0mTZtQ2Rf+vfAcN3+SYy3tpJ2AAYSs X-Received: by 2002:a17:903:18b:b0:1ac:8be5:8787 with SMTP id z11-20020a170903018b00b001ac8be58787mr11456562plg.21.1684752768358; Mon, 22 May 2023 03:52:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684752768; cv=none; d=google.com; s=arc-20160816; b=M5NqlGylSuN/gZVz8VTEJlIkFObUk2270BNNzd9cHPvIAqVVT8JvNxmAqrITXs2PW8 gCV5wLseo3E2fs6OZ72yzhpmI0o7Xh6s4Efww4IcFa+HObOJ4qhxe294VBebqy+YVnzL ejj7Xf0a1HeiDUBWEUVhAGFTkZqAlh+dsEoTStU12UuIVV273aEOfgUSgTiWkGPYxsn9 xSsU/w1UQvoovv0MhH6P3735gQGHBbrFjRGuLKFR9JKLKuQkp0aPZA/0BInlfhYPXwP+ 2ighn+vYGOJlipiV07x6GBeEoyp77HqQRdjHDTJKwaoD1w1klcF2LuncEccSkm/CCBxo pO+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=q5WHw/SgtkaVTPctnVHOVEBqPFqOL6HMy6Jcy1alaS4=; b=JX5NYszt0+eezqyhc41QEGl3heFV9QOtP3w5ZBvTX8S4kxUZ7xvaVcBt2uYDpfyYTx tVvyJjHtYrsnEKug6cSBEaFiahw80/gdN60QQhd23/75FABR0ChIa9XDfDHeuvMID7N7 WCWHNCBu5UovnbCk28CU2aqqZLNDk9ggzYbSGxLrSHqUy2UnRSO1ymw58iuJedgOiH64 JK7tB4U/qCTOTfFY7L1DKfjQwcHo6JSXE20ISRzLmSjVvRLB++6Ewxjq0DoJD5l/rine BDOT35u+sHV6rP+tOi/b4UH26knyi8QvBxIVJfmqUJxAjn0sLLt7XoyDrS5EMN4TF7RH EDVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a170902748a00b001a51bb4ad81si2335830pll.44.2023.05.22.03.52.35; Mon, 22 May 2023 03:52:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbjEVKsb (ORCPT + 99 others); Mon, 22 May 2023 06:48:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230188AbjEVKs1 (ORCPT ); Mon, 22 May 2023 06:48:27 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02F86B3 for ; Mon, 22 May 2023 03:48:25 -0700 (PDT) Received: (Authenticated sender: alex@ghiti.fr) by mail.gandi.net (Postfix) with ESMTPSA id 7904B1BF204; Mon, 22 May 2023 10:48:20 +0000 (UTC) Message-ID: <3022ab59-02f8-6f95-c7a1-b4c271729120@ghiti.fr> Date: Mon, 22 May 2023 12:48:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v8 1/3] riscv: Introduce CONFIG_RELOCATABLE Content-Language: en-US To: Palmer Dabbelt , schwab@linux-m68k.org Cc: alexghiti@rivosinc.com, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, Paul Walmsley , aou@eecs.berkeley.edu, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org References: From: Alexandre Ghiti In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org On 19/05/2023 23:55, Palmer Dabbelt wrote: > On Fri, 19 May 2023 14:48:59 PDT (-0700), schwab@linux-m68k.org wrote: >> On Mai 19 2023, Alexandre Ghiti wrote: >> >>> I have tested the following patch successfully, can you give it a try >>> while I make sure this is the only place I forgot to add the -fno-pie >>> flag? >>> >>> diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile >>> index fbdccc21418a..153864e4f399 100644 >>> --- a/arch/riscv/kernel/Makefile >>> +++ b/arch/riscv/kernel/Makefile >>> @@ -23,6 +23,10 @@ ifdef CONFIG_FTRACE >>>  CFLAGS_REMOVE_alternative.o = $(CC_FLAGS_FTRACE) >>>  CFLAGS_REMOVE_cpufeature.o = $(CC_FLAGS_FTRACE) >>>  endif >>> +ifdef CONFIG_RELOCATABLE >>> +CFLAGS_alternative.o += -fno-pie >>> +CFLAGS_cpufeature.o += -fno-pie >>> +endif >>>  ifdef CONFIG_KASAN >>>  KASAN_SANITIZE_alternative.o := n >>>  KASAN_SANITIZE_cpufeature.o := n >> >> I can confirm that this fixes the crash. > > Thanks.  Alex: can you send a patch? I don't think this patch alone will work, all the code in early alternatives must be compiled with -fno-pie, but I'm a bit scared that's a "big" constraint. For now, I see 2 solutions: - Document somewhere the fact that anything called from early alternatives must be compiled with -fno-pie - Or relocate once with physical address, call early alternatives, and then do the final virtual relocation Both options can be cumbersome in their own way, if anyone has an opinion, I'd be happy to discuss that :)