Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp699844rwd; Wed, 31 May 2023 04:20:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CQMQrunifPWZGwghNm8lWOiGyv7OnqxbbQ+kbNKtaZAAPJYIFrdAgKtk6L+g1AXj4DX2K X-Received: by 2002:a6b:490d:0:b0:775:262:5c5d with SMTP id u13-20020a6b490d000000b0077502625c5dmr4441249iob.5.1685532038815; Wed, 31 May 2023 04:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685532038; cv=none; d=google.com; s=arc-20160816; b=hW2jhJrH4BkjeXXw3EpSk9Ioi+Lwy7TXzqfN+6sLXhBwEgob1Jf/BTCLx4VqUSH3r7 7RjSjke4EASAPlWxFxNk2wDPWqWjmbyB5ww69NRU2N7DoSIR++P4mk4foAHi+uaptSRZ F0AT1b1nuHVoU5IO7GDRG4r47tKa/wkpbxQ06B8YVLlrnMn6pDFc1b5nI1Kj0b76BLJq YSQAxuU3ADRw4+tw/iSebEVKkzcMZvHdYvyP5tykTOv2B+rBeR1DaipIs3GLxeplWCcw 4RPePvPxgKaQ0pwPxzNcXJMLd7ISD/LbHhsaaq8/5upabBN804TKDQ0BfGgFil+jonIw QmPg== 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=U3w5hiPZZ1D5j2Tiyd6sO8FaqTUJlhmwjjbS0OGlaUM=; b=o8zlbE3DyQW1PCcQpmpz6LJ9S7ilHh+wlW2YjS2haxsBxR5+UjTyPBYwH+sEfyWIS7 m5phChqPZjtGlKY3+CYkpAuGz81s3AyjE6Zb2B1ZgfwE0jVvyvOGpz4/1ccNJMwpm9I/ G9LPYZn1NF3OFTaVP0jx2UAeEq/YJhY57eyfMKaryHwSU4Jr7IvPgV6q1CnC3p7Ya/qP uHLoYv1G0H9JTAM1f14T7bxwgoxd5PeEhZjOnlWhbSCFmrPAvriFIYRjZ+c3ndmkNyDY gs19SWa6pnut01wjRTj5h74TnhBV5+Kp54fOtKieP2bi47Wss64JVcvPOVRdpnV0xr8C zKMA== 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 o18-20020a637312000000b005304a8af2a2si825992pgc.404.2023.05.31.04.20.27; Wed, 31 May 2023 04:20:38 -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 S234678AbjEaLEC (ORCPT + 99 others); Wed, 31 May 2023 07:04:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235358AbjEaLDq (ORCPT ); Wed, 31 May 2023 07:03:46 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D27A5E4B for ; Wed, 31 May 2023 04:03:30 -0700 (PDT) X-GND-Sasl: alex@ghiti.fr X-GND-Sasl: alex@ghiti.fr X-GND-Sasl: alex@ghiti.fr X-GND-Sasl: alex@ghiti.fr X-GND-Sasl: alex@ghiti.fr X-GND-Sasl: alex@ghiti.fr X-GND-Sasl: alex@ghiti.fr X-GND-Sasl: alex@ghiti.fr X-GND-Sasl: alex@ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id 9E54DC0006; Wed, 31 May 2023 11:03:26 +0000 (UTC) Message-ID: <9a94446d-bc6c-6272-8101-d1adeec3d672@ghiti.fr> Date: Wed, 31 May 2023 13:03:26 +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 -fixes] riscv: Fix relocatable kernels with early alternatives using -fno-pie Content-Language: en-US To: Conor Dooley Cc: Alexandre Ghiti , Conor Dooley , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andreas Schwab , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20230528-uneatable-earpiece-3f8673548863@spud> <20230529-skillet-quarters-3fbc3b6edb3a@spud> <41e57bb9-ce0c-7772-abeb-5c01d5ec19bb@ghiti.fr> <20230530-polka-trifle-7ccd7a093099@wendy> <92d4aaa8-a1ed-74e1-3a22-df9be1ca1e4a@ghiti.fr> <20230530-hatchery-unifier-64d7a2ffe0d0@spud> <20230530-atrocious-control-bcb37de558fc@spud> <0068add0-8949-11b7-a864-2ef8bed00809@ghiti.fr> <20230531-staff-pampers-0250f7f6026a@spud> From: Alexandre Ghiti In-Reply-To: <20230531-staff-pampers-0250f7f6026a@spud> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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, URIBL_BLOCKED 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 31/05/2023 11:32, Conor Dooley wrote: > On Wed, May 31, 2023 at 09:26:27AM +0200, Alexandre Ghiti wrote: >> On 30/05/2023 22:22, Conor Dooley wrote: >>> On Tue, May 30, 2023 at 08:04:17PM +0200, Alexandre Ghiti wrote: >>>> Ahah, I think we found the culprit! >>>> >>>> With CONFIG_RELOCATABLE, vmlinux is actually stripped from all the >>>> relocations (so that it can be shipped) and vmlinux.relocs is what you >>>> should use instead, since it is just a copy of vmlinux before the >>>> removal of the relocations! >>> That probably makes us both eejits for not realising sooner... >> Ahah, TIL a new word, thanks :) >> >>> Tested-by: Conor Dooley # booted on nezha & unmatched >>> >>> Thanks for your patience here Alex. >> So I checked again if the -fno-pie should be applied to mm/dma-noncoherent.c >> as I suggested, but actually no: errata/thead/errata.c never reaches >> riscv_noncoherent_supported() in early boot (you can see how 'fragile' it is >> though and why something needs to be done...). > I did make sure to check this patch itself, without the additional bit, > to see if it was needed. > But yeah, it is going to be super fragile - do you have any ideas about > how to circumvent that? Yes, I was thinking about multiple solutions: - All the early code could go into kernel/pi: all the dependencies of the early code is built in its own way (the symbols are actually 'duplicated'). I see that a bit like the EFI stub. My first try failed with !CONFIG_RELOCATABLE, I have to dig further. - Simply do a physical relocation before any early code, execute the early code, and then do the virtual relocation. But that does not solve the issue fixed by kernel/pi which allows to recompile standard functions (like the string ones) without any instrumentation and have the versions with the instrumentation for normal execution. - Compile relocatable kernels without -fPIE (why can't we just use medany actually?). That won't fix certain types of situations where we need relocations, but that will limit the number of outliers that need to be compiled with -fno-pie and it will be easier to spot (we'll still have to be very careful though) - Be very strict about what can/cannot be done in this pre-mmu stage, and document that... The best solution would be the first I guess. Any other ideas welcome :) > >> Oh and I realized that I forgot the Reported-by from Andreas and the Fixes >> tags, so here they are: >> >> Fixes: 39b33072941f ("riscv: Introduce CONFIG_RELOCATABLE") >> Reported-by: Andreas Schwab >> >> >> Thank you too for your patience and your quick answers! >> >> Alex >> >> >>> _______________________________________________ >>> linux-riscv mailing list >>> linux-riscv@lists.infradead.org >>> http://lists.infradead.org/mailman/listinfo/linux-riscv