All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h'
@ 2026-08-12 21:16 Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 01/23] hexagon: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
                   ` (22 more replies)
  0 siblings, 23 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

Missing review: 2, 11, 17+

Since v2:
- Fixed net/vhost-vdpa (new patch)
- Use QOM-cast macros (bonus)

Since v1:
- extract QMP inject_nmi/memsave/pmemsave out of cpus.c
  (first 12 patches left unchanged).

Another HMP cleanup series to help Marc-André with his
'Make HMP optional' series [*].

We could also remove "exec/hwaddr.h" by moving gpa2hva()
declaration elsewhere, and "qapi/qapi-types-misc.h" by
moving monitor_fdset_add_fd() out to some "monitor/fdset.h"
header.

[*] 20260626-qemu-no-hmp-v2-0-8af31bc54c61@redhat.com
Based-on: <20260812121232.71958-1-philmd@oss.qualcomm.com>

Philippe Mathieu-Daudé (23):
  hexagon: Remove unnecessary 'monitor/monitor.h' header
  net/vhost-vdpa: Include missing 'qemu/iov.h' header
  tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c
  qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h'
  qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header
  migration/hmp-cmds: Include 'block/block-global-state.h' header
  monitor: Include missing 'qemu/aio-wait.h' header
  monitor: Include missing 'qemu/lockable.h' header
  monitor: Include missing 'qemu/coroutine-core.h' header
  monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header
  monitor: Remove unnecessary 'block/block.h' header
  system: Remove unnecessary 'monitor/monitor.h' header
  system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c
  system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c
  system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c
  system: Move runstate-related code from cpus.c to runstate.c
  monitor: Rename MonitorQMP @mon -> @qmon
  monitor: Rename MonitorHMP @mon -> @hmon
  monitor: Better express monitor_read()'s opaque arg is of Monitor type
  monitor: Use QOM MONITOR() macro to access MonitorQMP->parent_obj
  monitor: Use QOM MONITOR() macro to access MonitorHMP->parent_obj
  monitor: Replace container_of(MonitorHMP, parent_obj) -> MONITOR_HMP()
  monitor/hmp: Remove unnecessary 'monitor/monitor.h' header

 MAINTAINERS                      |   2 +
 include/hw/hexagon/hexagon_tlb.h |   2 +-
 include/monitor/hmp.h            |   1 -
 include/monitor/monitor.h        |   7 +-
 include/qapi/qmp-registry.h      |   1 -
 monitor/monitor-internal.h       |   7 +-
 target/hexagon/hex_mmu.h         |   3 +-
 hw/core/machine-qmp-cmds.c       |   6 +
 migration/migration-hmp-cmds.c   |   5 +-
 monitor/fds.c                    |   1 +
 monitor/hmp-cmds.c               |  10 +-
 monitor/hmp.c                    | 164 ++++++++++---------
 monitor/monitor.c                |   2 +
 monitor/qmp-cmds-control.c       |  18 +--
 monitor/qmp-cmds.c               |  13 +-
 monitor/qmp.c                    | 270 ++++++++++++++++---------------
 net/vhost-vdpa.c                 |   1 +
 qapi/qmp-dispatch.c              |   2 +
 system/cpus.c                    | 247 ----------------------------
 system/device_tree.c             |   1 -
 system/dirtylimit-hmp-cmds.c     |  74 +++++++++
 system/dirtylimit.c              |  60 -------
 system/physmem-qmp-cmds.c        | 107 ++++++++++++
 system/physmem.c                 |   2 -
 system/runstate.c                | 154 ++++++++++++++++++
 tests/unit/test-util-sockets.c   |   1 +
 ui/ui-hmp-cmds.c                 |   6 +-
 system/meson.build               |   2 +
 28 files changed, 617 insertions(+), 552 deletions(-)
 create mode 100644 system/dirtylimit-hmp-cmds.c
 create mode 100644 system/physmem-qmp-cmds.c

-- 
2.53.0



^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 01/23] hexagon: Remove unnecessary 'monitor/monitor.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 02/23] net/vhost-vdpa: Include missing 'qemu/iov.h' header Philippe Mathieu-Daudé
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Brian Cain,
	Pierrick Bouvier

The Monitor type is used in these 2 files, as a pointer.
Since the type is forward-declared in "qemu/typedefs.h",
which all source files include via "qemu/osdep.h", we do
not need to include it.

Do however include "exec/hwaddr.h" and "exec/mmu-access-type.h"
which declare the types used by hex_tlb_find_match prototype:

  extern bool hex_tlb_find_match(CPUHexagonState *env, uint32_t VA,
                                 MMUAccessType access_type, hwaddr *PA, int *prot,
                                 ^^^^^^^^^^^^^              ^^^^^^
                                 uint64_t *size, int32_t *excp, int mmu_idx);

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/hexagon/hexagon_tlb.h | 2 +-
 target/hexagon/hex_mmu.h         | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/hw/hexagon/hexagon_tlb.h b/include/hw/hexagon/hexagon_tlb.h
index 90d9ed84043..760dc1ea811 100644
--- a/include/hw/hexagon/hexagon_tlb.h
+++ b/include/hw/hexagon/hexagon_tlb.h
@@ -12,7 +12,7 @@
 #include "qom/object.h"
 #include "exec/hwaddr.h"
 #include "exec/mmu-access-type.h"
-#include "monitor/monitor.h"
+
 #define TYPE_HEXAGON_TLB "hexagon-tlb"
 OBJECT_DECLARE_SIMPLE_TYPE(HexagonTLBState, HEXAGON_TLB)
 
diff --git a/target/hexagon/hex_mmu.h b/target/hexagon/hex_mmu.h
index 4f556c715a9..6aa450b9413 100644
--- a/target/hexagon/hex_mmu.h
+++ b/target/hexagon/hex_mmu.h
@@ -7,8 +7,9 @@
 #ifndef HEXAGON_MMU_H
 #define HEXAGON_MMU_H
 
+#include "exec/hwaddr.h"
+#include "exec/mmu-access-type.h"
 #include "cpu.h"
-#include "monitor/monitor.h"
 
 extern void hex_tlbw(CPUHexagonState *env, uint32_t index, uint64_t value);
 extern uint32_t hex_tlb_lookup(CPUHexagonState *env, uint32_t ssr, uint32_t VA);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 02/23] net/vhost-vdpa: Include missing 'qemu/iov.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 01/23] hexagon: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:28   ` Michael S. Tsirkin
  2026-08-12 21:16 ` [PATCH v3 03/23] tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c Philippe Mathieu-Daudé
                   ` (20 subsequent siblings)
  22 siblings, 1 reply; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé,
	Michael S. Tsirkin, Stefano Garzarella, Jason Wang

vhost-vdpa.c uses methods declared in the "qemu/iov." header.
Include it otherwise we get when refactoring unrelated headers:

  ../net/vhost-vdpa.c: In function ‘vhost_vdpa_net_load_cmd’:
  ../net/vhost-vdpa.c:714:24: error: implicit declaration of function ‘iov_size’
    714 |     size_t data_size = iov_size(data_sg, data_num), cmd_size;
        |                        ^~~~~~~~
  ../net/vhost-vdpa.c:714:24: error: nested extern declaration of ‘iov_size’
  ../net/vhost-vdpa.c:742:5: error: implicit declaration of function ‘iov_from_buf’
    742 |     iov_from_buf(out_cursor, 1, 0, &ctrl, sizeof(ctrl));
        |     ^~~~~~~~~~~~
  ../net/vhost-vdpa.c:742:5: error: nested extern declaration of ‘iov_from_buf’
  ../net/vhost-vdpa.c:744:5: error: implicit declaration of function ‘iov_to_buf’
    744 |     iov_to_buf(data_sg, data_num, 0,
        |     ^~~~~~~~~~
  ../net/vhost-vdpa.c:744:5: error: nested extern declaration of ‘iov_to_buf’
  ../net/vhost-vdpa.c:748:5: error: implicit declaration of function ‘iov_copy’
    748 |     iov_copy(&out, 1, out_cursor, 1, 0, cmd_size);
        |     ^~~~~~~~

Fixes: bd907ae4b00 ("vdpa: manual forward CVQ buffers")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 net/vhost-vdpa.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index c526c2b2dc0..1052361a4ab 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -17,6 +17,7 @@
 #include "hw/virtio/vhost-vdpa.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
+#include "qemu/iov.h"
 #include "qemu/log.h"
 #include "qemu/memalign.h"
 #include "qemu/option.h"
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 03/23] tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 01/23] hexagon: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 02/23] net/vhost-vdpa: Include missing 'qemu/iov.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 04/23] qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

test-util-sockets.c calls qemu_init_main_loop(), itself declared in
the "qemu/main-loop.h" header. Include the latter to avoid when
refactoring unrelated headers:

  ../tests/unit/test-util-sockets.c:553:5: error: call to undeclared function 'qemu_init_main_loop'
  553 |     qemu_init_main_loop(&error_abort);
      |     ^

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/unit/test-util-sockets.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c
index ee66d727c38..ab3f39c3efb 100644
--- a/tests/unit/test-util-sockets.c
+++ b/tests/unit/test-util-sockets.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "qapi/error.h"
 #include "socket-helpers.h"
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 04/23] qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h'
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 03/23] tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 05/23] qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Michael Roth

qmp-dispatch.c calls aio_wait_kick() and monitor_cur(). Include the
header declaring them in order to avoid the following build failure
when refactoring unrelated headers:

  ../qapi/qmp-dispatch.c:126:12: error: call to undeclared function 'monitor_cur'
    126 |     assert(monitor_cur() == NULL);
        |            ^
  ../qapi/qmp-dispatch.c:141:5: error: call to undeclared function 'aio_wait_kick'
    141 |     aio_wait_kick();
        |     ^

Fixes: 41725fa7eda ("qmp: Call monitor_set_cur() only in qmp_dispatch()")
Fixes: fc1a2ec7da5 ("monitor: Fix deadlock in monitor_cleanup")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 qapi/qmp-dispatch.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index e3897d51977..965cad64998 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 
 #include "qemu/aio.h"
+#include "qemu/aio-wait.h"
 #include "qapi/compat-policy.h"
 #include "qapi/error.h"
 #include "qapi/qmp-registry.h"
@@ -24,6 +25,7 @@
 #include "qobject/qbool.h"
 #include "qemu/coroutine.h"
 #include "qemu/main-loop.h"
+#include "monitor/monitor.h"
 
 Visitor *qobject_input_visitor_new_qmp(QObject *obj)
 {
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 05/23] qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 04/23] qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h' Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 06/23] migration/hmp-cmds: Include 'block/block-global-state.h' header Philippe Mathieu-Daudé
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Michael Roth

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qapi/qmp-registry.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/qapi/qmp-registry.h b/include/qapi/qmp-registry.h
index e0ee1ad3ac6..6146306a3a1 100644
--- a/include/qapi/qmp-registry.h
+++ b/include/qapi/qmp-registry.h
@@ -14,7 +14,6 @@
 #ifndef QAPI_QMP_DISPATCH_H
 #define QAPI_QMP_DISPATCH_H
 
-#include "monitor/monitor.h"
 #include "qemu/queue.h"
 
 typedef void (QmpCommandFunc)(QDict *, QObject **, Error **);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 06/23] migration/hmp-cmds: Include 'block/block-global-state.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 05/23] qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 23:26   ` Dr. David Alan Gilbert
  2026-08-12 21:16 ` [PATCH v3 07/23] monitor: Include missing 'qemu/aio-wait.h' header Philippe Mathieu-Daudé
                   ` (16 subsequent siblings)
  22 siblings, 1 reply; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Peter Xu,
	Fabiano Rosas

migration-hmp-cmds.c uses types / methods declared in
"block/block-global-state.h".  Include the latter otherwise
we get when refactoring unrelated headers:

  ../migration/migration-hmp-cmds.c:911:5: error: use of undeclared identifier 'BdrvNextIterator'
    911 |     BdrvNextIterator it;
        |     ^
  ../migration/migration-hmp-cmds.c:918:15: error: call to undeclared function 'bdrv_first'
    918 |     for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
        |               ^

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 migration/migration-hmp-cmds.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c
index b04fc4489f4..351512942af 100644
--- a/migration/migration-hmp-cmds.c
+++ b/migration/migration-hmp-cmds.c
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "block/qapi.h"
+#include "block/block-global-state.h"
 #include "migration/snapshot.h"
 #include "monitor/hmp.h"
 #include "monitor/hmp-completion.h"
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 07/23] monitor: Include missing 'qemu/aio-wait.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 06/23] migration/hmp-cmds: Include 'block/block-global-state.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 08/23] monitor: Include missing 'qemu/lockable.h' header Philippe Mathieu-Daudé
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

Both monitor.c and qmp.c use types / methods declared in
"qemu/aio-wait.h". Include the latter to avoid the following
errors when refactoring unrelated headers:

  ../monitor/monitor.c:648:5: error: call to undeclared function 'AIO_WAIT_WHILE_UNLOCKED'
    648 |     AIO_WAIT_WHILE_UNLOCKED(NULL,
        |     ^
  ../monitor/qmp.c:792:9: error: call to undeclared function 'aio_wait_bh_oneshot'
    792 |         aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread),
        |         ^

Fixes: 9ce44e2ce26 ("qmp: Move dispatcher to a coroutine")
Fixes: a5df506e129 ("monitor: implement support for deleting QMP objects")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 monitor/monitor.c | 1 +
 monitor/qmp.c     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/monitor/monitor.c b/monitor/monitor.c
index ed195fd97bb..c75ae815343 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -30,6 +30,7 @@
 #include "qapi/qapi-visit-control.h"
 #include "qobject/qdict.h"
 #include "qom/object_interfaces.h"
+#include "qemu/aio-wait.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
 #include "system/qtest.h"
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 338d37cb7e5..6ae1098d39f 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-
+#include "qemu/aio-wait.h"
 #include "chardev/char-io.h"
 #include "monitor-internal.h"
 #include "qapi/error.h"
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 08/23] monitor: Include missing 'qemu/lockable.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 07/23] monitor: Include missing 'qemu/aio-wait.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 09/23] monitor: Include missing 'qemu/coroutine-core.h' header Philippe Mathieu-Daudé
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

Files in monitor/ use the QEMU_LOCK_GUARD() macros, which
are declared in "qemu/lockable.h". Include the latter to
avoid when refactoring unrelated headers:

  ../monitor/fds.c:146:5: error: call to undeclared function 'QEMU_LOCK_GUARD'
    146 |     QEMU_LOCK_GUARD(&mon->mon_lock);
        |     ^
  ../monitor/monitor.c:176:5: error: call to undeclared function 'QEMU_LOCK_GUARD'
    176 |     QEMU_LOCK_GUARD(&mon->mon_lock);
        |     ^
  ../monitor/qmp.c:164:5: error: call to undeclared function 'WITH_QEMU_LOCK_GUARD'
    164 |     WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
        |     ^

Fixes: 0210c3b39be ("monitor: Use LOCK_GUARD macros")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 monitor/fds.c     | 1 +
 monitor/monitor.c | 1 +
 monitor/qmp.c     | 1 +
 3 files changed, 3 insertions(+)

diff --git a/monitor/fds.c b/monitor/fds.c
index cc35d2ec334..abe5f13487d 100644
--- a/monitor/fds.c
+++ b/monitor/fds.c
@@ -29,6 +29,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
+#include "qemu/lockable.h"
 #include "system/runstate.h"
 
 /* file descriptors passed via SCM_RIGHTS */
diff --git a/monitor/monitor.c b/monitor/monitor.c
index c75ae815343..6af09f2f6ea 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -32,6 +32,7 @@
 #include "qom/object_interfaces.h"
 #include "qemu/aio-wait.h"
 #include "qemu/error-report.h"
