qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: qemu-devel@nongnu.org, Luiz Capitulino <lcapitulino@redhat.com>,
	Qiao Nuohan <qiaonuohan@cn.fujitsu.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 3/7] dump: eliminate DumpState.page_shift ("guest's page shift")
Date: Tue, 20 May 2014 13:39:43 +0200	[thread overview]
Message-ID: <1400585987-6285-4-git-send-email-lersek@redhat.com> (raw)
In-Reply-To: <1400585987-6285-1-git-send-email-lersek@redhat.com>

Just use TARGET_PAGE_BITS.

"DumpState.page_shift" used to have type "uint32_t", while the replacement
TARGET_PAGE_BITS has type "int". Since "DumpState.page_shift" was only
used as bit shift counts in the paddr_to_pfn() and pfn_to_paddr() macros,
this is safe.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 include/sysemu/dump.h |  8 ++++----
 dump.c                | 10 ++++------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index efab7a3..12af557 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -20,14 +20,14 @@
 #define VERSION_FLAT_HEADER         (1)    /* version of flattened format */
 #define END_FLAG_FLAT_HEADER        (-1)
 
 #define ARCH_PFN_OFFSET             (0)
 
-#define paddr_to_pfn(X, page_shift) \
-    (((unsigned long long)(X) >> (page_shift)) - ARCH_PFN_OFFSET)
-#define pfn_to_paddr(X, page_shift) \
-    (((unsigned long long)(X) + ARCH_PFN_OFFSET) << (page_shift))
+#define paddr_to_pfn(X) \
+    (((unsigned long long)(X) >> TARGET_PAGE_BITS) - ARCH_PFN_OFFSET)
+#define pfn_to_paddr(X) \
+    (((unsigned long long)(X) + ARCH_PFN_OFFSET) << TARGET_PAGE_BITS)
 
 /*
  * flag for compressed format
  */
 #define DUMP_DH_COMPRESSED_ZLIB     (0x1)
diff --git a/dump.c b/dump.c
index 6dec8d2..cde14d9 100644
--- a/dump.c
+++ b/dump.c
@@ -89,11 +89,10 @@ typedef struct DumpState {
 
     uint8_t *note_buf;          /* buffer for notes */
     size_t note_buf_offset;     /* the writing place in note_buf */
     uint32_t nr_cpus;           /* number of guest's cpu */
     size_t page_size;           /* guest's page size */
-    uint32_t page_shift;        /* guest's page shift */
     uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
     size_t len_dump_bitmap;     /* the size of the place used to store
                                    dump_bitmap in vmcore */
     off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
     off_t offset_page;          /* offset of page part in vmcore */
@@ -1084,19 +1083,19 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
     if (!block) {
         block = QTAILQ_FIRST(&s->guest_phys_blocks.head);
         *blockptr = block;
         assert(block->target_start % s->page_size == 0);
         assert(block->target_end % s->page_size == 0);
-        *pfnptr = paddr_to_pfn(block->target_start, s->page_shift);
+        *pfnptr = paddr_to_pfn(block->target_start);
         if (bufptr) {
             *bufptr = block->host_addr;
         }
         return true;
     }
 
     *pfnptr = *pfnptr + 1;
-    addr = pfn_to_paddr(*pfnptr, s->page_shift);
+    addr = pfn_to_paddr(*pfnptr);
 
     if ((addr >= block->target_start) &&
         (addr + s->page_size <= block->target_end)) {
         buf = block->host_addr + (addr - block->target_start);
     } else {
@@ -1106,11 +1105,11 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
         if (!block) {
             return false;
         }
         assert(block->target_start % s->page_size == 0);
         assert(block->target_end % s->page_size == 0);
-        *pfnptr = paddr_to_pfn(block->target_start, s->page_shift);
+        *pfnptr = paddr_to_pfn(block->target_start);
         buf = block->host_addr;
     }
 
     if (bufptr) {
         *bufptr = buf;
@@ -1532,11 +1531,11 @@ static ram_addr_t get_start_block(DumpState *s)
 static void get_max_mapnr(DumpState *s)
 {
     GuestPhysBlock *last_block;
 
     last_block = QTAILQ_LAST(&s->guest_phys_blocks.head, GuestPhysBlockHead);
-    s->max_mapnr = paddr_to_pfn(last_block->target_end, s->page_shift);
+    s->max_mapnr = paddr_to_pfn(last_block->target_end);
 }
 
 static int dump_init(DumpState *s, int fd, bool has_format,
                      DumpGuestMemoryFormat format, bool paging, bool has_filter,
                      int64_t begin, int64_t length, Error **errp)
@@ -1610,11 +1609,10 @@ static int dump_init(DumpState *s, int fd, bool has_format,
         qemu_get_guest_simple_memory_mapping(&s->list, &s->guest_phys_blocks);
     }
 
     s->nr_cpus = nr_cpus;
     s->page_size = TARGET_PAGE_SIZE;
-    s->page_shift = ffs(s->page_size) - 1;
 
     get_max_mapnr(s);
 
     uint64_t tmp;
     tmp = DIV_ROUND_UP(DIV_ROUND_UP(s->max_mapnr, CHAR_BIT), s->page_size);
-- 
1.8.3.1

  reply	other threads:[~2014-05-20 11:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-20 11:39 [Qemu-devel] [PATCH 0/7] cleanups for compressed dumps (kdumps) Laszlo Ersek
2014-05-20 11:39 ` Laszlo Ersek [this message]
2014-05-20 11:39 ` [Qemu-devel] [PATCH 4/7] dump: eliminate DumpState.page_size ("guest's page size") Laszlo Ersek
2014-05-20 11:39 ` [Qemu-devel] [PATCH 5/7] dump: select header bitness based on ELF class, not ELF architecture Laszlo Ersek
2014-05-20 11:42 ` [Qemu-devel] [PATCH 6/7] dump: hoist lzo_init() from get_len_buf_out() to dump_init() Laszlo Ersek
2014-05-20 11:42 ` [Qemu-devel] [PATCH 7/7] dump: simplify get_len_buf_out() Laszlo Ersek
2014-05-20 12:56 ` [Qemu-devel] [PATCH 0/7] cleanups for compressed dumps (kdumps) Paolo Bonzini
2014-05-20 13:03   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400585987-6285-4-git-send-email-lersek@redhat.com \
    --to=lersek@redhat.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qiaonuohan@cn.fujitsu.com \
    --cc=tumanova@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).