Skip to contentSkip to conversation

Lguest for 2.6.21

RELEASE Rusty Russell 3 participants 21 messages May 2, 2007 – May 4, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi all,

Lguest is a simple hypervisor which runs Linux under Linux, without
needing VT hardware.

Two people asked if I had a version of lguest which worked on
other-than-bleeding-edge-mm kernels, so I did a backport of the latest version to 2.6.21.

	http://lguest.ozlabs.org/lguest-2.6.21-254.patch.gz

See Documentation/lguest/lguest.txt for how to run, drivers/lguest/README for the draft code documentation journey.

Bug or even success reports always welcome!
Rusty.

Quickstart:

$ cd linux-2.6.21
$ zcat /tmp/lguest-2.6.21-254.patch.gz | patch -p1
$ make
	- Say "y" to CONFIG_EXPERIMENTAL, "m" to CONFIG_LGUEST.
$ make modules_install
$ make -C Documentation/lguest
$ sudo Documentation/lguest/lguest --block=<some-convenient-raw-image> \
	128 vmlinux root=/dev/lgba

Three ^C's within one second will kill the guest.

#1 lore raw

Hi Rusty!

I found you forgot to check the return value of copy_from_user, and here is the fix for drivers/lguest/interrupts_and_traps.c.

---

drivers/lguest/interrupts_and_traps.c renamed from drivers/lguest/interrupts_and_traps.c.orig +2 -1
@@ -75,7 +75,8 @@ void maybe_do_interrupt(struct lguest *l
 		set_bit(0, lg->irqs_pending);
 
 	/* Mask out any interrupts they have blocked. */
-	copy_from_user(&blk, lg->lguest_data->blocked_interrupts, sizeof(blk));
+	if (copy_from_user(&blk, lg->lguest_data->blocked_interrupts, sizeof(blk)))
+		return;
 	bitmap_andnot(blk, lg->irqs_pending, blk, LGUEST_IRQS);
 
 	irq = find_first_bit(blk, LGUEST_IRQS);
#2 lore raw
In reply to Rusty Russell

Hi Rusty!

I found you forgot to check the return value of copy_from_user, and here is the fix for drivers/lguest/interrupts_and_traps.c.

---

drivers/lguest/interrupts_and_traps.c renamed from drivers/lguest/interrupts_and_traps.c.orig +2 -1
@@ -75,7 +75,8 @@ void maybe_do_interrupt(struct lguest *l
 		set_bit(0, lg->irqs_pending);
 
 	/* Mask out any interrupts they have blocked. */
-	copy_from_user(&blk, lg->lguest_data->blocked_interrupts, sizeof(blk));
+	if (copy_from_user(&blk, lg->lguest_data->blocked_interrupts, sizeof(blk)))
+		return;
 	bitmap_andnot(blk, lg->irqs_pending, blk, LGUEST_IRQS);
 
 	irq = find_first_bit(blk, LGUEST_IRQS);
#3 lore raw
Quoted 4 lines · WANG Cong

Hi Rusty!

I found you forgot to check the return value of copy_from_user, and here is the fix for drivers/lguest/interrupts_and_traps.c.

Also this one, in drivers/lguest/hypercalls.c.

---

drivers/lguest/hypercalls.c renamed from drivers/lguest/hypercalls.c.orig +2 -1
@@ -102,7 +102,8 @@ static void do_async_hcalls(struct lgues
 	unsigned int i;
 	u8 st[LHCALL_RING_SIZE];
 
-	copy_from_user(&st, &lg->lguest_data->hcall_status, sizeof(st));
+	if (copy_from_user(&st, &lg->lguest_data->hcall_status, sizeof(st)))
+		return;
 	for (i = 0; i < ARRAY_SIZE(st); i++) {
 		struct lguest_regs regs;
 		unsigned int n = lg->next_hcall;
#4 lore raw
In reply to WANG Cong
Quoted 4 lines · WANG Cong

Hi Rusty!

I found you forgot to check the return value of copy_from_user, and here is the fix for drivers/lguest/interrupts_and_traps.c.

Also this one, in drivers/lguest/hypercalls.c.

---

drivers/lguest/hypercalls.c renamed from drivers/lguest/hypercalls.c.orig +2 -1
@@ -102,7 +102,8 @@ static void do_async_hcalls(struct lgues
 	unsigned int i;
 	u8 st[LHCALL_RING_SIZE];
 
-	copy_from_user(&st, &lg->lguest_data->hcall_status, sizeof(st));
+	if (copy_from_user(&st, &lg->lguest_data->hcall_status, sizeof(st)))
+		return;
 	for (i = 0; i < ARRAY_SIZE(st); i++) {
 		struct lguest_regs regs;
 		unsigned int n = lg->next_hcall;
#5 lore raw
In reply to WANG Cong
Quoted 6 lines · WANG Cong

Hi Rusty!

I found you forgot to check the return value of copy_from_user, and here is the fix for drivers/lguest/interrupts_and_traps.c.

Hi Wang!

Thanks for the patch. This omission (in several places) was
deliberate. We can't really do anything sensible if the user unmapped the page. I assume you saw a gcc warning from this code?

We could also use lgread() in these places which does this check and
kills the guest if something goes wrong. I'll check the benchmarks to make sure the (slight) extra overhead doesn't cause a regression...

Thanks!
Rusty.

#6 lore raw
In reply to WANG Cong
Quoted 6 lines · WANG Cong

Hi Rusty!

I found you forgot to check the return value of copy_from_user, and here is the fix for drivers/lguest/interrupts_and_traps.c.

Hi Wang!

Thanks for the patch. This omission (in several places) was
deliberate. We can't really do anything sensible if the user unmapped the page. I assume you saw a gcc warning from this code?

We could also use lgread() in these places which does this check and
kills the guest if something goes wrong. I'll check the benchmarks to make sure the (slight) extra overhead doesn't cause a regression...

Thanks!
Rusty.

#7 lore raw
Quoted 6 lines · Rusty Russell
Quoted 5 lines · WANG Cong

Hi Rusty!

I found you forgot to check the return value of copy_from_user, and here is the fix for drivers/lguest/interrupts_and_traps.c.

Quoted 7 lines
Quoted 1 line

Hi Wang!

Thanks for the patch. This omission (in several places) was
deliberate. We can't really do anything sensible if the user unmapped the page. I assume you saw a gcc warning from this code?

Yes. In fact, I got two warnings, another one is in drivers/lguest/hypercalls.c.

If I understand you correctly, you mean we can do nothing useful to fix it?

Quoted 7 lines

We could also use lgread() in these places which does this check and
kills the guest if something goes wrong. I'll check the benchmarks to make sure the (slight) extra overhead doesn't cause a regression...

Thanks!
Rusty.

I have sent a mail which described the errors I got when comipling Documentation/lguest/lguest.c. But it seems that you didn't receive it (it didn't appear in lkml.org neither!). It is that, I have already made my .config as you suggested, but I still can't compile Documentation/lguest/lguest.c, errors are:

lguest.c: In function 'add_to_bridge':
lguest.c:779: error: 'SIOCBRADDIF' undeclared (first use in this function) lguest.c:779: error: (Each undeclared identifier is reported only once lguest.c:779: error: for each function it appears in.)

Can you help me out?

Thanks!

#8 lore raw
In reply to Rusty Russell
Quoted 6 lines · Rusty Russell
Quoted 5 lines · WANG Cong

Hi Rusty!

I found you forgot to check the return value of copy_from_user, and here is the fix for drivers/lguest/interrupts_and_traps.c.

Quoted 7 lines
Quoted 1 line

Hi Wang!

Thanks for the patch. This omission (in several places) was
deliberate. We can't really do anything sensible if the user unmapped the page. I assume you saw a gcc warning from this code?

Yes. In fact, I got two warnings, another one is in drivers/lguest/hypercalls.c.

If I understand you correctly, you mean we can do nothing useful to fix it?

Quoted 7 lines

We could also use lgread() in these places which does this check and
kills the guest if something goes wrong. I'll check the benchmarks to make sure the (slight) extra overhead doesn't cause a regression...

Thanks!
Rusty.

I have sent a mail which described the errors I got when comipling Documentation/lguest/lguest.c. But it seems that you didn't receive it (it didn't appear in lkml.org neither!). It is that, I have already made my .config as you suggested, but I still can't compile Documentation/lguest/lguest.c, errors are:

lguest.c: In function 'add_to_bridge':
lguest.c:779: error: 'SIOCBRADDIF' undeclared (first use in this function) lguest.c:779: error: (Each undeclared identifier is reported only once lguest.c:779: error: for each function it appears in.)

Can you help me out?

Thanks!

#9 lore raw
Quoted 8 lines · WANG Cong
Quoted 3 lines · Rusty Russell

Thanks for the patch. This omission (in several places) was
deliberate. We can't really do anything sensible if the user unmapped the page. I assume you saw a gcc warning from this code?

Yes. In fact, I got two warnings, another one is in drivers/lguest/hypercalls.c.

If I understand you correctly, you mean we can do nothing useful to fix it?

We can, but we can ignore those warnings for the moment; they're harmless.

Quoted 3 lines

I have sent a mail which described the errors I got when comipling Documentation/lguest/lguest.c. But it seems that you didn't receive it (it didn't appear in lkml.org neither!).

Hmm, no, I didn't get it here either 8(

Quoted 7 lines

It is that, I have already made my .config as you suggested, but I
still can't compile Documentation/lguest/lguest.c, errors are:

lguest.c: In function 'add_to_bridge':
lguest.c:779: error: 'SIOCBRADDIF' undeclared (first use in this function) lguest.c:779: error: (Each undeclared identifier is reported only once lguest.c:779: error: for each function it appears in.)

Ah, perhaps older libc headers? Can you try adding this to the top of Documentation/lguest/lguest.c after the #define BRIDGE_PFX "bridge:"

#ifndef SIOCBRADDIF
#define SIOCBRADDIF 0x89a2 /* add interface to bridge */
#endif

Thanks,
Rusty.

#10 lore raw
In reply to WANG Cong
Quoted 8 lines · WANG Cong
Quoted 3 lines · Rusty Russell

Thanks for the patch. This omission (in several places) was
deliberate. We can't really do anything sensible if the user unmapped the page. I assume you saw a gcc warning from this code?

Yes. In fact, I got two warnings, another one is in drivers/lguest/hypercalls.c.

If I understand you correctly, you mean we can do nothing useful to fix it?

We can, but we can ignore those warnings for the moment; they're harmless.

Quoted 3 lines

I have sent a mail which described the errors I got when comipling Documentation/lguest/lguest.c. But it seems that you didn't receive it (it didn't appear in lkml.org neither!).

Hmm, no, I didn't get it here either 8(

Quoted 7 lines

It is that, I have already made my .config as you suggested, but I
still can't compile Documentation/lguest/lguest.c, errors are:

lguest.c: In function 'add_to_bridge':
lguest.c:779: error: 'SIOCBRADDIF' undeclared (first use in this function) lguest.c:779: error: (Each undeclared identifier is reported only once lguest.c:779: error: for each function it appears in.)

Ah, perhaps older libc headers? Can you try adding this to the top of Documentation/lguest/lguest.c after the #define BRIDGE_PFX "bridge:"

#ifndef SIOCBRADDIF
#define SIOCBRADDIF 0x89a2 /* add interface to bridge */
#endif

Thanks,
Rusty.

#11 lore raw
Quoted 6 lines · Rusty Russell
Quoted 5 lines · WANG Cong
Quoted 3 lines · Rusty Russell

Thanks for the patch. This omission (in several places) was
deliberate. We can't really do anything sensible if the user unmapped the page. I assume you saw a gcc warning from this code?

Quoted 6 lines
Quoted 3 lines

Yes. In fact, I got two warnings, another one is in drivers/lguest/hypercalls.c.

If I understand you correctly, you mean we can do nothing useful to fix it?

We can, but we can ignore those warnings for the moment; they're harmless.

OK.

Quoted 18 lines
Quoted 4 lines

I have sent a mail which described the errors I got when comipling Documentation/lguest/lguest.c. But it seems that you didn't receive it (it didn't appear in lkml.org neither!).

Hmm, no, I didn't get it here either 8(

Quoted 7 lines

It is that, I have already made my .config as you suggested, but I
still can't compile Documentation/lguest/lguest.c, errors are:

lguest.c: In function 'add_to_bridge':
lguest.c:779: error: 'SIOCBRADDIF' undeclared (first use in this function) lguest.c:779: error: (Each undeclared identifier is reported only once lguest.c:779: error: for each function it appears in.)

Ah, perhaps older libc headers? Can you try adding this to the top of Documentation/lguest/lguest.c after the #define BRIDGE_PFX "bridge:"

Quoted 6 lines

#ifndef SIOCBRADDIF
#define SIOCBRADDIF 0x89a2 /* add interface to bridge */
#endif

Thanks,
Rusty.

Yes, it works. Thanks very much for your pointing.

I have already found you also forgot some checking in this user-space code. I will fix them soon. ;)

