All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/1] monitor: Add pmemload command
@ 2014-04-08 17:17 Baojun Wang
  2014-04-08 18:17 ` Baojun Wang
  2014-04-08 18:31 ` Eric Blake
  0 siblings, 2 replies; 4+ messages in thread
From: Baojun Wang @ 2014-04-08 17:17 UTC (permalink / raw
  To: qemu-devel


[-- Attachment #1.1: Type: text/plain, Size: 399 bytes --]

Hi list,

Is it possible to add a monitor command ``pmemload'' as pmemsave?
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.

Attachment is a trivial patch add pmemload monitor command.

Thanks
baojun

[-- Attachment #1.2: Type: text/html, Size: 492 bytes --]

[-- Attachment #2: pmemload.diff --]
[-- Type: text/plain, Size: 4343 bytes --]

diff --git a/cpus.c b/cpus.c
index 1104d61..03d1277 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1467,6 +1467,30 @@ exit:
     fclose(f);
 }
 
+void qmp_pmemload(int64_t addr, int64_t size, const char *filename,
+                  Error **errp)
+{
+    FILE *f;
+    uint32_t l;
+    uint8_t buf[1024];
+
+    f = fopen(filename, "rb");
+    if (!f) {
+        error_setg_file_open(errp, errno, filename);
+        return;
+    }
+
+    while (size != 0) {
+        l = fread(buf, 1, sizeof(buf), f);
+        if (l > size)
+            l = size;
+        cpu_physical_memory_rw(addr, buf, l, 1);
+        addr += l;
+        size -= l;
+    }
+
+    fclose(f);
+}
 void qmp_inject_nmi(Error **errp)
 {
 #if defined(TARGET_I386)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index f3fc514..75d162e 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -803,12 +803,25 @@ ETEXI
     },
 
 STEXI
-@item pmemsave @var{addr} @var{size} @var{file}
-@findex pmemsave
-save to disk physical memory dump starting at @var{addr} of size @var{size}.
+@item pmemload @var{addr} @var{size} @var{file}
+@findex pmemload
+load from disk physical memory dump starting at @var{addr} of size @var{size}.
 ETEXI
 
     {
+        .name       = "pmemload",
+        .args_type  = "val:l,size:i,filename:s",
+        .params     = "addr size file",
+        .help       = "load from disk physical memory dump starting at 'addr' of size 'size'",
+        .mhandler.cmd = hmp_pmemload,
+    },
+
+STEXI
+@item pmemload @var{addr} @var{size} @var{file}
+@findex pmemload
+save to disk physical memory dump starting at @var{addr} of size @var{size}.
+ETEXI
+    {
         .name       = "boot_set",
         .args_type  = "bootdevice:s",
         .params     = "bootdevice",
diff --git a/hmp.c b/hmp.c
index 2f279c4..6e932f9 100644
--- a/hmp.c
+++ b/hmp.c
@@ -767,6 +767,17 @@ void hmp_pmemsave(Monitor *mon, const QDict *qdict)
     hmp_handle_error(mon, &errp);
 }
 
+void hmp_pmemload(Monitor *mon, const QDict *qdict)
+{
+    uint32_t size = qdict_get_int(qdict, "size");
+    const char *filename = qdict_get_str(qdict, "filename");
+    uint64_t addr = qdict_get_int(qdict, "val");
+    Error *errp = NULL;
+
+    qmp_pmemload(addr, size, filename, &errp);
+    hmp_handle_error(mon, &errp);
+}
+
 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
 {
     const char *chardev = qdict_get_str(qdict, "device");
diff --git a/hmp.h b/hmp.h
index ed58f0e..f5f2a16 100644
--- a/hmp.h
+++ b/hmp.h
@@ -44,6 +44,7 @@ void hmp_system_powerdown(Monitor *mon, const QDict *qdict);
 void hmp_cpu(Monitor *mon, const QDict *qdict);
 void hmp_memsave(Monitor *mon, const QDict *qdict);
 void hmp_pmemsave(Monitor *mon, const QDict *qdict);
+void hmp_pmemload(Monitor *mon, const QDict *qdict);
 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict);
 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict);
 void hmp_cont(Monitor *mon, const QDict *qdict);
diff --git a/qapi-schema.json b/qapi-schema.json
index 391356f..f511ff3 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1708,6 +1708,26 @@
   '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
+#
+# @size: the size of memory region to save
+#
+# @filename: the file to load the memory from as binary data
+#
+# Returns: Nothing on success
+#
+# Since: 2.0
+#
+# Notes: Errors were not reliably returned until 1.1
+##
+{ 'command': 'pmemload',
+  'data': {'val': 'int', 'size': 'int', 'filename': 'str'} }
+
+##
 # @cont:
 #
 # Resume guest VCPU execution.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index ed3ab92..2312839 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -467,6 +467,27 @@ Example:
 
 EQMP
 
+SQMP
+pmemload
+--------
+
+Restore from disk physical memory dump starting at 'val' of size 'size'.
+
+Arguments:
+
+- "val": the starting address (json-int)
+- "size": the memory size, in bytes (json-int)
+- "filename": file path (json-string)
+
+Example:
+
+-> { "execute": "pmemload",
+             "arguments": { "val": 10,
+                            "size": 100,
+                            "filename": "/tmp/physical-mem-dump" } }
+<- { "return": {} }
+
+EQMP
     {
         .name       = "inject-nmi",
         .args_type  = "",

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

* Re: [Qemu-devel] [PATCH 1/1] monitor: Add pmemload command
  2014-04-08 17:17 [Qemu-devel] [PATCH 1/1] monitor: Add pmemload command Baojun Wang
@ 2014-04-08 18:17 ` Baojun Wang
  2014-04-08 18:31   ` Eric Blake
  2014-04-08 18:31 ` Eric Blake
  1 sibling, 1 reply; 4+ messages in thread
From: Baojun Wang @ 2014-04-08 18:17 UTC (permalink / raw
  To: qemu-devel


[-- Attachment #1.1: Type: text/plain, Size: 528 bytes --]

fix an error in qmp-commands.hx


On Tue, Apr 8, 2014 at 10:17 AM, Baojun Wang <wangbj@gmail.com> wrote:

> Hi list,
>
> Is it possible to add a monitor command ``pmemload'' as pmemsave?
> 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.
>
> Attachment is a trivial patch add pmemload monitor command.
>
> Thanks
> baojun
>

[-- Attachment #1.2: Type: text/html, Size: 959 bytes --]

[-- Attachment #2: pmemload.diff --]
[-- Type: text/plain, Size: 4556 bytes --]

diff --git a/cpus.c b/cpus.c
index 1104d61..03d1277 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1467,6 +1467,30 @@ exit:
     fclose(f);
 }
 
+void qmp_pmemload(int64_t addr, int64_t size, const char *filename,
+                  Error **errp)
+{
+    FILE *f;
+    uint32_t l;
+    uint8_t buf[1024];
+
+    f = fopen(filename, "rb");
+    if (!f) {
+        error_setg_file_open(errp, errno, filename);
+        return;
+    }
+
+    while (size != 0) {
+        l = fread(buf, 1, sizeof(buf), f);
+        if (l > size)
+            l = size;
+        cpu_physical_memory_rw(addr, buf, l, 1);
+        addr += l;
+        size -= l;
+    }
+
+    fclose(f);
+}
 void qmp_inject_nmi(Error **errp)
 {
 #if defined(TARGET_I386)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index f3fc514..75d162e 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -803,12 +803,25 @@ ETEXI
     },
 
 STEXI
-@item pmemsave @var{addr} @var{size} @var{file}
-@findex pmemsave
-save to disk physical memory dump starting at @var{addr} of size @var{size}.
+@item pmemload @var{addr} @var{size} @var{file}
+@findex pmemload
+load from disk physical memory dump starting at @var{addr} of size @var{size}.
 ETEXI
 
     {
+        .name       = "pmemload",
+        .args_type  = "val:l,size:i,filename:s",
+        .params     = "addr size file",
+        .help       = "load from disk physical memory dump starting at 'addr' of size 'size'",
+        .mhandler.cmd = hmp_pmemload,
+    },
+
+STEXI
+@item pmemload @var{addr} @var{size} @var{file}
+@findex pmemload
+save to disk physical memory dump starting at @var{addr} of size @var{size}.
+ETEXI
+    {
         .name       = "boot_set",
         .args_type  = "bootdevice:s",
         .params     = "bootdevice",
diff --git a/hmp.c b/hmp.c
index 2f279c4..6e932f9 100644
--- a/hmp.c
+++ b/hmp.c
@@ -767,6 +767,17 @@ void hmp_pmemsave(Monitor *mon, const QDict *qdict)
     hmp_handle_error(mon, &errp);
 }
 
+void hmp_pmemload(Monitor *mon, const QDict *qdict)
+{
+    uint32_t size = qdict_get_int(qdict, "size");
+    const char *filename = qdict_get_str(qdict, "filename");
+    uint64_t addr = qdict_get_int(qdict, "val");
+    Error *errp = NULL;
+
+    qmp_pmemload(addr, size, filename, &errp);
+    hmp_handle_error(mon, &errp);
+}
+
 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
 {
     const char *chardev = qdict_get_str(qdict, "device");
diff --git a/hmp.h b/hmp.h
index ed58f0e..f5f2a16 100644
--- a/hmp.h
+++ b/hmp.h
@@ -44,6 +44,7 @@ void hmp_system_powerdown(Monitor *mon, const QDict *qdict);
 void hmp_cpu(Monitor *mon, const QDict *qdict);
 void hmp_memsave(Monitor *mon, const QDict *qdict);
 void hmp_pmemsave(Monitor *mon, const QDict *qdict);
+void hmp_pmemload(Monitor *mon, const QDict *qdict);
 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict);
 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict);
 void hmp_cont(Monitor *mon, const QDict *qdict);
diff --git a/qapi-schema.json b/qapi-schema.json
index 391356f..f511ff3 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1708,6 +1708,26 @@
   '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
+#
+# @size: the size of memory region to save
+#
+# @filename: the file to load the memory from as binary data
+#
+# Returns: Nothing on success
+#
+# Since: 2.0
+#
+# Notes: Errors were not reliably returned until 1.1
+##
+{ 'command': 'pmemload',
+  'data': {'val': 'int', 'size': 'int', 'filename': 'str'} }
+
+##
 # @cont:
 #
 # Resume guest VCPU execution.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index ed3ab92..584d6cf 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -468,6 +468,33 @@ Example:
 EQMP
 
     {
+        .name       = "pmemload",
+        .args_type  = "val:l,size:i,filename:s",
+        .mhandler.cmd_new = qmp_marshal_input_pmemload,
+    },
+
+SQMP
+pmemload
+--------
+
+load from disk physical memory dump starting at 'val' of size 'size'.
+
+Arguments:
+
+- "val": the starting address (json-int)
+- "size": the memory size, in bytes (json-int)
+- "filename": file path (json-string)
+
+Example:
+
+-> { "execute": "pmemload",
+             "arguments": { "val": 10,
+                            "size": 100,
+                            "filename": "/tmp/physical-mem-dump" } }
+<- { "return": {} }
+
+EQMP
+    {
         .name       = "inject-nmi",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_input_inject_nmi,

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

* Re: [Qemu-devel] [PATCH 1/1] monitor: Add pmemload command
  2014-04-08 17:17 [Qemu-devel] [PATCH 1/1] monitor: Add pmemload command Baojun Wang
  2014-04-08 18:17 ` Baojun Wang
@ 2014-04-08 18:31 ` Eric Blake
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Blake @ 2014-04-08 18:31 UTC (permalink / raw
  To: Baojun Wang, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1384 bytes --]

On 04/08/2014 11:17 AM, Baojun Wang wrote:
> Hi list,
> 
> Is it possible to add a monitor command ``pmemload'' as pmemsave?
> 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.
> 
> Attachment is a trivial patch add pmemload monitor command.

We prefer patches sent inline via 'git send-email', as they are easier
to reply to.


> +++ b/qapi-schema.json
> @@ -1708,6 +1708,26 @@
>    '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
> +#
> +# @size: the size of memory region to save

s/save/load/ ?

> +#
> +# @filename: the file to load the memory from as binary data
> +#
> +# Returns: Nothing on success
> +#
> +# Since: 2.0

You've missed 2.0; at the earliest, this would be 2.1.

> +#
> +# Notes: Errors were not reliably returned until 1.1

This note is bogus copy and paste - since the command is new to 2.1,
there is no unreliable error handling in 1.1.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

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

* Re: [Qemu-devel] [PATCH 1/1] monitor: Add pmemload command
  2014-04-08 18:17 ` Baojun Wang
@ 2014-04-08 18:31   ` Eric Blake
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2014-04-08 18:31 UTC (permalink / raw
  To: Baojun Wang, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]

On 04/08/2014 12:17 PM, Baojun Wang wrote:
> fix an error in qmp-commands.hx

When sending a v2 patch, it's better to explicitly label it as v2 in the
subject line.

Here's some more hints about the best way to send patches:
http://wiki.qemu.org/Contribute/SubmitAPatch


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

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

end of thread, other threads:[~2014-04-08 18:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-08 17:17 [Qemu-devel] [PATCH 1/1] monitor: Add pmemload command Baojun Wang
2014-04-08 18:17 ` Baojun Wang
2014-04-08 18:31   ` Eric Blake
2014-04-08 18:31 ` Eric Blake

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.