diff mbox series

[v2,6/6] target/riscv/riscv-qmp-cmds.c: check CPU accel in query-cpu-model-expansion

Message ID 20230926184019.166352-7-dbarboza@ventanamicro.com
State New
Headers show
Series riscv: query-cpu-model-expansion API | expand

Commit Message

Daniel Henrique Barboza Sept. 26, 2023, 6:40 p.m. UTC
Use the recently added riscv_cpu_accelerator_compatible() to filter
unavailable CPUs for a given accelerator. At this moment this is the
case for a QEMU built with KVM and TCG support querying a binary running
with TCG:

qemu-system-riscv64 -S -M virt,accel=tcg -display none
    -qmp tcp:localhost:1234,server,wait=off

./qemu/scripts/qmp/qmp-shell localhost:1234

(QEMU) query-cpu-model-expansion type=full model={"name":"host"}
{"error": {"class": "GenericError", "desc": "'host' CPU not available with tcg"}}

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
 target/riscv/riscv-qmp-cmds.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Alistair Francis Oct. 16, 2023, 5:29 a.m. UTC | #1
On Wed, Sep 27, 2023 at 4:42 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Use the recently added riscv_cpu_accelerator_compatible() to filter
> unavailable CPUs for a given accelerator. At this moment this is the
> case for a QEMU built with KVM and TCG support querying a binary running
> with TCG:
>
> qemu-system-riscv64 -S -M virt,accel=tcg -display none
>     -qmp tcp:localhost:1234,server,wait=off
>
> ./qemu/scripts/qmp/qmp-shell localhost:1234
>
> (QEMU) query-cpu-model-expansion type=full model={"name":"host"}
> {"error": {"class": "GenericError", "desc": "'host' CPU not available with tcg"}}
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  target/riscv/riscv-qmp-cmds.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/target/riscv/riscv-qmp-cmds.c b/target/riscv/riscv-qmp-cmds.c
> index 5b2d186c83..2f2dbae7c8 100644
> --- a/target/riscv/riscv-qmp-cmds.c
> +++ b/target/riscv/riscv-qmp-cmds.c
> @@ -31,6 +31,8 @@
>  #include "qapi/qobject-input-visitor.h"
>  #include "qapi/visitor.h"
>  #include "qom/qom-qobject.h"
> +#include "sysemu/kvm.h"
> +#include "sysemu/tcg.h"
>  #include "cpu-qom.h"
>  #include "cpu.h"
>
> @@ -63,6 +65,17 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
>      return cpu_list;
>  }
>
> +static void riscv_check_if_cpu_available(RISCVCPU *cpu, Error **errp)
> +{
> +    if (!riscv_cpu_accelerator_compatible(cpu)) {
> +        g_autofree char *name = riscv_cpu_get_name(cpu);
> +        const char *accel = kvm_enabled() ? "kvm" : "tcg";
> +
> +        error_setg(errp, "'%s' CPU not available with %s", name, accel);
> +        return;
> +    }
> +}
> +
>  static void riscv_obj_add_qdict_prop(Object *obj, QDict *qdict_out,
>                                       const char *name)
>  {
> @@ -161,6 +174,13 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
>
>      obj = object_new(object_class_get_name(oc));
>
> +    riscv_check_if_cpu_available(RISCV_CPU(obj), &local_err);
> +    if (local_err != NULL) {
> +        error_propagate(errp, local_err);
> +        object_unref(obj);
> +        return NULL;
> +    }
> +
>      if (qdict_in) {
>          riscv_cpuobj_validate_qdict_in(obj, model->props, qdict_in,
>                                         &local_err);
> --
> 2.41.0
>
>
diff mbox series

Patch

diff --git a/target/riscv/riscv-qmp-cmds.c b/target/riscv/riscv-qmp-cmds.c
index 5b2d186c83..2f2dbae7c8 100644
--- a/target/riscv/riscv-qmp-cmds.c
+++ b/target/riscv/riscv-qmp-cmds.c
@@ -31,6 +31,8 @@ 
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/visitor.h"
 #include "qom/qom-qobject.h"
+#include "sysemu/kvm.h"
+#include "sysemu/tcg.h"
 #include "cpu-qom.h"
 #include "cpu.h"
 
@@ -63,6 +65,17 @@  CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
     return cpu_list;
 }
 
+static void riscv_check_if_cpu_available(RISCVCPU *cpu, Error **errp)
+{
+    if (!riscv_cpu_accelerator_compatible(cpu)) {
+        g_autofree char *name = riscv_cpu_get_name(cpu);
+        const char *accel = kvm_enabled() ? "kvm" : "tcg";
+
+        error_setg(errp, "'%s' CPU not available with %s", name, accel);
+        return;
+    }
+}
+
 static void riscv_obj_add_qdict_prop(Object *obj, QDict *qdict_out,
                                      const char *name)
 {
@@ -161,6 +174,13 @@  CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
 
     obj = object_new(object_class_get_name(oc));
 
+    riscv_check_if_cpu_available(RISCV_CPU(obj), &local_err);
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        object_unref(obj);
+        return NULL;
+    }
+
     if (qdict_in) {
         riscv_cpuobj_validate_qdict_in(obj, model->props, qdict_in,
                                        &local_err);