|
|
9ae3a8 |
From 3555c9b0e05c410028022a1b1af34ad7a2e83e98 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
Date: Fri, 7 Nov 2014 17:17:59 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 12/41] dump: add API to write dump_bitmap
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1415380693-16593-13-git-send-email-lersek@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 62198
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1 qemu-kvm PATCH 12/26] dump: add API to write dump_bitmap
|
|
|
9ae3a8 |
Bugzilla: 1157798
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: dgibson <dgibson@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: qiaonuohan <qiaonuohan@cn.fujitsu.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
functions are used to write 1st and 2nd dump_bitmap of kdump-compressed format,
|
|
|
9ae3a8 |
which is used to indicate whether the corresponded page is existed in vmcore.
|
|
|
9ae3a8 |
1st and 2nd dump_bitmap are same, because dump level is specified to 1 here.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
|
|
|
9ae3a8 |
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit d0686c7291fe8f0210e7a666f80892fa71395510)
|
|
|
9ae3a8 |
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
dump.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
include/sysemu/dump.h | 2 +
|
|
|
9ae3a8 |
2 files changed, 166 insertions(+)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/dump.c b/dump.c
|
|
|
9ae3a8 |
index 4d135fd..f416093 100644
|
|
|
9ae3a8 |
--- a/dump.c
|
|
|
9ae3a8 |
+++ b/dump.c
|
|
|
9ae3a8 |
@@ -1007,6 +1007,170 @@ static int write_dump_header(DumpState *s)
|
|
|
9ae3a8 |
}
|
|
|
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 |
+ * set_dump_bitmap will always leave the recently set bit un-sync. And setting
|
|
|
9ae3a8 |
+ * (last bit + sizeof(buf) * 8) to 0 will do flushing the content in buf into
|
|
|
9ae3a8 |
+ * vmcore, ie. synchronizing un-sync bit into vmcore.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+static int set_dump_bitmap(uint64_t last_pfn, uint64_t pfn, bool value,
|
|
|
9ae3a8 |
+ uint8_t *buf, DumpState *s)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ off_t old_offset, new_offset;
|
|
|
9ae3a8 |
+ off_t offset_bitmap1, offset_bitmap2;
|
|
|
9ae3a8 |
+ uint32_t byte, bit;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* should not set the previous place */
|
|
|
9ae3a8 |
+ assert(last_pfn <= pfn);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /*
|
|
|
9ae3a8 |
+ * if the bit needed to be set is not cached in buf, flush the data in buf
|
|
|
9ae3a8 |
+ * to vmcore firstly.
|
|
|
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 |
+
|
|
|
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 |
+ return -1;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* dump level 1 is chosen, so 1st and 2nd bitmap are same */
|
|
|
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 |
+ return -1;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ memset(buf, 0, BUFSIZE_BITMAP);
|
|
|
9ae3a8 |
+ old_offset += BUFSIZE_BITMAP;
|
|
|
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 |
+ if (value) {
|
|
|
9ae3a8 |
+ buf[byte] |= 1u << bit;
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ buf[byte] &= ~(1u << bit);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return 0;
|
|
|
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 |
+ * blocks, so block->target_start and block->target_end should be interal
|
|
|
9ae3a8 |
+ * multiples of the target page size.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+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 |
+ 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 % s->page_size == 0);
|
|
|
9ae3a8 |
+ assert(block->target_end % s->page_size == 0);
|
|
|
9ae3a8 |
+ *pfnptr = paddr_to_pfn(block->target_start, s->page_shift);
|
|
|
9ae3a8 |
+ if (bufptr) {
|
|
|
9ae3a8 |
+ *bufptr = block->host_addr;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return true;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ *pfnptr = *pfnptr + 1;
|
|
|
9ae3a8 |
+ addr = pfn_to_paddr(*pfnptr, s->page_shift);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if ((addr >= block->target_start) &&
|
|
|
9ae3a8 |
+ (addr + s->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 |
+ block = QTAILQ_NEXT(block, next);
|
|
|
9ae3a8 |
+ *blockptr = block;
|
|
|
9ae3a8 |
+ if (!block) {
|
|
|
9ae3a8 |
+ return false;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ assert(block->target_start % s->page_size == 0);
|
|
|
9ae3a8 |
+ assert(block->target_end % s->page_size == 0);
|
|
|
9ae3a8 |
+ *pfnptr = paddr_to_pfn(block->target_start, s->page_shift);
|
|
|
9ae3a8 |
+ buf = block->host_addr;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bufptr) {
|
|
|
9ae3a8 |
+ *bufptr = buf;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return true;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static int write_dump_bitmap(DumpState *s)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int ret = 0;
|
|
|
9ae3a8 |
+ uint64_t last_pfn, pfn;
|
|
|
9ae3a8 |
+ void *dump_bitmap_buf;
|
|
|
9ae3a8 |
+ size_t num_dumpable;
|
|
|
9ae3a8 |
+ GuestPhysBlock *block_iter = NULL;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* dump_bitmap_buf is used to store dump_bitmap temporarily */
|
|
|
9ae3a8 |
+ dump_bitmap_buf = g_malloc0(BUFSIZE_BITMAP);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ num_dumpable = 0;
|
|
|
9ae3a8 |
+ last_pfn = 0;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /*
|
|
|
9ae3a8 |
+ * exam memory page by page, and set the bit in dump_bitmap corresponded
|
|
|
9ae3a8 |
+ * to the existing page.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ while (get_next_page(&block_iter, &pfn, NULL, s)) {
|
|
|
9ae3a8 |
+ ret = set_dump_bitmap(last_pfn, pfn, true, dump_bitmap_buf, s);
|
|
|
9ae3a8 |
+ if (ret < 0) {
|
|
|
9ae3a8 |
+ dump_error(s, "dump: failed to set dump_bitmap.\n");
|
|
|
9ae3a8 |
+ ret = -1;
|
|
|
9ae3a8 |
+ goto out;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ last_pfn = pfn;
|
|
|
9ae3a8 |
+ num_dumpable++;
|
|
|
9ae3a8 |
+ }
|
|
|
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 |
+ */
|
|
|
9ae3a8 |
+ if (num_dumpable > 0) {
|
|
|
9ae3a8 |
+ ret = set_dump_bitmap(last_pfn, last_pfn + PFN_BUFBITMAP, false,
|
|
|
9ae3a8 |
+ dump_bitmap_buf, s);
|
|
|
9ae3a8 |
+ if (ret < 0) {
|
|
|
9ae3a8 |
+ dump_error(s, "dump: failed to sync dump_bitmap.\n");
|
|
|
9ae3a8 |
+ ret = -1;
|
|
|
9ae3a8 |
+ goto out;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* number of dumpable pages that will be dumped later */
|
|
|
9ae3a8 |
+ s->num_dumpable = num_dumpable;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+out:
|
|
|
9ae3a8 |
+ g_free(dump_bitmap_buf);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static ram_addr_t get_start_block(DumpState *s)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
GuestPhysBlock *block;
|
|
|
9ae3a8 |
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
|
|
|
9ae3a8 |
index dfee238..6d4d0bc 100644
|
|
|
9ae3a8 |
--- a/include/sysemu/dump.h
|
|
|
9ae3a8 |
+++ b/include/sysemu/dump.h
|
|
|
9ae3a8 |
@@ -39,6 +39,8 @@
|
|
|
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 |
|
|
|
9ae3a8 |
typedef struct ArchDumpInfo {
|
|
|
9ae3a8 |
int d_machine; /* Architecture */
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|