Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1650635iob; Fri, 29 Apr 2022 09:43:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcFN9CgeioRmLNiPDmoVakdJ+IXzpzIwvrFXoENSbCCbbRnY2N/0mxkkBec2VO7O1GpnG9 X-Received: by 2002:a63:5d60:0:b0:3a9:ef9f:eac2 with SMTP id o32-20020a635d60000000b003a9ef9feac2mr191840pgm.553.1651250627625; Fri, 29 Apr 2022 09:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651250627; cv=none; d=google.com; s=arc-20160816; b=ytrncgmYo0RA6x5F96aJ1HUsIeLKEzKcHI8+fOwhaVysoM/sDlrKQXXCoXqzl/u3yw m5HkFSwIVjG5ftv8JqofkASmXPHBOgmmDobrcepluwLWnFkkDtC6QHYX5c5gfOLggIIZ EAPufypk2yEfm5pXdxgVdbCRy22ZJb8fAauBNzI13l7ByFvTXeOOTRmtfdcdDe2Hn1ty JBvIC0Gll6zw32a1a/Cv8AY1xkH4B5Tji6uOjSsZANMcrmJCF1NylU5EXNFnIy+5Lp99 1MQl1zaD+2Ogbzu7yI7vrEiHuE6Zocjp0sYo7GRBTjJ3gUX5FgptJmbt58NUJLhwAlra qaHA== 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:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=sLdFSM+gbbluSAusN2hlLl8hXUCFXq74MUxOmPI7lC0=; b=h3oqmuUOBnSnjUnGhAPEex3vD2Qw8sv7KlGwNPgvPkbzB3uqK0zXxZDsmvBSZDzHDg GWljUw0Cs9oHtDOZWtpm+4BLuM9PN5ZHWMOv6/nn1G1Wuc8qWexX00uBtRG0DGy6uxC6 E4ceAK9Jpg0h9l1+UQWCRC3DiG81xYUqDooOXWP96E5Ur7wNGBkl/FrWXk6ANQ9Ghp6B WZplFpMT+e9abnQOp6Ct34TxuTuiK+QPkP1TXoYS1ibrFq2roXF/lnHXkhv+LKpT+2bP 3v2A3xCMr7pZmq9s1WMBpsN2Hh+tBz+SgjxhCtchNRo8JGAMyxlacx1vvlbtWKIFHB89 iM4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20210112.gappssmtp.com header.s=20210112 header.b=3c5J22p4; 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 c1-20020a056a000ac100b004fb5d3f2495si8172461pfl.274.2022.04.29.09.43.31; Fri, 29 Apr 2022 09:43:47 -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=@dabbelt-com.20210112.gappssmtp.com header.s=20210112 header.b=3c5J22p4; 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 S1352412AbiD1Vvc (ORCPT + 99 others); Thu, 28 Apr 2022 17:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232756AbiD1Vvb (ORCPT ); Thu, 28 Apr 2022 17:51:31 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F330BB0A8 for ; Thu, 28 Apr 2022 14:48:16 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id w17-20020a17090a529100b001db302efed6so4079023pjh.4 for ; Thu, 28 Apr 2022 14:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=sLdFSM+gbbluSAusN2hlLl8hXUCFXq74MUxOmPI7lC0=; b=3c5J22p40msR1l4Xh1SUIN5QgolDrzxQVQG2JpLcEVDr9mNIJeAISUgdjeEfg1sJyi YL/8puFtsiANQ6jN74xg+Hp1RLFxl41WZ4wGvwETlk7A9r9pIpLJtq81CEkMEHo7ir6z PD4U3xSe9A0v4VdHDz/bVNlrA9NFKHBTQ7VXgy1HMVYmy68DRh1qk4rvKvHw50zqPRYQ NC/YJg+JCBA9uUTBlqOD9WqfZOEUAXg6Li01tkS+2A2TyMECJ/bcbRDjCwInb+27Yq1z gdmycesrmfxSR74zLeak0/mshq8XIL8hVLVMqH0zosqpFmlxRdeTyXenBQqp3mUCd+WW xkSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=sLdFSM+gbbluSAusN2hlLl8hXUCFXq74MUxOmPI7lC0=; b=7t3dFYhC6uluRLUzWaDNfOOys9hJz9qb/zic/LG9ZePxe6WLEqOUkHUq1jea53wBW+ hk00kNp+PQ02FhEMRmi0rU8XinlnqFzqgFT28CyioU5rvImp4aKjyq0gpYz5tiO6bQmH cwph4rAhMqHp4Bj97r3RHIhF2nXMLc1vqV8HqFvcdEv0oYlyc9KTx40xy2OAzxxrcHj7 9yg2M66KB5VAgc0ztk1DBCIO/9qZOKR4MRBkpc4o6GdKtkAhOsm847COwD+op90ft/73 68poZh9XB+WR+hwMauFMKv+y5I4iIQhrvcu6hRmuu2B618zptwA57lOoMqf7JstIgH0F z3vw== X-Gm-Message-State: AOAM530f57lm/03OMJdY1g9uDmFX3mYH8eTHVhhj8R9/7292fLPNX1wm nOWB/VmZrtkOI6GuUnqV/XQERg== X-Received: by 2002:a17:90b:4b4f:b0:1db:d2ac:8f8c with SMTP id mi15-20020a17090b4b4f00b001dbd2ac8f8cmr306376pjb.237.1651182495382; Thu, 28 Apr 2022 14:48:15 -0700 (PDT) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id l22-20020a17090a071600b001d9781de67fsm7631976pjl.31.2022.04.28.14.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 14:48:14 -0700 (PDT) Date: Thu, 28 Apr 2022 14:48:14 -0700 (PDT) X-Google-Original-Date: Thu, 28 Apr 2022 14:48:01 PDT (-0700) Subject: Re: [PATCH] RISC-V-fixes: relocate DTB if it's outside memory region In-Reply-To: <8491e0c3-3e6e-325e-0cc1-5b237ce4f9fd@ics.forth.gr> CC: Paul Walmsley , aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org From: Palmer Dabbelt To: mick@ics.forth.gr Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 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 Mon, 25 Apr 2022 23:11:23 PDT (-0700), mick@ics.forth.gr wrote: > Hello Palmer, > > Any updates on this ? Sorry about that, it's on fixes. > > Regards, > Nick > > On 3/22/22 15:28, Nick Kossifidis wrote: >> In case the DTB provided by the bootloader/BootROM is before the kernel >> image or outside /memory, we won't be able to access it through the >> linear mapping, and get a segfault on setup_arch(). Currently OpenSBI >> relocates DTB but that's not always the case (e.g. if FW_JUMP_FDT_ADDR >> is not specified), and it's also not the most portable approach since >> the default FW_JUMP_FDT_ADDR of the generic platform relocates the DTB >> at a specific offset that may not be available. To avoid this situation >> copy DTB so that it's visible through the linear mapping. >> >> Signed-off-by: Nick Kossifidis >> --- >> arch/riscv/mm/init.c | 21 +++++++++++++++++++-- >> 1 file changed, 19 insertions(+), 2 deletions(-) >> >> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c >> index 0d588032d..697a9aed4 100644 >> --- a/arch/riscv/mm/init.c >> +++ b/arch/riscv/mm/init.c >> @@ -206,8 +206,25 @@ static void __init setup_bootmem(void) >> * early_init_fdt_reserve_self() since __pa() does >> * not work for DTB pointers that are fixmap addresses >> */ >> - if (!IS_ENABLED(CONFIG_BUILTIN_DTB)) >> - memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va)); >> + if (!IS_ENABLED(CONFIG_BUILTIN_DTB)) { >> + /* >> + * In case the DTB is not located in a memory region we won't >> + * be able to locate it later on via the linear mapping and >> + * get a segfault when accessing it via __va(dtb_early_pa). >> + * To avoid this situation copy DTB to a memory region. >> + * Note that memblock_phys_alloc will also reserve DTB region. >> + */ >> + if (!memblock_is_memory(dtb_early_pa)) { >> + size_t fdt_size = fdt_totalsize(dtb_early_va); >> + phys_addr_t new_dtb_early_pa = memblock_phys_alloc(fdt_size, PAGE_SIZE); >> + void *new_dtb_early_va = early_memremap(new_dtb_early_pa, fdt_size); >> + >> + memcpy(new_dtb_early_va, dtb_early_va, fdt_size); >> + early_memunmap(new_dtb_early_va, fdt_size); >> + _dtb_early_pa = new_dtb_early_pa; >> + } else >> + memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va)); >> + } >> >> early_init_fdt_scan_reserved_mem(); >> dma_contiguous_reserve(dma32_phys_limit);