From nobody Mon Mar 2 08:45:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1772122351; cv=none; d=zohomail.com; s=zohoarc; b=D3ZoHy3C8WPHLSrbQIL7TsUTlmbbjbMIMX/y+JPu0BUOxj7eocv08cDTEgTTB/MPyVyLFeOpEcFWspFl1K2nvjP0tVuGtvWSwq4YNqa9WeY43OLUSXUzCshlL/Sl0n2+0IFIk5OodTC4YjDdcV+TmDsyQBxkrguTA2XSWWZPOqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772122351; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6S/q21pFn1OT/H9EqBcYzae2OwIFRQGq7oFgZeO8mDM=; b=TsfzAsltod6qN0NOHnynlRx5YMojy3ID2pIwZzmFkKWr2kXnqbuRKCh1Sy/nla7Gms53zJJPc+9K/W42Jx1HtURcOW1HC1sUC+hn9wqWDrhq2fQRIuus93NVcMeL1b03c8N9Wicju60DBoe4KTewhQgond1Y+3+15MdFeAJOSiY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772122351309241.61547767263278; Thu, 26 Feb 2026 08:12:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvdy4-0001aB-Lb; Thu, 26 Feb 2026 11:12:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvdy1-0001ZF-JA for qemu-devel@nongnu.org; Thu, 26 Feb 2026 11:11:58 -0500 Received: from qs-2005g-snip4-2.eps.apple.com ([57.103.86.193] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvdxz-0005fD-OA for qemu-devel@nongnu.org; Thu, 26 Feb 2026 11:11:57 -0500 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-0 (Postfix) with ESMTPS id 56145180015C; Thu, 26 Feb 2026 16:11:50 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-0 (Postfix) with ESMTPSA id 097CB1874A07; Thu, 26 Feb 2026 16:11:48 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1772122312; x=1774714312; bh=6S/q21pFn1OT/H9EqBcYzae2OwIFRQGq7oFgZeO8mDM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=G+xP7o5oaS4qPyfJS6AuGlAl73GhKB3Llfkp0J9V0UP5MDfojfiZX77iOxZ555dl13fwR+2R6nerfPoV1y6OPkLGMZfrqQ3iETpptzXO/cWbDRs/6Wv++YuVzLTUK7MhqEAxSB1szUJsewJcBTM8MsvFHMRhgXqF5HqECeLFlLZLE5u1sdt9XXtxbSW0njUDTCotbgRdRmCgtxb98OG3pYAHxNByRq5YbrcPoMMSQOO5f+YgHCthU6OKFDx4P8nW1o6M9gZpxEH3nSVeRBQdeiwE+Ef7qOapskSZVBreCM1EW3RtA4ewilkNcl9MXxaVJxkKQiQRZDhEs9XwmDIIfw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Mohamed Mediouni Subject: [PATCH] Revert "elf-ops.h: Map into memory the ELF to load" Date: Thu, 26 Feb 2026 17:11:46 +0100 Message-ID: <20260226161146.68876-1-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=b6K/I9Gx c=1 sm=1 tr=0 ts=69a070c6 cx=c_apl:c_apl_out:c_pps a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=c_HyBtZksB4fQN2gfusA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjI2MDE0NSBTYWx0ZWRfXzajmgqgc9gn6 3nfu7bLQelLUHqO2/XJwUSM8mSi+TBOf960oziwJMU2c1xwShiOzbb3bpIsIOatX+0yZmZU2hUx EIm6VBaY0YZcrcEerX3xRyV+6dcq99AhaO3jvAJ/CTQg73c9sUQKFvKS4/pAbJKML/syM4Lyho8 Nwu/itI4q8XPPvZ3+0wBl81/Pk23VjQipgIfK2HtmNcWC6XbfxJbwnu8swSDB92YIvlmACQaeVr YviICU+8pKs4Xfp6iUX0ReKT0vilk3eKg4aXjaJyIjLxDOu3Smq0R23cCBlGUTKGcLK50nPY55a bnPtqAyTCds7aePx4Yt9bPsZ8+TsI4RSDH6NjuenKW9Gf84Ii+JK2/x2wMi4sU= X-Proofpoint-GUID: WRAdG0wSoPuTRCd6SgM7eweGGcE-Nl8j X-Proofpoint-ORIG-GUID: WRAdG0wSoPuTRCd6SgM7eweGGcE-Nl8j X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-26_01,2026-02-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 adultscore=0 clxscore=1030 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602260145 X-JNJ: AAAAAAABGi2J0b637XDYQfOx5VmKkNoV1JPUiB4HHKbjC615WKXSPH3PyvOjSBw1bEqqceKe2/OdThVoKEPohxA4YfmFS1TGb5DtRB0MXVEMS64Li7G5oTraGi8BzNqyjAHXMk4akGhTieriJ3HlRU8YGfttluY0zbAgedNhjnu4zK5pFPJkRlQ3L46RFd7LgMlGSL2wDYrhcInUW+E2Q3mslvWq4L55PF8VcEboNh+7JpxyXEFzgIksrdaGCv/9H354bJsrWaVo3iJAxSq2DltemEO1n2Rg5ow9bJjGKLLmEgHrFDbK41wTF5nI2SFzX/4/GVBocJptkRyz3qtRS9iX27G4XsGd7pRyLscQ7JNcdVYlrJ7vyuj1K3aKz4R7UWQGyRilO8dNbfBh0CsdsNuekQrKWO2UQahELZrZMWIua6uqzlKhs8Bh01ezEkQYijHhixl5R/FedP4b4zE+SjoVHlZNttLqsdk+o8RHBoRbcg5AiWCAn1J24ydj9umHLWdhNJGVMyM5abY8t5Oh7ylt3qWxuynrs1Zr3HtOYNbHBAPyAEdbdljXz8w7+NDktmxH7aFhcCtYJELI40kqQgT4zsB1wbNH27WG8ZMiB7aj5JA= 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=57.103.86.193; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.306, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.668, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1772122355206158500 Content-Type: text/plain; charset="utf-8" This reverts commit 816b9fe450220e19acb91a0ce4a8ade7000648d1. Unfortunately, this optimisation breaks -kernel [x] on Windows hosts. Reverting this commit enabled proceeding with kvm-unit-tests testing. Signed-off-by: Mohamed Mediouni --- include/hw/elf_ops.h.inc | 71 +++++++++++++++------------------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/include/hw/elf_ops.h.inc b/include/hw/elf_ops.h.inc index 9c35d1b9da..bcf484b938 100644 --- a/include/hw/elf_ops.h.inc +++ b/include/hw/elf_ops.h.inc @@ -325,11 +325,9 @@ static ssize_t glue(load_elf, SZ)(const char *name, in= t fd, { struct elfhdr ehdr; struct elf_phdr *phdr =3D NULL, *ph; - int size, i; - ssize_t total_size; - elf_word mem_size, file_size, data_offset; + int size, i, total_size; + elf_word mem_size, file_size; uint64_t addr, low =3D (uint64_t)-1, high =3D 0; - GMappedFile *mapped_file =3D NULL; uint8_t *data =3D NULL; ssize_t ret =3D ELF_LOAD_FAILED; =20 @@ -409,32 +407,20 @@ static ssize_t glue(load_elf, SZ)(const char *name, i= nt fd, } } =20 - /* - * Since we want to be able to modify the mapped buffer, we set the - * 'writable' parameter to 'true'. Modifications to the buffer are not - * written back to the file. - */ - mapped_file =3D g_mapped_file_new_from_fd(fd, true, NULL); - if (!mapped_file) { - goto fail; - } - total_size =3D 0; for(i =3D 0; i < ehdr.e_phnum; i++) { ph =3D &phdr[i]; if (ph->p_type =3D=3D PT_LOAD) { mem_size =3D ph->p_memsz; /* Size of the ROM */ file_size =3D ph->p_filesz; /* Size of the allocated data */ - data_offset =3D ph->p_offset; /* Offset where the data is loca= ted */ - - if (file_size > 0) { - if (g_mapped_file_get_length(mapped_file) < - file_size + data_offset) { + data =3D g_malloc0(file_size); + if (ph->p_filesz > 0) { + if (lseek(fd, ph->p_offset, SEEK_SET) < 0) { + goto fail; + } + if (read(fd, data, file_size) !=3D file_size) { goto fail; } - - data =3D (uint8_t *)g_mapped_file_get_contents(mapped_file= ); - data +=3D data_offset; } =20 /* The ELF spec is somewhat vague about the purpose of the @@ -530,23 +516,22 @@ static ssize_t glue(load_elf, SZ)(const char *name, i= nt fd, *pentry =3D ehdr.e_entry - ph->p_vaddr + ph->p_paddr; } =20 - /* Some ELF files really do have segments of zero size; - * just ignore them rather than trying to create empty - * ROM blobs, because the zero-length blob can falsely - * trigger the overlapping-ROM-blobs check. - */ - if (mem_size !=3D 0) { + if (mem_size =3D=3D 0) { + /* Some ELF files really do have segments of zero size; + * just ignore them rather than trying to create empty + * ROM blobs, because the zero-length blob can falsely + * trigger the overlapping-ROM-blobs check. + */ + g_free(data); + } else { if (load_rom) { g_autofree char *label =3D g_strdup_printf("%s ELF program header segment %d", name, i); =20 - /* - * rom_add_elf_program() takes its own reference to - * 'mapped_file'. - */ - rom_add_elf_program(label, mapped_file, data, file_siz= e, - mem_size, addr, as); + /* rom_add_elf_program() seize the ownership of 'data'= */ + rom_add_elf_program(label, NULL, data, file_size, mem_= size, + addr, as); } else { MemTxResult res; =20 @@ -584,16 +569,14 @@ static ssize_t glue(load_elf, SZ)(const char *name, i= nt fd, struct elf_note *nhdr =3D NULL; =20 file_size =3D ph->p_filesz; /* Size of the range of ELF notes = */ - data_offset =3D ph->p_offset; /* Offset where the notes are lo= cated */ - - if (file_size > 0) { - if (g_mapped_file_get_length(mapped_file) < - file_size + data_offset) { + data =3D g_malloc0(file_size); + if (ph->p_filesz > 0) { + if (lseek(fd, ph->p_offset, SEEK_SET) < 0) { + goto fail; + } + if (read(fd, data, file_size) !=3D file_size) { goto fail; } - - data =3D (uint8_t *)g_mapped_file_get_contents(mapped_file= ); - data +=3D data_offset; } =20 /* @@ -607,6 +590,7 @@ static ssize_t glue(load_elf, SZ)(const char *name, int= fd, if (nhdr !=3D NULL) { elf_note_fn((void *)nhdr, (void *)&ph->p_align, SZ =3D=3D = 64); } + g_free(data); data =3D NULL; } } @@ -619,9 +603,6 @@ static ssize_t glue(load_elf, SZ)(const char *name, int= fd, } ret =3D total_size; fail: - if (mapped_file) { - g_mapped_file_unref(mapped_file); - } g_free(phdr); return ret; } --=20 2.50.1 (Apple Git-155)