From nobody Tue Nov 26 14:51:28 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=1706790605; cv=none; d=zohomail.com; s=zohoarc; b=mMxgmT/WWJ7xSmmWUcg6apcLCPFwuqGjxeDjLFk8BWnyT3ulcBJvH/z6KZDbQejTWaDyrUdCTAZcQ+Zd3Rdl6nFcEpSgRuW7FaFGHakZzQ/klXV+ChzO9d6n2BJa7ysew5cG4uC/mePnhYTfk3wvFJ9B7jSmyoxmnd5UEFivdNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706790605; 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=4TIyz7/5C01pE+WSqKNz5zxOPpiT8BdSgjCe1JUQ504=; b=PGGPsEdWpRvW/i1+0/BCfTGKmkiYbTvLLrM28MmaaQN0jB5iBAA3OzGL4V2RFExNDbCXX9pxSmu1WwxP4HB1UfcN9kNEcSIt7HASoG6IkPI0h7Oq4AF91AgsCvwoFRokDJnf0/6udexgDXl9tWO/YlpDndy5GpOJy9M1mKUVeHE= 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 1706790605886643.9490398110707; Thu, 1 Feb 2024 04:30:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVWBR-0007qy-Jf; Thu, 01 Feb 2024 07:28:45 -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 1rVWBP-0007pQ-KM for qemu-devel@nongnu.org; Thu, 01 Feb 2024 07:28:43 -0500 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rVWBN-0002Av-C2 for qemu-devel@nongnu.org; Thu, 01 Feb 2024 07:28:43 -0500 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-55c2cf644f3so1113389a12.1 for ; Thu, 01 Feb 2024 04:28:39 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id n17-20020aa7c791000000b0055f283314e1sm3153680eds.43.2024.02.01.04.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 04:28:36 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A41CA5F9DC; Thu, 1 Feb 2024 12:28:35 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706790519; x=1707395319; 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=4TIyz7/5C01pE+WSqKNz5zxOPpiT8BdSgjCe1JUQ504=; b=iKFzcPNBT4hBJlKNTH47w2k7xk2xnvjUB0Lm5z+IxjbJfy/kbFDSE4MWl9oqQwJO2B zBcuNSvEul1e45KiHJ/gMvsc7/HfMocY4YC0o4AxiF91KDlf0QlKzOkj0EIAWUZf4EFv 77ZoAGIo4/aVBR35qYlDrqZ9scTZrnB8n0Jt52pmf9ab2sCGrdi56FAj7raReni6JmSs d9kgPIJgaMZey0sPkIGfsy4VkMwloiU4LteTRJf6fSDlS+6KQ1ohkJCW8v6lBJAUQ9WB kh9u8YuH7u+O7Ozu3sYRa0W2mvjR30Czo/wBbU8gTg35rKezoc8zT9AWt1WYypMy8Xl4 tRiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706790519; x=1707395319; 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=4TIyz7/5C01pE+WSqKNz5zxOPpiT8BdSgjCe1JUQ504=; b=ldu/uD9g0KyD8Qc6z/r4hBn65F6z3AvRoU21Ok4bXJj8dCLXYoQyoE553KrqZMgi9f RbZLhMoY0fpzBSHN0REeR9a1juppHfV50um242T9F8x8AZAK0mMkXl763/CZ6ET/mlLy h4QL9x+0ScJABPLvQ+DBMDwJhd3dE34GYf3LsB9RdxXtjGmAL8zpxLFOdNE7yATT6i/F tUcBYXf2BXzVuMfXhGRjXML27/1UqXAOvROClhYr9fIXOd9DcxRaBxIAsd0qM8kFiUH8 jIQcV+Eo8BGsEQbrye5X6nrQvHTyIgZojmsiFN02zhm+IMJV4rth2UykoYkGQNGGQI7N F1TQ== X-Gm-Message-State: AOJu0YwAXaq5/BDc7kCSmCz/3dXQlgIBXpm+rDkILhGnRl/K9wDuOFMa rlQY0n8AtRbEPA87EQRGsKqhc2DomIOnba7qYeZMMDNcFT7scsJjnU/V35LnGBw= X-Google-Smtp-Source: AGHT+IHxgV7bzGmvJmYDMfkZzy3sm3ndOVRBWrFh7bUG5k2eu/yqJgeQqWkvo5P/d9q+uORlG1tyHQ== X-Received: by 2002:a50:c35a:0:b0:55e:dbb8:4c6b with SMTP id q26-20020a50c35a000000b0055edbb84c6bmr3262632edb.42.1706790518811; Thu, 01 Feb 2024 04:28:38 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXV63BBOD1doNfROSikQ+uHSekeSYo5CJveFGyWQ+kPkTaqLMFJZRuoSpP65MHERodTnenmx8G/AjLsGYLHOawz42s0Hk1E/qCLREc4mQVL2IBtyjHj8Ek/AdTy4YeY3WNBrlQtgv9jl2gqRqffF/pUwX4WQekAEWDopbI4KcrGyXi+3RuRRhdoFjl3R6t52FhAOJitPp9LND9aJ++sGJRLsUEizQt2GSRDd/j3kTkQVPtA5HcXA2dnG677nzvUTq8DI6/MsxaLprrdk7FUTlXvBXht2QC1Ypp+XmwRDEx/P1ngzbuD7Y/HgiHHWxYjPLbkZ4h3P2tHLVtUc/EVALkxYY4peXwzJ9a7jr7halPZkSzOBOHRJ7/M4HjFMG+zuEqXAM7X3njgAUud0U3e6yrYYXlIKI8N5M/CbdxVVH3PH9NV1BcdaQcc+2lPyREEutUKVxNeCI4kg7loti/s0AMaS73fqBWGvLvkFxBQmVp84EgSSH15eMRJ2JdL/YD7eOC9BAnCQJEXyqFfVslffqlj47LPMEPAlSiFD9vAAcKqZ/IcaC8VBOku4vqWHd4sEXWbqk6vqY9riklq8CnyfvMIbPiXCbv0fOW2dRzixEU3/wUwibpIZzqmbnw4QFmyZ0/hlWd3m3A= From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Weiwei Li , Bin Meng , Laurent Vivier , Jiaxun Yang , Palmer Dabbelt , devel@lists.libvirt.org, Paolo Bonzini , Alistair Francis , Max Filippov , Marek Vasut , Liu Zhiwei , Thomas Huth , qemu-riscv@nongnu.org, Wainer dos Santos Moschetta , Aleksandar Rikalo , Beraldo Leal , Aurelien Jarno , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Chris Wulff Subject: [PATCH 4/5] Revert "hw/elf_ops: Ignore loadable segments with zero size" Date: Thu, 1 Feb 2024 12:28:34 +0000 Message-Id: <20240201122835.1712347-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240201122835.1712347-1-alex.bennee@linaro.org> References: <20240201122835.1712347-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::52e; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52e.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=unavailable 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: 1706790606813100004 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. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Thomas Huth --- 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