qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Janosch Frank <frankja@linux.ibm.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, QEMU <qemu-devel@nongnu.org>
Subject: Re: [PATCH 5/7] dump: Consolidate phdr note writes
Date: Tue, 1 Mar 2022 17:00:39 +0100	[thread overview]
Message-ID: <0fece214-179c-bbea-c383-cf6a34aee825@linux.ibm.com> (raw)
In-Reply-To: <CAJ+F1CLsQ5vwOdwURSuLAp_afSk-hffJC1wEYH7zVFiiLEXmfw@mail.gmail.com>

On 3/1/22 15:30, Marc-André Lureau wrote:
> Hi
> 
> On Tue, Mar 1, 2022 at 6:26 PM Janosch Frank <frankja@linux.ibm.com> wrote:
> 
>> There's no need to have two write functions. Let's rather have two
>> functions that set the data for elf 32/64 and then write it in a
>> common function.
>>
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
>>   dump/dump.c | 96 ++++++++++++++++++++++++++---------------------------
> 
>   1 file changed, 48 insertions(+), 48 deletions(-)
>>
> 
> I suppose there are other parts of the series that make use of that,
> because as such, it's not a clear improvement to me.

It's one piece of the effort to get rid of that big if/else in 
dump_begin() and that frees the way to make re-ordering the write 
functions possible.

I'll send out the other two series tomorrow.

