From nobody Tue Feb 10 17:45:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1588255000; cv=none; d=zohomail.com; s=zohoarc; b=UqkHKsRip50Nf3ac7Vx2Zdujk5MdiFsq6BWSCR1PGWqLk9JqWumi0xTat/V4U79/nhLjHGeMMp8QqwL9nF8bVikB6xwJWo/I5WUCmWX1GSukV27qGErqsPsSAovdaMdH4ycY9YfYCBbbc/xPE69RP18YQM6QSWGaOz4r0oM9vQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588255000; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=kUkFhpkmkerAUcEO23m978mFXGVV+mbiJpdw3pimI38=; b=dUBw817fU1Dy/OnF9bECML0ui4JPdUq/KKvOjPTzUqOI80amBX4Qnt7n+5+EtqvlL7l/+bm469wvYYGSEEEjdCN3PtRGspznw9QtomnK8tMo/ElkzEweZPBxA6CJzaxV+qwOmyGhaJ9Lt+X2m52uwxKJSv6DJekurn3PEbrl1+0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158825500091251.943833138741525; Thu, 30 Apr 2020 06:56:40 -0700 (PDT) Received: from localhost ([::1]:41170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jU9g7-0006Po-KA for importer@patchew.org; Thu, 30 Apr 2020 09:56:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49836) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jU9TM-0001BU-Qb for qemu-devel@nongnu.org; Thu, 30 Apr 2020 09:45:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jU9Qd-0008Fi-E8 for qemu-devel@nongnu.org; Thu, 30 Apr 2020 09:43:28 -0400 Received: from forwardcorp1p.mail.yandex.net ([2a02:6b8:0:1472:2741:0:8b6:217]:60108) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jU9NM-0001jK-CA; Thu, 30 Apr 2020 09:37:16 -0400 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 45D5D2E151A; Thu, 30 Apr 2020 16:37:12 +0300 (MSK) Received: from myt4-18a966dbd9be.qloud-c.yandex.net (myt4-18a966dbd9be.qloud-c.yandex.net [2a02:6b8:c00:12ad:0:640:18a9:66db]) by mxbackcorp2j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id SUWv4Mec3s-b7X4UTL4; Thu, 30 Apr 2020 16:37:12 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b080:7108::1:9]) by myt4-18a966dbd9be.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id tZ29y7t6r8-b7WKL4mb; Thu, 30 Apr 2020 16:37:07 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1588253832; bh=kUkFhpkmkerAUcEO23m978mFXGVV+mbiJpdw3pimI38=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=Qi+NXMT6Ijxlj0zDe0PAUGxzXOWda3qxv7gQmA+ZoORjIW3HqEiIYEnUoqlD4tBPI gHfE4/nmIUufy+22SeuwA1PkVA7JXHZZcphUSW4Zh+95uWDEMjSLvNNi219uV8mOCv ADGOrjjqNJk6TK2hZvdvNiJoh6loNHp9n0nL/yoQ= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [PATCH v2 3/5] vhost-user-blk: add mechanism to track the guest notifiers init state Date: Thu, 30 Apr 2020 16:36:18 +0300 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: 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=2a02:6b8:0:1472:2741:0:8b6:217; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/30 09:37:12 X-ACL-Warn: Detected OS = ??? X-Received-From: 2a02:6b8:0:1472:2741:0:8b6:217 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, kwolf@redhat.com, yc-core@yandex-team.ru, qemu-block@nongnu.org, mst@redhat.com, jasowang@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, arei.gonglei@huawei.com, fengli@smartx.com, stefanha@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In case of the vhost-user devices the daemon can be killed at any moment. Since QEMU supports the reconnet functionality the guest notifiers should be reset and disabled after "disconnect" event. The most issues were found if the "disconnect" event happened during vhost device initialization step. The disconnect event leads to the call of the vhost_dev_cleanup() routine. Which memset to 0 a vhost device structure. Because of this, if device was not started (dev.started =3D=3D false) and the connection is broken, then the set_guest_notifier method will produce assertion error. Also connection can be broken after the dev.started field is set to true. A new notifiers_set field is added to the vhost_dev structure to track the state of the guest notifiers during the initialization process. Signed-off-by: Dima Stepanov --- hw/block/vhost-user-blk.c | 8 ++++---- hw/virtio/vhost.c | 11 +++++++++++ include/hw/virtio/vhost.h | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 70d7842..5a3de0f 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -175,7 +175,9 @@ static void vhost_user_blk_stop(VirtIODevice *vdev) return; } =20 - vhost_dev_stop(&s->dev, vdev); + if (s->dev.started) { + vhost_dev_stop(&s->dev, vdev); + } =20 ret =3D vhost_dev_drop_guest_notifiers(&s->dev, vdev, s->dev.nvqs); if (ret < 0) { @@ -337,9 +339,7 @@ static void vhost_user_blk_disconnect(DeviceState *dev) } s->connected =3D false; =20 - if (s->dev.started) { - vhost_user_blk_stop(vdev); - } + vhost_user_blk_stop(vdev); =20 vhost_dev_cleanup(&s->dev); } diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index fa3da9c..ddbdc53 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1380,6 +1380,7 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev= , VirtIODevice *vdev) goto fail_vq; } } + hdev->notifiers_set =3D true; =20 return 0; fail_vq: @@ -1407,6 +1408,10 @@ void vhost_dev_disable_notifiers(struct vhost_dev *h= dev, VirtIODevice *vdev) BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); int i, r; =20 + if (!hdev->notifiers_set) { + return; + } + for (i =3D 0; i < hdev->nvqs; ++i) { r =3D virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_inde= x + i, false); @@ -1417,6 +1422,8 @@ void vhost_dev_disable_notifiers(struct vhost_dev *hd= ev, VirtIODevice *vdev) virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index = + i); } virtio_device_release_ioeventfd(vdev); + + hdev->notifiers_set =3D false; } =20 /* @@ -1449,6 +1456,10 @@ int vhost_dev_drop_guest_notifiers(struct vhost_dev = *hdev, VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret; =20 + if (!hdev->notifiers_set) { + return 0; + } + ret =3D k->set_guest_notifiers(qbus->parent, nvqs, false); if (ret < 0) { error_report("Error reset guest notifier: %d", -ret); diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 4d0d2e2..e3711a7 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -90,6 +90,7 @@ struct vhost_dev { QLIST_HEAD(, vhost_iommu) iommu_list; IOMMUNotifier n; const VhostDevConfigOps *config_ops; + bool notifiers_set; }; =20 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, --=20 2.7.4