Skip to contentSkip to conversation

monitor: Reduce headers included in 'monitor/monitor.h'

PATCH Superseded Philippe Mathieu-Daudé 2 participants 34 messages Aug 12

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover monitor: Reduce headers included in 'monitor/monitor.h'

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

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

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.

[1] I expect his work to trivially rebase ;)
[2] [email protected]
Based-on: <[email protected]>

Philippe Mathieu-Daudé (16):
hexagon: Remove unnecessary 'monitor/monitor.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 monitor/hmp: Remove unnecessary 'monitor/monitor.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

 include/hw/hexagon/hexagon_tlb.h |   2 +-
 include/monitor/hmp.h            |   1 -
 include/monitor/monitor.h        |   3 +-
 include/qapi/qmp-registry.h      |   1 -
 monitor/monitor-internal.h       |   1 +
 target/hexagon/hex_mmu.h         |   3 +-
 hw/core/machine-qmp-cmds.c       |   6 +
 migration/migration-hmp-cmds.c   |   1 +
 monitor/fds.c                    |   1 +
 monitor/monitor.c                |   2 +
 monitor/qmp.c                    |   3 +-
 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 +
 system/meson.build               |   2 +
 21 files changed, 357 insertions(+), 317 deletions(-)
 create mode 100644 system/dirtylimit-hmp-cmds.c
 create mode 100644 system/physmem-qmp-cmds.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/16 hexagon: Remove unnecessary 'monitor/monitor.h' header

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);
---
 include/hw/hexagon/hexagon_tlb.h | 2 +-
 target/hexagon/hex_mmu.h         | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
include/hw/hexagon/hexagon_tlb.h +1 -1
index 90d9ed84043..760dc1ea811 100644
@@ -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)
 
target/hexagon/hex_mmu.h +2 -1
index 4f556c715a9..6aa450b9413 100644
@@ -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);
Signature · 1 line
2.53.0
Reviewed-by on v2 1/16
#2 lore raw

Re: [PATCH v2 01/16] hexagon: Remove unnecessary 'monitor/monitor.h' header

Quoted 9 lines · Philippe Mathieu-Daudé

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:

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#3 lore raw

PATCH v2 2/16 tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c

In reply to 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);
      |     ^
---
 tests/unit/test-util-sockets.c | 1 +
 1 file changed, 1 insertion(+)
tests/unit/test-util-sockets.c +1 -0
index ee66d727c38..ab3f39c3efb 100644
@@ -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"
Signature · 1 line
2.53.0
Reviewed-by on v2 2/16
#4 lore raw

Re: [PATCH v2 02/16] tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c

Quoted 9 lines · 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);
      |     ^

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#5 lore raw

PATCH v2 3/16 qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h'

In reply to Philippe Mathieu-Daudé

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();
        |     ^
---
 qapi/qmp-dispatch.c | 2 ++
 1 file changed, 2 insertions(+)
qapi/qmp-dispatch.c +2 -0
index e3897d51977..965cad64998 100644
@@ -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)
 {
Signature · 1 line
2.53.0
Reviewed-by on v2 3/16
#6 lore raw

Re: [PATCH v2 03/16] qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h'

Quoted 4 lines · Philippe Mathieu-Daudé

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:

Quoted 8 lines

../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();
        |     ^

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#7 lore raw

PATCH v2 4/16 qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header

In reply to Philippe Mathieu-Daudé
---
 include/qapi/qmp-registry.h | 1 -
 1 file changed, 1 deletion(-)
include/qapi/qmp-registry.h +0 -1
index e0ee1ad3ac6..6146306a3a1 100644
@@ -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 **);
Signature · 1 line
2.53.0
#9 lore raw

PATCH v2 5/16 migration/hmp-cmds: Include 'block/block-global-state.h' header