+#include "qemu/lockable.h"
 #include "qemu/option.h"
 #include "system/qtest.h"
 #include "trace.h"
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 6ae1098d39f..aec03157750 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/aio-wait.h"
+#include "qemu/lockable.h"
 #include "chardev/char-io.h"
 #include "monitor-internal.h"
 #include "qapi/error.h"
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 09/23] monitor: Include missing 'qemu/coroutine-core.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 08/23] monitor: Include missing 'qemu/lockable.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 10/23] monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header Philippe Mathieu-Daudé
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

"monitor/monitor.h" declares monitor_set_cur() which use the
'Coroutine' type, itself declared in "qemu/coroutine-core.h".
Include the latter to avoid when refactoring unrelated headers:

  In file included from ../../target/sh4/monitor.c:26:
  qemu/include/monitor/monitor.h:32:26: error: unknown type name 'Coroutine'
     32 | Monitor *monitor_set_cur(Coroutine *co, Monitor *mon);
        |                          ^

Fixes: e69ee454b5f ("monitor: Make current monitor a per-coroutine property")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/monitor/monitor.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 890497b0d22..efdd2165aa9 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -4,6 +4,7 @@
 #include "block/block.h"
 #include "qapi/qapi-types-misc.h"
 #include "qapi/qapi-emit-events.h"
+#include "qemu/coroutine-core.h"
 #include "qemu/readline.h"
 #include "exec/hwaddr.h"
 #include "qom/object.h"
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 10/23] monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 09/23] monitor: Include missing 'qemu/coroutine-core.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 11/23] monitor: Remove unnecessary 'block/block.h' header Philippe Mathieu-Daudé
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

"monitor/monitor.h" don't use anything declared in the generated
"qapi/qapi-emit-events.h" header.
However the "monitor/monitor-internal.h" do:

  107 struct MonitorClass {
  ...
  116     /*
  117      * If non-NULL, the monitor is able to send event
  118      * notifications back to the client
  119      */
  120     void (*emit_event)(Monitor *mon, QAPIEvent event, QDict *qdict);
                                           ^^^^^^^^^

Move the header inclusion to "monitor/monitor-internal.h" to
avoid including / re-exposing unnecessary declarations in the
global "monitor/monitor.h" header.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/monitor/monitor.h  | 1 -
 monitor/monitor-internal.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index efdd2165aa9..fa9f4a8a75a 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -3,7 +3,6 @@
 
 #include "block/block.h"
 #include "qapi/qapi-types-misc.h"
-#include "qapi/qapi-emit-events.h"
 #include "qemu/coroutine-core.h"
 #include "qemu/readline.h"
 #include "exec/hwaddr.h"
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index 23829f32f9a..bc0932c425a 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -27,6 +27,7 @@
 
 #include "chardev/char-fe.h"
 #include "monitor/monitor.h"
+#include "qapi/qapi-emit-events.h"
 #include "qapi/qapi-types-control.h"
 #include "qapi/qapi-types-qom.h"
 #include "qapi/qmp-registry.h"
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 11/23] monitor: Remove unnecessary 'block/block.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 10/23] monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 12/23] system: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

Nothing here requires declarations from "block/block.h" anymore.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 include/monitor/monitor.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index fa9f4a8a75a..fd98ee2c71d 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -1,7 +1,6 @@
 #ifndef MONITOR_H
 #define MONITOR_H
 
-#include "block/block.h"
 #include "qapi/qapi-types-misc.h"
 #include "qemu/coroutine-core.h"
 #include "qemu/readline.h"
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 12/23] system: Remove unnecessary 'monitor/monitor.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (10 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 11/23] monitor: Remove unnecessary 'block/block.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 13/23] system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c Philippe Mathieu-Daudé
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Alistair Francis,
	David Gibson, Paolo Bonzini, Peter Xu,
	Philippe Mathieu-Daudé

No code in device_tree.c or physmem.c require declarations
from "monitor/monitor.h".

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 system/device_tree.c | 1 -
 system/physmem.c     | 2 --
 2 files changed, 3 deletions(-)

diff --git a/system/device_tree.c b/system/device_tree.c
index 1ea19629841..48365435ea0 100644
--- a/system/device_tree.c
+++ b/system/device_tree.c
@@ -29,7 +29,6 @@
 #include "qemu/config-file.h"
 #include "qapi/qapi-commands-machine.h"
 #include "qobject/qdict.h"
-#include "monitor/hmp.h"
 
 #include <libfdt.h>
 
diff --git a/system/physmem.c b/system/physmem.c
index c21ea929153..21614e1c4d0 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -84,8 +84,6 @@
 #include "qemu/mmap-alloc.h"
 #endif
 
-#include "monitor/monitor.h"
-
 #ifdef CONFIG_LIBDAXCTL
 #include <daxctl/libdaxctl.h>
 #endif
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 13/23] system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (11 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 12/23] system: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 14/23] system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Hyman Huang

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 MAINTAINERS                  |  1 +
 system/dirtylimit-hmp-cmds.c | 74 ++++++++++++++++++++++++++++++++++++
 system/dirtylimit.c          | 60 -----------------------------
 system/meson.build           |  1 +
 4 files changed, 76 insertions(+), 60 deletions(-)
 create mode 100644 system/dirtylimit-hmp-cmds.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 4628793dde6..a33fbeebf61 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3858,6 +3858,7 @@ Migration dirty limit and dirty page rate
 M: Hyman Huang <infra.ai.cloud@bitdeer.com>
 S: Maintained
 F: system/dirtylimit.c
+F: system/dirtylimit-hmp-cmds.c
 F: include/system/dirtylimit.h
 F: migration/dirtyrate.c
 F: migration/dirtyrate.h
diff --git a/system/dirtylimit-hmp-cmds.c b/system/dirtylimit-hmp-cmds.c
new file mode 100644
index 00000000000..4928d57cc8e
--- /dev/null
+++ b/system/dirtylimit-hmp-cmds.c
@@ -0,0 +1,74 @@
+/*
+ * HMP commands related to migration dirty page rate limit
+ *
+ * Copyright (c) 2022 CHINA TELECOM CO.,LTD.
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-migration.h"
+#include "qobject/qdict.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
+#include "system/dirtylimit.h"
+
+void hmp_cancel_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
+{
+    int64_t cpu_index = qdict_get_try_int(qdict, "cpu_index", -1);
+    Error *err = NULL;
+
+    qmp_cancel_vcpu_dirty_limit(!!(cpu_index != -1), cpu_index, &err);
+    if (err) {
+        hmp_handle_error(mon, err);
+        return;
+    }
+
+    monitor_printf(mon, "[Please use 'info vcpu_dirty_limit' to query "
+                   "dirty limit for virtual CPU]\n");
+}
+
+void hmp_set_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
+{
+    int64_t dirty_rate = qdict_get_int(qdict, "dirty_rate");
+    int64_t cpu_index = qdict_get_try_int(qdict, "cpu_index", -1);
+    Error *err = NULL;
+
+    if (dirty_rate < 0) {
+        error_setg(&err, "invalid dirty page limit %" PRId64, dirty_rate);
+        goto out;
+    }
+
+    qmp_set_vcpu_dirty_limit(!!(cpu_index != -1), cpu_index, dirty_rate, &err);
+
+out:
+    hmp_handle_error(mon, err);
+}
+
+void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
+{
+    DirtyLimitInfoList *info;
+    g_autoptr(DirtyLimitInfoList) head = NULL;
+    Error *err = NULL;
+
+    if (!dirtylimit_in_service()) {
+        monitor_printf(mon, "Dirty page limit not enabled!\n");
+        return;
+    }
+
+    head = qmp_query_vcpu_dirty_limit(&err);
+    if (err) {
+        hmp_handle_error(mon, err);
+        return;
+    }
+
+    for (info = head; info != NULL; info = info->next) {
+        monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s),"
+                            " current rate %"PRIi64 " (MB/s)\n",
+                            info->value->cpu_index,
+                            info->value->limit_rate,
+                            info->value->current_rate);
+    }
+}
diff --git a/system/dirtylimit.c b/system/dirtylimit.c
index 50fa67f3d6a..70bb7bac2d0 100644
--- a/system/dirtylimit.c
+++ b/system/dirtylimit.c
@@ -17,8 +17,6 @@
 #include "qapi/error.h"
 #include "system/dirtyrate.h"
 #include "system/dirtylimit.h"
-#include "monitor/hmp.h"
-#include "monitor/monitor.h"
 #include "system/memory.h"
 #include "exec/target_page.h"
 #include "hw/core/boards.h"
@@ -491,21 +489,6 @@ void qmp_cancel_vcpu_dirty_limit(bool has_cpu_index,
     dirtylimit_state_unlock();
 }
 
-void hmp_cancel_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
-{
-    int64_t cpu_index = qdict_get_try_int(qdict, "cpu_index", -1);
-    Error *err = NULL;
-
-    qmp_cancel_vcpu_dirty_limit(!!(cpu_index != -1), cpu_index, &err);
-    if (err) {
-        hmp_handle_error(mon, err);
-        return;
-    }
-
-    monitor_printf(mon, "[Please use 'info vcpu_dirty_limit' to query "
-                   "dirty limit for virtual CPU]\n");
-}
-
 void qmp_set_vcpu_dirty_limit(bool has_cpu_index,
                               int64_t cpu_index,
                               uint64_t dirty_rate,
@@ -548,23 +531,6 @@ void qmp_set_vcpu_dirty_limit(bool has_cpu_index,
     dirtylimit_state_unlock();
 }
 
-void hmp_set_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
-{
-    int64_t dirty_rate = qdict_get_int(qdict, "dirty_rate");
-    int64_t cpu_index = qdict_get_try_int(qdict, "cpu_index", -1);
-    Error *err = NULL;
-
-    if (dirty_rate < 0) {
-        error_setg(&err, "invalid dirty page limit %" PRId64, dirty_rate);
-        goto out;
-    }
-
-    qmp_set_vcpu_dirty_limit(!!(cpu_index != -1), cpu_index, dirty_rate, &err);
-
-out:
-    hmp_handle_error(mon, err);
-}
-
 /* Return the max throttle time of each virtual CPU */
 uint64_t dirtylimit_throttle_time_per_round(void)
 {
@@ -646,29 +612,3 @@ struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(Error **errp)
 {
     return dirtylimit_query_all();
 }
-
-void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
-{
-    DirtyLimitInfoList *info;
-    g_autoptr(DirtyLimitInfoList) head = NULL;
-    Error *err = NULL;
-
-    if (!dirtylimit_in_service()) {
-        monitor_printf(mon, "Dirty page limit not enabled!\n");
-        return;
-    }
-
-    head = qmp_query_vcpu_dirty_limit(&err);
-    if (err) {
-        hmp_handle_error(mon, err);
-        return;
-    }
-
-    for (info = head; info != NULL; info = info->next) {
-        monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s),"
-                            " current rate %"PRIi64 " (MB/s)\n",
-                            info->value->cpu_index,
-                            info->value->limit_rate,
-                            info->value->current_rate);
-    }
-}
diff --git a/system/meson.build b/system/meson.build
index cd3193d170b..377adce8035 100644
--- a/system/meson.build
+++ b/system/meson.build
@@ -9,6 +9,7 @@ system_ss.add(files(
   'cpus.c',
   'cpu-timers.c',
   'dirtylimit.c',
+  'dirtylimit-hmp-cmds.c',
   'dma-helpers.c',
   'exit-with-parent.c',
   'globals.c',
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 14/23] system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (12 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 13/23] system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:16 ` [PATCH v3 15/23] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé,
	Philippe Mathieu-Daudé, Zhao Liu, Paolo Bonzini

We figured NMI relates to machines (for their machine-specific
handling), so move the 'inject-nmi' QMP handler with the rest
of machine ones, in hw/core/machine-qmp-cmds.c.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/core/machine-qmp-cmds.c | 6 ++++++
 system/cpus.c              | 8 --------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index e62cb4ec888..1aa5f262298 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -10,6 +10,7 @@
 #include "qemu/osdep.h"
 #include "hw/acpi/vmgenid.h"
 #include "hw/core/boards.h"
+#include "hw/core/nmi.h"
 #include "hw/intc/intc.h"
 #include "hw/mem/memory-device.h"
 #include "qapi/error.h"
@@ -448,3 +449,8 @@ void qmp_dump_skeys(const char *filename, Error **errp)
     }
     DUMP_SKEYS_INTERFACE_CLASS(oc)->qmp_dump_skeys(filename, errp);
 }
+
+void qmp_inject_nmi(Error **errp)
+{
+    nmi_inject(errp);
+}
diff --git a/system/cpus.c b/system/cpus.c
index 9758cda4636..aa2510bf8fc 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -26,7 +26,6 @@
 #include "qemu/coroutine-tls.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-machine.h"
-#include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-events-run-state.h"
 #include "qapi/qmp/qerror.h"
 #include "exec/gdbstub.h"
@@ -38,7 +37,6 @@
 #include "qemu/plugin.h"
 #include "system/cpus.h"
 #include "qemu/guest-random.h"
-#include "hw/core/nmi.h"
 #include "system/physmem.h"
 #include "system/replay.h"
 #include "system/runstate.h"
@@ -922,9 +920,3 @@ void qmp_pmemsave(uint64_t addr, uint64_t size, const char *filename,
 exit:
     fclose(f);
 }
-
-void qmp_inject_nmi(Error **errp)
-{
-    nmi_inject(errp);
-}
-
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 15/23] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (13 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 14/23] system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c Philippe Mathieu-Daudé
@ 2026-08-12 21:16 ` Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 16/23] system: Move runstate-related code from cpus.c to runstate.c Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Paolo Bonzini,
	Philippe Mathieu-Daudé, Peter Xu

Keep cpus.c related to vCPU scheduling, move the QMP handlers
related to dumping physical memory to file to their own unit.
Fix a pair of checkpatch.pl errors doing so:

  ERROR: braces {} are necessary for all arms of this statement
  #185: FILE: system/physmem-qmp-cmds.c:51:
  +        if (l > size)
  [...]

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 MAINTAINERS               |   1 +
 system/cpus.c             |  92 --------------------------------
 system/physmem-qmp-cmds.c | 107 ++++++++++++++++++++++++++++++++++++++
 system/meson.build        |   1 +
 4 files changed, 109 insertions(+), 92 deletions(-)
 create mode 100644 system/physmem-qmp-cmds.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a33fbeebf61..f4689530b5e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3419,6 +3419,7 @@ F: system/ioport.c
 F: system/memory.c
 F: system/memory_mapping.c
 F: system/physmem.c
+F: system/physmem-qmp-cmds.c
 F: system/memory_ldst*
 F: system/memory-internal.h
 F: system/ram-block-attributes.c
diff --git a/system/cpus.c b/system/cpus.c
index aa2510bf8fc..43ff10cf008 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -25,9 +25,7 @@
 #include "qemu/osdep.h"
 #include "qemu/coroutine-tls.h"
 #include "qapi/error.h"
-#include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-events-run-state.h"
-#include "qapi/qmp/qerror.h"
 #include "exec/gdbstub.h"
 #include "accel/accel-cpu-ops.h"
 #include "system/hw_accel.h"
@@ -40,7 +38,6 @@
 #include "system/physmem.h"
 #include "system/replay.h"
 #include "system/runstate.h"
-#include "migration/misc.h"
 #include "system/cpu-timers.h"
 #include "system/whpx.h"
 #include "hw/core/boards.h"
@@ -831,92 +828,3 @@ int vm_stop_force_state(RunState state)
         return ret;
     }
 }
