Skip to contentSkip to conversation

Hypercalls from HVM guests

PATCH In review Steve Ofsthun 3 participants 5 messages Apr 21, 2006 – Apr 24, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Hypercalls from HVM guests

Here is the basic plumbing for hypercalls from HVM guests. The changes cover the following:

o Modify VMX VMCALL exit handler to call the generic hvm_hypercall()
o Modify SVM VMMCALL exit handler to safely handle VMMCALL for hvmloader else call the generic hvm_hypercall()
o Modify copy_[to/from]_guest to use hvm_copy() for hvm guests. Without this the hvm domain gets hung and eventually hangs dom0 as well.
o Modify hvmloader to use VMMCALL symbols from vmmcall.h.

With these changes you can make raw hypercalls from HVM guests.

Testing included 32/64 bit guests on both VMX hardware and SVM hardware.

Steve

Signature · 1 line
Steve Ofsthun - Virtual Iron Software, Inc.
xen-unstable-test64/./tools/firmware/hvmloader/hvmloader.c renamed from tools/firmware/hvmloader/hvmloader.c +3 -5
@@ -23,15 +23,13 @@
  */
 #include "roms.h"
 #include "../acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
+#include <asm/hvm/svm/vmmcall.h>
 
 /* memory map */
 #define VGABIOS_PHYSICAL_ADDRESS	0x000C0000
 #define	VMXASSIST_PHYSICAL_ADDRESS	0x000D0000
 #define	ROMBIOS_PHYSICAL_ADDRESS	0x000F0000
 
-/* invoke SVM's paged realmode support */
-#define SVM_VMMCALL_RESET_TO_REALMODE	0x00000001
-
 /*
  * C runtime start off
  */
@@ -138,7 +136,7 @@
         __asm__ __volatile__(
 		".byte 0x0F,0x01,0xD9"
                 : "=a" (eax)
-		: "a"(0x58454E00), /* XEN\0 key */
+		: "a"(VMMCALL_MAGIC), /* XEN\0 key */
 		  "b"(ebx), "c"(ecx), "d"(edx), "D"(edi), "S"(esi)
 	);
         return eax;
