On Wed, Oct 29, 2025 at 09:48:58 -0500, Praveen K Paladugu wrote:
> From: Praveen K Paladugu <[email protected]>
> 
> qemu recently introduced `query-accelerators` command to generically query the
> list of supported accelerators. Below is an example QMP invocation in qemu:
> 
>  { "execute": "query-accelerators"}
>  {"return": {"enabled": "kvm", "present": ["kvm", "mshv", "qtest", "tcg", 
> "xen"]}}
> 
> "enabled" here indicates "kvm" is enabled and present.
> 
> If query-accelerators command is available, use it. If not, fallback to
> existing mechanisms for quyerying kvm and hvf capabilities.
> 
> Signed-off-by: Praveen K Paladugu <[email protected]>
> ---
>  src/qemu/qemu_capabilities.c                  |    40 +-
>  src/qemu/qemu_capabilities.h                  |     1 +
>  src/qemu/qemu_monitor.c                       |    12 +
>  src/qemu/qemu_monitor.h                       |     5 +
>  src/qemu/qemu_monitor_json.c                  |    35 +
>  src/qemu/qemu_monitor_json.h                  |     6 +
>  .../qemu_10.1.50-q35.x86_64.xml               |  1795 +
>  .../qemu_10.1.50-tcg.x86_64.xml               |  1827 +
>  tests/domaincapsdata/qemu_10.1.50.x86_64.xml  |  1795 +
>  .../caps_10.1.50_x86_64.replies               | 46770 ++++++++++++++++
>  .../caps_10.1.50_x86_64.xml                   |  4950 ++
>  11 files changed, 57231 insertions(+), 5 deletions(-)
>  create mode 100644 tests/domaincapsdata/qemu_10.1.50-q35.x86_64.xml
>  create mode 100644 tests/domaincapsdata/qemu_10.1.50-tcg.x86_64.xml
>  create mode 100644 tests/domaincapsdata/qemu_10.1.50.x86_64.xml
>  create mode 100644 tests/qemucapabilitiesdata/caps_10.1.50_x86_64.replies
>  create mode 100644 tests/qemucapabilitiesdata/caps_10.1.50_x86_64.xml

As noted in other sub-tread drop all the "caps_10.1.50" related files.

I've also posted a patch that updates the README from the docs dumps to
specifically explain why that filename is wrong.

After my patch for updating the 'caps_10.2.0' dump lands you'll have
everything you need to merge this patch. This diff will be needed to
represent the probing changes done in this patch:

diff --git a/tests/qemucapabilitiesdata/caps_10.2.0_x86_64.replies 
b/tests/qemucapabilitiesdata/caps_10.2.0_x86_64.replies
index 6c14a0f9f6..3b6d4e0575 100644
--- a/tests/qemucapabilitiesdata/caps_10.2.0_x86_64.replies
+++ b/tests/qemucapabilitiesdata/caps_10.2.0_x86_64.replies
@@ -24947,14 +24947,19 @@
 }

 {
-  "execute": "query-kvm",
+  "execute": "query-accelerators",
   "id": "libvirt-5"
 }

 {
   "return": {
-    "enabled": true,
-    "present": true
+    "enabled": "kvm",
+    "present": [
+      "kvm",
+      "mshv",
+      "qtest",
+      "tcg"
+    ]
   },
   "id": "libvirt-5"
 }


Also the corresponding .xml will need to be regenerated with the new
capability but that's easy to do.

> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index 83946123be..b4db755099 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -746,6 +746,7 @@ VIR_ENUM_IMPL(virQEMUCaps,
>  
>                /* 485 */
>                "acpi-generic-initiator", /* QEMU_CAPS_ACPI_GENERIC_INITIATOR 
> */
> +              "query-accelerators", /* QEMU_CAPS_QUERY_ACCELERATORS */
>      );
>  
>  
> @@ -1261,6 +1262,7 @@ struct virQEMUCapsStringFlags virQEMUCapsCommands[] = {
>      { "display-reload", QEMU_CAPS_DISPLAY_RELOAD },
>      { "blockdev-set-active", QEMU_CAPS_BLOCKDEV_SET_ACTIVE },
>      { "qom-list-get", QEMU_CAPS_QOM_LIST_GET },
> +    { "query-accelerators", QEMU_CAPS_QUERY_ACCELERATORS },
>  };
>  
>  struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
> @@ -3460,6 +3462,30 @@ virQEMUCapsProbeQMPKVMState(virQEMUCaps *qemuCaps,
>      return 0;
>  }
>  
> +static int
> +virQEMUCapsProbeAccels(virQEMUCaps *qemuCaps,
> +                       qemuMonitor *mon)
> +{
> +    g_autofree char *enabled = NULL;
> +    g_auto(GStrv) present = NULL;
> +
> +    if (qemuMonitorGetAccelerators(mon, &enabled, &present) < 0)
> +        return -1;

Do you plan to use 'present'? If no consider dropping it completely.

> +
> +    if (!enabled) {
> +        return 0;
> +    }
> +
> +    if (STREQ(enabled, "tcg"))
> +        virQEMUCapsSet(qemuCaps, QEMU_CAPS_TCG);
> +    else if (STREQ(enabled, "hvf"))
> +        virQEMUCapsSet(qemuCaps, QEMU_CAPS_HVF);
> +    else if (STREQ(enabled, "kvm"))
> +        virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM);
> +
> +    return 0;
> +}
> +
>  #ifdef __APPLE__
>  bool
>  virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps)

