From patchwork Fri Aug 27 07:55:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristian Amlie X-Patchwork-Id: 1521538 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=northern.tech header.i=@northern.tech header.a=rsa-sha256 header.s=google header.b=b0ECIz1b; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GwsTh1Qszz9sPf for ; Fri, 27 Aug 2021 17:55:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5021B8327F; Fri, 27 Aug 2021 09:55:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=northern.tech Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=northern.tech header.i=@northern.tech header.b="b0ECIz1b"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C7CE583264; Fri, 27 Aug 2021 09:55:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4E1188326E for ; Fri, 27 Aug 2021 09:55:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=northern.tech Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kristian.amlie@northern.tech Received: by mail-lf1-x12a.google.com with SMTP id y34so12589816lfa.8 for ; Fri, 27 Aug 2021 00:55:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=northern.tech; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=qZwqmEsn5tj91/39U9easqFugvWJrxb5pIAUChbqXnU=; b=b0ECIz1bkIMJti7rcTw665ofcL5qOneBliGG8XaEudqpLWC5mDUF6U7MSNohT36ypq Rl4TXXpTdZlEJS2uvUOImiYq2wnqsbQ/ej8XxR/xHVkppduYjQMj0d7qdV90sYrxAajC bEv1oEVOaEwptxjmyVQuVoTzQ+dbkLSpTvz9oACcjS4j50pRpffKaIJVTnE8ClmoeeXb 0mEy3ubtWxekdw2ZGpCbLQgvA5I8dG0BLaztvrISItx+WC/u2y0FS/t+RuC7SG2sAHhw tGyaaHm2VhlRvVPtyBk2TbOn+WtvnLlQhhl2MkgjHAyBnakZklu6KzxJ7BiPCRHBQET2 n0iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=qZwqmEsn5tj91/39U9easqFugvWJrxb5pIAUChbqXnU=; b=bWEABY6Nh1zgfrLKyGN+gjCPA4fdD/N+TPatlKExeXZijqR8hC5DcCy2ptiKgo/ueS +x9PBohu/3gKUDVNsuzeLj/yn1LSScgLE1HgoLlaLMYNBYpo4jQLbxE2Q9Q6UCWMLf6V 4uxhFMbXXK/2EJlK/S7AI9RLI4Bq3SqN9wyelgWziT35+qL9ZtX+Koc/lfS6OlWXWkEy gBdWG9eyCZnno//eLaC1oy7y8ZB/mvyZVp8foP5DpTackHRRxmHOjZYydg4jaJouYUxm 2KJ4nlI/90rx92rGDkYGeC4fgvPtkmMyGmN6wrPbokeCU2TyD5Gd8Eg3hFDFCCvp1ZqL nyGA== X-Gm-Message-State: AOAM530zQXh5r4cS0TewXTX3NvBQ3drfrdjJE8bpfD62Tx9W8i1TV58D 3rJee0suVqn3wMKVb6oqfObSn0i4cwnKhM1p X-Google-Smtp-Source: ABdhPJyBnJQSnVyO5gH5E9XGiTbYyipgeQt0CoebbeNXzpY1gCPXwcu2kSOdRgg/1fQUylSe5bH39Q== X-Received: by 2002:ac2:5963:: with SMTP id h3mr5793496lfp.203.1630050921655; Fri, 27 Aug 2021 00:55:21 -0700 (PDT) Received: from kristian-Mender-T460s.mender.io (195-159-235-214.customer.powertech.no. [195.159.235.214]) by smtp.googlemail.com with ESMTPSA id z24sm523082lfr.105.2021.08.27.00.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Aug 2021 00:55:21 -0700 (PDT) From: Kristian Amlie To: u-boot@lists.denx.de Subject: [PATCH] efi_loader: Omit memory with "no-map" when returning memory map. Date: Fri, 27 Aug 2021 09:55:05 +0200 Message-Id: <20210827075505.25506-2-kristian.amlie@northern.tech> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210827075505.25506-1-kristian.amlie@northern.tech> References: <20210827075505.25506-1-kristian.amlie@northern.tech> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean efi_reserve_memory() states that memory marked with "no-map" shall not be accessed by the UEFI payload. Make sure efi_get_memory_map() honors this. This helps the case when booting vexpress_ca9x4 under QEMU. Because the kernel wants to use an address in the lowest 128MiB of the range, but this range is reserved with "no-map", the kernel complains that it can not allocate the low memory it needs. In reality the actual usable memory starts much higher, which is reflected correctly in the memory map after this fix. Signed-off-by: Kristian Amlie --- lib/efi_loader/efi_memory.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index f4acbee4f9..7f8543143a 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -646,8 +646,16 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, provided_map_size = *memory_map_size; - list_for_each(lhandle, &efi_mem) + list_for_each(lhandle, &efi_mem) { + struct efi_mem_list *lmem; + + lmem = list_entry(lhandle, struct efi_mem_list, link); + + if (lmem->desc.type == EFI_RESERVED_MEMORY_TYPE) + continue; + map_entries++; + } map_size = map_entries * sizeof(struct efi_mem_desc); @@ -672,6 +680,10 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, struct efi_mem_list *lmem; lmem = list_entry(lhandle, struct efi_mem_list, link); + + if (lmem->desc.type == EFI_RESERVED_MEMORY_TYPE) + continue; + *memory_map = lmem->desc; memory_map--; }