Skip to contentSkip to conversation

monitor: Remove need of per-target handlers

PATCH Superseded Philippe Mathieu-Daudé 6 participants 59 messages Apr 10 – Apr 15

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover monitor: Remove need of per-target handlers

Changes needed for the single binary (and heterogeneous emulation).

Convert target_monitor_defs() and target_monitor_defs() to SysemuCPUOps fields, adapting the 4 targets using these 'legacy' code.

Instead of filtering the commands per target / device at build time, add a new field to HMPCommand to filter them at runtime, allowing to compile the command array once.

Philippe Mathieu-Daudé (27):
monitor: Have MonitorDef::get_value() always return int64_t type
monitor: Remove target_long use in get_monitor_def()
monitor: Reduce target-specific methods further
monitor: Remove 'monitor/hmp-target.h' header
monitor: Forward-declare the MonitorDef type
cpus: Introduce SysemuCPUOps::monitor_defs hook target/i386: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs target/m68k: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs target/sparc: Replace target_monitor_defs ->
SysemuCPUOps::monitor_defs
monitor: Remove target_monitor_defs()
cpus: Introduce SysemuCPUOps::monitor_get_register() hook target/riscv: Register target_get_monitor_def in SysemuCPUOps
monitor: Remove target_get_monitor_def()
monitor/meson: Use SPICE with migration HMP commands
stubs: Rename monitor* -> qmp* files
monitor: Make 'info via' a generic command
monitor: Make Xen emulation commands generic ones
system: Expose 'arch_init.h' as 'qemu/target-arch-defs.h'
monitor: Introduce HMPCommand::arch_bitmask field hw/s390x: Reduce 'monitor/monitor.h' inclusions
monitor: Do not check TARGET_S390X to build s390x commands
monitor: Do not check TARGET_I386 to build target/i386/ commands
monitor: Do not check TARGET_I386 to build 'info sgx' command
monitor: Do not check TARGET_I386 to build 'info sev' command
monitor: Do not check TARGET_I386/RISCV to build 'info mem' command
monitor: Do not check multiple TARGET_* to build 'info tlb' command
monitor: Merge hmp-target.c code within hmp-cmds.c

 MAINTAINERS                                   |  14 ++-
 include/hw/core/sysemu-cpu-ops.h              |  13 ++
 include/hw/s390x/storage-attributes.h         |   4 -
 include/hw/s390x/storage-keys.h               |   3 -
 include/monitor/hmp-target.h                  |  46 -------
 include/monitor/hmp.h                         |  21 ++++
 .../qemu/base-arch-defs.h                     |  10 +-
 include/qemu/typedefs.h                       |   1 +
 monitor/monitor-internal.h                    |   7 +-
 target/riscv/internals.h                      |   3 +
 hw/i386/kvm/xen-stubs.c                       |  12 ++
 hw/i386/sgx-hmp-stub.c                        |  16 +++
 hw/i386/sgx-stub.c                            |   6 -
 hw/i386/sgx.c                                 |   1 -
 hw/misc/mos6522-stub.c                        |  16 +++
 hw/pci/pci.c                                  |   2 +-
 hw/s390x/s390-skeys.c                         |   2 +
 hw/s390x/s390-stattrib.c                      |   2 +
 monitor/hmp-cmds.c                            |  41 ++++++-
 monitor/hmp-target.c                          | 115 ------------------
 monitor/hmp.c                                 |  53 +++++++-
 stubs/hmp-cmd-info_mem.c                      |  12 ++
 stubs/hmp-cmd-info_sev.c                      |  16 +++
 stubs/hmp-cmd-info_tlb.c                      |  12 ++
 stubs/hmp-cmds-hw-s390x.c                     |  15 +++
 stubs/hmp-cmds-target-i386.c                  |  13 ++
 stubs/{monitor-arm-gic.c => qmp-arm-gic.c}    |   0
 ...or-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} |   0
 .../{monitor-cpu-s390x.c => qmp-cpu-s390x.c}  |   0
 stubs/{monitor-cpu.c => qmp-cpu.c}            |   0
 stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c}  |   0
 stubs/{monitor-i386-sev.c => qmp-i386-sev.c}  |   0
 stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c}  |   0
 stubs/{monitor-i386-xen.c => qmp-i386-xen.c}  |   0
 stubs/target-get-monitor-def.c                |  29 -----
 stubs/target-monitor-defs.c                   |   7 --
 system/arch_init.c                            |   2 +-
 system/qdev-monitor.c                         |   2 +-
 system/vl.c                                   |   2 +-
 target/i386/cpu-apic.c                        |   1 -
 target/i386/cpu.c                             |  24 ++++
 target/i386/monitor.c                         |  26 ----
 target/i386/sev-system-stub.c                 |   6 -
 target/i386/sev.c                             |   1 -
 target/m68k/cpu.c                             |  18 +++
 target/m68k/monitor.c                         |  22 ----
 target/ppc/monitor.c                          |   2 -
 target/riscv/cpu.c                            |   1 +
 target/riscv/monitor.c                        |   5 +-
 target/sh4/monitor.c                          |   1 -
 target/sparc/cpu.c                            |  19 +++
 target/sparc/monitor.c                        |  19 ---
 target/xtensa/monitor.c                       |   1 -
 hmp-commands-info.hx                          |  26 ++--
 hmp-commands.hx                               |  13 +-
 hw/i386/meson.build                           |   1 +
 hw/misc/meson.build                           |   1 +
 migration/meson.build                         |   2 +-
 monitor/meson.build                           |   5 +-
 stubs/meson.build                             |  23 ++--
 60 files changed, 368 insertions(+), 347 deletions(-)
 delete mode 100644 include/monitor/hmp-target.h
 rename system/arch_init.h => include/qemu/base-arch-defs.h (92%)
 create mode 100644 hw/i386/sgx-hmp-stub.c
 create mode 100644 hw/misc/mos6522-stub.c
 delete mode 100644 monitor/hmp-target.c
 create mode 100644 stubs/hmp-cmd-info_mem.c
 create mode 100644 stubs/hmp-cmd-info_sev.c
 create mode 100644 stubs/hmp-cmd-info_tlb.c
 create mode 100644 stubs/hmp-cmds-hw-s390x.c
 create mode 100644 stubs/hmp-cmds-target-i386.c
 rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%)
 rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%)
 rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%)
 rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%)
 rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%)
 rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%)
 rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%)
 rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%)
 delete mode 100644 stubs/target-get-monitor-def.c
 delete mode 100644 stubs/target-monitor-defs.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/27 monitor: Have MonitorDef::get_value() always return int64_t type

Simplify MonitorDef::get_value() handler by having it always return a int64_t type. Truncate to 32-bit in the single caller.

Note, this handler is only implemented once for the x86 targets.

---
 include/monitor/hmp-target.h | 6 +-----
 monitor/hmp-target.c         | 4 +++-
 target/i386/monitor.c        | 4 ++--
 3 files changed, 6 insertions(+), 8 deletions(-)
include/monitor/hmp-target.h +1 -5
index ce0bb1983cc..6364c94edf8 100644
@@ -27,15 +27,11 @@
 
 typedef struct MonitorDef MonitorDef;
 
-#ifdef COMPILING_PER_TARGET
-#include "exec/target_long.h"
 struct MonitorDef {
     const char *name;
     int offset;
-    target_long (*get_value)(Monitor *mon, const struct MonitorDef *md,
-                             int val);
+    int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset);
 };
-#endif
 
 const MonitorDef *target_monitor_defs(void);
 int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval);
monitor/hmp-target.c +3 -1
index da7dd7f31f2..812714ada01 100644
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/target-info.h"
 #include "monitor-internal.h"
 #include "monitor/qdev.h"
 #include "net/slirp.h"
@@ -79,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
     for(; md->name != NULL; md++) {
         if (hmp_compare_cmd(name, md->name)) {
             if (md->get_value) {
-                *pval = md->get_value(mon, md, md->offset);
+                int64_t val = md->get_value(mon, md, md->offset);
+                *pval = target_long_bits() == 32 ? (int32_t)val : val;
             } else {
                 CPUArchState *env = mon_get_cpu_env(mon);
                 ptr = (uint8_t *)env + md->offset;
target/i386/monitor.c +2 -2
index 977f65fe16c..b128334e571 100644
@@ -593,8 +593,8 @@ void hmp_mce(Monitor *mon, const QDict *qdict)
     }
 }
 
-static target_long monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
-                                  int val)
+static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
+                              int offset)
 {
     CPUArchState *env = mon_get_cpu_env(mon);
     return env->eip + env->segs[R_CS].base;
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2 01/27] monitor: Have MonitorDef::get_value() always return int64_t type

Quoted 11 lines · Philippe Mathieu-Daudé

Simplify MonitorDef::get_value() handler by having it always return a int64_t type. Truncate to 32-bit in the single caller.

Note, this handler is only implemented once for the x86 targets.

---
  include/monitor/hmp-target.h | 6 +-----
  monitor/hmp-target.c         | 4 +++-
  target/i386/monitor.c        | 4 ++--
  3 files changed, 6 insertions(+), 8 deletions(-)

Given there's only one use, we could just define that the hook itself extends.

target/i386/monitor.c void hmp_mce(Monitor *mon, const QDict *qdict) · line 600

Quoted 5 lines
target/i386/monitor.c +2 -0
+static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
+                              int offset)
  {
      CPUArchState *env = mon_get_cpu_env(mon);
      return env->eip + env->segs[R_CS].base;
    ret = env->eip + env->segs[R_CS].base;
    if (!(env->hflags & HF_CS64_MASK)) {
        ret = (int32_t)ret;
    }

The test will always be true for i386, but will also apply when the cpu is in 32-bit or 16-bit mode.

r~

#3 lore raw

PATCH v2 2/27 monitor: Remove target_long use in get_monitor_def()

In reply to Philippe Mathieu-Daudé

Truncate manually, removing the need of target-specific code in get_monitor_def().

---
 monitor/hmp-target.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor/hmp-target.c +1 -1
index 812714ada01..b9b79e8e927 100644
@@ -93,7 +93,7 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
 
     ret = target_get_monitor_def(cs, name, &tmp);
     if (!ret) {
-        *pval = (target_long) tmp;
+        *pval = target_long_bits() == 32 ? (int32_t)tmp : tmp;
     }
 
     return ret;
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH v2 02/27] monitor: Remove target_long use in get_monitor_def()

Quoted 13 lines · Philippe Mathieu-Daudé

Truncate manually, removing the need of target-specific code in get_monitor_def().

---
  monitor/hmp-target.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
monitor/hmp-target.c +0 -0
index 812714ada01..b9b79e8e927 100644

monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 97

Quoted 6 lines
monitor/hmp-target.c +1 -1
@@ -93,7 +93,7 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
 
      ret = target_get_monitor_def(cs, name, &tmp);
      if (!ret) {
-        *pval = (target_long) tmp;
+        *pval = target_long_bits() == 32 ? (int32_t)tmp : tmp;
      }

Likewise force the target to deal with int64_t.
There is only one user: riscv.

r~

#5 lore raw

PATCH v2 3/27 monitor: Reduce target-specific methods further

In reply to Philippe Mathieu-Daudé

get_monitor_def() doesn't use any target-specific declaration anymore, move it to hmp.c to compile it once.

---
 monitor/monitor-internal.h |  1 -
 monitor/hmp-target.c       | 39 -------------------------------------
 monitor/hmp.c              | 40 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 40 deletions(-)
monitor/monitor-internal.h +0 -1
index feca111ae31..3ecd394ecf6 100644
@@ -181,7 +181,6 @@ void monitor_data_destroy_qmp(MonitorQMP *mon);
 void coroutine_fn monitor_qmp_dispatcher_co(void *data);
 void qmp_dispatcher_co_wake(void);
 
-int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
 void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
 int hmp_compare_cmd(const char *name, const char *list);
 
monitor/hmp-target.c +0 -39
index b9b79e8e927..c840ae5f0a2 100644
@@ -23,7 +23,6 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu/target-info.h"
 #include "monitor-internal.h"
 #include "monitor/qdev.h"
 #include "net/slirp.h"
@@ -61,44 +60,6 @@ HMPCommand *hmp_cmds_for_target(bool info_command)
     return info_command ? hmp_info_cmds : hmp_cmds;
 }
 
