thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
bf143f
From c851676d202b5b76962529f3b6d433936becbd8a Mon Sep 17 00:00:00 2001
bf143f
From: Janosch Frank <frankja@linux.ibm.com>
bf143f
Date: Wed, 30 Mar 2022 12:36:00 +0000
bf143f
Subject: [PATCH 18/42] dump: Introduce dump_is_64bit() helper function
bf143f
MIME-Version: 1.0
bf143f
Content-Type: text/plain; charset=UTF-8
bf143f
Content-Transfer-Encoding: 8bit
bf143f
bf143f
RH-Author: Cédric Le Goater <clg@redhat.com>
bf143f
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
bf143f
RH-Bugzilla: 1664378 2043909
bf143f
RH-Acked-by: Thomas Huth <thuth@redhat.com>
bf143f
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
bf143f
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
bf143f
RH-Commit: [18/41] a0fd2d1985c61b8e50d4a7ca26bc0ee6fcaa6196
bf143f
bf143f
Checking d_class in dump_info leads to lengthy conditionals so let's
bf143f
shorten things a bit by introducing a helper function.
bf143f
bf143f
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
bf143f
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
bf143f
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
bf143f
Message-Id: <20220330123603.107120-7-frankja@linux.ibm.com>
bf143f
(cherry picked from commit 05bbaa5040ccb3419e8b93af8040485430e2db42)
bf143f
Signed-off-by: Cédric Le Goater <clg@redhat.com>
bf143f
---
bf143f
 dump/dump.c | 25 +++++++++++++++----------
bf143f
 1 file changed, 15 insertions(+), 10 deletions(-)
bf143f
bf143f
diff --git a/dump/dump.c b/dump/dump.c
bf143f
index 85a402b38c..6394e94023 100644
bf143f
--- a/dump/dump.c
bf143f
+++ b/dump/dump.c
bf143f
@@ -55,6 +55,11 @@ static Error *dump_migration_blocker;
bf143f
       DIV_ROUND_UP((name_size), 4) +                    \
bf143f
       DIV_ROUND_UP((desc_size), 4)) * 4)
bf143f
 
bf143f
+static inline bool dump_is_64bit(DumpState *s)
bf143f
+{
bf143f
+    return s->dump_info.d_class == ELFCLASS64;
bf143f
+}
bf143f
+
bf143f
 uint16_t cpu_to_dump16(DumpState *s, uint16_t val)
bf143f
 {
bf143f
     if (s->dump_info.d_endian == ELFDATA2LSB) {
bf143f
@@ -489,7 +494,7 @@ static void write_elf_loads(DumpState *s, Error **errp)
bf143f
         get_offset_range(memory_mapping->phys_addr,
bf143f
                          memory_mapping->length,
bf143f
                          s, &offset, &filesz);
bf143f
-        if (s->dump_info.d_class == ELFCLASS64) {
bf143f
+        if (dump_is_64bit(s)) {
bf143f
             write_elf64_load(s, memory_mapping, phdr_index++, offset,
bf143f
                              filesz, errp);
bf143f
         } else {
bf143f
@@ -537,7 +542,7 @@ static void dump_begin(DumpState *s, Error **errp)
bf143f
      */
bf143f
 
bf143f
     /* write elf header to vmcore */
bf143f
-    if (s->dump_info.d_class == ELFCLASS64) {
bf143f
+    if (dump_is_64bit(s)) {
bf143f
         write_elf64_header(s, errp);
bf143f
     } else {
bf143f
         write_elf32_header(s, errp);
bf143f
@@ -546,7 +551,7 @@ static void dump_begin(DumpState *s, Error **errp)
bf143f
         return;
bf143f
     }
bf143f
 
bf143f
-    if (s->dump_info.d_class == ELFCLASS64) {
bf143f
+    if (dump_is_64bit(s)) {
bf143f
         /* write PT_NOTE to vmcore */
bf143f
         write_elf64_note(s, errp);
bf143f
         if (*errp) {
bf143f
@@ -757,7 +762,7 @@ static void get_note_sizes(DumpState *s, const void *note,
bf143f
     uint64_t name_sz;
bf143f
     uint64_t desc_sz;
bf143f
 
bf143f
-    if (s->dump_info.d_class == ELFCLASS64) {
bf143f
+    if (dump_is_64bit(s)) {
bf143f
         const Elf64_Nhdr *hdr = note;
bf143f
         note_head_sz = sizeof(Elf64_Nhdr);
bf143f
         name_sz = tswap64(hdr->n_namesz);
bf143f
@@ -1017,10 +1022,10 @@ out:
bf143f
 
bf143f
 static void write_dump_header(DumpState *s, Error **errp)
bf143f
 {
bf143f
-    if (s->dump_info.d_class == ELFCLASS32) {
bf143f
-        create_header32(s, errp);
bf143f
-    } else {
bf143f
+    if (dump_is_64bit(s)) {
bf143f
         create_header64(s, errp);
bf143f
+    } else {
bf143f
+        create_header32(s, errp);
bf143f
     }
bf143f
 }
bf143f
 
bf143f
@@ -1715,8 +1720,8 @@ static void dump_init(DumpState *s, int fd, bool has_format,
bf143f
         uint32_t size;
bf143f
         uint16_t format;
bf143f
 
bf143f
-        note_head_size = s->dump_info.d_class == ELFCLASS32 ?
bf143f
-            sizeof(Elf32_Nhdr) : sizeof(Elf64_Nhdr);
bf143f
+        note_head_size = dump_is_64bit(s) ?
bf143f
+            sizeof(Elf64_Nhdr) : sizeof(Elf32_Nhdr);
bf143f
 
bf143f
         format = le16_to_cpu(vmci->vmcoreinfo.guest_format);
bf143f
         size = le32_to_cpu(vmci->vmcoreinfo.size);
bf143f
@@ -1819,7 +1824,7 @@ static void dump_init(DumpState *s, int fd, bool has_format,
bf143f
         }
bf143f
     }
bf143f
 
bf143f
-    if (s->dump_info.d_class == ELFCLASS64) {
bf143f
+    if (dump_is_64bit(s)) {
bf143f
         s->phdr_offset = sizeof(Elf64_Ehdr);
bf143f
         s->shdr_offset = s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_num;
bf143f
         s->note_offset = s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_num;
bf143f
-- 
bf143f
2.37.3
bf143f