From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02132C433DF for ; Tue, 7 Jul 2020 09:11:03 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1E58206DF for ; Tue, 7 Jul 2020 09:11:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Xoy2YFM4"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="gEd0VKTS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1E58206DF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HjfNN9LbzqUCAeSWOqtKgoCS6ceE+5NrFWHuA6UEDcA=; b=Xoy2YFM4CxufAH8vjiYAQFqA4 TfXyQjPNeAZ4qZ6vz2xcLQKzF70cdlK2QuwTDE7WWIF0GeQUUSv/lysgoDfoxmGwhI+mapydlh8Wj q4rBEEQANiIS7UZdyxlWN+bqyP94fEZM1hgDEi97zanRPvAIkxyhfJC0vZPdkFl0gJGzbzJTD3Zir VlF9L6b7ELoO8GmwcLWzimRAcpzE3xE/e5np9he30s6vq37gock1JeFlltIdZgxo+M8d9uNUeUIv9 AbrDJGlveNtAsCfseCAuQItObyW/WHSxKYmhW0KiM968ozGKbnh5dCOnx3DUyAEFA5h8oh7WrAd4k qKJ9gPuJg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsjbH-0006Da-TZ; Tue, 07 Jul 2020 09:09:15 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsjbF-0006DF-Dz for linux-arm-kernel@lists.infradead.org; Tue, 07 Jul 2020 09:09:14 +0000 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 68C0B207BB for ; Tue, 7 Jul 2020 09:09:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594112952; bh=hK5nN8/Wvs1FMwASbOwqFL9C3E3fy5MqSNQBt/shppg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gEd0VKTSapPn7YQidFciomoHNt/RJYeC7sf6vQHUzZpylxxWz6bstCFryh2n6nINR tzzcKcKur/fwNZkmIxrt9yvpssOb/BkngNYCkIIskR+a4Ao5w2qynCmitcRo4Q9PJZ TVLet3fRBnmZIM3ynmFe/izz8xiHoroqWCbLr06M= Received: by mail-oi1-f178.google.com with SMTP id 12so27814872oir.4 for ; Tue, 07 Jul 2020 02:09:12 -0700 (PDT) X-Gm-Message-State: AOAM530cwodC1hwPpMiWlssZqBqrbHVJpCli0pfxjN+XbsL+9kWTs7kC cnu8IuvLdpL35ciJ2zk2dyf4v6A74BbfaP7CzI4= X-Google-Smtp-Source: ABdhPJxsOX9Jy3qrafy7mGlwIGPlyia8dT+UJ6Tu/Cy/ojpSU/osSJQb+NF13/qmIw7OoRsgvtt7ZOWqTwKg47V0+Nk= X-Received: by 2002:aca:5516:: with SMTP id j22mr827405oib.47.1594112951685; Tue, 07 Jul 2020 02:09:11 -0700 (PDT) MIME-Version: 1.0 References: <20200706150205.22053-1-geert+renesas@glider.be> In-Reply-To: From: Ard Biesheuvel Date: Tue, 7 Jul 2020 12:09:00 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH/RFC v7] ARM: boot: Obtain start of physical memory from DTB To: Geert Uytterhoeven X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200707_050913_680333_0828A642 X-CRM114-Status: GOOD ( 40.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Nicolas Pitre , Masahiro Yamada , Lukasz Stelmach , Russell King , Linux-Renesas , Chris Brandt , =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , Eric Miao , Dmitry Osipenko , Linux ARM , Marek Szyprowski Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 7 Jul 2020 at 11:40, Ard Biesheuvel wrote: > > On Tue, 7 Jul 2020 at 11:35, Ard Biesheuvel wrote: > > > > On Tue, 7 Jul 2020 at 10:58, Geert Uytterhoeven wrote: > > > > > > Hi Ard, > > > > > > On Tue, Jul 7, 2020 at 9:45 AM Ard Biesheuvel wrote: > > > > On Tue, 7 Jul 2020 at 10:39, Geert Uytterhoeven wrote: > > > > > On Tue, Jul 7, 2020 at 8:50 AM Ard Biesheuvel wrote: > > > > > > On Mon, 6 Jul 2020 at 18:02, Geert Uytterhoeven wrote: > > > > > > > Currently, the start address of physical memory is obtained by masking > > > > > > > the program counter with a fixed mask of 0xf8000000. This mask value > > > > > > > was chosen as a balance between the requirements of different platforms. > > > > > > > However, this does require that the start address of physical memory is > > > > > > > a multiple of 128 MiB, precluding booting Linux on platforms where this > > > > > > > requirement is not fulfilled. > > > > > > > > > > > > > > Fix this limitation by obtaining the start address from the DTB instead, > > > > > > > if available (either explicitly passed, or appended to the kernel). > > > > > > > Fall back to the traditional method when needed. > > > > > > > > > > > > > > This allows to boot Linux on r7s9210/rza2mevb using the 64 MiB of SDRAM > > > > > > > on the RZA2MEVB sub board, which is located at 0x0C000000 (CS3 space), > > > > > > > i.e. not at a multiple of 128 MiB. > > > > > > > > > > > > > > Suggested-by: Nicolas Pitre > > > > > > > Signed-off-by: Geert Uytterhoeven > > > > > > > Reviewed-by: Nicolas Pitre > > > > > > > Reviewed-by: Ard Biesheuvel > > > > > > > Tested-by: Marek Szyprowski > > > > > > > Tested-by: Dmitry Osipenko > > > > > > > Cc: Lukasz Stelmach > > > > > > > --- > > > > > > > Marked as RFC, because: > > > > > > > 1. This is known to break crashkernel support, as the memory used by > > > > > > > the crashkernel is not marked reserved in DT (yet), > > > > > > > 2. Russell won't apply this for v5.9 anyway, > > > > > > > > > > > > > > > > > > > Would it help if we make this behavior dependent on a simple heuristic, e.g., > > > > > > > > > > > > if (round_up(load_address, 128M) >= dram_end) > > > > > > use dram_start from DT > > > > > > else > > > > > > use round_up(load_address, 128M) > > > > > > > > > > > > That way, the fix is guaranteed to only take effect for systems that > > > > > > cannot even boot otherwise, which fixes the crashkernel case, as well > > > > > > as other potential regressions due to the load address of the core > > > > > > kernel changing for existing boards. > > > > > > > > > > Thanks for your suggestion! > > > > > 1. Shouldn't the calculation use round_down() instead of round_up()? > > > > > 2. Likewise, "round_down(load_address, 128M) < dram_start from DT"? > > > > > > > > > > > > > No. > > > > > > > > What the code does today is round *up* to a multiple of 128 MB, and > > > > only when that leads to a problem, we should use the DT provided > > > > memory regions. > > > > > > mov r4, pc > > > and r4, r4, #0xf8000000 > > > > > > Surely this is rounding down, isn't it? > > > > > > > Yes you are right. > > > > > add r4, r4, #TEXT_OFFSET > > > > > > Followed by adding a small number (typically 0x00008000). > > > > > > On RZA2MEVB with 64 MiB of RAM, the result lies below dram_start. > > > > Yes, but in the general case, this is not true. Platforms that manage > > to boot using the current arrangement will do so by putting the > > decompressor above the first 128 MB aligned boundary covered by DRAM > > (and lose access to any memory below it via the linear mapping, but > > this memory could still be used via a no-map reserved-memory node > > AFAIK.) > > > > > BTW, how to obtain dram_end? From DT again? Do we trust it, as we > > > apparently cannot trust dram_start in some configurations. > > > > > > Do I need more coffee? > > > > > > > Maybe we both do :-) > > > > AIUI, the reason we cannot trust dram_start is because of the > > crashkernel case, i.e., the kernel may have deliberately been put high > > up in memory, and the expectation is that the load address is derived > > by rounding down the load address of the decompressor. > > > > Hence my suggestion to round *up* and compare with dram_end: if > > round_up(load_address, 128M) >= dram_end holds, it is guaranteed that > > no address exists in memory from which we could round down and arrive > > at a valid DRAM address. This would mean that your change will only > > affect platforms that were unable to boot to begin with, and not > > affect any other weird configurations including crashkernels etc > > Uhm maybe not ... > > Time to get that coffee... OK so we know that the memory base should be a 16 MB aligned value >= dram_start. This holds for the crashkernel as well, although in that case, the memory base is much higher than dram_start, and not right above it. So how about if we *only* use the DT dram_start as the memory base if it is aligned to 16 MB, and if rounding down from the load_address produces an address that is below it? That should cover your use case, but very conservatively, reducing the likelihood of regressions. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel