From patchwork Wed Mar 30 12:35:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795764 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B6B6C433EF for ; Wed, 30 Mar 2022 12:42:11 +0000 (UTC) Received: from localhost ([::1]:39956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXeL-00029l-Sl for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:42:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZV-0006Xk-2a for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48940) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZS-0003Mw-Pl for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:08 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UBvdQH000582; Wed, 30 Mar 2022 12:37:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=i+HPchXzeHXR2eEOrsdTckR8wM8h73tHSo5dB+eTHOU=; b=buB95T/P3SL/dY9uyMJIa8QOZpAAHD744GvvltKGBpMF4N3cjJZYDd9v8XzzAo0ELZBe 8tq/YHvpyJm+ckhQUQ8xLbFguh6xuVZ2DBaWyto5o47W0esPF5Xcn2/Y+ouwzGVgthaQ kXudeDVRMlslR33LWqjsCUvoFpOurc5WTEZyucDIAFvp8wCgpJauqhQ1bgH45a4aVIPj jcMawSNOgaD6qw9HFOcJfrLvQC0Vmpyk8MFDfpi4lWFeBGH8yTSXw8vlIqaWYoO59WSC 2UPV3i92bpIZdTEvHM2EkvfQLlRPwUd1FaKQ317XBAdTssHwOpvl9ifmkAJ/VbyRvy7r lQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f4psu0ubq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:02 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UCb1iE025934; Wed, 30 Mar 2022 12:37:01 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f4psu0uas-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:01 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCNnVs018840; Wed, 30 Mar 2022 12:36:59 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03ams.nl.ibm.com with ESMTP id 3f1tf9gjm9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:36:59 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCauOK40304974 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:36:56 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB2065204F; Wed, 30 Mar 2022 12:36:56 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 3E5D252054; Wed, 30 Mar 2022 12:36:56 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 1/9] dump: Use ERRP_GUARD() Date: Wed, 30 Mar 2022 12:35:55 +0000 Message-Id: <20220330123603.107120-2-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: iapEIg_E46W7LWLgAlHnCYTn1VClvLS6 X-Proofpoint-GUID: o7zsFkKxJc9Ja0iAw81NG2xLrhOuV1kB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_03,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=957 malwarescore=0 clxscore=1015 suspectscore=0 bulkscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Let's move to the new way of handling errors before changing the dump code. This patch has mostly been generated by the coccinelle script scripts/coccinelle/errp-guard.cocci. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson Reviewed-by: Marc-André Lureau --- dump/dump.c | 144 ++++++++++++++++++++++------------------------------ 1 file changed, 61 insertions(+), 83 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index f57ed76fa7..58c4923fce 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -390,23 +390,21 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp) static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start, int64_t size, Error **errp) { + ERRP_GUARD(); int64_t i; - Error *local_err = NULL; for (i = 0; i < size / s->dump_info.page_size; i++) { write_data(s, block->host_addr + start + i * s->dump_info.page_size, - s->dump_info.page_size, &local_err); - if (local_err) { - error_propagate(errp, local_err); + s->dump_info.page_size, errp); + if (*errp) { return; } } if ((size % s->dump_info.page_size) != 0) { write_data(s, block->host_addr + start + i * s->dump_info.page_size, - size % s->dump_info.page_size, &local_err); - if (local_err) { - error_propagate(errp, local_err); + size % s->dump_info.page_size, errp); + if (*errp) { return; } } @@ -476,11 +474,11 @@ static void get_offset_range(hwaddr phys_addr, static void write_elf_loads(DumpState *s, Error **errp) { + ERRP_GUARD(); hwaddr offset, filesz; MemoryMapping *memory_mapping; uint32_t phdr_index = 1; uint32_t max_index; - Error *local_err = NULL; if (s->have_section) { max_index = s->sh_info; @@ -494,14 +492,13 @@ static void write_elf_loads(DumpState *s, Error **errp) s, &offset, &filesz); if (s->dump_info.d_class == ELFCLASS64) { write_elf64_load(s, memory_mapping, phdr_index++, offset, - filesz, &local_err); + filesz, errp); } else { write_elf32_load(s, memory_mapping, phdr_index++, offset, - filesz, &local_err); + filesz, errp); } - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { return; } @@ -514,7 +511,7 @@ static void write_elf_loads(DumpState *s, Error **errp) /* write elf header, PT_NOTE and elf note to vmcore. */ static void dump_begin(DumpState *s, Error **errp) { - Error *local_err = NULL; + ERRP_GUARD(); /* * the vmcore's format is: @@ -542,73 +539,64 @@ static void dump_begin(DumpState *s, Error **errp) /* write elf header to vmcore */ if (s->dump_info.d_class == ELFCLASS64) { - write_elf64_header(s, &local_err); + write_elf64_header(s, errp); } else { - write_elf32_header(s, &local_err); + write_elf32_header(s, errp); } - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { return; } if (s->dump_info.d_class == ELFCLASS64) { /* write PT_NOTE to vmcore */ - write_elf64_note(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf64_note(s, errp); + if (*errp) { return; } /* write all PT_LOAD to vmcore */ - write_elf_loads(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf_loads(s, errp); + if (*errp) { return; } /* write section to vmcore */ if (s->have_section) { - write_elf_section(s, 1, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf_section(s, 1, errp); + if (*errp) { return; } } /* write notes to vmcore */ - write_elf64_notes(fd_write_vmcore, s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf64_notes(fd_write_vmcore, s, errp); + if (*errp) { return; } } else { /* write PT_NOTE to vmcore */ - write_elf32_note(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf32_note(s, errp); + if (*errp) { return; } /* write all PT_LOAD to vmcore */ - write_elf_loads(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf_loads(s, errp); + if (*errp) { return; } /* write section to vmcore */ if (s->have_section) { - write_elf_section(s, 0, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf_section(s, 0, errp); + if (*errp) { return; } } /* write notes to vmcore */ - write_elf32_notes(fd_write_vmcore, s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf32_notes(fd_write_vmcore, s, errp); + if (*errp) { return; } } @@ -644,9 +632,9 @@ static int get_next_block(DumpState *s, GuestPhysBlock *block) /* write all memory to vmcore */ static void dump_iterate(DumpState *s, Error **errp) { + ERRP_GUARD(); GuestPhysBlock *block; int64_t size; - Error *local_err = NULL; do { block = s->next_block; @@ -658,9 +646,8 @@ static void dump_iterate(DumpState *s, Error **errp) size -= block->target_end - (s->begin + s->length); } } - write_memory(s, block, s->start, size, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_memory(s, block, s->start, size, errp); + if (*errp) { return; } @@ -669,11 +656,10 @@ static void dump_iterate(DumpState *s, Error **errp) static void create_vmcore(DumpState *s, Error **errp) { - Error *local_err = NULL; + ERRP_GUARD(); - dump_begin(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + dump_begin(s, errp); + if (*errp) { return; } @@ -810,6 +796,7 @@ static bool note_name_equal(DumpState *s, /* write common header, sub header and elf note to vmcore */ static void create_header32(DumpState *s, Error **errp) { + ERRP_GUARD(); DiskDumpHeader32 *dh = NULL; KdumpSubHeader32 *kh = NULL; size_t size; @@ -818,7 +805,6 @@ static void create_header32(DumpState *s, Error **errp) uint32_t bitmap_blocks; uint32_t status = 0; uint64_t offset_note; - Error *local_err = NULL; /* write common header, the version of kdump-compressed format is 6th */ size = sizeof(DiskDumpHeader32); @@ -894,9 +880,8 @@ static void create_header32(DumpState *s, Error **errp) s->note_buf_offset = 0; /* use s->note_buf to store notes temporarily */ - write_elf32_notes(buf_write_note, s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf32_notes(buf_write_note, s, errp); + if (*errp) { goto out; } if (write_buffer(s->fd, offset_note, s->note_buf, @@ -922,6 +907,7 @@ out: /* write common header, sub header and elf note to vmcore */ static void create_header64(DumpState *s, Error **errp) { + ERRP_GUARD(); DiskDumpHeader64 *dh = NULL; KdumpSubHeader64 *kh = NULL; size_t size; @@ -930,7 +916,6 @@ static void create_header64(DumpState *s, Error **errp) uint32_t bitmap_blocks; uint32_t status = 0; uint64_t offset_note; - Error *local_err = NULL; /* write common header, the version of kdump-compressed format is 6th */ size = sizeof(DiskDumpHeader64); @@ -1006,9 +991,8 @@ static void create_header64(DumpState *s, Error **errp) s->note_buf_offset = 0; /* use s->note_buf to store notes temporarily */ - write_elf64_notes(buf_write_note, s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_elf64_notes(buf_write_note, s, errp); + if (*errp) { goto out; } @@ -1464,8 +1448,8 @@ out: static void create_kdump_vmcore(DumpState *s, Error **errp) { + ERRP_GUARD(); int ret; - Error *local_err = NULL; /* * the kdump-compressed format is: @@ -1495,21 +1479,18 @@ static void create_kdump_vmcore(DumpState *s, Error **errp) return; } - write_dump_header(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_dump_header(s, errp); + if (*errp) { return; } - write_dump_bitmap(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_dump_bitmap(s, errp); + if (*errp) { return; } - write_dump_pages(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + write_dump_pages(s, errp); + if (*errp) { return; } @@ -1639,10 +1620,10 @@ static void dump_init(DumpState *s, int fd, bool has_format, DumpGuestMemoryFormat format, bool paging, bool has_filter, int64_t begin, int64_t length, Error **errp) { + ERRP_GUARD(); VMCoreInfoState *vmci = vmcoreinfo_find(); CPUState *cpu; int nr_cpus; - Error *err = NULL; int ret; s->has_format = has_format; @@ -1761,9 +1742,8 @@ static void dump_init(DumpState *s, int fd, bool has_format, /* get memory mapping */ if (paging) { - qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, &err); - if (err != NULL) { - error_propagate(errp, err); + qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, errp); + if (*errp) { goto cleanup; } } else { @@ -1862,33 +1842,32 @@ cleanup: /* this operation might be time consuming. */ static void dump_process(DumpState *s, Error **errp) { - Error *local_err = NULL; + ERRP_GUARD(); DumpQueryResult *result = NULL; if (s->has_format && s->format == DUMP_GUEST_MEMORY_FORMAT_WIN_DMP) { #ifdef TARGET_X86_64 - create_win_dump(s, &local_err); + create_win_dump(s, errp); #endif } else if (s->has_format && s->format != DUMP_GUEST_MEMORY_FORMAT_ELF) { - create_kdump_vmcore(s, &local_err); + create_kdump_vmcore(s, errp); } else { - create_vmcore(s, &local_err); + create_vmcore(s, errp); } /* make sure status is written after written_size updates */ smp_wmb(); qatomic_set(&s->status, - (local_err ? DUMP_STATUS_FAILED : DUMP_STATUS_COMPLETED)); + (*errp ? DUMP_STATUS_FAILED : DUMP_STATUS_COMPLETED)); /* send DUMP_COMPLETED message (unconditionally) */ result = qmp_query_dump(NULL); /* should never fail */ assert(result); - qapi_event_send_dump_completed(result, !!local_err, (local_err ? - error_get_pretty(local_err) : NULL)); + qapi_event_send_dump_completed(result, !!*errp, (*errp ? + error_get_pretty(*errp) : NULL)); qapi_free_DumpQueryResult(result); - error_propagate(errp, local_err); dump_cleanup(s); } @@ -1917,10 +1896,10 @@ void qmp_dump_guest_memory(bool paging, const char *file, int64_t length, bool has_format, DumpGuestMemoryFormat format, Error **errp) { + ERRP_GUARD(); const char *p; int fd = -1; DumpState *s; - Error *local_err = NULL; bool detach_p = false; if (runstate_check(RUN_STATE_INMIGRATE)) { @@ -2020,9 +1999,8 @@ void qmp_dump_guest_memory(bool paging, const char *file, dump_state_prepare(s); dump_init(s, fd, has_format, format, paging, has_begin, - begin, length, &local_err); - if (local_err) { - error_propagate(errp, local_err); + begin, length, errp); + if (*errp) { qatomic_set(&s->status, DUMP_STATUS_FAILED); return; } From patchwork Wed Mar 30 12:35:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795788 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37233C433F5 for ; Wed, 30 Mar 2022 12:49:40 +0000 (UTC) Received: from localhost ([::1]:54360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXlb-0004dC-CI for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:49:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZT-0006Xh-4i for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:3790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZQ-0003Mh-Ar for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:06 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UBCkOd011116; Wed, 30 Mar 2022 12:37:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=8WzN/R0WchSHBbAcZ3MykMNtGn68Gdr+7wJbS81+pB8=; b=Jfx4wr/oecunugbRktkjq7ZJvOo/Vg+2vxhQWBIU5ZBRCvuEkhy79yLSOzMXBn5FPu1w cWS+h5BXt2IMtRpSkP11m9C/ftfSzSP8/2QXKQgoCe3HAuEXCzjngRfqndZMKgaHfbmn ZCmJ6OYT5qT8m5jFIecZbceTlqEg6FZAgYC5pez9uBI8yaOksiIoluhFhiAHZIAH6EG8 Ga6excmYyUERrfWN35ccaL5nuIoyLegFra84WozlGKQPFNMRotW3ubS5wqXjaoGfxzpA mkPi/QuOwj2K0H/Dnd5YZN6NzEJdbe+pkeJ5/9DIF9qtxMAKBJkDTXc3alDZEzOYy6kO /Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f3ydcpr23-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:02 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UBslKd006796; Wed, 30 Mar 2022 12:37:01 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f3ydcpr15-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:01 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCMYpm010026; Wed, 30 Mar 2022 12:36:59 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06fra.de.ibm.com with ESMTP id 3f1t3hyay4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:36:59 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCb38933227082 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:37:03 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5F6235204E; Wed, 30 Mar 2022 12:36:57 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id D73A952051; Wed, 30 Mar 2022 12:36:56 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 2/9] dump: Remove the sh_info variable Date: Wed, 30 Mar 2022 12:35:56 +0000 Message-Id: <20220330123603.107120-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: rWSH4wFFpJiDOi13iOa0Va3p8T6skcoz X-Proofpoint-GUID: syjJT8OqPnwkRZ1hvwhCwzfJsxysFD5k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_04,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 clxscore=1015 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" There's no need to have phdr_num and sh_info at the same time. We can make phdr_num 32 bit and set PN_XNUM when we write the header if phdr_num >= PN_XNUM. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson --- dump/dump.c | 34 ++++++++++++++-------------------- include/sysemu/dump.h | 3 +-- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 58c4923fce..0e6187c962 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -124,6 +124,7 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque) static void write_elf64_header(DumpState *s, Error **errp) { + uint16_t phnum = s->phdr_num >= PN_XNUM ? PN_XNUM : s->phdr_num; Elf64_Ehdr elf_header; int ret; @@ -138,9 +139,9 @@ static void write_elf64_header(DumpState *s, Error **errp) elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header)); elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr)); elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr)); - elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num); + elf_header.e_phnum = cpu_to_dump16(s, phnum); if (s->have_section) { - uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->sh_info; + uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num; elf_header.e_shoff = cpu_to_dump64(s, shoff); elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr)); @@ -155,6 +156,7 @@ static void write_elf64_header(DumpState *s, Error **errp) static void write_elf32_header(DumpState *s, Error **errp) { + uint16_t phnum = s->phdr_num >= PN_XNUM ? PN_XNUM : s->phdr_num; Elf32_Ehdr elf_header; int ret; @@ -169,9 +171,9 @@ static void write_elf32_header(DumpState *s, Error **errp) elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header)); elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr)); elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr)); - elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num); + elf_header.e_phnum = cpu_to_dump16(s, phnum); if (s->have_section) { - uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->sh_info; + uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num; elf_header.e_shoff = cpu_to_dump32(s, shoff); elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr)); @@ -358,12 +360,12 @@ static void write_elf_section(DumpState *s, int type, Error **errp) if (type == 0) { shdr_size = sizeof(Elf32_Shdr); memset(&shdr32, 0, shdr_size); - shdr32.sh_info = cpu_to_dump32(s, s->sh_info); + shdr32.sh_info = cpu_to_dump32(s, s->phdr_num); shdr = &shdr32; } else { shdr_size = sizeof(Elf64_Shdr); memset(&shdr64, 0, shdr_size); - shdr64.sh_info = cpu_to_dump32(s, s->sh_info); + shdr64.sh_info = cpu_to_dump32(s, s->phdr_num); shdr = &shdr64; } @@ -478,13 +480,6 @@ static void write_elf_loads(DumpState *s, Error **errp) hwaddr offset, filesz; MemoryMapping *memory_mapping; uint32_t phdr_index = 1; - uint32_t max_index; - - if (s->have_section) { - max_index = s->sh_info; - } else { - max_index = s->phdr_num; - } QTAILQ_FOREACH(memory_mapping, &s->list.head, next) { get_offset_range(memory_mapping->phys_addr, @@ -502,7 +497,7 @@ static void write_elf_loads(DumpState *s, Error **errp) return; } - if (phdr_index >= max_index) { + if (phdr_index >= s->phdr_num) { break; } } @@ -1801,22 +1796,21 @@ static void dump_init(DumpState *s, int fd, bool has_format, s->phdr_num += s->list.num; s->have_section = false; } else { + /* sh_info of section 0 holds the real number of phdrs */ s->have_section = true; - s->phdr_num = PN_XNUM; - s->sh_info = 1; /* PT_NOTE */ /* the type of shdr->sh_info is uint32_t, so we should avoid overflow */ if (s->list.num <= UINT32_MAX - 1) { - s->sh_info += s->list.num; + s->phdr_num += s->list.num; } else { - s->sh_info = UINT32_MAX; + s->phdr_num = UINT32_MAX; } } if (s->dump_info.d_class == ELFCLASS64) { if (s->have_section) { s->memory_offset = sizeof(Elf64_Ehdr) + - sizeof(Elf64_Phdr) * s->sh_info + + sizeof(Elf64_Phdr) * s->phdr_num + sizeof(Elf64_Shdr) + s->note_size; } else { s->memory_offset = sizeof(Elf64_Ehdr) + @@ -1825,7 +1819,7 @@ static void dump_init(DumpState *s, int fd, bool has_format, } else { if (s->have_section) { s->memory_offset = sizeof(Elf32_Ehdr) + - sizeof(Elf32_Phdr) * s->sh_info + + sizeof(Elf32_Phdr) * s->phdr_num + sizeof(Elf32_Shdr) + s->note_size; } else { s->memory_offset = sizeof(Elf32_Ehdr) + diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 250143cb5a..b463fc9c02 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -154,8 +154,7 @@ typedef struct DumpState { GuestPhysBlockList guest_phys_blocks; ArchDumpInfo dump_info; MemoryMappingList list; - uint16_t phdr_num; - uint32_t sh_info; + uint32_t phdr_num; bool have_section; bool resume; bool detached; From patchwork Wed Mar 30 12:35:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795774 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64BFFC433F5 for ; Wed, 30 Mar 2022 12:45:06 +0000 (UTC) Received: from localhost ([::1]:44416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXhB-0005bd-72 for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:45:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZT-0006Xe-6N for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43364) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZQ-0003Ml-3C for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:05 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UBLY7H011195; Wed, 30 Mar 2022 12:37:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9dgrN1vBwy7wDkw6GU22GaS7vRhMJQ8kjbgrRPAymT0=; b=ggQOmE/TZhI+3Ebk+lmGHQ3K9MxXjiwe2tgFhH+h69RAl1CTuN/y6fGDF8apkkzl9EBD z9A+zWJIi/PnjSL486QJ+aw7WyzdgsOkePrDPdiKjx0jRNyIAR//8AUugmFN5UOkN/DI HBQ5IbhY6e2Ck6+S69dBoMc6hF4ZZlmuOLpGGJMt5irfc9wmVmTy3er9BPBa+Nt/haf5 2Y94LD4TCgdQyP6PaVW00/enoq/ATTamAXNHUNbyoixMbsalq568TApBgaol7lEDDeMJ F5+0Dk4QxTyOU3b4Oysz0BSRBpq93nomjAeXpaQBuqW3XwN4wY61HWthLtokf3bmmzzN tg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f3ydcpr28-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:02 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UC8Bss021184; Wed, 30 Mar 2022 12:37:02 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f3ydcpr1h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:01 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCMY12030982; Wed, 30 Mar 2022 12:37:00 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3f1tf90js3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:00 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCOw4O46072122 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:24:58 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 043C45204F; Wed, 30 Mar 2022 12:36:58 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7BC2A5204E; Wed, 30 Mar 2022 12:36:57 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 3/9] dump: Introduce shdr_num to decrease complexity Date: Wed, 30 Mar 2022 12:35:57 +0000 Message-Id: <20220330123603.107120-4-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: yxgERfuVSq99Lr7HMNtlAsmShqrjZVty X-Proofpoint-GUID: PIGD6td-DDnJXcKZLJRoGuotPcd70PId X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_04,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 clxscore=1015 malwarescore=0 mlxscore=0 mlxlogscore=793 suspectscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Let's move from a boolean to a int variable which will later enable us to store the number of sections that are in the dump file. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson Reviewed-by: Marc-André Lureau --- dump/dump.c | 24 ++++++++++++------------ include/sysemu/dump.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 0e6187c962..cd11dec0f4 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -140,12 +140,12 @@ static void write_elf64_header(DumpState *s, Error **errp) elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr)); elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr)); elf_header.e_phnum = cpu_to_dump16(s, phnum); - if (s->have_section) { + if (s->shdr_num) { uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num; elf_header.e_shoff = cpu_to_dump64(s, shoff); elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr)); - elf_header.e_shnum = cpu_to_dump16(s, 1); + elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num); } ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s); @@ -172,12 +172,12 @@ static void write_elf32_header(DumpState *s, Error **errp) elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr)); elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr)); elf_header.e_phnum = cpu_to_dump16(s, phnum); - if (s->have_section) { + if (s->shdr_num) { uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num; elf_header.e_shoff = cpu_to_dump32(s, shoff); elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr)); - elf_header.e_shnum = cpu_to_dump16(s, 1); + elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num); } ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s); @@ -556,7 +556,7 @@ static void dump_begin(DumpState *s, Error **errp) } /* write section to vmcore */ - if (s->have_section) { + if (s->shdr_num) { write_elf_section(s, 1, errp); if (*errp) { return; @@ -582,7 +582,7 @@ static void dump_begin(DumpState *s, Error **errp) } /* write section to vmcore */ - if (s->have_section) { + if (s->shdr_num) { write_elf_section(s, 0, errp); if (*errp) { return; @@ -1793,11 +1793,11 @@ static void dump_init(DumpState *s, int fd, bool has_format, */ s->phdr_num = 1; /* PT_NOTE */ if (s->list.num < UINT16_MAX - 2) { + s->shdr_num = 0; s->phdr_num += s->list.num; - s->have_section = false; } else { /* sh_info of section 0 holds the real number of phdrs */ - s->have_section = true; + s->shdr_num = 1; /* the type of shdr->sh_info is uint32_t, so we should avoid overflow */ if (s->list.num <= UINT32_MAX - 1) { @@ -1808,19 +1808,19 @@ static void dump_init(DumpState *s, int fd, bool has_format, } if (s->dump_info.d_class == ELFCLASS64) { - if (s->have_section) { + if (s->shdr_num) { s->memory_offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num + - sizeof(Elf64_Shdr) + s->note_size; + sizeof(Elf64_Shdr) * s->shdr_num + s->note_size; } else { s->memory_offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num + s->note_size; } } else { - if (s->have_section) { + if (s->shdr_num) { s->memory_offset = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num + - sizeof(Elf32_Shdr) + s->note_size; + sizeof(Elf32_Shdr) * s->shdr_num + s->note_size; } else { s->memory_offset = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num + s->note_size; diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index b463fc9c02..19458bffbd 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -155,7 +155,7 @@ typedef struct DumpState { ArchDumpInfo dump_info; MemoryMappingList list; uint32_t phdr_num; - bool have_section; + uint32_t shdr_num; bool resume; bool detached; ssize_t note_size; From patchwork Wed Mar 30 12:35:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E198BC433F5 for ; Wed, 30 Mar 2022 12:48:22 +0000 (UTC) Received: from localhost ([::1]:51206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXkL-0002Tv-Qz for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:48:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZU-0006Xi-KU for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:10980) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZS-0003Nm-Qx for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:08 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UB7Zbw009893; Wed, 30 Mar 2022 12:37:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=J/pXvdpT3ijRk510GtbPUmcm/+8by8LUDmrBVKwhts4=; b=BjXIiVNa1wyBygh7IegYexvdNjacjzwKaRmnOVb6ZcRWIcmVEYhZKvzJdYPansNl9LmT Q29WGeG7/vNjqwCR4ZhSdf0YwwDZNjwwOc4yDR8nU/NO9hfq7myPXRoJj4K/dakQqaIT jE1gKN1zPMINl+ORffKJzPgFMJD1jbnj6iOyCxUYf4ucshPWQXHWsxIAqC2TvilJVt8w GRumcVIxq47PACQHB73V7QAD04sw4M9gYVzramoSiTiPz9sl3cjDSJ4z1aFeZLFebe9s bwGZtYfdZrMBkte5q1KYMbyhQexdB4qheRm3OhsUjpgv/eyNICXOTbrNTjsiTMpKbN7H 5Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f40t8wdsu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:03 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UBe2t8004916; Wed, 30 Mar 2022 12:37:03 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f40t8wds5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:03 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCNbQe027068; Wed, 30 Mar 2022 12:37:01 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 3f3rs3kjc0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:00 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCOx0t34210144 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:24:59 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CAA452050; Wed, 30 Mar 2022 12:36:58 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 205585204E; Wed, 30 Mar 2022 12:36:58 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 4/9] dump: Remove the section if when calculating the memory offset Date: Wed, 30 Mar 2022 12:35:58 +0000 Message-Id: <20220330123603.107120-5-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Qm5p3O_XyI7Xh-ryiymuQbHCRzM4SdNM X-Proofpoint-GUID: O5tFIRGP8VOU4hkNKZeQfqV4jmhFP3MQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_04,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 clxscore=1015 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 spamscore=0 mlxlogscore=809 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When s->shdr_num is 0 we'll add 0 bytes of section headers which is equivalent to not adding section headers but with the multiplication we can remove a if/else. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson Reviewed-by: Marc-André Lureau --- dump/dump.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index cd11dec0f4..bdff651da4 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1808,23 +1808,15 @@ static void dump_init(DumpState *s, int fd, bool has_format, } if (s->dump_info.d_class == ELFCLASS64) { - if (s->shdr_num) { - s->memory_offset = sizeof(Elf64_Ehdr) + - sizeof(Elf64_Phdr) * s->phdr_num + - sizeof(Elf64_Shdr) * s->shdr_num + s->note_size; - } else { - s->memory_offset = sizeof(Elf64_Ehdr) + - sizeof(Elf64_Phdr) * s->phdr_num + s->note_size; - } + s->memory_offset = sizeof(Elf64_Ehdr) + + sizeof(Elf64_Phdr) * s->phdr_num + + sizeof(Elf64_Shdr) * s->shdr_num + + s->note_size; } else { - if (s->shdr_num) { - s->memory_offset = sizeof(Elf32_Ehdr) + - sizeof(Elf32_Phdr) * s->phdr_num + - sizeof(Elf32_Shdr) * s->shdr_num + s->note_size; - } else { - s->memory_offset = sizeof(Elf32_Ehdr) + - sizeof(Elf32_Phdr) * s->phdr_num + s->note_size; - } + s->memory_offset = sizeof(Elf32_Ehdr) + + sizeof(Elf32_Phdr) * s->phdr_num + + sizeof(Elf32_Shdr) * s->shdr_num + + s->note_size; } return; From patchwork Wed Mar 30 12:35:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30FCBC433EF for ; Wed, 30 Mar 2022 12:57:19 +0000 (UTC) Received: from localhost ([::1]:40258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXsz-0006HF-OD for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:57:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZV-0006Xm-Tp for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:17040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZT-0003OL-5z for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:09 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UCJ61P005023; Wed, 30 Mar 2022 12:37:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=/bxzL1zrriq4h7IYUC0+uRerRwm/BeU9sGVMTIaluhM=; b=dk2LCds9+S//k/CHc+XxG5P4CDnmid5GNEZ7kDwX82Y2NvQ69bdLaImcRFaExFtL/JwK CZBc8cl1TP4z2K3m0wKKGiaDuJ8uJ3s13xf/oOpshi1MRnSnVHUuwOYDkpujBczqhkpP bWQshrZqoxeanujJS+kW8lel3UOd/Yg6wtrJY5z2lgi9noyqgPncv77FWppbFaD37FLi oEyBKZE6TwbPRaElQhJ1r+YRc3FfL51Z0Nhkeu8Ph1vw8h6uLFrKB3yQ85VGzFeEEZKR xj4OZnZ1xjtwi518XPBcU0T7OX83bvb/jnwU/zi8AwXSX26QcJtRlQWRk9kNUr2knt4l Ig== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f3yqmp2du-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:04 +0000 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UCOmDP015018; Wed, 30 Mar 2022 12:37:04 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f3yqmp2d6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:04 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCMQel008366; Wed, 30 Mar 2022 12:37:01 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03fra.de.ibm.com with ESMTP id 3f1tf8y9c6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:01 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCaxH537290334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:36:59 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4158E52054; Wed, 30 Mar 2022 12:36:59 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id B8F2D5204E; Wed, 30 Mar 2022 12:36:58 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 5/9] dump: Add more offset variables Date: Wed, 30 Mar 2022 12:35:59 +0000 Message-Id: <20220330123603.107120-6-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: xRjSGJUREPi2uFS_ki3xFs-6hVDedXLd X-Proofpoint-ORIG-GUID: 56BB8qTmrh7zm9Kr06x6QcZ2ijZbQNbh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_03,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 bulkscore=0 spamscore=0 phishscore=0 malwarescore=0 suspectscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Offset calculations are easy enough to get wrong. Let's add a few variables to make moving around elf headers and data sections easier. Signed-off-by: Janosch Frank Reviewed-by: Marc-André Lureau Reviewed-by: Richard Henderson --- dump/dump.c | 35 +++++++++++++++-------------------- include/sysemu/dump.h | 4 ++++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index bdff651da4..4be4dcab24 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -137,13 +137,11 @@ static void write_elf64_header(DumpState *s, Error **errp) 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, sizeof(Elf64_Ehdr)); + 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) { - uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num; - - elf_header.e_shoff = cpu_to_dump64(s, shoff); + 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); } @@ -169,13 +167,11 @@ static void write_elf32_header(DumpState *s, Error **errp) 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, sizeof(Elf32_Ehdr)); + 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) { - uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num; - - elf_header.e_shoff = cpu_to_dump32(s, shoff); + 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); } @@ -238,12 +234,11 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping, static void write_elf64_note(DumpState *s, Error **errp) { Elf64_Phdr phdr; - hwaddr begin = s->memory_offset - s->note_size; int ret; memset(&phdr, 0, sizeof(Elf64_Phdr)); phdr.p_type = cpu_to_dump32(s, PT_NOTE); - phdr.p_offset = cpu_to_dump64(s, begin); + 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); @@ -303,13 +298,12 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s, static void write_elf32_note(DumpState *s, Error **errp) { - hwaddr begin = s->memory_offset - s->note_size; 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, begin); + 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); @@ -1808,15 +1802,16 @@ static void dump_init(DumpState *s, int fd, bool has_format, } if (s->dump_info.d_class == ELFCLASS64) { - s->memory_offset = sizeof(Elf64_Ehdr) + - sizeof(Elf64_Phdr) * s->phdr_num + - sizeof(Elf64_Shdr) * s->shdr_num + - s->note_size; + 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->memory_offset = sizeof(Elf32_Ehdr) + - sizeof(Elf32_Phdr) * s->phdr_num + - sizeof(Elf32_Shdr) * s->shdr_num + - s->note_size; + + 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; } return; diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 19458bffbd..ffc2ea1072 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -159,6 +159,10 @@ typedef struct DumpState { 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; From patchwork Wed Mar 30 12:36:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8EC3CC433F5 for ; Wed, 30 Mar 2022 12:44:10 +0000 (UTC) Received: from localhost ([::1]:43064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXgH-0004VP-Iw for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:44:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZU-0006Xj-KU for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:20024) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZS-0003Ne-R7 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:08 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UBtK8G027552; Wed, 30 Mar 2022 12:37:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=WYQ+Xlox94YTYQMkY2zxvl6qIS/JoH4wVE56qMQ37kg=; b=fXLWKYfAjeTnX8poy3Glh4nCSUYfD9aTn5DwdknQyz3xlX26zqEU8meHJv35OeDWkMAT 7AHXMTWJKmG/qLvuBTnmkqG8o1m9YPTbunnVYDgwrvN/QKGHEqwFQpKU/XVdP9SL8/Vu 0PybjCtWo7wx2V+z3Od2Nls6skp4y4d6eYegPB/N+AJk+2Ebsmp+s5YcNmfnjK75/+2f 31aT6K4AQArisKZVVD+WK7lu1on6K/+DuY44gEGNFx8VYfgctPnbbSfpZk0L1WfrrQQG Ej4+UAV6GOB2sdBqQLrGkdQ2ITgZdAedGdak6oTNSjQRVDwGvhzhDELYyZEyad6Rp3go DQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f3ydcpr3c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:04 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UBqQvG024589; Wed, 30 Mar 2022 12:37:04 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f3ydcpr2n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:03 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCMiqd012534; Wed, 30 Mar 2022 12:37:02 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma01fra.de.ibm.com with ESMTP id 3f1tf8q9wx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:02 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCaxPf39125254 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:36:59 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9EE95204F; Wed, 30 Mar 2022 12:36:59 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 5DB5D5204E; Wed, 30 Mar 2022 12:36:59 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 6/9] dump: Introduce dump_is_64bit() helper function Date: Wed, 30 Mar 2022 12:36:00 +0000 Message-Id: <20220330123603.107120-7-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: AQAa805WNUy4sP4F9QsieHmsRYhtndsP X-Proofpoint-GUID: FDHUrl71YoYEmtCPXHAHkIGwqnQmQEPp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_04,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 clxscore=1015 malwarescore=0 mlxscore=0 mlxlogscore=880 suspectscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Checking d_class in dump_info leads to lengthy conditionals so let's shorten things a bit by introducing a helper function. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson Reviewed-by: Marc-André Lureau --- dump/dump.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 4be4dcab24..a7cf112d8f 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -55,6 +55,11 @@ static Error *dump_migration_blocker; DIV_ROUND_UP((name_size), 4) + \ DIV_ROUND_UP((desc_size), 4)) * 4) +static inline bool dump_is_64bit(DumpState *s) +{ + return s->dump_info.d_class == ELFCLASS64; +} + uint16_t cpu_to_dump16(DumpState *s, uint16_t val) { if (s->dump_info.d_endian == ELFDATA2LSB) { @@ -479,7 +484,7 @@ static void write_elf_loads(DumpState *s, Error **errp) get_offset_range(memory_mapping->phys_addr, memory_mapping->length, s, &offset, &filesz); - if (s->dump_info.d_class == ELFCLASS64) { + if (dump_is_64bit(s)) { write_elf64_load(s, memory_mapping, phdr_index++, offset, filesz, errp); } else { @@ -527,7 +532,7 @@ static void dump_begin(DumpState *s, Error **errp) */ /* write elf header to vmcore */ - if (s->dump_info.d_class == ELFCLASS64) { + if (dump_is_64bit(s)) { write_elf64_header(s, errp); } else { write_elf32_header(s, errp); @@ -536,7 +541,7 @@ static void dump_begin(DumpState *s, Error **errp) return; } - if (s->dump_info.d_class == ELFCLASS64) { + if (dump_is_64bit(s)) { /* write PT_NOTE to vmcore */ write_elf64_note(s, errp); if (*errp) { @@ -747,7 +752,7 @@ static void get_note_sizes(DumpState *s, const void *note, uint64_t name_sz; uint64_t desc_sz; - if (s->dump_info.d_class == ELFCLASS64) { + if (dump_is_64bit(s)) { const Elf64_Nhdr *hdr = note; note_head_sz = sizeof(Elf64_Nhdr); name_sz = tswap64(hdr->n_namesz); @@ -1007,10 +1012,10 @@ out: static void write_dump_header(DumpState *s, Error **errp) { - if (s->dump_info.d_class == ELFCLASS32) { - create_header32(s, errp); - } else { + if (dump_is_64bit(s)) { create_header64(s, errp); + } else { + create_header32(s, errp); } } @@ -1697,8 +1702,8 @@ static void dump_init(DumpState *s, int fd, bool has_format, uint32_t size; uint16_t format; - note_head_size = s->dump_info.d_class == ELFCLASS32 ? - sizeof(Elf32_Nhdr) : sizeof(Elf64_Nhdr); + note_head_size = dump_is_64bit(s) ? + sizeof(Elf64_Nhdr) : sizeof(Elf32_Nhdr); format = le16_to_cpu(vmci->vmcoreinfo.guest_format); size = le32_to_cpu(vmci->vmcoreinfo.size); @@ -1801,7 +1806,7 @@ static void dump_init(DumpState *s, int fd, bool has_format, } } - if (s->dump_info.d_class == ELFCLASS64) { + 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; From patchwork Wed Mar 30 12:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84751C433EF for ; Wed, 30 Mar 2022 12:51:36 +0000 (UTC) Received: from localhost ([::1]:57172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXnT-0006gQ-7e for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:51:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZW-0006Xp-Gv for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:28994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZU-0003Oi-As for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UAg4i8009870; Wed, 30 Mar 2022 12:37:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=uc/60VnmIhmn8zwJuhVcpJY/A2MZIP+QnuB4GprNaaM=; b=eHbCW0x99xSdS7jdHhUszev/OCukFY8r0/1tmhtU52dpRQqJHfa8K0kDlVt6bfChp2df hBMyTdJE2o+caejq5W7D28lv2TXbvvAMASCnNiGeK8lPu0a6cYddvuLa6e3qtn49iopa ci5MY47HQHdZ3bGMe0H6OUFHa6Gbifb110O9ejYJzDpf8kRb5Re/naNYBAzNNxTkIO8P NrKafnOS45vgGNNmFnAqizn9cCXSQidnBQEENei+COvLLDMFelJ8lszf7Dt45HpdamJs jUUAEQ/gpnSnDUfQRRl0uLagMZLS0a1WIjIz0zHEg+aA606dF2XGJq24Nfi0064LM7R8 iA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f40t8wdtk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:05 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UCDf0e031988; Wed, 30 Mar 2022 12:37:05 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f40t8wdsq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:05 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCMY13030982; Wed, 30 Mar 2022 12:37:02 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 3f1tf90js6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:02 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCb0xa43843968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:37:00 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F07D5204F; Wed, 30 Mar 2022 12:37:00 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 0239B5204E; Wed, 30 Mar 2022 12:36:59 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 7/9] dump: Consolidate phdr note writes Date: Wed, 30 Mar 2022 12:36:01 +0000 Message-Id: <20220330123603.107120-8-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: fVxTtrygZZ7wB4n-8N_ZSw_Qnr0Hlecj X-Proofpoint-GUID: oKSlfGffj5a0wLu0GD6Ec85ahP4ADZIP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_04,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 clxscore=1015 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 spamscore=0 mlxlogscore=768 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Richard Henderson Reviewed-by: Marc-André Lureau --- dump/dump.c | 94 +++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index a7cf112d8f..365798f5a1 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -236,24 +236,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) @@ -301,24 +292,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, @@ -348,6 +330,32 @@ 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) +{ + ERRP_GUARD(); + 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; @@ -541,13 +549,13 @@ static void dump_begin(DumpState *s, Error **errp) return; } - if (dump_is_64bit(s)) { - /* write PT_NOTE to vmcore */ - write_elf64_note(s, errp); - if (*errp) { - return; - } + /* write PT_NOTE to vmcore */ + write_elf_phdr_note(s, errp); + if (*errp) { + return; + } + if (dump_is_64bit(s)) { /* write all PT_LOAD to vmcore */ write_elf_loads(s, errp); if (*errp) { @@ -568,12 +576,6 @@ static void dump_begin(DumpState *s, Error **errp) return; } } else { - /* write PT_NOTE to vmcore */ - write_elf32_note(s, errp); - if (*errp) { - return; - } - /* write all PT_LOAD to vmcore */ write_elf_loads(s, errp); if (*errp) { From patchwork Wed Mar 30 12:36:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06C49C433F5 for ; Wed, 30 Mar 2022 12:52:42 +0000 (UTC) Received: from localhost ([::1]:60840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXoX-0000oZ-43 for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:52:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZW-0006Xo-Dp for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:10370) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZU-0003Op-Hu for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UBQi5q026876; Wed, 30 Mar 2022 12:37:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=3DQXpi3vjEu9RFmblTblEcw2UqB1K4JNcjBtW1w7GVw=; b=hg7NjhLTO+7x4AW+lRhfJGLAqxmsjLNAYIQj9yVoRSgPuRHN31V2/BVpN8iKSCkUZAgu fVvTMj96ObTqFY7lpGpwt7lGxfEBJYfIeM6Mk223QQm2fKGzNNFOWvJDYKTcMbJ7z4Gm PfIN/N4aDhqa5vN6Gub1R4J5R4kctbgbKGg5JdsAv59XtW+wnLmSqtgV7/t+vhG6k5jy M4PoN2wQCvi392cjMoI3/kvbr6pdsjd5LS5D+mNR5uZWShAMwrop3fvjget69CQgvZye 1Lzyo/sNn2P9vQCuUQkxndYSe0sWkfARo4qWfmi9GlIs68QgHZQ4Pii/C3UkxAIlNyvu qw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f4pbchfw1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:06 +0000 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UCBh3K002377; Wed, 30 Mar 2022 12:37:06 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f4pbchfv8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:05 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCMPwe030948; Wed, 30 Mar 2022 12:37:03 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04ams.nl.ibm.com with ESMTP id 3f1tf90js8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:03 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCb1VW47972700 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:37:01 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2353E5204F; Wed, 30 Mar 2022 12:37:01 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 9B02C5204E; Wed, 30 Mar 2022 12:37:00 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 8/9] dump: Cleanup dump_begin write functions Date: Wed, 30 Mar 2022 12:36:02 +0000 Message-Id: <20220330123603.107120-9-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: MKT_8cWgwe9kyKg2yTN197nCaSabt_mZ X-Proofpoint-ORIG-GUID: v9_rF_2ih-dEFazPE0gJ7K2nYJF3A9G9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_04,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=954 bulkscore=0 phishscore=0 adultscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" There's no need to have a gigantic if in there let's move the elf 32/64 bit logic into the section, segment or note code. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson Reviewed-by: Marc-André Lureau --- dump/dump.c | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 365798f5a1..92acd9eb5c 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -555,46 +555,26 @@ static void dump_begin(DumpState *s, Error **errp) return; } - if (dump_is_64bit(s)) { - /* write all PT_LOAD to vmcore */ - write_elf_loads(s, errp); + /* write all PT_LOAD to vmcore */ + write_elf_loads(s, errp); + if (*errp) { + return; + } + + /* write section to vmcore */ + if (s->shdr_num) { + write_elf_section(s, 1, errp); if (*errp) { return; } + } - /* write section to vmcore */ - if (s->shdr_num) { - write_elf_section(s, 1, errp); - if (*errp) { - return; - } - } - + if (dump_is_64bit(s)) { /* write notes to vmcore */ write_elf64_notes(fd_write_vmcore, s, errp); - if (*errp) { - return; - } } else { - /* write all PT_LOAD to vmcore */ - write_elf_loads(s, errp); - if (*errp) { - return; - } - - /* write section to vmcore */ - if (s->shdr_num) { - write_elf_section(s, 0, errp); - if (*errp) { - return; - } - } - /* write notes to vmcore */ write_elf32_notes(fd_write_vmcore, s, errp); - if (*errp) { - return; - } } } From patchwork Wed Mar 30 12:36:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12795765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B89DC433EF for ; Wed, 30 Mar 2022 12:42:18 +0000 (UTC) Received: from localhost ([::1]:40404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZXeT-0002Sq-UT for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 08:42:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZW-0006Xn-70 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:31456 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXZU-0003Ol-Cf for qemu-devel@nongnu.org; Wed, 30 Mar 2022 08:37:09 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UAgOM1002845; Wed, 30 Mar 2022 12:37:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=DNx5PAzIS1qHZF/9OjgwYDkg0yhzscgqZ0MpqCjbyd0=; b=MiL1L/dkT+HmLVi9x53d1hH6sg6dH60UMQIr3S9HcCZRvgqQzI/HktB82EgDD7SuO9ek CA4TaNhlq5rlaGOIpuHMSX1QNHLo2l1HuWU1KSsQKOUxk+EkwpuzU6hysze27wZOfnmw +eNh9j7lZRJG/B4W3tcS1HpMgAdsmUBUA5tI87eGKVG5Ou20Rc2x2uKcxfcWLZxRH910 VE6Ld8mYUwgfutHJ9/FVeuWNRP40K6TUJ6bHNG/7S/RfG8TyVXAWpRBjizgMO/W7FsTp d56dg0erU+FS9UcpX+0jwMPpWEqiIhje/CYVNBi9H7aA0KfnQVlcooxa2LMM3cBvSLx6 nA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3f4npk2fhk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:06 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UCVY6Q006867; Wed, 30 Mar 2022 12:37:06 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 3f4npk2fgy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:05 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCNXwD027057; Wed, 30 Mar 2022 12:37:04 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 3f3rs3kjc3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:37:04 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCb1h747972704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:37:01 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C7AF75204E; Wed, 30 Mar 2022 12:37:01 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 3F7775204F; Wed, 30 Mar 2022 12:37:01 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v3 9/9] dump: Consolidate elf note function Date: Wed, 30 Mar 2022 12:36:03 +0000 Message-Id: <20220330123603.107120-10-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220330123603.107120-1-frankja@linux.ibm.com> References: <20220330123603.107120-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: zzw7LUETBlkoAUSYm-IOpfm-kvoAdX9A X-Proofpoint-ORIG-GUID: tRcCUb53Etik9dIAf4N9QgdOm-TF0X1q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_04,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 adultscore=0 bulkscore=0 clxscore=1015 spamscore=0 impostorscore=0 mlxlogscore=738 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300063 Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Just like with the other write functions let's move the 32/64 bit elf handling to a function to improve readability. Signed-off-by: Janosch Frank Reviewed-by: Marc-André Lureau --- dump/dump.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 92acd9eb5c..4af71de9b1 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -510,6 +510,15 @@ static void write_elf_loads(DumpState *s, Error **errp) } } +static void write_elf_notes(DumpState *s, Error **errp) +{ + if (dump_is_64bit(s)) { + write_elf64_notes(fd_write_vmcore, s, errp); + } else { + write_elf32_notes(fd_write_vmcore, s, errp); + } +} + /* write elf header, PT_NOTE and elf note to vmcore. */ static void dump_begin(DumpState *s, Error **errp) { @@ -569,13 +578,8 @@ static void dump_begin(DumpState *s, Error **errp) } } - if (dump_is_64bit(s)) { - /* write notes to vmcore */ - write_elf64_notes(fd_write_vmcore, s, errp); - } else { - /* write notes to vmcore */ - write_elf32_notes(fd_write_vmcore, s, errp); - } + /* write notes to vmcore */ + write_elf_notes(s, errp); } static int get_next_block(DumpState *s, GuestPhysBlock *block)