-
-void qmp_memsave(uint64_t addr, uint64_t size, const char *filename,
-                 bool has_cpu, int64_t cpu_index, Error **errp)
-{
-    FILE *f;
-    uint64_t l;
-    CPUState *cpu;
-    uint8_t buf[1024];
-    uint64_t orig_addr = addr, orig_size = size;
-
-    if (migration_guest_ram_loading()) {
-        error_setg(errp, "Guest memory access not allowed during migration");
-        return;
-    }
-
-    if (!has_cpu) {
-        cpu_index = 0;
-    }
-
-    cpu = qemu_get_cpu(cpu_index);
-    if (cpu == NULL) {
-        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
-                   "a CPU number");
-        return;
-    }
-
-    f = fopen(filename, "wb");
-    if (!f) {
-        error_setg_file_open(errp, errno, filename);
-        return;
-    }
-
-    while (size != 0) {
-        l = sizeof(buf);
-        if (l > size)
-            l = size;
-        if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) != 0) {
-            error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRIu64
-                             " specified", orig_addr, orig_size);
-            goto exit;
-        }
-        if (fwrite(buf, 1, l, f) != l) {
-            error_setg(errp, "writing memory to '%s' failed",
-                       filename);
-            goto exit;
-        }
-        addr += l;
-        size -= l;
-    }
-
-exit:
-    fclose(f);
-}
-
-void qmp_pmemsave(uint64_t addr, uint64_t size, const char *filename,
-                  Error **errp)
-{
-    FILE *f;
-    uint64_t l;
-    uint8_t buf[1024];
-
-    if (migration_guest_ram_loading()) {
-        error_setg(errp, "Guest memory access not allowed during migration");
-        return;
-    }
-
-    f = fopen(filename, "wb");
-    if (!f) {
-        error_setg_file_open(errp, errno, filename);
-        return;
-    }
-
-    while (size != 0) {
-        l = sizeof(buf);
-        if (l > size)
-            l = size;
-        physical_memory_read(addr, buf, l);
-        if (fwrite(buf, 1, l, f) != l) {
-            error_setg(errp, "writing memory to '%s' failed",
-                       filename);
-            goto exit;
-        }
-        addr += l;
-        size -= l;
-    }
-
-exit:
-    fclose(f);
-}
diff --git a/system/physmem-qmp-cmds.c b/system/physmem-qmp-cmds.c
new file mode 100644
index 00000000000..d85430357d5
--- /dev/null
+++ b/system/physmem-qmp-cmds.c
@@ -0,0 +1,107 @@
+/*
+ * QMP commands to dump physical memory
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-machine.h"
+#include "qapi/qmp/qerror.h"
+#include "hw/core/cpu.h"
+#include "system/physmem.h"
+#include "migration/misc.h"
+
+void qmp_memsave(uint64_t addr, uint64_t size, const char *filename,
+                 bool has_cpu, int64_t cpu_index, Error **errp)
+{
+    FILE *f;
+    uint64_t l;
+    CPUState *cpu;
+    uint8_t buf[1024];
+    uint64_t orig_addr = addr, orig_size = size;
+
+    if (migration_guest_ram_loading()) {
+        error_setg(errp, "Guest memory access not allowed during migration");
+        return;
+    }
+
+    if (!has_cpu) {
+        cpu_index = 0;
+    }
+
+    cpu = qemu_get_cpu(cpu_index);
+    if (cpu == NULL) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
+                   "a CPU number");
+        return;
+    }
+
+    f = fopen(filename, "wb");
+    if (!f) {
+        error_setg_file_open(errp, errno, filename);
+        return;
+    }
+
+    while (size != 0) {
+        l = sizeof(buf);
+        if (l > size) {
+            l = size;
+        }
+        if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) != 0) {
+            error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRIu64
+                             " specified", orig_addr, orig_size);
+            goto exit;
+        }
+        if (fwrite(buf, 1, l, f) != l) {
+            error_setg(errp, "writing memory to '%s' failed",
+                       filename);
+            goto exit;
+        }
+        addr += l;
+        size -= l;
+    }
+
+exit:
+    fclose(f);
+}
+
+void qmp_pmemsave(uint64_t addr, uint64_t size, const char *filename,
+                  Error **errp)
+{
+    FILE *f;
+    uint64_t l;
+    uint8_t buf[1024];
+
+    if (migration_guest_ram_loading()) {
+        error_setg(errp, "Guest memory access not allowed during migration");
+        return;
+    }
+
+    f = fopen(filename, "wb");
+    if (!f) {
+        error_setg_file_open(errp, errno, filename);
+        return;
+    }
+
+    while (size != 0) {
+        l = sizeof(buf);
+        if (l > size) {
+            l = size;
+        }
+        physical_memory_read(addr, buf, l);
+        if (fwrite(buf, 1, l, f) != l) {
+            error_setg(errp, "writing memory to '%s' failed",
+                       filename);
+            goto exit;
+        }
+        addr += l;
+        size -= l;
+    }
+
+exit:
+    fclose(f);
+}
diff --git a/system/meson.build b/system/meson.build
index 377adce8035..64e06e7abcc 100644
--- a/system/meson.build
+++ b/system/meson.build
@@ -19,6 +19,7 @@ system_ss.add(files(
   'memory_mapping.c',
   'memory.c',
   'physmem.c',
+  'physmem-qmp-cmds.c',
   'qdev-monitor.c',
   'qtest.c',
   'rtc.c',
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 16/23] system: Move runstate-related code from cpus.c to runstate.c
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (14 preceding siblings ...)
  2026-08-12 21:16 ` [PATCH v3 15/23] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c Philippe Mathieu-Daudé
@ 2026-08-12 21:17 ` Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 17/23] monitor: Rename MonitorQMP @mon -> @qmon Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Paolo Bonzini,
	Philippe Mathieu-Daudé

Keep cpus.c focused on vCPUs handling, move code related to
VM state to runstate.c where similar code lives.

Fix few checkpatch.pl warnings:

  WARNING: Block comments use a leading /* on a separate line
  WARNING: Block comments use * on subsequent lines
  #327: FILE: system/runstate.c:541:
  +/* does a state transition even if the VM is already stopped,
  +   current state is forgotten forever */

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 system/cpus.c     | 147 -------------------------------------------
 system/runstate.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+), 147 deletions(-)

diff --git a/system/cpus.c b/system/cpus.c
index 43ff10cf008..f37e215c586 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -25,7 +25,6 @@
 #include "qemu/osdep.h"
 #include "qemu/coroutine-tls.h"
 #include "qapi/error.h"
-#include "qapi/qapi-events-run-state.h"
 #include "exec/gdbstub.h"
 #include "accel/accel-cpu-ops.h"
 #include "system/hw_accel.h"
@@ -272,58 +271,6 @@ void cpu_interrupt(CPUState *cpu, int mask)
     cpus_accel->handle_interrupt(cpu, mask);
 }
 
-/*
- * True if the vm was previously suspended, and has not been woken or reset.
- */
-static int vm_was_suspended;
-
-void vm_set_suspended(bool suspended)
-{
-    vm_was_suspended = suspended;
-}
-
-bool vm_get_suspended(void)
-{
-    return vm_was_suspended;
-}
-
-static int do_vm_stop(RunState state, bool send_stop)
-{
-    int ret = 0;
-    RunState oldstate = runstate_get();
-
-    if (runstate_is_live(oldstate)) {
-        vm_was_suspended = (oldstate == RUN_STATE_SUSPENDED);
-        runstate_set(state);
-        cpu_disable_ticks();
-        if (oldstate == RUN_STATE_RUNNING) {
-            pause_all_vcpus();
-        }
-        ret = vm_state_notify(0, state);
-        if (send_stop) {
-            qapi_event_send_stop();
-        }
-    }
-
-    bdrv_drain_all();
-    /*
-     * Even if vm_state_notify() return failure,
-     * it would be better to flush as before.
-     */
-    ret |= bdrv_flush_all();
-    trace_vm_stop_flush_all(ret);
-
-    return ret;
-}
-
-/* Special vm_stop() variant for terminating the process.  Historically clients
- * did not expect a QMP STOP event and so we need to retain compatibility.
- */
-int vm_shutdown(void)
-{
-    return do_vm_stop(RUN_STATE_SHUTDOWN, false);
-}
-
 bool cpu_can_run(CPUState *cpu)
 {
     if (cpu->stop) {
@@ -734,97 +681,3 @@ void cpu_stop_current(void)
         cpu_exit(current_cpu);
     }
 }
-
-int vm_stop(RunState state)
-{
-    if (qemu_in_vcpu_thread()) {
-        qemu_system_vmstop_request_prepare();
-        qemu_system_vmstop_request(state);
-        /*
-         * FIXME: should not return to device code in case
-         * vm_stop() has been requested.
-         */
-        cpu_stop_current();
-        return 0;
-    }
-
-    return do_vm_stop(state, true);
-}
-
-/**
- * Prepare for (re)starting the VM.
- * Returns 0 if the vCPUs should be restarted, -1 on an error condition,
- * and 1 otherwise.
- */
-int vm_prepare_start(bool step_pending)
-{
-    int ret = vm_was_suspended ? 1 : 0;
-    RunState state = vm_was_suspended ? RUN_STATE_SUSPENDED : RUN_STATE_RUNNING;
-    RunState requested;
-
-    qemu_vmstop_requested(&requested);
-    if (runstate_is_running() && requested == RUN_STATE__MAX) {
-        return -1;
-    }
-
-    /* Ensure that a STOP/RESUME pair of events is emitted if a
-     * vmstop request was pending.  The BLOCK_IO_ERROR event, for
-     * example, according to documentation is always followed by
-     * the STOP event.
-     */
-    if (runstate_is_running()) {
-        qapi_event_send_stop();
-        qapi_event_send_resume();
-        return -1;
-    }
-
-    /*
-     * WHPX accelerator needs to know whether we are going to step
-     * any CPUs, before starting the first one.
-     */
-    accel_pre_resume(MACHINE(qdev_get_machine()), step_pending);
-
-    /* We are sending this now, but the CPUs will be resumed shortly later */
-    qapi_event_send_resume();
-
-    cpu_enable_ticks();
-    runstate_set(state);
-    vm_state_notify(1, state);
-    vm_was_suspended = false;
-    return ret;
-}
-
-void vm_start(void)
-{
-    if (!vm_prepare_start(false)) {
-        resume_all_vcpus();
-    }
-}
-
-void vm_resume(RunState state)
-{
-    if (runstate_is_live(state)) {
-        vm_start();
-    } else {
-        runstate_set(state);
-    }
-}
-
-/* does a state transition even if the VM is already stopped,
-   current state is forgotten forever */
-int vm_stop_force_state(RunState state)
-{
-    if (runstate_is_live(runstate_get())) {
-        return vm_stop(state);
-    } else {
-        int ret;
-        runstate_set(state);
-
-        bdrv_drain_all();
-        /* Make sure to return an error if the flush in a previous vm_stop()
-         * failed. */
-        ret = bdrv_flush_all();
-        trace_vm_stop_flush_all(ret);
-        return ret;
-    }
-}
diff --git a/system/runstate.c b/system/runstate.c
index 08acf801b0e..d3e64d2b625 100644
--- a/system/runstate.c
+++ b/system/runstate.c
@@ -52,6 +52,7 @@
 #include "qemu/thread.h"
 #include "qom/object.h"
 #include "qom/object_interfaces.h"
+#include "system/cpu-timers.h"
 #include "system/cpus.h"
 #include "system/qtest.h"
 #include "system/replay.h"
@@ -408,6 +409,159 @@ int vm_state_notify(bool running, RunState state)
     return ret;
 }
 
+/*
+ * True if the vm was previously suspended, and has not been woken or reset.
+ */
+static int vm_was_suspended;
+
+void vm_set_suspended(bool suspended)
+{
+    vm_was_suspended = suspended;
+}
+
+bool vm_get_suspended(void)
+{
+    return vm_was_suspended;
+}
+
+static int do_vm_stop(RunState state, bool send_stop)
+{
+    int ret = 0;
+    RunState oldstate = runstate_get();
+
+    if (runstate_is_live(oldstate)) {
+        vm_was_suspended = (oldstate == RUN_STATE_SUSPENDED);
+        runstate_set(state);
+        cpu_disable_ticks();
+        if (oldstate == RUN_STATE_RUNNING) {
+            pause_all_vcpus();
+        }
+        ret = vm_state_notify(0, state);
+        if (send_stop) {
+            qapi_event_send_stop();
+        }
+    }
+
+    bdrv_drain_all();
+    /*
+     * Even if vm_state_notify() return failure,
+     * it would be better to flush as before.
+     */
+    ret |= bdrv_flush_all();
+    trace_vm_stop_flush_all(ret);
+
+    return ret;
+}
+
+/*
+ * Special vm_stop() variant for terminating the process.  Historically clients
+ * did not expect a QMP STOP event and so we need to retain compatibility.
+ */
+int vm_shutdown(void)
+{
+    return do_vm_stop(RUN_STATE_SHUTDOWN, false);
+}
+
+
+int vm_stop(RunState state)
+{
+    if (qemu_in_vcpu_thread()) {
+        qemu_system_vmstop_request_prepare();
+        qemu_system_vmstop_request(state);
+        /*
+         * FIXME: should not return to device code in case
+         * vm_stop() has been requested.
+         */
+        cpu_stop_current();
+        return 0;
+    }
+
+    return do_vm_stop(state, true);
+}
+
+/**
+ * Prepare for (re)starting the VM.
+ * Returns 0 if the vCPUs should be restarted, -1 on an error condition,
+ * and 1 otherwise.
+ */
+int vm_prepare_start(bool step_pending)
+{
+    int ret = vm_was_suspended ? 1 : 0;
+    RunState state = vm_was_suspended ? RUN_STATE_SUSPENDED : RUN_STATE_RUNNING;
+    RunState requested;
+
+    qemu_vmstop_requested(&requested);
+    if (runstate_is_running() && requested == RUN_STATE__MAX) {
+        return -1;
+    }
+
+    /*
+     * Ensure that a STOP/RESUME pair of events is emitted if a
+     * vmstop request was pending.  The BLOCK_IO_ERROR event, for
+     * example, according to documentation is always followed by
+     * the STOP event.
+     */
+    if (runstate_is_running()) {
+        qapi_event_send_stop();
+        qapi_event_send_resume();
+        return -1;
+    }
+
+    /*
+     * WHPX accelerator needs to know whether we are going to step
+     * any CPUs, before starting the first one.
+     */
+    accel_pre_resume(MACHINE(qdev_get_machine()), step_pending);
+
+    /* We are sending this now, but the CPUs will be resumed shortly later */
+    qapi_event_send_resume();
+
+    cpu_enable_ticks();
+    runstate_set(state);
+    vm_state_notify(1, state);
+    vm_was_suspended = false;
+    return ret;
+}
+
+void vm_start(void)
+{
+    if (!vm_prepare_start(false)) {
+        resume_all_vcpus();
+    }
+}
+
+void vm_resume(RunState state)
+{
+    if (runstate_is_live(state)) {
+        vm_start();
+    } else {
+        runstate_set(state);
+    }
+}
+
+/*
+ * does a state transition even if the VM is already stopped,
+ * current state is forgotten forever
+ */
+int vm_stop_force_state(RunState state)
+{
+    if (runstate_is_live(runstate_get())) {
+        return vm_stop(state);
+    } else {
+        int ret;
+        runstate_set(state);
+
+        bdrv_drain_all();
+        /*
+         * Make sure to return an error if the flush in a previous vm_stop()
+         * failed.
+         */
+        ret = bdrv_flush_all();
+        trace_vm_stop_flush_all(ret);
+        return ret;
+    }
+}
+
 static ShutdownCause reset_requested;
 static ShutdownCause shutdown_requested;
 static int shutdown_exit_code = EXIT_SUCCESS;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 17/23] monitor: Rename MonitorQMP @mon -> @qmon
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (15 preceding siblings ...)
  2026-08-12 21:17 ` [PATCH v3 16/23] system: Move runstate-related code from cpus.c to runstate.c Philippe Mathieu-Daudé
@ 2026-08-12 21:17 ` Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 18/23] monitor: Rename MonitorHMP @mon -> @hmon Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

