Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp148723pxk; Wed, 9 Sep 2020 01:18:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMZXcyPgyZDMHP0UbMs56lYuXhMvY8OCdh5rt7a1H/xXGj6Ga4qWUtEBFTUOQi/JfxrGum X-Received: by 2002:a17:907:72c5:: with SMTP id du5mr2587608ejc.469.1599639519748; Wed, 09 Sep 2020 01:18:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599639519; cv=none; d=google.com; s=arc-20160816; b=UeDvsXcO2KFxj45nZ2zZCgDimiYgd3etVRUFAp2JcUZ88odrOfxMzCJX6h508OhfUX 1vc25oDFwPuB8sPTC7DScSNUKxLyLuNbukYEXyK+gEcK+xA0VozDHsZrOseE9eHoi5HU 3T4xFRivb5lVHVktdnH9XY2hqGeATF8t5O2q8Kjx8Xfe0V/GlC/mLDFaUWSz3Sjk1Yf/ 0+TQm3V1XpUTUui/KN3FgVPi326tkKHHCPKJI5RoIREPuxr0usTjFklc/8mTX4xhT5Nl icu0k37xtzMhj8a1oiEMzJu6QpUn5/9ps+mPrOuKbJ+WnxPCWgSuEZUkh19jxXmdQDwK NtQA== 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=/3sdzpyiFKFeveSbF5RoIwUqJ+Q2OF2qnBuEmu/3ud0=; b=RkudAwoesPMdJDJPjcLCWe5R23iIi4AhRK6JzFFM0RTP62bJVQ+QGDt9yqXtTBiU3d +Wgv1wchoHc2MfLQGVPQoUZK/RYtj+ZOI5Eu9zLNUQmtoQqZ+g1fGGfoQCmAeEl3O1q/ 4uUq4KYiDTqCBUwGEHHRMluSwl04I0Ti6ie/xxc+lu9ijw3678BzEw2bBZ7JJ32+x36i kVFO2oI6YDhlsq2boHHyqDrHT0WdgC63OFLwDl4TFwOCW6GQ7tWkZoc0/aLCHVXDN3aK zA1EDkAZgrKCjLhX5lHdDF5p9RPmirfATy+f6HNVvVB1MBQ9wPoSjKRfAixxW71Sf0nt cDLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="r+wC/3pa"; 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 u6si1081220ejf.115.2020.09.09.01.18.16; Wed, 09 Sep 2020 01:18:39 -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="r+wC/3pa"; 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 S1728405AbgIIIRo (ORCPT + 99 others); Wed, 9 Sep 2020 04:17:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:56816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbgIIIRo (ORCPT ); Wed, 9 Sep 2020 04:17:44 -0400 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 7EA10208FE; Wed, 9 Sep 2020 08:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599639463; bh=4+g46RsugZchnLXhayE48WIwyLhN70ak3YgT2AhHBMk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=r+wC/3pap46RbU4I1s15WbdBrJ7m6iWmMXIyo1a51QLfC3BAeQ+ncAE3VdMQMBOs2 fGTcyDD8CFit7CeYkzEvd/NeQrCTZM7DHb2G1IHUMbWqhpOBdSFvE7bzsgP3ywyAvD 19ltaLgVLzHvLgPuqiOt5Nrie4e+VjT66meIEe1Y= Received: by mail-ot1-f45.google.com with SMTP id w25so352387otk.8; Wed, 09 Sep 2020 01:17:43 -0700 (PDT) X-Gm-Message-State: AOAM530Z9nZAqZ80khNsW3ZudmxeGYULT3l9u+kevWnb/t6DkYhrRRRL /58KEyawG3R3+J9u1rZwaaYt+Xmhxx67+PqugfY= X-Received: by 2002:a9d:69c9:: with SMTP id v9mr2060217oto.90.1599639462827; Wed, 09 Sep 2020 01:17:42 -0700 (PDT) MIME-Version: 1.0 References: <20200904155025.55718-1-xypron.glpk@gmx.de> In-Reply-To: <20200904155025.55718-1-xypron.glpk@gmx.de> From: Ard Biesheuvel Date: Wed, 9 Sep 2020 11:17:32 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/1] efi/libstub: DRAM base calculation To: Heinrich Schuchardt , Atish Patra , Palmer Dabbelt Cc: Ingo Molnar , Arvind Sankar , linux-efi , Linux Kernel Mailing List , Maxim Uvarov , Jens Wiklander 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 (+ 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. 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.