From nobody Sat Dec 28 09:43:40 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1719539516; cv=none; d=zohomail.com; s=zohoarc; b=lPTvZWkEF8/kcnOPKAm+u9QNKfdKCpsTOowOTsSboD2Rgi/VsEtQimTjbKsGmEfQTO/Ekrhcz79GBlCAUvm+Agm7/EqIu5ew76a+bz5Dihk5qf/+kGAtY3zPGGarYhV/o5CEjtLTswn2El9pm9Ttt09hkz4ZiTdTT5ZZUSFed1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719539516; 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=hIsxbBapIyHOOkTI4zsd8EUZ8OdiGNTjF94+afrWNJo=; b=OmrizQtvVvZqeuNJKZs9BpUIAx35eZUvK3BlPXJaPmrhHnE1MpIKI/74SCVqNIXmccgaMuNfdWhWFF6jEN4pD2wQ7R3em6tyI/q0YRe4qrS8QTYzNshc6mFI3GrSs5+ynfOEunR2aTiYodnhmMXgn25qMeAxdCtzEkCj9I0Sd/U= 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+importer2=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 1719539516721499.0748785768076; Thu, 27 Jun 2024 18:51:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN0lb-0004cU-Ed; Thu, 27 Jun 2024 21:51:11 -0400 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 1sN0lZ-0004c8-85 for qemu-devel@nongnu.org; Thu, 27 Jun 2024 21:51:09 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN0lX-0007uQ-Mg for qemu-devel@nongnu.org; Thu, 27 Jun 2024 21:51:09 -0400 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3d55ed47cc6so71260b6e.2 for ; Thu, 27 Jun 2024 18:51:07 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70801e63abcsm391648b3a.2.2024.06.27.18.51.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Jun 2024 18:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719539465; x=1720144265; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hIsxbBapIyHOOkTI4zsd8EUZ8OdiGNTjF94+afrWNJo=; b=mKLTztPnroYx0yaU34T/W5GuoW7MuhND/BaCHnAGn9bQcMXgHy4TRCNuMtjqWMgkmR TOCjZHWibse8IMbRnrThmGeF1vE8dr0l34rpgHsFanQWqw9tzkHTvI9wON3kkVWSmjV1 9lh3znfqLLv6OzN9RBAzxdQ+T1NmofvRZe0wVnCikLXkFKLen1vH5zoOwXFmIHQdmW4u j8Dk62Ehb93IrpitDz6duqMRAwY2adryyf4K0Esmcs/ub7NbBB9VOA4FiHi4k7pZqJgD knBKDQy12Vbz1DzSCbBBAJJzQdb3MRuGOAnYglU+laoK5l18OKjD9UMGMsOxP+Z2hgK4 jHFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719539465; x=1720144265; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hIsxbBapIyHOOkTI4zsd8EUZ8OdiGNTjF94+afrWNJo=; b=rxeCQ0yY21Pc5SJmrKNZGBnP2lmWTQwRGkyqmynW16OY/rbQw4JqE5BSVSki8FTWkn K5Ge4a7JQuHVZBjvqIad4PduD9ap94uLWMs6ZFphtpAKYHAq3qZJ11g3kfWqWDkKo6+M 2euxMRwmA8IVSoOjablkQoM0K1NCy6iXjZVQMZ3yb+Duw/fD34h9td8GIPECVibrh0nC zoNd0gyAxTRAw3pxXxVkZgSQvupefLQM7WHIPhTYHO3TVcVWl4WxpipTAZeWBLxY3UKh k3P4AUAVk4PVptcouSKy62lqFXr9ssOgtC44ILdVQ2vaWghr6L7IaTC40hlH6JCyklR+ b9vg== X-Gm-Message-State: AOJu0YwklvW9wsZbzl0+2Y57dwbfOZVZOBGxLcsfYu2ue8BKnQtQ2rQS U1XWImsfufU+uryO9yZSVa3xXB7AR2KmlnnDa8UezHTkpPnhpuE2bL0i9Tl/ X-Google-Smtp-Source: AGHT+IHZqiyfyE68aBfi7ZlkOjHxbZuuypWtrZ05NltJ35zwpqL6DajdQh5pVP98+UQaZMhUrdC7UQ== X-Received: by 2002:a05:6808:120d:b0:3d5:47bc:14db with SMTP id 5614622812f47-3d547bc1742mr16055372b6e.22.1719539465131; Thu, 27 Jun 2024 18:51:05 -0700 (PDT) From: Gregor Haas To: qemu-devel@nongnu.org Cc: yaoxt.fnst@fujitsu.com, Gregor Haas Subject: [PATCH v3] hw/core/loader: allow loading larger ROMs Date: Thu, 27 Jun 2024 18:50:36 -0700 Message-ID: <20240628015036.1815838-1-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=gregorhaas1997@gmail.com; helo=mail-oi1-x22f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1719539517958100003 Content-Type: text/plain; charset="utf-8" The read() syscall is not guaranteed to return all data from a file. The default ROM loader implementation currently does not take this into account, instead failing if all bytes are not read at once. This change loads the ROM using load_image_size() instead, which correctly reads all data using multiple calls to read(). Also, the ROM size is now determined using the get_image_size() function rather than using manual lseek(). Signed-off-by: Gregor Haas Reviewed-by: Xingtao Yao --- hw/core/loader.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/hw/core/loader.c b/hw/core/loader.c index 2f8105d7de..c2c61158f1 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -1076,7 +1076,6 @@ ssize_t rom_add_file(const char *file, const char *fw= _dir, MachineClass *mc =3D MACHINE_GET_CLASS(qdev_get_machine()); Rom *rom; ssize_t rc; - int fd =3D -1; char devpath[100]; =20 if (as && mr) { @@ -1094,19 +1093,12 @@ ssize_t rom_add_file(const char *file, const char *= fw_dir, rom->path =3D g_strdup(file); } =20 - fd =3D open(rom->path, O_RDONLY | O_BINARY); - if (fd =3D=3D -1) { - fprintf(stderr, "Could not open option rom '%s': %s\n", - rom->path, strerror(errno)); - goto err; - } - if (fw_dir) { rom->fw_dir =3D g_strdup(fw_dir); rom->fw_file =3D g_strdup(file); } rom->addr =3D addr; - rom->romsize =3D lseek(fd, 0, SEEK_END); + rom->romsize =3D get_image_size(rom->path); if (rom->romsize =3D=3D -1) { fprintf(stderr, "rom: file %-20s: get size error: %s\n", rom->name, strerror(errno)); @@ -1115,14 +1107,12 @@ ssize_t rom_add_file(const char *file, const char *= fw_dir, =20 rom->datasize =3D rom->romsize; rom->data =3D g_malloc0(rom->datasize); - lseek(fd, 0, SEEK_SET); - rc =3D read(fd, rom->data, rom->datasize); + rc =3D load_image_size(rom->path, rom->data, rom->datasize); if (rc !=3D rom->datasize) { fprintf(stderr, "rom: file %-20s: read error: rc=3D%zd (expected %= zd)\n", rom->name, rc, rom->datasize); goto err; } - close(fd); rom_insert(rom); if (rom->fw_file && fw_cfg) { const char *basename; @@ -1159,9 +1149,6 @@ ssize_t rom_add_file(const char *file, const char *fw= _dir, return 0; =20 err: - if (fd !=3D -1) - close(fd); - rom_free(rom); return -1; } --=20 2.45.2