From nobody Sun Apr 28 07:49:05 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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537979908143736.4115444682526; Wed, 26 Sep 2018 09:38:28 -0700 (PDT) Received: from localhost ([::1]:59775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5CpG-0004eG-RK for importer@patchew.org; Wed, 26 Sep 2018 12:38:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5CoO-0003pD-38 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 12:37:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5CoK-0008Lx-4k for qemu-devel@nongnu.org; Wed, 26 Sep 2018 12:37:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34232) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5CoJ-0008LU-TB for qemu-devel@nongnu.org; Wed, 26 Sep 2018 12:37:12 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11D9DC0587FF for ; Wed, 26 Sep 2018 16:37:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-98.ams2.redhat.com [10.36.116.98]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCC3760BE1; Wed, 26 Sep 2018 16:37:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2AAA311385F2; Wed, 26 Sep 2018 18:37:09 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 18:37:09 +0200 Message-Id: <20180926163709.22876-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 26 Sep 2018 16:37:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] ivshmem: Fix unplug of device "ivshmem-plain" 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: pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit 2aece63c8a "hostmem: detect host backend memory is being used properly" fixed "ivshmem-plain" to reject memory backends that are already in use, and to block their deletion while in use. Two bugs escaped review: * New ivshmem_plain_exit() fails to call ivshmem_exit(). This breaks unplug. Reproducer: migration after unplug still fails with "Migration is disabled when using feature 'peer mode' in device 'ivshmem'". * It failed to update legacy "ivshmem". Harmless, because it creates the memory backend itself, and nothing else should use it. Fix by moving the two host_memory_backend_set_mapped() calls into ivshmem_common_realize() and ivshmem_exit(), guarded by s->hostmem. Fixes: 2aece63c8a9d2c3a8ff41d2febc4cdeff2633331 Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Paolo Bonzini --- hw/misc/ivshmem.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 6febbabcaa..8cb17b9dd4 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -911,6 +911,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Erro= r **errp) IVSHMEM_DPRINTF("using hostmem\n"); =20 s->ivshmem_bar2 =3D host_memory_backend_get_memory(s->hostmem); + host_memory_backend_set_mapped(s->hostmem, true); } else { Chardev *chr =3D qemu_chr_fe_get_driver(&s->server_chr); assert(chr); @@ -993,6 +994,10 @@ static void ivshmem_exit(PCIDevice *dev) vmstate_unregister_ram(s->ivshmem_bar2, DEVICE(dev)); } =20 + if (s->hostmem) { + host_memory_backend_set_mapped(s->hostmem, false); + } + if (s->peers) { for (i =3D 0; i < s->nb_peers; i++) { close_peer_eventfds(s, i); @@ -1101,14 +1106,6 @@ static void ivshmem_plain_realize(PCIDevice *dev, Er= ror **errp) } =20 ivshmem_common_realize(dev, errp); - host_memory_backend_set_mapped(s->hostmem, true); -} - -static void ivshmem_plain_exit(PCIDevice *pci_dev) -{ - IVShmemState *s =3D IVSHMEM_COMMON(pci_dev); - - host_memory_backend_set_mapped(s->hostmem, false); } =20 static void ivshmem_plain_class_init(ObjectClass *klass, void *data) @@ -1117,7 +1114,6 @@ static void ivshmem_plain_class_init(ObjectClass *kla= ss, void *data) PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); =20 k->realize =3D ivshmem_plain_realize; - k->exit =3D ivshmem_plain_exit; dc->props =3D ivshmem_plain_properties; dc->vmsd =3D &ivshmem_plain_vmsd; } --=20 2.17.1