-/*
- * Set @pval to the value in the register identified by @name.
- * return 0 if OK, -1 if not found
- */
-int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
-{
-    const MonitorDef *md = target_monitor_defs();
-    CPUState *cs = mon_get_cpu(mon);
-    void *ptr;
-    uint64_t tmp = 0;
-    int ret;
-
-    if (cs == NULL || md == NULL) {
-        return -1;
-    }
-
-    for(; md->name != NULL; md++) {
-        if (hmp_compare_cmd(name, md->name)) {
-            if (md->get_value) {
-                int64_t val = md->get_value(mon, md, md->offset);
-                *pval = target_long_bits() == 32 ? (int32_t)val : val;
-            } else {
-                CPUArchState *env = mon_get_cpu_env(mon);
-                ptr = (uint8_t *)env + md->offset;
-                *pval = *(int32_t *)ptr;
-            }
-            return 0;
-        }
-    }
-
-    ret = target_get_monitor_def(cs, name, &tmp);
-    if (!ret) {
-        *pval = target_long_bits() == 32 ? (int32_t)tmp : tmp;
-    }
-
-    return ret;
-}
-
 static int
 compare_mon_cmd(const void *a, const void *b)
 {
monitor/hmp.c +40 -0
index 0e5913fabb1..20ba1e62988 100644
@@ -355,6 +355,8 @@ static bool gdb_get_register(Monitor *mon, int64_t *pval, const char *name)
 static const char *pch;
 static sigjmp_buf expr_env;
 
+static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
+
 static G_NORETURN G_GNUC_PRINTF(2, 3)
 void expr_error(Monitor *mon, const char *fmt, ...)
 {
@@ -1595,3 +1597,41 @@ void monitor_register_hmp_info_hrt(const char *name,
     }
     g_assert_not_reached();
 }
+
+/*
+ * Set @pval to the value in the register identified by @name.
+ * return 0 if OK, -1 if not found
+ */
+static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
+{
+    const MonitorDef *md = target_monitor_defs();
+    CPUState *cs = mon_get_cpu(mon);
+    void *ptr;
+    uint64_t tmp = 0;
+    int ret;
+
+    if (cs == NULL || md == NULL) {
+        return -1;
+    }
+
+    for (; md->name != NULL; md++) {
+        if (hmp_compare_cmd(name, md->name)) {
+            if (md->get_value) {
+                int64_t val = md->get_value(mon, md, md->offset);
+                *pval = target_long_bits() == 32 ? (int32_t)val : val;
+            } else {
+                CPUArchState *env = mon_get_cpu_env(mon);
+                ptr = (uint8_t *)env + md->offset;
+                *pval = *(int32_t *)ptr;
+            }
+            return 0;
+        }
+    }
+
+    ret = target_get_monitor_def(cs, name, &tmp);
+    if (!ret) {
+        *pval = target_long_bits() == 32 ? (int32_t)tmp : tmp;
+    }
+
+    return ret;
+}
Signature · 1 line
2.53.0
Reviewed-by on v2 3/27
#6 lore raw

Re: [PATCH v2 03/27] monitor: Reduce target-specific methods further

Quoted 10 lines · Philippe Mathieu-Daudé

get_monitor_def() doesn't use any target-specific declaration anymore, move it to hmp.c to compile it once.

---
  monitor/monitor-internal.h |  1 -
  monitor/hmp-target.c       | 39 -------------------------------------
  monitor/hmp.c              | 40 ++++++++++++++++++++++++++++++++++++++
  3 files changed, 40 insertions(+), 40 deletions(-)

r~

#7 lore raw

PATCH v2 4/27 monitor: Remove 'monitor/hmp-target.h' header

In reply to Philippe Mathieu-Daudé

The "monitor/hmp-target.h" header doesn't contain any target-specific declarations anymore. Merge it with "monitor/hmp.h", its target-agnostic counterpart.

---
 MAINTAINERS                   |  1 -
 include/monitor/hmp-target.h  | 42 -----------------------------------
 include/monitor/hmp.h         | 12 ++++++++++
 hw/i386/sgx-stub.c            |  1 -
 hw/i386/sgx.c                 |  1 -
 monitor/hmp-cmds.c            |  1 -
 monitor/hmp-target.c          |  1 -
 monitor/hmp.c                 |  1 -
 stubs/target-monitor-defs.c   |  2 +-
 target/i386/cpu-apic.c        |  1 -
 target/i386/monitor.c         |  1 -
 target/i386/sev-system-stub.c |  1 -
 target/i386/sev.c             |  1 -
 target/m68k/monitor.c         |  1 -
 target/ppc/monitor.c          |  2 --
 target/riscv/monitor.c        |  1 -
 target/sh4/monitor.c          |  1 -
 target/sparc/monitor.c        |  1 -
 target/xtensa/monitor.c       |  1 -
 19 files changed, 13 insertions(+), 60 deletions(-)
 delete mode 100644 include/monitor/hmp-target.h
MAINTAINERS +0 -1
index 535d1d3398e..edbbd544d62 100644
@@ -3411,7 +3411,6 @@ F: hmp.h
 F: hmp-commands*.hx
 F: include/monitor/hmp.h
 F: include/monitor/hmp-completion.h
-F: include/monitor/hmp-target.h
 F: tests/qtest/test-hmp.c
 F: include/qemu/qemu-print.h
 F: util/qemu-print.c
include/monitor/hmp-target.h deleted +0 -42

42 lines not on this page · raw message

include/monitor/hmp.h +12 -0
index 9c2330205fc..f17a50a3fed 100644
@@ -17,6 +17,18 @@
 #include "qemu/readline.h"
 #include "qapi/qapi-types-common.h"
 
+typedef struct MonitorDef {
+    const char *name;
+    int offset;
+    int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset);
+} MonitorDef;
+
+const MonitorDef *target_monitor_defs(void);
+int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval);
+
+CPUArchState *mon_get_cpu_env(Monitor *mon);
+CPUState *mon_get_cpu(Monitor *mon);
+
 bool hmp_handle_error(Monitor *mon, Error *err);
 void hmp_help_cmd(Monitor *mon, const char *name);
 strList *hmp_split_at_comma(const char *str);
hw/i386/sgx-stub.c +0 -1
index 1dd8d9afbfa..6e82773a86d 100644
@@ -1,7 +1,6 @@
 #include "qemu/osdep.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "hw/i386/pc.h"
 #include "hw/i386/sgx-epc.h"
 #include "qapi/qapi-commands-misc-i386.h"
hw/i386/sgx.c +0 -1
index 5e792e8e6e9..7e4c509f5a4 100644
@@ -17,7 +17,6 @@
 #include "monitor/qdev.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qapi/qapi-commands-misc-i386.h"
monitor/hmp-cmds.c +0 -1
index bc26b39d708..e81632f5551 100644
@@ -22,7 +22,6 @@
 #include "monitor/hmp.h"
 #include "qemu/help_option.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "monitor/monitor-internal.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-control.h"
monitor/hmp-target.c +0 -1
index c840ae5f0a2..d07e545ef7e 100644
@@ -27,7 +27,6 @@
 #include "monitor/qdev.h"
 #include "net/slirp.h"
 #include "system/device_tree.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 #include "monitor/hmp-completion.h"
 #include "block/block-hmp-cmds.h"
monitor/hmp.c +0 -1
index 20ba1e62988..983048db1b9 100644
@@ -27,7 +27,6 @@
 #include "hw/core/qdev.h"
 #include "monitor-internal.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "qobject/qdict.h"
 #include "qobject/qnum.h"
 #include "qemu/bswap.h"
stubs/target-monitor-defs.c +1 -1
index 35a0a342772..0dd4cdb34f6 100644
@@ -1,5 +1,5 @@
 #include "qemu/osdep.h"
-#include "monitor/hmp-target.h"
+#include "monitor/hmp.h"
 
 const MonitorDef *target_monitor_defs(void)
 {
target/i386/cpu-apic.c +0 -1
index eaa10ad2a3d..5599a4675c5 100644
@@ -11,7 +11,6 @@
 #include "qapi/error.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "system/hw_accel.h"
 #include "system/kvm.h"
 #include "system/xen.h"
target/i386/monitor.c +0 -1
index b128334e571..ddc666d3451 100644
@@ -25,7 +25,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 #include "qobject/qdict.h"
 #include "qapi/error.h"
target/i386/sev-system-stub.c +0 -1
index fb84aee94d2..f799a338d60 100644
@@ -14,7 +14,6 @@
 #include "qemu/osdep.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "qapi/error.h"
 #include "sev.h"
 
target/i386/sev.c +0 -1
index 9dde972c118..97e745f27c4 100644
@@ -39,7 +39,6 @@
 #include "qom/object.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "qapi/qapi-commands-misc-i386.h"
 #include "confidential-guest.h"
 #include "hw/i386/pc.h"
target/m68k/monitor.c +0 -1
index 94bb12833af..be7411edca6 100644
@@ -8,7 +8,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "monitor/monitor.h"
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
target/ppc/monitor.c +0 -2
index 776a76602ea..7c88e0e2bda 100644
@@ -7,9 +7,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu/ctype.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 #include "cpu.h"
 
target/riscv/monitor.c +0 -1
index a9d31114442..3f206b9fca5 100644
@@ -25,7 +25,6 @@
 #include "cpu_bits.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "system/memory.h"
 
 #ifdef TARGET_RISCV64
target/sh4/monitor.c +0 -1
index 2da6a5426eb..50324d3600c 100644
@@ -24,7 +24,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
 static void print_tlb(Monitor *mon, int idx, tlb_t *tlb)
target/sparc/monitor.c +0 -1
index a60671a60a4..99abddbf1e0 100644
@@ -24,7 +24,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
 
target/xtensa/monitor.c +0 -1
index fbf60d55530..2af84934f83 100644
@@ -24,7 +24,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
Signature · 1 line
2.53.0
Reviewed-by on v2 4/27
#8 lore raw

Re: [PATCH v2 04/27] monitor: Remove 'monitor/hmp-target.h' header

Quoted 27 lines · Philippe Mathieu-Daudé

he "monitor/hmp-target.h" header doesn't contain any target-specific declarations anymore. Merge it with "monitor/hmp.h", its target-agnostic counterpart.

---
  MAINTAINERS                   |  1 -
  include/monitor/hmp-target.h  | 42 -----------------------------------
  include/monitor/hmp.h         | 12 ++++++++++
  hw/i386/sgx-stub.c            |  1 -
  hw/i386/sgx.c                 |  1 -
  monitor/hmp-cmds.c            |  1 -
  monitor/hmp-target.c          |  1 -
  monitor/hmp.c                 |  1 -
  stubs/target-monitor-defs.c   |  2 +-
  target/i386/cpu-apic.c        |  1 -
  target/i386/monitor.c         |  1 -
  target/i386/sev-system-stub.c |  1 -
  target/i386/sev.c             |  1 -
  target/m68k/monitor.c         |  1 -
  target/ppc/monitor.c          |  2 --
  target/riscv/monitor.c        |  1 -
  target/sh4/monitor.c          |  1 -
  target/sparc/monitor.c        |  1 -
  target/xtensa/monitor.c       |  1 -
  19 files changed, 13 insertions(+), 60 deletions(-)
Quoted 1 line

delete mode 100644 include/monitor/hmp-target.h

r~

#9 lore raw

PATCH v2 5/27 monitor: Forward-declare the MonitorDef type

In reply to Philippe Mathieu-Daudé

Rather than having core header forced to include "monitor/hmp.h" to get the MonitorDef type declaration, forward-declare it in "qemu/typedefs.h".

---
 include/monitor/hmp.h   | 6 +++---
 include/qemu/typedefs.h | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)
include/monitor/hmp.h +3 -3
index f17a50a3fed..516089eb5c6 100644
@@ -17,11 +17,11 @@
 #include "qemu/readline.h"
 #include "qapi/qapi-types-common.h"
 
-typedef struct MonitorDef {
+struct MonitorDef {
     const char *name;
     int offset;
-    int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset);
-} MonitorDef;
+    int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset);
+};
 
 const MonitorDef *target_monitor_defs(void);
 int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval);
include/qemu/typedefs.h +1 -0
index 416a8c9acea..07f2ae7c9f1 100644
@@ -72,6 +72,7 @@ typedef struct MemoryRegionSection MemoryRegionSection;
 typedef struct MigrationIncomingState MigrationIncomingState;
 typedef struct MigrationState MigrationState;
 typedef struct Monitor Monitor;
+typedef struct MonitorDef MonitorDef;
 typedef struct MSIMessage MSIMessage;
 typedef struct NetClientState NetClientState;
 typedef struct NetFilterState NetFilterState;
Signature · 1 line
2.53.0
Reviewed-by on v2 5/27
#10 lore raw

Re: [PATCH v2 05/27] monitor: Forward-declare the MonitorDef type

Quoted 9 lines · Philippe Mathieu-Daudé

Rather than having core header forced to include "monitor/hmp.h" to get the MonitorDef type declaration, forward-declare it in "qemu/typedefs.h".

---
  include/monitor/hmp.h   | 6 +++---
  include/qemu/typedefs.h | 1 +
  2 files changed, 4 insertions(+), 3 deletions(-)

r~

#11 lore raw

PATCH v2 6/27 cpus: Introduce SysemuCPUOps::monitor_defs hook

In reply to Philippe Mathieu-Daudé

Allow targets to register their legacy target_monitor_defs() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper.

