From patchwork Fri May 26 15:46:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 99563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp590664vqr; Fri, 26 May 2023 09:10:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lY2cPN2IC+gQ8nyCGKN30HInWoFDHSdrQbsLi5SlDMqXzxZokHE24RfqOc3Ra9e+AuqvK X-Received: by 2002:a17:903:41c3:b0:1ae:4a0b:5957 with SMTP id u3-20020a17090341c300b001ae4a0b5957mr3641221ple.54.1685117452484; Fri, 26 May 2023 09:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685117452; cv=none; d=google.com; s=arc-20160816; b=iBYWfeCwvTvTfLs8XgjI1lchoV3CRdP3cE9jDY3yrnodCiFzNeuu5yoTAacwj3AChk baCYF6B2b7+6N5wtWgi1lzL0eeTtNm9Zcz1wLePzkDwMSm6FtQ6Y23Jp9G6Lwa453H2f jgRiKGsXIWLEPc+lwIoWUA2JI2yQNUYHKsXebD0XP7+oj6SghuyjEbGtqscvmBC0LO58 u5cc3+2jlsDemuSZUAirtIDBFUOwAPHr1EDt8NwOTWDeuccuvWgt9FekOBBxn4TnJ/DF zJfpF3uYYRta2kIFoaT2y9tCzmBECVd15+hbP7QK2ahgLoFZnH3mSLPJnbiRYHxLFIqT DDkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3GWh9UDKye2M20srh+R8Vryxrum2NkiwrFA9635wntA=; b=ICV9wToiiiPCcUjtY9nUQKUSaYSRGQRxEDdHGjqHNJ/oR/JLyhhMossDlHQ742L6Fg D4QjOf51ANDIMykV6joQObxi3JU8eF9wBAcpuPhf/AI8rKjTDBMoWG9zBnSu8ihhS8Ba dHcHRIRfB6Iu3TvjUgaPAdMCtTd/TltwclLNbyP2JdL3DtaiIr1gXwS4eq2Nn1kCF7A1 kg+tcJ0ykgeE5U4Ia7dVb9eAE9o3UPbWSlqRNx/aRbiQspHhAYljGrgDsfFgfWcWayat Cdnv36O8L7cczpac54Vb7AEZXw0IPoMZAq2Fg8SsPYFdQK7LBkrbW1UbRPtHlKDHhOcH CPnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=mAnILZNn; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ja17-20020a170902efd100b001a9581fe4b6si3703325plb.653.2023.05.26.09.10.37; Fri, 26 May 2023 09:10:52 -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; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=mAnILZNn; 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 S237496AbjEZPqn (ORCPT + 99 others); Fri, 26 May 2023 11:46:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236978AbjEZPql (ORCPT ); Fri, 26 May 2023 11:46:41 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8FCD119 for ; Fri, 26 May 2023 08:46:35 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f603d4bc5bso10091545e9.3 for ; Fri, 26 May 2023 08:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1685115994; x=1687707994; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3GWh9UDKye2M20srh+R8Vryxrum2NkiwrFA9635wntA=; b=mAnILZNnk/4CYo5pVG/iS9vkO1SnDeZwD3+xRXH7NanqhZoZeSn8FMqcBtzJa+Hi/t G3Y9tZzZSSCZG0Q5rnyuc3pFJgdNCFFQaxZe9O84iYBuGfDwIM05oLvxa2byTdLYn50n 8CJY85sep/QmwfdU67veyl4OfaBn2sNIwLEezvBypEiboJ0zoOM5VulhN7SNd8GhS3BT 5kEe3M8tWLz5VysifPEsu7Im0BUycU+q0J/6alQywOUuyWNIWatLD+3c3ymh2ILWkWWD kINojqleKsckPtypyHuNZF86nn5ouDQumSUmuKOHKPMMAPQCjdheF2PNSsyZRjJY4WTu qD2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685115994; x=1687707994; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3GWh9UDKye2M20srh+R8Vryxrum2NkiwrFA9635wntA=; b=H+3EY5Xx4X7IfGWws33WIAly9ObIDreIky6IfCRmV+NlfzDLhVc5wKOlMp42LN/8uQ 4pbzXX/obmttdA3gCbKzbokAC6n4t6K9YGCYCxZtsZdKYAg+fjgzlD3OvzJWuB2E+t6t VXSLxSNSaR+yVVLnRBSft0Vvhl6LfgpOqMPiWVMaj8qWA/fTyRLFxx/XYvwkslCU+ojH N4DBp4YUZnjXb276n/MQnQfYVMmITwDhxs5MX2LntxyVDxlg5//RViVK2x4iKRZobwCT u2fNbne0euqvxAew6x50e262XEEKduCmtjfaY3ZrY7MXsa3pTKc8n6FC016TNSF0CHM5 XaAw== X-Gm-Message-State: AC+VfDx10p8HdHtE6DN35W8Ffv68k8FEqf/aOuYlyDwRewMpLqgI33Et gUs6V91vb1j6WfGI1+bGky1wXw== X-Received: by 2002:a05:600c:2197:b0:3f6:787:5e53 with SMTP id e23-20020a05600c219700b003f607875e53mr1969948wme.20.1685115994303; Fri, 26 May 2023 08:46:34 -0700 (PDT) Received: from localhost.localdomain (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id f10-20020a7bc8ca000000b003f42ceb3bf4sm5562995wml.32.2023.05.26.08.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 08:46:34 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andreas Schwab , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH -fixes] riscv: Fix relocatable kernels with early alternatives using -fno-pie Date: Fri, 26 May 2023 17:46:30 +0200 Message-Id: <20230526154630.289374-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766973718105467268?= X-GMAIL-MSGID: =?utf-8?q?1766973718105467268?= Early alternatives are called with the mmu disabled, and then should not access any global symbols through the GOT since it requires relocations, relocations that we do before but *virtually*. So only use medany code model for this early code. Signed-off-by: Alexandre Ghiti Tested-by: Conor Dooley # booted on nezha & unmatched Reported-by: Andreas Schwab --- Note that I'm not very happy with this fix, I think we need to put more effort into "harmonizing" this very early code (ie before the mmu is enabled) as it is spread between different locations and compiled differently. I'll work on that later, but for now, this fix does what is needed to work (from my testing at least). Any Tested-by on the Unmatched and T-head boards is welcome! arch/riscv/errata/Makefile | 4 ++++ arch/riscv/kernel/Makefile | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/arch/riscv/errata/Makefile b/arch/riscv/errata/Makefile index a1055965fbee..7b2637c8c332 100644 --- a/arch/riscv/errata/Makefile +++ b/arch/riscv/errata/Makefile @@ -1,2 +1,6 @@ +ifdef CONFIG_RELOCATABLE +KBUILD_CFLAGS += -fno-pie +endif + obj-$(CONFIG_ERRATA_SIFIVE) += sifive/ obj-$(CONFIG_ERRATA_THEAD) += thead/ 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