Mechanical change to sanitize using the following patterns:

  MonitorQMP *qmon  (this patch)
  MonitorHMP *hmon  (following one)
  Monitor *mon

Rename @mon (and @qmp_mon) as @qmon when the type is MonitorQMP.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 monitor/monitor-internal.h |   4 +-
 monitor/qmp-cmds-control.c |  18 +--
 monitor/qmp.c              | 256 ++++++++++++++++++-------------------
 3 files changed, 139 insertions(+), 139 deletions(-)

diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index bc0932c425a..cfbb3e5ecea 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -216,8 +216,8 @@ void monitor_list_append(Monitor *mon);
 void monitor_fdsets_cleanup(void);
 int monitor_set_cpu(Monitor *mon, int cpu_index);
 
-void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
-void monitor_data_destroy_qmp(MonitorQMP *mon);
+void qmp_send_response(MonitorQMP *qmon, const QDict *rsp);
+void monitor_data_destroy_qmp(MonitorQMP *qmon);
 void coroutine_fn monitor_qmp_dispatcher_co(void *data);
 void qmp_dispatcher_co_wake(void);
 
diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c
index 8fe0876a3da..45f4fe4f6fb 100644
--- a/monitor/qmp-cmds-control.c
+++ b/monitor/qmp-cmds-control.c
@@ -39,7 +39,7 @@
  * On success, set mon->qmp.capab[], and return true.
  * On error, set @errp, and return false.
  */
-static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list,
+static bool qmp_caps_accept(MonitorQMP *qmon, QMPCapabilityList *list,
                             Error **errp)
 {
     GString *unavailable = NULL;
@@ -48,7 +48,7 @@ static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list,
     memset(capab, 0, sizeof(capab));
 
     for (; list; list = list->next) {
-        if (!mon->capab_offered[list->value]) {
+        if (!qmon->capab_offered[list->value]) {
             if (!unavailable) {
                 unavailable = g_string_new(QMPCapability_str(list->value));
             } else {
@@ -65,27 +65,27 @@ static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list,
         return false;
     }
 
-    memcpy(mon->capab, capab, sizeof(capab));
+    memcpy(qmon->capab, capab, sizeof(capab));
     return true;
 }
 
 void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable,
                           Error **errp)
 {
-    MonitorQMP *mon = MONITOR_QMP(monitor_cur());
+    MonitorQMP *qmon = MONITOR_QMP(monitor_cur());
 
-    if (mon->commands == &qmp_commands) {
+    if (qmon->commands == &qmp_commands) {
         error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
                   "Capabilities negotiation is already complete, command "
                   "ignored");
         return;
     }
 
-    if (!qmp_caps_accept(mon, enable, errp)) {
+    if (!qmp_caps_accept(qmon, enable, errp)) {
         return;
     }
 
-    mon->commands = &qmp_commands;
+    qmon->commands = &qmp_commands;
 }
 
 VersionInfo *qmp_query_version(Error **errp)
@@ -118,9 +118,9 @@ static void query_commands_cb(const QmpCommand *cmd, void *opaque)
 CommandInfoList *qmp_query_commands(Error **errp)
 {
     CommandInfoList *list = NULL;
-    MonitorQMP *mon = MONITOR_QMP(monitor_cur());
+    MonitorQMP *qmon = MONITOR_QMP(monitor_cur());
 
-    qmp_for_each_command(mon->commands, query_commands_cb, &list);
+    qmp_for_each_command(qmon->commands, query_commands_cb, &list);
 
     return list;
 }
diff --git a/monitor/qmp.c b/monitor/qmp.c
index aec03157750..d6ce734916e 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -79,44 +79,44 @@ static MonitorQMP *qmp_dispatcher_current_mon;
 
 OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR);
 
-static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon);
+static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *qmon);
 
 static void monitor_qmp_finalize(Object *obj)
 {
-    MonitorQMP *mon = MONITOR_QMP(obj);
+    MonitorQMP *qmon = MONITOR_QMP(obj);
 
-    json_message_parser_destroy(&mon->parser);
-    qemu_mutex_destroy(&mon->qmp_queue_lock);
-    monitor_qmp_cleanup_req_queue_locked(mon);
-    g_queue_free(mon->qmp_requests);
+    json_message_parser_destroy(&qmon->parser);
+    qemu_mutex_destroy(&qmon->qmp_queue_lock);
+    monitor_qmp_cleanup_req_queue_locked(qmon);
+    g_queue_free(qmon->qmp_requests);
 }
 
 static bool monitor_qmp_get_pretty(Object *obj, Error **errp)
 {
-    MonitorQMP *mon = MONITOR_QMP(obj);
+    MonitorQMP *qmon = MONITOR_QMP(obj);
 
-    return mon->pretty;
+    return qmon->pretty;
 }
 
 static void monitor_qmp_set_pretty(Object *obj, bool val, Error **errp)
 {
-    MonitorQMP *mon = MONITOR_QMP(obj);
+    MonitorQMP *qmon = MONITOR_QMP(obj);
 
-    mon->pretty = val;
+    qmon->pretty = val;
 }
 
 static int monitor_qmp_get_close_action(Object *obj, Error **errp)
 {
-    MonitorQMP *mon = MONITOR_QMP(obj);
+    MonitorQMP *qmon = MONITOR_QMP(obj);
 
-    return mon->close_action;
+    return qmon->close_action;
 }
 
 static void monitor_qmp_set_close_action(Object *obj, int val, Error **errp)
 {
-    MonitorQMP *mon = MONITOR_QMP(obj);
+    MonitorQMP *qmon = MONITOR_QMP(obj);
 
-    mon->close_action = val;
+    qmon->close_action = val;
 }
 
 static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict);
@@ -150,25 +150,25 @@ static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
 static void handle_qmp_command(void *opaque, QObject *req, Error *err);
 static void monitor_qmp_init(Object *obj)
 {
-    MonitorQMP *mon = MONITOR_QMP(obj);
+    MonitorQMP *qmon = MONITOR_QMP(obj);
 
-    qemu_mutex_init(&mon->qmp_queue_lock);
-    mon->qmp_requests = g_queue_new();
+    qemu_mutex_init(&qmon->qmp_queue_lock);
+    qmon->qmp_requests = g_queue_new();
 
-    json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL);
+    json_message_parser_init(&qmon->parser, handle_qmp_command, qmon, NULL);
 }
 
 static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict)
 {
-    MonitorQMP *qmp = MONITOR_QMP(mon);
+    MonitorQMP *qmon = MONITOR_QMP(mon);
 
     WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
-        if (qmp->commands == &qmp_cap_negotiation_commands) {
+        if (qmon->commands == &qmp_cap_negotiation_commands) {
             return;
         }
     }
 
-    qmp_send_response(qmp, qdict);
+    qmp_send_response(qmon, qdict);
 }
 
 static bool monitor_qmp_requires_iothread(const Monitor *mon)
@@ -177,17 +177,17 @@ static bool monitor_qmp_requires_iothread(const Monitor *mon)
                                 QEMU_CHAR_FEATURE_GCONTEXT);
 }
 
-static bool qmp_oob_enabled(MonitorQMP *mon)
+static bool qmp_oob_enabled(MonitorQMP *qmon)
 {
-    return mon->capab[QMP_CAPABILITY_OOB];
+    return qmon->capab[QMP_CAPABILITY_OOB];
 }
 
-static void monitor_qmp_caps_reset(MonitorQMP *mon)
+static void monitor_qmp_caps_reset(MonitorQMP *qmon)
 {
-    memset(mon->capab_offered, 0, sizeof(mon->capab_offered));
-    memset(mon->capab, 0, sizeof(mon->capab));
-    mon->capab_offered[QMP_CAPABILITY_OOB] =
-        monitor_requires_iothread(MONITOR(mon));
+    memset(qmon->capab_offered, 0, sizeof(qmon->capab_offered));
+    memset(qmon->capab, 0, sizeof(qmon->capab));
+    qmon->capab_offered[QMP_CAPABILITY_OOB] =
+        monitor_requires_iothread(MONITOR(qmon));
 }
 
 static void qmp_request_free(QMPRequest *req)
@@ -198,22 +198,22 @@ static void qmp_request_free(QMPRequest *req)
 }
 
 /* Caller must hold mon->qmp.qmp_queue_lock */
-static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon)
+static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *qmon)
 {
-    while (!g_queue_is_empty(mon->qmp_requests)) {
-        qmp_request_free(g_queue_pop_head(mon->qmp_requests));
+    while (!g_queue_is_empty(qmon->qmp_requests)) {
+        qmp_request_free(g_queue_pop_head(qmon->qmp_requests));
     }
 }
 
-static void monitor_qmp_drain_queue(MonitorQMP *mon)
+static void monitor_qmp_drain_queue(MonitorQMP *qmon)
 {
-    QEMU_LOCK_GUARD(&mon->qmp_queue_lock);
-    monitor_qmp_cleanup_req_queue_locked(mon);
+    QEMU_LOCK_GUARD(&qmon->qmp_queue_lock);
+    monitor_qmp_cleanup_req_queue_locked(qmon);
 }
 
-static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon)
+static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *qmon)
 {
-    QEMU_LOCK_GUARD(&mon->qmp_queue_lock);
+    QEMU_LOCK_GUARD(&qmon->qmp_queue_lock);
 
     /*
      * Same condition as in monitor_qmp_dispatcher_co(), but before
@@ -221,11 +221,11 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon)
      * Also, the queue should not be empty either, otherwise the
      * monitor hasn't been suspended yet (or was already resumed).
      */
-    bool need_resume = (!qmp_oob_enabled(mon) ||
-        mon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX)
-        && !g_queue_is_empty(mon->qmp_requests);
+    bool need_resume = (!qmp_oob_enabled(qmon) ||
+        qmon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX)
+        && !g_queue_is_empty(qmon->qmp_requests);
 
-    monitor_qmp_cleanup_req_queue_locked(mon);
+    monitor_qmp_cleanup_req_queue_locked(qmon);
 
     if (need_resume) {
         /*
@@ -237,22 +237,22 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon)
          * when we get here while the monitor is suspended.  An
          * unfortunately timed CHR_EVENT_CLOSED can do the trick.
          */
-        monitor_resume(&mon->parent_obj);
+        monitor_resume(&qmon->parent_obj);
     }
 
 }
 
-void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
+void qmp_send_response(MonitorQMP *qmon, const QDict *rsp)
 {
     const QObject *data = QOBJECT(rsp);
     GString *json;
 
-    json = qobject_to_json_pretty(data, mon->pretty);
+    json = qobject_to_json_pretty(data, qmon->pretty);
     assert(json != NULL);
-    trace_monitor_qmp_respond(mon, json->str);
+    trace_monitor_qmp_respond(qmon, json->str);
 
     g_string_append_c(json, '\n');
-    monitor_puts(&mon->parent_obj, json->str);
+    monitor_puts(&qmon->parent_obj, json->str);
 
     g_string_free(json, true);
 }
@@ -262,10 +262,10 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
  * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP.
  * Nothing is emitted then.
  */
-static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
+static void monitor_qmp_respond(MonitorQMP *qmon, QDict *rsp)
 {
     if (rsp) {
-        qmp_send_response(mon, rsp);
+        qmp_send_response(qmon, rsp);
     }
 }
 
@@ -273,15 +273,15 @@ static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
  * Runs outside of coroutine context for OOB commands, but in
  * coroutine context for everything else.
  */
