[Lguest] [PATCH 0/2] Add support for KVM hypercalls mechanism

Matias Zabaljauregui zabaljauregui at gmail.com
Sun Mar 15 02:33:23 EST 2009


Hi! 

this patches (2.6.29-rc8) add support for KVM hypercall mechanism.

The first one [1/2] is the previously accepted "kvm hypercalls" patch, including Rusty's comments (http://ozlabs.org/pipermail/lguest/2008-October/001280.html).
Tested with "vmcall" and "int 0x1f" (modified) linux guests. 

It should be noted here that although we keep supporting the "int 0x1f" guests, we changed the hypercall args registers in order
to be KVM-compatible. Then, old-style guests should change argument registers every time they appear explicitly mentioned in code. 
For example, in "old" Linux guests, I had to replace %edx with %ebx in arch/x86/lguest/i386_head.S, 
so the host reads the proper struct lguest_data address.

A little patch with the corrections for making old-style guests (vanilla 2.6.29-rc8) compatible with new kvm-style hypercall lguest implementation (patch  1/2)
is appended next ONLY FOR REFERENCE. It could help to other guests developers to study the few changes that are needed:


diff --git a/arch/x86/include/asm/lguest_hcall.h b/arch/x86/include/asm/lguest_hcall.h
index 4389442..de9cbb8 100644
--- a/arch/x86/include/asm/lguest_hcall.h
+++ b/arch/x86/include/asm/lguest_hcall.h
@@ -49,7 +49,7 @@ hcall(unsigned long call,
 		     /* The call in %eax (aka "a") might be overwritten */
 		     : "=a"(call)
 		       /* The arguments are in %eax, %edx, %ebx & %ecx */
-		     : "a"(call), "d"(arg1), "b"(arg2), "c"(arg3)
+		     : "a"(call), "b"(arg1), "c"(arg2), "d"(arg3)
 		       /* "memory" means this might write somewhere in memory.
 			* This isn't true for all calls, but it's safe to tell
 			* gcc that it might happen so it doesn't get clever. */
@@ -64,7 +64,7 @@ hcall(unsigned long call,
 #define LHCALL_RING_SIZE 64
 struct hcall_args {
 	/* These map directly onto eax, ebx, ecx, edx in struct lguest_regs */
-	unsigned long arg0, arg2, arg3, arg1;
+	unsigned long arg0, arg1, arg2, arg3;
 };
 
 #endif /* !__ASSEMBLY__ */
diff --git a/arch/x86/lguest/i386_head.S b/arch/x86/lguest/i386_head.S
index 10b9bd3..32bd90e 100644
--- a/arch/x86/lguest/i386_head.S
+++ b/arch/x86/lguest/i386_head.S
@@ -27,7 +27,7 @@ ENTRY(lguest_entry)
 	/* We make the "initialization" hypercall now to tell the Host about
 	 * us, and also find out where it put our page tables. */
 	movl $LHCALL_LGUEST_INIT, %eax
-	movl $lguest_data - __PAGE_OFFSET, %edx
+	movl $lguest_data - __PAGE_OFFSET, %ebx
 	int $LGUEST_TRAP_ENTRY
 
 	/* Set up the initial stack so we can run C code. */


----



The second patch [2/2] adds support for 4 args KVM hypercall (useful for PAE and eventually for 64bits support)
I've been playing with 4 args dummy hypercalls and seems ok

Applying this one will yield "arch/x86/lguest/boot.c:174: warning: ‘lazy_hcall4’ defined but not used" message during compilation,
but this should disappear as soon as PAE patch is ready (still hunting a disgusting bug in my code, anyone interested in helping ? )

With patch [2/2] applied, you can only run other guests if, in addition to the changes mentioned previously (and shown in the reference patch), 
you extend struct hcall_args (in other guest code) to include arg4 member. Otherwise, the array 

                       struct hcall_args hcalls[LHCALL_RING_SIZE];

embedded in struct lguest_data differ in size so, for example, when the host tries to access the .syscall_vec member, it fetches the wrong value, 
and kills the guest with the "bad syscall vector" message. 

And, of course, other guests will have to implement their side of 4 arguments hypercalls, if they want this functionality.





Comments and corrections are highly appreciated

regards, 

Matias





More information about the Lguest mailing list