From: Rusty Russell Eric Biederman complained that lguest doesn't use the Linux standard boot header format. He's got a good point. This also simplifies the code: the example launcher writes the header directly, rather than lguest writing into it during boot. While we're touching this code, we also fix the problem of initrd's which don't have a page-aligned size. This anticipates changing the paravirt-finding routines to use a "platform type" field from %esi, rather than a "probe all until one succeeds" routine, but doesn't actually change that code. Signed-off-by: Rusty Russell Signed-off-by: Andrew Morton --- drivers/lguest/lguest.c | 20 ++++++++------------ drivers/lguest/lguest_asm.S | 5 ++++- drivers/lguest/lguest_user.c | 4 +--- include/linux/lguest.h | 5 ----- include/linux/lguest_launcher.h | 8 -------- 5 files changed, 13 insertions(+), 29 deletions(-) diff -puN /dev/null /dev/null diff -puN drivers/lguest/lguest.c~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized drivers/lguest/lguest.c --- a/drivers/lguest/lguest.c~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized +++ a/drivers/lguest/lguest.c @@ -52,7 +52,6 @@ struct lguest_data lguest_data = { .blocked_interrupts = { 1 }, /* Block timer interrupts */ }; struct lguest_device_desc *lguest_devices; -static __initdata const struct lguest_boot_info *boot = __va(0); static enum paravirt_lazy_mode lazy_mode; static void lguest_lazy_mode(enum paravirt_lazy_mode mode) @@ -377,8 +376,7 @@ static __init char *lguest_memory_setup( /* We do this here because lockcheck barfs if before start_kernel */ atomic_notifier_chain_register(&panic_notifier_list, &paniced); - e820.nr_map = 0; - add_memory_region(0, PFN_PHYS(boot->max_pfn), E820_RAM); + add_memory_region(E820_MAP->addr, E820_MAP->size, E820_MAP->type); return "LGUEST"; } @@ -409,8 +407,14 @@ static unsigned lguest_patch(u8 type, u1 return insn_len; } -__init void lguest_init(void) +__init void lguest_init(void *boot) { + /* Copy boot parameters first. */ + memcpy(boot_params, boot, PARAM_SIZE); + memcpy(boot_command_line, + __va(*(unsigned long *)(boot_params + NEW_CL_POINTER)), + COMMAND_LINE_SIZE); + paravirt_ops.name = "lguest"; paravirt_ops.paravirt_enabled = 1; paravirt_ops.kernel_rpl = 1; @@ -459,7 +463,6 @@ __init void lguest_init(void) paravirt_ops.wbinvd = lguest_wbinvd; hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0); - strncpy(boot_command_line, boot->cmdline, COMMAND_LINE_SIZE); /* We use top of mem for initial pagetables. */ init_pg_tables_end = __pa(pg0); @@ -485,13 +488,6 @@ __init void lguest_init(void) add_preferred_console("hvc", 0, NULL); - if (boot->initrd_size) { - /* We stash this at top of memory. */ - INITRD_START = boot->max_pfn*PAGE_SIZE - boot->initrd_size; - INITRD_SIZE = boot->initrd_size; - LOADER_TYPE = 0xFF; - } - pm_power_off = lguest_power_off; start_kernel(); } diff -puN drivers/lguest/lguest_asm.S~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized drivers/lguest/lguest_asm.S --- a/drivers/lguest/lguest_asm.S~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized +++ a/drivers/lguest/lguest_asm.S @@ -10,7 +10,8 @@ * This is where we begin: we have a magic signature which the launcher looks * for. The plan is that the Linux boot protocol will be extended with a * "platform type" field which will guide us here from the normal entry point, - * but for the moment this suffices. + * but for the moment this suffices. We pass the virtual address of the boot + * info to lguest_init(). * * We put it in .init.text will be discarded after boot. */ @@ -18,6 +19,8 @@ .ascii "GenuineLguest" /* Set up initial stack. */ movl $(init_thread_union+THREAD_SIZE),%esp + movl %esi, %eax + addl $__PAGE_OFFSET, %eax jmp lguest_init /* The templates for inline patching. */ diff -puN drivers/lguest/lguest_user.c~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized drivers/lguest/lguest_user.c --- a/drivers/lguest/lguest_user.c~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized +++ a/drivers/lguest/lguest_user.c @@ -7,13 +7,11 @@ static void setup_regs(struct lguest_regs *regs, unsigned long start) { /* Write out stack in format lguest expects, so we can switch to it. */ - regs->edi = LGUEST_MAGIC_EDI; - regs->ebp = LGUEST_MAGIC_EBP; - regs->esi = LGUEST_MAGIC_ESI; regs->ds = regs->es = regs->ss = __KERNEL_DS|GUEST_PL; regs->cs = __KERNEL_CS|GUEST_PL; regs->eflags = 0x202; /* Interrupts enabled. */ regs->eip = start; + /* esi points to our boot information (physical address 0) */ } /* + addr */ diff -puN include/linux/lguest.h~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized include/linux/lguest.h --- a/include/linux/lguest.h~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized +++ a/include/linux/lguest.h @@ -3,11 +3,6 @@ #ifndef _ASM_LGUEST_H #define _ASM_LGUEST_H -/* These are randomly chosen numbers which indicate we're an lguest at boot */ -#define LGUEST_MAGIC_EBP 0x4C687970 -#define LGUEST_MAGIC_EDI 0x652D4D65 -#define LGUEST_MAGIC_ESI 0xFFFFFFFF - #ifndef __ASSEMBLY__ #include diff -puN include/linux/lguest_launcher.h~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized include/linux/lguest_launcher.h --- a/include/linux/lguest_launcher.h~lguest-the-host-code-lguest-use-standard-bootloader-format-fix-badly-sized +++ a/include/linux/lguest_launcher.h @@ -17,14 +17,6 @@ struct lguest_dma u16 len[LGUEST_MAX_DMA_SECTIONS]; }; -/* This is found at address 0. */ -struct lguest_boot_info -{ - u32 max_pfn; - u32 initrd_size; - char cmdline[256]; -}; - struct lguest_block_page { /* 0 is a read, 1 is a write. */ _