All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Ruderich <simon@ruderich.org>
To: qemu-devel@nongnu.org
Cc: David Alan Gilbert <dgilbert@redhat.com>,
	Peter Crosthwaite <crosthwaitepeter@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Markus Armbruster <armbru@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Simon Ruderich <simon@ruderich.org>
Subject: [Qemu-devel] [PATCH v7 6/7] qmp: add pmemload command
Date: Thu, 15 Nov 2018 14:22:39 +0100	[thread overview]
Message-ID: <4e25c4e14e76cee9a1b0d062f2623426e2a0e0bb.1542287931.git.simon@ruderich.org> (raw)
In-Reply-To: <cover.1542287931.git.simon@ruderich.org>

Adapted patch from Baojun Wang [1] with the following commit message:

    I found this could be useful to have qemu-softmmu as a cross
    debugger (launch with -s -S command line option), then if we can
    have a command to load guest physical memory, we can use cross gdb
    to do some target debug which gdb cannot do directly.

This patch contains only the qmp changes of the original patch.

pmemload is necessary to directly write physical memory which is not
possible with gdb alone as it uses only logical addresses.

The QAPI for pmemload uses "val" as parameter name for the physical
address. This name is not very descriptive but is consistent with the
existing pmemsave. Changing the parameter name of pmemsave is not
possible without breaking the existing API.

[1]: https://lists.gnu.org/archive/html/qemu-trivial/2014-04/msg00074.html

Based-on-patch-by: Baojun Wang <wangbj@gmail.com>
Signed-off-by: Simon Ruderich <simon@ruderich.org>
---
 cpus.c         | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 qapi/misc.json | 20 ++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/cpus.c b/cpus.c
index ee54595733..a12076dc68 100644
--- a/cpus.c
+++ b/cpus.c
@@ -2445,6 +2445,57 @@ exit:
     qemu_close(fd);
 }
 
