Skip to contentSkip to conversation

dump: fix Windows dump memory run mapping

PATCH Applied Viktor Prutyanov 3 participants 4 messages Aug 29, 2018 – Sep 11, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dump: fix Windows dump memory run mapping

We should map and use guest memory run by parts if it can't be mapped as a whole.
After this patch, continuos guest physical memory blocks which are not continuos in host virtual address space will be processed correctly.

---
 win_dump.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
win_dump.c +22 -18
index b15c191..aa39d9c 100644
@@ -30,28 +30,32 @@ static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp)
     void *buf;
     uint64_t addr = run->BasePage << TARGET_PAGE_BITS;
     uint64_t size = run->PageCount << TARGET_PAGE_BITS;
-    uint64_t len = size;
+    uint64_t len, l;
+    size_t total = 0;
 
-    buf = cpu_physical_memory_map(addr, &len, false);
-    if (!buf) {
-        error_setg(errp, "win-dump: failed to map run");
-        return 0;
-    }
-    if (len != size) {
-        error_setg(errp, "win-dump: failed to map entire run");
-        len = 0;
-        goto out_unmap;
-    }
+    while (size) {
+        len = size;
 
-    len = qemu_write_full(fd, buf, len);
-    if (len != size) {
-        error_setg(errp, QERR_IO_ERROR);
-    }
+        buf = cpu_physical_memory_map(addr, &len, false);
+        if (!buf) {
+            error_setg(errp, "win-dump: failed to map physical range"
+                             " 0x%016lx-0x%016lx", addr, addr + size - 1);
+            return 0;
+        }
+
+        l = qemu_write_full(fd, buf, len);
+        cpu_physical_memory_unmap(buf, addr, false, len);
+        if (l != len) {
+            error_setg(errp, QERR_IO_ERROR);
+            return 0;
+        }
 
-out_unmap:
-    cpu_physical_memory_unmap(buf, addr, false, len);
+        addr += l;
+        size -= l;
+        total += l;
+    }
 
-    return len;
+    return total;
 }
 
 static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp)
Signature · 1 line
2.7.4
#1 lore raw

2018-08-29 21:30 GMT+03:00 Viktor Prutyanov <[email protected]>:

Quoted 67 lines

We should map and use guest memory run by parts if it can't be mapped as a whole.
After this patch, continuos guest physical memory blocks which are not continuos in host virtual address space will be processed correctly.

---
 win_dump.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
win_dump.c +22 -19
index b15c191..aa39d9c 100644
@@ -30,28 +30,32 @@ static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp)
     void *buf;
     uint64_t addr = run->BasePage << TARGET_PAGE_BITS;
     uint64_t size = run->PageCount << TARGET_PAGE_BITS;
-    uint64_t len = size;
+    uint64_t len, l;
+    size_t total = 0;
 
-    buf = cpu_physical_memory_map(addr, &len, false);
-    if (!buf) {
-        error_setg(errp, "win-dump: failed to map run");
-        return 0;
-    }
-    if (len != size) {
-        error_setg(errp, "win-dump: failed to map entire run");
-        len = 0;
-        goto out_unmap;
-    }
+    while (size) {
+        len = size;
 
-    len = qemu_write_full(fd, buf, len);
-    if (len != size) {
-        error_setg(errp, QERR_IO_ERROR);
-    }
+        buf = cpu_physical_memory_map(addr, &len, false);
+        if (!buf) {
+            error_setg(errp, "win-dump: failed to map physical range"
+                             " 0x%016lx-0x%016lx", addr, addr + size - 1);
+            return 0;
+        }
+
+        l = qemu_write_full(fd, buf, len);
+        cpu_physical_memory_unmap(buf, addr, false, len);
+        if (l != len) {
+            error_setg(errp, QERR_IO_ERROR);
+            return 0;
+        }
 
-out_unmap:
-    cpu_physical_memory_unmap(buf, addr, false, len);
+        addr += l;
+        size -= l;
+        total += l;
+    }
 
-    return len;
+    return total;
 }
 
 static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp)
--
Quoted 2 lines

2.7.4

ping

#2 lore raw
In reply to Viktor Prutyanov

