From nobody Sun Feb 8 12:28:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649325011178897.9115772396716; Thu, 7 Apr 2022 02:50:11 -0700 (PDT) Received: from localhost ([::1]:58324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncOmH-0005Ga-Rd for importer@patchew.org; Thu, 07 Apr 2022 05:50:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncOkq-0004VS-3y for qemu-devel@nongnu.org; Thu, 07 Apr 2022 05:48:40 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncOko-0002js-4H for qemu-devel@nongnu.org; Thu, 07 Apr 2022 05:48:39 -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 2377o76V019758; Thu, 7 Apr 2022 09:48:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f9uwtt8vx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Apr 2022 09:48:35 +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 2379d7Ci004817; Thu, 7 Apr 2022 09:48:34 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 3f9uwtt8vk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Apr 2022 09:48:34 +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 2379lbSh010784; Thu, 7 Apr 2022 09:48:32 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 3f6e491jjy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Apr 2022 09:48:32 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2379mUNQ25821482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Apr 2022 09:48:30 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8485611C04A; Thu, 7 Apr 2022 09:48:30 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 070F711C052; Thu, 7 Apr 2022 09:48:30 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 7 Apr 2022 09:48:29 +0000 (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=yq1+2fI4oLtAiDsL7FDbEmYV14IgDPF68uKRwduD6UY=; b=gyRVZxQPoCaFAuij0n4wCFYbbTi6HfU4sGlEVSLJhAuukKewGCxqYVwGKEEh2hA8jq5X M/PNFAQnylCguVPyYjrbMvsvzjC+nwEwt3WzoYcg2jqSTHAu77LE4eXfIclE9fDfJrAs 1pMlTEahzr3CC8EnEJwCXLrvMU+bm7eu8GsGJseW5XkyZnpIBbh2T/D7TGVyyaNOiMvh OKf60puHL6In71XWv7ol1PfyGydziBLazZ+6yel+KdcTT3vjTuuW9TaSWQv7wwTHd3dN gGiwJwciErmLRF28koAoOln0YbRBSWg4RDavoxyfTet4cREYRZZqoFimPCd52XeaFyKl Hw== From: Janosch Frank To: qemu-devel@nongnu.org Subject: [PATCH v4] dump: Remove the sh_info variable Date: Thu, 7 Apr 2022 09:48:24 +0000 Message-Id: <20220407094824.5074-1-frankja@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: pwxRTkVLYwMg_GUtiFog5Z4HKXeIW4zJ X-Proofpoint-GUID: mp2Q2zT1vWntKq3Oj6Lg91PCKjAn7hGh 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-04-06_13,2022-04-06_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204070048 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H3=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: pbonzini@redhat.com, richard.henderson@linaro.org, marcandre.lureau@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649325013080100001 Content-Type: text/plain; charset="utf-8" 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 >=3D PN_XNUM. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson --- A question out of general curiosity: Is PN_XNUM a real concern anyway? Are architectures using >65k segments in real life? * Uses MIN() * Added explanation for the PN_XNUM usage --- dump/dump.c | 44 +++++++++++++++++++++++-------------------- include/sysemu/dump.h | 3 +-- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 58c4923fce..56cd1b2bb8 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -124,6 +124,12 @@ static int fd_write_vmcore(const void *buf, size_t siz= e, void *opaque) =20 static void write_elf64_header(DumpState *s, Error **errp) { + /* + * phnum in the elf header is 16 bit, if we have more segments we + * set phnum to PN_XNUM and write the real number of segments to a + * special section. + */ + uint16_t phnum =3D MIN(s->phdr_num, PN_XNUM); Elf64_Ehdr elf_header; int ret; =20 @@ -138,9 +144,9 @@ static void write_elf64_header(DumpState *s, Error **er= rp) elf_header.e_ehsize =3D cpu_to_dump16(s, sizeof(elf_header)); elf_header.e_phoff =3D cpu_to_dump64(s, sizeof(Elf64_Ehdr)); elf_header.e_phentsize =3D cpu_to_dump16(s, sizeof(Elf64_Phdr)); - elf_header.e_phnum =3D cpu_to_dump16(s, s->phdr_num); + elf_header.e_phnum =3D cpu_to_dump16(s, phnum); if (s->have_section) { - uint64_t shoff =3D sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->sh= _info; + uint64_t shoff =3D sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->ph= dr_num; =20 elf_header.e_shoff =3D cpu_to_dump64(s, shoff); elf_header.e_shentsize =3D cpu_to_dump16(s, sizeof(Elf64_Shdr)); @@ -155,6 +161,12 @@ static void write_elf64_header(DumpState *s, Error **e= rrp) =20 static void write_elf32_header(DumpState *s, Error **errp) { + /* + * phnum in the elf header is 16 bit, if we have more segments we + * set phnum to PN_XNUM and write the real number of segments to a + * special section. + */ + uint16_t phnum =3D MIN(s->phdr_num, PN_XNUM); Elf32_Ehdr elf_header; int ret; =20 @@ -169,9 +181,9 @@ static void write_elf32_header(DumpState *s, Error **er= rp) elf_header.e_ehsize =3D cpu_to_dump16(s, sizeof(elf_header)); elf_header.e_phoff =3D cpu_to_dump32(s, sizeof(Elf32_Ehdr)); elf_header.e_phentsize =3D cpu_to_dump16(s, sizeof(Elf32_Phdr)); - elf_header.e_phnum =3D cpu_to_dump16(s, s->phdr_num); + elf_header.e_phnum =3D cpu_to_dump16(s, phnum); if (s->have_section) { - uint32_t shoff =3D sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->sh= _info; + uint32_t shoff =3D sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->ph= dr_num; =20 elf_header.e_shoff =3D cpu_to_dump32(s, shoff); elf_header.e_shentsize =3D cpu_to_dump16(s, sizeof(Elf32_Shdr)); @@ -358,12 +370,12 @@ static void write_elf_section(DumpState *s, int type,= Error **errp) if (type =3D=3D 0) { shdr_size =3D sizeof(Elf32_Shdr); memset(&shdr32, 0, shdr_size); - shdr32.sh_info =3D cpu_to_dump32(s, s->sh_info); + shdr32.sh_info =3D cpu_to_dump32(s, s->phdr_num); shdr =3D &shdr32; } else { shdr_size =3D sizeof(Elf64_Shdr); memset(&shdr64, 0, shdr_size); - shdr64.sh_info =3D cpu_to_dump32(s, s->sh_info); + shdr64.sh_info =3D cpu_to_dump32(s, s->phdr_num); shdr =3D &shdr64; } =20 @@ -478,13 +490,6 @@ static void write_elf_loads(DumpState *s, Error **errp) hwaddr offset, filesz; MemoryMapping *memory_mapping; uint32_t phdr_index =3D 1; - uint32_t max_index; - - if (s->have_section) { - max_index =3D s->sh_info; - } else { - max_index =3D s->phdr_num; - } =20 QTAILQ_FOREACH(memory_mapping, &s->list.head, next) { get_offset_range(memory_mapping->phys_addr, @@ -502,7 +507,7 @@ static void write_elf_loads(DumpState *s, Error **errp) return; } =20 - if (phdr_index >=3D max_index) { + if (phdr_index >=3D s->phdr_num) { break; } } @@ -1801,22 +1806,21 @@ static void dump_init(DumpState *s, int fd, bool ha= s_format, s->phdr_num +=3D s->list.num; s->have_section =3D false; } else { + /* sh_info of section 0 holds the real number of phdrs */ s->have_section =3D true; - s->phdr_num =3D PN_XNUM; - s->sh_info =3D 1; /* PT_NOTE */ =20 /* the type of shdr->sh_info is uint32_t, so we should avoid overf= low */ if (s->list.num <=3D UINT32_MAX - 1) { - s->sh_info +=3D s->list.num; + s->phdr_num +=3D s->list.num; } else { - s->sh_info =3D UINT32_MAX; + s->phdr_num =3D UINT32_MAX; } } =20 if (s->dump_info.d_class =3D=3D ELFCLASS64) { if (s->have_section) { s->memory_offset =3D 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 =3D sizeof(Elf64_Ehdr) + @@ -1825,7 +1829,7 @@ static void dump_init(DumpState *s, int fd, bool has_= format, } else { if (s->have_section) { s->memory_offset =3D 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 =3D 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; --=20 2.32.0