[Lguest] question about lguest inside kvm

Stefanos Geraggelos sgerag at cslab.ece.ntua.gr
Thu Jul 28 04:54:17 EST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/27/2011 06:43 AM, Rusty Russell wrote:
> On Tue, 26 Jul 2011 14:36:57 +0300, Stefanos Geraggelos <sgerag at cslab.ece.ntua.gr> wrote:
>>>> the output was pv_info: kvm. Finally, I tried to comment out the
>>>> return -EPERM, the module loaded but when I ran ./lguest it printed a
>>>> trap 13 (or something). So, I think it indeed does Tricky Stuff :) and
>>>> I though that is wise to drop you an email before I try to dig inside
>>>> for the trap thing. Can you point me a solution to that?
>>>>
>>>> Thanks and sorry for any inconvenience!
>>>
>>> Hi Stefanos!
>>>
>>>     Fascinating... I think it *should* be OK to run inside KVM, as the
>>> parts that kvm paravirt cover do not effect lguest.
>>>
>>> Can you send your .config file?
>>>
>>> Thanks,
>>> Rusty.
>>
>> yeap, here it is (attached).
> 
> OK.  Two problems; one is related to KVM, another is related to
> CONFIG_RELOCATABLE=y.
> 
> These three patches fix it for me on your config; do they work for you?
> 
> Cheers,
> Rusty.
> 
> From: Rusty Russell <rusty at rustcorp.com.au>
> Subject: lguest: Allow running under paravirt-enabled KVM.
> 
> We actually can run under KVM, as it doesn't paravirtualize anything we
> need to use; reduce the check to checking we are the normal ringlevel.
> 
> Reported-by: Stefanos Geraggelos <sgerag at cslab.ece.ntua.gr>
> Signed-off-by: Rusty Russell <rusty at rustcorp.com.au># HG changeset patch
> ---
>  drivers/lguest/core.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
> --- a/drivers/lguest/core.c
> +++ b/drivers/lguest/core.c
> @@ -313,7 +313,7 @@ static int __init init(void)
>  	int err;
>  
>  	/* Lguest can't run under Xen, VMI or itself.  It does Tricky Stuff. */
> -	if (paravirt_enabled()) {
> +	if (get_kernel_rpl() != 0) {
>  		printk("lguest is afraid of being a guest\n");
>  		return -EPERM;
>  	}
> 
> 
> From: Rusty Russell <rusty at rustcorp.com.au>
> Subject: lguest: don't allow KVM-detection cpuid.
> 
> Host might be running under KVM, but we shouldn't allow Guest to think it
> can use KVM hypercalls (it can't, and it will embarrass itself if it tries).
> 
> Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
> ---
>  arch/x86/lguest/boot.c |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
> --- a/arch/x86/lguest/boot.c
> +++ b/arch/x86/lguest/boot.c
> @@ -70,6 +70,7 @@
>  #include <asm/i387.h>
>  #include <asm/stackprotector.h>
>  #include <asm/reboot.h>		/* for struct machine_ops */
> +#include <asm/kvm_para.h>
>  
>  /*G:010
>   * Welcome to the Guest!
> @@ -455,6 +456,15 @@ static void lguest_cpuid(unsigned int *a
>  		*ax &= 0xFFFFF0FF;
>  		*ax |= 0x00000500;
>  		break;
> +
> +	/*
> +	 * This is used to detect if we're running under KVM.  We might be,
> +	 * but that's a Host matter, not us.  So say we're not.
> +	 */
> +	case KVM_CPUID_SIGNATURE:
> +		*bx = *cx = *dx = 0;
> +		break;
> +
>  	/*
>  	 * 0x80000000 returns the highest Extended Function, so we futureproof
>  	 * like we do above by limiting it to known fields.
> 
> 
> From: Rusty Russell <rusty at rustcorp.com.au>
> Subject: lguest: allow booting guest with CONFIG_RELOCATABLE=y
> 
> The CONFIG_RELOCATABLE code tries to align the unpack destination to
> the value of 'kernel_alignment' in the setup_hdr.  If that's 0, it
> tries to unpack to address 0, which in fact causes the gunzip code
> to call 'error("Out of memory while allocating output buffer")'.
> 
> The bootloader (ie. the lguest Launcher in this case) should be doing
> setting this field; the normal bzImage is 16M, we can use the same.
> 
> Reported-by: Stefanos Geraggelos <sgerag at cslab.ece.ntua.gr>
> Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
> ---
>  Documentation/virtual/lguest/lguest.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/Documentation/virtual/lguest/lguest.c b/Documentation/virtual/lguest/lguest.c
> --- a/Documentation/virtual/lguest/lguest.c
> +++ b/Documentation/virtual/lguest/lguest.c
> @@ -1996,6 +1996,9 @@ int main(int argc, char *argv[])
>  	/* We use a simple helper to copy the arguments separated by spaces. */
>  	concat((char *)(boot + 1), argv+optind+2);
>  
> +	/* Set kernel alignment to 16M (CONFIG_PHYSICAL_ALIGN) */
> +	boot->hdr.kernel_alignment = 0x1000000;
> +
>  	/* Boot protocol version: 2.07 supports the fields for lguest. */
>  	boot->hdr.version = 0x207;
>  

Yeap, it worked! thx Russel!

Though I have another problem (probably it is caused by my mistake). I
created an image as you describe in Documentation/lguest/lguest.txt (the
cd image part, the link of xm-test is down :) ) and then this panic comes:


root at kvm-cslab:/home/sgerag/linux-2.6.38.8/Documentation/lguest#
./lguest 64m ../../vmlinux --block=/home/sgerag/rootfile
root=/dev/vda|tail -n 15
lguest: CRASH: VFS: Unable to mount root fs on unknown-block(254,0)
[    0.756407] Initalizing network drop monitor service
[    0.764113] List of all partitions:
[    0.764113] fe00         2097152 vda  driver: virtio_blk
[    0.789100]   fe01         2095104 vda1
00000000-0000-0000-0000-000000000vda1
[    0.789100] No filesystem could mount root, tried:  ext2
[    0.789100] Kernel panic - not syncing: VFS: Unable to mount root fs
on unknown-block(254,0)
[    0.789100] Pid: 1, comm: swapper Not tainted 2.6.38.8 #7
[    0.789100] Call Trace:
[    0.789100]  [<c128bc23>] ? panic+0x4d/0x137
[    0.789100]  [<c13d1b94>] ? mount_block_root+0x1f2/0x213
[    0.789100]  [<c13d1bee>] ? mount_root+0x39/0x4d
[    0.789100]  [<c13d1d10>] ? prepare_namespace+0x10e/0x13e
[    0.789100]  [<c13d13ae>] ? kernel_init+0x18d/0x198
[    0.789100]  [<c13d1221>] ? kernel_init+0x0/0x198
[    0.789100]  [<c10034fe>] ? kernel_thread_helper+0x6/0x10


I know it is a mistake of mine. I did a little web search but no
solution worked out for me. I don't want to disturb you further though!
Thx again!

- -- 
Stefanos
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOMF7IAAoJEDvFaozEhZubQe4H/jJfSrBuYriQ3oPPdjP1n5kG
kvYe7FJOuZ84ZjZlakmeOiLd8Zcim1XiKO0zoIMWHK8MyTXEVkZvM4GY6NEMIrFP
YN2LDCmppL3lz3LCZfJmyG5hBnxESA1fZmIDs7cKAsxAtAXlnTgVjoA5qtYsopB4
BlAFaBV0LcX7f3bgA9767QZ7GkrNn4vMHyYbB0KNbPVaaKwxPOXh2tSA7+IaYTeE
IOoZpbxhsMjq7BctSbmw0KaGQ5xi1QHsB7I2pkQYDgN/7Tyj2PeGM5YpFmOvUArY
hQAT3IV/pfG1pv4jkHADm90htve4is4oZVSD4isRNnV5Y5l4uXaj+g5Jt/oyJ7M=
=3hBB
-----END PGP SIGNATURE-----


More information about the Lguest mailing list