[RFC PATCH 01/25] accel: Add Meson and config support for MSHV accelerator

Magnus Kulke posted 25 patches 5 months, 4 weeks ago
There is a newer version of this series
[RFC PATCH 01/25] accel: Add Meson and config support for MSHV accelerator
Posted by Magnus Kulke 5 months, 4 weeks ago
Introduce a Meson feature option and default-config entry to allow
building QEMU with MSHV (Microsoft Hypervisor) acceleration support.

This is the first step toward implementing an MSHV backend in QEMU.

Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
---
 accel/Kconfig                 |  3 +++
 meson.build                   | 16 ++++++++++++++++
 meson_options.txt             |  2 ++
 scripts/meson-buildoptions.sh |  3 +++
 4 files changed, 24 insertions(+)

diff --git a/accel/Kconfig b/accel/Kconfig
index 4263cab722..a60f114923 100644
--- a/accel/Kconfig
+++ b/accel/Kconfig
@@ -13,6 +13,9 @@ config TCG
 config KVM
     bool
 
+config MSHV
+    bool
+
 config XEN
     bool
     select FSDEV_9P if VIRTFS
diff --git a/meson.build b/meson.build
index e819a7084c..a4269b816b 100644
--- a/meson.build
+++ b/meson.build
@@ -322,6 +322,13 @@ else
 endif
 accelerator_targets += { 'CONFIG_XEN': xen_targets }
 
+if cpu == 'x86_64'
+  mshv_targets = ['x86_64-softmmu']
+else
+  mshv_targets = []
+endif
+accelerator_targets += { 'CONFIG_MSHV': mshv_targets }
+
 if cpu == 'aarch64'
   accelerator_targets += {
     'CONFIG_HVF': ['aarch64-softmmu']
@@ -877,6 +884,14 @@ accelerators = []
 if get_option('kvm').allowed() and host_os == 'linux'
   accelerators += 'CONFIG_KVM'
 endif
+
+if get_option('mshv').allowed() and host_os == 'linux'
+  if get_option('mshv').enabled() and host_machine.cpu() != 'x86_64'
+    error('mshv accelerator requires x64_64 host')
+  endif
+  accelerators += 'CONFIG_MSHV'
+endif
+
 if get_option('whpx').allowed() and host_os == 'windows'
   if get_option('whpx').enabled() and host_machine.cpu() != 'x86_64'
     error('WHPX requires 64-bit host')
@@ -4747,6 +4762,7 @@ if have_system
   summary_info += {'HVF support':       config_all_accel.has_key('CONFIG_HVF')}
   summary_info += {'WHPX support':      config_all_accel.has_key('CONFIG_WHPX')}
   summary_info += {'NVMM support':      config_all_accel.has_key('CONFIG_NVMM')}
+  summary_info += {'MSHV support':       config_all_accel.has_key('CONFIG_MSHV')}
   summary_info += {'Xen support':       xen.found()}
   if xen.found()
     summary_info += {'xen ctrl version':  xen.version()}
diff --git a/meson_options.txt b/meson_options.txt
index cc66b46c63..e5671884b8 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -71,6 +71,8 @@ option('malloc', type : 'combo', choices : ['system', 'tcmalloc', 'jemalloc'],
 
 option('kvm', type: 'feature', value: 'auto',
        description: 'KVM acceleration support')
+option('mshv', type: 'feature', value: 'auto',
+       description: 'MSHV acceleration support')
 option('whpx', type: 'feature', value: 'auto',
        description: 'WHPX acceleration support')
 option('hvf', type: 'feature', value: 'auto',
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
index 8a67a14e2e..cfd767a425 100644
--- a/scripts/meson-buildoptions.sh
+++ b/scripts/meson-buildoptions.sh
@@ -155,6 +155,7 @@ meson_options_help() {
   printf "%s\n" '  membarrier      membarrier system call (for Linux 4.14+ or Windows'
   printf "%s\n" '  modules         modules support (non Windows)'
   printf "%s\n" '  mpath           Multipath persistent reservation passthrough'
+  printf "%s\n" '  mshv            MSHV acceleration support'
   printf "%s\n" '  multiprocess    Out of process device emulation support'
   printf "%s\n" '  netmap          netmap network backend support'
   printf "%s\n" '  nettle          nettle cryptography support'
@@ -410,6 +411,8 @@ _meson_option_parse() {
     --disable-modules) printf "%s" -Dmodules=disabled ;;
     --enable-mpath) printf "%s" -Dmpath=enabled ;;
     --disable-mpath) printf "%s" -Dmpath=disabled ;;
+    --enable-mshv) printf "%s" -Dmshv=enabled ;;
+    --disable-mshv) printf "%s" -Dmshv=disabled ;;
     --enable-multiprocess) printf "%s" -Dmultiprocess=enabled ;;
     --disable-multiprocess) printf "%s" -Dmultiprocess=disabled ;;
     --enable-netmap) printf "%s" -Dnetmap=enabled ;;
