9ae3a8
From 4e6b46284cde10374bd0660e89958fe9c2477887 Mon Sep 17 00:00:00 2001
9ae3a8
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
9ae3a8
Date: Wed, 13 Dec 2017 13:38:52 +0100
9ae3a8
Subject: [PATCH 21/41] dump: allow target to set the page size
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
Message-id: <20171213133912.26176-22-marcandre.lureau@redhat.com>
9ae3a8
Patchwork-id: 78370
9ae3a8
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 21/41] dump: allow target to set the page size
9ae3a8
Bugzilla: 1411490
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
From: Andrew Jones <drjones@redhat.com>
9ae3a8
9ae3a8
This is necessary for targets that don't have TARGET_PAGE_SIZE ==
9ae3a8
real-target-page-size. The target should set the page size to the
9ae3a8
correct one, if known, or, if not known, to the maximum page size
9ae3a8
it supports.
9ae3a8
9ae3a8
(No functional change.)
9ae3a8
9ae3a8
Signed-off-by: Andrew Jones <drjones@redhat.com>
9ae3a8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9ae3a8
Message-id: 1452542185-10914-4-git-send-email-drjones@redhat.com
9ae3a8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9ae3a8
9ae3a8
(cherry picked from commit 8161befdd15ddc5a8bb9e807ff1ac5907c594688)
9ae3a8
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 dump.c                     | 127 ++++++++++++++++++++++++++++-----------------
9ae3a8
 include/sysemu/dump-arch.h |   8 +--
9ae3a8
 include/sysemu/dump.h      |  10 +---
9ae3a8
 3 files changed, 85 insertions(+), 60 deletions(-)
9ae3a8
9ae3a8
diff --git a/dump.c b/dump.c
9ae3a8
index 83b6d20..b5d6608 100644
9ae3a8
--- a/dump.c
9ae3a8
+++ b/dump.c
9ae3a8
@@ -352,18 +352,18 @@ static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
9ae3a8
     int64_t i;
9ae3a8
     Error *local_err = NULL;
9ae3a8
 
9ae3a8
-    for (i = 0; i < size / TARGET_PAGE_SIZE; i++) {
9ae3a8
-        write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
9ae3a8
-                   TARGET_PAGE_SIZE, &local_err);
9ae3a8
+    for (i = 0; i < size / s->dump_info.page_size; i++) {
9ae3a8
+        write_data(s, block->host_addr + start + i * s->dump_info.page_size,
9ae3a8
+                   s->dump_info.page_size, &local_err);
9ae3a8
         if (local_err) {
9ae3a8
             error_propagate(errp, local_err);
9ae3a8
             return;
9ae3a8
         }
9ae3a8
     }
9ae3a8
 
9ae3a8
-    if ((size % TARGET_PAGE_SIZE) != 0) {
9ae3a8
-        write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
9ae3a8
-                   size % TARGET_PAGE_SIZE, &local_err);
9ae3a8
+    if ((size % s->dump_info.page_size) != 0) {
9ae3a8
+        write_data(s, block->host_addr + start + i * s->dump_info.page_size,
9ae3a8
+                   size % s->dump_info.page_size, &local_err);
9ae3a8
         if (local_err) {
9ae3a8
             error_propagate(errp, local_err);
9ae3a8
             return;
9ae3a8
@@ -742,7 +742,7 @@ static void create_header32(DumpState *s, Error **errp)
9ae3a8
 
9ae3a8
     strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
9ae3a8
     dh->header_version = cpu_to_dump32(s, 6);
9ae3a8
-    block_size = TARGET_PAGE_SIZE;
9ae3a8
+    block_size = s->dump_info.page_size;
9ae3a8
     dh->block_size = cpu_to_dump32(s, block_size);
9ae3a8
     sub_hdr_size = sizeof(struct KdumpSubHeader32) + s->note_size;
9ae3a8
     sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);
9ae3a8
@@ -842,7 +842,7 @@ static void create_header64(DumpState *s, Error **errp)
9ae3a8
 
9ae3a8
     strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
9ae3a8
     dh->header_version = cpu_to_dump32(s, 6);
9ae3a8
-    block_size = TARGET_PAGE_SIZE;
9ae3a8
+    block_size = s->dump_info.page_size;
9ae3a8
     dh->block_size = cpu_to_dump32(s, block_size);
9ae3a8
     sub_hdr_size = sizeof(struct KdumpSubHeader64) + s->note_size;
9ae3a8
     sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);