In reply to Philippe Mathieu-Daudé

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)) {
        |               ^
---
 migration/migration-hmp-cmds.c | 1 +
 1 file changed, 1 insertion(+)
migration/migration-hmp-cmds.c +1 -0
index b04fc4489f4..351512942af 100644
@@ -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"
Signature · 1 line
2.53.0
Reviewed-by on v2 5/16
#10 lore raw

Re: [PATCH v2 05/16] migration/hmp-cmds: Include 'block/block-global-state.h' header

Quoted 4 lines · Philippe Mathieu-Daudé

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

Quoted 8 lines

../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)) {
        |               ^

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#11 lore raw

PATCH v2 6/16 monitor: Include missing 'qemu/aio-wait.h' header

In reply to 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),
        |         ^
---
 monitor/monitor.c | 1 +
 monitor/qmp.c     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
monitor/monitor.c +1 -0
index ed195fd97bb..c75ae815343 100644
@@ -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"
monitor/qmp.c +1 -1
index 338d37cb7e5..6ae1098d39f 100644
@@ -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"
Signature · 1 line
2.53.0
Reviewed-by on v2 6/16
#12 lore raw

Re: [PATCH v2 06/16] monitor: Include missing 'qemu/aio-wait.h' header

Quoted 4 lines · 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:

Quoted 8 lines

../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),
        |         ^

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#13 lore raw

PATCH v2 7/16 monitor: Include missing 'qemu/lockable.h' header

In reply to 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) {
        |     ^
---
 monitor/fds.c     | 1 +
 monitor/monitor.c | 1 +
 monitor/qmp.c     | 1 +
 3 files changed, 3 insertions(+)
monitor/fds.c +1 -0
index cc35d2ec334..abe5f13487d 100644
@@ -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 */
monitor/monitor.c +1 -0
index c75ae815343..6af09f2f6ea 100644
@@ -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"
monitor/qmp.c +1 -0
index 6ae1098d39f..aec03157750 100644
@@ -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"
Signature · 1 line
2.53.0
Reviewed-by on v2 7/16
#14 lore raw

Re: [PATCH v2 07/16] monitor: Include missing 'qemu/lockable.h' header

Quoted 14 lines · 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) {
        |     ^
Quoted 1 line

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#15 lore raw

PATCH v2 8/16 monitor: Include missing 'qemu/coroutine-core.h' header

In reply to 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);
        |                          ^
---
 include/monitor/monitor.h | 1 +
 1 file changed, 1 insertion(+)
include/monitor/monitor.h +1 -0
index 890497b0d22..efdd2165aa9 100644
@@ -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"
Signature · 1 line
2.53.0
Reviewed-by on v2 8/16
#16 lore raw

Re: [PATCH v2 08/16] monitor: Include missing 'qemu/coroutine-core.h' header

Quoted 10 lines · 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);
        |                          ^

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#17 lore raw

PATCH v2 9/16 monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header

In reply to 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.

---
 include/monitor/monitor.h  | 1 -
 monitor/monitor-internal.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
include/monitor/monitor.h +0 -1
index efdd2165aa9..fa9f4a8a75a 100644
@@ -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"
monitor/monitor-internal.h +1 -0
index 23829f32f9a..bc0932c425a 100644
@@ -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"
Signature · 1 line
2.53.0
Reviewed-by on v2 9/16
#18 lore raw

Re: [PATCH v2 09/16] monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header