Regards.
WANG Cong

#12 lore raw
In reply to Rusty Russell
Quoted 6 lines · Rusty Russell
Quoted 5 lines · WANG Cong
Quoted 3 lines · Rusty Russell

Thanks for the patch. This omission (in several places) was
deliberate. We can't really do anything sensible if the user unmapped the page. I assume you saw a gcc warning from this code?

Quoted 6 lines
Quoted 3 lines

Yes. In fact, I got two warnings, another one is in drivers/lguest/hypercalls.c.

If I understand you correctly, you mean we can do nothing useful to fix it?

We can, but we can ignore those warnings for the moment; they're harmless.

OK.

Quoted 18 lines
Quoted 4 lines

I have sent a mail which described the errors I got when comipling Documentation/lguest/lguest.c. But it seems that you didn't receive it (it didn't appear in lkml.org neither!).

Hmm, no, I didn't get it here either 8(

Quoted 7 lines

It is that, I have already made my .config as you suggested, but I
still can't compile Documentation/lguest/lguest.c, errors are:

lguest.c: In function 'add_to_bridge':
lguest.c:779: error: 'SIOCBRADDIF' undeclared (first use in this function) lguest.c:779: error: (Each undeclared identifier is reported only once lguest.c:779: error: for each function it appears in.)