9ae3a8
@@ -938,6 +938,11 @@ static void write_dump_header(DumpState *s, Error **errp)
9ae3a8
     }
9ae3a8
 }
9ae3a8
 
9ae3a8
+static size_t dump_bitmap_get_bufsize(DumpState *s)
9ae3a8
+{
9ae3a8
+    return s->dump_info.page_size;
9ae3a8
+}
9ae3a8
+
9ae3a8
 /*
9ae3a8
  * set dump_bitmap sequencely. the bit before last_pfn is not allowed to be
9ae3a8
  * rewritten, so if need to set the first bit, set last_pfn and pfn to 0.
9ae3a8
@@ -951,6 +956,8 @@ static int set_dump_bitmap(uint64_t last_pfn, uint64_t pfn, bool value,
9ae3a8
     off_t old_offset, new_offset;
9ae3a8
     off_t offset_bitmap1, offset_bitmap2;
9ae3a8
     uint32_t byte, bit;
9ae3a8
+    size_t bitmap_bufsize = dump_bitmap_get_bufsize(s);
9ae3a8
+    size_t bits_per_buf = bitmap_bufsize * CHAR_BIT;
9ae3a8
 
9ae3a8
     /* should not set the previous place */
9ae3a8
     assert(last_pfn <= pfn);
