WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] hvmloader: reduce unnecessary e820 reservations for

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] hvmloader: reduce unnecessary e820 reservations for SeaBIOS
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Mon, 6 Jun 2011 16:11:52 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Mon, 06 Jun 2011 08:13:06 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1307373107 -3600
# Node ID b9f424fd0c854afb3fd76090fdbe1ac534be2eff
# Parent  b4ec90b846d342858c2efbef2f18bf5f4b1959e6
hvmloader: reduce unnecessary e820 reservations for SeaBIOS

SeaBIOS will reserve memory in the e820 as necessary, including BIOS data
structures such as the EBDA, any tables it creates or copies into pleace etc.
Therefore arrange that the memory map provided by hvmloader to SeaBIOS reserves
only things which HVMloader has created.

Since ROMBIOS is more tightly coupled with hvmloader we retain the ability to
reserve BIOS regions in the hvmloader produced e820 and use that from the
ROMBIOS backend.

The code for this could probably have been simpler but the existing code avoids
overlapping e820 areas and so the new code does the same (many guest OSes
sanitize the e820 map to handle this, but I wouldn't trust that all do, so I
didn't take the risk)

For ROMBIOS the resulting e820 map as seen by the guest is the same except the
reserved regions at 0x9e000-0x9fc00,0x9fc00-0xa0000 are merged into a single
region 0x9e000-0xa0000 (Linux guests sanitize the e820 to look like this 
anyway).

For SeaBIOS the result is that the lowmem reserved region is from
0x9f000-0xa0000 rather than 0x9e000-0xa0000 which correctly reflects SeaBIOS's
actual usage.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r b4ec90b846d3 -r b9f424fd0c85 tools/firmware/hvmloader/config.h
--- a/tools/firmware/hvmloader/config.h Mon Jun 06 09:24:07 2011 +0100
+++ b/tools/firmware/hvmloader/config.h Mon Jun 06 16:11:47 2011 +0100
@@ -66,6 +66,9 @@ extern unsigned long pci_mem_start, pci_
 #define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
 #define HVMLOADER_PHYSICAL_ADDRESS    0x00100000
 
+#define ACPI_INFO_SIZE                     0xC00
+#define ACPI_INFO_PHYSICAL_END (ACPI_INFO_PHYSICAL_ADDRESS + ACPI_INFO_SIZE)
+
 extern unsigned long scratch_start;
 
 #endif /* __HVMLOADER_CONFIG_H__ */
diff -r b4ec90b846d3 -r b9f424fd0c85 tools/firmware/hvmloader/e820.c
--- a/tools/firmware/hvmloader/e820.c   Mon Jun 06 09:24:07 2011 +0100
+++ b/tools/firmware/hvmloader/e820.c   Mon Jun 06 16:11:47 2011 +0100
@@ -69,28 +69,67 @@ void dump_e820_table(struct e820entry *e
 }
 
 /* Create an E820 table based on memory parameters provided in hvm_info. */
-int build_e820_table(struct e820entry *e820)
+int build_e820_table(struct e820entry *e820,
+                     unsigned int lowmem_reserved_base,
+                     unsigned int bios_image_base)
 {
     unsigned int nr = 0;
 
-    /* 0x0-0x9E000: Ordinary RAM. */
-    /* (Must be at least 512K to keep Windows happy) */
-    e820[nr].addr = 0x00000;
-    e820[nr].size = 0x9E000;
-    e820[nr].type = E820_RAM;
-    nr++;
+    if ( !lowmem_reserved_base )
+            lowmem_reserved_base = 0xA0000;
 
-    /* 0x9E000-0x9FC00: Reserved for internal use. */
-    e820[nr].addr = 0x9E000;
-    e820[nr].size = 0x01C00;
-    e820[nr].type = E820_RESERVED;
-    nr++;
+    /* Lowmem must be at least 512K to keep Windows happy) */
+    ASSERT ( lowmem_reserved_base > 512<<10 );
 
-    /* 0x9FC00-0xA0000: Extended BIOS Data Area (EBDA). */
-    e820[nr].addr = 0x9FC00;
-    e820[nr].size = 0x400;
-    e820[nr].type = E820_RESERVED;
-    nr++;
+    /*
+     * Lowmem reservation must either cover the ACPI info region
+     * entirely or not at all. Sitting half way through suggests
+     * something funny is going on.
+     */
+    ASSERT ( lowmem_reserved_base < ACPI_INFO_PHYSICAL_ADDRESS ||
+             lowmem_reserved_base > ACPI_INFO_PHYSICAL_END );
+
+    ASSERT ( bios_image_base < 0x100000 );
+
+    if ( lowmem_reserved_base < ACPI_INFO_PHYSICAL_ADDRESS ) {
+        /*
+         * 0x0-lowmem_reserved_base: Ordinary RAM.
+         */
+        e820[nr].addr = 0x00000;
+        e820[nr].size = lowmem_reserved_base;
+        e820[nr].type = E820_RAM;
+        nr++;
+    }
+    else
+    {
+        /* 0x0-ACPI_INFO: Ordinary RAM. */
+        e820[nr].addr = 0x00000;
+        e820[nr].size = ACPI_INFO_PHYSICAL_ADDRESS;
+        e820[nr].type = E820_RAM;
+        nr++;
+
+        /* ACPI INFO: Reserved. */
+        e820[nr].addr = ACPI_INFO_PHYSICAL_ADDRESS;
+        e820[nr].size = ACPI_INFO_SIZE;
+        e820[nr].type = E820_RESERVED;
+        nr++;
+
+        /* ACPI_INFO-lowmem_reserved_base: Ordinary RAM. */
+        e820[nr].addr = ACPI_INFO_PHYSICAL_END;
+        e820[nr].size = lowmem_reserved_base - ACPI_INFO_PHYSICAL_END;
+        e820[nr].type = E820_RAM;
+        nr++;
+    }
+
+    /* lowmem_reserved_base-0xa00000: reserved by BIOS implementation. */
+    if ( lowmem_reserved_base < 0xA0000 )
+    {
+            /* Reserved for internal use. */
+            e820[nr].addr = lowmem_reserved_base;
+            e820[nr].size = 0xA0000-lowmem_reserved_base;
+            e820[nr].type = E820_RESERVED;
+            nr++;
+    }
 
     /*
      * Following regions are standard regions of the PC memory map.
@@ -101,12 +140,10 @@ int build_e820_table(struct e820entry *e
      */
 
     /*
-     * 0xE0000-0x0F0000: PC-specific area. We place various tables here.
-     * 0xF0000-0x100000: System BIOS.
-     * TODO: free pages which turn out to be unused.
+     * BIOS region.
      */
-    e820[nr].addr = 0xE0000;
-    e820[nr].size = 0x20000;
+    e820[nr].addr = bios_image_base;
+    e820[nr].size = 0x100000-bios_image_base;
     e820[nr].type = E820_RESERVED;
     nr++;
 
diff -r b4ec90b846d3 -r b9f424fd0c85 tools/firmware/hvmloader/rombios.c
--- a/tools/firmware/hvmloader/rombios.c        Mon Jun 06 09:24:07 2011 +0100
+++ b/tools/firmware/hvmloader/rombios.c        Mon Jun 06 16:11:47 2011 +0100
@@ -61,7 +61,15 @@ static void rombios_init_vm86_tss(void)
 
 static void rombios_setup_e820(void)
 {
-    *E820_NR = build_e820_table(E820);
+    /*
+     * 0x9E000-0x09F000: Stack.
+     * 0x9F000-0x09C000: ACPI info.
+     * 0x9FC00-0x0A0000: Extended BIOS Data Area (EBDA).
+     * ...
+     * 0xE0000-0x0F0000: PC-specific area. We place various tables here.
+     * 0xF0000-0x100000: System BIOS.
+     */
+    *E820_NR = build_e820_table(E820, 0x9E000, 0xE0000);
     dump_e820_table(E820, *E820_NR);
 }
 
diff -r b4ec90b846d3 -r b9f424fd0c85 tools/firmware/hvmloader/seabios.c
--- a/tools/firmware/hvmloader/seabios.c        Mon Jun 06 09:24:07 2011 +0100
+++ b/tools/firmware/hvmloader/seabios.c        Mon Jun 06 16:11:47 2011 +0100
@@ -117,7 +117,9 @@ static void seabios_setup_e820(void)
     struct seabios_info *info = (void *)BIOS_INFO_PHYSICAL_ADDRESS;
     struct e820entry *e820 = scratch_alloc(sizeof(struct e820entry)*16, 0);
     info->e820 = (uint32_t)e820;
-    info->e820_nr = build_e820_table(e820);
+
+    /* SeaBIOS reserves memory in e820 as necessary so no low reservation. */
+    info->e820_nr = build_e820_table(e820, 0, 0x100000-sizeof(seabios));
     dump_e820_table(e820, info->e820_nr);
 }
 
diff -r b4ec90b846d3 -r b9f424fd0c85 tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h   Mon Jun 06 09:24:07 2011 +0100
+++ b/tools/firmware/hvmloader/util.h   Mon Jun 06 16:11:47 2011 +0100
@@ -200,7 +200,9 @@ unsigned long create_pir_tables(void);
 void smp_initialise(void);
 
 #include "e820.h"
-int build_e820_table(struct e820entry *e820);
+int build_e820_table(struct e820entry *e820,
+                    unsigned int lowmem_reserved_base,
+                    unsigned int bios_image_base);
 void dump_e820_table(struct e820entry *e820, unsigned int nr);
 
 #ifndef NDEBUG

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] hvmloader: reduce unnecessary e820 reservations for SeaBIOS, Ian Campbell <=