В Wed, 29 Aug 2018 21:30:56 +0300
Viktor Prutyanov <[email protected]> пишет:

Quoted 66 lines

We should map and use guest memory run by parts if it can't be mapped as a whole.
After this patch, continuos guest physical memory blocks which are not continuos in host virtual address space will be processed correctly.

---
 win_dump.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
win_dump.c +22 -19
index b15c191..aa39d9c 100644
@@ -30,28 +30,32 @@ static size_t write_run(WinDumpPhyMemRun64 *run,
 int fd, Error **errp) void *buf;
     uint64_t addr = run->BasePage << TARGET_PAGE_BITS;
     uint64_t size = run->PageCount << TARGET_PAGE_BITS;
-    uint64_t len = size;
+    uint64_t len, l;
+    size_t total = 0;
 
-    buf = cpu_physical_memory_map(addr, &len, false);
-    if (!buf) {
-        error_setg(errp, "win-dump: failed to map run");
-        return 0;
-    }
-    if (len != size) {
-        error_setg(errp, "win-dump: failed to map entire run");
-        len = 0;
-        goto out_unmap;
-    }
+    while (size) {
+        len = size;
 
-    len = qemu_write_full(fd, buf, len);
-    if (len != size) {
-        error_setg(errp, QERR_IO_ERROR);
-    }
+        buf = cpu_physical_memory_map(addr, &len, false);
+        if (!buf) {
+            error_setg(errp, "win-dump: failed to map physical range"
+                             " 0x%016lx-0x%016lx", addr, addr + size
- 1);
+            return 0;
+        }
+
+        l = qemu_write_full(fd, buf, len);
+        cpu_physical_memory_unmap(buf, addr, false, len);
+        if (l != len) {
+            error_setg(errp, QERR_IO_ERROR);
+            return 0;
+        }
 
-out_unmap:
-    cpu_physical_memory_unmap(buf, addr, false, len);
+        addr += l;
+        size -= l;
+        total += l;
+    }
 
-    return len;
+    return total;
 }
 
 static void write_runs(DumpState *s, WinDumpHeader64 *h, Error
Quoted 1 line

**errp)

ping

#3 lore raw
In reply to Viktor Prutyanov
Quoted 56 lines · Viktor Prutyanov

We should map and use guest memory run by parts if it can't be mapped as a whole.
After this patch, continuos guest physical memory blocks which are not continuos in host virtual address space will be processed correctly.

---
 win_dump.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
win_dump.c +17 -17
index b15c191..aa39d9c 100644
@@ -30,28 +30,32 @@ static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp)
     void *buf;
     uint64_t addr = run->BasePage << TARGET_PAGE_BITS;
     uint64_t size = run->PageCount << TARGET_PAGE_BITS;
-    uint64_t len = size;
+    uint64_t len, l;
+    size_t total = 0;
 
-    buf = cpu_physical_memory_map(addr, &len, false);
-    if (!buf) {
-        error_setg(errp, "win-dump: failed to map run");
-        return 0;
-    }
-    if (len != size) {
-        error_setg(errp, "win-dump: failed to map entire run");
-        len = 0;
-        goto out_unmap;
-    }
+    while (size) {
+        len = size;
 
-    len = qemu_write_full(fd, buf, len);
-    if (len != size) {
-        error_setg(errp, QERR_IO_ERROR);
-    }
+        buf = cpu_physical_memory_map(addr, &len, false);
+        if (!buf) {
+            error_setg(errp, "win-dump: failed to map physical range"
+                             " 0x%016lx-0x%016lx", addr, addr + size - 1);
+            return 0;
+        }
+
+        l = qemu_write_full(fd, buf, len);
+        cpu_physical_memory_unmap(buf, addr, false, len);
+        if (l != len) {
+            error_setg(errp, QERR_IO_ERROR);
+            return 0;
+        }
 
-out_unmap:
-    cpu_physical_memory_unmap(buf, addr, false, len);

win_dump.c static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp) · line 61

Quoted 10 lines
win_dump.c +5 -1
+        addr += l;
+        size -= l;
+        total += l;
+    }
 
-    return len;
+    return total;
 }
 
 static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp)

Queued, thanks.

Paolo