Skip to contentSkip to conversation

dump: Set correct vaddr for ELF dump

PATCH In review Jon Doron 3 participants 5 messages Jan 9, 2019 – Jan 22, 2019

lore
Share & tools
lore

Jon Doron

author
#0 lore raw

PATCH v3 1/1 dump: Set correct vaddr for ELF dump

vaddr needs to be equal to the paddr since the dump file represents the physical memory image.

Without setting vaddr correctly, GDB would load all the different memory regions on top of each other to vaddr 0, thus making GDB showing the wrong memory data for a given address.

---
 dump.c                       | 5 +++--
 scripts/dump-guest-memory.py | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
dump.c +3 -2
index 4ec94c5e25..de7f70f099 100644
@@ -192,7 +192,7 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump64(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump64(s, filesz);
     phdr.p_memsz = cpu_to_dump64(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr);
+    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
@@ -216,7 +216,8 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump32(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump32(s, filesz);
     phdr.p_memsz = cpu_to_dump32(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump32(s, memory_mapping->virt_addr);
+    phdr.p_vaddr =
+        cpu_to_dump32(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
scripts/dump-guest-memory.py +1 -0
index 198cd0fe40..2c587cbefc 100644
@@ -163,6 +163,7 @@ class ELF(object):
         phdr = get_arch_phdr(self.endianness, self.elfclass)
         phdr.p_type = p_type
         phdr.p_paddr = p_paddr
+        phdr.p_vaddr = p_paddr
         phdr.p_filesz = p_size
         phdr.p_memsz = p_size
         self.segments.append(phdr)
Signature · 1 line
2.19.2
Tested-by Reviewed-by on v3 1/1
#1 lore raw
Quoted 9 lines · Jon Doron

vaddr needs to be equal to the paddr since the dump file represents the physical memory image.

Without setting vaddr correctly, GDB would load all the different memory regions on top of each other to vaddr 0, thus making GDB showing the wrong memory data for a given address.

Quoted 44 lines
---
 dump.c                       | 5 +++--
 scripts/dump-guest-memory.py | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
dump.c +3 -2
index 4ec94c5e25..de7f70f099 100644
@@ -192,7 +192,7 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump64(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump64(s, filesz);
     phdr.p_memsz = cpu_to_dump64(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr);
+    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
@@ -216,7 +216,8 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump32(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump32(s, filesz);
     phdr.p_memsz = cpu_to_dump32(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump32(s, memory_mapping->virt_addr);
+    phdr.p_vaddr =
+        cpu_to_dump32(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
scripts/dump-guest-memory.py +1 -1
index 198cd0fe40..2c587cbefc 100644
@@ -163,6 +163,7 @@ class ELF(object):
         phdr = get_arch_phdr(self.endianness, self.elfclass)
         phdr.p_type = p_type
         phdr.p_paddr = p_paddr
+        phdr.p_vaddr = p_paddr
         phdr.p_filesz = p_size
         phdr.p_memsz = p_size
         self.segments.append(phdr)
--

2.19.2

Signature · 1 line
Marc-André Lureau
Acked-by
#2 lore raw
Quoted 5 lines · Marc-André Lureau
Quoted 4 lines · Jon Doron

vaddr needs to be equal to the paddr since the dump file represents the physical memory image.

Quoted 8 lines
Quoted 5 lines

Without setting vaddr correctly, GDB would load all the different memory regions on top of each other to vaddr 0, thus making GDB showing the wrong memory data for a given address.

Apparently the only change in v3, relative to v2, is cleaning up the whitespace problem that was caught by Patchew.

Thanks
Laszlo

Quoted 27 lines
Quoted 27 lines
 dump.c                       | 5 +++--
 scripts/dump-guest-memory.py | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
dump.c +3 -2
index 4ec94c5e25..de7f70f099 100644
@@ -192,7 +192,7 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump64(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump64(s, filesz);
     phdr.p_memsz = cpu_to_dump64(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr);
+    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
@@ -216,7 +216,8 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump32(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump32(s, filesz);
     phdr.p_memsz = cpu_to_dump32(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump32(s, memory_mapping->virt_addr);
+    phdr.p_vaddr =
+        cpu_to_dump32(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
Quoted 18 lines
Quoted 13 lines
scripts/dump-guest-memory.py +1 -1
index 198cd0fe40..2c587cbefc 100644
@@ -163,6 +163,7 @@ class ELF(object):
         phdr = get_arch_phdr(self.endianness, self.elfclass)
         phdr.p_type = p_type
         phdr.p_paddr = p_paddr
+        phdr.p_vaddr = p_paddr
         phdr.p_filesz = p_size
         phdr.p_memsz = p_size
         self.segments.append(phdr)
--
Quoted 3 lines

2.19.2

I pre

author
#3 lore raw

ping, so this means that the patch will be merged in?

Thanks,
-- Jon.

Quoted 70 lines · Laszlo Ersek
Quoted 5 lines · Marc-André Lureau
Quoted 4 lines · Jon Doron

vaddr needs to be equal to the paddr since the dump file represents the physical memory image.

Quoted 8 lines
Quoted 5 lines

Without setting vaddr correctly, GDB would load all the different memory regions on top of each other to vaddr 0, thus making GDB showing the wrong memory data for a given address.

Apparently the only change in v3, relative to v2, is cleaning up the whitespace problem that was caught by Patchew.

Thanks
Laszlo

Quoted 27 lines
Quoted 27 lines
 dump.c                       | 5 +++--
 scripts/dump-guest-memory.py | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
dump.c +3 -2
index 4ec94c5e25..de7f70f099 100644
@@ -192,7 +192,7 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump64(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump64(s, filesz);
     phdr.p_memsz = cpu_to_dump64(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr);
+    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
@@ -216,7 +216,8 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump32(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump32(s, filesz);
     phdr.p_memsz = cpu_to_dump32(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump32(s, memory_mapping->virt_addr);
+    phdr.p_vaddr =
+        cpu_to_dump32(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
Quoted 18 lines
Quoted 13 lines
scripts/dump-guest-memory.py +1 -1
index 198cd0fe40..2c587cbefc 100644
@@ -163,6 +163,7 @@ class ELF(object):
         phdr = get_arch_phdr(self.endianness, self.elfclass)
         phdr.p_type = p_type
         phdr.p_paddr = p_paddr
+        phdr.p_vaddr = p_paddr
         phdr.p_filesz = p_size
         phdr.p_memsz = p_size
         self.segments.append(phdr)
--
Quoted 3 lines

2.19.2

I pre

#4 lore raw
Quoted 4 lines · Jon Doron

ping, so this means that the patch will be merged in?

Thanks,
-- Jon.

Marc-André, can you please confirm if you've queued this patch for a pull? (According to scripts/get_maintainer.pl, you are "supporter:Dump", for both files touched by this patch.)

Apologies if I missed a message elsewhere in this thread, and I should know already.

Thanks!
Laszlo

Quoted 72 lines · Laszlo Ersek
Quoted 70 lines · Marc-André Lureau
Quoted 5 lines · Jon Doron
Quoted 4 lines

vaddr needs to be equal to the paddr since the dump file represents the physical memory image.

Quoted 8 lines
Quoted 5 lines

Without setting vaddr correctly, GDB would load all the different memory regions on top of each other to vaddr 0, thus making GDB showing the wrong memory data for a given address.

Apparently the only change in v3, relative to v2, is cleaning up the whitespace problem that was caught by Patchew.

Thanks
Laszlo

Quoted 27 lines
Quoted 27 lines
 dump.c                       | 5 +++--
 scripts/dump-guest-memory.py | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
dump.c +3 -2
index 4ec94c5e25..de7f70f099 100644
@@ -192,7 +192,7 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump64(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump64(s, filesz);
     phdr.p_memsz = cpu_to_dump64(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr);
+    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
@@ -216,7 +216,8 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
     phdr.p_paddr = cpu_to_dump32(s, memory_mapping->phys_addr);
     phdr.p_filesz = cpu_to_dump32(s, filesz);
     phdr.p_memsz = cpu_to_dump32(s, memory_mapping->length);
-    phdr.p_vaddr = cpu_to_dump32(s, memory_mapping->virt_addr);
+    phdr.p_vaddr =
+        cpu_to_dump32(s, memory_mapping->virt_addr) ? : phdr.p_paddr;
 
     assert(memory_mapping->length >= filesz);
 
Quoted 18 lines
Quoted 13 lines
scripts/dump-guest-memory.py +1 -1
index 198cd0fe40..2c587cbefc 100644
@@ -163,6 +163,7 @@ class ELF(object):
         phdr = get_arch_phdr(self.endianness, self.elfclass)
         phdr.p_type = p_type
         phdr.p_paddr = p_paddr
+        phdr.p_vaddr = p_paddr
         phdr.p_filesz = p_size
         phdr.p_memsz = p_size
         self.segments.append(phdr)
--
Quoted 3 lines

2.19.2

I pre