All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>, qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Dr. David Alan Gilbert" <dave@treblig.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>
Subject: [PATCH v2 15/16] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c
Date: Wed, 12 Aug 2026 15:11:46 +0200	[thread overview]
Message-ID: <20260812131147.83188-16-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20260812131147.83188-1-philmd@oss.qualcomm.com>

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

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



  parent reply	other threads:[~2026-08-12 13:40 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 13:11 [PATCH v2 00/16] monitor: Reduce headers included in 'monitor/monitor.h' Philippe Mathieu-Daudé
2026-08-12 13:11 ` [PATCH v2 01/16] hexagon: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 02/16] tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 03/16] qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h' Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 04/16] qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 05/16] migration/hmp-cmds: Include 'block/block-global-state.h' header Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 06/16] monitor: Include missing 'qemu/aio-wait.h' header Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 07/16] monitor: Include missing 'qemu/lockable.h' header Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 08/16] monitor: Include missing 'qemu/coroutine-core.h' header Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 09/16] monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 10/16] monitor: Remove unnecessary 'block/block.h' header Philippe Mathieu-Daudé
2026-08-12 14:00   ` Marc-André Lureau
2026-08-12 16:05     ` Philippe Mathieu-Daudé
2026-08-12 13:11 ` [PATCH v2 11/16] monitor/hmp: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 12/16] system: " Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 13/16] system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 14/16] system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau
2026-08-12 13:11 ` Philippe Mathieu-Daudé [this message]
2026-08-12 14:05   ` [PATCH v2 15/16] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c marcandre.lureau
2026-08-12 13:11 ` [PATCH v2 16/16] system: Move runstate-related code from cpus.c to runstate.c Philippe Mathieu-Daudé
2026-08-12 14:05   ` marcandre.lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260812131147.83188-16-philmd@oss.qualcomm.com \
    --to=philmd@oss.qualcomm.com \
    --cc=armbru@redhat.com \
    --cc=dave@treblig.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@mailo.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.