thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-dump-Introduce-shdr_num-to-decrease-complexity.patch

bf143f
From 255722667a4fa4d522bb0b7e0825cbbe635abb8d Mon Sep 17 00:00:00 2001
bf143f
From: Janosch Frank <frankja@linux.ibm.com>
bf143f
Date: Wed, 30 Mar 2022 12:35:57 +0000
bf143f
Subject: [PATCH 15/42] dump: Introduce shdr_num to decrease complexity
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: [15/41] b0215ea5d381ef7f6abfe3f3bafea51ce933da56
bf143f
bf143f
Let's move from a boolean to a int variable which will later enable us
bf143f
to store the number of sections that are in the dump file.
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-4-frankja@linux.ibm.com>
bf143f
(cherry picked from commit 862a395858e5a302ed5921487777acdc95a3a31b)
bf143f
Signed-off-by: Cédric Le Goater <clg@redhat.com>
bf143f
---
bf143f
 dump/dump.c           | 24 ++++++++++++------------
bf143f
 include/sysemu/dump.h |  2 +-
bf143f
 2 files changed, 13 insertions(+), 13 deletions(-)
bf143f
bf143f
diff --git a/dump/dump.c b/dump/dump.c
bf143f
index 7236b167cc..972e28b089 100644
bf143f
--- a/dump/dump.c
bf143f
+++ b/dump/dump.c
bf143f
@@ -145,12 +145,12 @@ static void write_elf64_header(DumpState *s, Error **errp)
bf143f
     elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
bf143f
     elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
bf143f
     elf_header.e_phnum = cpu_to_dump16(s, phnum);
bf143f
-    if (s->have_section) {
bf143f
+    if (s->shdr_num) {
bf143f
         uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num;
bf143f
 
bf143f
         elf_header.e_shoff = cpu_to_dump64(s, shoff);
bf143f
         elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
bf143f
-        elf_header.e_shnum = cpu_to_dump16(s, 1);
bf143f
+        elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
bf143f
     }
bf143f
 
bf143f
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
bf143f
@@ -182,12 +182,12 @@ static void write_elf32_header(DumpState *s, Error **errp)
bf143f
     elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
bf143f
     elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
bf143f
     elf_header.e_phnum = cpu_to_dump16(s, phnum);
bf143f
-    if (s->have_section) {
bf143f
+    if (s->shdr_num) {
bf143f
         uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num;
bf143f
 
bf143f
         elf_header.e_shoff = cpu_to_dump32(s, shoff);
bf143f
         elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
bf143f
-        elf_header.e_shnum = cpu_to_dump16(s, 1);
bf143f
+        elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
bf143f
     }
bf143f
 
bf143f
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
bf143f
@@ -566,7 +566,7 @@ static void dump_begin(DumpState *s, Error **errp)
bf143f
         }
bf143f
 
bf143f
         /* write section to vmcore */
bf143f
-        if (s->have_section) {
bf143f
+        if (s->shdr_num) {
bf143f
             write_elf_section(s, 1, errp);
bf143f
             if (*errp) {
bf143f
                 return;
bf143f
@@ -592,7 +592,7 @@ static void dump_begin(DumpState *s, Error **errp)
bf143f
         }
bf143f
 
bf143f
         /* write section to vmcore */
bf143f
-        if (s->have_section) {
bf143f
+        if (s->shdr_num) {
bf143f
             write_elf_section(s, 0, errp);
bf143f
             if (*errp) {
bf143f
                 return;
bf143f
@@ -1811,11 +1811,11 @@ static void dump_init(DumpState *s, int fd, bool has_format,
bf143f
      */
bf143f
     s->phdr_num = 1; /* PT_NOTE */
bf143f
     if (s->list.num < UINT16_MAX - 2) {
bf143f
+        s->shdr_num = 0;
bf143f
         s->phdr_num += s->list.num;
bf143f
-        s->have_section = false;
bf143f
     } else {
bf143f
         /* sh_info of section 0 holds the real number of phdrs */
bf143f
-        s->have_section = true;
bf143f
+        s->shdr_num = 1;
bf143f
 
bf143f
         /* the type of shdr->sh_info is uint32_t, so we should avoid overflow */
bf143f
         if (s->list.num <= UINT32_MAX - 1) {
bf143f
@@ -1826,19 +1826,19 @@ static void dump_init(DumpState *s, int fd, bool has_format,
bf143f
     }
bf143f
 
bf143f
     if (s->dump_info.d_class == ELFCLASS64) {
bf143f
-        if (s->have_section) {
bf143f
+        if (s->shdr_num) {
bf143f
             s->memory_offset = sizeof(Elf64_Ehdr) +
bf143f
                                sizeof(Elf64_Phdr) * s->phdr_num +
bf143f
-                               sizeof(Elf64_Shdr) + s->note_size;
bf143f
+                               sizeof(Elf64_Shdr) * s->shdr_num + s->note_size;
bf143f
         } else {
bf143f
             s->memory_offset = sizeof(Elf64_Ehdr) +
bf143f
                                sizeof(Elf64_Phdr) * s->phdr_num + s->note_size;
bf143f
         }
bf143f
     } else {
bf143f
-        if (s->have_section) {
bf143f
+        if (s->shdr_num) {
bf143f
             s->memory_offset = sizeof(Elf32_Ehdr) +
bf143f
                                sizeof(Elf32_Phdr) * s->phdr_num +
bf143f
-                               sizeof(Elf32_Shdr) + s->note_size;
bf143f
+                               sizeof(Elf32_Shdr) * s->shdr_num + s->note_size;
bf143f
         } else {
bf143f
             s->memory_offset = sizeof(Elf32_Ehdr) +
bf143f
                                sizeof(Elf32_Phdr) * s->phdr_num + s->note_size;
bf143f
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
bf143f
index b463fc9c02..19458bffbd 100644
bf143f
--- a/include/sysemu/dump.h
bf143f
+++ b/include/sysemu/dump.h
bf143f
@@ -155,7 +155,7 @@ typedef struct DumpState {
bf143f
     ArchDumpInfo dump_info;
bf143f
     MemoryMappingList list;
bf143f
     uint32_t phdr_num;
bf143f
-    bool have_section;
bf143f
+    uint32_t shdr_num;
bf143f
     bool resume;
bf143f
     bool detached;
bf143f
     ssize_t note_size;
bf143f
-- 
bf143f
2.37.3
bf143f