From patchwork Wed Feb 7 16:38:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 770639 Delivered-To: patch@linaro.org Received: by 2002:a5d:40c1:0:b0:33b:4db1:f5b3 with SMTP id b1csp400641wrq; Wed, 7 Feb 2024 08:39:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+hDPcJxUz4jKoFY/9ren/toiM9hFMBNV2noku1IANOT8tS2A7WKXhTqSWomBovEm82aiN X-Received: by 2002:a05:6808:309e:b0:3bf:dc4a:f3f7 with SMTP id bl30-20020a056808309e00b003bfdc4af3f7mr6401695oib.35.1707323960605; Wed, 07 Feb 2024 08:39:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707323960; cv=none; d=google.com; s=arc-20160816; b=pCcy6cWPpe7aF7TuPpZNCiSBvtq4KgauUf8EYSmNVZdSoog+41CrUtjf9MMXNYpu9N t2f89z3GfXNjh47VQEin5Imu0Zh0N0cHswNAszNy54yFwzWzlbZsQENhSpnSrEeYyXlF MrO2y3A28jZntrtgEl/yKwyrpHuDEAKk0j3VvD1CCap9hcAxg+bkpjH5GpN73gpw+MZr p2cn+P0Jc2pnEiKt3d/zphJSXe3+VT+dqthqtFmVkUTsIZcr9Ygg9pXQZuGae4MdP77S poreqO1KKWUoKokiCLJYzecv3h+5UrBWPrWN/lhk1iAKxTXg5g0Knjn9tTcJ0OV782Pc Uq1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=al2EF5joR1GpZYix/IJ7sorp1km6Nnx+serOjQtc33w=; fh=n3s7qGoCu//JPKieQRsiO2LKreTKSPwfsQw9ivy8Xe8=; b=Zz+LmaHZKfcEuccRc2Mv+fRzkWWI6KTal766FnPs7fiqoBWXFHEO+kcwT988llaey9 FPcpkqnlPU8ttSDlejI4L0YGvBnUuIEnhh7RKg9NHj3S52D9Glq6B2/WWIWhB6J8oVPc TZZTGVZBNpign2taaVc/tDHR8x409ciVhsBql4w95YKqKvC0rLNWC1zZR+Kb/siqPK8a mGAafPPQL7sqHnTFgmFItGSN9OjsgrYTIgniQOMgj5irPkW75Af4mQgQrwAFkonUy4bx oZ/MMEF7C0mSnFo9zXZzVX8yt4ND8yZQie1t6mFR7KQVwM4S8zFuiywL8KeVXVg3ajn5 uFIw==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N+kFrznv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=1; AJvYcCWF6PXfpN67TJPKxOGTMHCOArERspJG2OMrz2HGXUFrQEm917CFPeksQcd+s1QV7jJHBaY1pQac7uJgrYdgUZox Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y2-20020a37e302000000b00783f0d6b2absi1422550qki.390.2024.02.07.08.39.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Feb 2024 08:39:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N+kFrznv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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= 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) From: =?utf-8?q?Alex_Benn=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?= =?utf-8?q?_Lureau?= , =?utf-8?q?Philippe_Mathi?= =?utf-8?q?eu-Daud=C3=A9?= , Alistair Francis , Warner Losh , Paolo Bonzini , Aurelien Jarno , Beraldo Leal , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Max Filippov , =?utf-8?q?Alex_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 default. 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 has 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 0x0000000000001000 - 0x0000000000001f26) test_load_store ELF program header segment 2 (addresses 0x0000000000001ab8 - 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ée --- 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, int fd, file_size = ph->p_filesz; /* Size of the allocated data */ data_offset = ph->p_offset; /* Offset where the data is located */ - /* - * 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 == 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, int fd, *pentry = ehdr.e_entry - ph->p_vaddr + ph->p_paddr; } - if (load_rom) { - g_autofree char *label = - 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 = address_space_write(as ? as : &address_space_memory, - addr, MEMTXATTRS_UNSPECIFIED, - data, file_size); - if (res != MEMTX_OK) { - goto fail; - } - /* - * We need to zero'ify the space that is not copied - * from file - */ - if (file_size < mem_size) { - res = address_space_set(as ? as : &address_space_memory, - 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 != 0) { + if (load_rom) { + g_autofree char *label = + 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 = address_space_write(as ? as : &address_space_memory, + addr, MEMTXATTRS_UNSPECIFIED, + data, file_size); if (res != MEMTX_OK) { goto fail; } + /* + * We need to zero'ify the space that is not copied + * from file + */ + if (file_size < mem_size) { + res = address_space_set(as ? as : &address_space_memory, + addr + file_size, 0, + mem_size - file_size, + MEMTXATTRS_UNSPECIFIED); + if (res != MEMTX_OK) { + goto fail; + } + } } }