From nobody Wed May 15 20:25:27 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1684155219; cv=none; d=zohomail.com; s=zohoarc; b=aitGkH9nQN3HwZmiGnQ0oYegq6+Dhe5RU6e1mKcoyWJnJohD2OWEXF9/x0zZ2OFQjES/Pwzrn98kxQu3i5k9Po/IEFDCw+cMiCOiR18rw2BPNSknqvvC3/T5MgA7hTIolUa4zjAPVMUfVmFvxih9S1DAa1bw0dlN9Pa13yXhUSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684155219; 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=tORhVGSGbo0QkcfVQkYLUYF8ZeO8psIK57yCudjbUFY=; b=Jh1gxYlYjJ31Ou7tbodCt//uQI/GhD3vefg3tIy3ur2A8UPKa7PELOOVHjFb0OyKp7fOUgdYi6zzWjUpJXP6fixmlYN2JI/uGScwBnvoWPYsMVTuUinqlfywgbMdWWWoPg/Hg06jo062m/Wb/aH33/9o1orypySLzVb0jDohMTU= 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 1684155219048455.57736536767504; Mon, 15 May 2023 05:53:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyXhY-0004Zq-PH; Mon, 15 May 2023 08:53:21 -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 1pyXhU-0004Yq-Id for qemu-devel@nongnu.org; Mon, 15 May 2023 08:53:16 -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 1pyXhO-0006sF-V0 for qemu-devel@nongnu.org; Mon, 15 May 2023 08:53:14 -0400 Received: from mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:a49a:0:640:edd6:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id EFCD761215; Mon, 15 May 2023 15:53:03 +0300 (MSK) Received: from vsementsov-nix.yandex.net (unknown [2a02:6b8:8f:4:7a31:c1ff:fef2:bf07]) by mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VqZgEb0OeGk0-BbKZGELJ; Mon, 15 May 2023 15:53:03 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1684155183; bh=tORhVGSGbo0QkcfVQkYLUYF8ZeO8psIK57yCudjbUFY=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=0QdMZr3bQzp1DcDT+1Y5hlTuKynZ43P4anoyDytd3JWamRIeLx40JjYX1KFK96gSk TB1nlK2D7e27JtiuKDJc2/U1s7KnD3X+TNGkD4UrN/dhVJhqW5pBYhfK6eWXKjLHfb qa2L0ttmptKM43ibNID6bQMmcFz+MiMlX86ljXHo= Authentication-Results: mail-nwsmtp-smtp-corp-main-44.iva.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, den-plotnikov@yandex-team.ru, lersek@redhat.com, kraxel@redhat.com, dgilbert@redhat.com, quintela@redhat.com, armbru@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v3 1/3] pci: pci_add_option_rom(): improve style Date: Mon, 15 May 2023 15:52:27 +0300 Message-Id: <20230515125229.44836-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230515125229.44836-1-vsementsov@yandex-team.ru> References: <20230515125229.44836-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: 1684155221818100003 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 Reviewed-by: David Hildenbrand Reviewed-by: Juan Quintela --- hw/pci/pci.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 8a87ccc8b0..e26e2a7e65 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2312,10 +2312,9 @@ static void pci_add_option_rom(PCIDevice *pdev, bool= is_default_rom, char name[32]; const VMStateDescription *vmsd; =20 - if (!pdev->romfile) - return; - if (strlen(pdev->romfile) =3D=3D 0) + if (!pdev->romfile || !strlen(pdev->romfile)) { return; + } =20 if (!pdev->rom_bar) { /* @@ -2364,7 +2363,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; @@ -2374,14 +2374,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 Wed May 15 20:25:27 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1684155267; cv=none; d=zohomail.com; s=zohoarc; b=Fm6rPj/JderCd7LK7xyIoXQyiYiXEsql9j8H9drchvoDYLZf6/xrnlx1DREpMNnzTUDrgtF4CZkUeNIEGRolxeT1aMrukpHoZVdjeSPXOc+IsfkvmEH8+RoR6k0A53wd8qRs+nmNc+y/cWQ6/1uumRPRUp6tmiZ6Gymgy4OifDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684155267; 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=7qlj134MfPihyqw93uUFOLC8IwnzaS/R7lAWsQXZ6Jw=; b=AoSpdfePhVGbhpkhFrdhTXsJcXiUhthNASx57C2H/ij5zU5OZ84CL/D8GTk7a6LGXYF334QKmqLBGM/Q/dQvuq6hAAADDbX9bhiyhyd7os6gvBlRtPEidNnLs1JCZ9Fgk2xR/arFtzmC7bTO5t93ebBCO1HLoFiavHH0gfkL4ig= 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 1684155267876498.69948567742256; Mon, 15 May 2023 05:54:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyXha-0004aR-5n; Mon, 15 May 2023 08:53:22 -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 1pyXhU-0004Ys-Ko for qemu-devel@nongnu.org; Mon, 15 May 2023 08:53:16 -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 1pyXhQ-0006sH-Nn for qemu-devel@nongnu.org; Mon, 15 May 2023 08:53:16 -0400 Received: from mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:a49a:0:640:edd6:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id BD35961236; Mon, 15 May 2023 15:53:04 +0300 (MSK) Received: from vsementsov-nix.yandex.net (unknown [2a02:6b8:8f:4:7a31:c1ff:fef2:bf07]) by mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VqZgEb0OeGk0-rHG1QqVi; Mon, 15 May 2023 15:53:04 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1684155184; bh=7qlj134MfPihyqw93uUFOLC8IwnzaS/R7lAWsQXZ6Jw=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=zHTeCFSeiKrP0W+jKHDiCeZcR/yIX2l1uGKiABTtJtyzOsXnWXcHTlZDLqP8YITyo dvIa/FwmBkyrIyw0zKrU46Ye6Htmm9f3xjreDBwmt7SGMefpPCaCNGiUVVLPItjZQS 9ivBEO1bj7oAMUUkpZIqboJmU74oJbLkbY9FXWWA= Authentication-Results: mail-nwsmtp-smtp-corp-main-44.iva.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, den-plotnikov@yandex-team.ru, lersek@redhat.com, kraxel@redhat.com, dgilbert@redhat.com, quintela@redhat.com, armbru@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v3 2/3] pci: pci_add_option_rom(): refactor: use g_autofree for path variable Date: Mon, 15 May 2023 15:52:28 +0300 Message-Id: <20230515125229.44836-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230515125229.44836-1-vsementsov@yandex-team.ru> References: <20230515125229.44836-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: 1684155271384100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: David Hildenbrand Reviewed-by: Juan Quintela --- 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 e26e2a7e65..3a0107758c 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2307,7 +2307,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; @@ -2349,16 +2349,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) { @@ -2366,7 +2363,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 { @@ -2384,10 +2380,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 Wed May 15 20:25:27 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1684155220; cv=none; d=zohomail.com; s=zohoarc; b=gGNFWx1mu+PYYGIoRC763l+3P6bEzPr9fYCtDuR/oF89J3Cu/qAphXxhfWxgrQkH9nm39VHKG40CPI7fvZnmpQMQQoDBFNhFVPrA5BVch9ELJWJoMU4vIKZ9SrcI6J/flqs0XMz9wrw11x8/2IVhVoP97mIXTtnzXWUv8dHypx8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684155220; 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=bSJe4lLMF86lef9u58KlWE3vNJAuDt6ICKNcWCe8RTg=; b=gVHHPjdw1XemWgx/h0lgn3J+TR3snPkbvAyXarBhaVb9NKd5k28Tm8jOgWVt59DiZzakdY4E2tQ20IQyFEjN1lGVYSC+vM96O+pFBN1ny17T1dP5qKckaM+tsvxzJcafgjRk8F72LtLggRm4lDmuYfp/yq0N5iqyON2fmG0BGRw= 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 1684155220812960.6893508657779; Mon, 15 May 2023 05:53:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyXhe-0004az-JL; Mon, 15 May 2023 08:53:26 -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 1pyXhW-0004Zo-HR for qemu-devel@nongnu.org; Mon, 15 May 2023 08:53:20 -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 1pyXhQ-0006sG-No for qemu-devel@nongnu.org; Mon, 15 May 2023 08:53:16 -0400 Received: from mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:a49a:0:640:edd6:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id B556C600A5; Mon, 15 May 2023 15:53:05 +0300 (MSK) Received: from vsementsov-nix.yandex.net (unknown [2a02:6b8:8f:4:7a31:c1ff:fef2:bf07]) by mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VqZgEb0OeGk0-kdsFUVSi; Mon, 15 May 2023 15:53:04 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1684155184; bh=bSJe4lLMF86lef9u58KlWE3vNJAuDt6ICKNcWCe8RTg=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=ga67Xy3Wcs/gqySRuoeTCU+RC8YG4iHpWo8FINPcNgEAGvHhAN0pOxk58CPTlwT1A kpF0/tltS4/1z8TvXFBvwrn4s8kbMoe5I7NiZdRUbp35jYgoKOaXhOi6N1HsEwSXSX CTLLj1o34Up0Fh/w+zMkfPz4QBrExrTbSFxKzazA= Authentication-Results: mail-nwsmtp-smtp-corp-main-44.iva.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, den-plotnikov@yandex-team.ru, lersek@redhat.com, kraxel@redhat.com, dgilbert@redhat.com, quintela@redhat.com, armbru@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v3 3/3] pci: ROM preallocation for incoming migration Date: Mon, 15 May 2023 15:52:29 +0300 Message-Id: <20230515125229.44836-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230515125229.44836-1-vsementsov@yandex-team.ru> References: <20230515125229.44836-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: 1684155221863100005 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, like this: Size mismatch: 0000:00:03.0/virtio-net-pci.rom: 0x40000 !=3D 0x80000: I= nvalid argument 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 Let's just ignore ROM file when romsize is specified and we are in incoming migration state. In other words, we need only to preallocate ROM of specified size, local ROM file is unrelated. This way: If romsize was specified on source, we just use same commandline as on source, and migration will work independently of local ROM files on target. If romsize was not specified on source (and we have mismatching local ROM file on target host), we have to specify romsize on target to match source romsize. romfile parameter may be kept same as on source or may be dropped, the file is not loaded anyway. As a bonus we avoid extra reading from ROM file on target. Note: when we don't have romsize parameter on source command line and need it for target, it may be calculated as aligned up to power of two size of ROM file on source (if we know, which file is it) or, alternatively it may be retrieved from source QEMU by QMP qom-get command, like { "execute": "qom-get", "arguments": { "path": "/machine/peripheral/CARD_ID/virtio-net-pci.rom[0]", "property": "size" } } Suggested-by: Michael S. Tsirkin Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: David Hildenbrand Reviewed-by: Juan Quintela --- hw/pci/pci.c | 77 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 3a0107758c..0f0c83c02f 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -36,6 +36,7 @@ #include "migration/vmstate.h" #include "net/net.h" #include "sysemu/numa.h" +#include "sysemu/runstate.h" #include "sysemu/sysemu.h" #include "hw/loader.h" #include "qemu/error-report.h" @@ -2308,10 +2309,16 @@ 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; =20 + /* + * In case of incoming migration ROM will come with migration stream, = no + * reason to load the file. Neither we want to fail if local ROM file + * mismatches with specified romsize. + */ + bool load_file =3D !runstate_check(RUN_STATE_INMIGRATE); + if (!pdev->romfile || !strlen(pdev->romfile)) { return; } @@ -2341,32 +2348,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 || pdev->romsize =3D=3D -1) { + 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)); @@ -2377,15 +2387,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