decui_microsoft.com updated the summary for this revision.
decui_microsoft.com updated this revision to Diff 26023.

CHANGES SINCE LAST UPDATE
  https://reviews.freebsd.org/D9904?vs=26020&id=26023

REVISION DETAIL
  https://reviews.freebsd.org/D9904

AFFECTED FILES
  sys/boot/efi/loader/copy.c

EMAIL PREFERENCES
  https://reviews.freebsd.org/settings/panel/emailpreferences/

To: decui_microsoft.com, imp, jhb, will, kib, delphij, emaste, marcel, 
sepherosa_gmail.com, honzhan_microsoft.com, howard0su_gmail.com, tsoome, gonzo, 
manu, andrew, sbruno, ambrisko, allanjude, bapt, cem, smh, ian
Cc: freebsd-virtualization-list
diff --git a/sys/boot/efi/loader/copy.c b/sys/boot/efi/loader/copy.c
--- a/sys/boot/efi/loader/copy.c
+++ b/sys/boot/efi/loader/copy.c
@@ -53,7 +53,7 @@
 	UINT32 dver;
 	EFI_STATUS status;
 	int i, ndesc;
-	unsigned long available_pages;
+	unsigned long available_pages = 0;
 
 	sz = 0;
 	status = BS->GetMemoryMap(&sz, 0, &key, &dsz, &dver);
@@ -70,7 +70,6 @@
 	}
 
 	ndesc = sz / dsz;
-
 	for (i = 0, p = map; i < ndesc;
 	     i++, p = NextMemoryDescriptor(p, dsz)) {
 		start = p->PhysicalStart;
@@ -81,20 +80,38 @@
 			continue;
 
 		if (p->Type != EfiConventionalMemory)
-			continue;
+			printf("Warning: wrong EFI memory type: %d\n",
+			    p->Type);
 
 		available_pages = p->NumberOfPages -
 			((KERNEL_PHYSICAL_BASE - start) >> EFI_PAGE_SHIFT);
+		break;
+	}
+
+	if (available_pages == 0) {
+		printf("Can't find valid memory map for staging area!\n");
+		goto out;
+	}
 
-		if (*nr_pages > available_pages) {
-			printf("staging area size is reduced: %ld -> %ld!\n",
-			    *nr_pages, available_pages);
-			*nr_pages = available_pages;
-		}
+	for ( ; i < ndesc;
+	     i++, p = NextMemoryDescriptor(p, dsz)) {
+		if (p->Type != EfiConventionalMemory &&
+		    p->Type != EfiLoaderData)
+			break;
 
-		break;
+		if (p->PhysicalStart != end)
+			break;
+
+		end = p->PhysicalStart + p->NumberOfPages * EFI_PAGE_SIZE;
+
+		available_pages += p->NumberOfPages;
 	}
 
+	if (*nr_pages > available_pages) {
+		printf("Staging area's size is reduced: %ld -> %ld!\n",
+		    *nr_pages, available_pages);
+		*nr_pages = available_pages;
+	}
 out:
 	free(map);
 }

_______________________________________________
freebsd-virtualization@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-virtualization
To unsubscribe, send any mail to 
"freebsd-virtualization-unsubscr...@freebsd.org"

Reply via email to