Skip to contentSkip to conversation

domain builder rewrite

RFC/patch Gerd Hoffmann 3 participants 5 messages Jun 1, 2006 – Jun 13, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

I've started cleaning up the domU domain builder, which basically ended up in being a nearly complete rewrite of the code. The patch below is the very first cut of the new code. I've tested it on x86_32 (both with and without shadow_translated) and with linux kernels only. In theory PAE mode and x86_64 should work too, I havn't even compiled on x86_64 though.

Design goals:
- General cleanup of the code, move lots of state information which currently is held in local variables into a struct.
- separate out arch-specific bits into functions and source files (as far as possible), so there are not tons of #ifdef's all over the place ;)
- Don't have xen hypercalls all over the place, so most of the code runs just fine without xen.

Why I'm doing this:
- The current code is a mess ...
- I want to reuse the domain builder code for other purposes than directly booting xen domains. domU kexec is the first item on my todo list. Directly writing a suspend image, then boot the virtual machines via "xm restore" should be easy too. It isn't very useful on a single host, but booting xen virtual machines on _another_ machine that way (using the migration protocol) probably is.
- I'm sure other people have fancy idea's too ;)

Current TODO list:
- discuss design, fixup if needed ;)
- more testing.
- re-add bsd symtab loading.
- re-add other architectures.
- re-add loader bits (plan9, ...)

cheers,

Gerd

tools/libxc/Makefile +7 -2
diff -r 4142bfd01e02 tools/libxc/Makefile
@@ -26,7 +26,7 @@
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
 
 GUEST_SRCS-y :=
-GUEST_SRCS-y += xc_linux_build.c
+#GUEST_SRCS-y += xc_linux_build.c
 GUEST_SRCS-y += xc_load_bin.c
 GUEST_SRCS-y += xc_load_elf.c
 GUEST_SRCS-y += xg_private.c
@@ -35,7 +35,12 @@
 GUEST_SRCS-$(CONFIG_MIGRATE) += xc_linux_restore.c xc_linux_save.c
 GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
 
-CFLAGS   += -Werror
+# new domain builder
+GUEST_SRCS-y += xc_dom_compat.c xc_dom_core.c xc_dom_elf.c xc_dom_boot.c
+GUEST_SRCS-$(CONFIG_X86) += xc_dom_x86.c
+#GUEST_SRCS-$(CONFIG_IA64) += xc_dom_ia86.c
+
+CFLAGS   += -g -Werror -Wmissing-prototypes
 CFLAGS   += -fno-strict-aliasing
 CFLAGS   += $(INCLUDES) -I.
 
tools/libxc/xc_linux_build.c +4 -4
diff -r 4142bfd01e02 tools/libxc/xc_linux_build.c
@@ -133,10 +133,10 @@
     return 0;
 }
 
