From patchwork Mon Jan 30 08:40:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13120504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 108D9C61D97 for ; Mon, 30 Jan 2023 08:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=RkahWO8MVF9pNKoeRvr9sIdzLxm3ZYCw8DnwEDC/sts=; b=wyBybgHhajxpsG WgCsZ1fsXuf53I5A0iP4nb+6Lnb9PEA2oortqLsVNRb1OiLOSfDhS9IP40OnwZWYnLc0aAPfIpV5Y uqm60rzKEIwzm/Yo52divsbhT3NA9HcZ3kARHOPFXcxSj+/nI3Ntg4xSCWoUhY8o8MIFVdpeVQbCn y/KMkPFoi+7qv8uAfAPdXAUmOFSkUZJ3JTtlukVXtuSk/r7QexAWCSQD3QLHQ6IzZuq4tR25X2ZAY JX/mewPuTIUmOfH/qcPT0JZmj5dYrdsk2XVmZFk7UoBkko5eS6Is3ZDG+2mw+0JZeOCYEmkvjDeFg WZKyuh2xntqu7GE8415A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMPjH-002g15-O1; Mon, 30 Jan 2023 08:41:31 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMPi6-002fvk-PR for linux-arm-kernel@lists.infradead.org; Mon, 30 Jan 2023 08:40:20 +0000 Received: by mail-ej1-x634.google.com with SMTP id ud5so29524537ejc.4 for ; Mon, 30 Jan 2023 00:40:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AxIX14/NNJpn+kwI1pQuHb1Ic9IzDxfIhmP5aAWuxiU=; b=SXiIQxbxObyrGGY+xCqVTWXYxnzwfeBg+Ds1QXsGsAGOJRHBCazhcNoYIzzXYAvmoG mAz96A64jCnBQZTVZsK5j1qPy9Vs5JB6+OGlKDxICDX90gZEgCufGjZAP9sKAlZtviCq Nf/NMRq2Hc6XunTcCs6l4nDXmTu5CH9ZfrTy7xVNMr5Zhzg+07w+25dDx2PYWg9Ueaee Piiu3hrVdssYG+TuQuxW/lC2l4nRk+URDclccHUfRdPie+HmksH9YkiLKNX4PyK7uTEq AGyyS2LGSh2neu9Qn4oxjAb++jxfz0WXZxgSn0l3avB4uXNluKPB2bwbT+t7m6NO0un7 WthA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=AxIX14/NNJpn+kwI1pQuHb1Ic9IzDxfIhmP5aAWuxiU=; b=MnI19u3YiyJHbgHNH0rMaykRUD8w6jNTxdASeVrBUh9UbxiMogBHpKRuUn2ZOv7Huo aTlsXaGraYuG2pM6cB4EHMGtuJNpCiFvQCKNx9FZUUqrFXeqy48yScFHc8P+wHhR+oFK Ndjb6RNYRFt4l0rTpyAFQn8MG/0JN0RK+U0ym8/3wFS93dpHItDEh8P01InprFNayrNb GZfbXz0A3e9u5784MmsLvrIul419khp5cuOOscAg+IUpfu4DoL+xnFpAsSvdeAMEP3Bn +rNQHRY22UMhmpJsD17k9RcYbpSlueD9SccPiBd1KdBzJU/zHO/CtVSj9v7Ivy1UO0to hNcA== X-Gm-Message-State: AO0yUKUe0kODNnCaGl1GuHLUrbS2psw01ebKmWlpsZNIfFGMtoG4ednq 6tWXQBrHe8FX9cUsCTJ57e326A== X-Google-Smtp-Source: AK7set9y3i6mDjatO9rOdTYsHn4YvbSUVTRb2UeDRi3koMLOuP7UhuAz2Nf/W/+Hd2a8TNHJXgpBhw== X-Received: by 2002:a17:906:44f:b0:878:8074:713b with SMTP id e15-20020a170906044f00b008788074713bmr13348813eja.53.1675068016290; Mon, 30 Jan 2023 00:40:16 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id p17-20020a170906b21100b00886c1a02d20sm2210638ejz.47.2023.01.30.00.40.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 00:40:15 -0800 (PST) From: Andrew Jones To: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: 'Will Deacon ' , 'Frank Rowand ' , 'Catalin Marinas ' , 'Alexandre Ghiti ' , 'Rob Herring ' Subject: [PATCH] of: Expose __early_init_dt_declare_initrd as a weak function Date: Mon, 30 Jan 2023 09:40:14 +0100 Message-Id: <20230130084014.1024623-1-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230130_004018_855486_61E61FCB X-CRM114-Status: GOOD ( 20.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org __early_init_dt_declare_initrd is provided by OF as a convenience for early setup of initrd_start and initrd_end. This is nice for the large majority of architectures, but arm64 cannot use it, as its early linear map is too limited to be used to translate the addresses. Rather than guarding the translations with !CONFIG_ARM64 in OF code, expose __early_init_dt_declare_initrd as a weak function which architectures may override. Architectures may prepare a mapping in their version of the function or, if they know it's safe to defer the setup until later, they can just provide a stub. Apply this to arm64 immediately in order to remove the !CONFIG_ARM64 check. riscv64 will also use this after modifying its linear map to use larger pages. Note, while this somewhat reverts what commit cdbc848b0341 ("of/fdt: Remove custom __early_init_dt_declare_initrd() implementation") is doing, the weak function approach shouldn't have the rebuild noise that changing CONFIG_BLK_DEV_INITRD was causing before. It is, however, necessary to duplicate the !CONFIG_BLK_DEV_INITRD check which early_init_dt_check_for_initrd() has into the newly exposed function, as the compiler will now treat it independently. Signed-off-by: Andrew Jones --- arch/arm64/kernel/setup.c | 11 +++++++++++ drivers/of/fdt.c | 26 +++++++++++++------------- include/linux/of_fdt.h | 2 ++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 12cfe9d0d3fa..ffdbe6900d8d 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -180,6 +180,17 @@ asmlinkage void __init early_fdt_map(u64 dt_phys) early_fdt_ptr = fixmap_remap_fdt(dt_phys, &fdt_size, PAGE_KERNEL); } +void __init early_init_dt_declare_initrd_arch(unsigned long start, + unsigned long end) +{ + /* + * Using OF's version of this function would cause ARM64 to BUG when + * CONFIG_DEBUG_VM is enabled, since __va() would be called too early. + * initrd_start and initrd_end will be initialized later in + * arm64_memblock_init() + */ +} + static void __init setup_machine_fdt(phys_addr_t dt_phys) { int size; diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index f08b25195ae7..6c555739cf20 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -888,19 +888,19 @@ const void * __init of_flat_dt_match_machine(const void *default_match, return best_data; } -static void __early_init_dt_declare_initrd(unsigned long start, - unsigned long end) +/* + * This may be overridden by architectures which do not have a linear map + * sufficiently setup this early to simply use __va(). + */ +void __init __weak early_init_dt_declare_initrd_arch(unsigned long start, + unsigned long end) { - /* ARM64 would cause a BUG to occur here when CONFIG_DEBUG_VM is - * enabled since __va() is called too early. ARM64 does make use - * of phys_initrd_start/phys_initrd_size so we can skip this - * conversion. - */ - if (!IS_ENABLED(CONFIG_ARM64)) { - initrd_start = (unsigned long)__va(start); - initrd_end = (unsigned long)__va(end); - initrd_below_start_ok = 1; - } + if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD)) + return; + + initrd_start = (unsigned long)__va(start); + initrd_end = (unsigned long)__va(end); + initrd_below_start_ok = 1; } /** @@ -930,7 +930,7 @@ static void __init early_init_dt_check_for_initrd(unsigned long node) if (start > end) return; - __early_init_dt_declare_initrd(start, end); + early_init_dt_declare_initrd_arch(start, end); phys_initrd_start = start; phys_initrd_size = end - start; diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index d69ad5bb1eb1..040ab7e402e0 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -65,6 +65,8 @@ extern int early_init_dt_scan_chosen_stdout(void); extern void early_init_fdt_scan_reserved_mem(void); extern void early_init_fdt_reserve_self(void); extern void early_init_dt_add_memory_arch(u64 base, u64 size); +extern void early_init_dt_declare_initrd_arch(unsigned long start, + unsigned long end); extern u64 dt_mem_next_cell(int s, const __be32 **cellp); /* Early flat tree scan hooks */