+void qmp_pmemload(int64_t addr, const char *filename,
+                  bool has_size, int64_t size,
+                  bool has_offset, int64_t offset,
+                  Error **errp)
+{
+    int fd;
+    size_t l;
+    ssize_t r;
+    uint8_t buf[1024];
+
+    fd = qemu_open(filename, O_RDONLY | O_BINARY);
+    if (fd < 0) {
+        error_setg_file_open(errp, errno, filename);
+        return;
+    }
+    if (has_offset && offset > 0) {
+        if (lseek(fd, offset, SEEK_SET) != offset) {
+            error_setg_errno(errp, errno,
+                             "could not seek to offset %" PRIx64, offset);
+            goto exit;
+        }
+    }
+    if (!has_size) {
+        struct stat s;
+        if (fstat(fd, &s)) {
+            error_setg_errno(errp, errno, "could not fstat fd to get size");
+            goto exit;
+        }
+        size = s.st_size;
+    }
+
+    while (size != 0) {
+        l = sizeof(buf);
+        if (l > size) {
+            l = size;
+        }
+        r = read(fd, buf, l);
+        if (r <= 0) {
+            error_setg(errp, QERR_IO_ERROR);
+            goto exit;
+        }
+        l = r; /* in case of short read */
+        cpu_physical_memory_write(addr, buf, l);
+        addr += l;
+        size -= l;
+    }
+
+exit:
+    qemu_close(fd);
+}
+
 void qmp_inject_nmi(Error **errp)
 {
     nmi_monitor_handle(monitor_get_cpu_index(), errp);
diff --git a/qapi/misc.json b/qapi/misc.json
index 6c1c5c0a37..6eb9d29339 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -1186,6 +1186,26 @@
 { 'command': 'pmemsave',
   'data': {'val': 'int', 'size': 'int', 'filename': 'str'} }
 
+##
+# @pmemload:
+#
+# Load a portion of guest physical memory from a file.
+#
+# @val: the physical address of the guest to start from
+#
+# @filename: the file to load the memory from as binary data
+#
+# @size: the size of memory region to load (defaults to whole file)
+#
+# @offset: the offset in the file to start from (defaults to 0)
+#
+# Returns: Nothing on success
+#
+# Since: 3.1
+##
+{ 'command': 'pmemload',
+  'data': {'val': 'int', 'filename': 'str', '*size': 'int', '*offset': 'int'} }
+
 ##
 # @cont:
 #
-- 
2.19.1

  parent reply	other threads:[~2018-11-15 13:22 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-10 21:24 [Qemu-devel] [PATCH] qmp: add pmemload command Simon Ruderich
2018-04-10 21:27 ` no-reply
2018-04-10 21:33 ` Eric Blake
2018-04-11  7:36   ` Simon Ruderich
2018-04-11 13:02     ` Eric Blake
2018-04-12 12:48       ` Simon Ruderich
2018-04-12 12:50         ` [Qemu-devel] [PATCH v2 1/5] cpus: correct coding style in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-04-12 12:50           ` [Qemu-devel] [PATCH v2 2/5] cpus: convert qmp_memsave/qmp_pmemsave to use qemu_open Simon Ruderich
2018-04-17 20:58             ` Eric Blake
2018-04-12 12:50           ` [Qemu-devel] [PATCH v2 3/5] cpus: use size_t in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-04-17 20:58             ` Eric Blake
2018-04-12 12:50           ` [Qemu-devel] [PATCH v2 4/5] hmp: don't truncate size in hmp_memsave/hmp_pmemsave Simon Ruderich
2018-04-17 20:59             ` Eric Blake
2018-04-12 12:50           ` [Qemu-devel] [PATCH v2 5/5] qmp: add pmemload command Simon Ruderich
2018-04-17 21:18             ` Eric Blake
2018-04-22  9:47               ` Simon Ruderich
2018-04-23 19:46                 ` Eric Blake
2018-04-24 14:50                   ` Simon Ruderich
2018-04-17 20:56           ` [Qemu-devel] [PATCH v2 1/5] cpus: correct coding style in qmp_memsave/qmp_pmemsave Eric Blake
2018-04-22  9:19             ` Simon Ruderich
2018-05-21 15:36 ` [Qemu-devel] [PATCH v3 0/5] qmp: add pmemload command Simon Ruderich
2018-05-21 15:36   ` [Qemu-devel] [PATCH v3 1/5] cpus: correct coding style in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-05-21 15:36   ` [Qemu-devel] [PATCH v3 2/5] cpus: convert qmp_memsave/qmp_pmemsave to use qemu_open Simon Ruderich
2018-05-21 15:36   ` [Qemu-devel] [PATCH v3 3/5] cpus: use size_t in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-05-21 15:36   ` [Qemu-devel] [PATCH v3 4/5] hmp: don't truncate size in hmp_memsave/hmp_pmemsave Simon Ruderich
2018-05-21 15:36   ` [Qemu-devel] [PATCH v3 5/5] qmp: add pmemload command Simon Ruderich
2018-08-09 16:46     ` Eric Blake
2018-08-14 14:16       ` Simon Ruderich
2018-08-10 10:36     ` Dr. David Alan Gilbert
2018-08-14 14:18       ` Simon Ruderich
2018-08-14 15:49         ` Markus Armbruster
2018-08-14 19:03           ` Simon Ruderich
2018-08-15  4:22             ` Markus Armbruster
2018-08-15 12:41               ` Simon Ruderich
2018-08-15 14:29                 ` Markus Armbruster
2018-08-15 15:46                   ` Simon Ruderich
2018-08-16  5:43                     ` Markus Armbruster
2018-08-16  8:13                       ` Simon Ruderich
2018-08-16  8:26                         ` Markus Armbruster
2018-08-16  8:38                           ` Simon Ruderich
2018-08-14 19:30         ` Dr. David Alan Gilbert
2018-08-09 14:43   ` [Qemu-devel] [PATCH v3 0/5] " Simon Ruderich
2018-08-10  6:06     ` Markus Armbruster
2018-08-14 14:16       ` Simon Ruderich
2018-08-14 15:27         ` Markus Armbruster
2018-08-16  9:01 ` [Qemu-devel] [PATCH v4 0/7] qmp/hmp: " Simon Ruderich
2018-08-16  9:01   ` [Qemu-devel] [PATCH v4 1/7] cpus: correct coding style in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-08-16 19:56     ` Eric Blake
2018-08-16  9:01   ` [Qemu-devel] [PATCH v4 2/7] cpus: convert qmp_memsave/qmp_pmemsave to use qemu_open Simon Ruderich
2018-08-16 19:58     ` Eric Blake
2018-08-16  9:01   ` [Qemu-devel] [PATCH v4 3/7] cpus: use size_t in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-08-16 19:58     ` Eric Blake
2018-08-16  9:01   ` [Qemu-devel] [PATCH v4 4/7] hmp: use l for size argument in memsave/pmemsave Simon Ruderich
2018-08-16 18:51     ` Dr. David Alan Gilbert
2018-08-16  9:01   ` [Qemu-devel] [PATCH v4 5/7] hmp: use F for filename arguments " Simon Ruderich
2018-08-16 18:53     ` Dr. David Alan Gilbert
2018-08-16  9:01   ` [Qemu-devel] [PATCH v4 6/7] qmp: add pmemload command Simon Ruderich
2018-08-16 20:01     ` Eric Blake
2018-08-17  7:50       ` Simon Ruderich
2018-08-21 12:38       ` [Qemu-devel] [PATCH v5 5/6] " Simon Ruderich
     [not found]         ` <20180921110205.GA904@ruderich.org>
2018-10-09 12:14           ` Simon Ruderich
2018-08-16  9:01   ` [Qemu-devel] [PATCH v4 7/7] hmp: " Simon Ruderich
2018-08-16 18:57     ` Dr. David Alan Gilbert
2018-11-15 13:01 ` [Qemu-devel] [PATCH v6 0/6] qmp: " Simon Ruderich
2018-11-15 13:01   ` [Qemu-devel] [PATCH v6 1/6] cpus: convert qmp_memsave/qmp_pmemsave to use qemu_open Simon Ruderich
2018-11-15 13:01   ` [Qemu-devel] [PATCH v6 2/6] cpus: use size_t in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-11-15 13:01   ` [Qemu-devel] [PATCH v6 3/6] hmp: use l for size argument in memsave/pmemsave Simon Ruderich
2018-11-15 13:01   ` [Qemu-devel] [PATCH v6 4/6] hmp: use F for filename arguments " Simon Ruderich
2018-11-15 13:01   ` [Qemu-devel] [PATCH v6 5/6] qmp: add pmemload command Simon Ruderich
2018-11-15 13:01   ` [Qemu-devel] [PATCH v6 6/6] hmp: " Simon Ruderich
2018-11-15 13:22 ` [Qemu-devel] [PATCH v7 0/7] qmp: " Simon Ruderich
2018-11-15 13:22   ` [Qemu-devel] [PATCH v7 1/7] cpus: correct coding style in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-11-15 13:46     ` Eric Blake
2018-11-15 13:22   ` [Qemu-devel] [PATCH v7 2/7] cpus: convert qmp_memsave/qmp_pmemsave to use qemu_open Simon Ruderich
2018-11-15 13:49     ` Eric Blake
2018-11-15 13:22   ` [Qemu-devel] [PATCH v7 3/7] cpus: use size_t in qmp_memsave/qmp_pmemsave Simon Ruderich
2018-11-15 13:22   ` [Qemu-devel] [PATCH v7 4/7] hmp: use l for size argument in memsave/pmemsave Simon Ruderich
2018-11-15 13:22   ` [Qemu-devel] [PATCH v7 5/7] hmp: use F for filename arguments " Simon Ruderich
2018-11-15 13:22   ` Simon Ruderich [this message]
2018-11-15 13:22   ` [Qemu-devel] [PATCH v7 7/7] hmp: add pmemload command Simon Ruderich
2018-11-15 13:45   ` [Qemu-devel] [PATCH v7 0/7] qmp: " Eric Blake
2018-11-15 14:09     ` Simon Ruderich

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=4e25c4e14e76cee9a1b0d062f2623426e2a0e0bb.1542287931.git.simon@ruderich.org \
    --to=simon@ruderich.org \
    --cc=armbru@redhat.com \
    --cc=crosthwaitepeter@gmail.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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.