Ah, perhaps older libc headers? Can you try adding this to the top of Documentation/lguest/lguest.c after the #define BRIDGE_PFX "bridge:"

Quoted 6 lines

#ifndef SIOCBRADDIF
#define SIOCBRADDIF 0x89a2 /* add interface to bridge */
#endif

Thanks,
Rusty.

Yes, it works. Thanks very much for your pointing.

I have already found you also forgot some checking in this user-space code. I will fix them soon. ;)

Regards.
WANG Cong

#13 lore raw
In reply to Rusty Russell
Quoted 5 lines · Rusty Russell

Hi all,

Lguest is a simple hypervisor which runs Linux under Linux, without
needing VT hardware.

Quoted 8 lines

Two people asked if I had a version of lguest which worked on
other-than-bleeding-edge-mm kernels, so I did a backport of the latest version to 2.6.21.

	http://lguest.ozlabs.org/lguest-2.6.21-254.patch.gz

See Documentation/lguest/lguest.txt for how to run, drivers/lguest/README for the draft code documentation journey.

Your lguest readme is quite lacking in the area of how to configure a guest kernel as opposed to the host kernel. More hand-holding, please.

Maybe it's obvious once I've actually applied the patch and run menuconfig, but I'm loathe to attempt anything that isn't a cake walk at my current loadavg, especially given the fits of blind rage trying to do anything nontrivial with Xen tends to provoke in me.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#14 lore raw
Quoted 8 lines · Matt Mackall
Quoted 4 lines · Rusty Russell
	http://lguest.ozlabs.org/lguest-2.6.21-254.patch.gz