---
 include/hw/core/sysemu-cpu-ops.h | 5 +++++
 monitor/hmp.c                    | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
include/hw/core/sysemu-cpu-ops.h +5 -0
index 7b2d2d2610f..a96f4907d05 100644
@@ -85,6 +85,11 @@ typedef struct SysemuCPUOps {
      */
     bool (*internal_is_big_endian)(CPUState *cpu);
 
+    /**
+     * @monitor_defs: Array of MonitorDef entries. This field is legacy,
+     *                use @gdb_core_xml_file to dump registers instead.
+     */
+    const MonitorDef *monitor_defs;
     /**
      * @legacy_vmsd: Legacy state for migration.
      *               Do not use in new targets, use #DeviceClass::vmsd instead.
monitor/hmp.c +7 -2
index 983048db1b9..6cf2f3e65ff 100644
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include <dirent.h>
 #include "hw/core/qdev.h"
+#include "hw/core/sysemu-cpu-ops.h"
 #include "monitor-internal.h"
 #include "monitor/hmp.h"
 #include "qobject/qdict.h"
@@ -1603,13 +1604,17 @@ void monitor_register_hmp_info_hrt(const char *name,
  */
 static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
 {
-    const MonitorDef *md = target_monitor_defs();
     CPUState *cs = mon_get_cpu(mon);
+    const MonitorDef *md;
     void *ptr;
     uint64_t tmp = 0;
     int ret;
 
-    if (cs == NULL || md == NULL) {
+    if (cs == NULL) {
+        return -1;
+    }
+    md = cs->cc->sysemu_ops->monitor_defs ?: target_monitor_defs();
+    if (md == NULL) {
         return -1;
     }
 
Signature · 1 line
2.53.0
Reviewed-by on v2 6/27
#12 lore raw

Re: [PATCH v2 06/27] cpus: Introduce SysemuCPUOps::monitor_defs hook

Quoted 9 lines · Philippe Mathieu-Daudé

Allow targets to register their legacy target_monitor_defs() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper.

---
  include/hw/core/sysemu-cpu-ops.h | 5 +++++
  monitor/hmp.c                    | 9 +++++++--
  2 files changed, 12 insertions(+), 2 deletions(-)

r~

#13 lore raw

PATCH v2 7/27 target/i386: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

In reply to Philippe Mathieu-Daudé

Restrict x86_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook, allowing to remove the target_monitor_defs() method.

---
 target/i386/cpu.c     | 24 ++++++++++++++++++++++++
 target/i386/monitor.c | 25 -------------------------
 2 files changed, 24 insertions(+), 25 deletions(-)
target/i386/cpu.c +24 -0
index c6fd1dc00eb..968414e7215 100644
@@ -39,6 +39,7 @@
 #include "exec/watchpoint.h"
 #ifndef CONFIG_USER_ONLY
 #include "confidential-guest.h"
+#include "monitor/hmp.h"
 #include "system/reset.h"
 #include "qapi/qapi-commands-machine.h"
 #include "system/address-spaces.h"
@@ -10685,6 +10686,28 @@ static const Property x86_cpu_properties[] = {
 };
 
 #ifndef CONFIG_USER_ONLY
+
+static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
+                              int offset)
+{
+    CPUArchState *env = mon_get_cpu_env(mon);
+    return env->eip + env->segs[R_CS].base;
+}
+
+static const MonitorDef x86_monitor_defs[] = {
+#define SEG(name, seg) \
+    { name ".limit", offsetof(CPUX86State, segs[seg].limit) },
+    SEG("cs", R_CS)
+    SEG("ds", R_DS)
+    SEG("es", R_ES)
+    SEG("ss", R_SS)
+    SEG("fs", R_FS)
+    SEG("gs", R_GS)
+    { "pc", 0, monitor_get_pc, },
+    { NULL },
+#undef SEG
+};
+
 #include "hw/core/sysemu-cpu-ops.h"
 
 static const struct SysemuCPUOps i386_sysemu_ops = {
@@ -10698,6 +10721,7 @@ static const struct SysemuCPUOps i386_sysemu_ops = {
     .write_elf64_note = x86_cpu_write_elf64_note,
     .write_elf32_qemunote = x86_cpu_write_elf32_qemunote,
     .write_elf64_qemunote = x86_cpu_write_elf64_qemunote,
+    .monitor_defs = x86_monitor_defs,
     .legacy_vmsd = &vmstate_x86_cpu,
 };
 #endif
target/i386/monitor.c +0 -25
index ddc666d3451..a536712c755 100644
@@ -591,28 +591,3 @@ void hmp_mce(Monitor *mon, const QDict *qdict)
                            flags);
     }
 }
-
-static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
-                              int offset)
-{
-    CPUArchState *env = mon_get_cpu_env(mon);
-    return env->eip + env->segs[R_CS].base;
-}
-
-const MonitorDef monitor_defs[] = {
-#define SEG(name, seg) \
-    { name ".limit", offsetof(CPUX86State, segs[seg].limit) },
-    SEG("cs", R_CS)
-    SEG("ds", R_DS)
-    SEG("es", R_ES)
-    SEG("ss", R_SS)
-    SEG("fs", R_FS)
-    SEG("gs", R_GS)
-    { "pc", 0, monitor_get_pc, },
-    { NULL },
-};
-
-const MonitorDef *target_monitor_defs(void)
-{
-    return monitor_defs;
-}
Signature · 1 line
2.53.0
Reviewed-by on v2 7/27
#14 lore raw

Re: [PATCH v2 07/27] target/i386: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

Quoted 9 lines · Philippe Mathieu-Daudé

Restrict x86_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook, allowing to remove the target_monitor_defs() method.

---
  target/i386/cpu.c     | 24 ++++++++++++++++++++++++
  target/i386/monitor.c | 25 -------------------------
  2 files changed, 24 insertions(+), 25 deletions(-)

r~

#15 lore raw

PATCH v2 8/27 target/m68k: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

In reply to Philippe Mathieu-Daudé

Restrict m68k_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook, allowing to remove the target_monitor_defs() method.

---
 target/m68k/cpu.c     | 18 ++++++++++++++++++
 target/m68k/monitor.c | 21 ---------------------
 2 files changed, 18 insertions(+), 21 deletions(-)
target/m68k/cpu.c +18 -0
index d849a4a90fc..f704a6af613 100644
@@ -25,6 +25,7 @@
 
 #ifndef CONFIG_USER_ONLY
 #include "migration/vmstate.h"
+#include "monitor/hmp.h"
 #endif
 
 #include "cpu.h"
@@ -602,11 +603,28 @@ static const VMStateDescription vmstate_m68k_cpu = {
     },
 };
 
+static const MonitorDef m68k_monitor_defs[] = {
+    { "ssp", offsetof(CPUM68KState, sp[0]) },
+    { "usp", offsetof(CPUM68KState, sp[1]) },
+    { "isp", offsetof(CPUM68KState, sp[2]) },
+    { "sfc", offsetof(CPUM68KState, sfc) },
+    { "dfc", offsetof(CPUM68KState, dfc) },
+    { "urp", offsetof(CPUM68KState, mmu.urp) },
+    { "srp", offsetof(CPUM68KState, mmu.srp) },
+    { "dttr0", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR0]) },
+    { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]) },
+    { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]) },
+    { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]) },
+    { "mmusr", offsetof(CPUM68KState, mmu.mmusr) },
+    { NULL },
+};
+
 #include "hw/core/sysemu-cpu-ops.h"
 
 static const struct SysemuCPUOps m68k_sysemu_ops = {
     .has_work = m68k_cpu_has_work,
     .get_phys_page_debug = m68k_cpu_get_phys_page_debug,
+    .monitor_defs = m68k_monitor_defs,
 };
 #endif /* !CONFIG_USER_ONLY */
 
target/m68k/monitor.c +0 -21
index be7411edca6..3e0df40a6b8 100644
@@ -21,24 +21,3 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 
     dump_mmu(env1);
 }
-
-static const MonitorDef monitor_defs[] = {
-    { "ssp", offsetof(CPUM68KState, sp[0]) },
-    { "usp", offsetof(CPUM68KState, sp[1]) },
-    { "isp", offsetof(CPUM68KState, sp[2]) },
-    { "sfc", offsetof(CPUM68KState, sfc) },
-    { "dfc", offsetof(CPUM68KState, dfc) },
-    { "urp", offsetof(CPUM68KState, mmu.urp) },
-    { "srp", offsetof(CPUM68KState, mmu.srp) },
-    { "dttr0", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR0]) },
-    { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]) },
-    { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]) },
-    { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]) },
-    { "mmusr", offsetof(CPUM68KState, mmu.mmusr) },
-    { NULL },
-};
-
-const MonitorDef *target_monitor_defs(void)
-{
-    return monitor_defs;
-}
Signature · 1 line
2.53.0
Reviewed-by on v2 8/27
#16 lore raw

Re: [PATCH v2 08/27] target/m68k: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

Quoted 9 lines · Philippe Mathieu-Daudé

Restrict m68k_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook, allowing to remove the target_monitor_defs() method.

---
  target/m68k/cpu.c     | 18 ++++++++++++++++++
  target/m68k/monitor.c | 21 ---------------------
  2 files changed, 18 insertions(+), 21 deletions(-)

r~

#17 lore raw

PATCH v2 9/27 target/sparc: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

In reply to Philippe Mathieu-Daudé

Restrict sparc64_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook (taking care to not register it on 32-bit SPARC target), allowing to remove the target_monitor_defs() method.

---
 target/sparc/cpu.c     | 19 +++++++++++++++++++
 target/sparc/monitor.c | 18 ------------------
 2 files changed, 19 insertions(+), 18 deletions(-)
target/sparc/cpu.c +19 -0
index 1493336e7a2..9c5175aca34 100644
@@ -993,12 +993,31 @@ static const Property sparc_cpu_properties[] = {
 };
 
 #ifndef CONFIG_USER_ONLY
+
+#ifdef TARGET_SPARC64
+#include "monitor/hmp.h"
+
+static const MonitorDef sparc64_monitor_defs[] = {
+    { "asi", offsetof(CPUSPARCState, asi) },
+    { "pstate", offsetof(CPUSPARCState, pstate) },
+    { "cansave", offsetof(CPUSPARCState, cansave) },
+    { "canrestore", offsetof(CPUSPARCState, canrestore) },
+    { "otherwin", offsetof(CPUSPARCState, otherwin) },
+    { "wstate", offsetof(CPUSPARCState, wstate) },
+    { "cleanwin", offsetof(CPUSPARCState, cleanwin) },
+    { NULL },
+};
+#endif
+
 #include "hw/core/sysemu-cpu-ops.h"
 
 static const struct SysemuCPUOps sparc_sysemu_ops = {
     .has_work = sparc_cpu_has_work,
     .get_phys_page_debug = sparc_cpu_get_phys_page_debug,
     .legacy_vmsd = &vmstate_sparc_cpu,
+#if defined(TARGET_SPARC64)
+    .monitor_defs = sparc64_monitor_defs,
+#endif
 };
 #endif
 
target/sparc/monitor.c +0 -18
index 99abddbf1e0..36f3d8d58e9 100644
@@ -37,21 +37,3 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict)
     }
     dump_mmu(env1);
 }
-
-const MonitorDef monitor_defs[] = {
-#ifdef TARGET_SPARC64
-    { "asi", offsetof(CPUSPARCState, asi) },
-    { "pstate", offsetof(CPUSPARCState, pstate) },
-    { "cansave", offsetof(CPUSPARCState, cansave) },
-    { "canrestore", offsetof(CPUSPARCState, canrestore) },
-    { "otherwin", offsetof(CPUSPARCState, otherwin) },
-    { "wstate", offsetof(CPUSPARCState, wstate) },
-    { "cleanwin", offsetof(CPUSPARCState, cleanwin) },
-#endif
-    { NULL },
-};
-
-const MonitorDef *target_monitor_defs(void)
-{
-    return monitor_defs;
-}
Signature · 1 line
2.53.0
Reviewed-by on v2 9/27
#18 lore raw

Re: [PATCH v2 09/27] target/sparc: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

Quoted 10 lines · Philippe Mathieu-Daudé

Restrict sparc64_monitor_defs[] to cpu.c, register it asSysemuCPUOps::monitor_defs hook (taking care to not register it on 32-bit SPARC target), allowing to remove the target_monitor_defs() method.

---
  target/sparc/cpu.c     | 19 +++++++++++++++++++
  target/sparc/monitor.c | 18 ------------------
  2 files changed, 19 insertions(+), 18 deletions(-)

r~

#19 lore raw

PATCH v2 10/27 monitor: Remove target_monitor_defs()

In reply to Philippe Mathieu-Daudé

target_monitor_defs() is now only a dead stub. Remove as pointless.