-static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
+static void monitor_qmp_dispatch(MonitorQMP *qmon, QObject *req)
 {
     QDict *rsp;
     QDict *error;
 
-    rsp = qmp_dispatch(mon->commands, req, qmp_oob_enabled(mon),
-                       &mon->parent_obj);
+    rsp = qmp_dispatch(qmon->commands, req, qmp_oob_enabled(qmon),
+                       &qmon->parent_obj);
 
-    if (mon->commands == &qmp_cap_negotiation_commands) {
+    if (qmon->commands == &qmp_cap_negotiation_commands) {
         error = qdict_get_qdict(rsp, "error");
         if (error
             && !g_strcmp0(qdict_get_try_str(error, "class"),
@@ -293,7 +293,7 @@ static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
         }
     }
 
-    monitor_qmp_respond(mon, rsp);
+    monitor_qmp_respond(qmon, rsp);
     qobject_unref(rsp);
 }
 
@@ -313,22 +313,22 @@ static QMPRequest *monitor_qmp_requests_pop_any_with_lock(void)
 {
     QMPRequest *req_obj = NULL;
     Monitor *mon;
-    MonitorQMP *qmp_mon;
+    MonitorQMP *qmon;
 
     QTAILQ_FOREACH(mon, &mon_list, entry) {
-        qmp_mon = MONITOR_QMP(
+        qmon = MONITOR_QMP(
             object_dynamic_cast(OBJECT(mon), TYPE_MONITOR_QMP));
-        if (!qmp_mon) {
+        if (!qmon) {
             continue;
         }
 
-        qemu_mutex_lock(&qmp_mon->qmp_queue_lock);
-        req_obj = g_queue_pop_head(qmp_mon->qmp_requests);
+        qemu_mutex_lock(&qmon->qmp_queue_lock);
+        req_obj = g_queue_pop_head(qmon->qmp_requests);
         if (req_obj) {
             /* With the lock of corresponding queue held */
             break;
         }
-        qemu_mutex_unlock(&qmp_mon->qmp_queue_lock);
+        qemu_mutex_unlock(&qmon->qmp_queue_lock);
     }
 
     if (req_obj) {
@@ -391,7 +391,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
     QMPRequest *req_obj;
     QDict *rsp;
     bool oob_enabled;
-    MonitorQMP *mon;
+    MonitorQMP *qmon;
 
     while ((req_obj = monitor_qmp_dispatcher_pop_any()) != NULL) {
         trace_monitor_qmp_in_band_dequeue(req_obj,
@@ -401,8 +401,8 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
          * @req_obj has a request, we hold req_obj->mon->qmp_queue_lock
          */
 
-        mon = req_obj->mon;
-        qmp_dispatcher_current_mon = mon;
+        qmon = req_obj->mon;
+        qmp_dispatcher_current_mon = qmon;
 
         /*
          * We need to resume the monitor if handle_qmp_command()
@@ -415,17 +415,17 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
          * We need to save qmp_oob_enabled() for later, because
          * qmp_qmp_capabilities() can change it.
          */
-        oob_enabled = qmp_oob_enabled(mon);
+        oob_enabled = qmp_oob_enabled(qmon);
         if (oob_enabled
-            && mon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1) {
-            monitor_resume(&mon->parent_obj);
+            && qmon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1) {
+            monitor_resume(&qmon->parent_obj);
         }
 
         /*
          * Drop the queue mutex now, before yielding, otherwise we might
          * deadlock if the main thread tries to lock it.
          */
-        qemu_mutex_unlock(&mon->qmp_queue_lock);
+        qemu_mutex_unlock(&qmon->qmp_queue_lock);
 
         if (qatomic_xchg(&qmp_dispatcher_co_busy, true) == true) {
             /*
@@ -448,18 +448,18 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
                 trace_monitor_qmp_cmd_in_band(id_json->str);
                 g_string_free(id_json, true);
             }
-            monitor_qmp_dispatch(mon, req_obj->req);
+            monitor_qmp_dispatch(qmon, req_obj->req);
         } else {
             assert(req_obj->err);
             trace_monitor_qmp_err_in_band(error_get_pretty(req_obj->err));
             rsp = qmp_error_response(req_obj->err);
             req_obj->err = NULL;
-            monitor_qmp_respond(mon, rsp);
+            monitor_qmp_respond(qmon, rsp);
             qobject_unref(rsp);
         }
 
         if (!oob_enabled) {
-            monitor_resume(&mon->parent_obj);
+            monitor_resume(&qmon->parent_obj);
         }
 
         qmp_request_free(req_obj);
@@ -481,7 +481,7 @@ void qmp_dispatcher_co_wake(void)
 
 static void handle_qmp_command(void *opaque, QObject *req, Error *err)
 {
-    MonitorQMP *mon = opaque;
+    MonitorQMP *qmon = opaque;
     QDict *qdict = qobject_to(QDict, req);
     QMPRequest *req_obj;
 
@@ -489,7 +489,7 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
 
     if (req && trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) {
         GString *req_json = qobject_to_json(req);
-        trace_handle_qmp_command(mon, req_json->str);
+        trace_handle_qmp_command(qmon, req_json->str);
         g_string_free(req_json, true);
     }
 
@@ -503,18 +503,18 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
             trace_monitor_qmp_cmd_out_of_band(id_json->str);
             g_string_free(id_json, true);
         }
-        monitor_qmp_dispatch(mon, req);
+        monitor_qmp_dispatch(qmon, req);
         qobject_unref(req);
         return;
     }
 
     req_obj = g_new0(QMPRequest, 1);
-    req_obj->mon = mon;
+    req_obj->mon = qmon;
     req_obj->req = req;
     req_obj->err = err;
 
     /* Protect qmp_requests and fetching its length. */
-    WITH_QEMU_LOCK_GUARD(&mon->qmp_queue_lock) {
+    WITH_QEMU_LOCK_GUARD(&qmon->qmp_queue_lock) {
 
         /*
          * Suspend the monitor when we can't queue more requests after
@@ -523,9 +523,9 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
          * Note that when OOB is disabled, we queue at most one command,
          * for backward compatibility.
          */
-        if (!qmp_oob_enabled(mon) ||
-            mon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1) {
-            monitor_suspend(&mon->parent_obj);
+        if (!qmp_oob_enabled(qmon) ||
+            qmon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1) {
+            monitor_suspend(&qmon->parent_obj);
         }
 
         /*
@@ -533,10 +533,10 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
          * handled in time order.  Ownership for req_obj, req,
          * etc. will be delivered to the handler side.
          */
-        trace_monitor_qmp_in_band_enqueue(req_obj, mon,
-                                          mon->qmp_requests->length);
-        assert(mon->qmp_requests->length < QMP_REQ_QUEUE_LEN_MAX);
-        g_queue_push_tail(mon->qmp_requests, req_obj);
+        trace_monitor_qmp_in_band_enqueue(req_obj, qmon,
+                                          qmon->qmp_requests->length);
+        assert(qmon->qmp_requests->length < QMP_REQ_QUEUE_LEN_MAX);
+        g_queue_push_tail(qmon->qmp_requests, req_obj);
     }
 
     /* Kick the dispatcher routine */
@@ -545,12 +545,12 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
 
 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
 {
-    MonitorQMP *mon = opaque;
+    MonitorQMP *qmon = opaque;
 
-    json_message_parser_feed(&mon->parser, (const char *) buf, size);
+    json_message_parser_feed(&qmon->parser, (const char *) buf, size);
 }
 
-static QDict *qmp_greeting(MonitorQMP *mon)
+static QDict *qmp_greeting(MonitorQMP *qmon)
 {
     QList *cap_list = qlist_new();
     QObject *ver = NULL;
@@ -562,7 +562,7 @@ static QDict *qmp_greeting(MonitorQMP *mon)
     qobject_unref(args);
 
     for (cap = 0; cap < QMP_CAPABILITY__MAX; cap++) {
-        if (mon->capab_offered[cap]) {
+        if (qmon->capab_offered[cap]) {
             qlist_append_str(cap_list, QMPCapability_str(cap));
         }
     }
@@ -574,10 +574,10 @@ static QDict *qmp_greeting(MonitorQMP *mon)
 
 static void monitor_qmp_self_delete_bh(void *opaque)
 {
-    MonitorQMP *mon = opaque;
+    MonitorQMP *qmon = opaque;
     const char *mon_id = object_get_canonical_path_component(
-        OBJECT(mon));
-    g_autofree char *chardev_id = g_strdup(mon->parent_obj.chardev_id);
+        OBJECT(qmon));
+    g_autofree char *chardev_id = g_strdup(qmon->parent_obj.chardev_id);
     Error *local_error = NULL;
 
     if (!mon_id) {
@@ -587,13 +587,13 @@ static void monitor_qmp_self_delete_bh(void *opaque)
          * mon from monitor_qmp_event but it is already
          * unparented.
          */
-        object_unref(mon);
+        object_unref(qmon);
         return;
     }
 
     user_creatable_del(mon_id, &local_error);
     /* Pairs with ref from monitor_qmp_event */
-    object_unref(mon);
+    object_unref(qmon);
     if (local_error != NULL) {
         error_report_err(local_error);
     } else {
@@ -604,25 +604,25 @@ static void monitor_qmp_self_delete_bh(void *opaque)
 static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
 {
     QDict *data;
-    MonitorQMP *mon = opaque;
+    MonitorQMP *qmon = opaque;
 
     /*
      * Protect against race if a client drops & quickly
      * reconnects - we'll have the delete BH scheduled
      * so must not honour a new open request
      */
-    if (mon->delete_pending) {
+    if (qmon->delete_pending) {
         return;
     }
 
     switch (event) {
     case CHR_EVENT_OPENED:
-        WITH_QEMU_LOCK_GUARD(&mon->parent_obj.mon_lock) {
-            mon->commands = &qmp_cap_negotiation_commands;
-            monitor_qmp_caps_reset(mon);
+        WITH_QEMU_LOCK_GUARD(&qmon->parent_obj.mon_lock) {
+            qmon->commands = &qmp_cap_negotiation_commands;
+            monitor_qmp_caps_reset(qmon);
         }
-        data = qmp_greeting(mon);
-        qmp_send_response(mon, data);
+        data = qmp_greeting(qmon);
+        qmp_send_response(qmon, data);
         qobject_unref(data);
         break;
     case CHR_EVENT_CLOSED:
@@ -632,16 +632,16 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
          * stdio, it's possible that stdout is still open when stdin
          * is closed.
          */
-        monitor_qmp_cleanup_queue_and_resume(mon);
-        json_message_parser_destroy(&mon->parser);
-        json_message_parser_init(&mon->parser, handle_qmp_command,
-                                 mon, NULL);
+        monitor_qmp_cleanup_queue_and_resume(qmon);
+        json_message_parser_destroy(&qmon->parser);
+        json_message_parser_init(&qmon->parser, handle_qmp_command,
+                                 qmon, NULL);
         monitor_fdsets_cleanup();
-        switch (mon->close_action) {
+        switch (qmon->close_action) {
         case MONITOR_QMP_CLOSE_ACTION_NONE:
             break;
         case MONITOR_QMP_CLOSE_ACTION_DELETE:
-            mon->delete_pending = true;
+            qmon->delete_pending = true;
             /*
              * Do NOT run in the AIO context associated with the
              * monitor. We need to run in the default AIO context
@@ -652,9 +652,9 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
              * with the BH by processing an explicit 'object-del'.
              * Will be released by monitor_qmp_self_delete_bh
              */
-            object_ref(mon);
+            object_ref(qmon);
             aio_bh_schedule_oneshot(qemu_get_aio_context(),
-                                    monitor_qmp_self_delete_bh, mon);
+                                    monitor_qmp_self_delete_bh, qmon);
             break;
         default:
             g_assert_not_reached();
@@ -668,24 +668,24 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
     }
 }
 
-static bool monitor_qmp_dispatcher_is_servicing(MonitorQMP *mon)
+static bool monitor_qmp_dispatcher_is_servicing(MonitorQMP *qmon)
 {
-    return qmp_dispatcher_current_mon == mon;
+    return qmp_dispatcher_current_mon == qmon;
 }
 
 static void monitor_qmp_setup_handlers_bh(void *opaque)
 {
-    MonitorQMP *mon = opaque;
+    MonitorQMP *qmon = opaque;
     GMainContext *context;
 
-    assert(monitor_requires_iothread(MONITOR(mon)));
+    assert(monitor_requires_iothread(MONITOR(qmon)));
     context = iothread_get_g_main_context(mon_iothread);
     assert(context);
-    qemu_chr_fe_set_handlers(&mon->parent_obj.chr, monitor_can_read,
+    qemu_chr_fe_set_handlers(&qmon->parent_obj.chr, monitor_can_read,
                              monitor_qmp_read, monitor_qmp_event,
-                             NULL, &mon->parent_obj, context, true);
-    monitor_list_append(&mon->parent_obj);
-    qatomic_set(&mon->setup_pending, false);
+                             NULL, &qmon->parent_obj, context, true);
+    monitor_list_append(&qmon->parent_obj);
+    qatomic_set(&qmon->setup_pending, false);
 }
 
 void monitor_new_qmp(const char *id, const char *chardev_id,
@@ -703,11 +703,11 @@ void monitor_new_qmp(const char *id, const char *chardev_id,
 
 static void monitor_qmp_complete(UserCreatable *uc, Error **errp)
 {
-    MonitorQMP *mon = MONITOR_QMP(uc);
+    MonitorQMP *qmon = MONITOR_QMP(uc);
     UserCreatableClass *ucc_parent =
         USER_CREATABLE_CLASS(
             object_class_get_parent(
-                OBJECT_CLASS(MONITOR_QMP_GET_CLASS(mon))));
+                OBJECT_CLASS(MONITOR_QMP_GET_CLASS(qmon))));
     ERRP_GUARD();
 
     ucc_parent->complete(uc, errp);
@@ -715,33 +715,33 @@ static void monitor_qmp_complete(UserCreatable *uc, Error **errp)
         return;
     }
 
-    qemu_chr_fe_set_echo(&mon->parent_obj.chr, true);
+    qemu_chr_fe_set_echo(&qmon->parent_obj.chr, true);
 
-    if (monitor_requires_iothread(MONITOR(mon))) {
+    if (monitor_requires_iothread(MONITOR(qmon))) {
         /*
          * Make sure the old iowatch is gone.  It's possible when
          * e.g. the chardev is in client mode, with wait=on.
          */
-        remove_fd_in_watch(mon->parent_obj.chr.chr);
+        remove_fd_in_watch(qmon->parent_obj.chr.chr);
         /*
          * Clean up listener IO sources early to prevent racy fd
          * handling between the main thread and the I/O thread.
          */
-        remove_listener_fd_in_watch(mon->parent_obj.chr.chr);
+        remove_listener_fd_in_watch(qmon->parent_obj.chr.chr);
         /*
          * We can't call qemu_chr_fe_set_handlers() directly here
          * since chardev might be running in the monitor I/O
          * thread.  Schedule a bottom half.
          */
-        mon->setup_pending = true;
+        qmon->setup_pending = true;
         aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
-                                monitor_qmp_setup_handlers_bh, mon);
+                                monitor_qmp_setup_handlers_bh, qmon);
         /* The bottom half will add @mon to @mon_list */
     } else {
-        qemu_chr_fe_set_handlers(&mon->parent_obj.chr, monitor_can_read,
+        qemu_chr_fe_set_handlers(&qmon->parent_obj.chr, monitor_can_read,
                                  monitor_qmp_read, monitor_qmp_event,
-                                 NULL, &mon->parent_obj, NULL, true);
-        monitor_list_append(&mon->parent_obj);
+                                 NULL, &qmon->parent_obj, NULL, true);
+        monitor_list_append(&qmon->parent_obj);
     }
 }
 
@@ -753,14 +753,14 @@ static void monitor_qmp_iothread_quiesce(void *opaque)
 static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp)
 {
     Monitor *mon = MONITOR(uc);
-    MonitorQMP *qmp = MONITOR_QMP(uc);
+    MonitorQMP *qmon = MONITOR_QMP(uc);
 
-    if (monitor_qmp_dispatcher_is_servicing(qmp)) {
+    if (monitor_qmp_dispatcher_is_servicing(qmon)) {
         error_setg(errp, "Cannot delete the current QMP monitor");
         return false;
     }
 
-    if (qatomic_read(&qmp->setup_pending)) {
+    if (qatomic_read(&qmon->setup_pending)) {
         error_setg(errp, "monitor is still initializing");
         return false;
     }
@@ -779,7 +779,7 @@ static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp)
                              NULL, NULL, true);
 
     /* Drain requests from any in-flight monitor_qmp_read(). */
-    monitor_qmp_drain_queue(qmp);
+    monitor_qmp_drain_queue(qmon);
 
     WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
         /* Disable flushes before cancel -- gcontext is already wrong. */
@@ -794,7 +794,7 @@ static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp)
     }
 
     /* Catch requests from a racing monitor_qmp_read(). */
-    monitor_qmp_drain_queue(qmp);
+    monitor_qmp_drain_queue(qmon);
     monitor_fdsets_cleanup();
 
     return true;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 18/23] monitor: Rename MonitorHMP @mon -> @hmon
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (16 preceding siblings ...)
  2026-08-12 21:17 ` [PATCH v3 17/23] monitor: Rename MonitorQMP @mon -> @qmon Philippe Mathieu-Daudé
@ 2026-08-12 21:17 ` Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 19/23] monitor: Better express monitor_read()'s opaque arg is of Monitor type Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé, Peter Xu,
	Fabiano Rosas

Mechanical change to sanitize using the following patterns:

  MonitorQMP *qmon  (previous patch)
  MonitorHMP *hmon  (this patch)
  Monitor *mon

Rename @mon (and @hmp_mon) as @hmon when the type is MonitorHMP.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 include/monitor/monitor.h      |   4 +-
 monitor/monitor-internal.h     |   2 +-
 migration/migration-hmp-cmds.c |   4 +-
 monitor/hmp-cmds.c             |  10 +--
 monitor/hmp.c                  | 155 +++++++++++++++++----------------
 monitor/qmp-cmds.c             |  12 +--
 ui/ui-hmp-cmds.c               |   4 +-
 7 files changed, 96 insertions(+), 95 deletions(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index fd98ee2c71d..e86b945350a 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -55,8 +55,8 @@ void monitor_flush_locked(Monitor *mon);
 
 void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, uint64_t size, Error **errp);
 
-void monitor_read_command(MonitorHMP *mon, int show_prompt);
-int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func,
+void monitor_read_command(MonitorHMP *hmon, int show_prompt);
+int monitor_read_password(MonitorHMP *hmon, ReadLineFunc *readline_func,
                           void *opaque);
 
 AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index cfbb3e5ecea..65015409288 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -221,7 +221,7 @@ void monitor_data_destroy_qmp(MonitorQMP *qmon);
 void coroutine_fn monitor_qmp_dispatcher_co(void *data);
 void qmp_dispatcher_co_wake(void);
 
-void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
+void handle_hmp_command(MonitorHMP *hmon, const char *cmdline);
 int hmp_compare_cmd(const char *name, const char *list);
 
 /*
diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c
index 351512942af..d4ca67575ab 100644
--- a/migration/migration-hmp-cmds.c
+++ b/migration/migration-hmp-cmds.c
@@ -855,9 +855,9 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
 
     if (!detach) {
         HMPMigrationStatus *status;
-        MonitorHMP *hmp = MONITOR_HMP(mon);
+        MonitorHMP *hmon = MONITOR_HMP(mon);
 
-        if (!hmp->use_readline) {
+        if (!hmon->use_readline) {
             monitor_printf(mon, "terminal does not allow synchronous "
                            "migration, continuing detached\n");
             return;
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index e9fb8d827a0..71d7df6d013 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -129,8 +129,8 @@ void hmp_info_version(Monitor *mon, const QDict *qdict)
 
 void hmp_quit(Monitor *mon, const QDict *qdict)
 {
-    MonitorHMP *hmp = MONITOR_HMP(mon);
-    if (hmp->use_readline) {
+    MonitorHMP *hmon = MONITOR_HMP(mon);
+    if (hmon->use_readline) {
         monitor_suspend(mon);
     }
     qmp_quit(NULL);
@@ -290,16 +290,16 @@ void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
 
 void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
-    MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, parent_obj);
+    MonitorHMP *hmon = container_of(mon, MonitorHMP, parent_obj);
     int i;
     const char *str;
 
-    if (!hmp_mon->rs) {
+    if (!hmon->rs) {
         return;
     }
     i = 0;
     for(;;) {
-        str = readline_get_history(hmp_mon->rs, i);
+        str = readline_get_history(hmon->rs, i);
         if (!str) {
             break;
         }
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 71a18882491..24076dc7c03 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -49,24 +49,24 @@ OBJECT_DEFINE_TYPE(MonitorHMP, monitor_hmp, MONITOR_HMP, MONITOR);
 
 static void monitor_hmp_finalize(Object *obj)
 {
-    MonitorHMP *mon = MONITOR_HMP(obj);
-    if (mon->rs) {
-        readline_free(mon->rs);
+    MonitorHMP *hmon = MONITOR_HMP(obj);
+    if (hmon->rs) {
+        readline_free(hmon->rs);
     }
 }
 
 static bool monitor_hmp_get_readline(Object *obj, Error **errp)
 {
-    MonitorHMP *mon = MONITOR_HMP(obj);
+    MonitorHMP *hmon = MONITOR_HMP(obj);
 
-    return mon->use_readline;
+    return hmon->use_readline;
 }
 
 static void monitor_hmp_set_readline(Object *obj, bool val, Error **errp)
 {
-    MonitorHMP *mon = MONITOR_HMP(obj);
+    MonitorHMP *hmon = MONITOR_HMP(obj);
 
-    mon->use_readline = val;
+    hmon->use_readline = val;
 }
 
 int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap)
@@ -93,14 +93,14 @@ static void monitor_hmp_class_init(ObjectClass *cls, const void *data)
 
 static void monitor_hmp_init(Object *obj)
 {
-    MonitorHMP *hmp = MONITOR_HMP(obj);
+    MonitorHMP *hmon = MONITOR_HMP(obj);
 
     /*
      * Default to common case for external HMP use,
      * as opposed to non-interactive internal use
      * from gdbstub
      */
-    hmp->use_readline = true;
+    hmon->use_readline = true;
 }
 
 int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap)
@@ -113,12 +113,12 @@ static void monitor_hmp_accept_input(Monitor *mon)
 {
     qemu_mutex_lock(&mon->mon_lock);
     if (mon->reset_seen) {
-        MonitorHMP *hmp = MONITOR_HMP(mon);
-        assert(hmp->rs);
-        readline_restart(hmp->rs);
+        MonitorHMP *hmon = MONITOR_HMP(mon);
+        assert(hmon->rs);
+        readline_restart(hmon->rs);
         qemu_chr_fe_accept_input(&mon->chr);
         qemu_mutex_unlock(&mon->mon_lock);
-        readline_show_prompt(hmp->rs);
+        readline_show_prompt(hmon->rs);
     } else {
         qemu_chr_fe_accept_input(&mon->chr);
         qemu_mutex_unlock(&mon->mon_lock);
@@ -128,34 +128,34 @@ static void monitor_hmp_accept_input(Monitor *mon)
 static void monitor_command_cb(void *opaque, const char *cmdline,
                                void *readline_opaque)
 {
-    MonitorHMP *mon = opaque;
+    MonitorHMP *hmon = opaque;
 
-    monitor_suspend(&mon->parent_obj);
-    handle_hmp_command(mon, cmdline);
-    monitor_resume(&mon->parent_obj);
+    monitor_suspend(&hmon->parent_obj);
+    handle_hmp_command(hmon, cmdline);
+    monitor_resume(&hmon->parent_obj);
 }
 
-void monitor_read_command(MonitorHMP *mon, int show_prompt)
+void monitor_read_command(MonitorHMP *hmon, int show_prompt)
 {
-    if (!mon->rs) {
+    if (!hmon->rs) {
         return;
     }
 
-    readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL);
+    readline_start(hmon->rs, "(qemu) ", 0, monitor_command_cb, NULL);
     if (show_prompt) {
-        readline_show_prompt(mon->rs);
+        readline_show_prompt(hmon->rs);
     }
 }
 
-int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func,
+int monitor_read_password(MonitorHMP *hmon, ReadLineFunc *readline_func,
                           void *opaque)
 {
-    if (mon->rs) {
-        readline_start(mon->rs, "Password: ", 1, readline_func, opaque);
+    if (hmon->rs) {
+        readline_start(hmon->rs, "Password: ", 1, readline_func, opaque);
         /* prompt is printed on return from the command handler */
         return 0;
     } else {
-        monitor_printf(&mon->parent_obj,
+        monitor_printf(&hmon->parent_obj,
                        "terminal does not support password prompting\n");
         return -ENOTTY;
     }
@@ -772,12 +772,12 @@ static const HMPCommand *search_dispatch_table(const HMPCommand *disp_table,
  * Do not assume the return value points into @table!  It doesn't when
  * the command is found in a sub-command table.
  */
-static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
+static const HMPCommand *monitor_parse_command(MonitorHMP *hmon,
                                                const char *cmdp_start,
                                                const char **cmdp,
                                                HMPCommand *table)
 {
-    Monitor *mon = &hmp_mon->parent_obj;
+    Monitor *mon = &hmon->parent_obj;
     const char *p;
     const HMPCommand *cmd;
     char cmdname[256];
@@ -809,7 +809,7 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
     *cmdp = p;
     /* search sub command */
     if (cmd->sub_table != NULL && *p != '\0') {
-        return monitor_parse_command(hmp_mon, cmdp_start, cmdp, cmd->sub_table);
+        return monitor_parse_command(hmon, cmdp_start, cmdp, cmd->sub_table);
     }
 
     return cmd;
@@ -1254,15 +1254,15 @@ static void handle_hmp_command_co(void *opaque)
     data->done = true;
 }
 
-void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
+void handle_hmp_command(MonitorHMP *hmon, const char *cmdline)
 {
     QDict *qdict;
     const HMPCommand *cmd;
     const char *cmd_start = cmdline;
 
-    trace_handle_hmp_command(mon, cmdline);
+    trace_handle_hmp_command(hmon, cmdline);
 
-    cmd = monitor_parse_command(mon, cmdline, &cmdline,
+    cmd = monitor_parse_command(hmon, cmdline, &cmdline,
                                 hmp_cmds_for_target(false));
     if (!cmd) {
         return;
@@ -1270,17 +1270,17 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
 
     if (!cmd->cmd && !cmd->cmd_info_hrt) {
         /* FIXME: is it useful to try autoload modules here ??? */
-        monitor_printf(&mon->parent_obj, "Command \"%.*s\" is not available.\n",
+        monitor_printf(&hmon->parent_obj, "Command \"%.*s\" is not available.\n",
                        (int)(cmdline - cmd_start), cmd_start);
         return;
     }
 
-    qdict = monitor_parse_arguments(&mon->parent_obj, &cmdline, cmd);
+    qdict = monitor_parse_arguments(&hmon->parent_obj, &cmdline, cmd);
     if (!qdict) {
         while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) {
             cmdline--;
         }
-        monitor_printf(&mon->parent_obj,
+        monitor_printf(&hmon->parent_obj,
                        "Try \"help %.*s\" for more information\n",
                        (int)(cmdline - cmd_start), cmd_start);
         return;
@@ -1289,18 +1289,18 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
     if (!cmd->coroutine) {
         /* old_mon is non-NULL when called from qmp_human_monitor_command() */
         Monitor *old_mon = monitor_set_cur(qemu_coroutine_self(),
-                                           &mon->parent_obj);
-        handle_hmp_command_exec(&mon->parent_obj, cmd, qdict);
+                                           &hmon->parent_obj);
+        handle_hmp_command_exec(&hmon->parent_obj, cmd, qdict);
         monitor_set_cur(qemu_coroutine_self(), old_mon);
     } else {
         HandleHmpCommandCo data = {
-            .mon = &mon->parent_obj,
+            .mon = &hmon->parent_obj,
             .cmd = cmd,
             .qdict = qdict,
             .done = false,
         };
         Coroutine *co = qemu_coroutine_create(handle_hmp_command_co, &data);
-        monitor_set_cur(co, &mon->parent_obj);
+        monitor_set_cur(co, &hmon->parent_obj);
         aio_co_enter(qemu_get_aio_context(), co);
         AIO_WAIT_WHILE_UNLOCKED(NULL, !data.done);
     }
@@ -1308,7 +1308,8 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
     qobject_unref(qdict);
 }
 
-static void cmd_completion(MonitorHMP *mon, const char *name, const char *list)
+static void cmd_completion(MonitorHMP *hmon,
+                           const char *name, const char *list)
 {
     const char *p, *pstart;
     char cmd[128];
@@ -1324,7 +1325,7 @@ static void cmd_completion(MonitorHMP *mon, const char *name, const char *list)
         }
         memcpy(cmd, pstart, len);
         cmd[len] = '\0';
-        readline_add_completion_of(mon->rs, name, cmd);
+        readline_add_completion_of(hmon->rs, name, cmd);
         if (*p == '\0') {
             break;
         }
@@ -1332,7 +1333,7 @@ static void cmd_completion(MonitorHMP *mon, const char *name, const char *list)
     }
 }
 
-static void file_completion(MonitorHMP *mon, const char *input)
+static void file_completion(MonitorHMP *hmon, const char *input)
 {
     DIR *ffs;
     struct dirent *d;
@@ -1384,7 +1385,7 @@ static void file_completion(MonitorHMP *mon, const char *input)
             if (stat(file, &sb) == 0 && S_ISDIR(sb.st_mode)) {
                 pstrcat(file, sizeof(file), "/");
             }
-            readline_add_completion(mon->rs, file);
+            readline_add_completion(hmon->rs, file);
         }
     }
     closedir(ffs);
@@ -1396,7 +1397,7 @@ static const char *next_arg_type(const char *typestr)
     return (p != NULL ? ++p : typestr);
 }
 
-static void monitor_find_completion_by_table(MonitorHMP *mon,
+static void monitor_find_completion_by_table(MonitorHMP *hmon,
                                              const HMPCommand *cmd_table,
                                              char **args,
                                              int nb_args)
@@ -1414,10 +1415,10 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
         } else {
             cmdname = args[0];
         }
-        readline_set_completion_index(mon->rs, strlen(cmdname));
+        readline_set_completion_index(hmon->rs, strlen(cmdname));
         for (cmd = cmd_table; cmd->name != NULL; cmd++) {
             if (cmd_available(cmd)) {
-                cmd_completion(mon, cmdname, cmd->name);
+                cmd_completion(hmon, cmdname, cmd->name);
             }
         }
     } else {
@@ -1434,12 +1435,12 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
 
         if (cmd->sub_table) {
             /* do the job again */
-            monitor_find_completion_by_table(mon, cmd->sub_table,
+            monitor_find_completion_by_table(hmon, cmd->sub_table,
                                              &args[1], nb_args - 1);
             return;
         }
         if (cmd->command_completion) {
-            cmd->command_completion(mon->rs, nb_args, args[nb_args - 1]);
+            cmd->command_completion(hmon->rs, nb_args, args[nb_args - 1]);
             return;
         }
 
@@ -1461,20 +1462,20 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
         switch (*ptype) {
         case 'F':
             /* file completion */
-            readline_set_completion_index(mon->rs, strlen(str));
-            file_completion(mon, str);
+            readline_set_completion_index(hmon->rs, strlen(str));
+            file_completion(hmon, str);
             break;
         case 'B':
             /* block device name completion */
-            readline_set_completion_index(mon->rs, strlen(str));
+            readline_set_completion_index(hmon->rs, strlen(str));
             while ((blk = blk_next(blk)) != NULL) {
-                readline_add_completion_of(mon->rs, str, blk_name(blk));
+                readline_add_completion_of(hmon->rs, str, blk_name(blk));
             }
             break;
         case 's':
         case 'S':
             if (!strcmp(cmd->name, "help|?")) {
-                monitor_find_completion_by_table(mon, cmd_table,
+                monitor_find_completion_by_table(hmon, cmd_table,
                                                  &args[1], nb_args - 1);
             }
             break;
@@ -1487,7 +1488,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
 static void monitor_find_completion(void *opaque,
                                     const char *cmdline)
 {
-    MonitorHMP *mon = opaque;
+    MonitorHMP *hmon = opaque;
     char *args[MAX_ARGS];
     int nb_args, len;
 
@@ -1509,7 +1510,7 @@ static void monitor_find_completion(void *opaque,
     }
 
     /* 2. auto complete according to args */
-    monitor_find_completion_by_table(mon, hmp_cmds_for_target(false),
+    monitor_find_completion_by_table(hmon, hmp_cmds_for_target(false),
                                      args, nb_args);
 
 cleanup:
@@ -1518,18 +1519,18 @@ cleanup:
 
 static void monitor_read(void *opaque, const uint8_t *buf, int size)
 {
-    MonitorHMP *mon = container_of(opaque, MonitorHMP, parent_obj);
+    MonitorHMP *hmon = container_of(opaque, MonitorHMP, parent_obj);
     int i;
 
-    if (mon->rs) {
+    if (hmon->rs) {
         for (i = 0; i < size; i++) {
-            readline_handle_byte(mon->rs, buf[i]);
+            readline_handle_byte(hmon->rs, buf[i]);
         }
     } else {
         if (size == 0 || buf[size - 1] != 0) {
-            monitor_printf(&mon->parent_obj, "corrupted command\n");
+            monitor_printf(&hmon->parent_obj, "corrupted command\n");
         } else {
-            handle_hmp_command(mon, (char *)buf);
+            handle_hmp_command(hmon, (char *)buf);
         }
     }
 }
@@ -1537,14 +1538,14 @@ static void monitor_read(void *opaque, const uint8_t *buf, int size)
 static void monitor_event(void *opaque, QEMUChrEvent event)
 {
     Monitor *mon = opaque;
-    MonitorHMP *hmp = MONITOR_HMP(mon);
+    MonitorHMP *hmon = MONITOR_HMP(mon);
 
     switch (event) {
     case CHR_EVENT_MUX_IN:
         qemu_mutex_lock(&mon->mon_lock);
         if (mon->mux_out) {
             mon->mux_out = 0;
-            if (hmp->use_readline) {
+            if (hmon->use_readline) {
                 monitor_resume(mon);
             }
         }
@@ -1559,7 +1560,7 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
             } else {
                 monitor_flush_locked(mon);
             }
-            if (hmp->use_readline) {
+            if (hmon->use_readline) {
                 monitor_suspend(mon);
             }
             mon->mux_out = 1;
@@ -1572,7 +1573,7 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
                        "information\n", QEMU_VERSION);
         qemu_mutex_lock(&mon->mon_lock);
         mon->reset_seen = 1;
-        if (!mon->mux_out && hmp->use_readline) {
+        if (!mon->mux_out && hmon->use_readline) {
             /* Suspend-resume forces the prompt to be printed.  */
             monitor_suspend(mon);
             monitor_resume(mon);
@@ -1598,17 +1599,17 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
 static void G_GNUC_PRINTF(2, 3) monitor_readline_printf(void *opaque,
                                                        const char *fmt, ...)
 {
-    MonitorHMP *mon = opaque;
+    MonitorHMP *hmon = opaque;
     va_list ap;
     va_start(ap, fmt);
-    monitor_vprintf(&mon->parent_obj, fmt, ap);
+    monitor_vprintf(&hmon->parent_obj, fmt, ap);
     va_end(ap);
 }
 
 static void monitor_readline_flush(void *opaque)
 {
-    MonitorHMP *mon = opaque;
-    monitor_flush(&mon->parent_obj);
+    MonitorHMP *hmon = opaque;
+    monitor_flush(&hmon->parent_obj);
 }
 
 void monitor_new_hmp(const char *id, const char *chardev_id,
@@ -1626,11 +1627,11 @@ void monitor_new_hmp(const char *id, const char *chardev_id,
 
 static void monitor_hmp_complete(UserCreatable *uc, Error **errp)
 {
-    MonitorHMP *mon = MONITOR_HMP(uc);
+    MonitorHMP *hmon = MONITOR_HMP(uc);
     UserCreatableClass *ucc_parent =
         USER_CREATABLE_CLASS(
             object_class_get_parent(
-                OBJECT_CLASS(MONITOR_HMP_GET_CLASS(mon))));
+                OBJECT_CLASS(MONITOR_HMP_GET_CLASS(hmon))));
     ERRP_GUARD();
 
     ucc_parent->complete(uc, errp);
@@ -1638,21 +1639,21 @@ static void monitor_hmp_complete(UserCreatable *uc, Error **errp)
         return;
     }
 
-    if (mon->parent_obj.chardev_id) {
-        if (mon->use_readline) {
-            mon->rs = readline_init(monitor_readline_printf,
+    if (hmon->parent_obj.chardev_id) {
+        if (hmon->use_readline) {
+            hmon->rs = readline_init(monitor_readline_printf,
                                     monitor_readline_flush,
-                                    mon,
+                                    hmon,
                                     monitor_find_completion);
-            monitor_read_command(mon, 0);
+            monitor_read_command(hmon, 0);
         }
 
-        qemu_chr_fe_set_handlers(&mon->parent_obj.chr,
+        qemu_chr_fe_set_handlers(&hmon->parent_obj.chr,
                                  monitor_can_read,
                                  monitor_read,
                                  monitor_event, NULL,
-                                 &mon->parent_obj, NULL, true);
-        monitor_list_append(&mon->parent_obj);
+                                 &hmon->parent_obj, NULL, true);
+        monitor_list_append(&hmon->parent_obj);
     }
 }
 
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 6cb0b587fbd..4ca87857c3f 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -166,10 +166,10 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
                                 int64_t cpu_index, Error **errp)
 {
     char *output = NULL;
-    MonitorHMP *hmp = MONITOR_HMP(object_new(TYPE_MONITOR_HMP));
+    MonitorHMP *hmon = MONITOR_HMP(object_new(TYPE_MONITOR_HMP));
 
     if (has_cpu_index) {
-        int ret = monitor_set_cpu(&hmp->parent_obj, cpu_index);
+        int ret = monitor_set_cpu(&hmon->parent_obj, cpu_index);
         if (ret < 0) {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
                        "a CPU number");
@@ -177,14 +177,14 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
         }
     }
 
-    handle_hmp_command(hmp, command_line);
+    handle_hmp_command(hmon, command_line);
 
-    WITH_QEMU_LOCK_GUARD(&hmp->parent_obj.mon_lock) {
-        output = g_strdup(hmp->parent_obj.outbuf->str);
+    WITH_QEMU_LOCK_GUARD(&hmon->parent_obj.mon_lock) {
+        output = g_strdup(hmon->parent_obj.outbuf->str);
     }
 
 out:
-    object_unref(hmp);
+    object_unref(hmon);
     return output;
 }
 
diff --git a/ui/ui-hmp-cmds.c b/ui/ui-hmp-cmds.c
index 06f4030ce4f..fb13eca0b0c 100644
--- a/ui/ui-hmp-cmds.c
+++ b/ui/ui-hmp-cmds.c
@@ -343,8 +343,8 @@ void hmp_change_vnc(Monitor *mon, const char *device, const char *target,
         return;
     }
     if (!arg) {
-        MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, parent_obj);
-        monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
+        MonitorHMP *hmon = container_of(mon, MonitorHMP, parent_obj);
+        monitor_read_password(hmon, hmp_change_read_arg, NULL);
     } else {
         qmp_change_vnc_password(arg, errp);
     }
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 19/23] monitor: Better express monitor_read()'s opaque arg is of Monitor type
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (17 preceding siblings ...)
  2026-08-12 21:17 ` [PATCH v3 18/23] monitor: Rename MonitorHMP @mon -> @hmon Philippe Mathieu-Daudé
@ 2026-08-12 21:17 ` Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 20/23] monitor: Use QOM MONITOR() macro to access MonitorQMP->parent_obj Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

monitor_read() is a IOReadHandler handler, called by
qemu_chr_fe_set_handlers() with a Monitor* opaque argument.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 monitor/hmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/monitor/hmp.c b/monitor/hmp.c
index 24076dc7c03..bfe3cea902c 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1519,7 +1519,8 @@ cleanup:
 
 static void monitor_read(void *opaque, const uint8_t *buf, int size)
 {
-    MonitorHMP *hmon = container_of(opaque, MonitorHMP, parent_obj);
+    Monitor *mon = opaque;
+    MonitorHMP *hmon = container_of(mon, MonitorHMP, parent_obj);
     int i;
 
     if (hmon->rs) {
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 20/23] monitor: Use QOM MONITOR() macro to access MonitorQMP->parent_obj
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (18 preceding siblings ...)
  2026-08-12 21:17 ` [PATCH v3 19/23] monitor: Better express monitor_read()'s opaque arg is of Monitor type Philippe Mathieu-Daudé
@ 2026-08-12 21:17 ` Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 21/23] monitor: Use QOM MONITOR() macro to access MonitorHMP->parent_obj Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

MonitorQMP QOM parent is Monitor, so we can use the following
QOM-cast macro:

  MONITOR(qmon) == &qmon->parent_obj

When introducing a Monitor variable, name it @mon.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 monitor/qmp.c | 45 ++++++++++++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/monitor/qmp.c b/monitor/qmp.c
index d6ce734916e..0fed9f47213 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -213,6 +213,8 @@ static void monitor_qmp_drain_queue(MonitorQMP *qmon)
 
 static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *qmon)
 {
+    Monitor *mon = MONITOR(qmon);
+
     QEMU_LOCK_GUARD(&qmon->qmp_queue_lock);
 
     /*
@@ -237,7 +239,7 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *qmon)
          * when we get here while the monitor is suspended.  An
          * unfortunately timed CHR_EVENT_CLOSED can do the trick.
          */
-        monitor_resume(&qmon->parent_obj);
+        monitor_resume(mon);
     }
 
 }
@@ -245,6 +247,7 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *qmon)
 void qmp_send_response(MonitorQMP *qmon, const QDict *rsp)
 {
     const QObject *data = QOBJECT(rsp);
+    Monitor *mon = MONITOR(qmon);
     GString *json;
 
     json = qobject_to_json_pretty(data, qmon->pretty);
@@ -252,7 +255,7 @@ void qmp_send_response(MonitorQMP *qmon, const QDict *rsp)
     trace_monitor_qmp_respond(qmon, json->str);
 
     g_string_append_c(json, '\n');
-    monitor_puts(&qmon->parent_obj, json->str);
+    monitor_puts(mon, json->str);
 
     g_string_free(json, true);
 }
@@ -277,9 +280,10 @@ static void monitor_qmp_dispatch(MonitorQMP *qmon, QObject *req)
 {
     QDict *rsp;
     QDict *error;
+    Monitor *mon = MONITOR(qmon);
 
     rsp = qmp_dispatch(qmon->commands, req, qmp_oob_enabled(qmon),
-                       &qmon->parent_obj);
+                       mon);
 
     if (qmon->commands == &qmp_cap_negotiation_commands) {
         error = qdict_get_qdict(rsp, "error");
@@ -392,6 +396,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
     QDict *rsp;
     bool oob_enabled;
     MonitorQMP *qmon;
+    Monitor *mon;
 
     while ((req_obj = monitor_qmp_dispatcher_pop_any()) != NULL) {
         trace_monitor_qmp_in_band_dequeue(req_obj,
@@ -402,6 +407,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
          */
 
         qmon = req_obj->mon;
+        mon = MONITOR(qmon);
         qmp_dispatcher_current_mon = qmon;
 
         /*
@@ -418,7 +424,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
         oob_enabled = qmp_oob_enabled(qmon);
         if (oob_enabled
             && qmon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1) {
-            monitor_resume(&qmon->parent_obj);
+            monitor_resume(mon);
         }
 
         /*
@@ -459,7 +465,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
         }
 
         if (!oob_enabled) {
-            monitor_resume(&qmon->parent_obj);
+            monitor_resume(mon);
         }
 
         qmp_request_free(req_obj);
@@ -482,6 +488,7 @@ void qmp_dispatcher_co_wake(void)
 static void handle_qmp_command(void *opaque, QObject *req, Error *err)
 {
     MonitorQMP *qmon = opaque;
+    Monitor *mon = MONITOR(qmon);
     QDict *qdict = qobject_to(QDict, req);
     QMPRequest *req_obj;
 
@@ -525,7 +532,7 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
          */
         if (!qmp_oob_enabled(qmon) ||
             qmon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1) {
-            monitor_suspend(&qmon->parent_obj);
+            monitor_suspend(mon);
         }
 
         /*
@@ -575,9 +582,10 @@ static QDict *qmp_greeting(MonitorQMP *qmon)
 static void monitor_qmp_self_delete_bh(void *opaque)
 {
     MonitorQMP *qmon = opaque;
+    Monitor *mon = MONITOR(qmon);
     const char *mon_id = object_get_canonical_path_component(
         OBJECT(qmon));
-    g_autofree char *chardev_id = g_strdup(qmon->parent_obj.chardev_id);
+    g_autofree char *chardev_id = g_strdup(mon->chardev_id);
     Error *local_error = NULL;
 
     if (!mon_id) {
@@ -605,6 +613,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
 {
     QDict *data;
     MonitorQMP *qmon = opaque;
+    Monitor *mon = MONITOR(qmon);
 
     /*
      * Protect against race if a client drops & quickly
@@ -617,7 +626,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
 
     switch (event) {
     case CHR_EVENT_OPENED:
-        WITH_QEMU_LOCK_GUARD(&qmon->parent_obj.mon_lock) {
+        WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
             qmon->commands = &qmp_cap_negotiation_commands;
             monitor_qmp_caps_reset(qmon);
         }
@@ -676,15 +685,16 @@ static bool monitor_qmp_dispatcher_is_servicing(MonitorQMP *qmon)
 static void monitor_qmp_setup_handlers_bh(void *opaque)
 {
     MonitorQMP *qmon = opaque;
+    Monitor *mon = MONITOR(qmon);
     GMainContext *context;
 
     assert(monitor_requires_iothread(MONITOR(qmon)));
     context = iothread_get_g_main_context(mon_iothread);
     assert(context);
-    qemu_chr_fe_set_handlers(&qmon->parent_obj.chr, monitor_can_read,
+    qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
                              monitor_qmp_read, monitor_qmp_event,
-                             NULL, &qmon->parent_obj, context, true);
-    monitor_list_append(&qmon->parent_obj);
+                             NULL, mon, context, true);
+    monitor_list_append(mon);
     qatomic_set(&qmon->setup_pending, false);
 }
 
@@ -704,6 +714,7 @@ void monitor_new_qmp(const char *id, const char *chardev_id,
 static void monitor_qmp_complete(UserCreatable *uc, Error **errp)
 {
     MonitorQMP *qmon = MONITOR_QMP(uc);
+    Monitor *mon = MONITOR(qmon);
     UserCreatableClass *ucc_parent =
         USER_CREATABLE_CLASS(
             object_class_get_parent(
@@ -715,19 +726,19 @@ static void monitor_qmp_complete(UserCreatable *uc, Error **errp)
         return;
     }
 
-    qemu_chr_fe_set_echo(&qmon->parent_obj.chr, true);
+    qemu_chr_fe_set_echo(&mon->chr, true);
 
     if (monitor_requires_iothread(MONITOR(qmon))) {
         /*
          * Make sure the old iowatch is gone.  It's possible when
          * e.g. the chardev is in client mode, with wait=on.
          */
-        remove_fd_in_watch(qmon->parent_obj.chr.chr);
+        remove_fd_in_watch(mon->chr.chr);
         /*
          * Clean up listener IO sources early to prevent racy fd
          * handling between the main thread and the I/O thread.
          */
-        remove_listener_fd_in_watch(qmon->parent_obj.chr.chr);
+        remove_listener_fd_in_watch(mon->chr.chr);
         /*
          * We can't call qemu_chr_fe_set_handlers() directly here
          * since chardev might be running in the monitor I/O
@@ -738,10 +749,10 @@ static void monitor_qmp_complete(UserCreatable *uc, Error **errp)
                                 monitor_qmp_setup_handlers_bh, qmon);
         /* The bottom half will add @mon to @mon_list */
     } else {
-        qemu_chr_fe_set_handlers(&qmon->parent_obj.chr, monitor_can_read,
+        qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
                                  monitor_qmp_read, monitor_qmp_event,
-                                 NULL, &qmon->parent_obj, NULL, true);
-        monitor_list_append(&qmon->parent_obj);
+                                 NULL, mon, NULL, true);
+        monitor_list_append(mon);
     }
 }
 
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 21/23] monitor: Use QOM MONITOR() macro to access MonitorHMP->parent_obj
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (19 preceding siblings ...)
  2026-08-12 21:17 ` [PATCH v3 20/23] monitor: Use QOM MONITOR() macro to access MonitorQMP->parent_obj Philippe Mathieu-Daudé
@ 2026-08-12 21:17 ` Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 22/23] monitor: Replace container_of(MonitorHMP, parent_obj) -> MONITOR_HMP() Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 23/23] monitor/hmp: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

MonitorHMP QOM parent is Monitor, so we can use the following
QOM-cast macro:

  MONITOR(hmon) == &hmon->parent_obj

When introducing a Monitor variable, name it @mon.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 monitor/hmp.c      | 44 ++++++++++++++++++++++++++------------------
 monitor/qmp-cmds.c |  7 ++++---
 2 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/monitor/hmp.c b/monitor/hmp.c
index bfe3cea902c..428ef014284 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -129,10 +129,11 @@ static void monitor_command_cb(void *opaque, const char *cmdline,
                                void *readline_opaque)
 {
     MonitorHMP *hmon = opaque;
+    Monitor *mon = MONITOR(hmon);
 
-    monitor_suspend(&hmon->parent_obj);
+    monitor_suspend(mon);
     handle_hmp_command(hmon, cmdline);
-    monitor_resume(&hmon->parent_obj);
+    monitor_resume(mon);
 }
 
 void monitor_read_command(MonitorHMP *hmon, int show_prompt)
@@ -155,7 +156,8 @@ int monitor_read_password(MonitorHMP *hmon, ReadLineFunc *readline_func,
         /* prompt is printed on return from the command handler */
         return 0;
     } else {
-        monitor_printf(&hmon->parent_obj,
+        Monitor *mon = MONITOR(hmon);
+        monitor_printf(mon,
                        "terminal does not support password prompting\n");
         return -ENOTTY;
     }
@@ -777,7 +779,7 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmon,
                                                const char **cmdp,
                                                HMPCommand *table)
 {
-    Monitor *mon = &hmon->parent_obj;
+    Monitor *mon = MONITOR(hmon);
     const char *p;
     const HMPCommand *cmd;
     char cmdname[256];
@@ -1257,6 +1259,7 @@ static void handle_hmp_command_co(void *opaque)
 void handle_hmp_command(MonitorHMP *hmon, const char *cmdline)
 {
     QDict *qdict;
+    Monitor *mon = MONITOR(hmon);
     const HMPCommand *cmd;
     const char *cmd_start = cmdline;
 
@@ -1270,17 +1273,17 @@ void handle_hmp_command(MonitorHMP *hmon, const char *cmdline)
 
     if (!cmd->cmd && !cmd->cmd_info_hrt) {
         /* FIXME: is it useful to try autoload modules here ??? */
-        monitor_printf(&hmon->parent_obj, "Command \"%.*s\" is not available.\n",
+        monitor_printf(mon, "Command \"%.*s\" is not available.\n",
                        (int)(cmdline - cmd_start), cmd_start);
         return;
     }
 
-    qdict = monitor_parse_arguments(&hmon->parent_obj, &cmdline, cmd);
+    qdict = monitor_parse_arguments(mon, &cmdline, cmd);
     if (!qdict) {
         while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) {
             cmdline--;
         }
-        monitor_printf(&hmon->parent_obj,
+        monitor_printf(mon,
                        "Try \"help %.*s\" for more information\n",
                        (int)(cmdline - cmd_start), cmd_start);
         return;
@@ -1289,18 +1292,18 @@ void handle_hmp_command(MonitorHMP *hmon, const char *cmdline)
     if (!cmd->coroutine) {
         /* old_mon is non-NULL when called from qmp_human_monitor_command() */
         Monitor *old_mon = monitor_set_cur(qemu_coroutine_self(),
-                                           &hmon->parent_obj);
-        handle_hmp_command_exec(&hmon->parent_obj, cmd, qdict);
+                                           mon);
+        handle_hmp_command_exec(mon, cmd, qdict);
         monitor_set_cur(qemu_coroutine_self(), old_mon);
     } else {
         HandleHmpCommandCo data = {
-            .mon = &hmon->parent_obj,
+            .mon = mon,
             .cmd = cmd,
             .qdict = qdict,
             .done = false,
         };
         Coroutine *co = qemu_coroutine_create(handle_hmp_command_co, &data);
-        monitor_set_cur(co, &hmon->parent_obj);
+        monitor_set_cur(co, mon);
         aio_co_enter(qemu_get_aio_context(), co);
         AIO_WAIT_WHILE_UNLOCKED(NULL, !data.done);
     }
@@ -1529,7 +1532,7 @@ static void monitor_read(void *opaque, const uint8_t *buf, int size)
         }
     } else {
         if (size == 0 || buf[size - 1] != 0) {
-            monitor_printf(&hmon->parent_obj, "corrupted command\n");
+            monitor_printf(mon, "corrupted command\n");
         } else {
             handle_hmp_command(hmon, (char *)buf);
         }
@@ -1601,16 +1604,20 @@ static void G_GNUC_PRINTF(2, 3) monitor_readline_printf(void *opaque,
                                                        const char *fmt, ...)
 {
     MonitorHMP *hmon = opaque;
+    Monitor *mon = MONITOR(hmon);
+
     va_list ap;
     va_start(ap, fmt);
-    monitor_vprintf(&hmon->parent_obj, fmt, ap);
+    monitor_vprintf(mon, fmt, ap);
     va_end(ap);
 }
 
 static void monitor_readline_flush(void *opaque)
 {
     MonitorHMP *hmon = opaque;
-    monitor_flush(&hmon->parent_obj);
+    Monitor *mon = MONITOR(hmon);
+
+    monitor_flush(mon);
 }
 
 void monitor_new_hmp(const char *id, const char *chardev_id,
@@ -1629,6 +1636,7 @@ void monitor_new_hmp(const char *id, const char *chardev_id,
 static void monitor_hmp_complete(UserCreatable *uc, Error **errp)
 {
     MonitorHMP *hmon = MONITOR_HMP(uc);
+    Monitor *mon = MONITOR(hmon);
     UserCreatableClass *ucc_parent =
         USER_CREATABLE_CLASS(
             object_class_get_parent(
@@ -1640,7 +1648,7 @@ static void monitor_hmp_complete(UserCreatable *uc, Error **errp)
         return;
     }
 
-    if (hmon->parent_obj.chardev_id) {
+    if (mon->chardev_id) {
         if (hmon->use_readline) {
             hmon->rs = readline_init(monitor_readline_printf,
                                     monitor_readline_flush,
@@ -1649,12 +1657,12 @@ static void monitor_hmp_complete(UserCreatable *uc, Error **errp)
             monitor_read_command(hmon, 0);
         }
 
-        qemu_chr_fe_set_handlers(&hmon->parent_obj.chr,
+        qemu_chr_fe_set_handlers(&mon->chr,
                                  monitor_can_read,
                                  monitor_read,
                                  monitor_event, NULL,
-                                 &hmon->parent_obj, NULL, true);
-        monitor_list_append(&hmon->parent_obj);
+                                 mon, NULL, true);
+        monitor_list_append(mon);
     }
 }
 
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 4ca87857c3f..48a2231b439 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -167,9 +167,10 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
 {
     char *output = NULL;
     MonitorHMP *hmon = MONITOR_HMP(object_new(TYPE_MONITOR_HMP));
+    Monitor *mon = MONITOR(hmon);
 
     if (has_cpu_index) {
-        int ret = monitor_set_cpu(&hmon->parent_obj, cpu_index);
+        int ret = monitor_set_cpu(mon, cpu_index);
         if (ret < 0) {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
                        "a CPU number");
@@ -179,8 +180,8 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
 
     handle_hmp_command(hmon, command_line);
 
-    WITH_QEMU_LOCK_GUARD(&hmon->parent_obj.mon_lock) {
-        output = g_strdup(hmon->parent_obj.outbuf->str);
+    WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
+        output = g_strdup(mon->outbuf->str);
     }
 
 out:
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 22/23] monitor: Replace container_of(MonitorHMP, parent_obj) -> MONITOR_HMP()
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (20 preceding siblings ...)
  2026-08-12 21:17 ` [PATCH v3 21/23] monitor: Use QOM MONITOR() macro to access MonitorHMP->parent_obj Philippe Mathieu-Daudé
@ 2026-08-12 21:17 ` Philippe Mathieu-Daudé
  2026-08-12 21:17 ` [PATCH v3 23/23] monitor/hmp: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

By replacing the container_of(MonitorHMP) use in ui/ui-hmp-cmds.c
we can remove its incorrect inclusion of "monitor/monitor-internal.h"
header, using the public "monitor/monitor.h" instead.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 monitor/hmp-cmds.c | 2 +-
 monitor/hmp.c      | 2 +-
 ui/ui-hmp-cmds.c   | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 71d7df6d013..19d71708394 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -290,7 +290,7 @@ void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
 
 void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
-    MonitorHMP *hmon = container_of(mon, MonitorHMP, parent_obj);
+    MonitorHMP *hmon = MONITOR_HMP(mon);
     int i;
     const char *str;
 
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 428ef014284..4eadf7c2e7d 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1523,7 +1523,7 @@ cleanup:
 static void monitor_read(void *opaque, const uint8_t *buf, int size)
 {
     Monitor *mon = opaque;
-    MonitorHMP *hmon = container_of(mon, MonitorHMP, parent_obj);
+    MonitorHMP *hmon = MONITOR_HMP(mon);
     int i;
 
     if (hmon->rs) {
diff --git a/ui/ui-hmp-cmds.c b/ui/ui-hmp-cmds.c
index fb13eca0b0c..eca3a82003f 100644
--- a/ui/ui-hmp-cmds.c
+++ b/ui/ui-hmp-cmds.c
@@ -19,7 +19,7 @@
 #endif
 #include "monitor/hmp.h"
 #include "monitor/hmp-completion.h"
-#include "monitor/monitor-internal.h"
+#include "monitor/monitor.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qobject/qdict.h"
@@ -343,7 +343,7 @@ void hmp_change_vnc(Monitor *mon, const char *device, const char *target,
         return;
     }
     if (!arg) {
-        MonitorHMP *hmon = container_of(mon, MonitorHMP, parent_obj);
+        MonitorHMP *hmon = MONITOR_HMP(mon);
         monitor_read_password(hmon, hmp_change_read_arg, NULL);
     } else {
         qmp_change_vnc_password(arg, errp);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 23/23] monitor/hmp: Remove unnecessary 'monitor/monitor.h' header
  2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
                   ` (21 preceding siblings ...)
  2026-08-12 21:17 ` [PATCH v3 22/23] monitor: Replace container_of(MonitorHMP, parent_obj) -> MONITOR_HMP() Philippe Mathieu-Daudé
@ 2026-08-12 21:17 ` Philippe Mathieu-Daudé
  22 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-12 21:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Philippe Mathieu-Daudé

Nothing here requires declarations from "monitor/monitor.h".

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 include/monitor/hmp.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index 9258a049bff..9be7fe28988 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -16,7 +16,6 @@
 
 #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) \
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 02/23] net/vhost-vdpa: Include missing 'qemu/iov.h' header
  2026-08-12 21:16 ` [PATCH v3 02/23] net/vhost-vdpa: Include missing 'qemu/iov.h' header Philippe Mathieu-Daudé
@ 2026-08-12 21:28   ` Michael S. Tsirkin
  0 siblings, 0 replies; 26+ messages in thread
From: Michael S. Tsirkin @ 2026-08-12 21:28 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Dr. David Alan Gilbert, Markus Armbruster,
	Marc-André Lureau, Richard Henderson, Stefano Garzarella,
	Jason Wang

On Wed, Aug 12, 2026 at 11:16:46PM +0200, Philippe Mathieu-Daudé wrote:
> vhost-vdpa.c uses methods declared in the "qemu/iov." header.
> Include it otherwise we get when refactoring unrelated headers:
> 
>   ../net/vhost-vdpa.c: In function ‘vhost_vdpa_net_load_cmd’:
>   ../net/vhost-vdpa.c:714:24: error: implicit declaration of function ‘iov_size’
>     714 |     size_t data_size = iov_size(data_sg, data_num), cmd_size;
>         |                        ^~~~~~~~
>   ../net/vhost-vdpa.c:714:24: error: nested extern declaration of ‘iov_size’
>   ../net/vhost-vdpa.c:742:5: error: implicit declaration of function ‘iov_from_buf’
>     742 |     iov_from_buf(out_cursor, 1, 0, &ctrl, sizeof(ctrl));
>         |     ^~~~~~~~~~~~
>   ../net/vhost-vdpa.c:742:5: error: nested extern declaration of ‘iov_from_buf’
>   ../net/vhost-vdpa.c:744:5: error: implicit declaration of function ‘iov_to_buf’
>     744 |     iov_to_buf(data_sg, data_num, 0,
>         |     ^~~~~~~~~~
>   ../net/vhost-vdpa.c:744:5: error: nested extern declaration of ‘iov_to_buf’
>   ../net/vhost-vdpa.c:748:5: error: implicit declaration of function ‘iov_copy’
>     748 |     iov_copy(&out, 1, out_cursor, 1, 0, cmd_size);
>         |     ^~~~~~~~
> 
> Fixes: bd907ae4b00 ("vdpa: manual forward CVQ buffers")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>


> ---
>  net/vhost-vdpa.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index c526c2b2dc0..1052361a4ab 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -17,6 +17,7 @@
>  #include "hw/virtio/vhost-vdpa.h"
>  #include "qemu/config-file.h"
>  #include "qemu/error-report.h"
> +#include "qemu/iov.h"
>  #include "qemu/log.h"
>  #include "qemu/memalign.h"
>  #include "qemu/option.h"
> -- 
> 2.53.0



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 06/23] migration/hmp-cmds: Include 'block/block-global-state.h' header
  2026-08-12 21:16 ` [PATCH v3 06/23] migration/hmp-cmds: Include 'block/block-global-state.h' header Philippe Mathieu-Daudé
@ 2026-08-12 23:26   ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 26+ messages in thread
From: Dr. David Alan Gilbert @ 2026-08-12 23:26 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Markus Armbruster, Marc-André Lureau,
	Richard Henderson, Peter Xu, Fabiano Rosas

* Philippe Mathieu-Daudé (philmd@oss.qualcomm.com) wrote:
> migration-hmp-cmds.c uses types / methods declared in
> "block/block-global-state.h".  Include the latter otherwise
> we get when refactoring unrelated headers:
> 
>   ../migration/migration-hmp-cmds.c:911:5: error: use of undeclared identifier 'BdrvNextIterator'
>     911 |     BdrvNextIterator it;
>         |     ^
>   ../migration/migration-hmp-cmds.c:918:15: error: call to undeclared function 'bdrv_first'
>     918 |     for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
>         |               ^
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>

> ---
>  migration/migration-hmp-cmds.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c
> index b04fc4489f4..351512942af 100644
> --- a/migration/migration-hmp-cmds.c
> +++ b/migration/migration-hmp-cmds.c
> @@ -15,6 +15,7 @@
>  
>  #include "qemu/osdep.h"
>  #include "block/qapi.h"
> +#include "block/block-global-state.h"
>  #include "migration/snapshot.h"
>  #include "monitor/hmp.h"
>  #include "monitor/hmp-completion.h"
> -- 
> 2.53.0
> 
-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2026-08-12 23:27 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-12 21:16 [PATCH v3 00/23] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 01/23] hexagon: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 02/23] net/vhost-vdpa: Include missing 'qemu/iov.h' header Philippe Mathieu-Daudé
2026-08-12 21:28   ` Michael S. Tsirkin
2026-08-12 21:16 ` [PATCH v3 03/23] tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 04/23] qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h' Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 05/23] qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 06/23] migration/hmp-cmds: Include 'block/block-global-state.h' header Philippe Mathieu-Daudé
2026-08-12 23:26   ` Dr. David Alan Gilbert
2026-08-12 21:16 ` [PATCH v3 07/23] monitor: Include missing 'qemu/aio-wait.h' header Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 08/23] monitor: Include missing 'qemu/lockable.h' header Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 09/23] monitor: Include missing 'qemu/coroutine-core.h' header Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 10/23] monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 11/23] monitor: Remove unnecessary 'block/block.h' header Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 12/23] system: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 13/23] system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 14/23] system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c Philippe Mathieu-Daudé
2026-08-12 21:16 ` [PATCH v3 15/23] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c Philippe Mathieu-Daudé
2026-08-12 21:17 ` [PATCH v3 16/23] system: Move runstate-related code from cpus.c to runstate.c Philippe Mathieu-Daudé
2026-08-12 21:17 ` [PATCH v3 17/23] monitor: Rename MonitorQMP @mon -> @qmon Philippe Mathieu-Daudé
2026-08-12 21:17 ` [PATCH v3 18/23] monitor: Rename MonitorHMP @mon -> @hmon Philippe Mathieu-Daudé
2026-08-12 21:17 ` [PATCH v3 19/23] monitor: Better express monitor_read()'s opaque arg is of Monitor type Philippe Mathieu-Daudé
2026-08-12 21:17 ` [PATCH v3 20/23] monitor: Use QOM MONITOR() macro to access MonitorQMP->parent_obj Philippe Mathieu-Daudé
2026-08-12 21:17 ` [PATCH v3 21/23] monitor: Use QOM MONITOR() macro to access MonitorHMP->parent_obj Philippe Mathieu-Daudé
2026-08-12 21:17 ` [PATCH v3 22/23] monitor: Replace container_of(MonitorHMP, parent_obj) -> MONITOR_HMP() Philippe Mathieu-Daudé
2026-08-12 21:17 ` [PATCH v3 23/23] monitor/hmp: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.