See Documentation/lguest/lguest.txt for how to run, drivers/lguest/README for the draft code documentation journey.

Your lguest readme is quite lacking in the area of how to configure a guest kernel as opposed to the host kernel. More hand-holding, please.

Hi Matt!

Ah, that's because they are the same kernel. Turning on CONFIG_LGUEST
builds-in the parts needed to be a guest as well.

Thanks for pointing out that weakness. I will modify lguest.txt to make that clear.

Cheers,
Rusty.

#15 lore raw
In reply to Matt Mackall
Quoted 8 lines · Matt Mackall
Quoted 4 lines · Rusty Russell
	http://lguest.ozlabs.org/lguest-2.6.21-254.patch.gz

See Documentation/lguest/lguest.txt for how to run, drivers/lguest/README for the draft code documentation journey.

Your lguest readme is quite lacking in the area of how to configure a guest kernel as opposed to the host kernel. More hand-holding, please.

Hi Matt!

Ah, that's because they are the same kernel. Turning on CONFIG_LGUEST
builds-in the parts needed to be a guest as well.

Thanks for pointing out that weakness. I will modify lguest.txt to make that clear.

Cheers,
Rusty.

#16 lore raw
Quoted 10 lines · Rusty Russell
Quoted 8 lines · Matt Mackall
Quoted 4 lines · Rusty Russell
	http://lguest.ozlabs.org/lguest-2.6.21-254.patch.gz

See Documentation/lguest/lguest.txt for how to run, drivers/lguest/README for the draft code documentation journey.

Your lguest readme is quite lacking in the area of how to configure a guest kernel as opposed to the host kernel. More hand-holding, please.

Quoted 7 lines

Hi Matt!

Ah, that's because they are the same kernel. Turning on CONFIG_LGUEST
builds-in the parts needed to be a guest as well.

Thanks for pointing out that weakness. I will modify lguest.txt to make that clear.

Something like this:

Documentation/lguest/lguest.txt +4 -1
diff -r 940ec1c6ac5a Documentation/lguest/lguest.txt
@@ -23,7 +23,10 @@ Developer features:
 
 Running Lguest:
 
