Initial support for Microsoft Hyper-V
cover Initial support for Microsoft Hyper-V
Enable some basic Hyper-V enlightenment functionalites, including relaxed timing, spinlock, and virtual APIC.
Vadim Rozenfeld (7):
[hyper-v] Add hyper-v parameters block.
[hyper-v] add hyper-v placeholders.
[hyper-v] make Hyper-V option configurable.
[hyper-v] hyper-v parameters
[hyper-v] hyper-v helper functions
[hyper-v] parse hyper-v parameters.
[hyper-v] init hyper-v cpuid leafs
Makefile.target | 1 + configure | 11 +++++++++ hyperv.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hyperv.h | 19 ++++++++++++++++ qemu-config.c | 19 ++++++++++++++++ qemu-config.h | 1 + qemu-options.hx | 23 +++++++++++++++++++ target-i386/kvm.c | 53 +++++++++++++++++++++++++++++++++++++++++++- vl.c | 12 ++++++++++ 9 files changed, 201 insertions(+), 1 deletions(-) create mode 100644 hyperv.c create mode 100644 hyperv.h
Signature · 1 line
1.7.4.4
RFC PATCH 1/7 Add hyper-v parameters block.
--- qemu-options.hx | 23 +++++++++++++++++++++++ vl.c | 2 ++ 2 files changed, 25 insertions(+), 0 deletions(-)
qemu-options.hx +23 -0
@@ -2483,6 +2483,29 @@ DEF("kvm-shadow-memory", HAS_ARG, QEMU_OPTION_kvm_shadow_memory, " allocate MEGABYTES for kvm mmu shadowing\n", QEMU_ARCH_I386) +DEF("hyperv", HAS_ARG, QEMU_OPTION_hyperv, + "-hyperv [vapic=on|off][,spinlock=retries][,wd=on|off]\n" + " enable Hyper-V Enlightenment\n", + QEMU_ARCH_ALL) +STEXI +@item -hyperv +@findex -hyperv +@item vapic=@var{vapic} +@var{vapic} is "on" or "off" and allows for using virtual APIC. +Default is "off". +@findex vapic +@item spinlock=@var{spinlock} +@var{spinlock} is a recommended number of attempts to retry +a spinlock failure befor notifying the hypervisor. +Default is 0xFFFFFFFF (never to retry). +@findex spinlock +:@item wd=@var{wd} +@var{wd} is "on" or "off" and recommends using relaxed timing. +Default is "off" +@findex wd +Simulate Hyper-V Enlightenment. Disable by default. +ETEXI + HXCOMM This is the last statement. Insert new options before this line! STEXI @end table
vl.c +2 -0
@@ -3185,6 +3185,8 @@ int main(int argc, char **argv, char **envp)fclose (fp);break ; } +case QEMU_OPTION_hyperv: +break ;default :os_parse_cmd_args (popt->index, optarg); }
Signature · 1 line
1.7.4.4
RFC PATCH 2/7 add hyper-v placeholders.
In reply to Vadim Rozenfeld--- hyperv.c | 3 +++ hyperv.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 0 deletions(-) create mode 100644 hyperv.c create mode 100644 hyperv.h
hyperv.c new file +3 -0
@@ -0,0 +1,3 @@ +#include "hyperv.h" +#include "qemu-common.h" +
hyperv.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef QEMU_HW_HYPERV_H +#define QEMU_HW_HYPERV_H 1 +/* +* public hyper-v header +*/ + +#include <asm/hyperv.h> + +#endif /* QEMU_HW_HYPERV_H */ +
Signature · 1 line
1.7.4.4
RFC PATCH 3/7 make Hyper-V option configurable.
In reply to Vadim Rozenfeld--- Makefile.target | 1 + configure | 11 +++++++++++ 2 files changed, 12 insertions(+), 0 deletions(-)
Makefile.target +1 -0
@@ -199,6 +199,7 @@ obj-$(CONFIG_VHOST_NET) += vhost.o obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o obj-$(CONFIG_KVM) += kvm.o kvm-all.o obj-$(CONFIG_NO_KVM) += kvm-stub.o +obj-$(CONFIG_HYPERV) += hyperv.o obj-y += memory.o LIBS+=-lz
configure +11 -0
@@ -150,6 +150,7 @@ debug="no" strip_opt="yes" bigendian="no" mingw32="no" +hyperv="no" EXESUF="" prefix="/usr/local" mandir="\${prefix}/share/man"
@@ -762,6 +763,10 @@ for opt do ;; --enable-vhost-net) vhost_net="yes" ;; + --disable-hyperv) hyperv="no" + ;; + --enable-hyperv) hyperv="yes" + ;; --disable-opengl) opengl="no" ;; --enable-opengl) opengl="yes"
@@ -1062,6 +1067,8 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" +echo " --enable-hyperv enable Hyper-V support" +echo " --disable-hyperv disable Hyper-V support" echo " --enable-trace-backend=B Set trace backend" echo " Available backends:" $("$source_path"/scripts/tracetool --list-backends) echo " --with-trace-file=NAME Full PATH,NAME of file to store traces"
@@ -2737,6 +2744,7 @@ echo "madvise $madvise" echo "posix_madvise $posix_madvise" echo "uuid support $uuid" echo "vhost-net support $vhost_net" +echo "Hyper-V support $hyperv" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-<pid>" echo "spice support $spice"
@@ -3424,6 +3432,9 @@ case "$target_arch2" in if test $kvm_cap_device_assignment = "yes" ; then echo "CONFIG_KVM_DEVICE_ASSIGNMENT=y" >> $config_target_mak fi + if test "$hyperv" = "yes" ; then + echo "CONFIG_HYPERV=y" >> $config_target_mak + fi fi esac if test "$target_bigendian" = "yes" ; then
Signature · 1 line
1.7.4.4
RFC PATCH 4/7 hyper-v parameters
In reply to Vadim Rozenfeld--- hyperv.c | 16 ++++++++++++++++ hyperv.h | 2 ++ qemu-config.c | 19 +++++++++++++++++++ qemu-config.h | 1 + 4 files changed, 38 insertions(+), 0 deletions(-)
hyperv.c +16 -0
@@ -1,3 +1,19 @@#include "hyperv.h" #include "qemu-common.h" +#include "qemu-option.h" +#include "qemu-config.h" +void hyperv_init (void ) +{ +QemuOpts *opts =QTAILQ_FIRST (&qemu_hyperv_opts.head); + +if (!opts) { +return ; + } +} + +static void hyperv_initialize (void ) +{ +hyperv_init (); +} +device_init (hyperv_initialize);
hyperv.h +2 -0
@@ -6,5 +6,7 @@#include <asm/hyperv.h> +void hyperv_init (void ); +#endif /* QEMU_HW_HYPERV_H */
qemu-config.c +19 -0
@@ -512,6 +512,24 @@ QemuOptsList qemu_boot_opts = { }, }; +QemuOptsList qemu_hyperv_opts = { + .name ="hyperv" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_hyperv_opts.head), + .desc = { + { + .name ="vapic" , + .type =QEMU_OPT_BOOL , + }, { + .name ="wd" , + .type =QEMU_OPT_BOOL , + }, { + .name ="spinlock" , + .type =QEMU_OPT_NUMBER , + }, + {/* end of list */ } + }, +}; +static QemuOptsList *vm_config_groups[32 ] = { &qemu_drive_opts, &qemu_chardev_opts,
@@ -526,6 +544,7 @@ static QemuOptsList *vm_config_groups[32] = { &qemu_option_rom_opts, &qemu_machine_opts, &qemu_boot_opts, + &qemu_hyperv_opts, NULL, };
qemu-config.h +1 -0
@@ -4,6 +4,7 @@extern QemuOptsList qemu_fsdev_opts;extern QemuOptsList qemu_virtfs_opts;extern QemuOptsList qemu_spice_opts; +extern QemuOptsList qemu_hyperv_opts;QemuOptsList *qemu_find_opts (const char *group);void qemu_add_opts (QemuOptsList *list);
Signature · 1 line
1.7.4.4
RFC PATCH 5/7 hyper-v helper functions
In reply to Vadim Rozenfeld--- hyperv.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hyperv.h | 7 +++++++ 2 files changed, 51 insertions(+), 0 deletions(-)
hyperv.c +44 -0
@@ -3,6 +3,10 @@#include "qemu-option.h" #include "qemu-config.h" +static int hyperv_apic; +static int hyperv_wd; +static int hyperv_spinlock_attempts =HYPERV_SPINLOCK_NEVER_RETRY ; +void hyperv_init (void ) {QemuOpts *opts =QTAILQ_FIRST (&qemu_hyperv_opts.head);
@@ -10,6 +14,46 @@ void hyperv_init(void)if (!opts) {return ; } + + hyperv_spinlock_attempts =qemu_opt_get_number (opts,"spinlock" , +HYPERV_SPINLOCK_NEVER_RETRY + ); + hyperv_wd =qemu_opt_get_bool (opts,"wd" ,0 ); + hyperv_apic =qemu_opt_get_bool (opts,"vapic" ,0 ); + +} + +int hyperv_enabled (void ) +{ +return hyperv_hypercall_available () |hyperv_relaxed_timing (); +} + +int hyperv_hypercall_available (void ) +{ +if (hyperv_apic || + (hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_RETRY )) { +return 1 ; + } +return 0 ; +} + +int hyperv_relaxed_timing (void ) +{ +return !hyperv_wd; +} + +int hyperv_apic_recommended (void ) +{ +#ifdef KVM_CAP_IRQCHIP +return hyperv_apic; +#else +return 0 ; +#endif +} + +int hyperv_spinlock_retries (void ) +{ +return hyperv_spinlock_attempts; }static void hyperv_initialize (void )
hyperv.h +7 -0
@@ -6,7 +6,14 @@#include <asm/hyperv.h> +#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF +void hyperv_init (void ); +int hyperv_enabled (void ); +int hyperv_hypercall_available (void ); +int hyperv_relaxed_timing (void ); +int hyperv_apic_recommended (void ); +int hyperv_spinlock_retries (void );#endif /* QEMU_HW_HYPERV_H */
Signature · 1 line
1.7.4.4
RFC PATCH 6/7 parse hyper-v parameters.
In reply to Vadim Rozenfeld--- vl.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
vl.c +10 -0
@@ -3186,6 +3186,16 @@ int main(int argc, char **argv, char **envp)break ; }case QEMU_OPTION_hyperv: + olist =qemu_find_opts ("hyperv" ); +if (!olist) { +fprintf (stderr,"Hyper-V is not supported by this qemu build.\n" ); +exit (1 ); + } + opts =qemu_opts_parse (olist, optarg,0 ); +if (!opts) { +fprintf (stderr,"parse error: %s\n" , optarg); +exit (1 ); + }break ;default :os_parse_cmd_args (popt->index, optarg);
Signature · 1 line
1.7.4.4
RFC PATCH 7/7 init hyper-v cpuid leafs
In reply to Vadim Rozenfeld--- target-i386/kvm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 52 insertions(+), 1 deletions(-)
target-i386/kvm.c +52 -1
@@ -29,6 +29,7 @@#include "hw/pc.h" #include "hw/apic.h" #include "ioport.h" +#include "hyperv.h" //#define DEBUG_KVM
@@ -379,11 +380,21 @@ int kvm_arch_init_vcpu(CPUState *env) cpuid_i =0 ;/* Paravirtualization CPUIDs */ -memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); c = &cpuid_data.entries[cpuid_i++];memset (c,0 ,sizeof (*c)); c->function =KVM_CPUID_SIGNATURE ; +#ifndef CONFIG_HYPERV +memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); c->eax =0 ; +#else +if (!hyperv_enabled ()) { +memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); + c->eax =0 ; + }else { +memcpy (signature,"Microsoft Hv" ,12 ); + c->eax =HYPERV_CPUID_MIN ; + } +#endif c->ebx = signature[0 ]; c->ecx = signature[1 ]; c->edx = signature[2 ];
@@ -393,6 +404,46 @@ int kvm_arch_init_vcpu(CPUState *env) c->function =KVM_CPUID_FEATURES ; c->eax = env->cpuid_kvm_features &kvm_arch_get_supported_cpuid (s,KVM_CPUID_FEATURES ,0 ,R_EAX ); +#ifdef CONFIG_HYPERV +if (hyperv_enabled ()) { +memcpy (signature,"Hv#1\0\0\0\0\0\0\0\0" ,12 ); + c->eax = signature[0 ]; + + c = &cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_VERSION ; + c->eax =0x00001bbc ; + c->ebx =0x00060001 ; + + c = &cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_FEATURES ; +if (hyperv_relaxed_timing ()) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + } +if (hyperv_apic_recommended ()) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + c->eax |=HV_X64_MSR_APIC_ACCESS_AVAILABLE ; + } + + c = &cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_ENLIGHTMENT_INFO ; +if (hyperv_relaxed_timing ()) { + c->eax |=HV_X64_RELAXED_TIMING_RECOMMENDED ; + } +if (hyperv_apic_recommended ()) { + c->eax |=HV_X64_APIC_ACCESS_RECOMMENDED ; + } + c->ebx =hyperv_spinlock_retries (); + + c = &cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_IMPLEMENT_LIMITS ; + c->eax =0x40 ; + c->ebx =0x40 ; + } +#endif has_msr_async_pf_en = c->eax & (1 <<KVM_FEATURE_ASYNC_PF );
Signature · 1 line
1.7.4.4
Re: [RFC PATCH 5/7] [hyper-v] hyper-v helper functions
In reply to Vadim RozenfeldQuoted 26 lines · Vadim Rozenfeld
--- hyperv.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hyperv.h | 7 +++++++ 2 files changed, 51 insertions(+), 0 deletions(-)hyperv.c +6
-0@@ -3,6 +3,10 @@#include "qemu-option.h" #include "qemu-config.h" +static int hyperv_apic; +static int hyperv_wd; +static int hyperv_spinlock_attempts =HYPERV_SPINLOCK_NEVER_RETRY ; +void hyperv_init (void ) {QemuOpts *opts =QTAILQ_FIRST (&qemu_hyperv_opts.head);@@ -10,6 +14,46 @@ void hyperv_init(void)if (!opts) {return ; } + + hyperv_spinlock_attempts = qemu_opt_get_number(opts, "spinlock",
hyperv.c void hyperv_init(void) · line 28
Quoted 10 lines
hyperv.c +10
-0+HYPERV_SPINLOCK_NEVER_RETRY + ); + hyperv_wd =qemu_opt_get_bool (opts,"wd" ,0 ); + hyperv_apic =qemu_opt_get_bool (opts,"vapic" ,0 ); + +} + +int hyperv_enabled (void ) +{ +return hyperv_hypercall_available () |hyperv_relaxed_timing ();
Shouldn't this be a logical or?
Quoted 57 lines
hyperv.c +28
-0+} + +int hyperv_hypercall_available (void ) +{ +if (hyperv_apic || + (hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_RETRY )) { +return 1 ; + } +return 0 ; +} + +int hyperv_relaxed_timing (void ) +{ +return !hyperv_wd; +} + +int hyperv_apic_recommended (void ) +{ +#ifdef KVM_CAP_IRQCHIP +return hyperv_apic; +#else +return 0 ; +#endif +} + +int hyperv_spinlock_retries (void ) +{ +return hyperv_spinlock_attempts; }static void hyperv_initialize (void )hyperv.h +7
-0@@ -6,7 +6,14 @@#include <asm/hyperv.h> +#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF +void hyperv_init (void ); +int hyperv_enabled (void ); +int hyperv_hypercall_available (void ); +int hyperv_relaxed_timing (void ); +int hyperv_apic_recommended (void ); +int hyperv_spinlock_retries (void );#endif /* QEMU_HW_HYPERV_H */ Signature · 6 lines
1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH 5/7] [hyper-v] hyper-v helper functions
Quoted 30 lines · Alon Levy
Quoted 29 lines · Vadim Rozenfeld
--- hyperv.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hyperv.h | 7 +++++++ 2 files changed, 51 insertions(+), 0 deletions(-)hyperv.c +9
-0@@ -3,6 +3,10 @@#include "qemu-option.h" #include "qemu-config.h" +static int hyperv_apic; +static int hyperv_wd; +static int hyperv_spinlock_attempts =HYPERV_SPINLOCK_NEVER_RETRY ; +void hyperv_init (void ) {QemuOpts *opts =QTAILQ_FIRST (&qemu_hyperv_opts.head);@@ -10,6 +14,46 @@ void hyperv_init(void)if (!opts) {return ; } + + hyperv_spinlock_attempts =qemu_opt_get_number (opts,"spinlock" , +HYPERV_SPINLOCK_NEVER_RETRY + ); + hyperv_wd =qemu_opt_get_bool (opts,"wd" ,0 );
Quoted 8 lines
hyperv.c void hyperv_init(void) · line 28
Quoted 7 lines
hyperv.c +7
-0+ hyperv_apic =qemu_opt_get_bool (opts,"vapic" ,0 ); + +} + +int hyperv_enabled (void ) +{ +return hyperv_hypercall_available () |hyperv_relaxed_timing ();Shouldn't this be a logical or?
Sure, thanks.
Quoted 62 lines
Quoted 58 lines
hyperv.c +28
-0+} + +int hyperv_hypercall_available (void ) +{ +if (hyperv_apic || + (hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_RETRY )) { +return 1 ; + } +return 0 ; +} + +int hyperv_relaxed_timing (void ) +{ +return !hyperv_wd; +} + +int hyperv_apic_recommended (void ) +{ +#ifdef KVM_CAP_IRQCHIP +return hyperv_apic; +#else +return 0 ; +#endif +} + +int hyperv_spinlock_retries (void ) +{ +return hyperv_spinlock_attempts; }static void hyperv_initialize (void )hyperv.h +7
-0@@ -6,7 +6,14 @@#include <asm/hyperv.h> +#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF +void hyperv_init (void ); +int hyperv_enabled (void ); +int hyperv_hypercall_available (void ); +int hyperv_relaxed_timing (void ); +int hyperv_apic_recommended (void ); +int hyperv_spinlock_retries (void );#endif /* QEMU_HW_HYPERV_H */ Signature · 6 lines
1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Vadim Rozenfeld
Enable some basic Hyper-V enlightenment functionalites, including relaxed timing, spinlock, and virtual APIC.
This targets uq/master, correct? Then you should CC qemu-devel on the next round.
I think this series could also be distributed over 3 or 4 patches without loosing bisectability. And please spend a bit time on commit logs.
Jan
Re: [RFC PATCH 1/7] [hyper-v] Add hyper-v parameters block.
In reply to Vadim RozenfeldQuoted 10 lines · Vadim Rozenfeld
--- qemu-options.hx | 23 +++++++++++++++++++++++ vl.c | 2 ++ 2 files changed, 25 insertions(+), 0 deletions(-)qemu-options.hx +0
-0
qemu-options.hx DEF("kvm-shadow-memory", HAS_ARG, QEMU_OPTION_kvm_shadow_memory, · line 2489
Quoted 7 lines
qemu-options.hx +4
-0@@ -2483,6 +2483,29 @@ DEF("kvm-shadow-memory", HAS_ARG, QEMU_OPTION_kvm_shadow_memory, " allocate MEGABYTES for kvm mmu shadowing\n", QEMU_ARCH_I386) +DEF("hyperv", HAS_ARG, QEMU_OPTION_hyperv, + "-hyperv [vapic=on|off][,spinlock=retries][,wd=on|off]\n" + " enable Hyper-V Enlightenment\n", + QEMU_ARCH_ALL)
These are CPU feature, so -cpu +/-hv_vapic,+/-hv_spinlock etc. looks more appropriate than a new command line parameter.
BTW, documentation and maybe also option processing should make clear that this is limited to KVM mode for now.
Jan
Re: [RFC PATCH 3/7] [hyper-v] make Hyper-V option configurable.
In reply to Vadim RozenfeldQuoted 58 lines · Vadim Rozenfeld
--- Makefile.target | 1 + configure | 11 +++++++++++ 2 files changed, 12 insertions(+), 0 deletions(-)Makefile.target +1
-0@@ -199,6 +199,7 @@ obj-$(CONFIG_VHOST_NET) += vhost.o obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o obj-$(CONFIG_KVM) += kvm.o kvm-all.o obj-$(CONFIG_NO_KVM) += kvm-stub.o +obj-$(CONFIG_HYPERV) += hyperv.o obj-y += memory.o LIBS+=-lzconfigure +8
-0@@ -150,6 +150,7 @@ debug="no" strip_opt="yes" bigendian="no" mingw32="no" +hyperv="no" EXESUF="" prefix="/usr/local" mandir="\${prefix}/share/man"@@ -762,6 +763,10 @@ for opt do ;; --enable-vhost-net) vhost_net="yes" ;; + --disable-hyperv) hyperv="no" + ;; + --enable-hyperv) hyperv="yes" + ;; --disable-opengl) opengl="no" ;; --enable-opengl) opengl="yes"@@ -1062,6 +1067,8 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" +echo " --enable-hyperv enable Hyper-V support" +echo " --disable-hyperv disable Hyper-V support" echo " --enable-trace-backend=B Set trace backend" echo " Available backends:" $("$source_path"/scripts/tracetool --list-backends) echo " --with-trace-file=NAME Full PATH,NAME of file to store traces"@@ -2737,6 +2744,7 @@ echo "madvise $madvise" echo "posix_madvise $posix_madvise" echo "uuid support $uuid" echo "vhost-net support $vhost_net" +echo "Hyper-V support $hyperv" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-<pid>" echo "spice support $spice"
configure case "$target_arch2" in · line 3440
Quoted 9 lines
configure +3
-0@@ -3424,6 +3432,9 @@ case "$target_arch2" in if test $kvm_cap_device_assignment = "yes" ; then echo "CONFIG_KVM_DEVICE_ASSIGNMENT=y" >> $config_target_mak fi + if test "$hyperv" = "yes" ; then + echo "CONFIG_HYPERV=y" >> $config_target_mak + fi fi esac if test "$target_bigendian" = "yes" ; then
Why do I want to --disable-hyperv? It rather looks like we could perfectly live with this feature built by default. Would also allow to drop the nasty #ifdefs from the code.
Jan
Quoted 10 lines · Jan Kiszka
Quoted 2 lines · Vadim Rozenfeld
Enable some basic Hyper-V enlightenment functionalites, including relaxed timing, spinlock, and virtual APIC.
This targets uq/master, correct? Then you should CC qemu-devel on the next round.
I think this series could also be distributed over 3 or 4 patches without loosing bisectability. And please spend a bit time on commit logs.
OK.
Quoted 2 lines
Jan
Re: [RFC PATCH 1/7] [hyper-v] Add hyper-v parameters block.
In reply to Jan KiszkaQuoted 14 lines · Jan Kiszka
Quoted 13 lines · Vadim Rozenfeld
--- qemu-options.hx | 23 +++++++++++++++++++++++ vl.c | 2 ++ 2 files changed, 25 insertions(+), 0 deletions(-)qemu-options.hx +0
-0@@ -2483,6 +2483,29 @@ DEF("kvm-shadow-memory", HAS_ARG, QEMU_OPTION_kvm_shadow_memory, " allocate MEGABYTES for kvm mmu shadowing\n", QEMU_ARCH_I386)
Quoted 8 lines
qemu-options.hx DEF("kvm-shadow-memory", HAS_ARG, QEMU_OPTION_kvm_shadow_memory, · line 2489
Quoted 4 lines
qemu-options.hx +4
-0+DEF("hyperv", HAS_ARG, QEMU_OPTION_hyperv, + "-hyperv [vapic=on|off][,spinlock=retries][,wd=on|off]\n" + " enable Hyper-V Enlightenment\n", + QEMU_ARCH_ALL)These are CPU feature, so -cpu +/-hv_vapic,+/-hv_spinlock etc. looks more appropriate than a new command line parameter.
I would like to keep hyper-v settings apart from cpu features for a very simple reason: if hyper-v VMBus support will be added one day, it won't be a CPU only feature anymore.
Quoted 3 lines
BTW, documentation and maybe also option processing should make clear that this is limited to KVM mode for now.
Will add it.
Vadim
Quoted 2 lines
Jan
Re: [RFC PATCH 1/7] [hyper-v] Add hyper-v parameters block.
Quoted 23 lines · Vadim Rozenfeld
Quoted 14 lines · Jan Kiszka
Quoted 13 lines · Vadim Rozenfeld
--- qemu-options.hx | 23 +++++++++++++++++++++++ vl.c | 2 ++ 2 files changed, 25 insertions(+), 0 deletions(-)qemu-options.hx +0
-0@@ -2483,6 +2483,29 @@ DEF("kvm-shadow-memory", HAS_ARG, QEMU_OPTION_kvm_shadow_memory, " allocate MEGABYTES for kvm mmu shadowing\n", QEMU_ARCH_I386)Quoted 8 lines
qemu-options.hx DEF("kvm-shadow-memory", HAS_ARG, QEMU_OPTION_kvm_shadow_memory, · line 2489
Quoted 4 lines
qemu-options.hx +4
-0+DEF("hyperv", HAS_ARG, QEMU_OPTION_hyperv, + "-hyperv [vapic=on|off][,spinlock=retries][,wd=on|off]\n" + " enable Hyper-V Enlightenment\n", + QEMU_ARCH_ALL)These are CPU feature, so -cpu +/-hv_vapic,+/-hv_spinlock etc. looks more appropriate than a new command line parameter.
Quoted 3 lines
I would like to keep hyper-v settings apart from cpu features for a very simple reason: if hyper-v VMBus support will be added one day, it won't be a CPU only feature anymore.
Then that feature would be controlled by adding the corresponding device. There is no need for -hyperv.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Paolo Bonzini
maintainerRe: [RFC PATCH 1/7] [hyper-v] Add hyper-v parameters block.
In reply to Vadim RozenfeldQuoted 44 lines · Vadim Rozenfeld
--- qemu-options.hx | 23 +++++++++++++++++++++++ vl.c | 2 ++ 2 files changed, 25 insertions(+), 0 deletions(-)qemu-options.hx +23
-0@@ -2483,6 +2483,29 @@ DEF("kvm-shadow-memory", HAS_ARG, QEMU_OPTION_kvm_shadow_memory, " allocate MEGABYTES for kvm mmu shadowing\n", QEMU_ARCH_I386) +DEF("hyperv", HAS_ARG, QEMU_OPTION_hyperv, + "-hyperv [vapic=on|off][,spinlock=retries][,wd=on|off]\n" + " enable Hyper-V Enlightenment\n", + QEMU_ARCH_ALL) +STEXI +@item -hyperv +@findex -hyperv +@item vapic=@var{vapic} +@var{vapic} is "on" or "off" and allows for using virtual APIC. +Default is "off". +@findex vapic +@item spinlock=@var{spinlock} +@var{spinlock} is a recommended number of attempts to retry +a spinlock failure befor notifying the hypervisor. +Default is 0xFFFFFFFF (never to retry). +@findex spinlock +:@item wd=@var{wd} +@var{wd} is "on" or "off" and recommends using relaxed timing. +Default is "off" +@findex wd +Simulate Hyper-V Enlightenment. Disable by default. +ETEXI + HXCOMM This is the last statement. Insert new options before this line! STEXI @end tablevl.c +0
-0
vl.c int main(int argc, char **argv, char **envp) · line 3192
Quoted 8 lines
vl.c +2
-0@@ -3185,6 +3185,8 @@ int main(int argc, char **argv, char **envp)fclose (fp);break ; } +case QEMU_OPTION_hyperv: +break ;default :os_parse_cmd_args (popt->index, optarg); }
I think these could be sub-options of -machine.
Paolo
Paolo Bonzini
maintainerRe: [RFC PATCH 7/7] [hyper-v] init hyper-v cpuid leafs
In reply to Vadim RozenfeldQuoted 17 lines · Vadim Rozenfeld
--- target-i386/kvm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 52 insertions(+), 1 deletions(-)target-i386/kvm.c +1
-0@@ -29,6 +29,7 @@#include "hw/pc.h" #include "hw/apic.h" #include "ioport.h" +#include "hyperv.h" //#define DEBUG_KVM
target-i386/kvm.c int kvm_arch_init_vcpu(CPUState *env) · line 382
Quoted 4 lines
target-i386/kvm.c +0
-1@@ -379,11 +380,21 @@ int kvm_arch_init_vcpu(CPUState *env) cpuid_i =0 ;/* Paravirtualization CPUIDs */ -memcpy (signature,"KVMKVMKVM\0\0\0" ,12 );
These should not be KVM-specific. You should be able to add enlightenments to a TCG VM. At the same time, the KVM leaves could be moved to 0x40000100 when enlightenments are active, similar to what Xen does.
Paolo
Quoted 65 lines
target-i386/kvm.c +51
-0c =&cpuid_data.entries[cpuid_i++];memset (c,0 ,sizeof (*c)); c->function =KVM_CPUID_SIGNATURE ; +#ifndef CONFIG_HYPERV +memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); c->eax =0 ; +#else +if (!hyperv_enabled ()) { +memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); + c->eax =0 ; + }else { +memcpy (signature,"Microsoft Hv" ,12 ); + c->eax =HYPERV_CPUID_MIN ; + } +#endif c->ebx = signature[0 ]; c->ecx = signature[1 ]; c->edx = signature[2 ];@@ -393,6 +404,46 @@ int kvm_arch_init_vcpu(CPUState *env) c->function =KVM_CPUID_FEATURES ; c->eax = env->cpuid_kvm_features&kvm_arch_get_supported_cpuid (s,KVM_CPUID_FEATURES ,0 ,R_EAX ); +#ifdef CONFIG_HYPERV +if (hyperv_enabled ()) { +memcpy (signature,"Hv#1\0\0\0\0\0\0\0\0" ,12 ); + c->eax = signature[0 ]; + + c =&cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_VERSION ; + c->eax =0x00001bbc ; + c->ebx =0x00060001 ; + + c =&cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_FEATURES ; +if (hyperv_relaxed_timing ()) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + } +if (hyperv_apic_recommended ()) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + c->eax |=HV_X64_MSR_APIC_ACCESS_AVAILABLE ; + } + + c =&cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_ENLIGHTMENT_INFO ; +if (hyperv_relaxed_timing ()) { + c->eax |=HV_X64_RELAXED_TIMING_RECOMMENDED ; + } +if (hyperv_apic_recommended ()) { + c->eax |=HV_X64_APIC_ACCESS_RECOMMENDED ; + } + c->ebx =hyperv_spinlock_retries (); + + c =&cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_IMPLEMENT_LIMITS ; + c->eax =0x40 ; + c->ebx =0x40 ; + } +#endif has_msr_async_pf_en = c->eax& (1 <<KVM_FEATURE_ASYNC_PF );
Paolo Bonzini
maintainerRe: [RFC PATCH 2/7] [hyper-v] add hyper-v placeholders.
In reply to Vadim RozenfeldQuoted 3 lines · Vadim Rozenfeld
--- hyperv.c | 3 +++ hyperv.h | 10 ++++++++++
Please move these to target-i386, and add a license header.
Also, I don't think it is necessary to add a new configure option; just leave it enabled by default and add CONFIG_HYPERV=y to default-configs/i386-softmmu.mak and default-configs/x86_64-softmmu.mak.
Paolo
Paolo Bonzini
maintainerRe: [RFC PATCH 1/7] [hyper-v] Add hyper-v parameters block.
In reply to Paolo BonziniQuoted 2 lines · Paolo Bonzini
I think these could be sub-options of -machine.
Oops, I obviously meant -cpu like Jan said.
Paolo
Re: [RFC PATCH 7/7] [hyper-v] init hyper-v cpuid leafs
In reply to Paolo BonziniQuoted 20 lines · Paolo Bonzini
Quoted 19 lines · Vadim Rozenfeld
--- target-i386/kvm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 52 insertions(+), 1 deletions(-)target-i386/kvm.c +1
-0@@ -29,6 +29,7 @@#include "hw/pc.h" #include "hw/apic.h" #include "ioport.h" +#include "hyperv.h" //#define DEBUG_KVM @@ -379,11 +380,21 @@ int kvm_arch_init_vcpu(CPUState *env) cpuid_i =0 ;
Quoted 8 lines
target-i386/kvm.c int kvm_arch_init_vcpu(CPUState *env) · line 382
Quoted 2 lines
target-i386/kvm.c +0
-1/* Paravirtualization CPUIDs */ -memcpy (signature,"KVMKVMKVM\0\0\0" ,12 );These should not be KVM-specific. You should be able to add enlightenments to a TCG VM. At the same time, the KVM leaves could be moved to
0x40000100when enlightenments are active, similar to what Xen does.
IMO, adding Hyper-V features without KVM support has little, if any, meaning. Relaxed timing is the only one thing, which can be activated without help from hypervisor.
Quoted 72 lines
Paolo
Quoted 55 lines
target-i386/kvm.c +44
-0c =&cpuid_data.entries[cpuid_i++];memset (c,0 ,sizeof (*c)); c->function =KVM_CPUID_SIGNATURE ; +#ifndef CONFIG_HYPERV +memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); c->eax =0 ; +#else +if (!hyperv_enabled ()) { +memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); + c->eax =0 ; + }else { +memcpy (signature,"Microsoft Hv" ,12 ); + c->eax =HYPERV_CPUID_MIN ; + } +#endif c->ebx = signature[0 ]; c->ecx = signature[1 ]; c->edx = signature[2 ];@@ -393,6 +404,46 @@ int kvm_arch_init_vcpu(CPUState *env) c->function =KVM_CPUID_FEATURES ; c->eax = env->cpuid_kvm_features&kvm_arch_get_supported_cpuid (s,KVM_CPUID_FEATURES ,0 ,R_EAX ); +#ifdef CONFIG_HYPERV +if (hyperv_enabled ()) { +memcpy (signature,"Hv#1\0\0\0\0\0\0\0\0" ,12 ); + c->eax = signature[0 ]; + + c =&cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_VERSION ; + c->eax =0x00001bbc ; + c->ebx =0x00060001 ; + + c =&cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_FEATURES ; +if (hyperv_relaxed_timing ()) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + } +if (hyperv_apic_recommended ()) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + c->eax |=HV_X64_MSR_APIC_ACCESS_AVAILABLE ; + } + + c =&cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_ENLIGHTMENT_INFO ; +if (hyperv_relaxed_timing ()) { + c->eax |=HV_X64_RELAXED_TIMING_RECOMMENDED ; + } +if (hyperv_apic_recommended ()) { + c->eax |=HV_X64_APIC_ACCESS_RECOMMENDED ; + } + c->ebx =hyperv_spinlock_retries (); +target-i386/kvm.c int kvm_arch_init_vcpu(CPUState *env) · line 449
Quoted 10 lines
target-i386/kvm.c +7
-0+ c =&cpuid_data.entries[cpuid_i++]; +memset (c,0 ,sizeof (*c)); + c->function =HYPERV_CPUID_IMPLEMENT_LIMITS ; + c->eax =0x40 ; + c->ebx = 0x40; + } +#endif has_msr_async_pf_en = c->eax& (1 <<KVM_FEATURE_ASYNC_PF );--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Paolo Bonzini
maintainerRe: [RFC PATCH 7/7] [hyper-v] init hyper-v cpuid leafs
Quoted 9 lines · Vadim Rozenfeld
Quoted 5 lines
These should not be KVM-specific. You should be able to add enlightenments to a TCG VM. At the same time, the KVM leaves could be moved to
0x40000100when enlightenments are active, similar to what Xen does.IMO, adding Hyper-V features without KVM support has little, if any, meaning. Relaxed timing is the only one thing, which can be activated without help from hypervisor.
Spinlocks too. TCG does its own round-robin scheduling, so having zero retries could be the best setting. But even if it is not useful for TCG, there's nothing KVM-specific, and that's the important point.
Paolo
Re: [RFC PATCH 7/7] [hyper-v] init hyper-v cpuid leafs
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · Vadim Rozenfeld
Quoted 5 lines
These should not be KVM-specific. You should be able to add enlightenments to a TCG VM. At the same time, the KVM leaves could be moved to
0x40000100when enlightenments are active, similar to what Xen does.
Quoted 5 lines
Quoted 3 lines
IMO, adding Hyper-V features without KVM support has little, if any, meaning. Relaxed timing is the only one thing, which can be activated without help from hypervisor.
Spinlocks too. TCG does its own round-robin scheduling, so having zero
How? You need hypercall page for it.
Best,
Vadim.
Quoted 4 lines
retries could be the best setting. But even if it is not useful for TCG, there's nothing KVM-specific, and that's the important point.
Paolo
Paolo Bonzini
maintainerRe: [RFC PATCH 7/7] [hyper-v] init hyper-v cpuid leafs
Quoted 2 lines · Vadim Rozenfeld
Quoted 1 line
Spinlocks too. TCG does its own round-robin scheduling, so having zero
How? You need hypercall page for it.
I'm not saying you should implement it, :) in principle TCG could have a hypercall page.
Paolo