[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 27/30] elf2dmp: introduce physical block alignment
From: |
Peter Maydell |
Subject: |
[PULL 27/30] elf2dmp: introduce physical block alignment |
Date: |
Thu, 21 Sep 2023 18:37:17 +0100 |
From: Viktor Prutyanov <viktor@daynix.com>
Physical memory ranges may not be aligned to page size in QEMU ELF, but
DMP can only contain page-aligned runs. So, align them.
Signed-off-by: Viktor Prutyanov <viktor@daynix.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-id: 20230915170153.10959-3-viktor@daynix.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
contrib/elf2dmp/addrspace.h | 1 +
contrib/elf2dmp/addrspace.c | 31 +++++++++++++++++++++++++++++--
contrib/elf2dmp/main.c | 5 +++--
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/contrib/elf2dmp/addrspace.h b/contrib/elf2dmp/addrspace.h
index 00b44c12180..039c70c5b07 100644
--- a/contrib/elf2dmp/addrspace.h
+++ b/contrib/elf2dmp/addrspace.h
@@ -12,6 +12,7 @@
#define ELF2DMP_PAGE_BITS 12
#define ELF2DMP_PAGE_SIZE (1ULL << ELF2DMP_PAGE_BITS)
+#define ELF2DMP_PAGE_MASK (ELF2DMP_PAGE_SIZE - 1)
#define ELF2DMP_PFN_MASK (~(ELF2DMP_PAGE_SIZE - 1))
#define INVALID_PA UINT64_MAX
diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c
index 0b04cba00e5..64b5d680adc 100644
--- a/contrib/elf2dmp/addrspace.c
+++ b/contrib/elf2dmp/addrspace.c
@@ -14,7 +14,7 @@ static struct pa_block *pa_space_find_block(struct pa_space
*ps, uint64_t pa)
for (i = 0; i < ps->block_nr; i++) {
if (ps->block[i].paddr <= pa &&
- pa <= ps->block[i].paddr + ps->block[i].size) {
+ pa < ps->block[i].paddr + ps->block[i].size) {
return ps->block + i;
}
}
@@ -33,6 +33,30 @@ static uint8_t *pa_space_resolve(struct pa_space *ps,
uint64_t pa)
return block->addr + (pa - block->paddr);
}
+static void pa_block_align(struct pa_block *b)
+{
+ uint64_t low_align = ((b->paddr - 1) | ELF2DMP_PAGE_MASK) + 1 - b->paddr;
+ uint64_t high_align = (b->paddr + b->size) & ELF2DMP_PAGE_MASK;
+
+ if (low_align == 0 && high_align == 0) {
+ return;
+ }
+
+ if (low_align + high_align < b->size) {
+ printf("Block 0x%"PRIx64"+:0x%"PRIx64" will be aligned to "
+ "0x%"PRIx64"+:0x%"PRIx64"\n", b->paddr, b->size,
+ b->paddr + low_align, b->size - low_align - high_align);
+ b->size -= low_align + high_align;
+ } else {
+ printf("Block 0x%"PRIx64"+:0x%"PRIx64" is too small to align\n",
+ b->paddr, b->size);
+ b->size = 0;
+ }
+
+ b->addr += low_align;
+ b->paddr += low_align;
+}
+
int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf)
{
Elf64_Half phdr_nr = elf_getphdrnum(qemu_elf->map);
@@ -60,10 +84,13 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf)
.paddr = phdr[i].p_paddr,
.size = phdr[i].p_filesz,
};
- block_i++;
+ pa_block_align(&ps->block[block_i]);
+ block_i = ps->block[block_i].size ? (block_i + 1) : block_i;
}
}
+ ps->block_nr = block_i;
+
return 0;
}
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index bb6744c0cd6..b7e39301641 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -400,9 +400,10 @@ static int write_dump(struct pa_space *ps,
for (i = 0; i < ps->block_nr; i++) {
struct pa_block *b = &ps->block[i];
- printf("Writing block #%zu/%zu to file...\n", i, ps->block_nr);
+ printf("Writing block #%zu/%zu of %"PRIu64" bytes to file...\n", i,
+ ps->block_nr, b->size);
if (fwrite(b->addr, b->size, 1, dmp_file) != 1) {
- eprintf("Failed to write dump header\n");
+ eprintf("Failed to write block\n");
fclose(dmp_file);
return 1;
}
--
2.34.1
- [PULL 13/30] target/arm: Pass unpriv bool to get_a64_user_mem_index(), (continued)
- [PULL 13/30] target/arm: Pass unpriv bool to get_a64_user_mem_index(), Peter Maydell, 2023/09/21
- [PULL 06/30] linux-user/elfload.c: Report previously missing arm32 hwcaps, Peter Maydell, 2023/09/21
- [PULL 23/30] audio/jackaudio: Avoid dynamic stack allocation in qjack_client_init, Peter Maydell, 2023/09/21
- [PULL 21/30] target/arm: Implement the CPY* instructions, Peter Maydell, 2023/09/21
- [PULL 18/30] target/arm: Define new TB flag for ATA0, Peter Maydell, 2023/09/21
- [PULL 28/30] elf2dmp: introduce merging of physical memory runs, Peter Maydell, 2023/09/21
- [PULL 15/30] target/arm: New function allocation_tag_mem_probe(), Peter Maydell, 2023/09/21
- [PULL 29/30] elf2dmp: use Linux mmap with MAP_NORESERVE when possible, Peter Maydell, 2023/09/21
- [PULL 24/30] audio/jackaudio: Avoid dynamic stack allocation in qjack_process(), Peter Maydell, 2023/09/21
- [PULL 30/30] elf2dmp: rework PDB_STREAM_INDEXES::segments obtaining, Peter Maydell, 2023/09/21
- [PULL 27/30] elf2dmp: introduce physical block alignment,
Peter Maydell <=
- [PULL 25/30] sbsa-ref: add non-secure EL2 virtual timer, Peter Maydell, 2023/09/21
- [PULL 26/30] elf2dmp: replace PE export name check with PDB name check, Peter Maydell, 2023/09/21
- [PULL 22/30] target/arm: Enable FEAT_MOPS for CPU 'max', Peter Maydell, 2023/09/21
- Re: [PULL 00/30] target-arm queue, Stefan Hajnoczi, 2023/09/25