From nobody Tue Feb 10 12:59:50 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=1682368657; cv=none; d=zohomail.com; s=zohoarc; b=A1UFqIs5gRTTejHgn+SLEAu2jwxswo+31cJCjtijycon47xmMsQAg9mV0EaxdGCG2hqouBVkPL1qm3aG3M9Jhts0TE0Gxk4GG+6Y+zgXcqJ+EiCbJxEI4GPqk/0F+6BoP2iCQ7uWyn4QxN4YuI4X2Lzmb8jYG1NoWJjNW+wstKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682368657; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=RbjdnH8M16Vfq6Hi7pqef94xRMhfwvbA5tfy+HMf10I=; b=PlCCkyz2OgDR2ll6Ea2UJZqrLJdKdObTiL5ChPYy+smJS+cL+s/XXWfjXcOPb0j3lD/OOKwgFfdnOs9CRO3piPgQAWCDBlCqFddeEN16ey069GNa7BaTMxFphum3YmttL/ai8butRHec8t/mUMSN3oNOvNupgtSIGZ69kerS+vU= 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 168236865701113.796112979813188; Mon, 24 Apr 2023 13:37:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pr2vw-0005iw-O2; Mon, 24 Apr 2023 16:37:12 -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 1pr2vv-0005gP-35 for qemu-devel@nongnu.org; Mon, 24 Apr 2023 16:37:11 -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 1pr2vq-0008Sf-33 for qemu-devel@nongnu.org; Mon, 24 Apr 2023 16:37:10 -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 3DE8D5F3B8; Mon, 24 Apr 2023 23:36:59 +0300 (MSK) Received: from vsementsov-nix.yandex-team.ru (unknown [2a02:6b8:b081:6523::1:a]) by mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id oaMVKO1OoCg0-t1ASXrEB; Mon, 24 Apr 2023 23:36:58 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1682368618; bh=RbjdnH8M16Vfq6Hi7pqef94xRMhfwvbA5tfy+HMf10I=; h=Message-Id:Date:Cc:Subject:To:From; b=v+DKg97++F4a7+dIrrmuiprk62ZULPFSRsonz3hxpokuE95VVWbYXqHhn6J+DnVqe z2+K3ZrmDeVkK3Herlf72jjx5QZkZfdVQ9sLNb7545eEu+gTkcB3gKpT6ao0rbHo7R GQRgyYReE6D43cIhaC185e+piYz1GEuM82QbwXgY= 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: philmd@linaro.org, david@redhat.com, peterx@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH] pci: make ROM memory resizable Date: Mon, 24 Apr 2023 23:36:47 +0300 Message-Id: <20230424203647.94614-1-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 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: 1682368660534100003 Content-Type: text/plain; charset="utf-8" On migration, on target we load local ROM file. But actual ROM content migrates through migration channel. Original ROM content from local file doesn't matter. But when size mismatch - we have an error like Size mismatch: 0000:00:03.0/virtio-net-pci.rom: 0x40000 !=3D 0x80000: Inva= lid argument Let's just allow resizing of ROM memory. This way migration is not relate on local ROM file on target node which is loaded by default but is not actually needed. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/pci/pci.c | 7 +++++-- include/exec/memory.h | 26 ++++++++++++++++++++++++++ softmmu/memory.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index def5000e7b..72ee8f6aea 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -59,6 +59,8 @@ # define PCI_DPRINTF(format, ...) do { } while (0) #endif =20 +#define MAX_ROM_SIZE (2 * GiB) + bool pci_available =3D true; =20 static char *pcibus_get_dev_path(DeviceState *dev); @@ -2341,7 +2343,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool = is_default_rom, error_setg(errp, "romfile \"%s\" is empty", pdev->romfile); g_free(path); return; - } else if (size > 2 * GiB) { + } else if (size > MAX_ROM_SIZE) { error_setg(errp, "romfile \"%s\" too large (size cannot exceed 2 G= iB)", pdev->romfile); g_free(path); @@ -2366,7 +2368,8 @@ static void pci_add_option_rom(PCIDevice *pdev, bool = is_default_rom, 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_resizable(&pdev->rom, OBJECT(pdev), name, + pdev->romsize, MAX_ROM_SIZE, &error_f= atal); 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); diff --git a/include/exec/memory.h b/include/exec/memory.h index 15ade918ba..ed1e5d9126 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1453,6 +1453,19 @@ void memory_region_init_rom_nomigrate(MemoryRegion *= mr, uint64_t size, Error **errp); =20 +/* + * memory_region_init_rom_nomigrate_resizable: same as + * memory_region_init_rom_nomigrate(), but initialize resizable memory reg= ion. + * + * @max_size maximum allowed size. + */ +void memory_region_init_rom_nomigrate_resizable(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + uint64_t max_size, + Error **errp); + /** * memory_region_init_rom_device_nomigrate: Initialize a ROM memory regio= n. * Writes are handled via callbacks. @@ -1562,6 +1575,19 @@ void memory_region_init_rom(MemoryRegion *mr, uint64_t size, Error **errp); =20 +/* + * memory_region_init_rom_resizable: same as memory_region_init_rom(), + * but initialize resizable memory region. + * + * @max_size maximum allowed size. + */ +void memory_region_init_rom_resizable(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + uint64_t max_size, + Error **errp); + /** * memory_region_init_rom_device: Initialize a ROM memory region. * Writes are handled via callbacks. diff --git a/softmmu/memory.c b/softmmu/memory.c index b1a6cae6f5..744d03bc02 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1701,6 +1701,18 @@ void memory_region_init_rom_nomigrate(MemoryRegion *= mr, mr->readonly =3D true; } =20 +void memory_region_init_rom_nomigrate_resizable(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + uint64_t max_size, + Error **errp) +{ + memory_region_init_resizeable_ram(mr, owner, name, size, max_size, NUL= L, + errp); + mr->readonly =3D true; +} + void memory_region_init_rom_device_nomigrate(MemoryRegion *mr, Object *owner, const MemoryRegionOps *ops, @@ -3580,6 +3592,33 @@ void memory_region_init_rom(MemoryRegion *mr, vmstate_register_ram(mr, owner_dev); } =20 +void memory_region_init_rom_resizable(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + uint64_t max_size, + Error **errp) +{ + DeviceState *owner_dev; + Error *err =3D NULL; + + memory_region_init_rom_nomigrate_resizable(mr, owner, name, size, max_= size, + &err); + if (err) { + error_propagate(errp, err); + return; + } + /* + * This will assert if owner is neither NULL nor a DeviceState. + * We only want the owner here for the purposes of defining a + * unique name for migration. TODO: Ideally we should implement + * a naming scheme for Objects which are not DeviceStates, in + * which case we can relax this restriction. + */ + owner_dev =3D DEVICE(owner); + vmstate_register_ram(mr, owner_dev); +} + void memory_region_init_rom_device(MemoryRegion *mr, Object *owner, const MemoryRegionOps *ops, --=20 2.34.1