zdump: dfo_elf: replace HDR_PER_CPU_SIZE with get_max_note_size_per_cpu

The maximum size of all supported ELF note entries for a CPU can be 0x4a4 bytes
and not 0x4a0. Use a function for the calculation so it's easier to maintain.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2022-09-01 20:09:48 +00:00
committed by Jan Höppner
parent d712806b39
commit dc87aef335
3 changed files with 25 additions and 4 deletions

View File

@@ -331,3 +331,21 @@ void *nt_vmcoreinfo(void *ptr, const char *vmcoreinfo)
return nt_init(ptr, 0, vmcoreinfo, strlen(vmcoreinfo),
NOTE_NAME_VMCOREINFO);
}
/* Keep in sync with `struct dfi_cpu` */
size_t get_max_note_size_per_cpu(void)
{
size_t size = 0;
size += ELF64_NOTE_SIZE(NOTE_NAME_CORE, sizeof(struct nt_prstatus_64));
size += ELF64_NOTE_SIZE(NOTE_NAME_CORE, sizeof(struct nt_fpregset_64));
size += ELF64_NOTE_SIZE(NOTE_NAME_LINUX, sizeof_field(struct dfi_cpu, timer));
size += ELF64_NOTE_SIZE(NOTE_NAME_LINUX, sizeof_field(struct dfi_cpu, todcmp));
size += ELF64_NOTE_SIZE(NOTE_NAME_LINUX, sizeof_field(struct dfi_cpu, todpreg));
size += ELF64_NOTE_SIZE(NOTE_NAME_LINUX, sizeof_field(struct dfi_cpu, ctrs));
size += ELF64_NOTE_SIZE(NOTE_NAME_LINUX, sizeof_field(struct dfi_cpu, prefix));
size += ELF64_NOTE_SIZE(NOTE_NAME_LINUX, sizeof_field(struct dfi_cpu, vxrs_low));
size += ELF64_NOTE_SIZE(NOTE_NAME_LINUX, sizeof_field(struct dfi_cpu, vxrs_high));
return size;
}

View File

@@ -79,6 +79,9 @@
#define NOTE_NAME_VMCOREINFO "VMCOREINFO"
#define ELF_NOTE_ROUNDUP(size) ROUNDUP(size, 4)
#define ELF_NOTE_NAME_SIZE(name) ELF_NOTE_ROUNDUP(name ? strlen(name) + 1 : 0)
#define ELF64_NOTE_SIZE(name, desc_size) \
(sizeof(Elf64_Nhdr) + ELF_NOTE_NAME_SIZE(name) + ELF_NOTE_ROUNDUP(desc_size))
/*
* prstatus ELF Note
@@ -266,4 +269,6 @@ void *nt_prpsinfo(void *ptr);
*/
void *nt_vmcoreinfo(void *ptr, const char *vmcoreinfo);
size_t get_max_note_size_per_cpu(void);
#endif /* DF_ELF_H */

View File

@@ -23,7 +23,6 @@
#include "dfi_vmcoreinfo.h"
#include "dfo.h"
#define HDR_PER_CPU_SIZE 0x4a0
#define HDR_PER_MEMC_SIZE 0x100
#define HDR_BASE_SIZE 0x2000
@@ -133,9 +132,8 @@ static void dfo_elf_init(void)
u64 hdr_off;
ensure_s390x();
alloc_size = HDR_BASE_SIZE +
dfi_cpu_cnt() * HDR_PER_CPU_SIZE +
dfi_mem_chunk_cnt() * HDR_PER_MEMC_SIZE;
alloc_size = HDR_BASE_SIZE + dfi_cpu_cnt() * get_max_note_size_per_cpu() +
dfi_mem_chunk_cnt() * HDR_PER_MEMC_SIZE;
buf = zg_alloc(alloc_size);
/* Init elf header */
ptr = ehdr_init(buf, dfi_mem_chunk_cnt() + 1);