@@ -192,7 +190,7 @@
 	if (check_amd()) {
 		/* AMD implies this is SVM */
                 puts("SVM go ...\n");
-                vmmcall(SVM_VMMCALL_RESET_TO_REALMODE, 0, 0, 0, 0);
+                vmmcall(VMMCALL_RESET_TO_REALMODE, 0, 0, 0, 0);
 	} else {
 		puts("Loading VMXAssist ...\n");
 		memcpy((void *)VMXASSIST_PHYSICAL_ADDRESS,
xen-unstable-test64/./tools/firmware/hvmloader/Makefile renamed from tools/firmware/hvmloader/Makefile +1 -1
@@ -29,7 +29,7 @@
 LOADADDR = 0x100000
 
 DEFINES  =-DDEBUG
-XENINC   =-I$(XEN_ROOT)/tools/libxc
+XENINC   =-I$(XEN_ROOT)/tools/libxc -I$(XEN_ROOT)/xen/include
 
 OBJECTS	 = hvmloader.o acpi_madt.o 
 
xen-unstable-test64/./xen/arch/x86/hvm/hvm.c renamed from xen/arch/x86/hvm/hvm.c +88 -0

94 lines not on this page · raw message

xen-unstable-test64/./xen/arch/x86/hvm/svm/svm.c renamed from xen/arch/x86/hvm/svm/svm.c +28 -23

67 lines not on this page · raw message

xen-unstable-test64/./xen/arch/x86/hvm/vmx/vmx.c renamed from xen/arch/x86/hvm/vmx/vmx.c +2 -4
@@ -2207,16 +2207,15 @@
         __update_guest_eip(inst_len);
         break;
     }
-#if 0 /* keep this for debugging */
     case EXIT_REASON_VMCALL:
         __get_instruction_length(inst_len);
         __vmread(GUEST_RIP, &eip);
         __vmread(EXIT_QUALIFICATION, &exit_qualification);
 
-        hvm_print_line(v, regs.eax); /* provides the current domain */
+	hvm_hypercall(&regs, eip);
+
         __update_guest_eip(inst_len);
         break;
-#endif
     case EXIT_REASON_CR_ACCESS:
     {
         __vmread(GUEST_RIP, &eip);
@@ -2257,7 +2256,6 @@
     case EXIT_REASON_MWAIT_INSTRUCTION:
         __hvm_bug(&regs);
         break;
-    case EXIT_REASON_VMCALL:
     case EXIT_REASON_VMCLEAR:
     case EXIT_REASON_VMLAUNCH:
     case EXIT_REASON_VMPTRLD:
xen-unstable-test64/./xen/include/asm-x86/guest_access.h renamed from xen/include/asm-x86/guest_access.h +55 -8

114 lines not on this page · raw message

xen-unstable-test64/./xen/include/asm-x86/hvm/support.h renamed from xen/include/asm-x86/hvm/support.h +4 -0
@@ -149,4 +149,8 @@
 extern void hvm_print_line(struct vcpu *v, const char c);
 extern void hlt_timer_fn(void *data);
 
+typedef unsigned long (*hypercall_ptr_t)(unsigned long, ...);
+extern hypercall_ptr_t hypercall_table[];
+extern void hvm_hypercall(struct cpu_user_regs *pregs, unsigned long rip);
+
 #endif /* __ASM_X86_HVM_SUPPORT_H__ */
xen-unstable-test64/./xen/include/asm-x86/hvm/svm/vmmcall.h renamed from xen/include/asm-x86/hvm/svm/vmmcall.h +3 -0
@@ -22,6 +22,9 @@
 #ifndef __ASM_X86_HVM_SVM_VMMCALL_H__
 #define __ASM_X86_HVM_SVM_VMMCALL_H__
 
+/* VMMCALL signature field */
+#define VMMCALL_MAGIC 0x58454E00 /* XEN\0 key */
+
 /* VMMCALL command fields */
 #define VMMCALL_CODE_CPL_MASK     0xC0000000
 #define VMMCALL_CODE_MBZ_MASK     0x3FFF0000

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 1 line · Steve Ofsthun

With these changes you can make raw hypercalls from HVM guests.

You probably want a separate hypercall table from that of paravirtualized guests, for several reasons:
1. Some hypercalls will not be HVM aware and are probably unsafe to
run from an HVM context
2. Some hypercalls may want different implementations (or at least a
wrapper) on HVM
3. On 64-bit, you may even want a separate 32-bit hypercall table
containing wrappers that interface between 32-bit callers and the core 64-bit hypercall functions.

(1) is most important right now -- we should only permit the hypercalls we need, and audit any others before they are added to the list.

-- Keir

#2 lore raw
Quoted 8 lines · Keir Fraser
Quoted 1 line · Steve Ofsthun

With these changes you can make raw hypercalls from HVM guests.

You probably want a separate hypercall table from that of paravirtualized guests, for several reasons:
1. Some hypercalls will not be HVM aware and are probably unsafe to run
from an HVM context

Which hypercalls in particular should be excluded from HVM use?

A number will require changes to perform properly for HVM guests. This work will require this patch. In particular, follow on patches for grant table operations, event channel operations, and memory operations all require this initial groundwork.

Are you concerned that enabling this patch will make the hypervisor more vulnerable in some way?

Shouldn't the hypervisor interface be made robust enough to deal with HVM guests (as well as malfunctioning paravirtualized guests)?

If it is just a matter of testing, I could filter all HVM requests for now and only allow requests through that have been exercised. As additional patches are submitted, we could enable new hypercalls to be passed through the HVM interface.

Quoted 2 lines

2. Some hypercalls may want different implementations (or at least a
wrapper) on HVM

If this becomes necessary, it can be added to the interface.

Quoted 2 lines

3. On 64-bit, you may even want a separate 32-bit hypercall table
containing wrappers that interface between 32-bit callers and the core 64-bit hypercall functions.

At the moment, all of this can be dealt with in HVM DomU code. By doing it there, we can avoid explicit parameter copying on every hypercall. The 32-bit vs. 64-bit hypercall interface variations are not unique to HVM code. Adding conversion interfaces in the hypervisor is only one solution to this problem. The interfaces themselves could be made size invariant. Except for backward compatibility, the 32-bit interfaces could be made identical to the 64-bit interfaces using proper data typing and explicit data alignment.

Quoted 1 line

(1) is most important right now -- we should only permit the hypercalls we need, and audit any others before they are added to the list.

OK, is a bitmap filter of the inbound requests sufficient? For this patch, I'll just filter every hypercall except HYPERVISOR_xen_version() and return ENOSYS?

Steve

Signature · 1 line
Steve Ofsthun - Virtual Iron Software, Inc.
#3 lore raw
Quoted 4 lines · Steve Ofsthun
Quoted 1 line

(1) is most important right now -- we should only permit the hypercalls we need, and audit any others before they are added to the list.

OK, is a bitmap filter of the inbound requests sufficient? For this patch, I'll just filter every hypercall except HYPERVISOR_xen_version() and return ENOSYS?

That would be okay, but also:
1. VMMCALL_MAGIC needs to go, and be replaced by a first-class
hypercall (HYPERVISOR_hvm_op maybe). Either by having an hvm-specific hypercall table, or by adding to the main jump table and have the hvm_op function itself bail on non-hvm guests.
2. guest_handle_okay() should always return TRUE for an hvm guest
3. get rid of the __user modifiers in your new functions in
guest_access.h. We don't use those in Xen (except in a few files taken fairly directly from Linux).

-- Keir

#4 lore raw
In reply to Steve Ofsthun
Quoted 6 lines · Steve Ofsthun
Quoted 3 lines

3. On 64-bit, you may even want a separate 32-bit hypercall table
containing wrappers that interface between 32-bit callers and the

core

Quoted 1 line

64-bit hypercall functions.

Quoted 13 lines

At the moment, all of this can be dealt with in HVM DomU code. By doing it
there, we can avoid explicit parameter copying on every hypercall. The 32-bit
vs. 64-bit hypercall interface variations are not unique to HVM code. Adding
conversion interfaces in the hypervisor is only one solution to this problem.
The interfaces themselves could be made size invariant. Except for backward
compatibility, the 32-bit interfaces could be made identical to the 64-bit
interfaces using proper data typing and explicit data alignment.

Sounds like a good idea to me... ;)

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center