[vfio-users] How to get Windows 7 to work with hyperv

Thomas Lindroth thomas.lindroth at gmail.com
Thu Feb 9 19:48:46 UTC 2017


Good news everyone. Everyone who is still using Windows 7 that is. I've got
win7 to run with hyperv enlightenments enabled.

The problem with win7 is that it won't boot if you use OVMF, multicore and
hyperv at the same time. This bug (comment 7) got the details as well as the
solution. https://bugs.launchpad.net/qemu/+bug/1593605

I did as the comment suggested and built my own patched OVMF binary. You can
get it here https://github.com/tholin/OVMF-win7-hyperv or you can build it
yourself with the patch from the description.

To use the prebuilt version download the binaries and add them to where
libvirt can read them (/usr/share/OVMF). Then change your libvirt xml to point
to the new binary.
<loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_win7_code.fd</loader>
If you disabled the hypervisor cpuflag you have to stop doing that by removing
this line if you have it.
<feature policy='disable' name='hypervisor'/>

Then add the usual hyperv settings.
<hyperv>
  <relaxed state='on'/>
  <vapic state='on'/>
  <spinlocks state='on' retries='8191'/>
  <vendor_id state='on' value='SomeString'/>
</hyperv>
...
<clock offset='localtime'>
  ...
  <timer name='hypervclock' present='yes'/>
</clock>

To test if hyperv is used start the VM while running this in a terminal.
"while true; do kvm_stat -1|grep kvm_hv_hypercall;done"
If the numbers change the guest is using hyperv enlightenments.
If you don't have kvm_stat installed it's part of the kernel source at
tools/kvm/kvm_stat/kvm_stat.

The main benefit of using hyperv for me is access to the hypervclock. A win7
guest can be configured to use various timing sources. The default if you use
an unmodified virt-manager generated xml is to use acpi_pm which is a slow
timer requiring a context switch to qemu in userspace on every access. By
hiding the hypervisor cpuflag win7 can use the TSC timer which is very fast but
unfortunately it's not completely stable. Time might sometimes run backwards
when it's used. Win7 will also fall back on acpi_pm if the guest got too many
cores. Too many seems to be 6, including HT cores, but I'm not sure if that is
a hardcoded limit or caused by the environment somehow. In an earlier post to
the mailing list I said that win7 will revert to acpi_pm when hyperthreading is
enabled but it looks like the real problem is related to the number of cores,
not HT specifically.

Hypervclock triggers a vm-exit on each access so it's not as fast as TSC but it
should be stable and works with 6 cores. Here is a simple benchmarks using
passmark's floating point math test and 3 guest cores. The floating point test
use the timer so much that it's more of a timer overhead test than a floating
point test.

acpi_pm     3315 points
hypervclock 4273 points
TSC         5578 points

Hypervclock is disappointingly slow compared to TSC but it's faster than
acpi_pm and works with more cores. If you use a setup with enough cores to make
win7 use acpi_pm switching to hypervclock will give better performance but if
your setup runs fine with TSC you can keep using that.




More information about the vfio-users mailing list