[PATCH] Handle gdb.MemoryError exception in dump-guest-memory.py

Kevin Buettner posted 1 patch 4 years, 2 months ago
Test docker-quick@centos7 passed
Test FreeBSD passed
Test docker-mingw@fedora passed
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20200214232650.35381-1-kevinb@redhat.com
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Cleber Rosa <crosa@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>
There is a newer version of this series
scripts/dump-guest-memory.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] Handle gdb.MemoryError exception in dump-guest-memory.py
Posted by Kevin Buettner 4 years, 2 months ago
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.
---
 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


Re: [PATCH] Handle gdb.MemoryError exception in dump-guest-memory.py
Posted by no-reply@patchew.org 4 years, 2 months ago
Patchew URL: https://patchew.org/QEMU/20200214232650.35381-1-kevinb@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [PATCH] Handle gdb.MemoryError exception in dump-guest-memory.py
Message-id: 20200214232650.35381-1-kevinb@redhat.com
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20200214232650.35381-1-kevinb@redhat.com -> patchew/20200214232650.35381-1-kevinb@redhat.com
Switched to a new branch 'test'
b41300a Handle gdb.MemoryError exception in dump-guest-memory.py

=== OUTPUT BEGIN ===
ERROR: Missing Signed-off-by: line(s)

total: 1 errors, 0 warnings, 13 lines checked

Commit b41300af0818 (Handle gdb.MemoryError exception in dump-guest-memory.py) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20200214232650.35381-1-kevinb@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com