From patchwork Thu Mar 10 11:16:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12776176 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 CFBF9C433F5 for ; Thu, 10 Mar 2022 11:21:20 +0000 (UTC) Received: from localhost ([::1]:44264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSGrA-0004Iy-0K for qemu-devel@archiver.kernel.org; Thu, 10 Mar 2022 06:21:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGmd-0004Gf-P3 for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:40 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:21676) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGma-0005ss-EM for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:39 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22A9rTkM020348 for ; Thu, 10 Mar 2022 11:16:35 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=U9JnNx1uTnbFfa6MKCnSb9q4Qkq9Crn3IUq0j/zg4k8=; b=C7wH798pPQHw+xxUiypfJ6dpiqsbY/RKKqC/L8k/xUFwtUKspPOhjBAYhtf5yPDlbaFK Lak1OvDlOLi6IhRYaraNpskjOgv1hTJ7dGEy40vlNnK40q1HxyPhGsfnI0/5yRw38GP3 iX2tq81SAfyqXVlup6lieuAPtYsh90IK9RlgK6EJjpwM7k8ozbtLB8QnFTbZFHcwqFKK Oqk/KTELo3Agfeg3QdAcf83iBwTqAj12GFRmEgQ0rt3bDu4ULqgowFoBltFIJ6eEOxiK L1DIUwtufuVbfSYpkrR0Jfv+Hp7erql27sfWXkDLfOqLtxQ2Yn1vzJlQ1JOD/p4MRMF4 3A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3eqf3n1jkx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 10 Mar 2022 11:16:35 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22AAh9uu015973 for ; Thu, 10 Mar 2022 11:16:34 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3eqf3n1jkb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:34 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22ABD9kQ029529; Thu, 10 Mar 2022 11:16:32 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma04fra.de.ibm.com with ESMTP id 3ep8c3v5dw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:32 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22ABGUVQ44892670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Mar 2022 11:16:30 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B9FA74C04E; Thu, 10 Mar 2022 11:16:29 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3CE7F4C044; Thu, 10 Mar 2022 11:16:29 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 10 Mar 2022 11:16:29 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH 1/5] dump: Allocate header Date: Thu, 10 Mar 2022 11:16:04 +0000 Message-Id: <20220310111608.3362-2-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220310111608.3362-1-frankja@linux.ibm.com> References: <20220310111608.3362-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: gslLjjUCrDBvCBRAYciMIhPF9ng3yYuj X-Proofpoint-GUID: 1pNZcH3hNWjcmyjB9DQ1Jo2di6jMAfy8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-10_03,2022-03-09_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 phishscore=0 clxscore=1015 spamscore=0 mlxscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203100059 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, mhartmay@linux.ibm.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- dump/dump.c | 115 ++++++++++++++++++++++-------------------- include/sysemu/dump.h | 1 + 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index ae8ec527de..88343d7486 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -99,6 +99,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) { @@ -127,63 +128,47 @@ 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) { - uint16_t phnum = s->phdr_num >= PN_XNUM ? PN_XNUM : s->phdr_num; - Elf64_Ehdr elf_header; - int ret; + 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, s->phdr_num); 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) { - uint16_t phnum = s->phdr_num >= PN_XNUM ? PN_XNUM : s->phdr_num; - Elf32_Ehdr elf_header; - int ret; + 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, s->phdr_num); 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); } } @@ -524,6 +509,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) { @@ -553,12 +558,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; } @@ -1683,6 +1687,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. diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index ffc2ea1072..9c4a83156b 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -172,6 +172,7 @@ typedef struct DumpState { int64_t begin; int64_t length; + 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 */ From patchwork Thu Mar 10 11:16:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12776174 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 9A30BC433F5 for ; Thu, 10 Mar 2022 11:19:54 +0000 (UTC) Received: from localhost ([::1]:41176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSGpl-0002EC-L0 for qemu-devel@archiver.kernel.org; Thu, 10 Mar 2022 06:19:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGmc-0004DJ-2z for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:38 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:8572 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 1nSGma-0005su-4v for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:37 -0500 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 22A9WGZK026557 for ; Thu, 10 Mar 2022 11:16:35 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=SCPx5HvDJd++c1/MVf9EaagbroBju7wFNfLCFRCjm0c=; b=r15w3xHBnFeUef1x7DSwFO5Xx75HDMHZu4mlupdFAmUZAc/Qu9x5mmtOCG2vDH9uzvhq XSAesknYk1FLid3293WRMVTUsEA3uDFloTvpc152HtjEm6mOZPfHgUSbYkBBJOw/hrHG 8xHN4Fo7D4FiOWAQ49uhr/fb13zS8WJ/IMcMd1Qz2lS6FwK5gF4/ZzWr15MnlEKU/1zY lcZrBsgmnKYz0djVwn1yGE39OFLrt2Kee1SDx8QOkZb89GmoAB2Yg6IvfoYU6w3K614q Z3iT6Nm676Ih3unMrrzSd8o3OAGqL36ynH8/ew2+LOFpUHqiooVkfM0V0zxxXg8paLCx nQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3eq7yr1qp0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 10 Mar 2022 11:16:34 +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 22A9pNMa018954 for ; Thu, 10 Mar 2022 11:16:34 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 3eq7yr1qnj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:34 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22ABDoAh009846; Thu, 10 Mar 2022 11:16:32 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma05fra.de.ibm.com with ESMTP id 3epysw9hne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:32 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22AB5HW946072194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Mar 2022 11:05:17 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 68C8C4C044; Thu, 10 Mar 2022 11:16:30 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E01A24C04A; Thu, 10 Mar 2022 11:16:29 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 10 Mar 2022 11:16:29 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH 2/5] dump: Split write of section headers and data and add a prepare step Date: Thu, 10 Mar 2022 11:16:05 +0000 Message-Id: <20220310111608.3362-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220310111608.3362-1-frankja@linux.ibm.com> References: <20220310111608.3362-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KEGgR9mNJR6iAYmgxwtC8bRP4j6SfSpz X-Proofpoint-ORIG-GUID: 3yY1E13u0tvHwfrZb_9fP-8M9MGjsQFe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-10_03,2022-03-09_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 clxscore=1015 adultscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203100059 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_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, mhartmay@linux.ibm.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- dump/dump.c | 112 ++++++++++++++++++++++++++++++++---------- include/sysemu/dump.h | 4 ++ 2 files changed, 90 insertions(+), 26 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 88343d7486..e4198e8f3e 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -341,30 +341,72 @@ 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; + Elf32_Shdr *shdr32 = buff; + 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; + if (dump_is_64bit(s)) { + 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; + 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"); } } @@ -561,12 +603,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) { @@ -579,14 +631,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); } @@ -643,6 +687,19 @@ static void dump_iterate(DumpState *s, Error **errp) } while (!get_next_block(s, block)); } +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(); @@ -653,6 +710,9 @@ static void create_vmcore(DumpState *s, Error **errp) } dump_iterate(s, errp); + + /* Write section data after memory has been dumped */ + dump_end(s, errp); } static int write_start_flat_header(int fd) diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 9c4a83156b..4c5a593b81 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -173,6 +173,10 @@ typedef struct DumpState { int64_t length; 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 */ From patchwork Thu Mar 10 11:16:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12776162 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 AA5B6C433F5 for ; Thu, 10 Mar 2022 11:18:27 +0000 (UTC) Received: from localhost ([::1]:35708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSGoM-00070Z-Px for qemu-devel@archiver.kernel.org; Thu, 10 Mar 2022 06:18:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGmd-0004Gh-Rp for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:40 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:32556) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGmc-0005t8-5Z for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:39 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22AB6UEK030195 for ; Thu, 10 Mar 2022 11:16:37 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=kOHEyNfe+Lk07VzkI2et3Ng3Woccm+KKZLNymM5uzJU=; b=mRZkkEytNaYVBKmrrxZ7TSBHJKnpKiZZ22six/IX/ixghOEmiyLn8nR0QZE0r94Hpdsn Y8FOZNaQubXlq7jGrPW2F9uQzNkqXOQDdr8Vfq8y61odbXVn/b7j6i5a7jvKEVxcVd6y BePMiW9hPH1faBvtv7nMeTwXVA2eYddIy93G6vgrAyO0j3ynpCx4W/vPtRqLtqxnKYrt 9Y7MIbm5bNvn0jaj/Wlp4Kib0tjJm1AoXlO69/MW+LXZMIaRsNsjkhaRzry1HcoBOMjB N+xt+kjCsrjeM2M5vzKJUr6dqzVfNE4OxzM2wE1T2upCEU3yxhxPDnWycJ69emz7ZELf og== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3epwy3nb07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 10 Mar 2022 11:16:36 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22ABArLw031161 for ; Thu, 10 Mar 2022 11:16:36 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 3epwy3nayk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:36 +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 22ABC1aK024037; Thu, 10 Mar 2022 11:16:33 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 3enqgnq1px-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:33 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22ABGVoJ54264102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Mar 2022 11:16:31 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 17DD74C046; Thu, 10 Mar 2022 11:16:31 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8EAE54C044; Thu, 10 Mar 2022 11:16:30 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 10 Mar 2022 11:16:30 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH 3/5] dump: Reorder struct DumpState Date: Thu, 10 Mar 2022 11:16:06 +0000 Message-Id: <20220310111608.3362-4-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220310111608.3362-1-frankja@linux.ibm.com> References: <20220310111608.3362-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ux5SPgMaOZDu8JxNn14j9kknVw6vq3dB X-Proofpoint-ORIG-GUID: mbMv5Q1KwiZiHqhB7B36xjRbtcuObNKd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-10_03,2022-03-09_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 clxscore=1015 malwarescore=0 spamscore=0 suspectscore=0 phishscore=0 mlxlogscore=758 lowpriorityscore=0 adultscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203100059 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, mhartmay@linux.ibm.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Let's move ELF related members into one block and guest memory related ones into another to improve readability. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson --- include/sysemu/dump.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 4c5a593b81..186348a972 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -154,24 +154,28 @@ 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; + /* Guest memory related data */ GuestPhysBlock *next_block; ram_addr_t start; bool has_filter; int64_t begin; int64_t length; + /* 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; From patchwork Thu Mar 10 11:16:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12776182 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 BB284C433EF for ; Thu, 10 Mar 2022 11:31:47 +0000 (UTC) Received: from localhost ([::1]:37436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSH1G-0002DQ-Tt for qemu-devel@archiver.kernel.org; Thu, 10 Mar 2022 06:31:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGmd-0004Ge-OL for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:40 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42518 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 1nSGmb-0005t4-6X for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:39 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22ABEWcL025811 for ; Thu, 10 Mar 2022 11:16:36 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=qVu2Erh61J7rw6GKWhuxsf80nSZOEzeoUcw18mQnUqE=; b=VFkqqa3/zEB1B3XN2/LBfGUKZsN2LPRcwT2QYIw6eWcCGWg5EHp1C+TfRU/BRiI+MTxZ dCXy8CXWNWOvN/oxuaugwQrIPZDsFVVMgwDj/mwlXz2qXUKUJ1Sbei5hyP22gsQHkRjp KSyz82DeCc2feGRk3P12MManUeh2vJ3lLAvVLjhn95aA4pfeOVfEY5s5emZB8ogWG3xg nOe/3GUQWgcHRrNEn1K/1+Gt1h3m4Y44sECW4D7+f04zmDyxne+qCzw+1VPLuGFLuON2 iU0Tyh5jee0BDxxVcgSOzy/8QWeXdLUevTHTvgGflfkfmg0Epem6IglIhrg8KFtEjN7f Aw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3eqg9dg1b2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 10 Mar 2022 11:16:36 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22ABEhGr026474 for ; Thu, 10 Mar 2022 11:16:35 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 3eqg9dg1ap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:35 +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 22ABC0vS024030; Thu, 10 Mar 2022 11:16:34 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 3enqgnq1py-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:33 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22ABGVgo52691208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Mar 2022 11:16:31 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BCCDA4C040; Thu, 10 Mar 2022 11:16:31 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E7164C046; Thu, 10 Mar 2022 11:16:31 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 10 Mar 2022 11:16:31 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH 4/5] dump/dump: Add section string table support Date: Thu, 10 Mar 2022 11:16:07 +0000 Message-Id: <20220310111608.3362-5-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220310111608.3362-1-frankja@linux.ibm.com> References: <20220310111608.3362-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: m9TgBqwHimZSZgQkXMBlGzMlOEiU5UnD X-Proofpoint-ORIG-GUID: Yj3PkZ5mKYp8Cj0E-D4Gxci2NpRL9xt7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-10_03,2022-03-09_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 clxscore=1015 adultscore=0 spamscore=0 impostorscore=0 bulkscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203100059 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_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, mhartmay@linux.ibm.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Time to add a bit more descriptiveness to the dumps. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson --- dump/dump.c | 106 ++++++++++++++++++++++++++++++++++++------ include/sysemu/dump.h | 1 + 2 files changed, 94 insertions(+), 13 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index e4198e8f3e..7b3fd6a065 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -100,6 +100,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) { @@ -357,14 +358,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 ; @@ -375,6 +409,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) @@ -403,11 +453,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) @@ -595,6 +652,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. @@ -709,6 +769,7 @@ static void create_vmcore(DumpState *s, Error **errp) return; } + /* Iterate over memory and dump it to file */ dump_iterate(s, errp); /* Write section data after memory has been dumped */ @@ -1704,6 +1765,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); @@ -1864,19 +1932,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: diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 186348a972..9a000e7483 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -180,6 +180,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 */ From patchwork Thu Mar 10 11:16:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12776179 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 92C1FC433EF for ; Thu, 10 Mar 2022 11:24:33 +0000 (UTC) Received: from localhost ([::1]:52838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSGuG-0001hS-Lc for qemu-devel@archiver.kernel.org; Thu, 10 Mar 2022 06:24:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGmf-0004JP-6M for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:41 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGmd-0005tU-7E for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:16:40 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22A9rS2H020319 for ; Thu, 10 Mar 2022 11:16:38 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=dNAfhfQAz+P+bmZW5Pz++s5XhKYotLEG36PfSjZOgDU=; b=n7vV01sWo0UTwdcojnoHdDo/fP0Jo4pdnncAWgR+kHYw4uhR8W4ujJhQynJA8T8oiRRT 7xR9Luv44Vh7x3wEY8D3VRuBFzhYbkinabSBgWQtxPYe++aTHSOtjx5vC9CN5HKXAHzd xIw0XOrV/Th1dT7AlWlVD+flU6JfbRn28LrHT65yBpkvTDUjQbcTp8IKcviMUZY4JKv+ AE4Ngvvgw+37pSeap+AC/qmLQZSv092N78qrryiviDb7cgKA5frAmirfxEqyxyI7kNe2 Uluyx8QljbE4VUCddH5a6X9E5tFsqK10XemjW1fIhOBjr72770Z72QtVQu+X9SPEHmLp fA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3eqf3n1jmw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 10 Mar 2022 11:16:37 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22AB0mtf010869 for ; Thu, 10 Mar 2022 11:16:37 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 3eqf3n1jm3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:37 +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 22ABF4Uj014763; Thu, 10 Mar 2022 11:16:34 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma01fra.de.ibm.com with ESMTP id 3ekyg8jmjc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Mar 2022 11:16:34 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22ABGWIW59113800 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Mar 2022 11:16:32 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B6254C044; Thu, 10 Mar 2022 11:16:32 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E2E944C040; Thu, 10 Mar 2022 11:16:31 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 10 Mar 2022 11:16:31 +0000 (GMT) From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH 5/5] dump/dump: Add arch section support Date: Thu, 10 Mar 2022 11:16:08 +0000 Message-Id: <20220310111608.3362-6-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220310111608.3362-1-frankja@linux.ibm.com> References: <20220310111608.3362-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: zGdyiKhcP91vmzK7my78W0fMRtgpNgiX X-Proofpoint-GUID: Tv_e_x1TiFFBU7LQiqAbDilhlvoC1RyE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-10_03,2022-03-09_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 phishscore=0 clxscore=1015 spamscore=0 mlxscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203100059 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, mhartmay@linux.ibm.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add hooks which architectures can use to add arbitrary data to custom sections. Signed-off-by: Janosch Frank --- dump/dump.c | 21 ++++++++++++++++++--- include/sysemu/dump-arch.h | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 7b3fd6a065..a9d9ea514d 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -398,6 +398,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); @@ -415,6 +416,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(). @@ -565,14 +569,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); @@ -685,8 +698,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; } @@ -755,6 +768,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); @@ -1939,6 +1953,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; diff --git a/include/sysemu/dump-arch.h b/include/sysemu/dump-arch.h index e25b02e990..de77908424 100644 --- a/include/sysemu/dump-arch.h +++ b/include/sysemu/dump-arch.h @@ -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