|
|
62547e |
From eb763bec53d6b9aea7a6b60b0cf8c5d8b5f1b35c Mon Sep 17 00:00:00 2001
|
|
|
62547e |
From: Janosch Frank <frankja@linux.ibm.com>
|
|
|
62547e |
Date: Thu, 7 Apr 2022 09:48:24 +0000
|
|
|
62547e |
Subject: [PATCH 14/42] dump: Remove the sh_info variable
|
|
|
62547e |
MIME-Version: 1.0
|
|
|
62547e |
Content-Type: text/plain; charset=UTF-8
|
|
|
62547e |
Content-Transfer-Encoding: 8bit
|
|
|
62547e |
|
|
|
62547e |
RH-Author: Cédric Le Goater <clg@redhat.com>
|
|
|
62547e |
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
|
|
|
62547e |
RH-Bugzilla: 1664378 2043909
|
|
|
62547e |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
62547e |
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
62547e |
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
|
|
|
62547e |
RH-Commit: [14/41] 24af12b78c8f5a02cf85df2f6b1d64249f9499c9
|
|
|
62547e |
|
|
|
62547e |
There's no need to have phdr_num and sh_info at the same time. We can
|
|
|
62547e |
make phdr_num 32 bit and set PN_XNUM when we write the header if
|
|
|
62547e |
phdr_num >= PN_XNUM.
|
|
|
62547e |
|
|
|
62547e |
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
|
|
|
62547e |
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
|
|
|
62547e |
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
62547e |
Message-Id: <20220407094824.5074-1-frankja@linux.ibm.com>
|
|
|
62547e |
(cherry picked from commit 046bc4160bc780eaacc2d702a2589f1a7a01188d)
|
|
|
62547e |
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
|
|
62547e |
---
|
|
|
62547e |
dump/dump.c | 44 +++++++++++++++++++++++--------------------
|
|
|
62547e |
include/sysemu/dump.h | 3 +--
|
|
|
62547e |
2 files changed, 25 insertions(+), 22 deletions(-)
|
|
|
62547e |
|
|
|
62547e |
diff --git a/dump/dump.c b/dump/dump.c
|
|
|
62547e |
index 9876123f2e..7236b167cc 100644
|
|
|
62547e |
--- a/dump/dump.c
|
|
|
62547e |
+++ b/dump/dump.c
|
|
|
62547e |
@@ -124,6 +124,12 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
|
|
|
62547e |
|
|
|
62547e |
static void write_elf64_header(DumpState *s, Error **errp)
|
|
|
62547e |
{
|
|
|
62547e |
+ /*
|
|
|
62547e |
+ * phnum in the elf header is 16 bit, if we have more segments we
|
|
|
62547e |
+ * set phnum to PN_XNUM and write the real number of segments to a
|
|
|
62547e |
+ * special section.
|
|
|
62547e |
+ */
|
|
|
62547e |
+ uint16_t phnum = MIN(s->phdr_num, PN_XNUM);
|
|
|
62547e |
Elf64_Ehdr elf_header;
|
|
|
62547e |
int ret;
|
|
|
62547e |
|
|
|
62547e |
@@ -138,9 +144,9 @@ static void write_elf64_header(DumpState *s, Error **errp)
|
|
|
62547e |
elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
|
|
62547e |
elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
|
|
|
62547e |
elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
|
|
|
62547e |
- elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num);
|
|
|
62547e |
+ elf_header.e_phnum = cpu_to_dump16(s, phnum);
|
|
|
62547e |
if (s->have_section) {
|
|
|
62547e |
- uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->sh_info;
|
|
|
62547e |
+ uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num;
|
|
|
62547e |
|
|
|
62547e |
elf_header.e_shoff = cpu_to_dump64(s, shoff);
|
|
|
62547e |
elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
|
|
|
62547e |
@@ -155,6 +161,12 @@ static void write_elf64_header(DumpState *s, Error **errp)
|
|
|
62547e |
|
|
|
62547e |
static void write_elf32_header(DumpState *s, Error **errp)
|
|
|
62547e |
{
|
|
|
62547e |
+ /*
|
|
|
62547e |
+ * phnum in the elf header is 16 bit, if we have more segments we
|
|
|
62547e |
+ * set phnum to PN_XNUM and write the real number of segments to a
|
|
|
62547e |
+ * special section.
|
|
|
62547e |
+ */
|
|
|
62547e |
+ uint16_t phnum = MIN(s->phdr_num, PN_XNUM);
|
|
|
62547e |
Elf32_Ehdr elf_header;
|
|
|
62547e |
int ret;
|
|
|
62547e |
|
|
|
62547e |
@@ -169,9 +181,9 @@ static void write_elf32_header(DumpState *s, Error **errp)
|
|
|
62547e |
elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
|
|
62547e |
elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
|
|
|
62547e |
elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
|
|
|
62547e |
- elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num);
|
|
|
62547e |
+ elf_header.e_phnum = cpu_to_dump16(s, phnum);
|
|
|
62547e |
if (s->have_section) {
|
|
|
62547e |
- uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->sh_info;
|
|
|
62547e |
+ uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num;
|
|
|
62547e |
|
|
|
62547e |
elf_header.e_shoff = cpu_to_dump32(s, shoff);
|
|
|
62547e |
elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
|
|
|
62547e |
@@ -358,12 +370,12 @@ static void write_elf_section(DumpState *s, int type, Error **errp)
|
|
|
62547e |
if (type == 0) {
|
|
|
62547e |
shdr_size = sizeof(Elf32_Shdr);
|
|
|
62547e |
memset(&shdr32, 0, shdr_size);
|
|
|
62547e |
- shdr32.sh_info = cpu_to_dump32(s, s->sh_info);
|
|
|
62547e |
+ shdr32.sh_info = cpu_to_dump32(s, s->phdr_num);
|
|
|
62547e |
shdr = &shdr32;
|
|
|
62547e |
} else {
|
|
|
62547e |
shdr_size = sizeof(Elf64_Shdr);
|
|
|
62547e |
memset(&shdr64, 0, shdr_size);
|
|
|
62547e |
- shdr64.sh_info = cpu_to_dump32(s, s->sh_info);
|
|
|
62547e |
+ shdr64.sh_info = cpu_to_dump32(s, s->phdr_num);
|
|
|
62547e |
shdr = &shdr64;
|
|
|
62547e |
}
|
|
|
62547e |
|
|
|
62547e |
@@ -478,13 +490,6 @@ static void write_elf_loads(DumpState *s, Error **errp)
|
|
|
62547e |
hwaddr offset, filesz;
|
|
|
62547e |
MemoryMapping *memory_mapping;
|
|
|
62547e |
uint32_t phdr_index = 1;
|
|
|
62547e |
- uint32_t max_index;
|
|
|
62547e |
-
|
|
|
62547e |
- if (s->have_section) {
|
|
|
62547e |
- max_index = s->sh_info;
|
|
|
62547e |
- } else {
|
|
|
62547e |
- max_index = s->phdr_num;
|
|
|
62547e |
- }
|
|
|
62547e |
|
|
|
62547e |
QTAILQ_FOREACH(memory_mapping, &s->list.head, next) {
|
|
|
62547e |
get_offset_range(memory_mapping->phys_addr,
|
|
|
62547e |
@@ -502,7 +507,7 @@ static void write_elf_loads(DumpState *s, Error **errp)
|
|
|
62547e |
return;
|
|
|
62547e |
}
|
|
|
62547e |
|
|
|
62547e |
- if (phdr_index >= max_index) {
|
|
|
62547e |
+ if (phdr_index >= s->phdr_num) {
|
|
|
62547e |
break;
|
|
|
62547e |
}
|
|
|
62547e |
}
|
|
|
62547e |
@@ -1809,22 +1814,21 @@ static void dump_init(DumpState *s, int fd, bool has_format,
|
|
|
62547e |
s->phdr_num += s->list.num;
|
|
|
62547e |
s->have_section = false;
|
|
|
62547e |
} else {
|
|
|
62547e |
+ /* sh_info of section 0 holds the real number of phdrs */
|
|
|
62547e |
s->have_section = true;
|
|
|
62547e |
- s->phdr_num = PN_XNUM;
|
|
|
62547e |
- s->sh_info = 1; /* PT_NOTE */
|
|
|
62547e |
|
|
|
62547e |
/* the type of shdr->sh_info is uint32_t, so we should avoid overflow */
|
|
|
62547e |
if (s->list.num <= UINT32_MAX - 1) {
|
|
|
62547e |
- s->sh_info += s->list.num;
|
|
|
62547e |
+ s->phdr_num += s->list.num;
|
|
|
62547e |
} else {
|
|
|
62547e |
- s->sh_info = UINT32_MAX;
|
|
|
62547e |
+ s->phdr_num = UINT32_MAX;
|
|
|
62547e |
}
|
|
|
62547e |
}
|
|
|
62547e |
|
|
|
62547e |
if (s->dump_info.d_class == ELFCLASS64) {
|
|
|
62547e |
if (s->have_section) {
|
|
|
62547e |
s->memory_offset = sizeof(Elf64_Ehdr) +
|
|
|
62547e |
- sizeof(Elf64_Phdr) * s->sh_info +
|
|
|
62547e |
+ sizeof(Elf64_Phdr) * s->phdr_num +
|
|
|
62547e |
sizeof(Elf64_Shdr) + s->note_size;
|
|
|
62547e |
} else {
|
|
|
62547e |
s->memory_offset = sizeof(Elf64_Ehdr) +
|
|
|
62547e |
@@ -1833,7 +1837,7 @@ static void dump_init(DumpState *s, int fd, bool has_format,
|
|
|
62547e |
} else {
|
|
|
62547e |
if (s->have_section) {
|
|
|
62547e |
s->memory_offset = sizeof(Elf32_Ehdr) +
|
|
|
62547e |
- sizeof(Elf32_Phdr) * s->sh_info +
|
|
|
62547e |
+ sizeof(Elf32_Phdr) * s->phdr_num +
|
|
|
62547e |
sizeof(Elf32_Shdr) + s->note_size;
|
|
|
62547e |
} else {
|
|
|
62547e |
s->memory_offset = sizeof(Elf32_Ehdr) +
|
|
|
62547e |
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
|
|
|
62547e |
index 250143cb5a..b463fc9c02 100644
|
|
|
62547e |
--- a/include/sysemu/dump.h
|
|
|
62547e |
+++ b/include/sysemu/dump.h
|
|
|
62547e |
@@ -154,8 +154,7 @@ typedef struct DumpState {
|
|
|
62547e |
GuestPhysBlockList guest_phys_blocks;
|
|
|
62547e |
ArchDumpInfo dump_info;
|
|
|
62547e |
MemoryMappingList list;
|
|
|
62547e |
- uint16_t phdr_num;
|
|
|
62547e |
- uint32_t sh_info;
|
|
|
62547e |
+ uint32_t phdr_num;
|
|
|
62547e |
bool have_section;
|
|
|
62547e |
bool resume;
|
|
|
62547e |
bool detached;
|
|
|
62547e |
--
|
|
|
62547e |
2.37.3
|
|
|
62547e |
|