Re: [Qemu-devel] [PATCH v3 3/9] dump: allow target to set the page size

2015-12-18 Thread Peter Maydell
On 15 December 2015 at 22:51, Andrew Jones  wrote:
> This is necessary for targets that don't have TARGET_PAGE_SIZE ==
> real-target-page-size. The target should set the page size to the
> correct one, if known, or, if not known, to the maximum page size
> it supports.
>
> (No functional change.)
>
> Signed-off-by: Andrew Jones 

Reviewed-by: Peter Maydell 

thanks
-- PMM



[Qemu-devel] [PATCH v3 3/9] dump: allow target to set the page size

2015-12-15 Thread Andrew Jones
This is necessary for targets that don't have TARGET_PAGE_SIZE ==
real-target-page-size. The target should set the page size to the
correct one, if known, or, if not known, to the maximum page size
it supports.

(No functional change.)

Signed-off-by: Andrew Jones 
---
 dump.c | 127 -
 include/sysemu/dump-arch.h |   8 +--
 include/sysemu/dump.h  |  10 +---
 3 files changed, 85 insertions(+), 60 deletions(-)

diff --git a/dump.c b/dump.c
index 78b7d843ceb29..e1d9bae9e89d1 100644
--- a/dump.c
+++ b/dump.c
@@ -347,18 +347,18 @@ static void write_memory(DumpState *s, GuestPhysBlock 
*block, ram_addr_t start,
 int64_t i;
 Error *local_err = NULL;
 
-for (i = 0; i < size / TARGET_PAGE_SIZE; i++) {
-write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
-   TARGET_PAGE_SIZE, &local_err);
+for (i = 0; i < size / s->dump_info.page_size; i++) {
+write_data(s, block->host_addr + start + i * s->dump_info.page_size,
+   s->dump_info.page_size, &local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 return;
 }
 }
 
-if ((size % TARGET_PAGE_SIZE) != 0) {
-write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
-   size % TARGET_PAGE_SIZE, &local_err);
+if ((size % s->dump_info.page_size) != 0) {
+write_data(s, block->host_addr + start + i * s->dump_info.page_size,
+   size % s->dump_info.page_size, &local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 return;
@@ -737,7 +737,7 @@ static void create_header32(DumpState *s, Error **errp)
 
 strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
 dh->header_version = cpu_to_dump32(s, 6);
-block_size = TARGET_PAGE_SIZE;
+block_size = s->dump_info.page_size;
 dh->block_size = cpu_to_dump32(s, block_size);
 sub_hdr_size = sizeof(struct KdumpSubHeader32) + s->note_size;
 sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);
@@ -837,7 +837,7 @@ static void create_header64(DumpState *s, Error **errp)
 
 strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
 dh->header_version = cpu_to_dump32(s, 6);
-block_size = TARGET_PAGE_SIZE;
+block_size = s->dump_info.page_size;
 dh->block_size = cpu_to_dump32(s, block_size);
 sub_hdr_size = sizeof(struct KdumpSubHeader64) + s->note_size;
 sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);
@@ -933,6 +933,11 @@ static void write_dump_header(DumpState *s, Error **errp)
 }
 }
 
+static size_t dump_bitmap_get_bufsize(DumpState *s)
+{
+return s->dump_info.page_size;
+}
+
 /*
  * set dump_bitmap sequencely. the bit before last_pfn is not allowed to be
  * rewritten, so if need to set the first bit, set last_pfn and pfn to 0.
@@ -946,6 +951,8 @@ static int set_dump_bitmap(uint64_t last_pfn, uint64_t pfn, 
bool value,
 off_t old_offset, new_offset;
 off_t offset_bitmap1, offset_bitmap2;
 uint32_t byte, bit;
+size_t bitmap_bufsize = dump_bitmap_get_bufsize(s);
+size_t bits_per_buf = bitmap_bufsize * CHAR_BIT;
 
 /* should not set the previous place */
 assert(last_pfn <= pfn);
@@ -956,14 +963,14 @@ static int set_dump_bitmap(uint64_t last_pfn, uint64_t 
pfn, bool value,
  * making new_offset be bigger than old_offset can also sync remained data
  * into vmcore.
  */
-old_offset = BUFSIZE_BITMAP * (last_pfn / PFN_BUFBITMAP);
-new_offset = BUFSIZE_BITMAP * (pfn / PFN_BUFBITMAP);
+old_offset = bitmap_bufsize * (last_pfn / bits_per_buf);
+new_offset = bitmap_bufsize * (pfn / bits_per_buf);
 
 while (old_offset < new_offset) {
 /* calculate the offset and write dump_bitmap */
 offset_bitmap1 = s->offset_dump_bitmap + old_offset;
 if (write_buffer(s->fd, offset_bitmap1, buf,
- BUFSIZE_BITMAP) < 0) {
+ bitmap_bufsize) < 0) {
 return -1;
 }
 
@@ -971,17 +978,17 @@ static int set_dump_bitmap(uint64_t last_pfn, uint64_t 
pfn, bool value,
 offset_bitmap2 = s->offset_dump_bitmap + s->len_dump_bitmap +
  old_offset;
 if (write_buffer(s->fd, offset_bitmap2, buf,
- BUFSIZE_BITMAP) < 0) {
+ bitmap_bufsize) < 0) {
 return -1;
 }
 
-memset(buf, 0, BUFSIZE_BITMAP);
-old_offset += BUFSIZE_BITMAP;
+memset(buf, 0, bitmap_bufsize);
+old_offset += bitmap_bufsize;
 }
 
 /* get the exact place of the bit in the buf, and set it */
-byte = (pfn % PFN_BUFBITMAP) / CHAR_BIT;
-bit = (pfn % PFN_BUFBITMAP) % CHAR_BIT;
+byte = (pfn % bits_per_buf) / CHAR_BIT;
+bit = (pfn % bits_per_buf) % CHAR_BIT;
 if (value) {
 buf[byte] |= 1u << bit;
 } else {
@@ -991,6 +998,20 @@ stati