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

97168e
From 255722667a4fa4d522bb0b7e0825cbbe635abb8d Mon Sep 17 00:00:00 2001
97168e
From: Janosch Frank <frankja@linux.ibm.com>
97168e
Date: Wed, 30 Mar 2022 12:35:57 +0000
97168e
Subject: [PATCH 15/42] dump: Introduce shdr_num to decrease complexity
97168e
MIME-Version: 1.0
97168e
Content-Type: text/plain; charset=UTF-8
97168e
Content-Transfer-Encoding: 8bit
97168e
97168e
RH-Author: Cédric Le Goater <clg@redhat.com>
97168e
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
97168e
RH-Bugzilla: 1664378 2043909
97168e
RH-Acked-by: Thomas Huth <thuth@redhat.com>
97168e
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
97168e
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
97168e
RH-Commit: [15/41] b0215ea5d381ef7f6abfe3f3bafea51ce933da56
97168e
97168e
Let's move from a boolean to a int variable which will later enable us
97168e
to store the number of sections that are in the dump file.
97168e
97168e
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
97168e
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
97168e
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
97168e
Message-Id: <20220330123603.107120-4-frankja@linux.ibm.com>
97168e
(cherry picked from commit 862a395858e5a302ed5921487777acdc95a3a31b)
97168e
Signed-off-by: Cédric Le Goater <clg@redhat.com>
97168e
---
97168e
 dump/dump.c           | 24 ++++++++++++------------
97168e
 include/sysemu/dump.h |  2 +-
97168e
 2 files changed, 13 insertions(+), 13 deletions(-)
97168e
97168e
diff --git a/dump/dump.c b/dump/dump.c
97168e
index 7236b167cc..972e28b089 100644
97168e
--- a/dump/dump.c
97168e
+++ b/dump/dump.c
97168e
@@ -145,12 +145,12 @@ static void write_elf64_header(DumpState *s, Error **errp)
97168e
     elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
97168e
     elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
97168e
     elf_header.e_phnum = cpu_to_dump16(s, phnum);
97168e
-    if (s->have_section) {
97168e
+    if (s->shdr_num) {
97168e
         uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num;
97168e
 
97168e
         elf_header.e_shoff = cpu_to_dump64(s, shoff);
97168e
         elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
97168e
-        elf_header.e_shnum = cpu_to_dump16(s, 1);
97168e
+        elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
97168e
     }
97168e
 
97168e
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
97168e
@@ -182,12 +182,12 @@ static void write_elf32_header(DumpState *s, Error **errp)
97168e
     elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
97168e
     elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
97168e
     elf_header.e_phnum = cpu_to_dump16(s, phnum);
97168e
-    if (s->have_section) {
97168e
+    if (s->shdr_num) {
97168e
         uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num;
97168e
 
97168e
         elf_header.e_shoff = cpu_to_dump32(s, shoff);
97168e
         elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
97168e
-        elf_header.e_shnum = cpu_to_dump16(s, 1);
97168e
+        elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
97168e
     }
97168e
 
97168e
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
97168e
@@ -566,7 +566,7 @@ static void dump_begin(DumpState *s, Error **errp)
97168e
         }
97168e
 
97168e
         /* write section to vmcore */
97168e
-        if (s->have_section) {
97168e
+        if (s->shdr_num) {
97168e
             write_elf_section(s, 1, errp);
97168e
             if (*errp) {
97168e
                 return;
97168e
@@ -592,7 +592,7 @@ static void dump_begin(DumpState *s, Error **errp)
97168e
         }
97168e
 
97168e
         /* write section to vmcore */
97168e
-        if (s->have_section) {
97168e
+        if (s->shdr_num) {
97168e
             write_elf_section(s, 0, errp);
97168e
             if (*errp) {
97168e
                 return;
97168e
@@ -1811,11 +1811,11 @@ static void dump_init(DumpState *s, int fd, bool has_format,
97168e
      */
97168e
     s->phdr_num = 1; /* PT_NOTE */
97168e
     if (s->list.num < UINT16_MAX - 2) {
97168e
+        s->shdr_num = 0;
97168e
         s->phdr_num += s->list.num;
97168e
-        s->have_section = false;
97168e
     } else {
97168e
         /* sh_info of section 0 holds the real number of phdrs */
97168e
-        s->have_section = true;
97168e
+        s->shdr_num = 1;
97168e
 
97168e
         /* the type of shdr->sh_info is uint32_t, so we should avoid overflow */
97168e
         if (s->list.num <= UINT32_MAX - 1) {
97168e
@@ -1826,19 +1826,19 @@ static void dump_init(DumpState *s, int fd, bool has_format,
97168e
     }
97168e
 
97168e
     if (s->dump_info.d_class == ELFCLASS64) {
97168e
-        if (s->have_section) {
97168e
+        if (s->shdr_num) {
97168e
             s->memory_offset = sizeof(Elf64_Ehdr) +
97168e
                                sizeof(Elf64_Phdr) * s->phdr_num +
97168e
-                               sizeof(Elf64_Shdr) + s->note_size;
97168e
+                               sizeof(Elf64_Shdr) * s->shdr_num + s->note_size;
97168e
         } else {
97168e
             s->memory_offset = sizeof(Elf64_Ehdr) +
97168e
                                sizeof(Elf64_Phdr) * s->phdr_num + s->note_size;
97168e
         }
97168e
     } else {
97168e
-        if (s->have_section) {
97168e
+        if (s->shdr_num) {
97168e
             s->memory_offset = sizeof(Elf32_Ehdr) +
97168e
                                sizeof(Elf32_Phdr) * s->phdr_num +
97168e
-                               sizeof(Elf32_Shdr) + s->note_size;
97168e
+                               sizeof(Elf32_Shdr) * s->shdr_num + s->note_size;
97168e
         } else {
97168e
             s->memory_offset = sizeof(Elf32_Ehdr) +
97168e
                                sizeof(Elf32_Phdr) * s->phdr_num + s->note_size;
97168e
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
97168e
index b463fc9c02..19458bffbd 100644
97168e
--- a/include/sysemu/dump.h
97168e
+++ b/include/sysemu/dump.h
97168e
@@ -155,7 +155,7 @@ typedef struct DumpState {
97168e
     ArchDumpInfo dump_info;
97168e
     MemoryMappingList list;
97168e
     uint32_t phdr_num;
97168e
-    bool have_section;
97168e
+    uint32_t shdr_num;
97168e
     bool resume;
97168e
     bool detached;
97168e
     ssize_t note_size;
97168e
-- 
97168e
2.37.3
97168e