qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Handle gdb.MemoryError exception in dump-guest-memory.py
@ 2020-02-15  0:33 Kevin Buettner
  2020-02-15 10:31 ` Marc-André Lureau
  2020-03-05  9:46 ` Marc-André Lureau
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Buettner @ 2020-02-15  0:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcandre.lureau, Kevin Buettner

[Included a "Signed-off-by" line in this version.]

I recently investigated a bug in which the dump-guest-memory.py script
sees a gdb.MemoryError exception while attempting to dump memory
obtained from a QEMU core dump.  (And, yes, dump-guest-core=on was
specified in the -machine option of the QEMU invocation.)

It turns out that memory region in question is not being placed in the
core dump and, after stepping through the kernel core dumping code
responsible for making this decision, it looks reasonable to me to not
include that region in the core dump.  The region in question consists
of all zeros and, according to the kernel's logic, has never been
written to.

This commit makes a small change to the dump-guest-memory script to
cause inaccessible memory to be dumped as zeroes.  This avoids the
exception and places the correct values in the guest memory dump.

Signed-off-by: Kevin Buettner <kevinb@redhat.com>
---
 scripts/dump-guest-memory.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
index 4177261d33..fbdfba458b 100644
--- a/scripts/dump-guest-memory.py
+++ b/scripts/dump-guest-memory.py
@@ -539,7 +539,12 @@ shape and this command should mostly work."""
 
             while left > 0:
                 chunk_size = min(TARGET_PAGE_SIZE, left)
-                chunk = qemu_core.read_memory(cur, chunk_size)
+                try:
+                    chunk = qemu_core.read_memory(cur, chunk_size)
+                except gdb.MemoryError:
+                    # Consider blocks of memory absent from a core file
+                    # as being zeroed.
+                    chunk = bytes(chunk_size)
                 vmcore.write(chunk)
                 cur += chunk_size
                 left -= chunk_size
-- 
2.24.1



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

* Re: [PATCH v2] Handle gdb.MemoryError exception in dump-guest-memory.py
  2020-02-15  0:33 [PATCH v2] Handle gdb.MemoryError exception in dump-guest-memory.py Kevin Buettner
@ 2020-02-15 10:31 ` Marc-André Lureau
  2020-03-05  9:46 ` Marc-André Lureau
  1 sibling, 0 replies; 3+ messages in thread
From: Marc-André Lureau @ 2020-02-15 10:31 UTC (permalink / raw)
  To: Kevin Buettner, qemu-devel; +Cc: keiths, Laszlo Ersek

Hi

On Sat, Feb 15, 2020 at 1:34 AM Kevin Buettner <kevinb@redhat.com> wrote:
>
> [Included a "Signed-off-by" line in this version.]
>
> I recently investigated a bug in which the dump-guest-memory.py script
> sees a gdb.MemoryError exception while attempting to dump memory
> obtained from a QEMU core dump.  (And, yes, dump-guest-core=on was
> specified in the -machine option of the QEMU invocation.)
>
> It turns out that memory region in question is not being placed in the
> core dump and, after stepping through the kernel core dumping code
> responsible for making this decision, it looks reasonable to me to not
> include that region in the core dump.  The region in question consists
> of all zeros and, according to the kernel's logic, has never been
> written to.
>
> This commit makes a small change to the dump-guest-memory script to
> cause inaccessible memory to be dumped as zeroes.  This avoids the
> exception and places the correct values in the guest memory dump.
>
> Signed-off-by: Kevin Buettner <kevinb@redhat.com>
> ---
>  scripts/dump-guest-memory.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
> index 4177261d33..fbdfba458b 100644
> --- a/scripts/dump-guest-memory.py
> +++ b/scripts/dump-guest-memory.py
> @@ -539,7 +539,12 @@ shape and this command should mostly work."""
>
>              while left > 0:
>                  chunk_size = min(TARGET_PAGE_SIZE, left)
> -                chunk = qemu_core.read_memory(cur, chunk_size)
> +                try:
> +                    chunk = qemu_core.read_memory(cur, chunk_size)
> +                except gdb.MemoryError:
> +                    # Consider blocks of memory absent from a core file
> +                    # as being zeroed.
> +                    chunk = bytes(chunk_size)

That seems reasonable, but it will silently ignore any other memory error.

Keith Seitz also looked at this bug, and he was wondering if BFD
shouldn't treat the missing section differently:
https://bugzilla.redhat.com/show_bug.cgi?id=1777751#c6

Keith, what do you think?

thanks



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

* Re: [PATCH v2] Handle gdb.MemoryError exception in dump-guest-memory.py
  2020-02-15  0:33 [PATCH v2] Handle gdb.MemoryError exception in dump-guest-memory.py Kevin Buettner
  2020-02-15 10:31 ` Marc-André Lureau
@ 2020-03-05  9:46 ` Marc-André Lureau
  1 sibling, 0 replies; 3+ messages in thread
From: Marc-André Lureau @ 2020-03-05  9:46 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: QEMU

Hi

On Sat, Feb 15, 2020 at 1:34 AM Kevin Buettner <kevinb@redhat.com> wrote:
>
> [Included a "Signed-off-by" line in this version.]
>
> I recently investigated a bug in which the dump-guest-memory.py script
> sees a gdb.MemoryError exception while attempting to dump memory
> obtained from a QEMU core dump.  (And, yes, dump-guest-core=on was
> specified in the -machine option of the QEMU invocation.)
>
> It turns out that memory region in question is not being placed in the
> core dump and, after stepping through the kernel core dumping code
> responsible for making this decision, it looks reasonable to me to not
> include that region in the core dump.  The region in question consists
> of all zeros and, according to the kernel's logic, has never been
> written to.
>
> This commit makes a small change to the dump-guest-memory script to
> cause inaccessible memory to be dumped as zeroes.  This avoids the
> exception and places the correct values in the guest memory dump.
>
> Signed-off-by: Kevin Buettner <kevinb@redhat.com>

fwiw, Kevin fixed it in gdb:
https://sourceware.org/ml/gdb-patches/2020-03/msg00106.html

> ---
>  scripts/dump-guest-memory.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
> index 4177261d33..fbdfba458b 100644
> --- a/scripts/dump-guest-memory.py
> +++ b/scripts/dump-guest-memory.py
> @@ -539,7 +539,12 @@ shape and this command should mostly work."""
>
>              while left > 0:
>                  chunk_size = min(TARGET_PAGE_SIZE, left)
> -                chunk = qemu_core.read_memory(cur, chunk_size)
> +                try:
> +                    chunk = qemu_core.read_memory(cur, chunk_size)
> +                except gdb.MemoryError:
> +                    # Consider blocks of memory absent from a core file
> +                    # as being zeroed.
> +                    chunk = bytes(chunk_size)
>                  vmcore.write(chunk)
>                  cur += chunk_size
>                  left -= chunk_size
> --
> 2.24.1
>
>


-- 
Marc-André Lureau


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

end of thread, other threads:[~2020-03-05  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-15  0:33 [PATCH v2] Handle gdb.MemoryError exception in dump-guest-memory.py Kevin Buettner
2020-02-15 10:31 ` Marc-André Lureau
2020-03-05  9:46 ` Marc-André Lureau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).