From nobody Tue Feb 10 20:08:32 2026 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1682420249; cv=none; d=zohomail.com; s=zohoarc; b=aXw1Eim8oZsZS39XW1TlJIO6L0o6NemtwfGXtErF5gfHn85bQQgrDE7+6+CzLQ04v0UPvr89+79S1rNk8kf0DMuv/W1e+p8Nj3dKWXFEl0FGhL/ixZN7mQ/CCdq0H5kXhMaqKgwrLGGUZkJZ9h3EFfpo3v2cEpYqABxglR7kTr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682420249; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ehBE2fK1ENA84Ps5bmvth2N8WSsXpBuCWBbENqvHwGk=; b=mVhsTAggSyiaWucrEz5Hw11b6/JC6LQAQVMhPvw+0cwWeiuYXoSPY3+0gsaSZkiTP9fuJpZFOi7UW3W94GF2vl/rt7cyFDJXfh/VlRiT8D6MvQoxwdGtSOiGmDnn1Zj9Wj6Qp/omGEelXvNdrZImqr+9o+8thwsy43OKKkJq4Jo= 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 1682420249848929.2021300648008; Tue, 25 Apr 2023 03:57:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prGLa-0001yX-FJ; Tue, 25 Apr 2023 06:56:34 -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 1prGLS-0001u1-FS for qemu-devel@nongnu.org; Tue, 25 Apr 2023 06:56:28 -0400 Received: from forwardcorp1c.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prGLQ-0004gm-La for qemu-devel@nongnu.org; Tue, 25 Apr 2023 06:56:26 -0400 Received: from mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net [IPv6:2a02:6b8:c00:2582:0:640:9a17:0]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 58FC65F0A8; Tue, 25 Apr 2023 13:56:18 +0300 (MSK) Received: from vsementsov-nix.yandex-team.ru (unknown [2a02:6b8:b081:b440::1:14]) by mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 4uDLUS1OcKo0-zXpFEGaH; Tue, 25 Apr 2023 13:56:17 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1682420177; bh=ehBE2fK1ENA84Ps5bmvth2N8WSsXpBuCWBbENqvHwGk=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Ql0iJHFFMyHIm/CaC8IgbD2S1/iRkAJO1M/04Ut/wUuMQT9VgDHRFqsXL5cCPDExz sVIpU5Xfqh7uI21yYKh29YY+KBDec2XrUDcDz0oQsJ5GU5wh9f9OIVkBwEzYvLwUBT OLrTInprQW2AeB8ElIGAIe9ggUph+dD1CArmYKdY= Authentication-Results: mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, david@redhat.com, peterx@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, lersek@redhat.com, kraxel@redhat.com Subject: [PATCH 1/3] pci: pci_add_option_rom(): improve style Date: Tue, 25 Apr 2023 13:56:01 +0300 Message-Id: <20230425105603.137823-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230425105603.137823-1-vsementsov@yandex-team.ru> References: <20230425105603.137823-1-vsementsov@yandex-team.ru> 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=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1682420251999100001 Content-Type: text/plain; charset="utf-8" Fix over-80 lines and missing curly brackets for if-operators, which are required by QEMU coding style. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/pci/pci.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index def5000e7b..4a61c8d24a 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2297,10 +2297,12 @@ static void pci_add_option_rom(PCIDevice *pdev, boo= l is_default_rom, char name[32]; const VMStateDescription *vmsd; =20 - if (!pdev->romfile) + if (!pdev->romfile) { return; - if (strlen(pdev->romfile) =3D=3D 0) + } + if (strlen(pdev->romfile) =3D=3D 0) { return; + } =20 if (!pdev->rom_bar) { /* @@ -2349,7 +2351,8 @@ static void pci_add_option_rom(PCIDevice *pdev, bool = is_default_rom, } if (pdev->romsize !=3D -1) { if (size > pdev->romsize) { - error_setg(errp, "romfile \"%s\" (%u bytes) is too large for R= OM size %u", + error_setg(errp, "romfile \"%s\" (%u bytes) " + "is too large for ROM size %u", pdev->romfile, (uint32_t)size, pdev->romsize); g_free(path); return; @@ -2359,14 +2362,13 @@ static void pci_add_option_rom(PCIDevice *pdev, boo= l is_default_rom, } =20 vmsd =3D qdev_get_vmsd(DEVICE(pdev)); + snprintf(name, sizeof(name), "%s.rom", + vmsd ? vmsd->name : object_get_typename(OBJECT(pdev))); =20 - if (vmsd) { - snprintf(name, sizeof(name), "%s.rom", vmsd->name); - } else { - snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(= pdev))); - } pdev->has_rom =3D true; - memory_region_init_rom(&pdev->rom, OBJECT(pdev), name, pdev->romsize, = &error_fatal); + memory_region_init_rom(&pdev->rom, OBJECT(pdev), name, pdev->romsize, + &error_fatal); + ptr =3D memory_region_get_ram_ptr(&pdev->rom); if (load_image_size(path, ptr, size) < 0) { error_setg(errp, "failed to load romfile \"%s\"", pdev->romfile); --=20 2.34.1 From nobody Tue Feb 10 20:08:32 2026 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1682420244; cv=none; d=zohomail.com; s=zohoarc; b=FPKoYWx0Milvaua5V6mnTc4pcNIB/irpR9IF5BNH1xCJKY342gv0BPzGVPhxF/fCpeaZ6XIX3qVGwSK4c8I1kBPhIna7W2F56Nc0LGLpVjHECiQu+MInarvsgz+qfhkk/cyZQWABgjKVLzLQmoIda3M6sJKNAGYBZ4cRs+KfgqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682420244; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T4OMW3uNIsuTtXXlaMvFRDkYLhI73waVVu2T/GxdfZQ=; b=WBUEMfJGKiVdZFeOcIYf30dfh5LMg/uKQcqdDjKdHbdKD+vdWz1u97Fo5i/LPTXugW8Nd3Uc58moT0484IQX8vuKVTTxOrsZtJf4eFT/oFVxsoMO7yWp8zarg8B9eq91759rvYrome3N5DXcD76wwkBCQbvhSrEr8Il24UUdFZU= 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 1682420244121969.787551324134; Tue, 25 Apr 2023 03:57:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prGLZ-0001xn-NP; Tue, 25 Apr 2023 06:56:33 -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 1prGLT-0001u6-Rc for qemu-devel@nongnu.org; Tue, 25 Apr 2023 06:56:29 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prGLQ-0004gq-L1 for qemu-devel@nongnu.org; Tue, 25 Apr 2023 06:56:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net [IPv6:2a02:6b8:c00:2582:0:640:9a17:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 3B1476098F; Tue, 25 Apr 2023 13:56:19 +0300 (MSK) Received: from vsementsov-nix.yandex-team.ru (unknown [2a02:6b8:b081:b440::1:14]) by mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 4uDLUS1OcKo0-tVwmMd5C; Tue, 25 Apr 2023 13:56:18 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1682420178; bh=T4OMW3uNIsuTtXXlaMvFRDkYLhI73waVVu2T/GxdfZQ=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=JhhP2+WhuAZhTAgJleS7ORULKuwxT8qXC/1FaTMv5Cmuejsdb540aqKOx6qyaby03 UfyNT6bJkyj1TdmNMc4W1ckU3aaVyOXeKABLT0U82M6bCKTjPKn4lZfM+Lt92DSGY2 m0ZvCafjJ+caL1bfZR5Spa+8TTwpTuvgWtQ8S8gs= Authentication-Results: mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, david@redhat.com, peterx@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, lersek@redhat.com, kraxel@redhat.com Subject: [PATCH 2/3] pci: pci_add_option_rom(): refactor: use g_autofree for path variable Date: Tue, 25 Apr 2023 13:56:02 +0300 Message-Id: <20230425105603.137823-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230425105603.137823-1-vsementsov@yandex-team.ru> References: <20230425105603.137823-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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 @yandex-team.ru) X-ZM-MESSAGEID: 1682420244595100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/pci/pci.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 4a61c8d24a..a442f8fce1 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2292,7 +2292,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool = is_default_rom, Error **errp) { int64_t size; - char *path; + g_autofree char *path =3D NULL; void *ptr; char name[32]; const VMStateDescription *vmsd; @@ -2337,16 +2337,13 @@ static void pci_add_option_rom(PCIDevice *pdev, boo= l is_default_rom, size =3D get_image_size(path); if (size < 0) { error_setg(errp, "failed to find romfile \"%s\"", pdev->romfile); - g_free(path); return; } else if (size =3D=3D 0) { error_setg(errp, "romfile \"%s\" is empty", pdev->romfile); - g_free(path); return; } else if (size > 2 * GiB) { error_setg(errp, "romfile \"%s\" too large (size cannot exceed 2 G= iB)", pdev->romfile); - g_free(path); return; } if (pdev->romsize !=3D -1) { @@ -2354,7 +2351,6 @@ static void pci_add_option_rom(PCIDevice *pdev, bool = is_default_rom, error_setg(errp, "romfile \"%s\" (%u bytes) " "is too large for ROM size %u", pdev->romfile, (uint32_t)size, pdev->romsize); - g_free(path); return; } } else { @@ -2372,10 +2368,8 @@ static void pci_add_option_rom(PCIDevice *pdev, bool= is_default_rom, ptr =3D memory_region_get_ram_ptr(&pdev->rom); if (load_image_size(path, ptr, size) < 0) { error_setg(errp, "failed to load romfile \"%s\"", pdev->romfile); - g_free(path); return; } - g_free(path); =20 if (is_default_rom) { /* Only the default rom images will be patched (if needed). */ --=20 2.34.1 From nobody Tue Feb 10 20:08:32 2026 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1682420225; cv=none; d=zohomail.com; s=zohoarc; b=EJ3/5f3PcaQueXu3Z9vt5q6DpAwQJsDHvcN8lGuQuOY1bbiGOXixFtLNhujrUi0ti/2yyFXUbLl+w20NAgOgQWAGFEPbHFyFoGKCoMBi2c7EveLblQXHLcVlvEsWeZatoCD7zf6j1Vh/ejgLZWNZo8/qDyyK9prDuBBTQ97arK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682420225; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dmP7RsqsNBWEKlsZF2unANl73sZ2JwhlINZhbJfI5yk=; b=ZUIs+uqbeWnUU11DB8O9uXaFFgsUEiwc9B9CW8B6yDFuKff/WWVIEeJW8bgdtt5NsEQKXtKdEDULI/3s+araxiOfnrXY6SE51CmPHd66N6fEngsVIDsHJK+Fe3+PzdO2GU7JqXtJ61EZ7uGINQ7t1BMp5ApiVtt+GX5JToDrNFo= 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 1682420225203721.0493866881195; Tue, 25 Apr 2023 03:57:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prGLX-0001vb-Br; Tue, 25 Apr 2023 06:56:31 -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 1prGLU-0001u7-1c for qemu-devel@nongnu.org; Tue, 25 Apr 2023 06:56:29 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prGLQ-0004hE-N4 for qemu-devel@nongnu.org; Tue, 25 Apr 2023 06:56:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net [IPv6:2a02:6b8:c00:2582:0:640:9a17:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 3E58060A02; Tue, 25 Apr 2023 13:56:20 +0300 (MSK) Received: from vsementsov-nix.yandex-team.ru (unknown [2a02:6b8:b081:b440::1:14]) by mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 4uDLUS1OcKo0-5wyXylCH; Tue, 25 Apr 2023 13:56:19 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1682420179; bh=dmP7RsqsNBWEKlsZF2unANl73sZ2JwhlINZhbJfI5yk=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=nZpR1AH4Qd+C2wgwRE+gZJF351T0qzLXCbKXUyLxN7E0Ia1uM1xdxahoBTHkyxp1Q vP47KzhQ6+XL8nS3Q6Rhk+9OpwL3T3nckeMj3fVoe6egUr+MX5Get6f4OambH6C+kZ OI7eIl86iWGcXToTa+kInRSFe4FtQCA0TvzmmiZ8= Authentication-Results: mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, david@redhat.com, peterx@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, lersek@redhat.com, kraxel@redhat.com Subject: [PATCH 3/3] pci: ROM preallocation for incoming migration Date: Tue, 25 Apr 2023 13:56:03 +0300 Message-Id: <20230425105603.137823-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230425105603.137823-1-vsementsov@yandex-team.ru> References: <20230425105603.137823-1-vsementsov@yandex-team.ru> 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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 @yandex-team.ru) X-ZM-MESSAGEID: 1682420226404100001 Content-Type: text/plain; charset="utf-8" On incoming migration we have the following sequence to load option ROM: 1. On device realize we do normal load ROM from the file 2. Than, on incoming migration we rewrite ROM from the incoming RAM block. If sizes mismatch we fail. This is not ideal when we migrate to updated distribution: we have to keep old ROM files in new distribution and be careful around romfile property to load correct ROM file. Which is loaded actually just to allocate the ROM with correct length. Note, that romsize property doesn't really help: if we try to specify it when default romfile is larger, it fails with something like: romfile "efi-virtio.rom" (160768 bytes) is too large for ROM size 65536 This commit brings new behavior for romfile=3D"",romsize=3DSIZE combination of options. Current behavior is just ignore romsize and not load or create any ROM. Let's instead preallocate ROM, not loading any file. This way we can migrate old vm to new environment not thinking about ROM files on destination host: 1. specify romfile=3D"",romsize=3DSIZE on target, with correct SIZE (actually, size of romfile on source aligned up to power of two, or just original romsize option on source) 2. On device realize we just preallocate ROM, and not load any file 3. On incoming migration ROM is filled from the migration stream As a bonus we avoid extra reading from ROM file on target. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/pci/pci.c | 76 +++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index a442f8fce1..039e762b66 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2293,17 +2293,21 @@ static void pci_add_option_rom(PCIDevice *pdev, boo= l is_default_rom, { int64_t size; g_autofree char *path =3D NULL; - void *ptr; char name[32]; const VMStateDescription *vmsd; + bool load_file; =20 if (!pdev->romfile) { return; } - if (strlen(pdev->romfile) =3D=3D 0) { + + load_file =3D strlen(pdev->romfile) > 0; + if (!load_file && pdev->romsize =3D=3D -1) { return; } =20 + assert(load_file || !is_default_rom); + if (!pdev->rom_bar) { /* * Load rom via fw_cfg instead of creating a rom bar, @@ -2329,32 +2333,35 @@ static void pci_add_option_rom(PCIDevice *pdev, boo= l is_default_rom, return; } =20 - path =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile); - if (path =3D=3D NULL) { - path =3D g_strdup(pdev->romfile); - } + if (load_file) { + path =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile); + if (path =3D=3D NULL) { + path =3D g_strdup(pdev->romfile); + } =20 - size =3D get_image_size(path); - if (size < 0) { - error_setg(errp, "failed to find romfile \"%s\"", pdev->romfile); - return; - } else if (size =3D=3D 0) { - error_setg(errp, "romfile \"%s\" is empty", pdev->romfile); - return; - } else if (size > 2 * GiB) { - error_setg(errp, "romfile \"%s\" too large (size cannot exceed 2 G= iB)", - pdev->romfile); - return; - } - if (pdev->romsize !=3D -1) { - if (size > pdev->romsize) { - error_setg(errp, "romfile \"%s\" (%u bytes) " - "is too large for ROM size %u", - pdev->romfile, (uint32_t)size, pdev->romsize); + size =3D get_image_size(path); + if (size < 0) { + error_setg(errp, "failed to find romfile \"%s\"", pdev->romfil= e); + return; + } else if (size =3D=3D 0) { + error_setg(errp, "romfile \"%s\" is empty", pdev->romfile); + return; + } else if (size > 2 * GiB) { + error_setg(errp, + "romfile \"%s\" too large (size cannot exceed 2 GiB= )", + pdev->romfile); return; } - } else { - pdev->romsize =3D pow2ceil(size); + if (pdev->romsize !=3D -1) { + if (size > pdev->romsize) { + error_setg(errp, "romfile \"%s\" (%u bytes) " + "is too large for ROM size %u", + pdev->romfile, (uint32_t)size, pdev->romsize); + return; + } + } else { + pdev->romsize =3D pow2ceil(size); + } } =20 vmsd =3D qdev_get_vmsd(DEVICE(pdev)); @@ -2365,15 +2372,18 @@ static void pci_add_option_rom(PCIDevice *pdev, boo= l is_default_rom, memory_region_init_rom(&pdev->rom, OBJECT(pdev), name, pdev->romsize, &error_fatal); =20 - ptr =3D memory_region_get_ram_ptr(&pdev->rom); - if (load_image_size(path, ptr, size) < 0) { - error_setg(errp, "failed to load romfile \"%s\"", pdev->romfile); - return; - } + if (load_file) { + void *ptr =3D memory_region_get_ram_ptr(&pdev->rom); =20 - if (is_default_rom) { - /* Only the default rom images will be patched (if needed). */ - pci_patch_ids(pdev, ptr, size); + if (load_image_size(path, ptr, size) < 0) { + error_setg(errp, "failed to load romfile \"%s\"", pdev->romfil= e); + return; + } + + if (is_default_rom) { + /* Only the default rom images will be patched (if needed). */ + pci_patch_ids(pdev, ptr, size); + } } =20 pci_register_bar(pdev, PCI_ROM_SLOT, 0, &pdev->rom); --=20 2.34.1