dump: Add arch section and s390x PV dump
v2 cover dump: Add arch section and s390x PV dump
Previously this series was two separate series:
* Arch section support
Adds the possibility for arch code to add custom section data.
* s390 PV dump support
Adds PV dump data to the custom arch sections.
I've chosen to merge them so it's easier to understand why the arch section support has been implement the way it is.
Additionally I've added a cleanup patch beforehand which cleans up the GuestPhysBlock usage.
v2:
* Added "dump: Cleanup memblock usage"
* Fixed whitespace problems and review comments
* Added missing *errp check in dump_end
Janosch Frank (11):
dump: Cleanup memblock usage
dump: Allocate header
dump: Split write of section headers and data and add a prepare step
dump: Reorder struct DumpState
dump/dump: Add section string table support
dump/dump: Add arch section support
linux header sync
s390x: Add protected dump cap
s390x: Introduce PV query interface
s390x: Add KVM PV dump interface
s390x: pv: Add dump support
dump/dump.c | 443 ++++++++++++++++++++++------------- hw/s390x/pv.c | 112 +++++++++ hw/s390x/s390-virtio-ccw.c | 5 + include/elf.h | 1 + include/hw/s390x/pv.h | 18 ++ include/sysemu/dump-arch.h | 27 +++ include/sysemu/dump.h | 70 +++++- linux-headers/linux/kvm.h | 55 +++++ target/s390x/arch_dump.c | 248 +++++++++++++++++--- target/s390x/kvm/kvm.c | 7 + target/s390x/kvm/kvm_s390x.h | 1 + 11 files changed, 780 insertions(+), 207 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/11 dump: Cleanup memblock usage
The iteration over the memblocks is hard to understand so it's about time to clean it up.
struct DumpState's next_block and start members can and should be local variables within the iterator.
Instead of manually grabbing the next memblock we can use QTAILQ_FOREACH to iterate over all memblocks.
The begin and length fields in the DumpState have been left untouched since the qmp arguments share their names.
--- dump/dump.c | 91 +++++++++++-------------------------------- include/sysemu/dump.h | 47 +++++++++++++++++++--- 2 files changed, 65 insertions(+), 73 deletions(-)
dump/dump.c +23 -68
@@ -591,56 +591,27 @@ static void dump_begin(DumpState *s, Error **errp)write_elf_notes (s, errp); } -static int get_next_block (DumpState *s,GuestPhysBlock *block) -{ -while (1 ) { - block =QTAILQ_NEXT (block, next); -if (!block) { -/* no more block */ -return 1 ; - } - - s->start =0 ; - s->next_block = block; -if (s->has_filter) { -if (block->target_start >= s->begin + s->length || - block->target_end <= s->begin) { -/* This block is out of the range */ -continue ; - } - -if (s->begin > block->target_start) { - s->start = s->begin - block->target_start; - } - } - -return 0 ; - } -} -/* write all memory to vmcore */ static void dump_iterate (DumpState *s,Error **errp) {ERRP_GUARD ();GuestPhysBlock *block; -int64_t size; +int64_t memblock_size, memblock_start; -do { - block = s->next_block; - - size = block->target_end - block->target_start; -if (s->has_filter) { - size -= s->start; -if (s->begin + s->length < block->target_end) { - size -= block->target_end - (s->begin + s->length); - } + QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { + memblock_start =dump_get_memblock_start (block, s->begin, s->length); +if (memblock_start ==-1 ) { +continue ; } -write_memory (s, block, s->start, size, errp); + + memblock_size =dump_get_memblock_size (block, s->begin, s->length); + +/* Write the memory to file */ +write_memory (s, block, memblock_start, memblock_size, errp);if (*errp) {return ; } - - }while (!get_next_block (s, block)); + } }static void create_vmcore (DumpState *s,Error **errp)
@@ -1490,30 +1461,22 @@ static void create_kdump_vmcore(DumpState *s, Error **errp) } } -static ram_addr_t get_start_block (DumpState *s) +static int validate_start_block (DumpState *s) {GuestPhysBlock *block;if (!s->has_filter) { - s->next_block =QTAILQ_FIRST (&s->guest_phys_blocks.head);return 0 ; } QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { +/* This block is out of the range */ if (block->target_start >= s->begin + s->length || block->target_end <= s->begin) { -/* This block is out of the range */ continue ; } - - s->next_block = block; -if (s->begin > block->target_start) { - s->start = s->begin - block->target_start; - }else { - s->start =0 ; - } -return s->start; - } +return 0 ; + }return -1 ; }
@@ -1540,25 +1503,17 @@ bool qemu_system_dump_in_progress(void)return (qatomic_read (&state->status) ==DUMP_STATUS_ACTIVE ); } -/* calculate total size of memory to be dumped (taking filter into -* acoount.) */ +/* +* calculate total size of memory to be dumped (taking filter into +* account.) +*/ static int64_t dump_calculate_size (DumpState *s) {GuestPhysBlock *block; -int64_t size =0 , total =0 , left =0 , right =0 ; +int64_t total =0 ; QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { -if (s->has_filter) { -/* calculate the overlapped region. */ - left =MAX (s->begin, block->target_start); - right =MIN (s->begin + s->length, block->target_end); - size = right - left; - size = size >0 ? size :0 ; - }else { -/* count the whole region in */ - size = (block->target_end - block->target_start); - } - total += size; + total +=dump_get_memblock_size (block, s->begin, s->length); }return total;
@@ -1660,8 +1615,8 @@ static void dump_init(DumpState *s, int fd, bool has_format, goto cleanup; } - s->start =get_start_block (s); -if (s->start ==-1 ) { +/* Is the filter filtering everything? */ +if (validate_start_block (s) ==-1 ) {error_setg (errp,QERR_INVALID_PARAMETER ,"begin" ); goto cleanup; }
include/sysemu/dump.h +42 -5
57 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 01/11] dump: Cleanup memblock usage
Hi
Quoted 7 lines · Janosch Frank
The iteration over the memblocks is hard to understand so it's about time to clean it up.
struct DumpState's
next_blockand start members can and should be local variables within the iterator.
Quoted 7 lines
Instead of manually grabbing the next memblock we can use
QTAILQ_FOREACHto iterate over all memblocks.The begin and length fields in the DumpState have been left untouched since the qmp arguments share their names.
Signed-off-by Janosch Frank <[email protected]>
After this patch:
./qemu-system-x86_64 -monitor stdio -S
(qemu) dump-guest-memory foo
Error: dump: failed to save memory: Bad address
Quoted 113 lines
--- dump/dump.c | 91 +++++++++++-------------------------------- include/sysemu/dump.h | 47 +++++++++++++++++++--- 2 files changed, 65 insertions(+), 73 deletions(-)dump/dump.c +15
-52@@ -591,56 +591,27 @@ static void dump_begin(DumpState *s, Error **errp)write_elf_notes (s, errp); } -static int get_next_block (DumpState *s,GuestPhysBlock *block) -{ -while (1 ) { - block =QTAILQ_NEXT (block, next); -if (!block) { -/* no more block */ -return 1 ; - } - - s->start =0 ; - s->next_block = block; -if (s->has_filter) { -if (block->target_start >= s->begin + s->length || - block->target_end <= s->begin) { -/* This block is out of the range */ -continue ; - } - -if (s->begin > block->target_start) { - s->start = s->begin - block->target_start; - } - } - -return 0 ; - } -} -/* write all memory to vmcore */ static void dump_iterate (DumpState *s,Error **errp) {ERRP_GUARD ();GuestPhysBlock *block; -int64_t size; +int64_t memblock_size, memblock_start; -do { - block = s->next_block; - - size = block->target_end - block->target_start; -if (s->has_filter) { - size -= s->start; -if (s->begin + s->length < block->target_end) { - size -= block->target_end - (s->begin + s->length); - } + QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { + memblock_start =dump_get_memblock_start (block, s->begin, s->length); +if (memblock_start ==-1 ) { +continue ; } -write_memory (s, block, s->start, size, errp); + + memblock_size =dump_get_memblock_size (block, s->begin, s->length); + +/* Write the memory to file */ +write_memory (s, block, memblock_start, memblock_size, errp);if (*errp) {return ; } - - }while (!get_next_block (s, block)); + } }static void create_vmcore (DumpState *s,Error **errp)@@ -1490,30 +1461,22 @@ static void create_kdump_vmcore(DumpState *s, Error **errp) } } -static ram_addr_t get_start_block (DumpState *s) +static int validate_start_block (DumpState *s) {GuestPhysBlock *block;if (!s->has_filter) { - s->next_block =QTAILQ_FIRST (&s->guest_phys_blocks.head);return 0 ; } QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { +/* This block is out of the range */ if (block->target_start >= s->begin + s->length || block->target_end <= s->begin) { -/* This block is out of the range */ continue ; } - - s->next_block = block; -if (s->begin > block->target_start) { - s->start = s->begin - block->target_start; - }else { - s->start =0 ; - } -return s->start; - } +return 0 ; + }return -1 ; }
dump/dump.c bool qemu_system_dump_in_progress(void) · line 1508
Quoted 8 lines
dump/dump.c +3
-2@@ -1540,25 +1503,17 @@ bool qemu_system_dump_in_progress(void)return (qatomic_read (&state->status) ==DUMP_STATUS_ACTIVE ); } -/* calculate total size of memory to be dumped (taking filter into -* acoount.) */ +/* +* calculate total size of memory to be dumped (taking filter into +* account.)
thanks for fixing the typo
Quoted 76 lines
dump/dump.c +5
-14+*/ static int64_t dump_calculate_size (DumpState *s) {GuestPhysBlock *block; -int64_t size =0 , total =0 , left =0 , right =0 ; +int64_t total =0 ; QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { -if (s->has_filter) { -/* calculate the overlapped region. */ - left =MAX (s->begin, block->target_start); - right =MIN (s->begin + s->length, block->target_end); - size = right - left; - size = size >0 ? size :0 ; - }else { -/* count the whole region in */ - size = (block->target_end - block->target_start); - } - total += size; + total +=dump_get_memblock_size (block, s->begin, s->length); }return total;@@ -1660,8 +1615,8 @@ static void dump_init(DumpState *s, int fd, bool has_format, goto cleanup; } - s->start =get_start_block (s); -if (s->start ==-1 ) { +/* Is the filter filtering everything? */ +if (validate_start_block (s) ==-1 ) {error_setg (errp,QERR_INVALID_PARAMETER ,"begin" ); goto cleanup; }include/sysemu/dump.h +22
-5@@ -166,11 +166,10 @@ typedef struct DumpState {hwaddr memory_offset;int fd; -GuestPhysBlock *next_block; -ram_addr_t start; -bool has_filter; -int64_t begin; -int64_t length; +/* Guest memory related data */ +bool has_filter;/* Are we dumping parts of the memory? */ +int64_t begin;/* Start address of the chunk we want to dump */ +int64_t length;/* Length of the dump we want to dump */ uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */ @@ -203,4 +202,42 @@ typedef struct DumpState {uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);uint32_t cpu_to_dump32 (DumpState *s,uint32_t val);uint64_t cpu_to_dump64 (DumpState *s,uint64_t val); + +static inline int64_t dump_get_memblock_size (GuestPhysBlock *block,int64_t filter_area_start, +int64_t filter_area_length) +{ +int64_t size, left, right; + +/* No filter, return full size */ +if (!filter_area_length) { +return block->target_end - block->target_start; + } + +/* calculate the overlapped region. */ + left =MAX (filter_area_start, block->target_start); + right =MIN (filter_area_start + filter_area_length, block->target_end); + size = right - left; + size = size >0 ? size :0 ; + +return size;
include/sysemu/dump.h typedef struct DumpState { · line 232
Quoted 10 lines
include/sysemu/dump.h +10
-0+} + +static inline int64_t dump_get_memblock_start (GuestPhysBlock *block,int64_t filter_area_start, +int64_t filter_area_length) +{ +if (filter_area_length) { +/* +* Check if block is within guest memory dump area. If not +* go to next one. +*/
Or rather "return -1 if the block is not within filter area"
include/sysemu/dump.h typedef struct DumpState { · line 241
Quoted 9 lines
include/sysemu/dump.h +9
-0+if (block->target_start >= filter_area_start + filter_area_length || + block->target_end <= filter_area_start) { +return -1 ; + } +if (filter_area_start > block->target_start) { +return filter_area_start - block->target_start; + } + } +return block->target_start;
This used to be 0. Changing that, I think the patch looks good. Although it could perhaps be splitted to introduce the two functions.
Quoted 5 lines
include/sysemu/dump.h +1
-1+}#endif --2.34.1
Re: [PATCH v2 01/11] dump: Cleanup memblock usage
Quoted 16 lines · Marc-André Lureau
Hi
Quoted 13 lines · Janosch Frank
The iteration over the memblocks is hard to understand so it's about time to clean it up.
struct DumpState's
next_blockand start members can and should be local variables within the iterator.Instead of manually grabbing the next memblock we can use
QTAILQ_FOREACHto iterate over all memblocks.The begin and length fields in the DumpState have been left untouched since the qmp arguments share their names.
Quoted 6 lines
Quoted 1 line
Signed-off-by Janosch Frank <[email protected]>After this patch:
./qemu-system-x86_64 -monitor stdio -S
(qemu) dump-guest-memory foo
Error: dump: failed to save memory: Bad address
If you have more ways to check for dump errors then please send them to me. I'm aware that this might not have been a 100% conversion and I'm a bit terrified about the fact that this will affect all architectures.
Anyway, I'll have a look.
[...]
Quoted 10 lines
include/sysemu/dump.h typedef struct DumpState { · line 232
Quoted 8 lines
include/sysemu/dump.h +8
-0+static inline int64_t dump_get_memblock_start (GuestPhysBlock *block,int64_t filter_area_start, +int64_t filter_area_length) +{ +if (filter_area_length) { +/* +* Check if block is within guest memory dump area. If not +* go to next one. +*/ Or rather "return -1 if the block is not within filter area"
Sure
Quoted 11 lines
include/sysemu/dump.h typedef struct DumpState { · line 241
Quoted 10 lines
include/sysemu/dump.h +9
-0+if (block->target_start >= filter_area_start + filter_area_length || + block->target_end <= filter_area_start) { +return -1 ; + } +if (filter_area_start > block->target_start) { +return filter_area_start - block->target_start; + } + } +return block->target_start;
Quoted 2 lines
This used to be 0. Changing that, I think the patch looks good. Although it could perhaps be splitted to introduce the two functions.
Yes but the 0 was used to indicate that we would have needed continue iterating and the iteration is done via other means in this patch.
Or am I missing something?
Quoted 8 lines
Quoted 6 lines
+}
#endif
--
2.34.1
Re: [PATCH v2 01/11] dump: Cleanup memblock usage
Hi
Quoted 20 lines · Janosch Frank
Quoted 18 lines · Marc-André Lureau
Hi
Quoted 14 lines · Janosch Frank
The iteration over the memblocks is hard to understand so it's about time to clean it up.
struct DumpState's
next_blockand start members can and should be local variables within the iterator.Instead of manually grabbing the next memblock we can use
QTAILQ_FOREACHto iterate over all memblocks.The begin and length fields in the DumpState have been left untouched since the qmp arguments share their names.
Signed-off-by Janosch Frank <[email protected]>
Quoted 8 lines
Quoted 4 lines
After this patch:
./qemu-system-x86_64 -monitor stdio -S
(qemu) dump-guest-memory foo
Error: dump: failed to save memory: Bad addressIf you have more ways to check for dump errors then please send them to me. I'm aware that this might not have been a 100% conversion and I'm a bit terrified about the fact that this will affect all architectures.
Same feeling here. Maybe it's about time to write real dump tests!
Quoted 30 lines
Anyway, I'll have a look.
[...]
Quoted 10 lines
include/sysemu/dump.h typedef struct DumpState { · line 232
Quoted 8 lines
include/sysemu/dump.h +8
-0+static inline int64_t dump_get_memblock_start (GuestPhysBlock *block,int64_t filter_area_start, +int64_t filter_area_length) +{ +if (filter_area_length) { +/* +* Check if block is within guest memory dump area. If not +* go to next one. +*/ Or rather "return -1 if the block is not within filter area"
Sure
Quoted 11 lines
Quoted 10 lines
include/sysemu/dump.h +9
-0+if (block->target_start >= filter_area_start + filter_area_length || + block->target_end <= filter_area_start) { +return -1 ; + } +if (filter_area_start > block->target_start) { +return filter_area_start - block->target_start; + } + } +return block->target_start;
Quoted 7 lines
Quoted 2 lines
This used to be 0. Changing that, I think the patch looks good. Although it could perhaps be splitted to introduce the two functions.
Yes but the 0 was used to indicate that we would have needed continue iterating and the iteration is done via other means in this patch.
Or am I missing something?
Well, you changed the way the loop used to work. it used to return 1/0 to indicate stop/continue and rely on s->start / s->next_block. Now you return memblock_start.
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
+}
#endif
--
2.34.1
Re: [PATCH v2 01/11] dump: Cleanup memblock usage
Quoted 28 lines · Marc-André Lureau
Hi
Quoted 25 lines · Janosch Frank
Quoted 22 lines · Marc-André Lureau
Hi
Quoted 7 lines · Janosch Frank
The iteration over the memblocks is hard to understand so it's about time to clean it up.
struct DumpState's
next_blockand start members can and should be local variables within the iterator.Quoted 7 lines
Instead of manually grabbing the next memblock we can use
QTAILQ_FOREACHto iterate over all memblocks.The begin and length fields in the DumpState have been left untouched since the qmp arguments share their names.
Signed-off-by Janosch Frank <[email protected]>After this patch:
./qemu-system-x86_64 -monitor stdio -S
(qemu) dump-guest-memory foo
Error: dump: failed to save memory: Bad address
Quoted 5 lines
Quoted 3 lines
If you have more ways to check for dump errors then please send them to me. I'm aware that this might not have been a 100% conversion and I'm a bit terrified about the fact that this will affect all architectures.
Same feeling here. Maybe it's about time to write real dump tests!
We have tests for s390 and I've prompted for tests with filtering so we can also cover that. Unfortunately s390 differs in the use of memory because we only have one large block which hid this error from me.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
include/sysemu/dump.h +9
-0+if (block->target_start >= filter_area_start + filter_area_length || + block->target_end <= filter_area_start) { +return -1 ; + } +if (filter_area_start > block->target_start) { +return filter_area_start - block->target_start; + } + } +return block->target_start;
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
This used to be 0. Changing that, I think the patch looks good. Although it could perhaps be splitted to introduce the two functions.
Yes but the 0 was used to indicate that we would have needed continue iterating and the iteration is done via other means in this patch.
Or am I missing something?
Had a look, turns out I missed something.
Quoted 4 lines
Well, you changed the way the loop used to work. it used to return 1/0 to indicate stop/continue and rely on
s->start/s->next_block. Now you returnmemblock_start.
Maybe we should call this "dump_get_memblock_start_offset()" to make it clearer that we don't return block->target_start i.e. a start address but rather an offset that we tack on the host address to read the memory?
Quoted 13 lines
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
+}
#endif
--
2.34.1
Re: [PATCH v2 01/11] dump: Cleanup memblock usage
Hi
Quoted 65 lines · Janosch Frank
Quoted 3 lines · Marc-André Lureau
Hi
On Wed, Jul 13, 2022 at 7:30 PM Janosch Frank <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines · Marc-André Lureau
Quoted 3 lines
Hi
On Wed, Jul 13, 2022 at 5:07 PM Janosch Frank <[email protected]>
Quoted 20 lines · wrote:
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
The iteration over the memblocks is hard to understand so it's about time to clean it up.
struct DumpState's
next_blockand start members can and should be local variables within the iterator.Quoted 7 lines
Instead of manually grabbing the next memblock we can use
QTAILQ_FOREACHto iterate over all memblocks.The begin and length fields in the DumpState have been left untouched since the qmp arguments share their names.
Signed-off-by Janosch Frank <[email protected]>After this patch:
./qemu-system-x86_64 -monitor stdio -S
(qemu) dump-guest-memory foo
Error: dump: failed to save memory: Bad addressQuoted 5 lines
Quoted 3 lines
If you have more ways to check for dump errors then please send them to me. I'm aware that this might not have been a 100% conversion and I'm a bit terrified about the fact that this will affect all architectures.
Same feeling here. Maybe it's about time to write real dump tests!
We have tests for s390 and I've prompted for tests with filtering so we can also cover that. Unfortunately s390 differs in the use of memory because we only have one large block which hid this error from me.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ if (
block->target_start>=filter_area_start+
filter_area_length||Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
include/sysemu/dump.h +8
-0+ block->target_end <= filter_area_start) { +return -1 ; + } +if (filter_area_start > block->target_start) { +return filter_area_start - block->target_start; + } + } +return block->target_start;Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
This used to be 0. Changing that, I think the patch looks good. Although it could perhaps be splitted to introduce the two functions.
Yes but the 0 was used to indicate that we would have needed continue iterating and the iteration is done via other means in this patch.
Or am I missing something?
Had a look, turns out I missed something.
Quoted 1 line
Quoted 9 lines
Quoted 3 lines
Well, you changed the way the loop used to work. it used to return 1/0 to indicate stop/continue and rely on
s->start/s->next_block. Now you returnmemblock_start.Maybe we should call this "
dump_get_memblock_start_offset()" to make it clearer that we don't returnblock->target_starti.e. a start address but rather an offset that we tack on the host address to read the memory?
Not a big difference to me. You would need to adjust write_memory() "start" argument name as well then.
Quoted 15 lines
Quoted 13 lines
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
+}
#endif
--
2.34.1
Signature · 1 line
Marc-André Lureau
PATCH v2 2/11 dump: Allocate header
In reply to Janosch FrankAllocating the header lets us write it at a later time and hence also allows us to change section and segment table offsets until we finally write it.
--- dump/dump.c | 127 +++++++++++++++++++++--------------------- include/sysemu/dump.h | 1 + 2 files changed, 64 insertions(+), 64 deletions(-)
dump/dump.c +63 -64
@@ -98,6 +98,7 @@ static int dump_cleanup(DumpState *s)memory_mapping_list_free (&s->list);close (s->fd);g_free (s->guest_note); +g_free (s->elf_header); s->guest_note =NULL ;if (s->resume) {if (s->detached) {
@@ -126,73 +127,49 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)return 0 ; } -static void write_elf64_header (DumpState *s,Error **errp) +static void prepare_elf64_header (DumpState *s) { -/* -* phnum in the elf header is 16 bit, if we have more segments we -* set phnum to PN_XNUM and write the real number of segments to a -* special section. -*/ -uint16_t phnum =MIN (s->phdr_num,PN_XNUM ); -Elf64_Ehdr elf_header; -int ret; +uint16_t phnum = s->phdr_num >=PN_XNUM ?PN_XNUM : s->phdr_num; +Elf64_Ehdr *elf_header = s->elf_header; -memset (&elf_header,0 ,sizeof (Elf64_Ehdr)); -memcpy (&elf_header,ELFMAG ,SELFMAG ); - elf_header.e_ident[EI_CLASS ] =ELFCLASS64 ; - elf_header.e_ident[EI_DATA ] = s->dump_info.d_endian; - elf_header.e_ident[EI_VERSION ] =EV_CURRENT ; - elf_header.e_type =cpu_to_dump16 (s,ET_CORE ); - elf_header.e_machine =cpu_to_dump16 (s, s->dump_info.d_machine); - elf_header.e_version =cpu_to_dump32 (s,EV_CURRENT ); - elf_header.e_ehsize =cpu_to_dump16 (s,sizeof (elf_header)); - elf_header.e_phoff =cpu_to_dump64 (s, s->phdr_offset); - elf_header.e_phentsize =cpu_to_dump16 (s,sizeof (Elf64_Phdr)); - elf_header.e_phnum =cpu_to_dump16 (s, phnum); +memcpy (elf_header,ELFMAG ,SELFMAG ); + elf_header->e_ident[EI_CLASS ] =ELFCLASS64 ; + elf_header->e_ident[EI_DATA ] = s->dump_info.d_endian; + elf_header->e_ident[EI_VERSION ] =EV_CURRENT ; + elf_header->e_type =cpu_to_dump16 (s,ET_CORE ); + elf_header->e_machine =cpu_to_dump16 (s, s->dump_info.d_machine); + elf_header->e_version =cpu_to_dump32 (s,EV_CURRENT ); + elf_header->e_ehsize =cpu_to_dump16 (s,sizeof (*elf_header)); + elf_header->e_phoff =cpu_to_dump64 (s, s->phdr_offset); + elf_header->e_phentsize =cpu_to_dump16 (s,sizeof (Elf64_Phdr)); + elf_header->e_phnum =cpu_to_dump16 (s, phnum);if (s->shdr_num) { - elf_header.e_shoff =cpu_to_dump64 (s, s->shdr_offset); - elf_header.e_shentsize =cpu_to_dump16 (s,sizeof (Elf64_Shdr)); - elf_header.e_shnum =cpu_to_dump16 (s, s->shdr_num); - } - - ret =fd_write_vmcore (&elf_header,sizeof (elf_header), s); -if (ret <0 ) { -error_setg_errno (errp, -ret,"dump: failed to write elf header" ); + elf_header->e_shoff =cpu_to_dump64 (s, s->shdr_offset); + elf_header->e_shentsize =cpu_to_dump16 (s,sizeof (Elf64_Shdr)); + elf_header->e_shnum =cpu_to_dump16 (s, s->shdr_num); } } -static void write_elf32_header (DumpState *s,Error **errp) +static void prepare_elf32_header (DumpState *s) { -/* -* phnum in the elf header is 16 bit, if we have more segments we -* set phnum to PN_XNUM and write the real number of segments to a -* special section. -*/ -uint16_t phnum =MIN (s->phdr_num,PN_XNUM ); -Elf32_Ehdr elf_header; -int ret; +uint16_t phnum = s->phdr_num >=PN_XNUM ?PN_XNUM : s->phdr_num; +Elf32_Ehdr *elf_header = s->elf_header; -memset (&elf_header,0 ,sizeof (Elf32_Ehdr)); -memcpy (&elf_header,ELFMAG ,SELFMAG ); - elf_header.e_ident[EI_CLASS ] =ELFCLASS32 ; - elf_header.e_ident[EI_DATA ] = s->dump_info.d_endian; - elf_header.e_ident[EI_VERSION ] =EV_CURRENT ; - elf_header.e_type =cpu_to_dump16 (s,ET_CORE ); - elf_header.e_machine =cpu_to_dump16 (s, s->dump_info.d_machine); - elf_header.e_version =cpu_to_dump32 (s,EV_CURRENT ); - elf_header.e_ehsize =cpu_to_dump16 (s,sizeof (elf_header)); - elf_header.e_phoff =cpu_to_dump32 (s, s->phdr_offset); - elf_header.e_phentsize =cpu_to_dump16 (s,sizeof (Elf32_Phdr)); - elf_header.e_phnum =cpu_to_dump16 (s, phnum); +memcpy (elf_header,ELFMAG ,SELFMAG ); + elf_header->e_ident[EI_CLASS ] =ELFCLASS32 ; + elf_header->e_ident[EI_DATA ] = s->dump_info.d_endian; + elf_header->e_ident[EI_VERSION ] =EV_CURRENT ; + elf_header->e_type =cpu_to_dump16 (s,ET_CORE ); + elf_header->e_machine =cpu_to_dump16 (s, s->dump_info.d_machine); + elf_header->e_version =cpu_to_dump32 (s,EV_CURRENT ); + elf_header->e_ehsize =cpu_to_dump16 (s,sizeof (*elf_header)); + elf_header->e_phoff =cpu_to_dump32 (s, s->phdr_offset); + elf_header->e_phentsize =cpu_to_dump16 (s,sizeof (Elf32_Phdr)); + elf_header->e_phnum =cpu_to_dump16 (s, phnum);if (s->shdr_num) { - elf_header.e_shoff =cpu_to_dump32 (s, s->shdr_offset); - elf_header.e_shentsize =cpu_to_dump16 (s,sizeof (Elf32_Shdr)); - elf_header.e_shnum =cpu_to_dump16 (s, s->shdr_num); - } - - ret =fd_write_vmcore (&elf_header,sizeof (elf_header), s); -if (ret <0 ) { -error_setg_errno (errp, -ret,"dump: failed to write elf header" ); + elf_header->e_shoff =cpu_to_dump32 (s, s->shdr_offset); + elf_header->e_shentsize =cpu_to_dump16 (s,sizeof (Elf32_Shdr)); + elf_header->e_shnum =cpu_to_dump16 (s, s->shdr_num); } }
@@ -528,6 +505,26 @@ static void write_elf_notes(DumpState *s, Error **errp) } } +static void prepare_elf_header (DumpState *s) +{ +if (dump_is_64bit (s)) { +prepare_elf64_header (s); + }else { +prepare_elf32_header (s); + } +} + +static void write_elf_header (DumpState *s,Error **errp) +{ +size_t size =dump_is_64bit (s) ?sizeof (Elf64_Ehdr) :sizeof (Elf32_Ehdr); +int ret; + + ret =fd_write_vmcore (s->elf_header, size, s); +if (ret <0 ) { +error_setg_errno (errp, -ret,"dump: failed to write elf header" ); + } +} +/* write elf header, PT_NOTE and elf note to vmcore. */ static void dump_begin (DumpState *s,Error **errp) {
@@ -557,12 +554,11 @@ static void dump_begin(DumpState *s, Error **errp)* vmcore. */ -/* write elf header to vmcore */ -if (dump_is_64bit (s)) { -write_elf64_header (s, errp); - }else { -write_elf32_header (s, errp); - } +/* Write elf header to buffer */ +prepare_elf_header (s); + +/* Start to write stuff into files*/ +write_elf_header (s, errp);if (*errp) {return ; }
@@ -1642,6 +1638,9 @@ static void dump_init(DumpState *s, int fd, bool has_format, goto cleanup; } + s->elf_header =g_malloc0 (dump_is_64bit (s) ? +sizeof (Elf64_Ehdr) :sizeof (Elf32_Ehdr)); +/* * The goal of this block is to (a) update the previously guessed * phys_base, (b) copy the guest note out of the guest.
include/sysemu/dump.h +1 -0
@@ -171,6 +171,7 @@ typedef struct DumpState {int64_t begin;/* Start address of the chunk we want to dump */ int64_t length;/* Length of the dump we want to dump */ +void *elf_header;uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */ uint32_t nr_cpus;/* number of guest's cpu */
Signature · 1 line
2.34.1
Re: [PATCH v2 02/11] dump: Allocate header
Quoted 6 lines · Janosch Frank
Allocating the header lets us write it at a later time and hence also allows us to change section and segment table offsets until we finally write it.
Signed-off-by Janosch Frank <[email protected]>
Quoted 156 lines
--- dump/dump.c | 127 +++++++++++++++++++++--------------------- include/sysemu/dump.h | 1 + 2 files changed, 64 insertions(+), 64 deletions(-)dump/dump.c +55
-58@@ -98,6 +98,7 @@ static int dump_cleanup(DumpState *s)memory_mapping_list_free (&s->list);close (s->fd);g_free (s->guest_note); +g_free (s->elf_header); s->guest_note =NULL ;if (s->resume) {if (s->detached) {@@ -126,73 +127,49 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)return 0 ; } -static void write_elf64_header (DumpState *s,Error **errp) +static void prepare_elf64_header (DumpState *s) { -/* -* phnum in the elf header is 16 bit, if we have more segments we -* set phnum to PN_XNUM and write the real number of segments to a -* special section. -*/ -uint16_t phnum =MIN (s->phdr_num,PN_XNUM ); -Elf64_Ehdr elf_header; -int ret; +uint16_t phnum = s->phdr_num >=PN_XNUM ?PN_XNUM : s->phdr_num; +Elf64_Ehdr *elf_header = s->elf_header; -memset (&elf_header,0 ,sizeof (Elf64_Ehdr)); -memcpy (&elf_header,ELFMAG ,SELFMAG ); - elf_header.e_ident[EI_CLASS ] =ELFCLASS64 ; - elf_header.e_ident[EI_DATA ] = s->dump_info.d_endian; - elf_header.e_ident[EI_VERSION ] =EV_CURRENT ; - elf_header.e_type =cpu_to_dump16 (s,ET_CORE ); - elf_header.e_machine =cpu_to_dump16 (s, s->dump_info.d_machine); - elf_header.e_version =cpu_to_dump32 (s,EV_CURRENT ); - elf_header.e_ehsize =cpu_to_dump16 (s,sizeof (elf_header)); - elf_header.e_phoff =cpu_to_dump64 (s, s->phdr_offset); - elf_header.e_phentsize =cpu_to_dump16 (s,sizeof (Elf64_Phdr)); - elf_header.e_phnum =cpu_to_dump16 (s, phnum); +memcpy (elf_header,ELFMAG ,SELFMAG ); + elf_header->e_ident[EI_CLASS ] =ELFCLASS64 ; + elf_header->e_ident[EI_DATA ] = s->dump_info.d_endian; + elf_header->e_ident[EI_VERSION ] =EV_CURRENT ; + elf_header->e_type =cpu_to_dump16 (s,ET_CORE ); + elf_header->e_machine =cpu_to_dump16 (s, s->dump_info.d_machine); + elf_header->e_version =cpu_to_dump32 (s,EV_CURRENT ); + elf_header->e_ehsize =cpu_to_dump16 (s,sizeof (*elf_header)); + elf_header->e_phoff =cpu_to_dump64 (s, s->phdr_offset); + elf_header->e_phentsize =cpu_to_dump16 (s,sizeof (Elf64_Phdr)); + elf_header->e_phnum =cpu_to_dump16 (s, phnum);if (s->shdr_num) { - elf_header.e_shoff =cpu_to_dump64 (s, s->shdr_offset); - elf_header.e_shentsize =cpu_to_dump16 (s,sizeof (Elf64_Shdr)); - elf_header.e_shnum =cpu_to_dump16 (s, s->shdr_num); - } - - ret =fd_write_vmcore (&elf_header,sizeof (elf_header), s); -if (ret <0 ) { -error_setg_errno (errp, -ret,"dump: failed to write elf header" ); + elf_header->e_shoff =cpu_to_dump64 (s, s->shdr_offset); + elf_header->e_shentsize =cpu_to_dump16 (s,sizeof (Elf64_Shdr)); + elf_header->e_shnum =cpu_to_dump16 (s, s->shdr_num); } } -static void write_elf32_header (DumpState *s,Error **errp) +static void prepare_elf32_header (DumpState *s) { -/* -* phnum in the elf header is 16 bit, if we have more segments we -* set phnum to PN_XNUM and write the real number of segments to a -* special section. -*/ -uint16_t phnum =MIN (s->phdr_num,PN_XNUM ); -Elf32_Ehdr elf_header; -int ret; +uint16_t phnum = s->phdr_num >=PN_XNUM ?PN_XNUM : s->phdr_num; +Elf32_Ehdr *elf_header = s->elf_header; -memset (&elf_header,0 ,sizeof (Elf32_Ehdr)); -memcpy (&elf_header,ELFMAG ,SELFMAG ); - elf_header.e_ident[EI_CLASS ] =ELFCLASS32 ; - elf_header.e_ident[EI_DATA ] = s->dump_info.d_endian; - elf_header.e_ident[EI_VERSION ] =EV_CURRENT ; - elf_header.e_type =cpu_to_dump16 (s,ET_CORE ); - elf_header.e_machine =cpu_to_dump16 (s, s->dump_info.d_machine); - elf_header.e_version =cpu_to_dump32 (s,EV_CURRENT ); - elf_header.e_ehsize =cpu_to_dump16 (s,sizeof (elf_header)); - elf_header.e_phoff =cpu_to_dump32 (s, s->phdr_offset); - elf_header.e_phentsize =cpu_to_dump16 (s,sizeof (Elf32_Phdr)); - elf_header.e_phnum =cpu_to_dump16 (s, phnum); +memcpy (elf_header,ELFMAG ,SELFMAG ); + elf_header->e_ident[EI_CLASS ] =ELFCLASS32 ; + elf_header->e_ident[EI_DATA ] = s->dump_info.d_endian; + elf_header->e_ident[EI_VERSION ] =EV_CURRENT ; + elf_header->e_type =cpu_to_dump16 (s,ET_CORE ); + elf_header->e_machine =cpu_to_dump16 (s, s->dump_info.d_machine); + elf_header->e_version =cpu_to_dump32 (s,EV_CURRENT ); + elf_header->e_ehsize =cpu_to_dump16 (s,sizeof (*elf_header)); + elf_header->e_phoff =cpu_to_dump32 (s, s->phdr_offset); + elf_header->e_phentsize =cpu_to_dump16 (s,sizeof (Elf32_Phdr)); + elf_header->e_phnum =cpu_to_dump16 (s, phnum);if (s->shdr_num) { - elf_header.e_shoff =cpu_to_dump32 (s, s->shdr_offset); - elf_header.e_shentsize =cpu_to_dump16 (s,sizeof (Elf32_Shdr)); - elf_header.e_shnum =cpu_to_dump16 (s, s->shdr_num); - } - - ret =fd_write_vmcore (&elf_header,sizeof (elf_header), s); -if (ret <0 ) { -error_setg_errno (errp, -ret,"dump: failed to write elf header" ); + elf_header->e_shoff =cpu_to_dump32 (s, s->shdr_offset); + elf_header->e_shentsize =cpu_to_dump16 (s,sizeof (Elf32_Shdr)); + elf_header->e_shnum =cpu_to_dump16 (s, s->shdr_num); } }@@ -528,6 +505,26 @@ static void write_elf_notes(DumpState *s, Error **errp) } } +static void prepare_elf_header (DumpState *s) +{ +if (dump_is_64bit (s)) { +prepare_elf64_header (s); + }else { +prepare_elf32_header (s); + } +} + +static void write_elf_header (DumpState *s,Error **errp) +{ +size_t size =dump_is_64bit (s) ?sizeof (Elf64_Ehdr) :sizeof (Elf32_Ehdr); +int ret; + + ret =fd_write_vmcore (s->elf_header, size, s); +if (ret <0 ) { +error_setg_errno (errp, -ret,"dump: failed to write elf header" ); + } +} +/* write elf header, PT_NOTE and elf note to vmcore. */ static void dump_begin (DumpState *s,Error **errp) {@@ -557,12 +554,11 @@ static void dump_begin(DumpState *s, Error **errp)* vmcore. */
dump/dump.c static void dump_begin(DumpState *s, Error **errp) · line 560
Quoted 10 lines
dump/dump.c +4
-6-/* write elf header to vmcore */ -if (dump_is_64bit (s)) { -write_elf64_header (s, errp); - }else { -write_elf32_header (s, errp); - } +/* Write elf header to buffer */ +prepare_elf_header (s); + +/* Start to write stuff into files*/
nits: missing space, files->file descriptor/stream ?
Quoted 29 lines
dump/dump.c +4
-0+write_elf_header (s, errp);if (*errp) {return ; }@@ -1642,6 +1638,9 @@ static void dump_init(DumpState *s, int fd, bool has_format, goto cleanup; } + s->elf_header =g_malloc0 (dump_is_64bit (s) ? +sizeof (Elf64_Ehdr) :sizeof (Elf32_Ehdr)); +/* * The goal of this block is to (a) update the previously guessed * phys_base, (b) copy the guest note out of the guest. include/sysemu/dump.h +1
-1@@ -171,6 +171,7 @@ typedef struct DumpState {int64_t begin;/* Start address of the chunk we want to dump */ int64_t length;/* Length of the dump we want to dump */ +void *elf_header;uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */ uint32_t nr_cpus;/* number of guest's cpu */ --2.34.1
PATCH v2 3/11 dump: Split write of section headers and data and add a prepare step
In reply to Janosch FrankBy splitting the writing of the section headers and (future) section data we prepare for the addition of a string table section and architecture sections.
--- dump/dump.c | 116 ++++++++++++++++++++++++++++++++---------- include/sysemu/dump.h | 4 ++ 2 files changed, 94 insertions(+), 26 deletions(-)
dump/dump.c +90 -26
@@ -342,30 +342,73 @@ static void write_elf_phdr_note(DumpState *s, Error **errp) } } -static void write_elf_section (DumpState *s,int type,Error **errp) +static size_t write_elf_section_hdr_zero (DumpState *s,void *buff) { -Elf32_Shdr shdr32; -Elf64_Shdr shdr64; -int shdr_size; -void *shdr; -int ret; +if (dump_is_64bit (s)) { +Elf64_Shdr *shdr64 = buff; -if (type ==0 ) { - shdr_size =sizeof (Elf32_Shdr); -memset (&shdr32,0 , shdr_size); - shdr32.sh_info =cpu_to_dump32 (s, s->phdr_num); - shdr = &shdr32; +memset (buff,0 ,sizeof (Elf64_Shdr)); + shdr64->sh_info =cpu_to_dump32 (s, s->phdr_num); }else { - shdr_size =sizeof (Elf64_Shdr); -memset (&shdr64,0 , shdr_size); - shdr64.sh_info =cpu_to_dump32 (s, s->phdr_num); - shdr = &shdr64; +Elf32_Shdr *shdr32 = buff; + +memset (buff,0 ,sizeof (Elf32_Shdr)); + shdr32->sh_info =cpu_to_dump32 (s, s->phdr_num); } - ret =fd_write_vmcore (shdr, shdr_size, s); +return dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); +} + +static void prepare_elf_section_hdrs (DumpState *s) +{ +uint8_t *buff_hdr; +size_t len, sizeof_shdr; + +/* +* Section ordering: +* - HDR zero (if needed) +*/ + sizeof_shdr =dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); + len = sizeof_shdr * s->shdr_num; + s->elf_section_hdrs =g_malloc0 (len); + buff_hdr = s->elf_section_hdrs; + +/* Write special section first */ +if (s->phdr_num ==PN_XNUM ) { +write_elf_section_hdr_zero (s, buff_hdr); + } +} + +static void prepare_elf_sections (DumpState *s,Error **errp) +{ +if (!s->shdr_num) { +return ; + } + +prepare_elf_section_hdrs (s); +} + +static void write_elf_section_headers (DumpState *s,Error **errp) +{ +size_t sizeof_shdr; +int ret; + + sizeof_shdr =dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); + + ret =fd_write_vmcore (s->elf_section_hdrs, s->shdr_num * sizeof_shdr, s);if (ret <0 ) { -error_setg_errno (errp, -ret, -"dump: failed to write section header table" ); +error_setg_errno (errp, -ret,"dump: failed to write section data" ); + } +} + +static void write_elf_sections (DumpState *s,Error **errp) +{ +int ret; + +/* Write section zero */ + ret =fd_write_vmcore (s->elf_section_data, s->elf_section_data_size, s); +if (ret <0 ) { +error_setg_errno (errp, -ret,"dump: failed to write section data" ); } }
@@ -557,12 +600,22 @@ static void dump_begin(DumpState *s, Error **errp)/* Write elf header to buffer */ prepare_elf_header (s); +prepare_elf_sections (s, errp); +if (*errp) { +return ; + } +/* Start to write stuff into files*/ write_elf_header (s, errp);if (*errp) {return ; } +write_elf_section_headers (s, errp); +if (*errp) { +return ; + } +/* write PT_NOTE to vmcore */ write_elf_phdr_note (s, errp);if (*errp) {
@@ -575,14 +628,6 @@ static void dump_begin(DumpState *s, Error **errp)return ; } -/* write section to vmcore */ -if (s->shdr_num) { -write_elf_section (s,1 , errp); -if (*errp) { -return ; - } - } -/* write notes to vmcore */ write_elf_notes (s, errp); }
@@ -610,6 +655,19 @@ static void dump_iterate(DumpState *s, Error **errp) } } +static void dump_end (DumpState *s,Error **errp) +{ +ERRP_GUARD (); + +if (!s->elf_section_data_size) { +return ; + } + s->elf_section_data =g_malloc0 (s->elf_section_data_size); + +/* write sections to vmcore */ +write_elf_sections (s, errp); +} +static void create_vmcore (DumpState *s,Error **errp) {ERRP_GUARD ();
@@ -620,6 +678,12 @@ static void create_vmcore(DumpState *s, Error **errp) }dump_iterate (s, errp); +if (*errp) { +return ; + } + +/* Write section data after memory has been dumped */ +dump_end (s, errp); }static int write_start_flat_header (int fd)
include/sysemu/dump.h +4 -0
@@ -172,6 +172,10 @@ typedef struct DumpState {int64_t length;/* Length of the dump we want to dump */ void *elf_header; +void *elf_section_hdrs; +uint64_t elf_section_data_size; +void *elf_section_data; +uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */ uint32_t nr_cpus;/* number of guest's cpu */
Signature · 1 line
2.34.1
Re: [PATCH v2 03/11] dump: Split write of section headers and data and add a prepare step
Hi
Quoted 16 lines · Janosch Frank
By splitting the writing of the section headers and (future) section data we prepare for the addition of a string table section and architecture sections.
Signed-off-by Janosch Frank <[email protected]>--- dump/dump.c | 116 ++++++++++++++++++++++++++++++++---------- include/sysemu/dump.h | 4 ++ 2 files changed, 94 insertions(+), 26 deletions(-)dump/dump.c +0
-0
dump/dump.c static void write_elf_phdr_note(DumpState *s, Error **errp) · line 345
Quoted 5 lines
dump/dump.c +1
-1@@ -342,30 +342,73 @@ static void write_elf_phdr_note(DumpState *s, Error **errp) } } -static void write_elf_section (DumpState *s,int type,Error **errp) +static size_t write_elf_section_hdr_zero (DumpState *s,void *buff)
Since the function no longer write, I'd suggest to rename it with prepare_ prefix
Quoted 5 lines
dump/dump.c +0
-4{ -Elf32_Shdr shdr32; -Elf64_Shdr shdr64; -int shdr_size; -void *shdr;
dump/dump.c static void write_elf_phdr_note(DumpState *s, Error **errp) · line 350
Quoted 10 lines
dump/dump.c +3
-6-int ret; +if (dump_is_64bit (s)) { +Elf64_Shdr *shdr64 = buff; -if (type ==0 ) { - shdr_size =sizeof (Elf32_Shdr); -memset (&shdr32,0 , shdr_size); - shdr32.sh_info =cpu_to_dump32 (s, s->phdr_num); - shdr = &shdr32; +memset (buff,0 ,sizeof (Elf64_Shdr));
You can drop this
dump/dump.c static void write_elf_phdr_note(DumpState *s, Error **errp) · line 355
Quoted 9 lines
dump/dump.c +4
-4+ shdr64->sh_info =cpu_to_dump32 (s, s->phdr_num); }else { - shdr_size =sizeof (Elf64_Shdr); -memset (&shdr64,0 , shdr_size); - shdr64.sh_info =cpu_to_dump32 (s, s->phdr_num); - shdr = &shdr64; +Elf32_Shdr *shdr32 = buff; + +memset (buff,0 ,sizeof (Elf32_Shdr));
and this
Quoted 9 lines
dump/dump.c +6
-1+ shdr32->sh_info =cpu_to_dump32 (s, s->phdr_num); } - ret =fd_write_vmcore (shdr, shdr_size, s); +return dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); +} + +static void prepare_elf_section_hdrs (DumpState *s) +{
dump/dump.c static void write_elf_phdr_note(DumpState *s, Error **errp) · line 373
Quoted 10 lines
dump/dump.c +10
-0+uint8_t *buff_hdr; +size_t len, sizeof_shdr; + +/* +* Section ordering: +* - HDR zero (if needed) +*/ + sizeof_shdr =dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); + len = sizeof_shdr * s->shdr_num; + s->elf_section_hdrs =g_malloc0 (len);
since you alloc0 here
dump/dump.c static void write_elf_phdr_note(DumpState *s, Error **errp) · line 378
Quoted 5 lines
dump/dump.c +5
-0+ buff_hdr = s->elf_section_hdrs; + +/* Write special section first */ +if (s->phdr_num ==PN_XNUM ) { +write_elf_section_hdr_zero (s, buff_hdr);
Eventually, drop buff_hdr, and pass only "s" as argument
+ Indentation is off
Quoted 14 lines
dump/dump.c +14
-0+ } +} + +static void prepare_elf_sections (DumpState *s,Error **errp) +{ +if (!s->shdr_num) { +return ; + } + +prepare_elf_section_hdrs (s); +} + +static void write_elf_section_headers (DumpState *s,Error **errp) +{
dump/dump.c static void write_elf_phdr_note(DumpState *s, Error **errp) · line 400
Quoted 10 lines
dump/dump.c +7
-2+size_t sizeof_shdr; +int ret; + + sizeof_shdr =dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); + + ret =fd_write_vmcore (s->elf_section_hdrs, s->shdr_num * sizeof_shdr, s);if (ret <0 ) { -error_setg_errno (errp, -ret, -"dump: failed to write section header table" ); +error_setg_errno (errp, -ret,"dump: failed to write section data" );
nit: data->header
Quoted 20 lines
dump/dump.c +13
-0+ } +} + +static void write_elf_sections (DumpState *s,Error **errp) +{ +int ret; + +/* Write section zero */ + ret =fd_write_vmcore (s->elf_section_data, s->elf_section_data_size, s); +if (ret <0 ) { +error_setg_errno (errp, -ret,"dump: failed to write section data" ); } }@@ -557,12 +600,22 @@ static void dump_begin(DumpState *s, Error **errp)/* Write elf header to buffer */ prepare_elf_header (s); +prepare_elf_sections (s, errp); +if (*errp) {
dump/dump.c static void dump_begin(DumpState *s, Error **errp) · line 614
Quoted 10 lines
dump/dump.c +4
-0+return ; + } +/* Start to write stuff into files*/ write_elf_header (s, errp);if (*errp) {return ; } +write_elf_section_headers (s, errp);
Why do you reorder the sections? Could you explain in the commit message why? Is this is format compliant? and update the comment above? thanks
Quoted 73 lines
dump/dump.c +23
-8+if (*errp) { +return ; + } +/* write PT_NOTE to vmcore */ write_elf_phdr_note (s, errp);if (*errp) {@@ -575,14 +628,6 @@ static void dump_begin(DumpState *s, Error **errp)return ; } -/* write section to vmcore */ -if (s->shdr_num) { -write_elf_section (s,1 , errp); -if (*errp) { -return ; - } - } -/* write notes to vmcore */ write_elf_notes (s, errp); }@@ -610,6 +655,19 @@ static void dump_iterate(DumpState *s, Error **errp) } } +static void dump_end (DumpState *s,Error **errp) +{ +ERRP_GUARD (); + +if (!s->elf_section_data_size) { +return ; + } + s->elf_section_data =g_malloc0 (s->elf_section_data_size); + +/* write sections to vmcore */ +write_elf_sections (s, errp); +} +static void create_vmcore (DumpState *s,Error **errp) {ERRP_GUARD ();@@ -620,6 +678,12 @@ static void create_vmcore(DumpState *s, Error **errp) }dump_iterate (s, errp); +if (*errp) { +return ; + } + +/* Write section data after memory has been dumped */ +dump_end (s, errp); }static int write_start_flat_header (int fd)include/sysemu/dump.h +4
-1@@ -172,6 +172,10 @@ typedef struct DumpState {int64_t length;/* Length of the dump we want to dump */ void *elf_header; +void *elf_section_hdrs; +uint64_t elf_section_data_size; +void *elf_section_data; +uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */ uint32_t nr_cpus;/* number of guest's cpu */ --2.34.1
Re: [PATCH v2 03/11] dump: Split write of section headers and data and add a prepare step
Quoted 10 lines · Marc-André Lureau
Hi
Quoted 7 lines · Janosch Frank
By splitting the writing of the section headers and (future) section data we prepare for the addition of a string table section and architecture sections.
Signed-off-by Janosch Frank <[email protected]>---
[...]
Quoted 15 lines
Quoted 15 lines
dump/dump.c +5
-0@@ -557,12 +600,22 @@ static void dump_begin(DumpState *s, Error **errp)/* Write elf header to buffer */ prepare_elf_header (s); +prepare_elf_sections (s, errp); +if (*errp) { +return ; + } +/* Start to write stuff into files*/ write_elf_header (s, errp);if (*errp) {return ; }
Quoted 5 lines
dump/dump.c static void dump_begin(DumpState *s, Error **errp) · line 614
Quoted 1 line
dump/dump.c +1
-0+write_elf_section_headers (s, errp);Why do you reorder the sections? Could you explain in the commit message why? Is this is format compliant? and update the comment above? thanks
Having the section data at the end of the file is unfortunately a s390 PV requirement since we can only grab the encrypted page tweaks and counts *after* all of the memory has been encrypted.
The sections are the most obvious way to add such data to the file since they are basically unused right now and we're able to write a string table at the very end after everyone registered their strings.
All of this is ELF compliant AFAIK, that's why elf specifies offsets of the headers and the data. From what I see only the main elf header needs to start at offset 0.
PATCH v2 4/11 dump: Reorder struct DumpState
In reply to Janosch FrankLet's move ELF related members into one block and guest memory related ones into another to improve readability.
--- include/sysemu/dump.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
include/sysemu/dump.h +10 -7
@@ -154,15 +154,8 @@ typedef struct DumpState {GuestPhysBlockList guest_phys_blocks;ArchDumpInfo dump_info;MemoryMappingList list; -uint32_t phdr_num; -uint32_t shdr_num;bool resume;bool detached; -ssize_t note_size; -hwaddr shdr_offset; -hwaddr phdr_offset; -hwaddr section_offset; -hwaddr note_offset;hwaddr memory_offset;int fd;
@@ -171,6 +164,16 @@ typedef struct DumpState {int64_t begin;/* Start address of the chunk we want to dump */ int64_t length;/* Length of the dump we want to dump */ +/* Elf dump related data */ +uint32_t phdr_num; +uint32_t shdr_num; +uint32_t sh_info; +ssize_t note_size; +hwaddr shdr_offset; +hwaddr phdr_offset; +hwaddr note_offset; +hwaddr section_offset; +void *elf_header;void *elf_section_hdrs;uint64_t elf_section_data_size;
Signature · 1 line
2.34.1
Re: [PATCH v2 04/11] dump: Reorder struct DumpState
Quoted 6 lines · Janosch Frank
Let's move ELF related members into one block and guest memory related ones into another to improve readability.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Quoted 44 lines
--- include/sysemu/dump.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)include/sysemu/dump.h +10
-8@@ -154,15 +154,8 @@ typedef struct DumpState {GuestPhysBlockList guest_phys_blocks;ArchDumpInfo dump_info;MemoryMappingList list; -uint32_t phdr_num; -uint32_t shdr_num;bool resume;bool detached; -ssize_t note_size; -hwaddr shdr_offset; -hwaddr phdr_offset; -hwaddr section_offset; -hwaddr note_offset;hwaddr memory_offset;int fd;@@ -171,6 +164,16 @@ typedef struct DumpState {int64_t begin;/* Start address of the chunk we want to dump */ int64_t length;/* Length of the dump we want to dump */ +/* Elf dump related data */ +uint32_t phdr_num; +uint32_t shdr_num; +uint32_t sh_info; +ssize_t note_size; +hwaddr shdr_offset; +hwaddr phdr_offset; +hwaddr note_offset; +hwaddr section_offset; +void *elf_header;void *elf_section_hdrs;uint64_t elf_section_data_size; --2.34.1
PATCH v2 5/11 dump/dump: Add section string table support
In reply to Janosch FrankTime to add a bit more descriptiveness to the dumps.
--- dump/dump.c | 106 ++++++++++++++++++++++++++++++++++++------ include/sysemu/dump.h | 1 + 2 files changed, 94 insertions(+), 13 deletions(-)
dump/dump.c +93 -13
@@ -99,6 +99,7 @@ static int dump_cleanup(DumpState *s)close (s->fd);g_free (s->guest_note);g_free (s->elf_header); +g_array_unref (s->string_table_buf); s->guest_note =NULL ;if (s->resume) {if (s->detached) {
@@ -359,14 +360,47 @@ static size_t write_elf_section_hdr_zero(DumpState *s, void *buff)return dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); } +static void write_elf_section_hdr_string (DumpState *s,void *buff) +{ +Elf32_Shdr shdr32; +Elf64_Shdr shdr64; +int shdr_size; +void *shdr = buff; + +if (dump_is_64bit (s)) { + shdr_size =sizeof (Elf64_Shdr); +memset (&shdr64,0 , shdr_size); + shdr64.sh_type =SHT_STRTAB ; + shdr64.sh_offset = s->section_offset + s->elf_section_data_size; + shdr64.sh_name = s->string_table_buf->len; +g_array_append_vals (s->string_table_buf,".strtab" ,sizeof (".strtab" )); + shdr64.sh_size = s->string_table_buf->len; + shdr = &shdr64; + }else { + shdr_size =sizeof (Elf32_Shdr); +memset (&shdr32,0 , shdr_size); + shdr32.sh_type =SHT_STRTAB ; + shdr32.sh_offset = s->section_offset + s->elf_section_data_size; + shdr32.sh_name = s->string_table_buf->len; +g_array_append_vals (s->string_table_buf,".strtab" ,sizeof (".strtab" )); + shdr32.sh_size = s->string_table_buf->len; + shdr = &shdr32; + } + +memcpy (buff, shdr, shdr_size); +} +static void prepare_elf_section_hdrs (DumpState *s) {uint8_t *buff_hdr; -size_t len, sizeof_shdr; +size_t len, size =0 , sizeof_shdr; +Elf64_Ehdr *hdr64 = s->elf_header; +Elf32_Ehdr *hdr32 = s->elf_header;/* * Section ordering: * - HDR zero (if needed) +* - String table hdr */ sizeof_shdr =dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); len = sizeof_shdr * s->shdr_num;
@@ -377,6 +411,22 @@ static void prepare_elf_section_hdrs(DumpState *s)if (s->phdr_num ==PN_XNUM ) {write_elf_section_hdr_zero (s, buff_hdr); } + buff_hdr += size; + +if (s->shdr_num <2 ) { +return ; + } + +/* +* String table needs to be last section since strings are added +* via arch_sections_write_hdr(). +*/ +write_elf_section_hdr_string (s, buff_hdr); +if (dump_is_64bit (s)) { + hdr64->e_shstrndx =cpu_to_dump16 (s, s->shdr_num -1 ); + }else { + hdr32->e_shstrndx =cpu_to_dump16 (s, s->shdr_num -1 ); + } }static void prepare_elf_sections (DumpState *s,Error **errp)
@@ -405,11 +455,18 @@ static void write_elf_sections(DumpState *s, Error **errp) {int ret; -/* Write section zero */ +/* Write section zero and arch sections */ ret =fd_write_vmcore (s->elf_section_data, s->elf_section_data_size, s);if (ret <0 ) {error_setg_errno (errp, -ret,"dump: failed to write section data" ); } + +/* Write string table data */ + ret =fd_write_vmcore (s->string_table_buf->data, + s->string_table_buf->len, s); +if (ret <0 ) { +error_setg_errno (errp, -ret,"dump: failed to write string table data" ); + } }static void write_data (DumpState *s,void *buf,int length,Error **errp)
@@ -592,6 +649,9 @@ static void dump_begin(DumpState *s, Error **errp)* -------------- * | memory | * -------------- +* | sectn data | +* -------------- +* * we only know where the memory is saved after we write elf note into * vmcore.
@@ -677,6 +737,7 @@ static void create_vmcore(DumpState *s, Error **errp)return ; } +/* Iterate over memory and dump it to file */ dump_iterate (s, errp);if (*errp) {return ;
@@ -1659,6 +1720,13 @@ static void dump_init(DumpState *s, int fd, bool has_format, s->has_filter = has_filter; s->begin = begin; s->length = length; +/* First index is 0, it's the special null name */ + s->string_table_buf =g_array_new (FALSE, TRUE,1 ); +/* +* Allocate the null name, due to the clearing option set to true +* it will be 0. +*/ +g_array_set_size (s->string_table_buf,1 );memory_mapping_list_init (&s->list);
@@ -1819,19 +1887,31 @@ static void dump_init(DumpState *s, int fd, bool has_format, } } -if (dump_is_64bit (s)) { - s->phdr_offset =sizeof (Elf64_Ehdr); - s->shdr_offset = s->phdr_offset +sizeof (Elf64_Phdr) * s->phdr_num; - s->note_offset = s->shdr_offset +sizeof (Elf64_Shdr) * s->shdr_num; - s->memory_offset = s->note_offset + s->note_size; - }else { - - s->phdr_offset =sizeof (Elf32_Ehdr); - s->shdr_offset = s->phdr_offset +sizeof (Elf32_Phdr) * s->phdr_num; - s->note_offset = s->shdr_offset +sizeof (Elf32_Shdr) * s->shdr_num; - s->memory_offset = s->note_offset + s->note_size; +/* +* calculate shdr_num and elf_section_data_size so we know the offsets and +* sizes of all parts. +* +* If phdr_num overflowed we have at least one section header +* More sections/hdrs can be added by the architectures +*/ +if (s->shdr_num >1 ) { +/* Reserve the string table */ + s->shdr_num +=1 ; } + tmp = (s->phdr_num ==PN_XNUM ) ? s->sh_info : s->phdr_num; +if (dump_is_64bit (s)) { + s->shdr_offset =sizeof (Elf64_Ehdr); + s->phdr_offset = s->shdr_offset +sizeof (Elf64_Shdr) * s->shdr_num; + s->note_offset = s->phdr_offset +sizeof (Elf64_Phdr) * tmp; + }else { + s->shdr_offset =sizeof (Elf32_Ehdr); + s->phdr_offset = s->shdr_offset +sizeof (Elf32_Shdr) * s->shdr_num; + s->note_offset = s->phdr_offset +sizeof (Elf32_Phdr) * tmp; + } + s->memory_offset = s->note_offset + s->note_size; + s->section_offset = s->memory_offset + s->total_size; +return ; cleanup:
include/sysemu/dump.h +1 -0
@@ -178,6 +178,7 @@ typedef struct DumpState {void *elf_section_hdrs;uint64_t elf_section_data_size;void *elf_section_data; +GArray *string_table_buf;/* String table section */ uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */
Signature · 1 line
2.34.1
Re: [PATCH v2 05/11] dump/dump: Add section string table support
Hi
Quoted 2 lines · Janosch Frank
Time to add a bit more descriptiveness to the dumps.
Please add some more description & motivation to the patch (supposedly necessary for next patches), and explain that it currently doesn't change the dump (afaict).
Quoted 172 lines
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- dump/dump.c | 106 ++++++++++++++++++++++++++++++++++++------ include/sysemu/dump.h | 1 + 2 files changed, 94 insertions(+), 13 deletions(-)dump/dump.c +81
-13@@ -99,6 +99,7 @@ static int dump_cleanup(DumpState *s)close (s->fd);g_free (s->guest_note);g_free (s->elf_header); +g_array_unref (s->string_table_buf); s->guest_note =NULL ;if (s->resume) {if (s->detached) {@@ -359,14 +360,47 @@ static size_t write_elf_section_hdr_zero(DumpState *s, void *buff)return dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); } +static void write_elf_section_hdr_string (DumpState *s,void *buff) +{ +Elf32_Shdr shdr32; +Elf64_Shdr shdr64; +int shdr_size; +void *shdr = buff; + +if (dump_is_64bit (s)) { + shdr_size =sizeof (Elf64_Shdr); +memset (&shdr64,0 , shdr_size); + shdr64.sh_type =SHT_STRTAB ; + shdr64.sh_offset = s->section_offset + s->elf_section_data_size; + shdr64.sh_name = s->string_table_buf->len; +g_array_append_vals (s->string_table_buf,".strtab" ,sizeof (".strtab" )); + shdr64.sh_size = s->string_table_buf->len; + shdr = &shdr64; + }else { + shdr_size =sizeof (Elf32_Shdr); +memset (&shdr32,0 , shdr_size); + shdr32.sh_type =SHT_STRTAB ; + shdr32.sh_offset = s->section_offset + s->elf_section_data_size; + shdr32.sh_name = s->string_table_buf->len; +g_array_append_vals (s->string_table_buf,".strtab" ,sizeof (".strtab" )); + shdr32.sh_size = s->string_table_buf->len; + shdr = &shdr32; + } + +memcpy (buff, shdr, shdr_size); +} +static void prepare_elf_section_hdrs (DumpState *s) {uint8_t *buff_hdr; -size_t len, sizeof_shdr; +size_t len, size =0 , sizeof_shdr; +Elf64_Ehdr *hdr64 = s->elf_header; +Elf32_Ehdr *hdr32 = s->elf_header;/* * Section ordering: * - HDR zero (if needed) +* - String table hdr */ sizeof_shdr =dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr); len = sizeof_shdr * s->shdr_num;@@ -377,6 +411,22 @@ static void prepare_elf_section_hdrs(DumpState *s)if (s->phdr_num ==PN_XNUM ) {write_elf_section_hdr_zero (s, buff_hdr); } + buff_hdr += size; + +if (s->shdr_num <2 ) { +return ; + } + +/* +* String table needs to be last section since strings are added +* via arch_sections_write_hdr(). +*/ +write_elf_section_hdr_string (s, buff_hdr); +if (dump_is_64bit (s)) { + hdr64->e_shstrndx =cpu_to_dump16 (s, s->shdr_num -1 ); + }else { + hdr32->e_shstrndx =cpu_to_dump16 (s, s->shdr_num -1 ); + } }static void prepare_elf_sections (DumpState *s,Error **errp)@@ -405,11 +455,18 @@ static void write_elf_sections(DumpState *s, Error **errp) {int ret; -/* Write section zero */ +/* Write section zero and arch sections */ ret =fd_write_vmcore (s->elf_section_data, s->elf_section_data_size, s);if (ret <0 ) {error_setg_errno (errp, -ret,"dump: failed to write section data" ); } + +/* Write string table data */ + ret =fd_write_vmcore (s->string_table_buf->data, + s->string_table_buf->len, s); +if (ret <0 ) { +error_setg_errno (errp, -ret,"dump: failed to write string table data" ); + } }static void write_data (DumpState *s,void *buf,int length,Error **errp)@@ -592,6 +649,9 @@ static void dump_begin(DumpState *s, Error **errp)* -------------- * | memory | * -------------- +* | sectn data | +* -------------- +* * we only know where the memory is saved after we write elf note into * vmcore. @@ -677,6 +737,7 @@ static void create_vmcore(DumpState *s, Error **errp)return ; } +/* Iterate over memory and dump it to file */ dump_iterate (s, errp);if (*errp) {return ;@@ -1659,6 +1720,13 @@ static void dump_init(DumpState *s, int fd, bool has_format, s->has_filter = has_filter; s->begin = begin; s->length = length; +/* First index is 0, it's the special null name */ + s->string_table_buf =g_array_new (FALSE, TRUE,1 ); +/* +* Allocate the null name, due to the clearing option set to true +* it will be 0. +*/ +g_array_set_size (s->string_table_buf,1 );memory_mapping_list_init (&s->list);@@ -1819,19 +1887,31 @@ static void dump_init(DumpState *s, int fd, bool has_format, } } -if (dump_is_64bit (s)) { - s->phdr_offset =sizeof (Elf64_Ehdr); - s->shdr_offset = s->phdr_offset +sizeof (Elf64_Phdr) * s->phdr_num; - s->note_offset = s->shdr_offset +sizeof (Elf64_Shdr) * s->shdr_num; - s->memory_offset = s->note_offset + s->note_size; - }else { - - s->phdr_offset =sizeof (Elf32_Ehdr); - s->shdr_offset = s->phdr_offset +sizeof (Elf32_Phdr) * s->phdr_num; - s->note_offset = s->shdr_offset +sizeof (Elf32_Shdr) * s->shdr_num; - s->memory_offset = s->note_offset + s->note_size; +/* +* calculate shdr_num and elf_section_data_size so we know the offsets and +* sizes of all parts. +* +* If phdr_num overflowed we have at least one section header +* More sections/hdrs can be added by the architectures +*/ +if (s->shdr_num >1 ) { +/* Reserve the string table */ + s->shdr_num +=1 ; } + tmp = (s->phdr_num ==PN_XNUM ) ? s->sh_info : s->phdr_num;
dump/dump.c static void dump_init(DumpState *s, int fd, bool has_format, · line 1912
Quoted 10 lines
dump/dump.c +10
-0+if (dump_is_64bit (s)) { + s->shdr_offset =sizeof (Elf64_Ehdr); + s->phdr_offset = s->shdr_offset +sizeof (Elf64_Shdr) * s->shdr_num; + s->note_offset = s->phdr_offset +sizeof (Elf64_Phdr) * tmp; + }else { + s->shdr_offset =sizeof (Elf32_Ehdr); + s->phdr_offset = s->shdr_offset +sizeof (Elf32_Shdr) * s->shdr_num; + s->note_offset = s->phdr_offset +sizeof (Elf32_Phdr) * tmp; + } + s->memory_offset = s->note_offset + s->note_size;
I suggest to split this in a different patch. It's not obvious that you can change phdr_offset / shdr_offset, it deserves a comment.
Quoted 20 lines
dump/dump.c +2
-0+ s->section_offset = s->memory_offset + s->total_size; +return ; cleanup:include/sysemu/dump.h +1
-1@@ -178,6 +178,7 @@ typedef struct DumpState {void *elf_section_hdrs;uint64_t elf_section_data_size;void *elf_section_data; +GArray *string_table_buf;/* String table section */ uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */ --2.34.1
Re: [PATCH v2 05/11] dump/dump: Add section string table support
Quoted 9 lines · Marc-André Lureau
Hi
Quoted 2 lines · Janosch Frank
Time to add a bit more descriptiveness to the dumps.
Please add some more description & motivation to the patch (supposedly necessary for next patches), and explain that it currently doesn't change the dump (afaict).
How about:
As sections don't have a type like the notes do we need another way to determine their contents. The string table allows us to assign each section an identification string which architectures can then use to tag their sections with.
There will be no string table if the architecture doesn't add custom sections which are introduced in a following patch.
Quoted 36 lines
Quoted 25 lines
dump/dump.c +11
-11-if (dump_is_64bit (s)) { - s->phdr_offset =sizeof (Elf64_Ehdr); - s->shdr_offset = s->phdr_offset +sizeof (Elf64_Phdr) * s->phdr_num; - s->note_offset = s->shdr_offset +sizeof (Elf64_Shdr) * s->shdr_num; - s->memory_offset = s->note_offset + s->note_size; - }else { - - s->phdr_offset =sizeof (Elf32_Ehdr); - s->shdr_offset = s->phdr_offset +sizeof (Elf32_Phdr) * s->phdr_num; - s->note_offset = s->shdr_offset +sizeof (Elf32_Shdr) * s->shdr_num; - s->memory_offset = s->note_offset + s->note_size; +/* +* calculate shdr_num and elf_section_data_size so we know the offsets and +* sizes of all parts. +* +* If phdr_num overflowed we have at least one section header +* More sections/hdrs can be added by the architectures +*/ +if (s->shdr_num >1 ) { +/* Reserve the string table */ + s->shdr_num +=1 ; } + tmp = (s->phdr_num ==PN_XNUM ) ? s->sh_info : s->phdr_num;dump/dump.c static void dump_init(DumpState *s, int fd, bool has_format, · line 1912
Quoted 10 lines
dump/dump.c +10
-0+if (dump_is_64bit (s)) { + s->shdr_offset =sizeof (Elf64_Ehdr); + s->phdr_offset = s->shdr_offset +sizeof (Elf64_Shdr) * s->shdr_num; + s->note_offset = s->phdr_offset +sizeof (Elf64_Phdr) * tmp; + }else { + s->shdr_offset =sizeof (Elf32_Ehdr); + s->phdr_offset = s->shdr_offset +sizeof (Elf32_Shdr) * s->shdr_num; + s->note_offset = s->phdr_offset +sizeof (Elf32_Phdr) * tmp; + } + s->memory_offset = s->note_offset + s->note_size;
Quoted 2 lines
I suggest to split this in a different patch. It's not obvious that you can change
phdr_offset/shdr_offset, it deserves a comment.
Right, will do
Quoted 22 lines
Quoted 21 lines
dump/dump.c +2
-0+ s->section_offset = s->memory_offset + s->total_size; +return ; cleanup:include/sysemu/dump.h +1
-1@@ -178,6 +178,7 @@ typedef struct DumpState {void *elf_section_hdrs;uint64_t elf_section_data_size;void *elf_section_data; +GArray *string_table_buf;/* String table section */ uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */ --2.34.1
Re: [PATCH v2 05/11] dump/dump: Add section string table support
Hi
Quoted 14 lines · Janosch Frank
Quoted 3 lines · Marc-André Lureau
Hi
On Wed, Jul 13, 2022 at 5:07 PM Janosch Frank <[email protected]>
Quoted 6 lines · wrote:
Quoted 2 lines
Time to add a bit more descriptiveness to the dumps.
Please add some more description & motivation to the patch (supposedly necessary for next patches), and explain that it currently doesn't change the dump (afaict).
How about:
Quoted 8 lines
As sections don't have a type like the notes do we need another way to determine their contents. The string table allows us to assign each section an identification string which architectures can then use to tag their sections with.
There will be no string table if the architecture doesn't add custom sections which are introduced in a following patch.
lgtm, thanks
Quoted 74 lines
Quoted 6 lines
dump/dump.c static void dump_init(DumpState *s, int fd, bool has_format,
Quoted 6 lines
dump/dump.c +0
-3-if (dump_is_64bit (s)) { - s->phdr_offset =sizeof (Elf64_Ehdr); - s->shdr_offset = s->phdr_offset + sizeof(Elf64_Phdr) *
s->phdr_num;Quoted 1 line
Quoted 1 line
-
s->note_offset=s->shdr_offset+sizeof(Elf64_Shdr)*
s->shdr_num;Quoted 5 lines
dump/dump.c static void dump_init(DumpState *s, int fd, bool has_format,
Quoted 5 lines
dump/dump.c +0
-5- s->memory_offset = s->note_offset + s->note_size; - }else { - - s->phdr_offset =sizeof (Elf32_Ehdr); - s->shdr_offset = s->phdr_offset + sizeof(Elf32_Phdr) *
s->phdr_num;Quoted 1 line
Quoted 1 line
-
s->note_offset=s->shdr_offset+sizeof(Elf32_Shdr)*
s->shdr_num;Quoted 3 lines
dump/dump.c static void dump_init(DumpState *s, int fd, bool has_format,
Quoted 3 lines
dump/dump.c +2
-1- s->memory_offset = s->note_offset + s->note_size; +/* +* calculate shdr_num and elf_section_data_size so we know the offsets and
Quoted 10 lines
Quoted 10 lines
dump/dump.c +8
-0+* sizes of all parts. +* +* If phdr_num overflowed we have at least one section header +* More sections/hdrs can be added by the architectures +*/ +if (s->shdr_num >1 ) { +/* Reserve the string table */ + s->shdr_num +=1 ; }Quoted 4 lines
dump/dump.c static void dump_init(DumpState *s, int fd, bool has_format,
Quoted 4 lines
dump/dump.c +4
-0+ tmp = (s->phdr_num ==PN_XNUM ) ? s->sh_info : s->phdr_num; +if (dump_is_64bit (s)) { + s->shdr_offset =sizeof (Elf64_Ehdr); + s->phdr_offset = s->shdr_offset + sizeof(Elf64_Shdr) *
s->shdr_num;Quoted 4 lines
dump/dump.c static void dump_init(DumpState *s, int fd, bool has_format,
Quoted 4 lines
dump/dump.c +4
-0+ s->note_offset = s->phdr_offset +sizeof (Elf64_Phdr) * tmp; + }else { + s->shdr_offset =sizeof (Elf32_Ehdr); + s->phdr_offset = s->shdr_offset + sizeof(Elf32_Shdr) *
s->shdr_num;Quoted 6 lines
dump/dump.c static void dump_init(DumpState *s, int fd, bool has_format, · line 1912
Quoted 3 lines
dump/dump.c +3
-0+ s->note_offset = s->phdr_offset +sizeof (Elf32_Phdr) * tmp; + } + s->memory_offset = s->note_offset + s->note_size;I suggest to split this in a different patch. It's not obvious that you can change
phdr_offset/shdr_offset, it deserves a comment.Right, will do
Quoted 22 lines
Quoted 21 lines
dump/dump.c +2
-0+ s->section_offset = s->memory_offset + s->total_size; +return ; cleanup:include/sysemu/dump.h +1
-1@@ -178,6 +178,7 @@ typedef struct DumpState {void *elf_section_hdrs;uint64_t elf_section_data_size;void *elf_section_data; +GArray *string_table_buf;/* String table section */ uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */ --2.34.1
Signature · 1 line
Marc-André Lureau
PATCH v2 6/11 dump/dump: Add arch section support
In reply to Janosch FrankAdd hooks which architectures can use to add arbitrary data to custom sections.
--- dump/dump.c | 21 ++++++++++++++++++--- include/sysemu/dump-arch.h | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-)
dump/dump.c +18 -3
@@ -400,6 +400,7 @@ static void prepare_elf_section_hdrs(DumpState *s)/* * Section ordering: * - HDR zero (if needed) +* - Arch section hdrs * - String table hdr */ sizeof_shdr =dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr);
@@ -417,6 +418,9 @@ static void prepare_elf_section_hdrs(DumpState *s)return ; } + size =dump_arch_sections_write_hdr (&s->dump_info, s, buff_hdr); + buff_hdr += size; +/* * String table needs to be last section since strings are added * via arch_sections_write_hdr().
@@ -567,14 +571,23 @@ static void get_offset_range(hwaddr phys_addr, } } -static void write_elf_loads (DumpState *s,Error **errp) +static void write_elf_phdr_loads (DumpState *s,Error **errp) {ERRP_GUARD ();hwaddr offset, filesz;MemoryMapping *memory_mapping;uint32_t phdr_index =1 ; +hwaddr min =0 , max =0 ; QTAILQ_FOREACH(memory_mapping, &s->list.head, next) { +if (memory_mapping->phys_addr < min) { + min = memory_mapping->phys_addr; + } +if (memory_mapping->phys_addr + memory_mapping->length > max) { + max = memory_mapping->phys_addr + memory_mapping->length; + } + +get_offset_range (memory_mapping->phys_addr, memory_mapping->length, s, &offset, &filesz);
@@ -682,8 +695,8 @@ static void dump_begin(DumpState *s, Error **errp)return ; } -/* write all PT_LOAD to vmcore */ -write_elf_loads (s, errp); +/* write all PT_LOADs to vmcore */ +write_elf_phdr_loads (s, errp);if (*errp) {return ; }
@@ -723,6 +736,7 @@ static void dump_end(DumpState *s, Error **errp)return ; } s->elf_section_data =g_malloc0 (s->elf_section_data_size); +dump_arch_sections_write (&s->dump_info, s, s->elf_section_data);/* write sections to vmcore */ write_elf_sections (s, errp);
@@ -1894,6 +1908,7 @@ static void dump_init(DumpState *s, int fd, bool has_format,* If phdr_num overflowed we have at least one section header * More sections/hdrs can be added by the architectures */ +dump_arch_sections_add (&s->dump_info, (void *)s);if (s->shdr_num >1 ) {/* Reserve the string table */ s->shdr_num +=1 ;
include/sysemu/dump-arch.h +27 -0
@@ -21,6 +21,9 @@ typedef struct ArchDumpInfo {uint32_t page_size;/* The target's page size. If it's variable and * unknown, then this should be the maximum. */ uint64_t phys_base;/* The target's physmem base. */ +void (*arch_sections_add_fn)(void *opaque); +uint64_t (*arch_sections_write_hdr_fn)(void *opaque,uint8_t *buff); +void (*arch_sections_write_fn)(void *opaque,uint8_t *buff); } ArchDumpInfo;struct GuestPhysBlockList ;/* memory_mapping.h */
@@ -28,4 +31,28 @@ int cpu_get_dump_info(ArchDumpInfo *info, const struct GuestPhysBlockList *guest_phys_blocks);ssize_t cpu_get_note_size (int class,int machine,int nr_cpus); +static inline void dump_arch_sections_add (ArchDumpInfo *info,void *opaque) +{ +if (info->arch_sections_add_fn) { + info->arch_sections_add_fn (opaque); + } +} + +static inline uint64_t dump_arch_sections_write_hdr (ArchDumpInfo *info, +void *opaque,uint8_t *buff) +{ +if (info->arch_sections_write_hdr_fn) { +return info->arch_sections_write_hdr_fn (opaque, buff); + } +return 0 ; +} + +static inline void dump_arch_sections_write (ArchDumpInfo *info,void *opaque, +uint8_t *buff) +{ +if (info->arch_sections_write_fn) { + info->arch_sections_write_fn (opaque, buff); + } +} +#endif
Signature · 1 line
2.34.1
Re: [PATCH v2 06/11] dump/dump: Add arch section support
Hi
Quoted 44 lines · Janosch Frank
Add hooks which architectures can use to add arbitrary data to custom sections.
Signed-off-by Janosch Frank <[email protected]>--- dump/dump.c | 21 ++++++++++++++++++--- include/sysemu/dump-arch.h | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-)dump/dump.c +6
-1@@ -400,6 +400,7 @@ static void prepare_elf_section_hdrs(DumpState *s)/* * Section ordering: * - HDR zero (if needed) +* - Arch section hdrs * - String table hdr */ sizeof_shdr =dump_is_64bit (s) ?sizeof (Elf64_Shdr) :sizeof (Elf32_Shdr);@@ -417,6 +418,9 @@ static void prepare_elf_section_hdrs(DumpState *s)return ; } + size =dump_arch_sections_write_hdr (&s->dump_info, s, buff_hdr); + buff_hdr += size; +/* * String table needs to be last section since strings are added * via arch_sections_write_hdr(). @@ -567,14 +571,23 @@ static void get_offset_range(hwaddr phys_addr, } } -static void write_elf_loads (DumpState *s,Error **errp) +static void write_elf_phdr_loads (DumpState *s,Error **errp) {ERRP_GUARD ();hwaddr offset, filesz;MemoryMapping *memory_mapping;uint32_t phdr_index =1 ; +hwaddr min =0 , max =0 ;
dump/dump.c static void get_offset_range(hwaddr phys_addr, · line 590
Quoted 10 lines
dump/dump.c +8
-0QTAILQ_FOREACH(memory_mapping, &s->list.head, next) { +if (memory_mapping->phys_addr < min) { + min = memory_mapping->phys_addr; + } +if (memory_mapping->phys_addr + memory_mapping->length > max) { + max = memory_mapping->phys_addr + memory_mapping->length; + } + +
Extra line & this belongs to a different patch.
Quoted 74 lines
dump/dump.c +4
-2get_offset_range (memory_mapping->phys_addr, memory_mapping->length, s, &offset, &filesz);@@ -682,8 +695,8 @@ static void dump_begin(DumpState *s, Error **errp)return ; } -/* write all PT_LOAD to vmcore */ -write_elf_loads (s, errp); +/* write all PT_LOADs to vmcore */ +write_elf_phdr_loads (s, errp);if (*errp) {return ; }@@ -723,6 +736,7 @@ static void dump_end(DumpState *s, Error **errp)return ; } s->elf_section_data =g_malloc0 (s->elf_section_data_size); +dump_arch_sections_write (&s->dump_info, s, s->elf_section_data);/* write sections to vmcore */ write_elf_sections (s, errp);@@ -1894,6 +1908,7 @@ static void dump_init(DumpState *s, int fd, bool has_format,* If phdr_num overflowed we have at least one section header * More sections/hdrs can be added by the architectures */ +dump_arch_sections_add (&s->dump_info, (void *)s);if (s->shdr_num >1 ) {/* Reserve the string table */ s->shdr_num +=1 ;include/sysemu/dump-arch.h +27
-1@@ -21,6 +21,9 @@ typedef struct ArchDumpInfo {uint32_t page_size;/* The target's page size. If it's variable and * unknown, then this should be the maximum. */ uint64_t phys_base;/* The target's physmem base. */ +void (*arch_sections_add_fn)(void *opaque); +uint64_t (*arch_sections_write_hdr_fn)(void *opaque,uint8_t *buff); +void (*arch_sections_write_fn)(void *opaque,uint8_t *buff); } ArchDumpInfo;struct GuestPhysBlockList ;/* memory_mapping.h */ @@ -28,4 +31,28 @@ int cpu_get_dump_info(ArchDumpInfo *info, const struct GuestPhysBlockList *guest_phys_blocks);ssize_t cpu_get_note_size (int class,int machine,int nr_cpus); +static inline void dump_arch_sections_add (ArchDumpInfo *info,void *opaque) +{ +if (info->arch_sections_add_fn) { + info->arch_sections_add_fn (opaque); + } +} + +static inline uint64_t dump_arch_sections_write_hdr (ArchDumpInfo *info, +void *opaque,uint8_t *buff) +{ +if (info->arch_sections_write_hdr_fn) { +return info->arch_sections_write_hdr_fn (opaque, buff); + } +return 0 ; +} + +static inline void dump_arch_sections_write (ArchDumpInfo *info,void *opaque, +uint8_t *buff) +{ +if (info->arch_sections_write_fn) { + info->arch_sections_write_fn (opaque, buff); + } +} +#endif --
Quoted 2 lines
2.34.1
otherwise, seems ok to me
PATCH v2 7/11 linux header sync
In reply to Janosch Frank--- linux-headers/linux/kvm.h | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
linux-headers/linux/kvm.h +55 -0
@@ -1150,6 +1150,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_DISABLE_QUIRKS2 213/* #define KVM_CAP_VM_TSC_CONTROL 214 */ #define KVM_CAP_SYSTEM_EVENT_DATA 215 +#define KVM_CAP_S390_PROTECTED_DUMP 217#ifdef KVM_CAP_IRQ_ROUTING
@@ -1651,6 +1652,55 @@ struct kvm_s390_pv_unp {__u64 tweak; }; +enum pv_cmd_info_id { +KVM_PV_INFO_VM , +KVM_PV_INFO_DUMP , +}; + +struct kvm_s390_pv_info_dump { +__u64 dump_cpu_buffer_len; +__u64 dump_config_mem_buffer_per_1m; +__u64 dump_config_finalize_len; +}; + +struct kvm_s390_pv_info_vm { +__u64 inst_calls_list[4 ]; +__u64 max_cpus; +__u64 max_guests; +__u64 max_guest_addr; +__u64 feature_indication; +}; + +struct kvm_s390_pv_info_header { +__u32 id; +__u32 len_max; +__u32 len_written; +__u32 reserved; +}; + +struct kvm_s390_pv_info { +struct kvm_s390_pv_info_header header; +union { +struct kvm_s390_pv_info_dump dump; +struct kvm_s390_pv_info_vm vm; + }; +}; + +enum pv_cmd_dmp_id { +KVM_PV_DUMP_INIT , +KVM_PV_DUMP_CONFIG_STATE , +KVM_PV_DUMP_COMPLETE , +KVM_PV_DUMP_CPU , +}; + +struct kvm_s390_pv_dmp { +__u64 subcmd; +__u64 buff_addr; +__u64 buff_len; +__u64 gaddr; +__u64 reserved[4 ]; +}; +enum pv_cmd_id {KVM_PV_ENABLE ,KVM_PV_DISABLE ,
@@ -1659,6 +1709,8 @@ enum pv_cmd_id {KVM_PV_VERIFY ,KVM_PV_PREP_RESET ,KVM_PV_UNSHARE_ALL , +KVM_PV_INFO , + KVM_PV_DUMP, }; struct kvm_pv_cmd {
@@ -1733,6 +1785,7 @@ struct kvm_xen_vcpu_attr {#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA 0x4#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST 0x5 +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
@@ -2066,4 +2119,6 @@ struct kvm_stats_desc {/* Available with KVM_CAP_XSAVE2 */ #define KVM_GET_XSAVE2 _IOR(KVMIO, 0xcf, struct kvm_xsave) +#define KVM_S390_PV_CPU_COMMAND _IOWR(KVMIO, 0xd0, struct kvm_pv_cmd) +#endif /* __LINUX_KVM_H */
Signature · 1 line
2.34.1
Re: [PATCH v2 07/11] linux header sync
Quoted 2 lines · Janosch Frank
Signed-off-by Janosch Frank <[email protected]>
Please tell which version this update come from. Otherwise, it should be fine
Quoted 99 lines
--- linux-headers/linux/kvm.h | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)linux-headers/linux/kvm.h +55
-1@@ -1150,6 +1150,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_DISABLE_QUIRKS2 213/* #define KVM_CAP_VM_TSC_CONTROL 214 */ #define KVM_CAP_SYSTEM_EVENT_DATA 215 +#define KVM_CAP_S390_PROTECTED_DUMP 217#ifdef KVM_CAP_IRQ_ROUTING @@ -1651,6 +1652,55 @@ struct kvm_s390_pv_unp {__u64 tweak; }; +enum pv_cmd_info_id { +KVM_PV_INFO_VM , +KVM_PV_INFO_DUMP , +}; + +struct kvm_s390_pv_info_dump { +__u64 dump_cpu_buffer_len; +__u64 dump_config_mem_buffer_per_1m; +__u64 dump_config_finalize_len; +}; + +struct kvm_s390_pv_info_vm { +__u64 inst_calls_list[4 ]; +__u64 max_cpus; +__u64 max_guests; +__u64 max_guest_addr; +__u64 feature_indication; +}; + +struct kvm_s390_pv_info_header { +__u32 id; +__u32 len_max; +__u32 len_written; +__u32 reserved; +}; + +struct kvm_s390_pv_info { +struct kvm_s390_pv_info_header header; +union { +struct kvm_s390_pv_info_dump dump; +struct kvm_s390_pv_info_vm vm; + }; +}; + +enum pv_cmd_dmp_id { +KVM_PV_DUMP_INIT , +KVM_PV_DUMP_CONFIG_STATE , +KVM_PV_DUMP_COMPLETE , +KVM_PV_DUMP_CPU , +}; + +struct kvm_s390_pv_dmp { +__u64 subcmd; +__u64 buff_addr; +__u64 buff_len; +__u64 gaddr; +__u64 reserved[4 ]; +}; +enum pv_cmd_id {KVM_PV_ENABLE ,KVM_PV_DISABLE ,@@ -1659,6 +1709,8 @@ enum pv_cmd_id {KVM_PV_VERIFY ,KVM_PV_PREP_RESET ,KVM_PV_UNSHARE_ALL , +KVM_PV_INFO , + KVM_PV_DUMP, }; struct kvm_pv_cmd {@@ -1733,6 +1785,7 @@ struct kvm_xen_vcpu_attr {#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA 0x4#define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST 0x5 +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */ @@ -2066,4 +2119,6 @@ struct kvm_stats_desc {/* Available with KVM_CAP_XSAVE2 */ #define KVM_GET_XSAVE2 _IOR(KVMIO, 0xcf, struct kvm_xsave) +#define KVM_S390_PV_CPU_COMMAND _IOWR(KVMIO, 0xd0, struct kvm_pv_cmd) +#endif /* __LINUX_KVM_H */ --2.34.1
PATCH v2 8/11 s390x: Add protected dump cap
In reply to Janosch FrankAdd a protected dump capability for later feature checking.
--- target/s390x/kvm/kvm.c | 7 +++++++ target/s390x/kvm/kvm_s390x.h | 1 + 2 files changed, 8 insertions(+)
target/s390x/kvm/kvm.c +7 -0
@@ -157,6 +157,7 @@ static int cap_ri;static int cap_hpage_1m;static int cap_vcpu_resets;static int cap_protected; +static int cap_protected_dump;static bool mem_op_storage_key_support;
@@ -362,6 +363,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) cap_s390_irq =kvm_check_extension (s,KVM_CAP_S390_INJECT_IRQ ); cap_vcpu_resets =kvm_check_extension (s,KVM_CAP_S390_VCPU_RESETS ); cap_protected =kvm_check_extension (s,KVM_CAP_S390_PROTECTED ); + cap_protected_dump =kvm_check_extension (s,KVM_CAP_S390_PROTECTED_DUMP );kvm_vm_enable_cap (s,KVM_CAP_S390_USER_SIGP ,0 );kvm_vm_enable_cap (s,KVM_CAP_S390_VECTOR_REGISTERS ,0 );
@@ -2043,6 +2045,11 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,return kvm_vm_ioctl (kvm_state,KVM_IOEVENTFD , &kick); } +int kvm_s390_get_protected_dump (void ) +{ +return cap_protected_dump; +} +int kvm_s390_get_ri (void ) {return cap_ri;
target/s390x/kvm/kvm_s390x.h +1 -0
@@ -26,6 +26,7 @@ int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);void kvm_s390_vcpu_interrupt_pre_save (S390CPU *cpu);int kvm_s390_vcpu_interrupt_post_load (S390CPU *cpu);int kvm_s390_get_hpage_1m (void ); +int kvm_s390_get_protected_dump (void );int kvm_s390_get_ri (void );int kvm_s390_get_clock (uint8_t *tod_high,uint64_t *tod_clock);int kvm_s390_get_clock_ext (uint8_t *tod_high,uint64_t *tod_clock);
Signature · 1 line
2.34.1
PATCH v2 9/11 s390x: Introduce PV query interface
In reply to Janosch FrankIntroduce an interface over which we can get information about UV data.
--- hw/s390x/pv.c | 61 ++++++++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 5 ++++ include/hw/s390x/pv.h | 10 +++++++ 3 files changed, 76 insertions(+)
hw/s390x/pv.c +61 -0
@@ -20,6 +20,11 @@#include "exec/confidential-guest-support.h" #include "hw/s390x/ipl.h" #include "hw/s390x/pv.h" +#include "target/s390x/kvm/kvm_s390x.h" + +static bool info_valid; +static struct kvm_s390_pv_info_vm info_vm; +static struct kvm_s390_pv_info_dump info_dump;static int __s390_pv_cmd (uint32_t cmd,const char *cmdname,void *data) {
@@ -56,6 +61,42 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data) } \ } +int s390_pv_query_info (void ) +{ +struct kvm_s390_pv_info info = { + .header.id =KVM_PV_INFO_VM , + .header.len_max =sizeof (info.header) +sizeof (info.vm), + }; +int rc; + +/* Info API's first user is dump so they are bundled */ +if (!kvm_s390_get_protected_dump ()) { +return 0 ; + } + + rc =s390_pv_cmd (KVM_PV_INFO , &info); +if (rc) { +error_report ("KVM PV INFO cmd %x failed: %s" , + info.header.id,strerror (rc)); +return rc; + } +memcpy (&info_vm, &info.vm,sizeof (info.vm)); + + info.header.id =KVM_PV_INFO_DUMP ; + info.header.len_max =sizeof (info.header) +sizeof (info.dump); + rc =s390_pv_cmd (KVM_PV_INFO , &info); +if (rc) { +error_report ("KVM PV INFO cmd %x failed: %s" , + info.header.id,strerror (rc)); +return rc; + } + +memcpy (&info_dump, &info.dump,sizeof (info.dump)); + info_valid = true; + +return rc; +} +int s390_pv_vm_enable (void ) {return s390_pv_cmd (KVM_PV_ENABLE ,NULL );
@@ -114,6 +155,26 @@ void s390_pv_inject_reset_error(CPUState *cs) env->regs[r1 +1 ] =DIAG_308_RC_INVAL_FOR_PV ; } +uint64_t kvm_s390_pv_dmp_get_size_cpu (void ) +{ +return info_dump.dump_cpu_buffer_len; +} + +uint64_t kvm_s390_pv_dmp_get_size_complete (void ) +{ +return info_dump.dump_config_finalize_len; +} + +uint64_t kvm_s390_pv_dmp_get_size_mem (void ) +{ +return info_dump.dump_config_mem_buffer_per_1m; +} + +bool kvm_s390_pv_info_basic_valid (void ) +{ +return info_valid; +} +#define TYPE_S390_PV_GUEST "s390-pv-guest"OBJECT_DECLARE_SIMPLE_TYPE (S390PVGuest,S390_PV_GUEST )
hw/s390x/s390-virtio-ccw.c +5 -0
@@ -366,6 +366,11 @@ static int s390_machine_protect(S390CcwMachineState *ms) ms->pv = true; + rc =s390_pv_query_info (); +if (rc) { + goto out_err; + } +/* Set SE header and unpack */ rc =s390_ipl_prepare_pv_header ();if (rc) {
include/hw/s390x/pv.h +10 -0
@@ -38,6 +38,7 @@ static inline bool s390_is_pv(void)return ccw->pv; } +int s390_pv_query_info (void );int s390_pv_vm_enable (void );void s390_pv_vm_disable (void );int s390_pv_set_sec_parms (uint64_t origin,uint64_t length);
@@ -46,8 +47,13 @@ void s390_pv_prep_reset(void);int s390_pv_verify (void );void s390_pv_unshare (void );void s390_pv_inject_reset_error (CPUState *cs); +uint64_t kvm_s390_pv_dmp_get_size_cpu (void ); +uint64_t kvm_s390_pv_dmp_get_size_mem (void ); +uint64_t kvm_s390_pv_dmp_get_size_complete (void ); +bool kvm_s390_pv_info_basic_valid (void );#else /* CONFIG_KVM */ static inline bool s390_is_pv (void ) {return false; } +static inline int s390_pv_query_info (void ) {return 0 ; }static inline int s390_pv_vm_enable (void ) {return 0 ; }static inline void s390_pv_vm_disable (void ) {}static inline int s390_pv_set_sec_parms (uint64_t origin,uint64_t length) {return 0 ; }
@@ -56,6 +62,10 @@ static inline void s390_pv_prep_reset(void) {}static inline int s390_pv_verify (void ) {return 0 ; }static inline void s390_pv_unshare (void ) {}static inline void s390_pv_inject_reset_error (CPUState *cs) {}; +static inline uint64_t kvm_s390_pv_dmp_get_size_cpu (void ) {return 0 ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_mem (void ) {return 0 ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_complete (void ) {return 0 ; } +static inline bool kvm_s390_pv_info_basic_valid (void ) {return false; }#endif /* CONFIG_KVM */ int s390_pv_kvm_init (ConfidentialGuestSupport *cgs,Error **errp);
Signature · 1 line
2.34.1
Re: [PATCH v2 09/11] s390x: Introduce PV query interface
Hi
Quoted 101 lines · Janosch Frank
Introduce an interface over which we can get information about UV data.
Signed-off-by Janosch Frank <[email protected]>--- hw/s390x/pv.c | 61 ++++++++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 5 ++++ include/hw/s390x/pv.h | 10 +++++++ 3 files changed, 76 insertions(+)hw/s390x/pv.c +41
-0@@ -20,6 +20,11 @@#include "exec/confidential-guest-support.h" #include "hw/s390x/ipl.h" #include "hw/s390x/pv.h" +#include "target/s390x/kvm/kvm_s390x.h" + +static bool info_valid; +static struct kvm_s390_pv_info_vm info_vm; +static struct kvm_s390_pv_info_dump info_dump;static int __s390_pv_cmd (uint32_t cmd,const char *cmdname,void *data) {@@ -56,6 +61,42 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data) } \ } +int s390_pv_query_info (void ) +{ +struct kvm_s390_pv_info info = { + .header.id =KVM_PV_INFO_VM , + .header.len_max =sizeof (info.header) +sizeof (info.vm), + }; +int rc; + +/* Info API's first user is dump so they are bundled */ +if (!kvm_s390_get_protected_dump ()) { +return 0 ; + } + + rc =s390_pv_cmd (KVM_PV_INFO , &info); +if (rc) { +error_report ("KVM PV INFO cmd %x failed: %s" , + info.header.id,strerror (rc)); +return rc; + } +memcpy (&info_vm, &info.vm,sizeof (info.vm)); + + info.header.id =KVM_PV_INFO_DUMP ; + info.header.len_max =sizeof (info.header) +sizeof (info.dump); + rc =s390_pv_cmd (KVM_PV_INFO , &info); +if (rc) { +error_report ("KVM PV INFO cmd %x failed: %s" , + info.header.id,strerror (rc)); +return rc; + } + +memcpy (&info_dump, &info.dump,sizeof (info.dump)); + info_valid = true; + +return rc; +} +int s390_pv_vm_enable (void ) {return s390_pv_cmd(KVM_PV_ENABLE, NULL);hw/s390x/pv.c +20
-0@@ -114,6 +155,26 @@ void s390_pv_inject_reset_error(CPUState *cs) env->regs[r1 +1 ] =DIAG_308_RC_INVAL_FOR_PV ; } +uint64_t kvm_s390_pv_dmp_get_size_cpu (void ) +{ +return info_dump.dump_cpu_buffer_len; +} + +uint64_t kvm_s390_pv_dmp_get_size_complete (void ) +{ +return info_dump.dump_config_finalize_len; +} + +uint64_t kvm_s390_pv_dmp_get_size_mem (void ) +{ +return info_dump.dump_config_mem_buffer_per_1m; +} + +bool kvm_s390_pv_info_basic_valid (void ) +{ +return info_valid; +} +#define TYPE_S390_PV_GUEST "s390-pv-guest"OBJECT_DECLARE_SIMPLE_TYPE (S390PVGuest,S390_PV_GUEST )hw/s390x/s390-virtio-ccw.c +0
-0
hw/s390x/s390-virtio-ccw.c static int s390_machine_protect(S390CcwMachineState · line 373
Quoted 8 lines
hw/s390x/s390-virtio-ccw.c +3
-0@@ -366,6 +366,11 @@ static int s390_machine_protect(S390CcwMachineState *ms) ms->pv = true; + rc =s390_pv_query_info (); +if (rc) { + goto out_err;
Maybe it's not necessary to make it fatal on error?
lgtm otherwise
Quoted 49 lines
hw/s390x/s390-virtio-ccw.c +2
-0+ } +/* Set SE header and unpack */ rc = s390_ipl_prepare_pv_header(); if (rc) {include/hw/s390x/pv.h +6
-0@@ -38,6 +38,7 @@ static inline bool s390_is_pv(void)return ccw->pv; } +int s390_pv_query_info (void );int s390_pv_vm_enable (void );void s390_pv_vm_disable (void );int s390_pv_set_sec_parms (uint64_t origin,uint64_t length);@@ -46,8 +47,13 @@ void s390_pv_prep_reset(void);int s390_pv_verify (void );void s390_pv_unshare (void );void s390_pv_inject_reset_error (CPUState *cs); +uint64_t kvm_s390_pv_dmp_get_size_cpu (void ); +uint64_t kvm_s390_pv_dmp_get_size_mem (void ); +uint64_t kvm_s390_pv_dmp_get_size_complete (void ); +bool kvm_s390_pv_info_basic_valid (void );#else /* CONFIG_KVM */ static inline bool s390_is_pv (void ) {return false; } +static inline int s390_pv_query_info (void ) {return 0 ; }static inline int s390_pv_vm_enable (void ) {return 0 ; }static inline void s390_pv_vm_disable (void ) {}static inline int s390_pv_set_sec_parms (uint64_t origin,uint64_t length){ return 0; }
include/hw/s390x/pv.h +4
-0@@ -56,6 +62,10 @@ static inline void s390_pv_prep_reset(void) {}static inline int s390_pv_verify (void ) {return 0 ; }static inline void s390_pv_unshare (void ) {}static inline void s390_pv_inject_reset_error (CPUState *cs) {}; +static inline uint64_t kvm_s390_pv_dmp_get_size_cpu (void ) {return 0 ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_mem (void ) {return 0 ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_complete (void ) {return 0 ; } +static inline bool kvm_s390_pv_info_basic_valid (void ) {return false; }#endif /* CONFIG_KVM */ int
s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
--
2.34.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH v2 09/11] s390x: Introduce PV query interface
On 7/15/22 10:10, Marc-André Lureau wrote:
[...]
Quoted 10 lines
hw/s390x/s390-virtio-ccw.c static int s390_machine_protect(S390CcwMachineState *ms) · line 371
Quoted 6 lines
ms->pv = true;hw/s390x/s390-virtio-ccw.c +3
-0+ rc =s390_pv_query_info (); +if (rc) { + goto out_err;Maybe it's not necessary to make it fatal on error?
lgtm otherwise
Hmm, yes and no.
The info API is fenced by the dump CAP so I don't ever expect an error here but on the other hand an optional info API fail might not warrant an error.
Quoted 52 lines
Quoted 51 lines
hw/s390x/s390-virtio-ccw.c +2
-0+ } +/* Set SE header and unpack */ rc =s390_ipl_prepare_pv_header ();if (rc) {include/hw/s390x/pv.h +6
-0@@ -38,6 +38,7 @@ static inline bool s390_is_pv(void)return ccw->pv; } +int s390_pv_query_info (void );int s390_pv_vm_enable (void );void s390_pv_vm_disable (void );int s390_pv_set_sec_parms (uint64_t origin,uint64_t length);@@ -46,8 +47,13 @@ void s390_pv_prep_reset(void);int s390_pv_verify (void );void s390_pv_unshare (void );void s390_pv_inject_reset_error (CPUState *cs); +uint64_t kvm_s390_pv_dmp_get_size_cpu (void ); +uint64_t kvm_s390_pv_dmp_get_size_mem (void ); +uint64_t kvm_s390_pv_dmp_get_size_complete (void ); +bool kvm_s390_pv_info_basic_valid (void );#else /* CONFIG_KVM */ static inline bool s390_is_pv (void ) {return false; } +static inline int s390_pv_query_info (void ) {return 0 ; }static inline int s390_pv_vm_enable (void ) {return 0 ; }static inline void s390_pv_vm_disable (void ) {}static inline int s390_pv_set_sec_parms (uint64_t origin,uint64_t length){ return 0; }
include/hw/s390x/pv.h +4
-0@@ -56,6 +62,10 @@ static inline void s390_pv_prep_reset(void) {}static inline int s390_pv_verify (void ) {return 0 ; }static inline void s390_pv_unshare (void ) {}static inline void s390_pv_inject_reset_error (CPUState *cs) {}; +static inline uint64_t kvm_s390_pv_dmp_get_size_cpu (void ) {return 0 ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_mem (void ) {return 0 ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_complete (void ) {return 0 ; } +static inline bool kvm_s390_pv_info_basic_valid (void ) {return false; }#endif /* CONFIG_KVM */ int
s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
--
2.34.1
Re: [PATCH v2 09/11] s390x: Introduce PV query interface
Quoted 9 lines · Janosch Frank
On 7/15/22 10:10, Marc-André Lureau wrote:
[...]Quoted 7 lines
Quoted 6 lines
ms->pv = true;hw/s390x/s390-virtio-ccw.c +3
-0+ rc =s390_pv_query_info (); +if (rc) { + goto out_err;
Quoted 10 lines
Quoted 3 lines
Maybe it's not necessary to make it fatal on error?
lgtm otherwise
Hmm, yes and no.
The info API is fenced by the dump CAP so I don't ever expect an error here but on the other hand an optional info API fail might not warrant an error.
I see. You could explain more explicitly in the commit messages and/or comments the kernel version/requirements.
Quoted 55 lines
Quoted 25 lines
Quoted 25 lines
hw/s390x/s390-virtio-ccw.c +2
-0+ } +/* Set SE header and unpack */ rc =s390_ipl_prepare_pv_header ();if (rc) {include/hw/s390x/pv.h +3
-0@@ -38,6 +38,7 @@ static inline bool s390_is_pv(void)return ccw->pv; } +int s390_pv_query_info (void );int s390_pv_vm_enable (void );void s390_pv_vm_disable (void );int s390_pv_set_sec_parms (uint64_t origin,uint64_t length);@@ -46,8 +47,13 @@ void s390_pv_prep_reset(void);int s390_pv_verify (void );void s390_pv_unshare (void );void s390_pv_inject_reset_error (CPUState *cs); +uint64_t kvm_s390_pv_dmp_get_size_cpu (void ); +uint64_t kvm_s390_pv_dmp_get_size_mem (void );Quoted 8 lines
include/hw/s390x/pv.h void s390_pv_prep_reset(void);
Quoted 8 lines
include/hw/s390x/pv.h +3
-0+uint64_t kvm_s390_pv_dmp_get_size_complete (void ); +bool kvm_s390_pv_info_basic_valid (void );#else /* CONFIG_KVM */ static inline bool s390_is_pv (void ) {return false; } +static inline int s390_pv_query_info (void ) {return 0 ; }static inline int s390_pv_vm_enable (void ) {return 0 ; }static inline void s390_pv_vm_disable (void ) {} static inline int s390_pv_set_sec_parms(uint64_t origin, uint64_tlength)
Quoted 19 lines
Quoted 18 lines
{ return 0; }
include/hw/s390x/pv.h +4
-0@@ -56,6 +62,10 @@ static inline void s390_pv_prep_reset(void) {}static inline int s390_pv_verify (void ) {return 0 ; }static inline void s390_pv_unshare (void ) {}static inline void s390_pv_inject_reset_error (CPUState *cs) {}; +static inline uint64_t kvm_s390_pv_dmp_get_size_cpu (void ) {return 0 ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_mem (void ) {return 0 ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_complete (void ) {return 0 ; } +static inline bool kvm_s390_pv_info_basic_valid (void ) {return false; }#endif /* CONFIG_KVM */ int
s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
--
2.34.1
Signature · 1 line
Marc-André Lureau
PATCH v2 10/11 s390x: Add KVM PV dump interface
In reply to Janosch FrankLet's add a few bits of code which hide the new KVM PV dump API from us via new functions.
--- hw/s390x/pv.c | 51 +++++++++++++++++++++++++++++++++++++++++++ include/hw/s390x/pv.h | 8 +++++++ 2 files changed, 59 insertions(+)
hw/s390x/pv.c +51 -0
@@ -175,6 +175,57 @@ bool kvm_s390_pv_info_basic_valid(void)return info_valid; } +static int s390_pv_dump_cmd (uint64_t subcmd,uint64_t uaddr,uint64_t gaddr, +uint64_t len) +{ +struct kvm_s390_pv_dmp dmp = { + .subcmd = subcmd, + .buff_addr = uaddr, + .buff_len = len, + .gaddr = gaddr, + }; +int ret; + + ret =s390_pv_cmd (KVM_PV_DUMP , (void *)&dmp); +if (ret) { +error_report ("KVM DUMP command %ld failed" , subcmd); + } +return ret; +} + +int kvm_s390_dump_cpu (S390CPU *cpu,void *buff) +{ +struct kvm_s390_pv_dmp dmp = { + .subcmd =KVM_PV_DUMP_CPU , + .buff_addr = (uint64_t )buff, + .gaddr =0 , + .buff_len = info_dump.dump_cpu_buffer_len, + }; +struct kvm_pv_cmd pv = { + .cmd =KVM_PV_DUMP , + .data = (uint64_t )&dmp, + }; + +return kvm_vcpu_ioctl (CPU (cpu),KVM_S390_PV_CPU_COMMAND , &pv); +} + +int kvm_s390_dump_init (void ) +{ +return s390_pv_dump_cmd (KVM_PV_DUMP_INIT ,0 ,0 ,0 ); +} + +int kvm_s390_dump_mem (uint64_t gaddr,size_t len,void *dest) +{ +return s390_pv_dump_cmd (KVM_PV_DUMP_CONFIG_STATE , (uint64_t )dest, + gaddr, len); +} + +int kvm_s390_dump_finish (void *buff) +{ +return s390_pv_dump_cmd (KVM_PV_DUMP_COMPLETE , (uint64_t )buff,0 , + info_dump.dump_config_finalize_len); +} +#define TYPE_S390_PV_GUEST "s390-pv-guest"OBJECT_DECLARE_SIMPLE_TYPE (S390PVGuest,S390_PV_GUEST )
include/hw/s390x/pv.h +8 -0
@@ -51,6 +51,10 @@ uint64_t kvm_s390_pv_dmp_get_size_cpu(void);uint64_t kvm_s390_pv_dmp_get_size_mem (void );uint64_t kvm_s390_pv_dmp_get_size_complete (void );bool kvm_s390_pv_info_basic_valid (void ); +int kvm_s390_dump_init (void ); +int kvm_s390_dump_cpu (S390CPU *cpu,void *buff); +int kvm_s390_dump_mem (uint64_t addr,size_t len,void *dest); +int kvm_s390_dump_finish (void *buff);#else /* CONFIG_KVM */ static inline bool s390_is_pv (void ) {return false; }static inline int s390_pv_query_info (void ) {return 0 ; }
@@ -66,6 +70,10 @@ static inline uint64_t kvm_s390_pv_dmp_get_size_cpu(void) { return 0; }static inline uint64_t kvm_s390_pv_dmp_get_size_mem (void ) {return 0 ; }static inline uint64_t kvm_s390_pv_dmp_get_size_complete (void ) {return 0 ; }static inline bool kvm_s390_pv_info_basic_valid (void ) {return false; } +static inline int kvm_s390_dump_init (void ) {return 0 ; } +static inline int kvm_s390_dump_cpu (S390CPU *cpu,void *buff,size_t len) {return 0 ; } +static inline int kvm_s390_dump_mem (uint64_t addr,size_t len,void *dest) {return 0 ; } +static inline int kvm_s390_dump_finish (void *buff) {return 0 ; }#endif /* CONFIG_KVM */ int s390_pv_kvm_init (ConfidentialGuestSupport *cgs,Error **errp);
Signature · 1 line
2.34.1
PATCH v2 11/11 s390x: pv: Add dump support
In reply to Janosch FrankSometimes dumping a guest from the outside is the only way to get the data that is needed. This can be the case if a dumping mechanism like KDUMP hasn't been configured or data needs to be fetched at a specific point. Dumping a protected guest from the outside without help from fw/hw doesn't yield sufficient data to be useful. Hence we now introduce PV dump support.
The PV dump support works by integrating the firmware into the dump process. New Ultravisor calls are used to initiate the dump process, dump cpu data, dump memory state and lastly complete the dump process. The UV calls are exposed by KVM via the new KVM_PV_DUMP command and its subcommands. The guest's data is fully encrypted and can only be decrypted by the entity that owns the customer communication key for the dumped guest. Also dumping needs to be allowed via a flag in the SE header.
On the QEMU side of things we store the PV dump data in the newly introduced architecture ELF sections (storage state and completion data) and the cpu notes (for cpu dump data).
Users can use the zgetdump tool to convert the encrypted QEMU dump to an unencrypted one.
--- include/elf.h | 1 + target/s390x/arch_dump.c | 248 ++++++++++++++++++++++++++++++++++----- 2 files changed, 219 insertions(+), 30 deletions(-)
include/elf.h +1 -0
@@ -1649,6 +1649,7 @@ typedef struct elf64_shdr {#define NT_TASKSTRUCT 4#define NT_AUXV 6#define NT_PRXFPREG 0x46e62b7f/* copied from gdb5.1/include/elf/common.h */ +#define NT_S390_PV_DATA 0x30e/* s390 protvirt cpu dump data */ #define NT_S390_GS_CB 0x30b/* s390 guarded storage registers */ #define NT_S390_VXRS_HIGH 0x30a/* s390 vector registers 16-31 */ #define NT_S390_VXRS_LOW 0x309/* s390 vector registers 0-15 (lower half) */
target/s390x/arch_dump.c +218 -30
317 lines not on this page · raw message
Signature · 1 line
2.34.1