[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] Re: [patch 2/5] libelf: use for x86 dom0 builder.



See comments below:

On Jan 23, 2007, at 15:53, Gerd Hoffmann wrote:
This patch switches the x86 dom0 builder over to libelf.

Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxx>
---
 xen/arch/ia64/xen/domain.c  |   79 +++++------
xen/arch/x86/domain_build.c | 303 +++++++++++++++-----------------------------
 xen/common/Makefile         |    4
 3 files changed, 148 insertions(+), 238 deletions(-)

Index: build-ia64-unstable-13282/xen/common/Makefile
===================================================================
--- build-ia64-unstable-13282.orig/xen/common/Makefile
+++ build-ia64-unstable-13282/xen/common/Makefile
@@ -2,8 +2,8 @@ obj-y += acm_ops.o
 obj-y += bitmap.o
 obj-y += domctl.o
 obj-y += domain.o
-obj-y += elf.o
-obj-$(CONFIG_COMPAT) += elf32.o
+#obj-y += elf.o
+#obj-$(CONFIG_COMPAT) += elf32.o

Can we just zap those lines?

 obj-y += event_channel.o
 obj-y += grant_table.o
 obj-y += kernel.o
Index: build-ia64-unstable-13282/xen/arch/x86/domain_build.c
===================================================================
--- build-ia64-unstable-13282.orig/xen/arch/x86/domain_build.c
+++ build-ia64-unstable-13282/xen/arch/x86/domain_build.c
@@ -13,7 +13,6 @@
 #include <xen/delay.h>

[snip]
-
 int construct_dom0(struct domain *d,
unsigned long _image_start, unsigned long image_len, unsigned long _initrd_start, unsigned long initrd_len,
                    char *cmdline)
 {
-    int i, rc, dom0_pae, xen_pae, order;
+    int i, rc, compatible, compat32, order, machine;
     struct cpu_user_regs *regs;
     unsigned long pfn, mfn;
     unsigned long nr_pages;
@@ -263,9 +205,7 @@ int construct_dom0(struct domain *d,
     struct page_info *page = NULL;
     start_info_t *si;
     struct vcpu *v = d->vcpu[0];
-    const char *p;
     unsigned long long value;
-    int value_defined;
 #if defined(__i386__)
char *image_start = (char *)_image_start; /* use lowmem mappings */ char *initrd_start = (char *)_initrd_start; /* use lowmem mappings */
@@ -287,7 +227,10 @@ int construct_dom0(struct domain *d,
* *_start address are page-aligned, except v_start (and v_end) which are
      * superpage-aligned.
      */
-    struct domain_setup_info dsi;
+    struct elf_binary elf;
+    struct elf_dom_parms parms;
+    unsigned long vkern_start;
+    unsigned long vkern_end;
     unsigned long vinitrd_start;
     unsigned long vinitrd_end;
     unsigned long vphysmap_start;
@@ -298,6 +241,7 @@ int construct_dom0(struct domain *d,
     unsigned long vstack_end;
     unsigned long vpt_start;
     unsigned long vpt_end;
+    unsigned long v_start;
     unsigned long v_end;

     /* Machine address of next candidate page-table page. */
@@ -312,21 +256,71 @@ int construct_dom0(struct domain *d,
     BUG_ON(d->vcpu[0] == NULL);
     BUG_ON(test_bit(_VCPUF_initialised, &v->vcpu_flags));

-    memset(&dsi, 0, sizeof(struct domain_setup_info));
-    dsi.image_addr = (unsigned long)image_start;
-    dsi.image_len  = image_len;
-
     printk("*** LOADING DOMAIN 0 ***\n");

     d->max_pages = ~0U;

     nr_pages = compute_dom0_nr_pages();

-    rc = parseelfimage(&dsi);
+    if (0 != (rc = elf_init(&elf, image_start, image_len)))
+        return rc;
+#ifdef VERBOSE
+    elf_set_verbose(&elf);
+#endif
+    elf_parse_binary(&elf);
+    if (0 != (elf_xen_parse(&elf, &parms)))
+        return rc;
+
+    /* compatibility check */
+    compatible = 0;
+    compat32   = 0;
+    machine = elf_uval(&elf, elf.ehdr, e_machine);
+    switch (CONFIG_PAGING_LEVELS) {

Can we make this a compile time check instead of run-time? Also, it
would seem easier to do all the checks first and then do a printk
specifying which kernel we found and, if it's not compatible with the
hypervisor, why not.

+    case 2: /* x86_32 */
+        if (parms.pae == PAEKERN_bimodal)
+            parms.pae = PAEKERN_no;
+        printk(" Xen  kernel: 32-bit, lsb\n");
+        if (elf_32bit(&elf) && !parms.pae && machine == EM_386)
+            compatible = 1;
+        break;
+    case 3: /* x86_32p */
+        if (parms.pae == PAEKERN_bimodal)
+            parms.pae = PAEKERN_extended_cr3;
+        printk(" Xen  kernel: 32-bit, PAE, lsb\n");
+        if (elf_32bit(&elf) && parms.pae && machine == EM_386)
+            compatible = 1;
+        break;
+    case 4: /* x86_64 */
+#ifndef CONFIG_COMPAT
+        printk(" Xen  kernel: 64-bit, lsb\n");
+#else
+        printk(" Xen  kernel: 64-bit, lsb, compat32\n");
+        if (elf_32bit(&elf) && parms.pae == PAEKERN_bimodal)
+            parms.pae = PAEKERN_extended_cr3;
+        if (elf_32bit(&elf) && parms.pae && machine == EM_386)
+        {
+            compat32 = 1;
+            compatible = 1;
+        }
+#endif
+        if (elf_64bit(&elf) && machine == EM_X86_64)
+            compatible = 1;
+        break;
+    }
+ printk(" Dom0 kernel: %s%s, %s, paddr 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
+           elf_64bit(&elf) ? "64-bit" : "32-bit",
+           parms.pae       ? ", PAE"  : "",
+           elf_msb(&elf)   ? "msb"    : "lsb",
+           elf.pstart, elf.pend);
+
+    if ( !compatible )
+    {
+        printk("Mismatch between Xen and DOM0 kernel\n");
+        return -EINVAL;
+    }
+
 #ifdef CONFIG_COMPAT
-    if ( rc == -ENOSYS
-         && !compat_disabled
-         && (rc = parseelf32image(&dsi)) == 0 )
+    if (compat32)
     {
         l1_pgentry_t gdt_l1e;

@@ -348,42 +342,10 @@ int construct_dom0(struct domain *d,
local_flush_tlb_one(GDT_LDT_VIRT_START + FIRST_RESERVED_GDT_BYTE);
     }
 #endif
-    if ( rc != 0)
-    {
-        if ( rc == -ENOSYS )
-            printk("DOM0 image is not a Xen-compatible Elf image.\n");
-       return rc;
-    }

[snip]


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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.