Quoted 7 lines · 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 /*

Quoted 7 lines
  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);
                                           ^^^^^^^^^

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#19 lore raw

PATCH v2 10/16 monitor: Remove unnecessary 'block/block.h' header

In reply to Philippe Mathieu-Daudé

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

---
 include/monitor/monitor.h | 1 -
 1 file changed, 1 deletion(-)
include/monitor/monitor.h +0 -1
index fa9f4a8a75a..fd98ee2c71d 100644
@@ -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"
Signature · 1 line
2.53.0
#20 lore raw

Re: [PATCH v2 10/16] monitor: Remove unnecessary 'block/block.h' header

Hi

Quoted 4 lines · Philippe Mathieu-Daudé

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

breaks for me:
[38/286] Compiling C object libsystem.a.p/net_vhost-vdpa.c.o
FAILED: [code=1] libsystem.a.p/net_vhost-vdpa.c.o
cc -m64 -Ilibsystem.a.p -I. -I.. -Isubprojects/libvduse -I../subprojects/libvduse -Iui -Iqapi -Itrace -Iui/shader -I/usr/include/p11-kit-1 -I/usr/include/libpng16 -I/usr/include/pixman-1 -I/usr/include/spice-1 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -I/usr/include/spice-server -I/usr/include/opus -I/usr/include/cacard -I/usr/include/nss3 -I/usr/include/nspr4 -I/usr/include/PCSC -I/usr/include/gstreamer-1.0 -I/usr/include/libdrm -I/usr/include/orc-0.4 -I/usr/include/slirp -I/usr/local/include -I/usr/include/libusb-1.0 -I/usr/include/SDL2 -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/cloudproviders -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glycin-2 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/atk-1.0 -I/usr/lib64/pkgconfig/../../include/dbus-1.0 -I/usr/lib64/pkgconfig/../../lib64/dbus-1.0/include -I/usr/include/fribidi -I/usr/include/libxml2 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/vte-2.91 -I/usr/include/rav1e -I/usr/include/svt-av1 -I/usr/include/libvmaf -I/usr/include/webp -I/usr/include/virgl -I/usr/include/fuse3 -I/usr/include/pipewire-0.3 -I/usr/include/spa-0.2 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -mcx16 -msse2 -fno-link-libatomic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fzero-call-used-regs=used-gpr -fsanitize=address -fstack-protector-strong -fno-omit-frame-pointer -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-overflow=2 -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough=2 -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow=local -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem /home/elmarco/src/qemu.nmi/linux-headers -isystem linux-headers -iquote . -iquote /home/elmarco/src/qemu.nmi -iquote /home/elmarco/src/qemu.nmi/include -iquote /home/elmarco/src/qemu.nmi/host/include/x86_64 -iquote /home/elmarco/src/qemu.nmi/host/include/generic -iquote /home/elmarco/src/qemu.nmi/tcg/x86_64 -pthread -fPIE -fno-strict-aliasing -fno-strict-overflow -DHWY_SHARED_DEFINE -DAVIF_DLL -DEB_DLL -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DNCURSES_WIDECHAR=1 -D_GNU_SOURCE=1 -D_REENTRANT -DSTRUCT_IOVEC_DEFINED -DWITH_GZFILEOP -DCONFIG_SOFTMMU -DCOMPILING_SYSTEM_VS_USER -MD -MQ libsystem.a.p/net_vhost-vdpa.c.o -MF libsystem.a.p/net_vhost-vdpa.c.o.d -o libsystem.a.p/net_vhost-vdpa.c.o -c ../net/vhost-vdpa.c ../net/vhost-vdpa.c: In function ‘vhost_vdpa_net_load_cmd’:
../net/vhost-vdpa.c:714:24: error: implicit declaration of function ‘iov_size’ [-Wimplicit-function-declaration]

  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’ [-Werror=nested-externs] ../net/vhost-vdpa.c:742:5: error: implicit declaration of function ‘iov_from_buf’ [-Wimplicit-function-declaration]

  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’ [-Werror=nested-externs] ../net/vhost-vdpa.c:744:5: error: implicit declaration of function ‘iov_to_buf’ [-Wimplicit-function-declaration]

  744 |     iov_to_buf(data_sg, data_num, 0,
      |     ^~~~~~~~~~

../net/vhost-vdpa.c:744:5: error: nested extern declaration of ‘iov_to_buf’ [-Werror=nested-externs] ../net/vhost-vdpa.c:748:5: error: implicit declaration of function ‘iov_copy’; did you mean ‘error_copy’? [-Wimplicit-function-declaration]

  748 |     iov_copy(&out, 1, out_cursor, 1, 0, cmd_size);
      |     ^~~~~~~~
      |     error_copy

../net/vhost-vdpa.c:748:5: error: nested extern declaration of ‘iov_copy’ [-Werror=nested-externs] ../net/vhost-vdpa.c:760:5: error: implicit declaration of function ‘iov_discard_front’ [-Wimplicit-function-declaration]

  760 |     iov_discard_front(&out_cursor, &dummy_cursor_iov_cnt, cmd_size);
      |     ^~~~~~~~~~~~~~~~~

../net/vhost-vdpa.c:760:5: error: nested extern declaration of ‘iov_discard_front’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
[55/286] Compiling C object libsystem.a.p/system_physmem.c.o
ninja: build stopped: subcommand failed.

Quoted 20 lines
---
 include/monitor/monitor.h | 1 -
 1 file changed, 1 deletion(-)
include/monitor/monitor.h +0 -2
index fa9f4a8a75a..fd98ee2c71d 100644
@@ -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

#21 lore raw

Re: [PATCH v2 10/16] monitor: Remove unnecessary 'block/block.h' header

Quoted 88 lines · Marc-André Lureau

Hi

Quoted 4 lines · Philippe Mathieu-Daudé

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

breaks for me:
[38/286] Compiling C object libsystem.a.p/net_vhost-vdpa.c.o
FAILED: [code=1] libsystem.a.p/net_vhost-vdpa.c.o cc -m64 -Ilibsystem.a.p -I. -I.. -Isubprojects/libvduse

(quoted diff) +0 -34
-I../subprojects/libvduse -Iui -Iqapi -Itrace -Iui/shader
-I/usr/include/p11-kit-1 -I/usr/include/libpng16
-I/usr/include/pixman-1 -I/usr/include/spice-1 -I/usr/include/glib-2.0
-I/usr/lib64/glib-2.0/include -I/usr/include/libmount
-I/usr/include/blkid -I/usr/include/sysprof-6
-I/usr/include/gio-unix-2.0 -I/usr/include/spice-server
-I/usr/include/opus -I/usr/include/cacard -I/usr/include/nss3
-I/usr/include/nspr4 -I/usr/include/PCSC -I/usr/include/gstreamer-1.0
-I/usr/include/libdrm -I/usr/include/orc-0.4 -I/usr/include/slirp
-I/usr/local/include -I/usr/include/libusb-1.0 -I/usr/include/SDL2
-I/usr/include/gtk-3.0 -I/usr/include/pango-1.0
-I/usr/include/cloudproviders -I/usr/include/cairo
-I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glycin-2
-I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0
-I/usr/include/atk-1.0 -I/usr/lib64/pkgconfig/../../include/dbus-1.0
-I/usr/lib64/pkgconfig/../../lib64/dbus-1.0/include
-I/usr/include/fribidi -I/usr/include/libxml2 -I/usr/include/harfbuzz
-I/usr/include/freetype2 -I/usr/include/vte-2.91 -I/usr/include/rav1e
-I/usr/include/svt-av1 -I/usr/include/libvmaf -I/usr/include/webp
-I/usr/include/virgl -I/usr/include/fuse3 -I/usr/include/pipewire-0.3
-I/usr/include/spa-0.2 -fdiagnostics-color=auto -Wall -Winvalid-pch
-Werror -std=gnu11 -O2 -g -mcx16 -msse2 -fno-link-libatomic
-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
-fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero
-fzero-init-padding-bits=all -fzero-call-used-regs=used-gpr
-fsanitize=address -fstack-protector-strong -fno-omit-frame-pointer
-Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-overflow=2
-Wformat-security -Wformat-y2k -Wignored-qualifiers
-Wimplicit-fallthrough=2 -Winit-self -Wmissing-format-attribute
-Wmissing-prototypes -Wnested-externs -Wold-style-declaration
-Wold-style-definition -Wredundant-decls -Wshadow=local
-Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings
-Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value
-isystem /home/elmarco/src/qemu.nmi/linux-headers -isystem

linux-headers -iquote . -iquote /home/elmarco/src/qemu.nmi -iquote /home/elmarco/src/qemu.nmi/include -iquote /home/elmarco/src/qemu.nmi/host/include/x86_64 -iquote /home/elmarco/src/qemu.nmi/host/include/generic -iquote /home/elmarco/src/qemu.nmi/tcg/x86_64 -pthread -fPIE

(quoted diff) +0 -6
-fno-strict-aliasing -fno-strict-overflow -DHWY_SHARED_DEFINE
-DAVIF_DLL -DEB_DLL -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600
-DNCURSES_WIDECHAR=1 -D_GNU_SOURCE=1 -D_REENTRANT
-DSTRUCT_IOVEC_DEFINED -DWITH_GZFILEOP -DCONFIG_SOFTMMU
-DCOMPILING_SYSTEM_VS_USER -MD -MQ libsystem.a.p/net_vhost-vdpa.c.o
-MF libsystem.a.p/net_vhost-vdpa.c.o.d -o

libsystem.a.p/net_vhost-vdpa.c.o -c ../net/vhost-vdpa.c ../net/vhost-vdpa.c: In function ‘vhost_vdpa_net_load_cmd’:
../net/vhost-vdpa.c:714:24: error: implicit declaration of function ‘iov_size’ [-Wimplicit-function-declaration]

   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’ [-Werror=nested-externs] ../net/vhost-vdpa.c:742:5: error: implicit declaration of function ‘iov_from_buf’ [-Wimplicit-function-declaration]

   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’ [-Werror=nested-externs] ../net/vhost-vdpa.c:744:5: error: implicit declaration of function ‘iov_to_buf’ [-Wimplicit-function-declaration]

   744 |     iov_to_buf(data_sg, data_num, 0,
       |     ^~~~~~~~~~

../net/vhost-vdpa.c:744:5: error: nested extern declaration of ‘iov_to_buf’ [-Werror=nested-externs] ../net/vhost-vdpa.c:748:5: error: implicit declaration of function ‘iov_copy’; did you mean ‘error_copy’? [-Wimplicit-function-declaration]

   748 |     iov_copy(&out, 1, out_cursor, 1, 0, cmd_size);
       |     ^~~~~~~~
       |     error_copy

../net/vhost-vdpa.c:748:5: error: nested extern declaration of ‘iov_copy’ [-Werror=nested-externs] ../net/vhost-vdpa.c:760:5: error: implicit declaration of function ‘iov_discard_front’ [-Wimplicit-function-declaration]

Quoted 7 lines
   760 |     iov_discard_front(&out_cursor, &dummy_cursor_iov_cnt, cmd_size);
       |     ^~~~~~~~~~~~~~~~~

../net/vhost-vdpa.c:760:5: error: nested extern declaration of ‘iov_discard_front’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
[55/286] Compiling C object libsystem.a.p/system_physmem.c.o
ninja: build stopped: subcommand failed.

TIL monitor_fd_param().

Anyway thanks, consider the following as "PATCH 9.5/16":
-- >8 --

Author: Philippe Mathieu-Daudé <[email protected]>
Date:   Wed Aug 12 18:03:10 2026 +0200

net/vhost-vdpa: Include missing 'qemu/iov.h' header

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);
            |     ^~~~~~~~
net/vhost-vdpa.c +1 -0
index c526c2b2dc..1052361a4a 100644
@@ -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"

---

#22 lore raw

PATCH v2 11/16 monitor/hmp: Remove unnecessary 'monitor/monitor.h' header

In reply to Philippe Mathieu-Daudé

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

---
 include/monitor/hmp.h | 1 -
 1 file changed, 1 deletion(-)
include/monitor/hmp.h +0 -1
index 9258a049bff..9be7fe28988 100644
@@ -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) \
Signature · 1 line
2.53.0
#23 lore raw

Re: [PATCH v2 11/16] monitor/hmp: Remove unnecessary 'monitor/monitor.h' header

Quoted 1 line

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

I think it's appropriate for monitor/hmp.h to include monitor/monitor.h. Some of my disable-hmp patches may depend on that. But in the meantime, I am okay dropping it.

Signature · 1 line
Marc-André Lureau <[email protected]>
#24 lore raw

PATCH v2 12/16 system: Remove unnecessary 'monitor/monitor.h' header

In reply to Philippe Mathieu-Daudé

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

---
 system/device_tree.c | 1 -
 system/physmem.c     | 2 --
 2 files changed, 3 deletions(-)
system/device_tree.c +0 -1
index 1ea19629841..48365435ea0 100644
@@ -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>
 
system/physmem.c +0 -2
index c21ea929153..21614e1c4d0 100644
@@ -84,8 +84,6 @@
 #include "qemu/mmap-alloc.h"
 #endif
 
-#include "monitor/monitor.h"
-
 #ifdef CONFIG_LIBDAXCTL
 #include <daxctl/libdaxctl.h>
 #endif
Signature · 1 line
2.53.0
#26 lore raw

PATCH v2 13/16 system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c

In reply to Philippe Mathieu-Daudé
---
 system/dirtylimit-hmp-cmds.c | 74 ++++++++++++++++++++++++++++++++++++
 system/dirtylimit.c          | 60 -----------------------------
 system/meson.build           |  1 +
 3 files changed, 75 insertions(+), 60 deletions(-)
 create mode 100644 system/dirtylimit-hmp-cmds.c
system/dirtylimit-hmp-cmds.c new file +74 -0
new file mode 100644
index 00000000000..4928d57cc8e
@@ -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);
+    }
+}
system/dirtylimit.c +0 -60

81 lines not on this page · raw message

system/meson.build +1 -0
index cd3193d170b..377adce8035 100644
@@ -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',
Signature · 1 line
2.53.0
#28 lore raw

PATCH v2 14/16 system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c

In reply to Philippe Mathieu-Daudé

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.

---
 hw/core/machine-qmp-cmds.c | 6 ++++++
 system/cpus.c              | 8 --------
 2 files changed, 6 insertions(+), 8 deletions(-)
hw/core/machine-qmp-cmds.c +6 -0
index e62cb4ec888..1aa5f262298 100644
@@ -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);
+}
system/cpus.c +0 -8
index 9758cda4636..aa2510bf8fc 100644
@@ -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);
-}
-
Signature · 1 line
2.53.0
Reviewed-by on v2 14/16
#29 lore raw

Re: [PATCH v2 14/16] system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c

Quoted 3 lines · Philippe Mathieu-Daudé

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.

Signature · 1 line
Marc-André Lureau <[email protected]>
#30 lore raw

PATCH v2 15/16 system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c

In reply to Philippe Mathieu-Daudé

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)
[...]

---
 system/cpus.c             |  92 --------------------------------
 system/physmem-qmp-cmds.c | 107 ++++++++++++++++++++++++++++++++++++++
 system/meson.build        |   1 +
 3 files changed, 108 insertions(+), 92 deletions(-)
 create mode 100644 system/physmem-qmp-cmds.c
system/cpus.c +0 -92
index aa2510bf8fc..43ff10cf008 100644
@@ -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);
-}
system/physmem-qmp-cmds.c new file +107 -0

107 lines not on this page · raw message

system/meson.build +1 -0
index 377adce8035..64e06e7abcc 100644
@@ -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',
Signature · 1 line
2.53.0
Reviewed-by on v2 15/16
#31 lore raw

Re: [PATCH v2 15/16] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c

Quoted 10 lines · Philippe Mathieu-Daudé

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)
[...]

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#32 lore raw

PATCH v2 16/16 system: Move runstate-related code from cpus.c to runstate.c

In reply to 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 */

---
 system/cpus.c     | 147 -------------------------------------------
 system/runstate.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+), 147 deletions(-)
system/cpus.c +0 -147
index 43ff10cf008..f37e215c586 100644
@@ -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;
-    }
-}
system/runstate.c +154 -0

166 lines not on this page · raw message

Signature · 1 line
2.53.0
Reviewed-by on v2 16/16
#33 lore raw

Re: [PATCH v2 16/16] system: Move runstate-related code from cpus.c to runstate.c

Quoted 5 lines · 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:

Quoted 7 lines

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 */

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>