All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] efi_loader: Always allocate the highest available address
@ 2016-03-30 14:38 Alexander Graf
  2016-04-02  2:00 ` [U-Boot] " Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Graf @ 2016-03-30 14:38 UTC (permalink / raw)
  To: u-boot

Some EFI applications (grub2) expect that an allocation always returns
the highest available memory address for the given size.

Without this, we may run into situations where the initrd gets allocated
at a lower address than the kernel.

This patch fixes booting in such situations for me.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 lib/efi_loader/efi_memory.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index c82b53f..8a1e249 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -13,6 +13,7 @@
 #include <malloc.h>
 #include <asm/global_data.h>
 #include <libfdt_env.h>
+#include <linux/list_sort.h>
 #include <inttypes.h>
 #include <watchdog.h>
 
@@ -27,6 +28,31 @@ struct efi_mem_list {
 LIST_HEAD(efi_mem);
 
 /*
+ * Sorts the memory list from highest address to lowest address
+ *
+ * When allocating memory we should always start from the highest
+ * address chunk, so sort the memory list such that the first list
+ * iterator gets the highest address and goes lower from there.
+ */
+static int efi_mem_cmp(void *priv, struct list_head *a, struct list_head *b)
+{
+	struct efi_mem_list *mema = list_entry(a, struct efi_mem_list, link);
+	struct efi_mem_list *memb = list_entry(b, struct efi_mem_list, link);
+
+	if (mema->desc.physical_start == memb->desc.physical_start)
+		return 0;
+	else if (mema->desc.physical_start < memb->desc.physical_start)
+		return 1;
+	else
+		return -1;
+}
+
+static void efi_mem_sort(void)
+{
+	list_sort(NULL, &efi_mem, efi_mem_cmp);
+}
+
+/*
  * Unmaps all memory occupied by the carve_desc region from the
  * list entry pointed to by map.
  *
@@ -142,6 +168,9 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type,
 	/* Add our new map */
         list_add_tail(&newlist->link, &efi_mem);
 
+	/* And make sure memory is listed in descending order */
+	efi_mem_sort();
+
 	return start;
 }
 
-- 
1.8.5.6

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] efi_loader: Always allocate the highest available address
  2016-03-30 14:38 [U-Boot] [PATCH] efi_loader: Always allocate the highest available address Alexander Graf
@ 2016-04-02  2:00 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2016-04-02  2:00 UTC (permalink / raw)
  To: u-boot

On Wed, Mar 30, 2016 at 04:38:29PM +0200, Alexander Graf wrote:

> Some EFI applications (grub2) expect that an allocation always returns
> the highest available memory address for the given size.
> 
> Without this, we may run into situations where the initrd gets allocated
> at a lower address than the kernel.
> 
> This patch fixes booting in such situations for me.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160401/70e7ac15/attachment.sig>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-04-02  2:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-30 14:38 [U-Boot] [PATCH] efi_loader: Always allocate the highest available address Alexander Graf
2016-04-02  2:00 ` [U-Boot] " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.