[PATCH v3 26/26] qapi/accel: Allow to query mshv capabilities

Magnus Kulke posted 26 patches 4 months, 1 week ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Magnus Kulke <magnus.kulke@linux.microsoft.com>, Wei Liu <wei.liu@kernel.org>, "Alex Bennée" <alex.bennee@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, Markus Armbruster <armbru@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, "Michael S. Tsirkin" <mst@redhat.com>, Cornelia Huck <cohuck@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Eric Blake <eblake@redhat.com>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>
There is a newer version of this series
[PATCH v3 26/26] qapi/accel: Allow to query mshv capabilities
Posted by Magnus Kulke 4 months, 1 week ago
From: Praveen K Paladugu <prapal@microsoft.com>

Allow to query mshv capabilities via query-mshv QMP command.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
---
 hw/core/machine-qmp-cmds.c | 14 ++++++++++++++
 qapi/accelerator.json      | 29 +++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 6aca1a626e..024ddb8d2d 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -28,6 +28,20 @@
 #include "system/runstate.h"
 #include "system/system.h"
 #include "hw/s390x/storage-keys.h"
+#include <sys/stat.h>
+
+/*
+ * QMP query for MSHV
+ */
+MshvInfo *qmp_query_mshv(Error **errp)
+{
+    MshvInfo *info = g_malloc0(sizeof(*info));
+    struct stat st;
+
+    info->present = accel_find("mshv");
+    info->enabled = (stat("/dev/mshv", &st) == 0);
+    return info;
+}
 
 /*
  * fast means: we NEVER interrupt vCPU threads to retrieve
diff --git a/qapi/accelerator.json b/qapi/accelerator.json
index fb28c8d920..c2bfbc507f 100644
--- a/qapi/accelerator.json
+++ b/qapi/accelerator.json
@@ -54,3 +54,32 @@
 { 'command': 'x-accel-stats',
   'returns': 'HumanReadableText',
   'features': [ 'unstable' ] }
+
+##
+# @MshvInfo:
+#
+# Information about support for MSHV acceleration
+#
+# @enabled: true if MSHV acceleration is active
+#
+# @present: true if MSHV acceleration is built into this executable
+#
+# Since: 10.0.92
+##
+{ 'struct': 'MshvInfo', 'data': {'enabled': 'bool', 'present': 'bool'} }
+
+##
+# @query-mshv:
+#
+# Return information about MSHV acceleration
+#
+# Returns: @MshvInfo
+#
+# Since: 10.0.92
+#
+# .. qmp-example::
+#
+#     -> { "execute": "query-mshv" }
+#     <- { "return": { "enabled": true, "present": true } }
+##
+{ 'command': 'query-mshv', 'returns': 'MshvInfo' }
-- 
2.34.1
Re: [PATCH v3 26/26] qapi/accel: Allow to query mshv capabilities
Posted by Daniel P. Berrangé 3 months, 2 weeks ago
On Thu, Aug 07, 2025 at 04:39:51PM +0200, Magnus Kulke wrote:
> From: Praveen K Paladugu <prapal@microsoft.com>
> 
> Allow to query mshv capabilities via query-mshv QMP command.
> 
> Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
> Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
> ---
>  hw/core/machine-qmp-cmds.c | 14 ++++++++++++++
>  qapi/accelerator.json      | 29 +++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
> index 6aca1a626e..024ddb8d2d 100644
> --- a/hw/core/machine-qmp-cmds.c
> +++ b/hw/core/machine-qmp-cmds.c
> @@ -28,6 +28,20 @@
>  #include "system/runstate.h"
>  #include "system/system.h"
>  #include "hw/s390x/storage-keys.h"
> +#include <sys/stat.h>
> +
> +/*
> + * QMP query for MSHV
> + */
> +MshvInfo *qmp_query_mshv(Error **errp)
> +{
> +    MshvInfo *info = g_malloc0(sizeof(*info));
> +    struct stat st;
> +
> +    info->present = accel_find("mshv");
> +    info->enabled = (stat("/dev/mshv", &st) == 0);

This does't have the right semantics

$ sudo touch /dev/mshv
$ ./scripts/qmp/qmp-shell-wrap ./build/qemu-system-x86_64 -display none -accel tcg
(QEMU) query-mshv
{"return": {"enabled": true, "present": true}}


It cannot be enabled, since I asked for 'tcg' as the accelerator

IIUC, it should be

  info->enabled = mshv_enabled();

to match what KVM does.


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: [PATCH v3 26/26] qapi/accel: Allow to query mshv capabilities
Posted by Wei Liu 4 months, 1 week ago
On Thu, Aug 07, 2025 at 04:39:51PM +0200, Magnus Kulke wrote:
> From: Praveen K Paladugu <prapal@microsoft.com>
> 
> Allow to query mshv capabilities via query-mshv QMP command.
> 
> Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
> Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
> ---
>  hw/core/machine-qmp-cmds.c | 14 ++++++++++++++
>  qapi/accelerator.json      | 29 +++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
> index 6aca1a626e..024ddb8d2d 100644
> --- a/hw/core/machine-qmp-cmds.c
> +++ b/hw/core/machine-qmp-cmds.c
> @@ -28,6 +28,20 @@
>  #include "system/runstate.h"
>  #include "system/system.h"
>  #include "hw/s390x/storage-keys.h"
> +#include <sys/stat.h>
> +
> +/*
> + * QMP query for MSHV
> + */
> +MshvInfo *qmp_query_mshv(Error **errp)
> +{
> +    MshvInfo *info = g_malloc0(sizeof(*info));
> +    struct stat st;
> +
> +    info->present = accel_find("mshv");
> +    info->enabled = (stat("/dev/mshv", &st) == 0);

I don't think this is the right way to check if MSHV is _enabled_. The
device node being around doesn't necessarily mean that QEMU is using it.

You can refer to kvm_enabled() to see how it is implemented.

Some functions that are of interest:
   do_configure_accelerator
   accel_init_machine

Thanks,
Wei
Re: [PATCH v3 26/26] qapi/accel: Allow to query mshv capabilities
Posted by Wei Liu 4 months ago
On Thu, Aug 07, 2025 at 07:22:21PM +0000, Wei Liu wrote:
> On Thu, Aug 07, 2025 at 04:39:51PM +0200, Magnus Kulke wrote:
> > From: Praveen K Paladugu <prapal@microsoft.com>
> > 
> > Allow to query mshv capabilities via query-mshv QMP command.
> > 
> > Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
> > Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
> > ---
> >  hw/core/machine-qmp-cmds.c | 14 ++++++++++++++
> >  qapi/accelerator.json      | 29 +++++++++++++++++++++++++++++
> >  2 files changed, 43 insertions(+)
> > 
> > diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
> > index 6aca1a626e..024ddb8d2d 100644
> > --- a/hw/core/machine-qmp-cmds.c
> > +++ b/hw/core/machine-qmp-cmds.c
> > @@ -28,6 +28,20 @@
> >  #include "system/runstate.h"
> >  #include "system/system.h"
> >  #include "hw/s390x/storage-keys.h"
> > +#include <sys/stat.h>
> > +
> > +/*
> > + * QMP query for MSHV
> > + */
> > +MshvInfo *qmp_query_mshv(Error **errp)
> > +{
> > +    MshvInfo *info = g_malloc0(sizeof(*info));
> > +    struct stat st;
> > +
> > +    info->present = accel_find("mshv");
> > +    info->enabled = (stat("/dev/mshv", &st) == 0);
> 
> I don't think this is the right way to check if MSHV is _enabled_. The
> device node being around doesn't necessarily mean that QEMU is using it.
> 
> You can refer to kvm_enabled() to see how it is implemented.
> 
> Some functions that are of interest:
>    do_configure_accelerator
>    accel_init_machine

This is likely as simple as squashing in the following diff.

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 024ddb8d2d7c..1b520599972a 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -39,7 +39,7 @@ MshvInfo *qmp_query_mshv(Error **errp)
     struct stat st;

     info->present = accel_find("mshv");
-    info->enabled = (stat("/dev/mshv", &st) == 0);
+    info->enabled = mshv_enabled();
     return info;
 }