Hypercalls from HVM guests (1/2)
RFC PATCH 1/1 Hypercalls from HVM guests (1/2)
Here is the main hypervisor/hvmloader patch.
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 (®s, 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 (®s);break ; -case EXIT_REASON_VMCALL :case EXIT_REASON_VMCLEAR :case EXIT_REASON_VMLAUNCH :case EXIT_REASON_VMPTRLD :
xen-unstable-test64/./xen/arch/x86/usercopy.c renamed from xen/arch/x86/usercopy.c +12 -0
@@ -91,6 +91,8 @@return (unsigned )__n; } +#include <asm/hvm/support.h> +/** * copy_to_user: - Copy a block of data into user space. * @to: Destination address, in user space.
@@ -107,6 +109,11 @@unsigned long copy_to_user (void __user *to,const void *from,unsigned n) { +if (hvm_guest (current) && !hypervisor_va (to)) { +if (hvm_copy ((void *)from, (unsigned long )to, n,HVM_COPY_OUT )) +return 0 ; +return n; + }if (access_ok (to, n)) n =__copy_to_user (to, from, n);return n;
@@ -131,6 +138,11 @@unsigned long copy_from_user (void *to,const void __user *from,unsigned n) { +if (hvm_guest (current) && !hypervisor_va (from)) { +if (hvm_copy ((void *)to, (unsigned long )from, n,HVM_COPY_IN )) +return 0 ; +return n; + }if (access_ok (from, n)) n =__copy_from_user (to, from, n);else
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-unstable-test64/./xen/include/public/arch-x86_32.h renamed from xen/include/public/arch-x86_32.h +2 -0
@@ -80,6 +80,8 @@#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)#endif +#define hypervisor_va (va) (__HYPERVISOR_VIRT_START <= (unsigned long)(va)) +#ifndef machine_to_phys_mapping#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)#endif
xen-unstable-test64/./xen/include/public/arch-x86_64.h renamed from xen/include/public/arch-x86_64.h +3 -0
@@ -89,6 +89,9 @@#define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END)#endif +#define hypervisor_va (va) (__HYPERVISOR_VIRT_START <= (unsigned long)(va) && \ + (unsigned long)(va) < __HYPERVISOR_VIRT_END) +/* Maximum number of virtual CPUs in multi-processor guests. */ #define MAX_VIRT_CPUS 32
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Steve Ofsthun
Here is the main hypervisor/hvmloader patch.
Signed-off-by Steve Ofsthun <[email protected]>
All in-memory hypercall arguments are now accessed via copy_to/from_guest and copy_to/from_user are no longer used for that purpose at all. That given, can the special path for HVM guests be made in copy_to/from_guest (no need to make conditional on hypervisor_va()) and not touch copy_to/from_user?
-- Keir
Quoted 8 lines · Keir Fraser
Quoted 3 lines · Steve Ofsthun
Here is the main hypervisor/hvmloader patch.
Signed-off-by Steve Ofsthun <[email protected]>All in-memory hypercall arguments are now accessed via copy_to/from_guest and copy_to/from_user are no longer used for that purpose at all. That given, can the special path for HVM guests be made in copy_to/from_guest (no need to make conditional on
hypervisor_va()) and not touch copy_to/from_user?
Yes, that sounds right. I'll put together an updated patch.
Thanks,
Steve
Signature · 1 line
Steve Ofsthun - Virtual Iron Software, Inc.
RFC PATCH 1/1 Hypercalls from HVM guests (1/2) [RESUBMIT]
In reply to Steve OfsthunHere is the updated main hypervisor/hvmloader patch.
- copy_to/from_user changes were moved to copy_to/from_guest.
- hypervisor_va() macro changes were removed
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 (®s, 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 (®s);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