Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp219065pxk; Wed, 9 Sep 2020 03:45:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz40rW6K2kHpC9ozP/vAT4g/YUSkIGyqZz7lNmv0LO1C8agM9TH5vPMjTgyNkB65d+gXAR7 X-Received: by 2002:a17:906:7cb:: with SMTP id m11mr3065083ejc.41.1599648321721; Wed, 09 Sep 2020 03:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599648321; cv=none; d=google.com; s=arc-20160816; b=EnKpK0cLqnY0T9FlkfP+nrAIlkjauUFkPueBl9k6raf1NlmFb2b+i5k0RY+IdYBFJJ oR8UJhV6rRNS8wwnpeYwMFu6+tCGS1Qehs23ZhSPma/ac/Jo7oYJgyijsrHmIQvu5AXF Y+CDy3IvHX9L/3JUYLVgoZKqLkdTr9h9Ai+PnaevtyCT+IcIlzs5douUmYXXvImKaXkf qFp78xYzWlG6HOd7E59TSc7dzhIuDOCeopMyue79FSR14dA0rrrz23wyzAL7OK2bwK/a uXWwsSzv6iXsp1rI3tVTPiCrkuRYAyy1mFyt9hCdwvGZgUM1MB5cXyrW9SLsqIqSR/Dw 9duw== 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=A0Fsk6Jnv3MENMkT7rSPlLPNZLuDbdUcu1ivYDd9EO0=; b=L4Uos4/OTMGIM8FAtde2flLT5P7a4D95fdGmCTYfyZEkaM1er3HEQ5hSCQVo2zxMNZ Qui4Y6Wd2TQ5GZAMh5cxQLCNvYDh3SWa+o6nTUDHlkJ1QAtPYw+akr9+Tto7wc3iP1W6 I7T6CxUDmcjRsh4MVtzFzBhnYGtAzkl/pLDc4j26oFaG0M3Yk2bEb8aQ6NUw6pE3/M0b WS60cBTE0GWKThuygYx8PQf1ExNZb2bFoqwOKR/3+9wQiccaJ2rVPcfWO4WskiqBmL1H 7nE3ckz4CVktaNW1AXBW/+YAPALn7HulrG3tnZhFccfxogN6UwjueeZsM4RLP4X4A+k4 STeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vhes60Wk; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si1241405ejo.88.2020.09.09.03.44.59; Wed, 09 Sep 2020 03:45:21 -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=@linaro.org header.s=google header.b=vhes60Wk; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727087AbgIIKoC (ORCPT + 99 others); Wed, 9 Sep 2020 06:44:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726535AbgIIKn7 (ORCPT ); Wed, 9 Sep 2020 06:43:59 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F202C061573 for ; Wed, 9 Sep 2020 03:43:59 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id z19so1786505pfn.8 for ; Wed, 09 Sep 2020 03:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=A0Fsk6Jnv3MENMkT7rSPlLPNZLuDbdUcu1ivYDd9EO0=; b=vhes60Wkr9Kt3qUeQbVH8RN+X5EzMn0QmaJddT0jEaWXocVnHucaji2O2s5Oh9f/23 uVSYg3RVfFqRgz36/BQJmkdCyVZ3jA5AjPUbuFRl1oaQ5p8gRzioL629EXrriaZ6/Ofh zpaBYpN5wQDVWmBR3/u5ii5mmvxUUBSAg4ecgai43reuH9v1IKq/8qctGrpAavVAxjFl s6Tyi49bYt0sNubyHnHVYgBMVPygeP39h43tzKoTZosMrNTyHU5dX7sqyCHognLlXJIR cIg4NIoqI/Jo+o7JzE65jTPSSsgnPgEEZsQ1MxpfCG+LFfl7qHKFD1zxyVd8siqNhgyz Ispg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A0Fsk6Jnv3MENMkT7rSPlLPNZLuDbdUcu1ivYDd9EO0=; b=jZSrNEZrOerCuZVtqY1s+5vh0+u0gaUZTKChaS7fPWC0YUDMkweZF4HqVXKFjqLhNU 31/2WG8BasKStJt9dwnD175X3a57ryGV8vhrPoqoTvqDQzojNjvARGRqaiZbCCUswy67 ISGvXVVYseOhliAZ0qlWtmxKTsBZ+7nGjfYXuABqiFfLvPJauUJWcCC5o7O/gp2xKJ6B lBblTX6jhIOpJgccvi6VAIpGT7gjBeAgJgjbO8hmP2oleXCuRzfoWNBJaXri0Hm/KfKn ZFQuLdl1fID0ZTZCGahMkk2wBXaV1f6NR1qv8QJs5t5m6p+t9IczwVdQqmYV01FCUm08 vQDw== X-Gm-Message-State: AOAM53230CPGpHHuc/m5km0Kfsh4L3pJ8SIDT9HBUtoXCtB0ivSQTfir d9LWvNWvX8+f3VL6OGIOlfzWc99ymoRZUAruuFsesg== X-Received: by 2002:a62:8349:: with SMTP id h70mr287020pfe.47.1599648239050; Wed, 09 Sep 2020 03:43:59 -0700 (PDT) MIME-Version: 1.0 References: <20200904155025.55718-1-xypron.glpk@gmx.de> In-Reply-To: From: Maxim Uvarov Date: Wed, 9 Sep 2020 13:43:48 +0300 Message-ID: Subject: Re: [PATCH 1/1] efi/libstub: DRAM base calculation To: Ard Biesheuvel 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 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. > 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. 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. Maxim.