[...]


> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index f9b320f765..9507dc1595 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -3443,6 +3443,18 @@ qemuMonitorGetKVMState(qemuMonitor *mon,
>      return qemuMonitorJSONGetKVMState(mon, enabled, present);
>  }
>  
> +int
> +qemuMonitorGetAccelerators(qemuMonitor *mon,
> +                            char **enabled,
> +                            char ***present)

Broken alignment. As noted consider dropping the 'present' argument.

> +{
> +    VIR_DEBUG("enabled=%p present=%p", enabled, present);

No need to log pointers for these.

> +
> +    QEMU_CHECK_MONITOR(mon);
> +
> +    return qemuMonitorJsonGetAccelerators(mon, enabled, present);
> +}
> +
>  
>  int
>  qemuMonitorGetObjectTypes(qemuMonitor *mon,
> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
> index f611ebfa24..bc2f490e58 100644
> --- a/src/qemu/qemu_monitor.h
> +++ b/src/qemu/qemu_monitor.h
> @@ -1429,6 +1429,11 @@ qemuMonitorGetKVMState(qemuMonitor *mon,
>                         bool *enabled,
>                         bool *present);
>  
> +int
> +qemuMonitorGetAccelerators(qemuMonitor *mon,
> +                            char **enabled,
> +                            char ***present);


Broken alignment.

> +
>  int
>  qemuMonitorGetObjectTypes(qemuMonitor *mon,
>                            char ***types);
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index c121c05ffd..8769e74b63 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -5600,6 +5600,41 @@ qemuMonitorJSONGetKVMState(qemuMonitor *mon,
>      return 0;
>  }
>  
> +int
> +qemuMonitorJsonGetAccelerators(qemuMonitor *mon,

qemuMonitorJSON...

All other functiosn use capital JSON

> +                               char **enabled,
> +                               char ***present)
> +{
> +    g_autoptr(virJSONValue) cmd = NULL;
> +    g_autoptr(virJSONValue) reply = NULL;
> +    virJSONValue *data;
> +    const char *enabled_accel;
> +    virJSONValue *present_array;
> +
> +    *enabled = NULL;
> +    *present = NULL;
> +
> +    if (!(cmd = qemuMonitorJSONMakeCommand("query-accelerators", NULL)))
> +        return -1;
> +
> +    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
> +        return -1;
> +
> +    if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
> +        return -1;
> +
> +    enabled_accel = virJSONValueObjectGetString(data, "enabled");
> +    if (enabled_accel)
> +        *enabled = g_strdup(enabled_accel);

Since you NULL-ed out 'enabled' there's no need to check if
'enabled_accel' is non-NULL as the result will be identical. Assign
directly into '*enabled' and remove the extra temp variable.

> +
> +    present_array = virJSONValueObjectGetArray(data, "present");
> +    if (present_array) {
> +        *present = virJSONValueArrayToStringList(present_array);
> +    }
> +
> +    return 0;
> +}
> +
>  
>  int
>  qemuMonitorJSONGetObjectTypes(qemuMonitor *mon,
> diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
> index 8b06b7599e..85366dca32 100644
> --- a/src/qemu/qemu_monitor_json.h
> +++ b/src/qemu/qemu_monitor_json.h
> @@ -451,6 +451,12 @@ qemuMonitorJSONGetKVMState(qemuMonitor *mon,
>                             bool *present)
>      ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
>  
> +int
> +qemuMonitorJsonGetAccelerators(qemuMonitor *mon,
> +                               char **enabled,
> +                               char ***present)
> +     ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
> +

Normally I'd also require a 'qemumonitorjsontest' test case for this
function but given that it fetches just one string from a command
without any arguments I don't think it'd provide any value, so it's okay
to leave it out. (Basically the only thing it'd check is that
query-accelerators didn't become deprecated, and IIRC we do that when
parsing the capability dump. And if we don't do that we should do it
there to test on real data anyways, so nothing to wory about in this
patch.)

Reply via email to