-int load_initrd(int xc_handle, domid_t dom,
-                struct initrd_info *initrd,
-                unsigned long physbase,
-                unsigned long *phys_to_mach)
+static int load_initrd(int xc_handle, domid_t dom,
+                       struct initrd_info *initrd,
+                       unsigned long physbase,
+                       unsigned long *phys_to_mach)
 {
     char page[PAGE_SIZE];
     unsigned long pfn_start, pfn, nr_pages;
tools/libxc/xc_linux_restore.c +1 -1
diff -r 4142bfd01e02 tools/libxc/xc_linux_restore.c
@@ -57,7 +57,7 @@
 ** This function inverts that operation, replacing the pfn values with
 ** the (now known) appropriate mfn values.
 */
-int uncanonicalize_pagetable(unsigned long type, void *page)
+static int uncanonicalize_pagetable(unsigned long type, void *page)
 {
     int i, pte_last;
     unsigned long pfn;
tools/libxc/xc_linux_save.c +1 -1
diff -r 4142bfd01e02 tools/libxc/xc_linux_save.c
@@ -415,7 +415,7 @@
 ** which entries do not require canonicalization (in particular, those
 ** entries which map the virtual address reserved for the hypervisor).
 */
-void canonicalize_pagetable(unsigned long type, unsigned long pfn,
+static void canonicalize_pagetable(unsigned long type, unsigned long pfn,
                              const void *spage, void *dpage)
 {
 
tools/libxc/xc_private.c +6 -3
diff -r 4142bfd01e02 tools/libxc/xc_private.c
@@ -5,6 +5,7 @@
  */
 
 #include "xc_private.h"
+#include "xg_private.h"
 
 /* NB: arr must be mlock'ed */
 int xc_get_pfn_type_batch(int xc_handle,
@@ -18,10 +19,11 @@
     return do_dom0_op(xc_handle, &op);
 }
 
+#if 0 /* dead code ??? */
 #define GETPFN_ERR (~0U)
-unsigned int get_pfn_type(int xc_handle,
-                          unsigned long mfn,
-                          uint32_t dom)
+static unsigned int get_pfn_type(int xc_handle,
+                                 unsigned long mfn,
+                                 uint32_t dom)
 {
     DECLARE_DOM0_OP;
     op.cmd = DOM0_GETPAGEFRAMEINFO;
@@ -34,6 +36,7 @@
     }
     return op.u.getpageframeinfo.type;
 }
+#endif
 
 int xc_mmuext_op(
     int xc_handle,
tools/libxc/xc_dom.h new file +179 -0

179 lines not on this page · raw message

tools/libxc/xc_dom_boot.c new file +288 -0

288 lines not on this page · raw message

tools/libxc/xc_dom_compat.c new file +125 -0

125 lines not on this page · raw message

tools/libxc/xc_dom_core.c new file +503 -0

503 lines not on this page · raw message

tools/libxc/xc_dom_elf.c new file +276 -0

276 lines not on this page · raw message

tools/libxc/xc_dom_x86.c new file +340 -0

340 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Hi Gerd!

I hope I've understood what you are trying to do.

At Thu, 01 Jun 2006 16:59:07 +0200,

Quoted 18 lines · Gerd Hoffmann

Hi,

I've started cleaning up the domU domain builder, which basically ended up in being a nearly complete rewrite of the code. The patch below is the very first cut of the new code. I've tested it on x86_32 (both with and without shadow_translated) and with linux kernels only. In theory PAE mode and x86_64 should work too, I havn't even compiled on x86_64 though.

Design goals:
- General cleanup of the code, move lots of state information which currently is held in local variables into a struct.
- separate out arch-specific bits into functions and source files (as far as possible), so there are not tons of #ifdef's all over the place ;)
- Don't have xen hypercalls all over the place, so most of the code runs just fine without xen.

Quoted 10 lines

Why I'm doing this:
- The current code is a mess ...
- I want to reuse the domain builder code for other purposes than directly booting xen domains. domU kexec is the first item on my todo list. Directly writing a suspend image, then boot the virtual machines via "xm restore" should be easy too. It isn't very useful on a single host, but booting xen virtual machines on _another_ machine that way (using the migration protocol) probably is.
- I'm sure other people have fancy idea's too ;)

This sounds like useful stuff to me :-). A thing which I think would be good is to allow more flexible handling of the ELF files. In particular, it would be nice if it was possible to arrange the virtual address space more freely, i.e., loading an ELF-file like:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        c0000000 02e000 1d9ce8 00 WAX  0   0 32
  [ 2] .rodata           PROGBITS        c01d9d00 207d00 05b840 00   A  0   0 32
  [ 3] header            PROGBITS        c0235540 263540 00004c 00   A  0   0  8
  [ 4] .kstrtab          PROGBITS        c023558c 26358c 00077a 00   A  0   0  1
  [ 5] __ksymtab         PROGBITS        c0235d08 263d08 000480 00   A  0   0  4
  [ 6] .data             PROGBITS        90000000 001000 00d5a8 00  WA  0   0 4096

...

where the data and code are mapped to different locations in memory. I guess this is along the lines of your "writing a suspended image directly" idea?

I guess that the hypervisor really doesn't need to know about ELF images at all? To me it seems that it should be enough for it to get a suspended image built by the domain.

Sorry if I've overlooked some fundamental issue here.

// Simon

#2 lore raw
Quoted 13 lines

This sounds like useful stuff to me :-). A thing which I think would be good is to allow more flexible handling of the ELF files. In particular, it would be nice if it was possible to arrange the virtual address space more freely, i.e., loading an ELF-file like:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        c0000000 02e000 1d9ce8 00 WAX  0   0 32
  [ 2] .rodata           PROGBITS        c01d9d00 207d00 05b840 00   A  0   0 32
  [ 3] header            PROGBITS        c0235540 263540 00004c 00   A  0   0  8
  [ 4] .kstrtab          PROGBITS        c023558c 26358c 00077a 00   A  0   0  1
  [ 5] __ksymtab         PROGBITS        c0235d08 263d08 000480 00   A  0   0  4
  [ 6] .data             PROGBITS        90000000 001000 00d5a8 00  WA  0   0 4096
Quoted 3 lines

...

where the data and code are mapped to different locations in memory.

That is an unrelated problem. It's certainly possible to do that, probably even easier in the new framework. On real hardware boot loaders usually do _not_ setup that kind mappings though, that is the job of the OS kernel. And I think we should to that in xen the same way, to make porting OS'es as simple as possible and also to keep the code differences between native and xen guest as small as possible.

Quoted 3 lines

I guess that the hypervisor really doesn't need to know about ELF images at all? To me it seems that it should be enough for it to get a suspended image built by the domain.

It needs to know to bootstrap domain 0 only, all other domains are created by the tools, not the hypervisor itself.

cheers,

Gerd

Signature · 2 lines
Gerd Hoffmann <[email protected]>
http://www.suse.de/~kraxel/julika-dora.jpeg
#3 lore raw
Quoted 8 lines · Gerd Hoffmann
Quoted 4 lines

I guess that the hypervisor really doesn't need to know about ELF images at all? To me it seems that it should be enough for it to get a suspended image built by the domain.

It needs to know to bootstrap domain 0 only, all other domains are created by the tools, not the hypervisor itself.

It always struck me as odd that we duplicated the domain builder code in both in userspace and in the hypervisor. Have you given any thought of unifying the two?

I always thought it would be neat to have a hypercall that could build paravirt domains at least...

Regards,

Anthony Liguori

Quoted 5 lines

cheers,

Gerd

#4 lore raw
Quoted 3 lines

It always struck me as odd that we duplicated the domain builder code in both in userspace and in the hypervisor. Have you given any thought of unifying the two?

No. It probably could work for the current one as you can see everywhere that one was created by copy&pasting the other one some time ago. The rewritten one wouldn't work very well within the hypervisor due to the design.

cheers,

Gerd

Signature · 2 lines
Gerd Hoffmann <[email protected]>
http://www.suse.de/~kraxel/julika-dora.jpeg