> 
>>
> 
>>
>> diff --git a/dump/dump.c b/dump/dump.c
>> index bb152bddff..88c2dbb466 100644
>> --- a/dump/dump.c
>> +++ b/dump/dump.c
>> @@ -231,24 +231,15 @@ static void write_elf32_load(DumpState *s,
>> MemoryMapping *memory_mapping,
>>       }
>>   }
>>
>> -static void write_elf64_note(DumpState *s, Error **errp)
>> +static void write_elf64_phdr_note(DumpState *s, Elf64_Phdr *phdr)
>>   {
>> -    Elf64_Phdr phdr;
>> -    int ret;
>> -
>> -    memset(&phdr, 0, sizeof(Elf64_Phdr));
>> -    phdr.p_type = cpu_to_dump32(s, PT_NOTE);
>> -    phdr.p_offset = cpu_to_dump64(s, s->note_offset);
>> -    phdr.p_paddr = 0;
>> -    phdr.p_filesz = cpu_to_dump64(s, s->note_size);
>> -    phdr.p_memsz = cpu_to_dump64(s, s->note_size);
>> -    phdr.p_vaddr = 0;
>> -
>> -    ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
>> -    if (ret < 0) {
>> -        error_setg_errno(errp, -ret,
>> -                         "dump: failed to write program header table");
>> -    }
>> +    memset(phdr, 0, sizeof(*phdr));
>> +    phdr->p_type = cpu_to_dump32(s, PT_NOTE);
>> +    phdr->p_offset = cpu_to_dump64(s, s->note_offset);
>> +    phdr->p_paddr = 0;
>> +    phdr->p_filesz = cpu_to_dump64(s, s->note_size);
>> +    phdr->p_memsz = cpu_to_dump64(s, s->note_size);
>> +    phdr->p_vaddr = 0;
>>   }
>>
>>   static inline int cpu_index(CPUState *cpu)
>> @@ -296,24 +287,15 @@ static void write_elf64_notes(WriteCoreDumpFunction
>> f, DumpState *s,
>>       write_guest_note(f, s, errp);
>>   }
>>
>> -static void write_elf32_note(DumpState *s, Error **errp)
>> +static void write_elf32_phdr_note(DumpState *s, Elf32_Phdr *phdr)
>>   {
>> -    Elf32_Phdr phdr;
>> -    int ret;
>> -
>> -    memset(&phdr, 0, sizeof(Elf32_Phdr));
>> -    phdr.p_type = cpu_to_dump32(s, PT_NOTE);
>> -    phdr.p_offset = cpu_to_dump32(s, s->note_offset);
>> -    phdr.p_paddr = 0;
>> -    phdr.p_filesz = cpu_to_dump32(s, s->note_size);
>> -    phdr.p_memsz = cpu_to_dump32(s, s->note_size);
>> -    phdr.p_vaddr = 0;
>> -
>> -    ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
>> -    if (ret < 0) {
>> -        error_setg_errno(errp, -ret,
>> -                         "dump: failed to write program header table");
>> -    }
>> +    memset(phdr, 0, sizeof(*phdr));
>> +    phdr->p_type = cpu_to_dump32(s, PT_NOTE);
>> +    phdr->p_offset = cpu_to_dump32(s, s->note_offset);
>> +    phdr->p_paddr = 0;
>> +    phdr->p_filesz = cpu_to_dump32(s, s->note_size);
>> +    phdr->p_memsz = cpu_to_dump32(s, s->note_size);
>> +    phdr->p_vaddr = 0;
>>   }
>>
>>   static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
>> @@ -343,6 +325,31 @@ static void write_elf32_notes(WriteCoreDumpFunction
>> f, DumpState *s,
>>       write_guest_note(f, s, errp);
>>   }
>>
>> +static void write_elf_phdr_note(DumpState *s, Error **errp)
>> +{
>> +    Elf32_Phdr phdr32;
>> +    Elf64_Phdr phdr64;
>> +    void *phdr;
>> +    size_t size;
>> +    int ret;
>> +
>> +    if (dump_is_64bit(s)) {
>> +        write_elf64_phdr_note(s, &phdr64);
>> +        size = sizeof(phdr64);
>> +        phdr = &phdr64;
>> +    } else {
>> +        write_elf32_phdr_note(s, &phdr32);
>> +        size = sizeof(phdr32);
>> +        phdr = &phdr32;
>> +    }
>> +
>> +    ret = fd_write_vmcore(phdr, size, s);
>> +    if (ret < 0) {
>> +        error_setg_errno(errp, -ret,
>> +                         "dump: failed to write program header table");
>> +    }
>> +}
>> +
>>   static void write_elf_section(DumpState *s, int type, Error **errp)
>>   {
>>       Elf32_Shdr shdr32;
>> @@ -540,14 +547,14 @@ static void dump_begin(DumpState *s, Error **errp)
>>           return;
>>       }
>>
>> -    if (dump_is_64bit(s)) {
>> -        /* write PT_NOTE to vmcore */
>> -        write_elf64_note(s, &local_err);
>> -        if (local_err) {
>> -            error_propagate(errp, local_err);
>> -            return;
>> -        }
>> +    /* write PT_NOTE to vmcore */
>> +    write_elf_phdr_note(s, &local_err);
>> +    if (local_err) {
>> +        error_propagate(errp, local_err);
>> +        return;
>> +    }
>>
>> +    if (dump_is_64bit(s)) {
>>           /* write all PT_LOAD to vmcore */
>>           write_elf_loads(s, &local_err);
>>           if (local_err) {
>> @@ -571,13 +578,6 @@ static void dump_begin(DumpState *s, Error **errp)
>>               return;
>>           }
>>       } else {
>> -        /* write PT_NOTE to vmcore */
>> -        write_elf32_note(s, &local_err);
>> -        if (local_err) {
>> -            error_propagate(errp, local_err);
>> -            return;
>> -        }
>> -
>>           /* write all PT_LOAD to vmcore */
>>           write_elf_loads(s, &local_err);
>>           if (local_err) {
>> --
>> 2.32.0
>>
>>
>>
> 


  reply	other threads:[~2022-03-01 16:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01 14:22 [PATCH 0/7] dump: Cleanup and consolidation Janosch Frank
2022-03-01 14:22 ` [PATCH 1/7] dump: Introduce shdr_num to decrease complexity Janosch Frank
2022-03-01 14:42   ` Marc-André Lureau
2022-03-08 13:16     ` Janosch Frank
2022-03-01 14:22 ` [PATCH 2/7] dump: Remove the sh_info variable Janosch Frank
2022-03-01 14:22 ` [PATCH 3/7] dump: Add more offset variables Janosch Frank
2022-03-02 10:20   ` Marc-André Lureau
2022-03-01 14:22 ` [PATCH 4/7] dump: Introduce dump_is_64bit() helper function Janosch Frank
2022-03-01 14:33   ` Marc-André Lureau
2022-03-01 14:22 ` [PATCH 5/7] dump: Consolidate phdr note writes Janosch Frank
2022-03-01 14:30   ` Marc-André Lureau
2022-03-01 16:00     ` Janosch Frank [this message]
2022-03-01 14:22 ` [PATCH 6/7] dump: Cleanup dump_begin write functions Janosch Frank
2022-03-01 14:22 ` [PATCH 7/7] dump: Consolidate elf note function Janosch Frank
2022-03-02 10:30   ` Marc-André Lureau
2022-03-02 12:44     ` Janosch Frank
2022-03-02 21:15       ` Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0fece214-179c-bbea-c383-cf6a34aee825@linux.ibm.com \
    --to=frankja@linux.ibm.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).