[Lguest] question about lguest inside kvm

Rusty Russell rusty at rustcorp.com.au
Wed Jul 27 13:43:23 EST 2011


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;
 


More information about the Lguest mailing list