-- 
2.34.1
Re: [RFC PATCH 01/25] accel: Add Meson and config support for MSHV accelerator
Posted by Daniel P. Berrangé 5 months, 4 weeks ago
On Tue, May 20, 2025 at 01:29:54PM +0200, Magnus Kulke wrote:
> Introduce a Meson feature option and default-config entry to allow
> building QEMU with MSHV (Microsoft Hypervisor) acceleration support.
> 
> This is the first step toward implementing an MSHV backend in QEMU.
> 
> Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
> ---
>  accel/Kconfig                 |  3 +++
>  meson.build                   | 16 ++++++++++++++++
>  meson_options.txt             |  2 ++
>  scripts/meson-buildoptions.sh |  3 +++
>  4 files changed, 24 insertions(+)
> 
> diff --git a/accel/Kconfig b/accel/Kconfig
> index 4263cab722..a60f114923 100644
> --- a/accel/Kconfig
> +++ b/accel/Kconfig
> @@ -13,6 +13,9 @@ config TCG
>  config KVM
>      bool
>  
> +config MSHV
> +    bool
> +
>  config XEN
>      bool
>      select FSDEV_9P if VIRTFS
> diff --git a/meson.build b/meson.build
> index e819a7084c..a4269b816b 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -322,6 +322,13 @@ else
>  endif
>  accelerator_targets += { 'CONFIG_XEN': xen_targets }
>  
> +if cpu == 'x86_64'
> +  mshv_targets = ['x86_64-softmmu']
> +else
> +  mshv_targets = []
> +endif
> +accelerator_targets += { 'CONFIG_MSHV': mshv_targets }
> +
>  if cpu == 'aarch64'
>    accelerator_targets += {
>      'CONFIG_HVF': ['aarch64-softmmu']
> @@ -877,6 +884,14 @@ accelerators = []
>  if get_option('kvm').allowed() and host_os == 'linux'
>    accelerators += 'CONFIG_KVM'
>  endif
> +
> +if get_option('mshv').allowed() and host_os == 'linux'
> +  if get_option('mshv').enabled() and host_machine.cpu() != 'x86_64'
> +    error('mshv accelerator requires x64_64 host')
> +  endif
> +  accelerators += 'CONFIG_MSHV'

This enables MSHV for non-x86 when the option is left on 'auto'.

You would need something more like this:

  if host_machine.cpu() != 'x86_64'
    if get_option('mshv').enabled()
      error('mshv accelerator requires x64_64 host')
    endif
  else
    accelerators += 'CONFIG_MSHV'
  endif

> +endif
> +
>  if get_option('whpx').allowed() and host_os == 'windows'
>    if get_option('whpx').enabled() and host_machine.cpu() != 'x86_64'
>      error('WHPX requires 64-bit host')

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: [RFC PATCH 01/25] accel: Add Meson and config support for MSHV accelerator
Posted by Paolo Bonzini 5 months, 4 weeks ago
On 5/20/25 13:50, Daniel P. Berrangé wrote:
>> +if get_option('mshv').allowed() and host_os == 'linux'
>> +  if get_option('mshv').enabled() and host_machine.cpu() != 'x86_64'
>> +    error('mshv accelerator requires x64_64 host')
>> +  endif
>> +  accelerators += 'CONFIG_MSHV'
> 
> This enables MSHV for non-x86 when the option is left on 'auto'.

This is similar to what other accelerators do.  The idea is that 
--enable-kvm will give an error on Windows, but not (say) on 
SPARC/Linux.  It was done this way to simplify packaging and let distros 
use --enable-kvm unconditionally; and now --enable-mshv should probably 
behave the same way.

The "requires x86_64 host" was copied from whpx, but is really 
unnecessary there because above you have

elif cpu == 'x86_64'
   accelerator_targets += {
     'CONFIG_HVF': ['x86_64-softmmu'],
     'CONFIG_NVMM': ['i386-softmmu', 'x86_64-softmmu'],
     'CONFIG_WHPX': ['i386-softmmu', 'x86_64-softmmu'],
   }
endif

So the patch is mostly okay, however I'd replace:

>> +if cpu == 'x86_64'
>> +  mshv_targets = ['x86_64-softmmu']
>> +else
>> +  mshv_targets = []
>> +endif
>> +accelerator_targets += { 'CONFIG_MSHV': mshv_targets }
>> +

with the simpler

  elif cpu == 'x86_64'
     accelerator_targets += {
       'CONFIG_HVF': ['x86_64-softmmu'],
       'CONFIG_NVMM': ['i386-softmmu', 'x86_64-softmmu'],
       'CONFIG_WHPX': ['i386-softmmu', 'x86_64-softmmu'],
+     'CONFIG_MSHV': ['x86_64-softmmu'],
     }
  endif

Thanks,

Paolo