-- You will need to configure your kernel with the following options:
+- Lguest runs the same kernel as guest and host.  You can configure
+  them differently, but usually it's easiest not to.
+
+  You will need to configure your kernel with the following options:
 
   CONFIG_HIGHMEM64G=n ("High Memory Support" "64GB")[1]
   CONFIG_TUN=y/m ("Universal TUN/TAP device driver support")

Cheers,
Rusty.

#17 lore raw
In reply to Rusty Russell
Quoted 10 lines · Rusty Russell
Quoted 8 lines · Matt Mackall
Quoted 4 lines · Rusty Russell
	http://lguest.ozlabs.org/lguest-2.6.21-254.patch.gz

See Documentation/lguest/lguest.txt for how to run, drivers/lguest/README for the draft code documentation journey.

Your lguest readme is quite lacking in the area of how to configure a guest kernel as opposed to the host kernel. More hand-holding, please.

Quoted 7 lines

Hi Matt!

Ah, that's because they are the same kernel. Turning on CONFIG_LGUEST
builds-in the parts needed to be a guest as well.

Thanks for pointing out that weakness. I will modify lguest.txt to make that clear.

Something like this:

Documentation/lguest/lguest.txt +4 -1
diff -r 940ec1c6ac5a Documentation/lguest/lguest.txt
@@ -23,7 +23,10 @@ Developer features:
 
 Running Lguest:
 
-- You will need to configure your kernel with the following options:
+- Lguest runs the same kernel as guest and host.  You can configure
+  them differently, but usually it's easiest not to.
+
+  You will need to configure your kernel with the following options:
 
   CONFIG_HIGHMEM64G=n ("High Memory Support" "64GB")[1]
   CONFIG_TUN=y/m ("Universal TUN/TAP device driver support")

Cheers,
Rusty.

#18 lore raw
Quoted 8 lines · Rusty Russell
Quoted 7 lines · Rusty Russell
Quoted 6 lines · Matt Mackall
Quoted 4 lines · Rusty Russell
	http://lguest.ozlabs.org/lguest-2.6.21-254.patch.gz

See Documentation/lguest/lguest.txt for how to run, drivers/lguest/README for the draft code documentation journey.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

Your lguest readme is quite lacking in the area of how to configure a guest kernel as opposed to the host kernel. More hand-holding, please.

Hi Matt!

Ah, that's because they are the same kernel. Turning on CONFIG_LGUEST
builds-in the parts needed to be a guest as well.

Ok, I thought that might be a possibility.

Quoted 3 lines

-- You will need to configure your kernel with the following options:

+- Lguest runs the same kernel as guest and host.  You can configure
+  them differently, but usually it's easiest not to.

I take it both sides of the virtual device drivers are turned on by the lguest option?

For the purposes of kernel hacking, I'd want to boot into one build and repeatedly launch another build as a guest, thereby getting faster hack/build/test cycles than either qemu or full reboot. How tightly coupled are things here?

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#19 lore raw
Quoted 2 lines · Matt Mackall

I take it both sides of the virtual device drivers are turned on by the lguest option?

Yeah, to quote the code in drivers/lguest/lguest_bus.c:

/* At the moment we build all the drivers into the kernel because they're so
* simple: 8144 bytes for all three of them as I type this. And as the console
* really needs to be built in, it's actually only 3527 bytes for the network
* and block drivers.

Quoted 4 lines

For the purposes of kernel hacking, I'd want to boot into one build and repeatedly launch another build as a guest, thereby getting faster hack/build/test cycles than either qemu or full reboot. How tightly coupled are things here?

I do that all the time, too. The main issue is that we provide no ABI for lguest (at least, not yet), so if you actually change guest/host kernel version, you're on your own...

Thanks!
Rusty.

#20 lore raw
In reply to Matt Mackall
Quoted 2 lines · Matt Mackall

I take it both sides of the virtual device drivers are turned on by the lguest option?

Yeah, to quote the code in drivers/lguest/lguest_bus.c:

/* At the moment we build all the drivers into the kernel because they're so
* simple: 8144 bytes for all three of them as I type this. And as the console
* really needs to be built in, it's actually only 3527 bytes for the network
* and block drivers.

Quoted 4 lines

For the purposes of kernel hacking, I'd want to boot into one build and repeatedly launch another build as a guest, thereby getting faster hack/build/test cycles than either qemu or full reboot. How tightly coupled are things here?

I do that all the time, too. The main issue is that we provide no ABI for lguest (at least, not yet), so if you actually change guest/host kernel version, you're on your own...

Thanks!
Rusty.