From nobody Fri May 3 16:24:19 2024 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.zoho.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 14949195285361000.2537796539924; Tue, 16 May 2017 00:25:28 -0700 (PDT) Received: from localhost ([::1]:40237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dAWrG-0004SH-M3 for importer@patchew.org; Tue, 16 May 2017 03:25:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dAWqI-0003s8-Gy for qemu-devel@nongnu.org; Tue, 16 May 2017 03:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dAWqD-0004r2-HG for qemu-devel@nongnu.org; Tue, 16 May 2017 03:24:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32878) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dAWqD-0004qs-C4; Tue, 16 May 2017 03:24:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5173104C8; Tue, 16 May 2017 07:24:19 +0000 (UTC) Received: from lemon.redhat.com (vpn1-5-58.pek2.redhat.com [10.72.5.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1838B5C546; Tue, 16 May 2017 07:24:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E5173104C8 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E5173104C8 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 16 May 2017 15:24:14 +0800 Message-Id: <20170516072414.19025-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 16 May 2017 07:24:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] virtio: Move memory_listener_unregister to .unrealize 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: Paolo Bonzini , Jason Wang , qemu-stable@nongnu.org, "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is noticed while working on RHBZ 1449031, and fixes the reported crash which happens when plugging back a virtio-scsi device after unplugging it. The root cause of the crash is not obvious here, but the change regardlessly makes sense so it's proposed here: the listener was registered in .realize(), so do the cleanup in the matching .unrealize() rather than the .finalize() callback. The difference this makes is that, due to some other references to the memory region that is owned here, .finalize() is not called when unplug. (Note that memory_region_ref() does object_ref() on the owner instead of the MemoryRegion itself.) This is something fishy, and is being investigated independently. Signed-off-by: Fam Zheng --- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 03592c5..12604d6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2515,6 +2515,7 @@ static void virtio_device_unrealize(DeviceState *dev,= Error **errp) } } =20 + memory_listener_unregister(&vdev->listener); g_free(vdev->bus_name); vdev->bus_name =3D NULL; } @@ -2539,7 +2540,6 @@ static void virtio_device_instance_finalize(Object *o= bj) { VirtIODevice *vdev =3D VIRTIO_DEVICE(obj); =20 - memory_listener_unregister(&vdev->listener); virtio_device_free_virtqueues(vdev); =20 g_free(vdev->config); --=20 2.9.3