---
 include/monitor/hmp.h       | 1 -
 monitor/hmp.c               | 2 +-
 stubs/target-monitor-defs.c | 7 -------
 stubs/meson.build           | 1 -
 4 files changed, 1 insertion(+), 10 deletions(-)
 delete mode 100644 stubs/target-monitor-defs.c
include/monitor/hmp.h +0 -1
index 516089eb5c6..cabb2c55f8e 100644
@@ -23,7 +23,6 @@ struct MonitorDef {
     int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset);
 };
 
-const MonitorDef *target_monitor_defs(void);
 int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval);
 
 CPUArchState *mon_get_cpu_env(Monitor *mon);
monitor/hmp.c +1 -1
index 6cf2f3e65ff..3d812ea3068 100644
@@ -1613,7 +1613,7 @@ static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
     if (cs == NULL) {
         return -1;
     }
-    md = cs->cc->sysemu_ops->monitor_defs ?: target_monitor_defs();
+    md = cs->cc->sysemu_ops->monitor_defs;
     if (md == NULL) {
         return -1;
     }
stubs/target-monitor-defs.c deleted +0 -7
deleted file mode 100644
index 0dd4cdb34f6..00000000000
@@ -1,7 +0,0 @@
-#include "qemu/osdep.h"
-#include "monitor/hmp.h"
-
-const MonitorDef *target_monitor_defs(void)
-{
-    return NULL;
-}
stubs/meson.build +0 -1
index 7189ff63ed5..10eb68ab55e 100644
@@ -75,7 +75,6 @@ if have_system
   endif
   stub_ss.add(files('kvm.c'))
   stub_ss.add(files('target-get-monitor-def.c'))
-  stub_ss.add(files('target-monitor-defs.c'))
   stub_ss.add(files('win32-kbd-hook.c'))
   stub_ss.add(files('xen-hw-stub.c'))
   stub_ss.add(files('monitor-arm-gic.c'))
Signature · 1 line
2.53.0
Reviewed-by on v2 10/27
#20 lore raw

Re: [PATCH v2 10/27] monitor: Remove target_monitor_defs()

Quoted 10 lines · Philippe Mathieu-Daudé

target_monitor_defs() is now only a dead stub. Remove as pointless.

---
  include/monitor/hmp.h       | 1 -
  monitor/hmp.c               | 2 +-
  stubs/target-monitor-defs.c | 7 -------
  stubs/meson.build           | 1 -
  4 files changed, 1 insertion(+), 10 deletions(-)

delete mode 100644 stubs/target-monitor-defs.c

r~

#21 lore raw

PATCH v2 11/27 cpus: Introduce SysemuCPUOps::monitor_get_register() hook

In reply to Philippe Mathieu-Daudé

Allow targets to register their legacy target_get_monitor_def() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper.

---
 include/hw/core/sysemu-cpu-ops.h | 8 ++++++++
 monitor/hmp.c                    | 6 +++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
