From nobody Tue Nov 4 18:52:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530814958469344.30867310594044; Thu, 5 Jul 2018 11:22:38 -0700 (PDT) Received: from localhost ([::1]:54279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fb8tp-0005d4-3r for importer@patchew.org; Thu, 05 Jul 2018 14:22:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fb8jj-0007HE-V6 for qemu-devel@nongnu.org; Thu, 05 Jul 2018 14:12:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fb8je-00024H-UX for qemu-devel@nongnu.org; Thu, 05 Jul 2018 14:12:11 -0400 Received: from 11.mo1.mail-out.ovh.net ([188.165.48.29]:57280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fb8je-00023n-Nw for qemu-devel@nongnu.org; Thu, 05 Jul 2018 14:12:06 -0400 Received: from player693.ha.ovh.net (unknown [10.109.122.113]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id EDF24F93AB for ; Thu, 5 Jul 2018 20:12:04 +0200 (CEST) Received: from zorba.kaod.org.com (LFbn-TOU-1-49-10.w86-201.abo.wanadoo.fr [86.201.141.10]) (Authenticated sender: clg@kaod.org) by player693.ha.ovh.net (Postfix) with ESMTPSA id 5D73944009C; Thu, 5 Jul 2018 20:11:58 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 20:11:48 +0200 Message-Id: <20180705181148.26871-1-clg@kaod.org> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 X-Ovh-Tracer-Id: 6878122533675043648 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtiedrfeeggdduvdefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.48.29 Subject: [Qemu-devel] [PATCH] pci: remove pci_del_option_rom() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Peter Xu , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" PCI devices needing a ROM allocate an optional MemoryRegion with pci_add_option_rom(). pci_del_option_rom() does the cleanup when the device is destroyed. The only action taken by this routine is to call vmstate_unregister_ram() which clears the id string of the optional ROM RAMBlock and now, also flags the RAMBlock as non-migratable. This was recently added by commit b895de502717 ("migration: discard non-migratable RAMBlocks"), . VFIO devices do their own allocation of the PCI ROM region. It is initialized in vfio_pci_size_rom() in which the PCI attribute 'has_rom' is set to true but the RAMBlock of the ROM region is not allocated. When the associated PCI device is deleted, pci_del_option_rom() calls vmstate_unregister_ram() which tries to flag a NULL RAMBlock because 'has_rom' is set, leading to a SEGV . The use of vmstate_unregister_ram() in the PCI device was added in commit b0e56e0b63f350691b52d3e75e89bb64143fbeff ("unset RAMBlock idstr when unregister MemoryRegion") and from the archive in http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00282.html, it seems that it was trying to fix a reference count issue. vmstate_unregister_ram() being a work around, let's remove it to fix the current SEGV issue and let's try to find a fix for the initial ref count issue if we can reproduce. Signed-off-by: C=C3=A9dric Le Goater --- hw/pci/pci.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 80bc45930dee..78bf74e19f22 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -191,7 +191,6 @@ static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num= ); static void pci_update_mappings(PCIDevice *d); static void pci_irq_handler(void *opaque, int irq_num, int level); static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, Error= **); -static void pci_del_option_rom(PCIDevice *pdev); =20 static uint16_t pci_default_sub_vendor_id =3D PCI_SUBVENDOR_ID_REDHAT_QUMR= ANET; static uint16_t pci_default_sub_device_id =3D PCI_SUBDEVICE_ID_QEMU; @@ -1096,7 +1095,6 @@ static void pci_qdev_unrealize(DeviceState *dev, Erro= r **errp) PCIDeviceClass *pc =3D PCI_DEVICE_GET_CLASS(pci_dev); =20 pci_unregister_io_regions(pci_dev); - pci_del_option_rom(pci_dev); =20 if (pc->exit) { pc->exit(pci_dev); @@ -2262,15 +2260,6 @@ static void pci_add_option_rom(PCIDevice *pdev, bool= is_default_rom, pci_register_bar(pdev, PCI_ROM_SLOT, 0, &pdev->rom); } =20 -static void pci_del_option_rom(PCIDevice *pdev) -{ - if (!pdev->has_rom) - return; - - vmstate_unregister_ram(&pdev->rom, &pdev->qdev); - pdev->has_rom =3D false; -} - /* * On success, pci_add_capability() returns a positive value * that the offset of the pci capability. --=20 2.13.6