Skip to contentSkip to conversation

multiboot-like domain building?

PATCH New Samuel Thibault 2 participants 5 messages Jan 2, 2007 – Nov 29, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

I'm currently porting Mach to Xen, and I need to preload several Mach modules and give them command lines. The limited "ramdisk" feature of Xen doesn't permits this. Maybe xen's domain building process could include a notion of module with associated command line? For instance, a bit like grub's multiboot module syntax:

modules = [ "/foo/bar arg1 arg2", "/baz arg3" ]

Samuel

#1 lore raw
Quoted 7 lines · Samuel Thibault

I'm currently porting Mach to Xen, and I need to preload several Mach modules and give them command lines. The limited "ramdisk" feature of Xen doesn't permits this. Maybe xen's domain building process could include a notion of module with associated command line? For instance, a bit like grub's multiboot module syntax:

modules = [ "/foo/bar arg1 arg2", "/baz arg3" ]

Fine. You could load them into contiguous memory with a header on the front, and call the whole thing a 'ramdisk'. Then your changes to Mach start of day can simply unpack the 'ramdisk' and set up module metadata inside Mach as necessary.

-- Keir

#2 lore raw

Hi,

Quoted 8 lines · Keir Fraser, le Wed 03 Jan 2007 14:55:30 +0000, a écrit :
Quoted 6 lines · Samuel Thibault

I'm currently porting Mach to Xen, and I need to preload several Mach modules and give them command lines. The limited "ramdisk" feature of Xen doesn't permits this. Maybe xen's domain building process could include a notion of module with associated command line? For instance, a bit like grub's multiboot module syntax:

Quoted 6 lines
Quoted 1 line

modules = [ "/foo/bar arg1 arg2", "/baz arg3" ]

Fine. You could load them into contiguous memory with a header on the front, and call the whole thing a 'ramdisk'. Then your changes to Mach start of day can simply unpack the 'ramdisk' and set up module metadata inside Mach as necessary.

I would be fine with that.

Samuel

#3 lore raw
In reply to Samuel Thibault

Hello,

A lot of time and things have happened since my initial post, but at last I took the time to implement something to support multiboot-like domain building.

As was discussed at the time, the principle would be to just stuff modules and command lines into a big module with a multiboot header, and let the guest unpack it. The patch below simply adds a xen_multiboot_mod_list structure that is used almost exactly like the multiboot standard, and a SIF_ flag to announce that the PV module is not a simple module but a multiboot module that should be unpacked.

The second part of my patch is a packing implementation in pv-grub, which does boot GNU/Hurd as expected.

Does it look sane to people?

Samuel

xen/include/public/xen.h +21 -0
diff -r bec27eb6f72c xen/include/public/xen.h
@@ -581,9 +581,30 @@
 #define console_evtchn console.domU.evtchn
 #endif
 
+/*
+ * A multiboot module is a sort of package containing modules very similar to a
+ * multiboot module list. The only differences are:
+ * - the list of module descriptors is at the beginning of the multiboot module,
+ * - addresses are based on the beginning of the multiboot module,
+ * - the number of modules is determined by a termination entry that has
+ *   mod_start == 0.
+ */
+struct xen_multiboot_mod_list
+{
+    /* Address of first byte of the module */
+    uint32_t mod_start;
+    /* Address of last byte of the module (inclusive) */
+    uint32_t mod_end;
+    /* Address of command line */
+    uint32_t cmdline;
+    /* Unused, must be zero */
+    uint32_t pad;
+};
+
 /* These flags are passed in the 'flags' field of start_info_t. */
 #define SIF_PRIVILEGED    (1<<0)  /* Is the domain privileged? */
 #define SIF_INITDOMAIN    (1<<1)  /* Is this the initial control domain? */
+#define SIF_MULTIBOOT_MOD (1<<2)  /* Is mod_start a multiboot module? */
 #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
 
 typedef struct dom0_vga_console_info {
stubdom/grub.patches/99minios +8 -0
diff -r bec27eb6f72c stubdom/grub.patches/99minios
@@ -151,6 +151,14 @@
  
  /* print */
  static int
+@@ -2910,6 +2910,7 @@
+   switch (kernel_type)
+     {
+     case KERNEL_TYPE_MULTIBOOT:
++    case KERNEL_TYPE_PV:
+       if (mb_cmdline + len + 1 > (char *) MB_CMDLINE_BUF + MB_CMDLINE_BUFLEN)
+ 	{
+ 	  errnum = ERR_WONT_FIT;
 @@ -3776,6 +3802,7 @@
  };
  
stubdom/grub/config.h +1 -1
diff -r bec27eb6f72c stubdom/grub/config.h
@@ -5,7 +5,7 @@
 #define debug _debug
 #define grub_halt(a) do_exit()
 #define printf grub_printf
-void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline);
+void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline, unsigned long flags);
 struct fbfront_dev *fb_open(void *fb, int width, int height, int depth);
 void fb_close(void);
 void pv_boot (void);
