From nobody Tue Nov 26 14:21:35 2024 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1707323960; cv=none; d=zohomail.com; s=zohoarc; b=M2gKglTp+nkVPqt1LuaD9ht5mNdpQQ5f+CKq2Ys70Avs+174VDgHQ0HyIOmsLODos/8VBHsnhz/3uZyMnuUARZ3LZscswO62LMU4ZIg/kyZlPLI0nJR+d4T2kvbCCWo/T1hqYJnhKNI/L6QgWBBnOzMVGFvcw7hArkw7ynJJxns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707323960; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=al2EF5joR1GpZYix/IJ7sorp1km6Nnx+serOjQtc33w=; b=mJQ4nN4hGtx3L8NZ6fxsvP7DYjIFV2fnwMQ2PZdAOseJk6vSvTCaITtZYpsRL0sskvlDDaD6QoNosW5B/ZqRAsH0PDHc/xJJu0bZOThaF8SWbO+hy8nU/XadyLIfCIZkC+LQiFDDdLJ8re6ctMhPKG6Yyifg9MF1Sqla/5BK/zo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1707323960975530.7104918186508; Wed, 7 Feb 2024 08:39:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXkwJ-0002r6-Im; Wed, 07 Feb 2024 11:38:24 -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 1rXkwH-0002pQ-Ln for qemu-devel@nongnu.org; Wed, 07 Feb 2024 11:38:21 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rXkwE-00067G-Cr for qemu-devel@nongnu.org; Wed, 07 Feb 2024 11:38:21 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4101d096c92so4429365e9.1 for ; Wed, 07 Feb 2024 08:38:17 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id az2-20020a05600c600200b00410141aa57csm2062945wmb.15.2024.02.07.08.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:38:13 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 7A6545F895; Wed, 7 Feb 2024 16:38:12 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707323897; x=1707928697; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=al2EF5joR1GpZYix/IJ7sorp1km6Nnx+serOjQtc33w=; b=N+kFrznvTJ0P9ZboHnXtaevVALylMSNP24w386OGQE+l3iK6kH3jvDND58pQkemXD0 a+GoRlPmPN07imDVS90HOho+O3UdnuIfGczSDciXexfPguAVP/Gbd8jNI7CiuuUlpaC6 rtFDbQs3FQeBNND6Bnt32VlVXThcQ0BPlXDHTj8F66R5qvjErPqOVRA4fyuP2QqBfeNo LoVkw0rVcXMLpqXRLnOJuDRVHi9D3bB+OvHbMMNCzqeuIitE6A7NAKJqXbCy1SaX5cR1 5ly7UNsiDcxJfg4jkKNJXZIgNJYZxLKlIfQOduwbXnJYldB7Edb6BDqIWW1s+WjIsh+r rQMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707323897; x=1707928697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=al2EF5joR1GpZYix/IJ7sorp1km6Nnx+serOjQtc33w=; b=GGvcpTemdTbemJhzqwSmH/SEzqQDYML9aTFa4WZrvM0dpaAe2G2qSXoYDbDJ9W/r0P 3B69I6D/2pE9iEfgyU4E+UF17kPANRjs50ukn7qUaRXH81kxKt9+1zmo44Ur+UP0MiP8 evidrwoUKtyrbPGZtvrbtuwdv0PRX6kvh3ljE01b7saVLeCCgyjbXYfC9WNUkTzMjwZi Ui0zzKD5OPszsNsPN/hRXP2FZjvAq2erMMF2FkpFWKk4au0avGk/z4lDQvr+ZTupwF2a vrgnl8wHw/l5b9w2BS6OjthmMgTq+JpchUoFi0J9noDRDwXP9LhnplGScYPfr2qeECql w0vg== X-Gm-Message-State: AOJu0YwCzNcM73ga5dGZRN8IprctjfMdRC+ewmiXDmKThHuXNnJ0ecfv Rv1Sky1ddQ8+4X45nfl4r74D8pKpqei/s59eRwTAIciNUEOwZcKY7ZHisAxGirw= X-Google-Smtp-Source: AGHT+IEllApoBVS2Af8bGtwiTxz/SrARQDrYzHCX+zMsLKLvVQIjfNdJUEgGbhM6ZEDvEQgUjp9vOQ== X-Received: by 2002:a5d:6703:0:b0:33b:1ae4:10b1 with SMTP id o3-20020a5d6703000000b0033b1ae410b1mr3549305wru.47.1707323896841; Wed, 07 Feb 2024 08:38:16 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU4pOfHiiGwCo4OdHghcmtkfTz/YfCpp7vi1P0k0xuEn7MMyfZkDp5SuiQyA+Dalk1TdFnzHYKAox7Cy2JBgUZvuV7AZWigReJq216WwBzezxWAcZ9bhnJQRXY2r0SV3mP8Tdnhel2lFPGIg2QKfsoGxAX6bATIC7y+sY9yBvBzKf8e/0ixlUCJFHy2ET3h4d9K4yPGT+UlK5zEtL3cEY0lRAFrRNFSNAEkudXO0jP81UW4Zl2AhKcYL6trJCRRZsToazF0RfHIgM+0nifwnqbafeCwP8Q+icMq2dVZkrxchd8ENxvMq3gtJWLuWTWIR0JNrfgc7BuLg4iQEYhNDmsRkTBnC6lqKreHleXYUqIkuoO17HJqdfmypDi+GS61iYaGNm6QSX95W4vqYBgJMLw1ukGO2Ziq3+aGhI+imBOSZ8HdelrkoaPUfJ/G2LGEGqCGLhvJk0RsOWyf8rUYpNr4E5VqVSNYF8rS7HI6wFQASzJeiVWZHPg2nrSjR+2USFDTG8FhgsMl/oWzZ2At9aXfcqxrwy9JRw9S71iJpLlNI6r1wkTvYKpgdcb3loyeVSRdBF9wk5mVZcMUCNprRJ7n6+OQbwWezf0y3wM7TNy6UYvOeKNQOSY8M76BnlFCy3Wfd0jYtU47cp02K7Vk1fw6bPr44uKVeyZQlwXfZFidPwYQESasogOqF1TYk/R/tCiAz4xyHqahKHEwaxfSwq7EGp5ChGqGqv8PakDLFUbxjElwOLUZ8halcTPZ2Fh72XskZVGrX/coi08kcBIduLGN3gKulq+c3/782DnwQc0MeM1LAPV+uT+DdlDYBBmjUDooTTp6Uu9WTxk= From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: devel@lists.libvirt.org, Jiaxun Yang , Daniel Henrique Barboza , Chris Wulff , Weiwei Li , Bin Meng , Thomas Huth , qemu-riscv@nongnu.org, Marek Vasut , Liu Zhiwei , Aleksandar Rikalo , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis , Warner Losh , Paolo Bonzini , Aurelien Jarno , Beraldo Leal , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Max Filippov , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Ed Maste , Palmer Dabbelt , Li-Wen Hsu , Laurent Vivier , Kyle Evans , Wainer dos Santos Moschetta , Riku Voipio Subject: [PATCH v2 04/14] Revert "hw/elf_ops: Ignore loadable segments with zero size" Date: Wed, 7 Feb 2024 16:38:02 +0000 Message-Id: <20240207163812.3231697-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240207163812.3231697-1-alex.bennee@linaro.org> References: <20240207163812.3231697-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::333; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.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_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1707323961521100001 This regressed qemu-system-xtensa: TEST test_load_store on xtensa qemu-system-xtensa: Some ROM regions are overlapping These ROM regions might have been loaded by direct user request or by def= ault. They could be BIOS/firmware images, a guest kernel, initrd or some other = file loaded into guest memory. Check whether you intended to load all this guest code, and whether it ha= s been built to load to the correct addresses. The following two regions overlap (in the memory address space): test_load_store ELF program header segment 1 (addresses 0x0000000000001= 000 - 0x0000000000001f26) test_load_store ELF program header segment 2 (addresses 0x0000000000001= ab8 - 0x0000000000001ab8) make[1]: *** [Makefile:187: run-test_load_store] Error 1 This reverts commit 62570f1434160d356311e1c217537e24a4ac85cd. Message-Id: <20240201122835.1712347-5-alex.bennee@linaro.org> Reviewed-by: Thomas Huth Signed-off-by: Alex Benn=C3=A9e --- include/hw/elf_ops.h | 75 +++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index 3e966ddd5a1..9c35d1b9da6 100644 --- a/include/hw/elf_ops.h +++ b/include/hw/elf_ops.h @@ -427,16 +427,6 @@ static ssize_t glue(load_elf, SZ)(const char *name, in= t fd, file_size =3D ph->p_filesz; /* Size of the allocated data */ data_offset =3D ph->p_offset; /* Offset where the data is loca= ted */ =20 - /* - * Some ELF files really do have segments of zero size; - * just ignore them rather than trying to set the wrong addr, - * or create empty ROM blobs, because the zero-length blob can - * falsely trigger the overlapping-ROM-blobs check. - */ - if (mem_size =3D=3D 0) { - continue; - } - if (file_size > 0) { if (g_mapped_file_get_length(mapped_file) < file_size + data_offset) { @@ -540,38 +530,45 @@ 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 - if (load_rom) { - g_autofree char *label =3D - g_strdup_printf("%s ELF program header segment %d", - name, i); - - /* - * rom_add_elf_program() takes its own reference to - * 'mapped_file'. - */ - rom_add_elf_program(label, mapped_file, data, file_size, - mem_size, addr, as); - } else { - MemTxResult res; - - res =3D address_space_write(as ? as : &address_space_memor= y, - addr, MEMTXATTRS_UNSPECIFIED, - data, file_size); - if (res !=3D MEMTX_OK) { - goto fail; - } - /* - * We need to zero'ify the space that is not copied - * from file - */ - if (file_size < mem_size) { - res =3D address_space_set(as ? as : &address_space_mem= ory, - addr + file_size, 0, - mem_size - file_size, - MEMTXATTRS_UNSPECIFIED); + /* 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 (load_rom) { + g_autofree char *label =3D + g_strdup_printf("%s ELF program header segment %d", + name, i); + + /* + * 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); + } else { + MemTxResult res; + + res =3D address_space_write(as ? as : &address_space_m= emory, + addr, MEMTXATTRS_UNSPECIFIED, + data, file_size); if (res !=3D MEMTX_OK) { goto fail; } + /* + * We need to zero'ify the space that is not copied + * from file + */ + if (file_size < mem_size) { + res =3D address_space_set(as ? as : &address_space= _memory, + addr + file_size, 0, + mem_size - file_size, + MEMTXATTRS_UNSPECIFIED); + if (res !=3D MEMTX_OK) { + goto fail; + } + } } } =20 --=20 2.39.2