9ae3a8
@@ -961,14 +968,14 @@ static int set_dump_bitmap(uint64_t last_pfn, uint64_t pfn, bool value,
9ae3a8
      * making new_offset be bigger than old_offset can also sync remained data
9ae3a8
      * into vmcore.
9ae3a8
      */
9ae3a8
-    old_offset = BUFSIZE_BITMAP * (last_pfn / PFN_BUFBITMAP);
9ae3a8
-    new_offset = BUFSIZE_BITMAP * (pfn / PFN_BUFBITMAP);
9ae3a8
+    old_offset = bitmap_bufsize * (last_pfn / bits_per_buf);
9ae3a8
+    new_offset = bitmap_bufsize * (pfn / bits_per_buf);
9ae3a8
 
9ae3a8
     while (old_offset < new_offset) {
9ae3a8
         /* calculate the offset and write dump_bitmap */
9ae3a8
         offset_bitmap1 = s->offset_dump_bitmap + old_offset;
9ae3a8
         if (write_buffer(s->fd, offset_bitmap1, buf,
9ae3a8
-                         BUFSIZE_BITMAP) < 0) {
9ae3a8
+                         bitmap_bufsize) < 0) {
9ae3a8
             return -1;
9ae3a8
         }
9ae3a8
 
9ae3a8
@@ -976,17 +983,17 @@ static int set_dump_bitmap(uint64_t last_pfn, uint64_t pfn, bool value,
9ae3a8
         offset_bitmap2 = s->offset_dump_bitmap + s->len_dump_bitmap +
9ae3a8
                          old_offset;
9ae3a8
         if (write_buffer(s->fd, offset_bitmap2, buf,
9ae3a8
-                         BUFSIZE_BITMAP) < 0) {
9ae3a8
+                         bitmap_bufsize) < 0) {
9ae3a8
             return -1;
9ae3a8
         }
9ae3a8
 
9ae3a8
-        memset(buf, 0, BUFSIZE_BITMAP);
9ae3a8
-        old_offset += BUFSIZE_BITMAP;
9ae3a8
+        memset(buf, 0, bitmap_bufsize);
9ae3a8
+        old_offset += bitmap_bufsize;
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* get the exact place of the bit in the buf, and set it */
9ae3a8
-    byte = (pfn % PFN_BUFBITMAP) / CHAR_BIT;
9ae3a8
-    bit = (pfn % PFN_BUFBITMAP) % CHAR_BIT;
9ae3a8
+    byte = (pfn % bits_per_buf) / CHAR_BIT;
9ae3a8
+    bit = (pfn % bits_per_buf) % CHAR_BIT;
9ae3a8
     if (value) {
9ae3a8
         buf[byte] |= 1u << bit;
9ae3a8
     } else {
9ae3a8
@@ -996,6 +1003,20 @@ static int set_dump_bitmap(uint64_t last_pfn, uint64_t pfn, bool value,
9ae3a8
     return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
+static uint64_t dump_paddr_to_pfn(DumpState *s, uint64_t addr)
9ae3a8
+{
9ae3a8
+    int target_page_shift = ctz32(s->dump_info.page_size);
9ae3a8
+
9ae3a8
+    return (addr >> target_page_shift) - ARCH_PFN_OFFSET;
9ae3a8
+}
9ae3a8
+
9ae3a8
+static uint64_t dump_pfn_to_paddr(DumpState *s, uint64_t pfn)
9ae3a8
+{
9ae3a8
+    int target_page_shift = ctz32(s->dump_info.page_size);
9ae3a8
+
9ae3a8
+    return (pfn + ARCH_PFN_OFFSET) << target_page_shift;
9ae3a8
+}
9ae3a8
+
9ae3a8
 /*
9ae3a8
  * exam every page and return the page frame number and the address of the page.
9ae3a8
  * bufptr can be NULL. note: the blocks here is supposed to reflect guest-phys
9ae3a8
@@ -1006,16 +1027,16 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
9ae3a8
                           uint8_t **bufptr, DumpState *s)
9ae3a8
 {
9ae3a8
     GuestPhysBlock *block = *blockptr;
9ae3a8
-    hwaddr addr;
9ae3a8
+    hwaddr addr, target_page_mask = ~((hwaddr)s->dump_info.page_size - 1);
9ae3a8
     uint8_t *buf;
9ae3a8
 
9ae3a8
     /* block == NULL means the start of the iteration */
9ae3a8
     if (!block) {
9ae3a8
         block = QTAILQ_FIRST(&s->guest_phys_blocks.head);
9ae3a8
         *blockptr = block;
9ae3a8
-        assert((block->target_start & ~TARGET_PAGE_MASK) == 0);
9ae3a8
-        assert((block->target_end & ~TARGET_PAGE_MASK) == 0);
9ae3a8
-        *pfnptr = paddr_to_pfn(block->target_start);
9ae3a8
+        assert((block->target_start & ~target_page_mask) == 0);
9ae3a8
+        assert((block->target_end & ~target_page_mask) == 0);
9ae3a8
+        *pfnptr = dump_paddr_to_pfn(s, block->target_start);
9ae3a8
         if (bufptr) {
9ae3a8
             *bufptr = block->host_addr;
9ae3a8
         }
9ae3a8
@@ -1023,10 +1044,10 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
9ae3a8
     }
9ae3a8
 
9ae3a8
     *pfnptr = *pfnptr + 1;
9ae3a8
-    addr = pfn_to_paddr(*pfnptr);
9ae3a8
+    addr = dump_pfn_to_paddr(s, *pfnptr);
9ae3a8
 
9ae3a8
     if ((addr >= block->target_start) &&
9ae3a8
-        (addr + TARGET_PAGE_SIZE <= block->target_end)) {
9ae3a8
+        (addr + s->dump_info.page_size <= block->target_end)) {
9ae3a8
         buf = block->host_addr + (addr - block->target_start);
9ae3a8
     } else {
9ae3a8
         /* the next page is in the next block */
9ae3a8
@@ -1035,9 +1056,9 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
9ae3a8
         if (!block) {
9ae3a8
             return false;
9ae3a8
         }
9ae3a8
-        assert((block->target_start & ~TARGET_PAGE_MASK) == 0);
9ae3a8
-        assert((block->target_end & ~TARGET_PAGE_MASK) == 0);
9ae3a8
-        *pfnptr = paddr_to_pfn(block->target_start);
9ae3a8
+        assert((block->target_start & ~target_page_mask) == 0);
9ae3a8
+        assert((block->target_end & ~target_page_mask) == 0);
9ae3a8
+        *pfnptr = dump_paddr_to_pfn(s, block->target_start);
9ae3a8
         buf = block->host_addr;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -1055,9 +1076,11 @@ static void write_dump_bitmap(DumpState *s, Error **errp)
9ae3a8
     void *dump_bitmap_buf;
9ae3a8
     size_t num_dumpable;
9ae3a8
     GuestPhysBlock *block_iter = NULL;
9ae3a8
+    size_t bitmap_bufsize = dump_bitmap_get_bufsize(s);
9ae3a8
+    size_t bits_per_buf = bitmap_bufsize * CHAR_BIT;
9ae3a8
 
9ae3a8
     /* dump_bitmap_buf is used to store dump_bitmap temporarily */
9ae3a8
-    dump_bitmap_buf = g_malloc0(BUFSIZE_BITMAP);
9ae3a8
+    dump_bitmap_buf = g_malloc0(bitmap_bufsize);
9ae3a8
 
9ae3a8
     num_dumpable = 0;
9ae3a8
     last_pfn = 0;
9ae3a8
@@ -1079,11 +1102,11 @@ static void write_dump_bitmap(DumpState *s, Error **errp)
9ae3a8
 
9ae3a8
     /*
9ae3a8
      * set_dump_bitmap will always leave the recently set bit un-sync. Here we
9ae3a8
-     * set last_pfn + PFN_BUFBITMAP to 0 and those set but un-sync bit will be
9ae3a8
-     * synchronized into vmcore.
9ae3a8
+     * set the remaining bits from last_pfn to the end of the bitmap buffer to
9ae3a8
+     * 0. With those set, the un-sync bit will be synchronized into the vmcore.
9ae3a8
      */
9ae3a8
     if (num_dumpable > 0) {
9ae3a8
-        ret = set_dump_bitmap(last_pfn, last_pfn + PFN_BUFBITMAP, false,
9ae3a8
+        ret = set_dump_bitmap(last_pfn, last_pfn + bits_per_buf, false,
9ae3a8
                               dump_bitmap_buf, s);
9ae3a8
         if (ret < 0) {
9ae3a8
             dump_error(s, "dump: failed to sync dump_bitmap", errp);
9ae3a8
@@ -1103,8 +1126,8 @@ static void prepare_data_cache(DataCache *data_cache, DumpState *s,
9ae3a8
 {
9ae3a8
     data_cache->fd = s->fd;
9ae3a8
     data_cache->data_size = 0;
9ae3a8
-    data_cache->buf_size = BUFSIZE_DATA_CACHE;
9ae3a8
-    data_cache->buf = g_malloc0(BUFSIZE_DATA_CACHE);
9ae3a8
+    data_cache->buf_size = 4 * dump_bitmap_get_bufsize(s);
9ae3a8
+    data_cache->buf = g_malloc0(data_cache->buf_size);
9ae3a8
     data_cache->offset = offset;
9ae3a8
 }
9ae3a8
 
9ae3a8
@@ -1198,7 +1221,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
9ae3a8
     prepare_data_cache(&page_data, s, offset_data);
9ae3a8
 
9ae3a8
     /* prepare buffer to store compressed data */
9ae3a8
-    len_buf_out = get_len_buf_out(TARGET_PAGE_SIZE, s->flag_compress);
9ae3a8
+    len_buf_out = get_len_buf_out(s->dump_info.page_size, s->flag_compress);
9ae3a8
     assert(len_buf_out != 0);
9ae3a8
 
9ae3a8
 #ifdef CONFIG_LZO
9ae3a8
@@ -1211,19 +1234,19 @@ static void write_dump_pages(DumpState *s, Error **errp)
9ae3a8
      * init zero page's page_desc and page_data, because every zero page
9ae3a8
      * uses the same page_data
9ae3a8
      */
9ae3a8
-    pd_zero.size = cpu_to_dump32(s, TARGET_PAGE_SIZE);
9ae3a8
+    pd_zero.size = cpu_to_dump32(s, s->dump_info.page_size);
9ae3a8
     pd_zero.flags = cpu_to_dump32(s, 0);
9ae3a8
     pd_zero.offset = cpu_to_dump64(s, offset_data);
9ae3a8
     pd_zero.page_flags = cpu_to_dump64(s, 0);
9ae3a8
-    buf = g_malloc0(TARGET_PAGE_SIZE);
9ae3a8
-    ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
9ae3a8
+    buf = g_malloc0(s->dump_info.page_size);
9ae3a8
+    ret = write_cache(&page_data, buf, s->dump_info.page_size, false);
9ae3a8
     g_free(buf);
9ae3a8
     if (ret < 0) {
9ae3a8
         dump_error(s, "dump: failed to write page data (zero page)", errp);
9ae3a8
         goto out;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    offset_data += TARGET_PAGE_SIZE;
9ae3a8
+    offset_data += s->dump_info.page_size;
9ae3a8
 
9ae3a8
     /*
9ae3a8
      * dump memory to vmcore page by page. zero page will all be resided in the
9ae3a8
@@ -1231,7 +1254,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
9ae3a8
      */
9ae3a8
     while (get_next_page(&block_iter, &pfn_iter, &buf, s)) {
9ae3a8
         /* check zero page */
9ae3a8
-        if (is_zero_page(buf, TARGET_PAGE_SIZE)) {
9ae3a8
+        if (is_zero_page(buf, s->dump_info.page_size)) {
9ae3a8
             ret = write_cache(&page_desc, &pd_zero, sizeof(PageDescriptor),
9ae3a8
                               false);
9ae3a8
             if (ret < 0) {
9ae3a8
@@ -1253,8 +1276,8 @@ static void write_dump_pages(DumpState *s, Error **errp)
9ae3a8
              size_out = len_buf_out;
9ae3a8
              if ((s->flag_compress & DUMP_DH_COMPRESSED_ZLIB) &&
9ae3a8
                     (compress2(buf_out, (uLongf *)&size_out, buf,
9ae3a8
-                               TARGET_PAGE_SIZE, Z_BEST_SPEED) == Z_OK) &&
9ae3a8
-                    (size_out < TARGET_PAGE_SIZE)) {
9ae3a8
+                               s->dump_info.page_size, Z_BEST_SPEED) == Z_OK) &&
9ae3a8
+                    (size_out < s->dump_info.page_size)) {
9ae3a8
                 pd.flags = cpu_to_dump32(s, DUMP_DH_COMPRESSED_ZLIB);
9ae3a8
                 pd.size  = cpu_to_dump32(s, size_out);
9ae3a8
 
9ae3a8
@@ -1265,9 +1288,9 @@ static void write_dump_pages(DumpState *s, Error **errp)
9ae3a8
                 }
9ae3a8
 #ifdef CONFIG_LZO
9ae3a8
             } else if ((s->flag_compress & DUMP_DH_COMPRESSED_LZO) &&
9ae3a8
-                    (lzo1x_1_compress(buf, TARGET_PAGE_SIZE, buf_out,
9ae3a8
+                    (lzo1x_1_compress(buf, s->dump_info.page_size, buf_out,
9ae3a8
                     (lzo_uint *)&size_out, wrkmem) == LZO_E_OK) &&
9ae3a8
-                    (size_out < TARGET_PAGE_SIZE)) {
9ae3a8
+                    (size_out < s->dump_info.page_size)) {
9ae3a8
                 pd.flags = cpu_to_dump32(s, DUMP_DH_COMPRESSED_LZO);
9ae3a8
                 pd.size  = cpu_to_dump32(s, size_out);
9ae3a8
 
9ae3a8
@@ -1279,9 +1302,9 @@ static void write_dump_pages(DumpState *s, Error **errp)
9ae3a8
 #endif
9ae3a8
 #ifdef CONFIG_SNAPPY
9ae3a8
             } else if ((s->flag_compress & DUMP_DH_COMPRESSED_SNAPPY) &&
9ae3a8
-                    (snappy_compress((char *)buf, TARGET_PAGE_SIZE,
9ae3a8
+                    (snappy_compress((char *)buf, s->dump_info.page_size,
9ae3a8
                     (char *)buf_out, &size_out) == SNAPPY_OK) &&
9ae3a8
-                    (size_out < TARGET_PAGE_SIZE)) {
9ae3a8
+                    (size_out < s->dump_info.page_size)) {
9ae3a8
                 pd.flags = cpu_to_dump32(s, DUMP_DH_COMPRESSED_SNAPPY);
9ae3a8
                 pd.size  = cpu_to_dump32(s, size_out);
9ae3a8
 
9ae3a8
@@ -1294,13 +1317,14 @@ static void write_dump_pages(DumpState *s, Error **errp)
9ae3a8
             } else {
9ae3a8
                 /*
9ae3a8
                  * fall back to save in plaintext, size_out should be
9ae3a8
-                 * assigned TARGET_PAGE_SIZE
9ae3a8
+                 * assigned the target's page size
9ae3a8
                  */
9ae3a8
                 pd.flags = cpu_to_dump32(s, 0);
9ae3a8
-                size_out = TARGET_PAGE_SIZE;
9ae3a8
+                size_out = s->dump_info.page_size;
9ae3a8
                 pd.size = cpu_to_dump32(s, size_out);
9ae3a8
 
9ae3a8
-                ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
9ae3a8
+                ret = write_cache(&page_data, buf,
9ae3a8
+                                  s->dump_info.page_size, false);
9ae3a8
                 if (ret < 0) {
9ae3a8
                     dump_error(s, "dump: failed to write page data", errp);
9ae3a8
                     goto out;
9ae3a8
@@ -1435,7 +1459,7 @@ static void get_max_mapnr(DumpState *s)
9ae3a8
     GuestPhysBlock *last_block;
9ae3a8
 
9ae3a8
     last_block = QTAILQ_LAST(&s->guest_phys_blocks.head, GuestPhysBlockHead);
9ae3a8
-    s->max_mapnr = paddr_to_pfn(last_block->target_end);
9ae3a8
+    s->max_mapnr = dump_paddr_to_pfn(s, last_block->target_end);
9ae3a8
 }
9ae3a8
 
9ae3a8
 static void dump_init(DumpState *s, int fd, bool has_format,
9ae3a8
@@ -1494,6 +1518,10 @@ static void dump_init(DumpState *s, int fd, bool has_format,
9ae3a8
         goto cleanup;
9ae3a8
     }
9ae3a8
 
9ae3a8
+    if (!s->dump_info.page_size) {
9ae3a8
+        s->dump_info.page_size = TARGET_PAGE_SIZE;
9ae3a8
+    }
9ae3a8
+
9ae3a8
     s->note_size = cpu_get_note_size(s->dump_info.d_class,
9ae3a8
                                      s->dump_info.d_machine, nr_cpus);
9ae3a8
     if (s->note_size < 0) {
9ae3a8
@@ -1517,8 +1545,9 @@ static void dump_init(DumpState *s, int fd, bool has_format,
9ae3a8
     get_max_mapnr(s);
9ae3a8
 
9ae3a8
     uint64_t tmp;
9ae3a8
-    tmp = DIV_ROUND_UP(DIV_ROUND_UP(s->max_mapnr, CHAR_BIT), TARGET_PAGE_SIZE);
9ae3a8
-    s->len_dump_bitmap = tmp * TARGET_PAGE_SIZE;
9ae3a8
+    tmp = DIV_ROUND_UP(DIV_ROUND_UP(s->max_mapnr, CHAR_BIT),
9ae3a8
+                       s->dump_info.page_size);
9ae3a8
+    s->len_dump_bitmap = tmp * s->dump_info.page_size;
9ae3a8
 
9ae3a8
     /* init for kdump-compressed format */
9ae3a8
     if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
9ae3a8
diff --git a/include/sysemu/dump-arch.h b/include/sysemu/dump-arch.h
9ae3a8
index 9c95ced..4335839 100644
9ae3a8
--- a/include/sysemu/dump-arch.h
9ae3a8
+++ b/include/sysemu/dump-arch.h
9ae3a8
@@ -15,9 +15,11 @@
9ae3a8
 #define DUMP_ARCH_H
9ae3a8
 
9ae3a8
 typedef struct ArchDumpInfo {
9ae3a8
-    int d_machine;  /* Architecture */
9ae3a8
-    int d_endian;   /* ELFDATA2LSB or ELFDATA2MSB */
9ae3a8
-    int d_class;    /* ELFCLASS32 or ELFCLASS64 */
9ae3a8
+    int d_machine;           /* Architecture */
9ae3a8
+    int d_endian;            /* ELFDATA2LSB or ELFDATA2MSB */
9ae3a8
+    int d_class;             /* ELFCLASS32 or ELFCLASS64 */
9ae3a8
+    uint32_t page_size;      /* The target's page size. If it's variable and
9ae3a8
+                              * unknown, then this should be the maximum. */
9ae3a8
 } ArchDumpInfo;
9ae3a8
 
9ae3a8
 struct GuestPhysBlockList; /* memory_mapping.h */
9ae3a8
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
9ae3a8
index 7e4ec5c..16cbd8d 100644
9ae3a8
--- a/include/sysemu/dump.h
9ae3a8
+++ b/include/sysemu/dump.h
9ae3a8
@@ -20,12 +20,9 @@
9ae3a8
 #define VERSION_FLAT_HEADER         (1)    /* version of flattened format */
9ae3a8
 #define END_FLAG_FLAT_HEADER        (-1)
9ae3a8
 
9ae3a8
+#ifndef ARCH_PFN_OFFSET
9ae3a8
 #define ARCH_PFN_OFFSET             (0)
9ae3a8
-
9ae3a8
-#define paddr_to_pfn(X) \
9ae3a8
-    (((unsigned long long)(X) >> TARGET_PAGE_BITS) - ARCH_PFN_OFFSET)
9ae3a8
-#define pfn_to_paddr(X) \
9ae3a8
-    (((unsigned long long)(X) + ARCH_PFN_OFFSET) << TARGET_PAGE_BITS)
9ae3a8
+#endif
9ae3a8
 
9ae3a8
 /*
9ae3a8
  * flag for compressed format
9ae3a8
@@ -39,9 +36,6 @@
9ae3a8
 #define PHYS_BASE                   (0)
9ae3a8
 #define DUMP_LEVEL                  (1)
9ae3a8
 #define DISKDUMP_HEADER_BLOCKS      (1)
9ae3a8
-#define BUFSIZE_BITMAP              (TARGET_PAGE_SIZE)
9ae3a8
-#define PFN_BUFBITMAP               (CHAR_BIT * BUFSIZE_BITMAP)
9ae3a8
-#define BUFSIZE_DATA_CACHE          (TARGET_PAGE_SIZE * 4)
9ae3a8
 
9ae3a8
 #include "sysemu/dump-arch.h"
9ae3a8
 #include "sysemu/memory_mapping.h"
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8