stubdom/grub/kexec.c +2 -2
diff -r bec27eb6f72c stubdom/grub/kexec.c
@@ -103,7 +103,7 @@
     return 0;
 }
 
-void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline)
+void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline, unsigned long flags)
 {
     struct xc_dom_image *dom;
     int rc;
@@ -129,7 +129,7 @@
     dom->ramdisk_blob = module;
     dom->ramdisk_size = module_size;
 
-    dom->flags = 0;
+    dom->flags = flags;
     dom->console_evtchn = start_info.console.domU.evtchn;
     dom->xenstore_evtchn = start_info.store_evtchn;
 
stubdom/grub/mini-os.c +68 -8

100 lines not on this page · raw message

#4 lore raw

PATCH 1/1 multiboot-like module support

This defines how multiple modules can be passed to a domain by packing them together in a "multiboot module" in a way very similar to the multiboot standard. An SIF_ flag is added to announce such package. This also adds a packing implementation to PV-GRUB.

xen/include/public/xen.h +27 -0
diff -r d0b030008814 xen/include/public/xen.h
@@ -584,8 +584,35 @@ typedef struct start_info start_info_t;
 /* These flags are passed in the 'flags' field of start_info_t. */
 #define SIF_PRIVILEGED    (1<<0)  /* Is the domain privileged? */
 #define SIF_INITDOMAIN    (1<<1)  /* Is this the initial control domain? */
+#define SIF_MULTIBOOT_MOD (1<<2)  /* Is mod_start a multiboot module? */
 #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
 
+/*
+ * A multiboot module is a package containing modules very similar to a
+ * multiboot module array. The only differences are:
+ * - the array of module descriptors is by convention simply at the beginning
+ *   of the multiboot module,
+ * - addresses in the module descriptors are based on the beginning of the
+ *   multiboot module,
+ * - the number of modules is determined by a termination descriptor that has
+ *   mod_start == 0.
+ *
+ * This permits to both build it statically and reference it in a configuration
+ * file, and let the PV guest easily rebase the addresses to virtual addresses
+ * and at the same time count the number of modules.
+ */
+struct xen_multiboot_mod_list
+{
+    /* Address of first byte of the module */
+    uint32_t mod_start;
+    /* Address of last byte of the module (inclusive) */
+    uint32_t mod_end;
+    /* Address of zero-terminated command line */
+    uint32_t cmdline;
+    /* Unused, must be zero */
+    uint32_t pad;
+};
+
 typedef struct dom0_vga_console_info {
     uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */
 #define XEN_VGATYPE_TEXT_MODE_3 0x03
stubdom/grub.patches/99minios +8 -0
diff -r d0b030008814 stubdom/grub.patches/99minios
@@ -151,6 +151,14 @@ Index: grub/stage2/builtins.c
  
  /* print */
  static int
+@@ -2910,6 +2910,7 @@
+   switch (kernel_type)
+     {
+     case KERNEL_TYPE_MULTIBOOT:
++    case KERNEL_TYPE_PV:
+       if (mb_cmdline + len + 1 > (char *) MB_CMDLINE_BUF + MB_CMDLINE_BUFLEN)
+ 	{
+ 	  errnum = ERR_WONT_FIT;
 @@ -3776,6 +3802,7 @@
  };
  
stubdom/grub/config.h +1 -1
diff -r d0b030008814 stubdom/grub/config.h
@@ -5,7 +5,7 @@
 #define debug _debug
 #define grub_halt(a) do_exit()
 #define printf grub_printf
-void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline);
+void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline, unsigned long flags);
 struct fbfront_dev *fb_open(void *fb, int width, int height, int depth);
 void fb_close(void);
 void pv_boot (void);
stubdom/grub/kexec.c +2 -2
diff -r d0b030008814 stubdom/grub/kexec.c
@@ -103,7 +103,7 @@ int kexec_allocate(struct xc_dom_image *
     return 0;
 }
 
-void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline)
+void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline, unsigned long flags)
 {
     struct xc_dom_image *dom;
     int rc;
@@ -129,7 +129,7 @@ void kexec(void *kernel, long kernel_siz
     dom->ramdisk_blob = module;
     dom->ramdisk_size = module_size;
 
-    dom->flags = 0;
+    dom->flags = flags;
     dom->console_evtchn = start_info.console.domU.evtchn;
     dom->xenstore_evtchn = start_info.store_evtchn;
 
stubdom/grub/mini-os.c +68 -8

100 lines not on this page · raw message