From nobody Sun Nov 24 23:46:07 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1719536362; cv=none; d=zohomail.com; s=zohoarc; b=P3j9W2ltIAiSibVZjzaDjm9n/u68LtPD7TIqG8ux8aqgQ1KlV9nvU+m8NAdVNNTap+9UeI0C6+Ntrec1GjF8IxhOXYy1waJYGow3BVhAzb04RgwUADFU62OyxWDMGxE+qOBi1hago36MXlg6LB5xwjrT3PgeiMvFenJwigQ43wM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719536362; 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=OngnKGGfUguIAEUGMPPSK1wlKkUjWQZBpJxdshqqNo4=; b=NSMla0q5SMKoKWRKECcEm8wuol/1i8SfLaxu9Ihpuju90w30GLqtqhDfeyPGaP3JzKD6TeUZuBT1EI2XmGm7Jse81MQ1rlPHh+9qjS4bmdl9SAuP/9oc5HVbqMH+pXQa10v9W1+Vefy8nA5Lvb8oisKD2G9TH7lUPGX8jV2wTTU= 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 1719536362860265.3183934728895; Thu, 27 Jun 2024 17:59:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMzwl-0004dW-Po; Thu, 27 Jun 2024 20:58:39 -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 1sMzwj-0004d9-BH for qemu-devel@nongnu.org; Thu, 27 Jun 2024 20:58:37 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMzwg-00064o-Fe for qemu-devel@nongnu.org; Thu, 27 Jun 2024 20:58:36 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-6c5bcb8e8edso33169a12.2 for ; Thu, 27 Jun 2024 17:58:34 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fac155c339sm3767425ad.184.2024.06.27.17.58.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Jun 2024 17:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719536313; x=1720141113; 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=OngnKGGfUguIAEUGMPPSK1wlKkUjWQZBpJxdshqqNo4=; b=SaN6p0b3wvkFY9CwFs1Za4yS2GoolmuQos5aCFkGxESrWnnBtOQKWbF2lgZlOYAMoi jHoivhT9x8PPLGLXKmBrHpwl1Vih15Uz842xNFsWqWRnDgsLRC1ShGRpj7p1ifrUZLuI GQ5vpLfV46wYOZ5w6rDc8s/XVGWJ4ou68TJiUyGCDjgyuXA0YGYy6B4wBj0IEC9jQFYX dyyiky1EiKGVEMfYtM7DYNyoDJwDtTyTKjTngA+90Qn0apGbpdYITEEodlR3KRfvJ/i5 lHkM+/IOWcoWOMVtR8LthNKnwdlbp55axFsa60QM+cVOY7rSCvbN54xBOwBESmfxtsHz 5Q5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719536313; x=1720141113; 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=OngnKGGfUguIAEUGMPPSK1wlKkUjWQZBpJxdshqqNo4=; b=TeLRfE/qMRGm1FiP1CmV/jEd21TBgDSEFuU6/7dZ0/t3rxjOkw0yEHkPoAh5Tts2qN NJG0Xwt3uKH+WOJ2VdWxvj04RwX9eIyVdtZL4Btx0ydStleDGPH88xnpKeJt4VSYSQC3 o7mTpUFOrtvNHQEEbm4S6s3/+jgV+fMr8r4yocKOhRSN+bHRNXR6GkrLoSPCaSCuFZG6 MYjCV0apJVCIgQu3M0y3jiZtpjJeQ5KBnDnfsb+054OrHBa/7c6+0bEfFdQNm6VDYoNq ICHbukX+I6ev5SJdkD9wMOIbfrWX2te+GTerut/whvOkI6sXWzuhND9oCQtgOrm/KoXa Ag2w== X-Gm-Message-State: AOJu0Yy0RlBtjMc84d/awhz3kP8CfcpcspucGIOU6d2r2CCeA4KDxIMT 7vnpKv9A7SHtWgAxo6uSiBKmf+Z64d1vuPUtfko+wgGPJaO9MHKZHXrWGAHD X-Google-Smtp-Source: AGHT+IG7pipFkVYVsBmwtzYnN2jGZTyU9BWvHC7PHkAS/JyggBoAxeQOX3VpXFyGA0dIZF2v8qRF1A== X-Received: by 2002:a05:6a20:608a:b0:1bd:2944:d295 with SMTP id adf61e73a8af0-1bd2944d464mr7011745637.44.1719536312994; Thu, 27 Jun 2024 17:58:32 -0700 (PDT) From: Gregor Haas To: qemu-devel@nongnu.org Cc: yaoxt.fnst@fujitsu.com, Gregor Haas Subject: [PATCH v2] hw/core/loader: allow loading larger ROMs Date: Thu, 27 Jun 2024 17:58:17 -0700 Message-ID: <20240628005817.1672298-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=gregorhaas1997@gmail.com; helo=mail-pg1-x535.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1719536363294100001 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(). Signed-off-by: Gregor Haas --- hw/core/loader.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/core/loader.c b/hw/core/loader.c index 2f8105d7de..8216781a75 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -1115,14 +1115,13 @@ 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); + close(fd); + 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; --=20 2.45.2