Lguest boot
时间:2010-05-17 来源:baozhao
一 2.6.23之前
在
http://www.kernel.org/doc/ols/2007/ols2007v2-pages-173-178.pdf
中说到How does the kernel know it’s an lguest guest? The
first code the x86 kernel runs are is startup_32 in head.S. This tests if paging is already enabled: if it is,
we know we’re under some kind of hypervisor. We end up trying all the registered paravirt_probe func-
tions, and end up in the one in drivers/lguest/lguest.c.
见
http://lkml.org/lkml/2007/4/10/74
中lguest_maybe_init 函数
二 2.6.23
但是出现了变化
下面的链接
http://lkml.org/lkml/2007/5/6/196
[PATCH 2/3] lguest: 2.6.21-mm1 update: lguest-magic-signature.patch解释了在2.6.23.2内核代码,
启动过程:
函数调用流程
main函数的流程(Documentation/lguest/lguest.c)
http://lkml.indiana.edu/hypermail/linux/kernel/0705.0/1995.html
1 . 得到第一条指令地址,返回在start中(实际为entry_point( Documentation/lguest/lguest.c)
start = load_kernel(open_or_die(argv[optind+1], O_RDONLY), &page_offset);
2 初始化各寄存器, 为启动做好准备
tell_kernel(pgdir, start, page_offset) => write=> initialize(file, (const u32 __user *)input); ==> setup_regs(lg->regs, args[2]); 将准备好cs:eip
3 run_guest
entry_point( Documentation/lguest/lguest.c)==>GenuineLguest(drivers/lguest/lguest_asm.S) ==> lguest_init (drivers/lguest/lguest.c)=>start_kernel
三 2.6.24
[RFC PATCH 2/3] lguest: Boot with virtual == physical to get closer to native Linux.
http://lkml.org/lkml/2007/5/4/203正 式的补丁 [patch 31/43] lguest: Boot with virtual == physical to get closer to native Linux. https://lists.linux-foundation.org/pipermail/virtualization/2007-September/008948.html
主要 变化:修改了Boot protocol , 增加虚拟机启动标志
见 Documentation/i386/boot.txt(自2.6.24开始)
[Lguest] [PATCH 0/5] Boot protocol changes http://lists.ozlabs.org/pipermail/lguest/2007-October/000579.html [PATCH 4/5] Revert lguest magic and use hook in head.S
http://lists.ozlabs.org/pipermail/lguest/2007-October/000583.html
2.6.34 的具体分析
从map_elf 和load_bzimage来看, lguest的启动直接跳过setup()函数, 而进入
/arch/x86/kernel/head_32.S 中的startup_32(), 参见ULK 3RD 附录A.
startup_32有对lguest的入口 lguest_entry,在arch/x86/lguest/i386_head.S中有ENTRY(lguest_entry)
#ifdef CONFIG_PARAVIRT
/* This is can only trip for a broken bootloader... */
cmpw $0x207, pa(boot_params + BP_version)
jb default_entry
/* Paravirt-compatible boot parameters. Look to see what architecture
we're booting under. */
movl pa(boot_params + BP_hardware_subarch), %eax
cmpl $num_subarch_entries, %eax
jae bad_subarch
movl pa(subarch_entries)(,%eax,4), %eax
subl $__PAGE_OFFSET, %eax
jmp *%eax
在main()( Documentation/lguest/lguest.c)函数中有如下代码, 可见根本不需要修改内核映像vmlinux或bzImage, 而是直接在代码中设定
/* Boot protocol version: 2.07 supports the fields for lguest. */
boot->hdr.version = 0x207;
/* The hardware_subarch value of "1" tells the Guest it's an lguest. */
boot->hdr.hardware_subarch = 1;