Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp220603pxk; Wed, 9 Sep 2020 03:48:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytetM6S+x1nFiAOgCyp8sv9KxNGkLi2tCrmaGFgHqTbi4y70mvLndir3sfyjmeFCm15YdW X-Received: by 2002:a50:d54b:: with SMTP id f11mr3381779edj.329.1599648505054; Wed, 09 Sep 2020 03:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599648505; cv=none; d=google.com; s=arc-20160816; b=yMbZVEW3t5G5+/QodwiFAlz/pf+uSnzy4ArzaKb3z7fOdENqy9TT+1sr7o7RUD2Cs5 jc2NfN1e12TgkRZhNblLz+Z7jKQlmFpnfv4rG31W/oxHTjSLvZuISa2I3PE/UdWXEVYg RR1xQf5g/OKIdKqRgAlRm6gKCckl5E/KBOYa0HD4Q4ETHJYjWxYdqPUU5Eh7ezV8fMMc AyUT4iRz4qWCsd1AkQ+sGmrLP0v6xQEVk+SYMndkks5QtbWpxe4JeVyb6c+86UqFpLT1 A91Je7krM/exKyddOA7wvpC+XDx18R3oSOb259XVBnCQQpL7azvW7NlaqgLXNbD3RqzK AXGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=l+U84G5cNSm+7Emkbmc3fGQmFjGXnieH5akfdR41ISw=; b=rWgSKINPczSLeA0MyfkLXMB8bckS4H9e2/7xgNSfoX95rydTdJHhQlu/v8cndeKOP+ +fmPhd1kMkMzHgfJ6o4+WomC+QNNUw0YsG3F21cfUdfzRSiCmyWH72bVamuE5fokGyLH F0WAtoL2FlmbPi7+40NeN0Ud7CVwfb1sQQsqT4k7A1TtWOHDh6pO8H5l20sH+2qaS+gu lWzMGfFN3fWRvQXdtSTqG1+J8XtQELr1Iw+rV3wJErkAmajI1pm6xUrd13fzAiToz0yT 8uJUmBOVdZi3e5T2QJ2jqnq3oUzolG2C7819r6V6RYAV9/d19fnJfMEKA9Q8XZu48N0Y KATQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hNmRQCeE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si1272581ejf.115.2020.09.09.03.48.01; Wed, 09 Sep 2020 03:48:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hNmRQCeE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727087AbgIIKrN (ORCPT + 99 others); Wed, 9 Sep 2020 06:47:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:41920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbgIIKrM (ORCPT ); Wed, 9 Sep 2020 06:47:12 -0400 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (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 2DB6621D7E; Wed, 9 Sep 2020 10:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599648431; bh=emLvqtcXwI/FQKrrePSjfuOAtAPtdcDmo8afGVbB6ro=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hNmRQCeEcYxGhMv2gn4pigC3Yy87hMLyawGznCEhRgmeELxf8H6ldxzQUrw1Q+D3M soJWLpSokDrv1LLORbRJiFwigjwFP+etzgMJ0ctHNmqcMmSHNSusM/ZNzzgRZRg51x jQ/5Nxxp1iK0H3mUJDXHRkaL5e3kjQueJFDHJei4= Received: by mail-ot1-f46.google.com with SMTP id 37so1888411oto.4; Wed, 09 Sep 2020 03:47:11 -0700 (PDT) X-Gm-Message-State: AOAM530vBLunRrxF/uYKyMhEIQ+kvs8g4XCnqEEEE6TSvLWvVbz//rFp /Wn+/XSPJOgAEnecldhc+mwuPxn5qdOfWXqVWlY= X-Received: by 2002:a9d:6250:: with SMTP id i16mr274599otk.77.1599648430374; Wed, 09 Sep 2020 03:47:10 -0700 (PDT) MIME-Version: 1.0 References: <20200904155025.55718-1-xypron.glpk@gmx.de> In-Reply-To: From: Ard Biesheuvel Date: Wed, 9 Sep 2020 13:46:59 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/1] efi/libstub: DRAM base calculation To: Maxim Uvarov Cc: Heinrich Schuchardt , Atish Patra , Palmer Dabbelt , Ingo Molnar , Arvind Sankar , linux-efi , Linux Kernel Mailing List , Jens Wiklander , =?UTF-8?Q?Fran=C3=A7ois_Ozog?= Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 9 Sep 2020 at 13:44, Maxim Uvarov wrote: > > On Wed, 9 Sep 2020 at 11:17, Ard Biesheuvel wrote: > > > > (+ Atish, Palmer) > > > > On Fri, 4 Sep 2020 at 18:50, Heinrich Schuchardt wrote: > > > > > > In the memory map the regions with the lowest addresses may be of type > > > EFI_RESERVED_TYPE. The reserved areas may be discontinuous relative to the > > > rest of the memory. So for calculating the maximum loading address for the > > > device tree and the initial ramdisk image these reserved areas should not > > > be taken into account. > > > > > > Signed-off-by: Heinrich Schuchardt > > > --- > > > drivers/firmware/efi/libstub/efi-stub.c | 3 ++- > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c > > > index c2484bf75c5d..13058ac75765 100644 > > > --- a/drivers/firmware/efi/libstub/efi-stub.c > > > +++ b/drivers/firmware/efi/libstub/efi-stub.c > > > @@ -106,7 +106,8 @@ static unsigned long get_dram_base(void) > > > map.map_end = map.map + map_size; > > > > > > for_each_efi_memory_desc_in_map(&map, md) { > > > - if (md->attribute & EFI_MEMORY_WB) { > > > + if (md->attribute & EFI_MEMORY_WB && > > > + md->type != EFI_RESERVED_TYPE) { > > > if (membase > md->phys_addr) > > > membase = md->phys_addr; > > > } > > > -- > > > 2.28.0 > > > > > > > This is not the right fix - on RPi2, for instance, which has some > > reserved memory at the base of DRAM, this change will result in the > > first 16 MB of memory to be wasted. > > > In the EFI memmap provided to the kernel efi stub it will be 2 > regions. First is EFI_RESERVED and second is EFI_CONVENTIONAL_MEMORY. > Even if they follow each other. > And for_each_efi_memory_desc_in_map will just return the second one. > Do not see where the problem is here. > The base of DRAM will no longer start at a 16 MB aligned address on RPi, and so it will round up to the next 16 MB, wasting the space in between. > > What I would prefer to do is get rid of get_dram_base() entirely - > > arm64 does not use its return value in the first place, and for ARM, > > the only reason we need it is so that we can place the uncompressed > > kernel image as low in memory as possible, and there are probably > > better ways to do that. RISC-V just started using it too, but only > > passes it from handle_kernel_image() to efi_relocate_kernel(), and > > afaict, passing 0x0 there instead would not cause any problems. > > For prior 5.8 kernels there was limitation for maximum address to > unpack the kernel. As I understand that was copy-pasted from x86 code, > and now is missing in 5.9. What code are you referring to here? > That is why the suggestion was to point > dram_base to the region where it's possible to allocate. I.e. I assume > that > patch was created not to the latest kernel. Removing the upper > allocation limit should work here. > As I pointed out, this will regress other platforms.