include/hw/core/sysemu-cpu-ops.h +8 -0
index a96f4907d05..a9200ec5737 100644
@@ -85,11 +85,19 @@ typedef struct SysemuCPUOps {
      */
     bool (*internal_is_big_endian)(CPUState *cpu);
 
+    /**
+     * @monitor_get_register: Callback to fill @pval with register @name.
+     *                        This field is legacy, use @gdb_core_xml_file
+     *                        to dump registers instead.
+     */
+    int (*monitor_get_register)(CPUState *cs, const char *name, uint64_t *pval);
+
     /**
      * @monitor_defs: Array of MonitorDef entries. This field is legacy,
      *                use @gdb_core_xml_file to dump registers instead.
      */
     const MonitorDef *monitor_defs;
+
     /**
      * @legacy_vmsd: Legacy state for migration.
      *               Do not use in new targets, use #DeviceClass::vmsd instead.
monitor/hmp.c +5 -1
index 3d812ea3068..799855f3f68 100644
@@ -1632,7 +1632,11 @@ static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
         }
     }
 
-    ret = target_get_monitor_def(cs, name, &tmp);
+    if (cs->cc->sysemu_ops->monitor_get_register) {
+        ret = cs->cc->sysemu_ops->monitor_get_register(cs, name, &tmp);
+    } else {
+        ret = target_get_monitor_def(cs, name, &tmp);
+    }
     if (!ret) {
         *pval = target_long_bits() == 32 ? (int32_t)tmp : tmp;
     }
Signature · 1 line
2.53.0
Reviewed-by on v2 11/27
#22 lore raw

Re: [PATCH v2 11/27] cpus: Introduce SysemuCPUOps::monitor_get_register() hook

Quoted 9 lines · Philippe Mathieu-Daudé

Allow targets to register their legacy target_get_monitor_def() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper.

---
  include/hw/core/sysemu-cpu-ops.h | 8 ++++++++
  monitor/hmp.c                    | 6 +++++-
  2 files changed, 13 insertions(+), 1 deletion(-)

r~

#23 lore raw

PATCH v2 12/27 target/riscv: Register target_get_monitor_def in SysemuCPUOps

In reply to Philippe Mathieu-Daudé

Rename target_get_monitor_def() as riscv_monitor_get_register_legacy() and register it as SysemuCPUOps::monitor_get_register() handler.

---
 target/riscv/internals.h | 3 +++
 target/riscv/cpu.c       | 1 +
 target/riscv/monitor.c   | 4 +++-
 3 files changed, 7 insertions(+), 1 deletion(-)
target/riscv/internals.h +3 -0
index 35b923c4bf5..7c91f1872b6 100644
@@ -233,4 +233,7 @@ static inline int insn_len(uint16_t first_word)
     return (first_word & 3) == 3 ? 4 : 2;
 }
 
+int riscv_monitor_get_register_legacy(CPUState *cs, const char *name,
+                                      uint64_t *pval);
+
 #endif
target/riscv/cpu.c +1 -0
index 8ac935ac06e..dbd88fa6655 100644
@@ -2720,6 +2720,7 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
     .get_phys_page_debug = riscv_cpu_get_phys_page_debug,
     .write_elf64_note = riscv_cpu_write_elf64_note,
     .write_elf32_note = riscv_cpu_write_elf32_note,
+    .monitor_get_register = riscv_monitor_get_register_legacy,
     .legacy_vmsd = &vmstate_riscv_cpu,
 };
 #endif
target/riscv/monitor.c +3 -1
index 3f206b9fca5..1c90c779534 100644
@@ -26,6 +26,7 @@
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
 #include "system/memory.h"
+#include "internals.h"
 
 #ifdef TARGET_RISCV64
 #define PTE_HEADER_FIELDS       "vaddr            paddr            "\
@@ -310,7 +311,8 @@ static bool reg_is_vreg(const char *name)
     return false;
 }
 
-int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
+int riscv_monitor_get_register_legacy(CPUState *cs, const char *name,
+                                      uint64_t *pval)
 {
     CPURISCVState *env = &RISCV_CPU(cs)->env;
     target_ulong val = 0;
Signature · 1 line
2.53.0
Reviewed-by on v2 12/27
#24 lore raw

Re: [PATCH v2 12/27] target/riscv: Register target_get_monitor_def in SysemuCPUOps

Quoted 9 lines · Philippe Mathieu-Daudé

Rename target_get_monitor_def() as riscv_monitor_get_register_legacy() and register it asSysemuCPUOps::monitor_get_register() handler.

---
  target/riscv/internals.h | 3 +++
  target/riscv/cpu.c       | 1 +
  target/riscv/monitor.c   | 4 +++-
  3 files changed, 7 insertions(+), 1 deletion(-)

r~

#25 lore raw

PATCH v2 13/27 monitor: Remove target_get_monitor_def()

In reply to Philippe Mathieu-Daudé

target_get_monitor_def() is now only a dead stub. Remove as pointless.

---
 include/monitor/hmp.h          |  2 --
 monitor/hmp.c                  |  7 +++----
 stubs/target-get-monitor-def.c | 29 -----------------------------
 stubs/meson.build              |  1 -
 4 files changed, 3 insertions(+), 36 deletions(-)
 delete mode 100644 stubs/target-get-monitor-def.c
include/monitor/hmp.h +0 -2
index cabb2c55f8e..b444095f684 100644
@@ -23,8 +23,6 @@ struct MonitorDef {
     int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset);
 };
 
-int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval);
-
 CPUArchState *mon_get_cpu_env(Monitor *mon);
 CPUState *mon_get_cpu(Monitor *mon);
 
monitor/hmp.c +3 -4
index 799855f3f68..3b9e180c1ca 100644
@@ -1632,11 +1632,10 @@ static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
         }
     }
 
-    if (cs->cc->sysemu_ops->monitor_get_register) {
-        ret = cs->cc->sysemu_ops->monitor_get_register(cs, name, &tmp);
-    } else {
-        ret = target_get_monitor_def(cs, name, &tmp);
+    if (!cs->cc->sysemu_ops->monitor_get_register) {
+        return -1;
     }
+    ret = cs->cc->sysemu_ops->monitor_get_register(cs, name, &tmp);
     if (!ret) {
         *pval = target_long_bits() == 32 ? (int32_t)tmp : tmp;
     }
stubs/target-get-monitor-def.c deleted +0 -29
deleted file mode 100644
index 394e0f9a7d2..00000000000
@@ -1,29 +0,0 @@
-/*
- *  Stub for target_get_monitor_def.
- *
- *  Copyright IBM Corp., 2015
- *
- *  Author: Alexey Kardashevskiy <[email protected]>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License,
- *  or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "qemu/osdep.h"
-
-int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval);
-
-int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
-{
-    return -1;
-}
stubs/meson.build +0 -1
index 10eb68ab55e..85f9e3a4f23 100644
@@ -74,7 +74,6 @@ if have_system
     stub_ss.add(files('igvm.c'))
   endif
   stub_ss.add(files('kvm.c'))
-  stub_ss.add(files('target-get-monitor-def.c'))
   stub_ss.add(files('win32-kbd-hook.c'))
   stub_ss.add(files('xen-hw-stub.c'))
   stub_ss.add(files('monitor-arm-gic.c'))
Signature · 1 line
2.53.0
Reviewed-by on v2 13/27
#26 lore raw

Re: [PATCH v2 13/27] monitor: Remove target_get_monitor_def()

Quoted 10 lines · Philippe Mathieu-Daudé

target_get_monitor_def() is now only a dead stub. Remove as pointless.

---
  include/monitor/hmp.h          |  2 --
  monitor/hmp.c                  |  7 +++----
  stubs/target-get-monitor-def.c | 29 -----------------------------
  stubs/meson.build              |  1 -
  4 files changed, 3 insertions(+), 36 deletions(-)

delete mode 100644 stubs/target-get-monitor-def.c

r~

#27 lore raw

PATCH v2 14/27 monitor/meson: Use SPICE with migration HMP commands

In reply to Philippe Mathieu-Daudé

When moving code around in commit 27be86351ec ("migration: Move the QMP command from monitor/ to migration/") we forgot to update the meson rule about SPICE pkg-config flags.

---
 migration/meson.build | 2 +-
 monitor/meson.build   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
migration/meson.build +1 -1
index c9f0f5f9f21..e583822dec6 100644
@@ -23,7 +23,6 @@ system_ss.add(files(
   'fd.c',
   'file.c',
   'global_state.c',
-  'migration-hmp-cmds.c',
   'migration.c',
   'multifd.c',
   'multifd-device-state.c',
@@ -37,6 +36,7 @@ system_ss.add(files(
   'socket.c',
   'tls.c',
 ), gnutls, zlib)
+system_ss.add([spice_headers, files('migration-hmp-cmds.c'), spice])
 
 if get_option('replication').allowed()
   system_ss.add(files('colo-failover.c', 'colo.c', 'multifd-colo.c'))
monitor/meson.build +2 -2
index 2647100e04c..585251804e4 100644
@@ -5,8 +5,8 @@ system_ss.add(files(
   'hmp-cmds.c',
   'hmp.c',
   'qemu-config-qmp.c',
+  'qmp-cmds.c',
 ))
-system_ss.add([spice_headers, files('qmp-cmds.c')])
 
 specific_ss.add(when: 'CONFIG_SYSTEM_ONLY',
-                if_true: [files('hmp-target.c'), spice])
+                if_true: [files('hmp-target.c')])
Signature · 1 line
2.53.0
Acked-by on v2 14/27
#28 lore raw

Re: [PATCH v2 14/27] monitor/meson: Use SPICE with migration HMP commands

Quoted 5 lines · Philippe Mathieu-Daudé

When moving code around in commit 27be86351ec ("migration: Move the QMP command from monitor/ to migration/") we forgot to update the meson rule about SPICE pkg-config flags.

Signature · 1 line
Peter Xu
Reviewed-by on v2 14/27
#29 lore raw

Re: [PATCH v2 14/27] monitor/meson: Use SPICE with migration HMP commands

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

When moving code around in commit 27be86351ec ("migration: Move the QMP command from monitor/ to migration/") we forgot to update the meson rule about SPICE pkg-config flags.

---
  migration/meson.build | 2 +-
  monitor/meson.build   | 4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)
#30 lore raw

PATCH v2 15/27 stubs: Rename monitor* -> qmp* files

In reply to Philippe Mathieu-Daudé

We use 'HMP' for Human monitor and 'QMP' for 'Machine protocol'. These files aren't about human monitor but QMP, so rename them for clarity using the 'qmp-' prefix instead of 'monitor-'.

---
 MAINTAINERS                                      |  6 ++++++
 stubs/{monitor-arm-gic.c => qmp-arm-gic.c}       |  0
 ...nitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} |  0
 stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c}   |  0
 stubs/{monitor-cpu.c => qmp-cpu.c}               |  0
 stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c}     |  0
 stubs/{monitor-i386-sev.c => qmp-i386-sev.c}     |  0
 stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c}     |  0
 stubs/{monitor-i386-xen.c => qmp-i386-xen.c}     |  0
 stubs/meson.build                                | 16 ++++++++--------
 10 files changed, 14 insertions(+), 8 deletions(-)
 rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%)
 rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%)
 rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%)
 rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%)
 rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%)
 rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%)
 rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%)
 rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%)
MAINTAINERS +6 -0
index edbbd544d62..932d6aee507 100644
@@ -121,6 +121,7 @@ F: include/hw/s390x/
 F: include/hw/watchdog/wdt_diag288.h
 F: pc-bios/s390-ccw/
 F: pc-bios/s390-ccw.img
+F: stubs/qmp-cpu-s390x.c
 F: target/s390x/
 F: docs/system/target-s390x.rst
 F: docs/system/s390x/
@@ -496,6 +497,7 @@ M: Christian Borntraeger <[email protected]>
 R: Eric Farman <[email protected]>
 R: Matthew Rosato <[email protected]>
 S: Supported
+F: stubs/qmp-cpu-s390x-kvm.c
 F: target/s390x/kvm/
 F: target/s390x/machine.c
 F: target/s390x/sigp.c
@@ -510,6 +512,8 @@ L: [email protected]
 S: Supported
 F: docs/system/i386/amd-memory-encryption.rst
 F: docs/system/i386/sgx.rst
+F: stubs/qmp-i386-sev.c
+F: stubs/qmp-i386-sgx.c
 F: target/i386/kvm/
 F: target/i386/sev*
 F: scripts/kvm/vmxcap
@@ -522,6 +526,7 @@ S: Supported
 F: include/system/kvm_xen.h
 F: target/i386/kvm/xen*
 F: hw/i386/kvm/xen*
+F: stubs/qmp-i386-xen.c
 F: tests/functional/x86_64/test_kvm_xen.py
 
 Guest CPU Cores (other accelerators)
@@ -800,6 +805,7 @@ F: include/hw/timer/a9gtimer.h
 F: include/hw/timer/arm_mptimer.h
 F: include/hw/timer/armv7m_systick.h
 F: include/hw/misc/armv7m_ras.h
+F: stubs/qmp-arm-gic.c
 F: tests/qtest/test-arm-mptimer.c
 
 Bananapi M2U
stubs/qmp-arm-gic.c renamed from stubs/monitor-arm-gic.c +0 -0
similarity index 100%
rename from stubs/monitor-arm-gic.c
rename to stubs/qmp-arm-gic.c
stubs/qmp-cpu-s390x-kvm.c renamed from stubs/monitor-cpu-s390x-kvm.c +0 -0
similarity index 100%
rename from stubs/monitor-cpu-s390x-kvm.c
rename to stubs/qmp-cpu-s390x-kvm.c
stubs/qmp-cpu-s390x.c renamed from stubs/monitor-cpu-s390x.c +0 -0
similarity index 100%
rename from stubs/monitor-cpu-s390x.c
rename to stubs/qmp-cpu-s390x.c
stubs/qmp-cpu.c renamed from stubs/monitor-cpu.c +0 -0
similarity index 100%
rename from stubs/monitor-cpu.c
rename to stubs/qmp-cpu.c
stubs/qmp-i386-rtc.c renamed from stubs/monitor-i386-rtc.c +0 -0
similarity index 100%
rename from stubs/monitor-i386-rtc.c
rename to stubs/qmp-i386-rtc.c
stubs/qmp-i386-sev.c renamed from stubs/monitor-i386-sev.c +0 -0
similarity index 100%
rename from stubs/monitor-i386-sev.c
rename to stubs/qmp-i386-sev.c
stubs/qmp-i386-sgx.c renamed from stubs/monitor-i386-sgx.c +0 -0
similarity index 100%
rename from stubs/monitor-i386-sgx.c
rename to stubs/qmp-i386-sgx.c
stubs/qmp-i386-xen.c renamed from stubs/monitor-i386-xen.c +0 -0
similarity index 100%
rename from stubs/monitor-i386-xen.c
rename to stubs/qmp-i386-xen.c
stubs/meson.build +8 -8
index 85f9e3a4f23..356d7800760 100644
@@ -76,14 +76,14 @@ if have_system
   stub_ss.add(files('kvm.c'))
   stub_ss.add(files('win32-kbd-hook.c'))
   stub_ss.add(files('xen-hw-stub.c'))
-  stub_ss.add(files('monitor-arm-gic.c'))
-  stub_ss.add(files('monitor-i386-rtc.c'))
-  stub_ss.add(files('monitor-i386-sev.c'))
-  stub_ss.add(files('monitor-i386-sgx.c'))
-  stub_ss.add(files('monitor-i386-xen.c'))
-  stub_ss.add(files('monitor-cpu.c'))
-  stub_ss.add(files('monitor-cpu-s390x.c'))
-  stub_ss.add(files('monitor-cpu-s390x-kvm.c'))
+  stub_ss.add(files('qmp-arm-gic.c'))
+  stub_ss.add(files('qmp-i386-rtc.c'))
+  stub_ss.add(files('qmp-i386-sev.c'))
+  stub_ss.add(files('qmp-i386-sgx.c'))
+  stub_ss.add(files('qmp-i386-xen.c'))
+  stub_ss.add(files('qmp-cpu.c'))
+  stub_ss.add(files('qmp-cpu-s390x.c'))
+  stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
 endif
 
 if have_system or have_user
Signature · 1 line
2.53.0
Reviewed-by on v2 15/27
#31 lore raw

Re: [PATCH v2 15/27] stubs: Rename monitor* -> qmp* files

Quoted 17 lines · Philippe Mathieu-Daudé

We use 'HMP' for Human monitor and 'QMP' for 'Machine protocol'. These files aren't about human monitor but QMP, so rename them for clarity using the 'qmp-' prefix instead of 'monitor-'.

---
  MAINTAINERS                                      |  6 ++++++
  stubs/{monitor-arm-gic.c => qmp-arm-gic.c}       |  0
  ...nitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} |  0
  stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c}   |  0
  stubs/{monitor-cpu.c => qmp-cpu.c}               |  0
  stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c}     |  0
  stubs/{monitor-i386-sev.c => qmp-i386-sev.c}     |  0
  stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c}     |  0
  stubs/{monitor-i386-xen.c => qmp-i386-xen.c}     |  0
  stubs/meson.build                                | 16 ++++++++--------
  10 files changed, 14 insertions(+), 8 deletions(-)
Quoted 9 lines

rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%) rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%) rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%) rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%)
rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%) rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%) rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%) rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%)

#32 lore raw

PATCH v2 16/27 monitor: Make 'info via' a generic command

In reply to Philippe Mathieu-Daudé

In order to build hmp-commands-info.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the device is not available.

---
 MAINTAINERS            |  2 +-
 hw/misc/mos6522-stub.c | 16 ++++++++++++++++
 hmp-commands-info.hx   |  2 --
 hw/misc/meson.build    |  1 +
 4 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 hw/misc/mos6522-stub.c
MAINTAINERS +1 -1
index 932d6aee507..1810625eb1e 100644
@@ -1558,7 +1558,7 @@ F: hw/ppc/mac_newworld.c
 F: hw/pci-host/uninorth.c
 F: hw/pci-bridge/dec.[hc]
 F: hw/misc/macio/
-F: hw/misc/mos6522.c
+F: hw/misc/mos6522*.c
 F: hw/nvram/mac_nvram.c
 F: hw/ppc/fw_cfg.c
 F: hw/input/adb*
hw/misc/mos6522-stub.c new file +16 -0
new file mode 100644
index 00000000000..85eb0ee36ee
@@ -0,0 +1,16 @@
+/*
+ * QEMU MOS6522 VIA stubs
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp.h"
+
+void hmp_info_via(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "MOS6522 VIA is not available in this QEMU\n");
+}
hmp-commands-info.hx +0 -2
index 74c741f80e2..463038c302a 100644
@@ -885,7 +885,6 @@ SRST
     Show intel SGX information.
 ERST
 
-#if defined(CONFIG_MOS6522)
     {
         .name         = "via",
         .args_type    = "",
@@ -893,7 +892,6 @@ ERST
         .help         = "show guest mos6522 VIA devices",
         .cmd          = hmp_info_via,
     },
-#endif
 
 SRST
   ``info via``
hw/misc/meson.build +1 -0
index 245ab9b98cc..d7e97a4a32f 100644
@@ -20,6 +20,7 @@ system_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_ras.c'))
 
 # Mac devices
 system_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c'))
+stub_ss.add(files('mos6522-stub.c'))
 system_ss.add(when: 'CONFIG_DJMEMC', if_true: files('djmemc.c'))
 system_ss.add(when: 'CONFIG_IOSB', if_true: files('iosb.c'))
 
Signature · 1 line
2.53.0
Reviewed-by on v2 16/27
#33 lore raw

Re: [PATCH v2 16/27] monitor: Make 'info via' a generic command

Quoted 5 lines · Philippe Mathieu-Daudé

In order to build hmp-commands-info.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the device is not available.

Quoted 8 lines
---
  MAINTAINERS            |  2 +-
  hw/misc/mos6522-stub.c | 16 ++++++++++++++++
  hmp-commands-info.hx   |  2 --
  hw/misc/meson.build    |  1 +
  4 files changed, 18 insertions(+), 3 deletions(-)

create mode 100644 hw/misc/mos6522-stub.c

r~

#34 lore raw

PATCH v2 17/27 monitor: Make Xen emulation commands generic ones

In reply to Philippe Mathieu-Daudé

In order to build hmp-commands.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the feature is not available.

---
 hw/i386/kvm/xen-stubs.c | 12 ++++++++++++
 hmp-commands.hx         |  2 --
 2 files changed, 12 insertions(+), 2 deletions(-)
hw/i386/kvm/xen-stubs.c +12 -0
index ce73119ee7a..bf6ac28bef4 100644
@@ -12,6 +12,8 @@
 #include "qemu/osdep.h"
 
 #include "qapi/error.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp.h"
 
 #include "xen_evtchn.h"
 #include "xen_primary_console.h"
@@ -37,3 +39,13 @@ void xen_primary_console_create(void)
 void xen_primary_console_set_be_port(uint16_t port)
 {
 }
+
+void hmp_xen_event_list(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "XEN emulation is not available in this QEMU\n");
+}
+
+void hmp_xen_event_inject(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "XEN emulation is not available in this QEMU\n");
+}
hmp-commands.hx +0 -2
index 5cc4788f12d..06d7b17bf25 100644
@@ -1839,7 +1839,6 @@ SRST
 ERST
 #endif
 
-#if defined(CONFIG_XEN_EMU)
     {
         .name       = "xen-event-inject",
         .args_type  = "port:i",
@@ -1866,4 +1865,3 @@ SRST
 ``xen-event-list``
   List event channels in the guest
 ERST
-#endif
Signature · 1 line
2.53.0
Acked-by on v2 17/27
#35 lore raw

Re: [PATCH v2 17/27] monitor: Make Xen emulation commands generic ones

Quoted 6 lines · Philippe Mathieu-Daudé

In order to build hmp-commands.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the feature is not available.

Reviewed-by on v2 17/27
#36 lore raw

Re: [PATCH v2 17/27] monitor: Make Xen emulation commands generic ones

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

In order to build hmp-commands.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the feature is not available.

---
  hw/i386/kvm/xen-stubs.c | 12 ++++++++++++
  hmp-commands.hx         |  2 --
  2 files changed, 12 insertions(+), 2 deletions(-)

r~

#37 lore raw

PATCH v2 18/27 system: Expose 'arch_init.h' as 'qemu/target-arch-defs.h'

In reply to Philippe Mathieu-Daudé

We already have a file unit outside of the local system' folder which include "system/arch_init.h". We want more files to use it, so make it official it is a generic header by moving it under include. Rename as "qemu/base-arch-defs.h" which is more descriptive.

---
 system/arch_init.h => include/qemu/base-arch-defs.h | 10 ++++++++--
 hw/pci/pci.c                                        |  2 +-
 system/arch_init.c                                  |  2 +-
 system/qdev-monitor.c                               |  2 +-
 system/vl.c                                         |  2 +-
 5 files changed, 12 insertions(+), 6 deletions(-)
 rename system/arch_init.h => include/qemu/base-arch-defs.h (92%)
include/qemu/base-arch-defs.h renamed from system/arch_init.h +8 -2
similarity index 92%
rename from system/arch_init.h
rename to include/qemu/base-arch-defs.h
index 0c2b1f3a5d0..f33465738c9 100644
@@ -1,5 +1,11 @@
-#ifndef QEMU_ARCH_INIT_H
-#define QEMU_ARCH_INIT_H
+/*
+ * QEMU base architecture bit definitions
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_BASE_ARCH_DEFS_H
+#define QEMU_BASE_ARCH_DEFS_H
 
 #include "qapi/qapi-types-machine.h"
 
hw/pci/pci.c +1 -1
index 2c3657d00de..a38dffd4899 100644
@@ -36,7 +36,7 @@
 #include "migration/qemu-file-types.h"
 #include "migration/vmstate.h"
 #include "net/net.h"
-#include "system/arch_init.h"
+#include "qemu/base-arch-defs.h"
 #include "system/numa.h"
 #include "system/runstate.h"
 #include "system/system.h"
system/arch_init.c +1 -1
index 604d5909ed0..1ad2f3d6f78 100644
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
-#include "system/arch_init.h"
+#include "qemu/base-arch-defs.h"
 #include "qemu/bitops.h"
 #include "qemu/target-info-qapi.h"
 
system/qdev-monitor.c +1 -1
index 2ed95e83602..2e9dbb9b5c2 100644
@@ -23,7 +23,7 @@
 #include "monitor/hmp-completion.h"
 #include "monitor/monitor.h"
 #include "monitor/qdev.h"
-#include "system/arch_init.h"
+#include "qemu/base-arch-defs.h"
 #include "system/runstate.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-qdev.h"
system/vl.c +1 -1
index 246623b3196..23f1da66369 100644
@@ -112,7 +112,7 @@
 #include "trace/control.h"
 #include "qemu/plugin.h"
 #include "qemu/queue.h"
-#include "system/arch_init.h"
+#include "qemu/base-arch-defs.h"
 #include "system/confidential-guest-support.h"
 
 #include "ui/qemu-spice.h"
Signature · 1 line
2.53.0
Reviewed-by on v2 18/27
#38 lore raw

Re: [PATCH v2 18/27] system: Expose 'arch_init.h' as 'qemu/target-arch-defs.h'

Quoted 7 lines · Philippe Mathieu-Daudé

We already have a file unit outside of the local system' folder which include "system/arch_init.h". We want more files to use it, so make it official it is a generic header by moving it under include. Rename as "qemu/base-arch-defs.h" which is more descriptive.

Quoted 8 lines
---
  system/arch_init.h => include/qemu/base-arch-defs.h | 10 ++++++++--
  hw/pci/pci.c                                        |  2 +-
  system/arch_init.c                                  |  2 +-
  system/qdev-monitor.c                               |  2 +-
  system/vl.c                                         |  2 +-
  5 files changed, 12 insertions(+), 6 deletions(-)

rename system/arch_init.h => include/qemu/base-arch-defs.h (92%)

$subject no longer matches patch.

Otherwise,

r~

#39 lore raw

PATCH v2 19/27 monitor: Introduce HMPCommand::arch_bitmask field

In reply to Philippe Mathieu-Daudé

Add the @arch_bitmask field to the HMPCommand structure, allowing to restrict a command to a set of target architectures (represented by the QEMU_ARCH_* enum constants).

---
 monitor/monitor-internal.h | 6 ++++++
 monitor/hmp-target.c       | 1 +
 monitor/hmp.c              | 4 ++++
 3 files changed, 11 insertions(+)
monitor/monitor-internal.h +6 -0
index 3ecd394ecf6..78281928e7a 100644
@@ -74,6 +74,12 @@ typedef struct HMPCommand {
     const char *params;
     const char *help;
     const char *flags; /* p=preconfig */
+    /**
+     * @arch_bitmask: bitmask of QEMU_ARCH_* constants
+     *     Allow to restrict the command for a particular set of
+     *     target architectures.
+     */
+    uint32_t arch_bitmask;
     void (*cmd)(Monitor *mon, const QDict *qdict);
     /*
      * If implementing a command that takes no arguments and simply
monitor/hmp-target.c +1 -0
index d07e545ef7e..9d8dcb8835a 100644
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/base-arch-defs.h"
 #include "monitor-internal.h"
 #include "monitor/qdev.h"
 #include "net/slirp.h"
monitor/hmp.c +4 -0
index 3b9e180c1ca..c1e99c462b8 100644
@@ -36,6 +36,7 @@
 #include "qemu/cutils.h"
 #include "qemu/log.h"
 #include "qemu/option.h"
+#include "qemu/base-arch-defs.h"
 #include "qemu/target-info.h"
 #include "qemu/units.h"
 #include "exec/gdbstub.h"
@@ -219,6 +220,9 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)
 
 static bool cmd_available(const HMPCommand *cmd)
 {
+    if (cmd->arch_bitmask && !qemu_arch_available(cmd->arch_bitmask)) {
+        return false;
+    }
     return phase_check(PHASE_MACHINE_READY) || cmd_can_preconfig(cmd);
 }
 
Signature · 1 line
2.53.0
Reviewed-by on v2 19/27
#40 lore raw

Re: [PATCH v2 19/27] monitor: Introduce HMPCommand::arch_bitmask field

Quoted 18 lines · Philippe Mathieu-Daudé

Add the @arch_bitmask field to the HMPCommand structure, allowing to restrict a command to a set of target architectures (represented by the QEMU_ARCH_* enum constants).

---
  monitor/monitor-internal.h | 6 ++++++
  monitor/hmp-target.c       | 1 +
  monitor/hmp.c              | 4 ++++
  3 files changed, 11 insertions(+)
monitor/monitor-internal.h +0 -0
index 3ecd394ecf6..78281928e7a 100644
@@ -74,6 +74,12 @@ typedef struct HMPCommand {
      const char *params;
      const char *help;

monitor/monitor-internal.h typedef struct HMPCommand { · line 85

Quoted 10 lines
monitor/monitor-internal.h +6 -0
      const char *flags; /* p=preconfig */
+    /**
+     * @arch_bitmask: bitmask of QEMU_ARCH_* constants
+     *     Allow to restrict the command for a particular set of
+     *     target architectures.
+     */
+    uint32_t arch_bitmask;
      void (*cmd)(Monitor *mon, const QDict *qdict);
      /*
       * If implementing a command that takes no arguments and simply

This and coroutine could be placed better to avoid two holes.

Otherwise,

r~

#41 lore raw

PATCH v2 20/27 hw/s390x: Reduce 'monitor/monitor.h' inclusions

In reply to Philippe Mathieu-Daudé

We want to make the HMP commands available for all targets, move the declarations to "monitor/hmp.h" where all other are, and only include the monitor headers in the source files.

---
 include/hw/s390x/storage-attributes.h | 4 ----
 include/hw/s390x/storage-keys.h       | 3 ---
 include/monitor/hmp.h                 | 5 +++++
 hw/s390x/s390-skeys.c                 | 2 ++
 hw/s390x/s390-stattrib.c              | 2 ++
 5 files changed, 9 insertions(+), 7 deletions(-)
include/hw/s390x/storage-attributes.h +0 -4
index 66716a97c05..0305873b019 100644
@@ -13,7 +13,6 @@
 #define S390_STORAGE_ATTRIBUTES_H
 
 #include "hw/core/qdev.h"
-#include "monitor/monitor.h"
 #include "qom/object.h"
 
 #define TYPE_S390_STATTRIB "s390-storage_attributes"
@@ -72,7 +71,4 @@ static inline Object *kvm_s390_stattrib_create(void)
 }
 #endif
 
-void hmp_info_cmma(Monitor *mon, const QDict *qdict);
-void hmp_migrationmode(Monitor *mon, const QDict *qdict);
-
 #endif /* S390_STORAGE_ATTRIBUTES_H */
include/hw/s390x/storage-keys.h +0 -3
index 2d02936c31c..666c05e2996 100644
@@ -13,7 +13,6 @@
 #define S390_STORAGE_KEYS_H
 
 #include "hw/core/qdev.h"
-#include "monitor/monitor.h"
 #include "qom/object.h"
 
 #define TYPE_S390_SKEYS "s390-skeys"
@@ -123,8 +122,6 @@ int s390_skeys_set(S390SKeysState *ks, uint64_t start_gfn,
 S390SKeysState *s390_get_skeys_device(void);
 
 void s390_qmp_dump_skeys(const char *filename, Error **errp);
-void hmp_dump_skeys(Monitor *mon, const QDict *qdict);
-void hmp_info_skeys(Monitor *mon, const QDict *qdict);
 
 #define TYPE_DUMP_SKEYS_INTERFACE "dump-skeys-interface"
 
include/monitor/hmp.h +5 -0
index b444095f684..a0a063db8e4 100644
@@ -182,4 +182,9 @@ void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
 void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
 void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
 
+void hmp_dump_skeys(Monitor *mon, const QDict *qdict);
+void hmp_info_skeys(Monitor *mon, const QDict *qdict);
+void hmp_info_cmma(Monitor *mon, const QDict *qdict);
+void hmp_migrationmode(Monitor *mon, const QDict *qdict);
+
 #endif
hw/s390x/s390-skeys.c +2 -0
index d974d97b5e7..7dca67d6618 100644
@@ -24,6 +24,8 @@
 #include "system/kvm.h"
 #include "migration/qemu-file-types.h"
 #include "migration/register.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
 #include "trace.h"
 
 #define S390_SKEYS_BUFFER_SIZE (128 * KiB)  /* Room for 128k storage keys */
hw/s390x/s390-stattrib.c +2 -0
index 2e83aa211cd..74b23b0a995 100644
@@ -15,6 +15,8 @@
 #include "system/ram_addr.h"
 #include "migration/qemu-file.h"
 #include "migration/register.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
 #include "hw/core/qdev-properties.h"
 #include "hw/s390x/storage-attributes.h"
 #include "qemu/error-report.h"
Signature · 1 line
2.53.0
Reviewed-by on v2 20/27
#42 lore raw

Re: [PATCH v2 20/27] hw/s390x: Reduce 'monitor/monitor.h' inclusions

Quoted 4 lines · Philippe Mathieu-Daudé

We want to make the HMP commands available for all targets, move the declarations to "monitor/hmp.h" where all other are, and only include the monitor headers in the source files.

Quoted 8 lines
---
  include/hw/s390x/storage-attributes.h | 4 ----
  include/hw/s390x/storage-keys.h       | 3 ---
  include/monitor/hmp.h                 | 5 +++++
  hw/s390x/s390-skeys.c                 | 2 ++
  hw/s390x/s390-stattrib.c              | 2 ++
  5 files changed, 9 insertions(+), 7 deletions(-)

r~

Acked-by on v2 20/27
#43 lore raw

Re: [PATCH v2 20/27] hw/s390x: Reduce 'monitor/monitor.h' inclusions

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

We want to make the HMP commands available for all targets, move the declarations to "monitor/hmp.h" where all other are, and only include the monitor headers in the source files.

Quoted 8 lines
---
 include/hw/s390x/storage-attributes.h | 4 ----
 include/hw/s390x/storage-keys.h       | 3 ---
 include/monitor/hmp.h                 | 5 +++++
 hw/s390x/s390-skeys.c                 | 2 ++
 hw/s390x/s390-stattrib.c              | 2 ++
 5 files changed, 9 insertions(+), 7 deletions(-)
#44 lore raw

PATCH v2 21/27 monitor: Do not check TARGET_S390X to build s390x commands

In reply to Philippe Mathieu-Daudé

These commands are filtered at build-time for s390x binary. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once.

Since the methods are used inconditionally within hw/s390x/, define them in the same stub file.

---
 MAINTAINERS               |  1 +
 include/monitor/hmp.h     |  7 +++++++
 monitor/hmp-target.c      |  5 -----
 stubs/hmp-cmds-hw-s390x.c | 15 +++++++++++++++
 hmp-commands-info.hx      |  6 ++----
 hmp-commands.hx           |  6 ++----
 stubs/meson.build         |  1 +
 7 files changed, 28 insertions(+), 13 deletions(-)
 create mode 100644 stubs/hmp-cmds-hw-s390x.c
MAINTAINERS +1 -0
index 1810625eb1e..e53158143a8 100644
@@ -122,6 +122,7 @@ F: include/hw/watchdog/wdt_diag288.h
 F: pc-bios/s390-ccw/
 F: pc-bios/s390-ccw.img
 F: stubs/qmp-cpu-s390x.c
+F: stubs/hmp-cmds-hw-s390x.c
 F: target/s390x/
 F: docs/system/target-s390x.rst
 F: docs/system/s390x/
include/monitor/hmp.h +7 -0
index a0a063db8e4..c8ce8579424 100644
@@ -16,6 +16,13 @@
 
 #include "qemu/readline.h"
 #include "qapi/qapi-types-common.h"
+#include "monitor/monitor.h"
+
+#define HMP_STUB(cmd) \
+    void hmp_##cmd(Monitor *mon, const QDict *qdict) \
+    { \
+        g_assert_not_reached(); \
+    }
 
 struct MonitorDef {
     const char *name;
monitor/hmp-target.c +0 -5
index 9d8dcb8835a..4968d511101 100644
@@ -35,11 +35,6 @@
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-machine.h"
 
-#if defined(TARGET_S390X)
-#include "hw/s390x/storage-keys.h"
-#include "hw/s390x/storage-attributes.h"
-#endif
-
 /* Make devices configuration available for use in hmp-commands*.hx templates */
 #include CONFIG_DEVICES
 
stubs/hmp-cmds-hw-s390x.c new file +15 -0
new file mode 100644
index 00000000000..2b4f4cac79f
@@ -0,0 +1,15 @@
+/*
+ * Human Monitor hw/s390x stubs
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(dump_skeys)
+HMP_STUB(info_cmma)
+HMP_STUB(info_skeys)
+HMP_STUB(migrationmode)
hmp-commands-info.hx +2 -4
index 463038c302a..28dec25642d 100644
@@ -717,30 +717,28 @@ SRST
     Show rocker OF-DPA groups.
 ERST
 
-#if defined(TARGET_S390X)
     {
         .name       = "skeys",
         .args_type  = "addr:l",
         .params     = "address",
         .help       = "Display the value of a storage key",
         .cmd        = hmp_info_skeys,
+        .arch_bitmask = QEMU_ARCH_S390X,
     },
-#endif
 
 SRST
   ``info skeys`` *address*
     Display the value of a storage key (s390 only)
 ERST
 
-#if defined(TARGET_S390X)
     {
         .name       = "cmma",
         .args_type  = "addr:l,count:l?",
         .params     = "address [count]",
         .help       = "Display the values of the CMMA storage attributes for a range of pages",
         .cmd        = hmp_info_cmma,
+        .arch_bitmask = QEMU_ARCH_S390X,
     },
-#endif
 
 SRST
   ``info cmma`` *address*
hmp-commands.hx +2 -4
index 06d7b17bf25..ff65b39b454 100644
@@ -1125,30 +1125,28 @@ SRST
 
 ERST
 
-#if defined(TARGET_S390X)
     {
         .name       = "dump-skeys",
         .args_type  = "filename:F",
         .params     = "",
         .help       = "Save guest storage keys into file 'filename'.\n",
         .cmd        = hmp_dump_skeys,
+        .arch_bitmask = QEMU_ARCH_S390X,
     },
-#endif
 
 SRST
 ``dump-skeys`` *filename*
   Save guest storage keys to a file.
 ERST
 
-#if defined(TARGET_S390X)
     {
         .name       = "migration_mode",
         .args_type  = "mode:i",
         .params     = "mode",
         .help       = "Enables or disables migration mode\n",
         .cmd        = hmp_migrationmode,
+        .arch_bitmask = QEMU_ARCH_S390X,
     },
-#endif
 
 SRST
 ``migration_mode`` *mode*
stubs/meson.build +1 -0
index 356d7800760..d4a6bc0dde4 100644
@@ -84,6 +84,7 @@ if have_system
   stub_ss.add(files('qmp-cpu.c'))
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
+  stub_ss.add(files('hmp-cmds-hw-s390x.c'))
 endif
 
 if have_system or have_user
Signature · 1 line
2.53.0
Reviewed-by on v2 21/27
#45 lore raw

Re: [PATCH v2 21/27] monitor: Do not check TARGET_S390X to build s390x commands

Quoted 18 lines · Philippe Mathieu-Daudé

These commands are filtered at build-time for s390x binary. By using the recently introducedHMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once.

Since the methods are used inconditionally within hw/s390x/, define them in the same stub file.

---
  MAINTAINERS               |  1 +
  include/monitor/hmp.h     |  7 +++++++
  monitor/hmp-target.c      |  5 -----
  stubs/hmp-cmds-hw-s390x.c | 15 +++++++++++++++
  hmp-commands-info.hx      |  6 ++----
  hmp-commands.hx           |  6 ++----
  stubs/meson.build         |  1 +
  7 files changed, 28 insertions(+), 13 deletions(-)
Quoted 1 line

create mode 100644 stubs/hmp-cmds-hw-s390x.c

r~

Acked-by on v2 21/27
#46 lore raw

Re: [PATCH v2 21/27] monitor: Do not check TARGET_S390X to build s390x commands

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

These commands are filtered at build-time for s390x binary. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once.

Since the methods are used inconditionally within hw/s390x/, define them in the same stub file.

Quoted 10 lines
---
 MAINTAINERS               |  1 +
 include/monitor/hmp.h     |  7 +++++++
 monitor/hmp-target.c      |  5 -----
 stubs/hmp-cmds-hw-s390x.c | 15 +++++++++++++++
 hmp-commands-info.hx      |  6 ++----
 hmp-commands.hx           |  6 ++----
 stubs/meson.build         |  1 +
 7 files changed, 28 insertions(+), 13 deletions(-)
 create mode 100644 stubs/hmp-cmds-hw-s390x.c
#47 lore raw

PATCH v2 22/27 monitor: Do not check TARGET_I386 to build target/i386/ commands

In reply to Philippe Mathieu-Daudé

These commands are filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once.

Since these methods are used inconditionally within target/i386/, define them in the same stub file.

---
 MAINTAINERS                  |  1 +
 stubs/hmp-cmds-target-i386.c | 13 +++++++++++++
 hmp-commands-info.hx         |  4 +---
 hmp-commands.hx              |  5 +----
 stubs/meson.build            |  1 +
 5 files changed, 17 insertions(+), 7 deletions(-)
 create mode 100644 stubs/hmp-cmds-target-i386.c
MAINTAINERS +1 -0
index e53158143a8..458951bc051 100644
@@ -148,6 +148,7 @@ F: configs/targets/i386-softmmu.mak
 F: configs/targets/x86_64-softmmu.mak
 F: docs/system/i386/
 F: docs/system/target-i386*
+F: stubs/hmp-cmds-target-i386.c
 F: target/i386/*.[ch]
 F: target/i386/Kconfig
 F: target/i386/meson.build
stubs/hmp-cmds-target-i386.c new file +13 -0
new file mode 100644
index 00000000000..43a167056d5
@@ -0,0 +1,13 @@
+/*
+ * Human Monitor x86 stubs
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(info_local_apic)
+HMP_STUB(mce)
hmp-commands-info.hx +1 -3
index 28dec25642d..b575e4ac993 100644
@@ -113,16 +113,14 @@ SRST
     Show the cpu registers.
 ERST
 
-#if defined(TARGET_I386)
     {
         .name       = "lapic",
         .args_type  = "apic-id:i?",
         .params     = "[apic-id]",
         .help       = "show local apic state (apic-id: local apic to read, default is which of current CPU)",
-
         .cmd        = hmp_info_local_apic,
+        .arch_bitmask = QEMU_ARCH_I386,
     },
-#endif
 
 SRST
   ``info lapic``
hmp-commands.hx +1 -4
index ff65b39b454..cfd53bdc744 100644
@@ -1488,18 +1488,15 @@ SRST
   Stop the QEMU embedded NBD server.
 ERST
 
-
-#if defined(TARGET_I386)
-
     {
         .name       = "mce",
         .args_type  = "broadcast:-b,cpu_index:i,bank:i,status:l,mcg_status:l,addr:l,misc:l",
         .params     = "[-b] cpu bank status mcgstatus addr misc",
         .help       = "inject a MCE on the given CPU [and broadcast to other CPUs with -b option]",
         .cmd        = hmp_mce,
+        .arch_bitmask = QEMU_ARCH_I386,
     },
 
-#endif
 SRST
 ``mce`` *cpu* *bank* *status* *mcgstatus* *addr* *misc*
   Inject an MCE on the given CPU (x86 only).
stubs/meson.build +1 -0
index d4a6bc0dde4..dc289e3a482 100644
@@ -85,6 +85,7 @@ if have_system
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
+  stub_ss.add(files('hmp-cmds-target-i386.c'))
 endif
 
 if have_system or have_user
Signature · 1 line
2.53.0
Reviewed-by on v2 22/27
#48 lore raw

Re: [PATCH v2 22/27] monitor: Do not check TARGET_I386 to build target/i386/ commands

Quoted 9 lines · Philippe Mathieu-Daudé

These commands are filtered at build-time for i386/x86_64 binaries. By using the recently introducedHMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once.

Since these methods are used inconditionally within target/i386/, define them in the same stub file.

Quoted 8 lines
---
  MAINTAINERS                  |  1 +
  stubs/hmp-cmds-target-i386.c | 13 +++++++++++++
  hmp-commands-info.hx         |  4 +---
  hmp-commands.hx              |  5 +----
  stubs/meson.build            |  1 +
  5 files changed, 17 insertions(+), 7 deletions(-)

create mode 100644 stubs/hmp-cmds-target-i386.c

r~

#49 lore raw

PATCH v2 23/27 monitor: Do not check TARGET_I386 to build 'info sgx' command

In reply to Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on the CONFIG_SGX definition, define it in its own stub file.

---
 MAINTAINERS            |  1 +
 hw/i386/sgx-hmp-stub.c | 16 ++++++++++++++++
 hw/i386/sgx-stub.c     |  5 -----
 hmp-commands-info.hx   |  3 +--
 hw/i386/meson.build    |  1 +
 5 files changed, 19 insertions(+), 7 deletions(-)
 create mode 100644 hw/i386/sgx-hmp-stub.c
MAINTAINERS +1 -0
index 458951bc051..31e973fdeb0 100644
@@ -514,6 +514,7 @@ L: [email protected]
 S: Supported
 F: docs/system/i386/amd-memory-encryption.rst
 F: docs/system/i386/sgx.rst
+F: hw/i386/sgx*
 F: stubs/qmp-i386-sev.c
 F: stubs/qmp-i386-sgx.c
 F: target/i386/kvm/
hw/i386/sgx-hmp-stub.c new file +16 -0
new file mode 100644
index 00000000000..cf1d9a6344b
@@ -0,0 +1,16 @@
+/*
+ * Human Monitor 'info sgx' stub (CONFIG_SGX)
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
+
+void hmp_info_sgx(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "SGX is not available in this QEMU\n");
+}
hw/i386/sgx-stub.c +0 -5
index 6e82773a86d..59d58926311 100644
@@ -22,11 +22,6 @@ SgxInfo *qmp_query_sgx_capabilities(Error **errp)
     return NULL;
 }
 
-void hmp_info_sgx(Monitor *mon, const QDict *qdict)
-{
-    monitor_printf(mon, "SGX is not available in this QEMU\n");
-}
-
 void pc_machine_init_sgx_epc(PCMachineState *pcms)
 {
     memset(&pcms->sgx_epc, 0, sizeof(SGXEPCState));
hmp-commands-info.hx +1 -2
index b575e4ac993..da9fdc0ab7b 100644
@@ -866,15 +866,14 @@ SRST
     Display the vcpu dirty page limit information.
 ERST
 
-#if defined(TARGET_I386)
     {
         .name       = "sgx",
         .args_type  = "",
         .params     = "",
         .help       = "show intel SGX information",
         .cmd        = hmp_info_sgx,
+        .arch_bitmask = QEMU_ARCH_I386,
     },
-#endif
 
 SRST
   ``info sgx``
hw/i386/meson.build +1 -0
index 63ae57baa51..b611fbb5a7f 100644
@@ -24,6 +24,7 @@ i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iommu.c'))
 i386_ss.add(when: 'CONFIG_VTD_ACCEL', if_true: files('intel_iommu_accel.c'))
 i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'),
                                 if_false: files('sgx-stub.c'))
+stub_ss.add(files('sgx-hmp-stub.c'))
 
 i386_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-common.c'))
 i386_ss.add(when: 'CONFIG_PC', if_true: files(
Signature · 1 line
2.53.0
Reviewed-by on v2 23/27
#50 lore raw

Re: [PATCH v2 23/27] monitor: Do not check TARGET_I386 to build 'info sgx' command

Quoted 9 lines · Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 binaries. By using the recently introducedHMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on the CONFIG_SGX definition, define it in its own stub file.

Quoted 8 lines
---
  MAINTAINERS            |  1 +
  hw/i386/sgx-hmp-stub.c | 16 ++++++++++++++++
  hw/i386/sgx-stub.c     |  5 -----
  hmp-commands-info.hx   |  3 +--
  hw/i386/meson.build    |  1 +
  5 files changed, 19 insertions(+), 7 deletions(-)

create mode 100644 hw/i386/sgx-hmp-stub.c

r~

#51 lore raw

PATCH v2 24/27 monitor: Do not check TARGET_I386 to build 'info sev' command

In reply to Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on the CONFIG_SEV definition, define it in its own stub file.

---
 MAINTAINERS                   |  1 +
 stubs/hmp-cmd-info_sev.c      | 16 ++++++++++++++++
 target/i386/sev-system-stub.c |  5 -----
 hmp-commands-info.hx          |  3 +--
 stubs/meson.build             |  1 +
 5 files changed, 19 insertions(+), 7 deletions(-)
 create mode 100644 stubs/hmp-cmd-info_sev.c
MAINTAINERS +1 -0
index 31e973fdeb0..5dcd24a8a89 100644
@@ -515,6 +515,7 @@ S: Supported
 F: docs/system/i386/amd-memory-encryption.rst
 F: docs/system/i386/sgx.rst
 F: hw/i386/sgx*
+F: stubs/hmp-cmd-info_sev.c
 F: stubs/qmp-i386-sev.c
 F: stubs/qmp-i386-sgx.c
 F: target/i386/kvm/
stubs/hmp-cmd-info_sev.c new file +16 -0
new file mode 100644
index 00000000000..f3624423a33
@@ -0,0 +1,16 @@
+/*
+ * Human Monitor 'info sev' stub (CONFIG_SEV)
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
+
+void hmp_info_sev(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "SEV is not available in this QEMU\n");
+}
target/i386/sev-system-stub.c +0 -5
index f799a338d60..d97536cca1c 100644
@@ -31,11 +31,6 @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
     g_assert_not_reached();
 }
 
-void hmp_info_sev(Monitor *mon, const QDict *qdict)
-{
-    monitor_printf(mon, "SEV is not available in this QEMU\n");
-}
-
 void pc_system_parse_sev_metadata(uint8_t *flash_ptr, size_t flash_size)
 {
 }
hmp-commands-info.hx +1 -2
index da9fdc0ab7b..336ab870a2c 100644
@@ -812,15 +812,14 @@ SRST
     enabled) memory in bytes.
 ERST
 
-#if defined(TARGET_I386)
     {
         .name       = "sev",
         .args_type  = "",
         .params     = "",
         .help       = "show SEV information",
         .cmd        = hmp_info_sev,
+        .arch_bitmask = QEMU_ARCH_I386,
     },
-#endif
 
 SRST
   ``info sev``
stubs/meson.build +1 -0
index dc289e3a482..09e73ef8b73 100644
@@ -84,6 +84,7 @@ if have_system
   stub_ss.add(files('qmp-cpu.c'))
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
+  stub_ss.add(files('hmp-cmd-info_sev.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
   stub_ss.add(files('hmp-cmds-target-i386.c'))
 endif
Signature · 1 line
2.53.0
Reviewed-by on v2 24/27
#52 lore raw

Re: [PATCH v2 24/27] monitor: Do not check TARGET_I386 to build 'info sev' command

Quoted 9 lines · Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 binaries. By using the recently introducedHMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on the CONFIG_SEV definition, define it in its own stub file.

Quoted 8 lines
---
  MAINTAINERS                   |  1 +
  stubs/hmp-cmd-info_sev.c      | 16 ++++++++++++++++
  target/i386/sev-system-stub.c |  5 -----
  hmp-commands-info.hx          |  3 +--
  stubs/meson.build             |  1 +
  5 files changed, 19 insertions(+), 7 deletions(-)

create mode 100644 stubs/hmp-cmd-info_sev.c

r~

#53 lore raw

PATCH v2 25/27 monitor: Do not check TARGET_I386/RISCV to build 'info mem' command

In reply to Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 and riscv32/riscv64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on a pair of distinct targets, define it in its own stub file.

---
 stubs/hmp-cmd-info_mem.c | 12 ++++++++++++
 hmp-commands-info.hx     |  3 +--
 stubs/meson.build        |  1 +
 3 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 stubs/hmp-cmd-info_mem.c
stubs/hmp-cmd-info_mem.c new file +12 -0
new file mode 100644
index 00000000000..8a53e367a9f
@@ -0,0 +1,12 @@
+/*
+ * Human Monitor 'info mem' stub
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(info_mem)
hmp-commands-info.hx +1 -2
index 336ab870a2c..2d0a8f7d48f 100644
@@ -209,15 +209,14 @@ SRST
     Show virtual to physical memory mappings.
 ERST
 
-#if defined(TARGET_I386) || defined(TARGET_RISCV)
     {
         .name       = "mem",
         .args_type  = "",
         .params     = "",
         .help       = "show the active virtual memory mappings",
         .cmd        = hmp_info_mem,
+        .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_RISCV,
     },
-#endif
 
 SRST
   ``info mem``
stubs/meson.build +1 -0
index 09e73ef8b73..ed7ca54ae06 100644
@@ -84,6 +84,7 @@ if have_system
   stub_ss.add(files('qmp-cpu.c'))
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
+  stub_ss.add(files('hmp-cmd-info_mem.c'))
   stub_ss.add(files('hmp-cmd-info_sev.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
   stub_ss.add(files('hmp-cmds-target-i386.c'))
Signature · 1 line
2.53.0
Reviewed-by on v2 25/27
#54 lore raw

Re: [PATCH v2 25/27] monitor: Do not check TARGET_I386/RISCV to build 'info mem' command

Quoted 8 lines · Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 and riscv32/riscv64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on a pair of distinct targets, define it in its own stub file.

Quoted 7 lines
---
  stubs/hmp-cmd-info_mem.c | 12 ++++++++++++
  hmp-commands-info.hx     |  3 +--
  stubs/meson.build        |  1 +
  3 files changed, 14 insertions(+), 2 deletions(-)

create mode 100644 stubs/hmp-cmd-info_mem.c

r~

#55 lore raw

PATCH v2 26/27 monitor: Do not check multiple TARGET_* to build 'info tlb' command

In reply to Philippe Mathieu-Daudé

This command is filtered at build-time for a selection of binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on a pair of distinct targets, define it in its own stub file.

---
 stubs/hmp-cmd-info_tlb.c | 12 ++++++++++++
 hmp-commands-info.hx     |  5 ++---
 stubs/meson.build        |  1 +
 3 files changed, 15 insertions(+), 3 deletions(-)
 create mode 100644 stubs/hmp-cmd-info_tlb.c
stubs/hmp-cmd-info_tlb.c new file +12 -0
new file mode 100644
index 00000000000..a144e68c1c7
@@ -0,0 +1,12 @@
+/*
+ * Human Monitor 'info tlb' stub
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(info_tlb)
hmp-commands-info.hx +2 -3
index 2d0a8f7d48f..0898221a486 100644
@@ -193,16 +193,15 @@ SRST
     Show PCI information.
 ERST
 
-#if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \
-    defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K)
     {
         .name       = "tlb",
         .args_type  = "",
         .params     = "",
         .help       = "show virtual to physical memory mappings",
         .cmd        = hmp_info_tlb,
+        .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_SH4 | QEMU_ARCH_SPARC \
+                        | QEMU_ARCH_PPC | QEMU_ARCH_XTENSA | QEMU_ARCH_M68K,
     },
-#endif
 
 SRST
   ``info tlb``
stubs/meson.build +1 -0
index ed7ca54ae06..3c6d0032e93 100644
@@ -86,6 +86,7 @@ if have_system
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
   stub_ss.add(files('hmp-cmd-info_mem.c'))
   stub_ss.add(files('hmp-cmd-info_sev.c'))
+  stub_ss.add(files('hmp-cmd-info_tlb.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
   stub_ss.add(files('hmp-cmds-target-i386.c'))
 endif
Signature · 1 line
2.53.0
Reviewed-by on v2 26/27
#56 lore raw

Re: [PATCH v2 26/27] monitor: Do not check multiple TARGET_* to build 'info tlb' command

Quoted 8 lines · Philippe Mathieu-Daudé

This command is filtered at build-time for a selection of binaries. By using the recently introducedHMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on a pair of distinct targets, define it in its own stub file.

Quoted 7 lines
---
  stubs/hmp-cmd-info_tlb.c | 12 ++++++++++++
  hmp-commands-info.hx     |  5 ++---
  stubs/meson.build        |  1 +
  3 files changed, 15 insertions(+), 3 deletions(-)

create mode 100644 stubs/hmp-cmd-info_tlb.c

r~

#57 lore raw

PATCH v2 27/27 monitor: Merge hmp-target.c code within hmp-cmds.c

In reply to Philippe Mathieu-Daudé

hmp-target.c doesn't contain any target-specific code anymore. Merge it within hmp-cmds.c (which is already built once).

---
 MAINTAINERS          |  1 -
 monitor/hmp-cmds.c   | 40 ++++++++++++++++++++++++
 monitor/hmp-target.c | 73 --------------------------------------------
 monitor/meson.build  |  3 --
 4 files changed, 40 insertions(+), 77 deletions(-)
 delete mode 100644 monitor/hmp-target.c
MAINTAINERS +0 -1
index 5dcd24a8a89..d184e25ddd4 100644
@@ -3414,7 +3414,6 @@ Human Monitor (HMP)
 M: Dr. David Alan Gilbert <[email protected]>
 S: Maintained
 F: monitor/monitor-internal.h
-F: monitor/hmp-target.c
 F: monitor/monitor.c
 F: monitor/hmp*
 F: hmp.h
monitor/hmp-cmds.c +40 -0
index e81632f5551..409a1a9c701 100644
@@ -14,6 +14,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/base-arch-defs.h"
 #include "system/address-spaces.h"
 #include "system/ioport.h"
 #include "exec/gdbstub.h"
@@ -22,19 +23,58 @@
 #include "monitor/hmp.h"
 #include "qemu/help_option.h"
 #include "monitor/hmp.h"
+#include "monitor/hmp-completion.h"
 #include "monitor/monitor-internal.h"
+#include "monitor/qdev.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-control.h"
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc.h"
+#include "block/block-hmp-cmds.h"
 #include "qobject/qdict.h"
 #include "qemu/cutils.h"
 #include "qemu/log.h"
+#include "net/slirp.h"
+#include "system/device_tree.h"
 #include "system/hw_accel.h"
 #include "system/memory.h"
 #include "system/system.h"
 #include "disas/disas.h"
 
+/* Please update hmp-commands.hx when adding or changing commands */
+static HMPCommand hmp_info_cmds[] = {
+#include "hmp-commands-info.h"
+    { NULL, NULL, },
+};
+
+/* hmp_cmds and hmp_info_cmds would be sorted at runtime */
+static HMPCommand hmp_cmds[] = {
+#include "hmp-commands.h"
+    { NULL, NULL, },
+};
+
+HMPCommand *hmp_cmds_for_target(bool info_command)
+{
+    return info_command ? hmp_info_cmds : hmp_cmds;
+}
+
+static int
+compare_mon_cmd(const void *a, const void *b)
+{
+    return strcmp(((const HMPCommand *)a)->name,
+            ((const HMPCommand *)b)->name);
+}
+
+static void __attribute__((__constructor__)) sortcmdlist(void)
+{
+    qsort(hmp_cmds, ARRAY_SIZE(hmp_cmds) - 1,
+          sizeof(*hmp_cmds),
+          compare_mon_cmd);
+    qsort(hmp_info_cmds, ARRAY_SIZE(hmp_info_cmds) - 1,
+          sizeof(*hmp_info_cmds),
+          compare_mon_cmd);
+}
+
 bool hmp_handle_error(Monitor *mon, Error *err)
 {
     if (err) {
monitor/hmp-target.c deleted +0 -73

73 lines not on this page · raw message

monitor/meson.build +0 -3
index 585251804e4..4c58dd148c0 100644
@@ -7,6 +7,3 @@ system_ss.add(files(
   'qemu-config-qmp.c',
   'qmp-cmds.c',
 ))
-
-specific_ss.add(when: 'CONFIG_SYSTEM_ONLY',
-                if_true: [files('hmp-target.c')])
Signature · 1 line
2.53.0
Reviewed-by on v2 27/27
#58 lore raw

Re: [PATCH v2 27/27] monitor: Merge hmp-target.c code within hmp-cmds.c

Quoted 11 lines · Philippe Mathieu-Daudé

hmp-target.c doesn't contain any target-specific code anymore. Merge it within hmp-cmds.c (which is already built once).

---
  MAINTAINERS          |  1 -
  monitor/hmp-cmds.c   | 40 ++++++++++++++++++++++++
  monitor/hmp-target.c | 73 --------------------------------------------
  monitor/meson.build  |  3 --
  4 files changed, 40 insertions(+), 77 deletions(-)

delete mode 100644 monitor/hmp-target.c

r~