From nobody Tue May 7 13:56:22 2024 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=1616685416; cv=none; d=zohomail.com; s=zohoarc; b=aRIMomznKRIzAC3mflWMbU3SlWkH8k8lKe6IIyupAIRmiJm1bhd8sQdhILakHYy4Y872GxpZoPh+Y+8OxDcFa5xbZKrQEbgt8QzvbOmEWQ/Wbk0sQHfHQnzuDeKRd/yCsoiWDbaCYWhlJjJzUBz+o+k+4ntA4HUwzTMk18Zl5S8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685416; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hBzrSLh8wifxU2O9BusH9ecMk35sqRl8yAeQIM+ZXKo=; b=U0Gu74isb5kIejkxcC7MVCcEveo9eTgNVyv76nCKxECdsu0QX+aebJDNnWPrH5A3jlhoBYFUJjo5bXYHN5mfDG/0ExGVFfIGrmd0GU00NaYLMKYa6GoCOncED0VM30m5EARrUPaMV9uas6PTy+L+iKoPYIYV3Q5VLB6wQvdIreg= 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 1616685416655801.3215346245709; Thu, 25 Mar 2021 08:16:56 -0700 (PDT) Received: from localhost ([::1]:55936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRjC-0007gd-3r for importer@patchew.org; Thu, 25 Mar 2021 11:16:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRf6-0002qM-8k; Thu, 25 Mar 2021 11:12:40 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:36674) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRf1-00022K-IJ; Thu, 25 Mar 2021 11:12:39 -0400 Received: from iva8-d077482f1536.qloud-c.yandex.net (iva8-d077482f1536.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:2f26:0:640:d077:482f]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 15A3F2E16B0; Thu, 25 Mar 2021 18:12:29 +0300 (MSK) Received: from iva8-5ba4ca89b0c6.qloud-c.yandex.net (iva8-5ba4ca89b0c6.qloud-c.yandex.net [2a02:6b8:c0c:a8ae:0:640:5ba4:ca89]) by iva8-d077482f1536.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id 1UX54ZKLeG-CScG9HV3; Thu, 25 Mar 2021 18:12:29 +0300 Received: from dynamic-iva.dhcp.yndx.net (dynamic-iva.dhcp.yndx.net [2a02:6b8:b080:8801::1:8]) by iva8-5ba4ca89b0c6.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ejfhBn90eX-CSpGF4iT; Thu, 25 Mar 2021 18:12:28 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1616685149; bh=hBzrSLh8wifxU2O9BusH9ecMk35sqRl8yAeQIM+ZXKo=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=QlYFKJjUJK9rfeIVNaggP5IM9dnY2aOTPfsLOBI1bfjpvP1io3S8O5oGBni7lk1iF dNpqiaYpOWqfSuCb8F+RrkuTwmrPzuXCqsKfAA4AOFLhLJ/uuBZqFDbz8jn2Oh+xzd oL8N/4Q2XZyuq6VLiKkKvCSRYD5l6XTX8Z4893Us= Authentication-Results: iva8-d077482f1536.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v3 1/3] vhost-user-blk: use different event handlers on initialization Date: Thu, 25 Mar 2021 18:12:15 +0300 Message-Id: <20210325151217.262793-2-den-plotnikov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210325151217.262793-1-den-plotnikov@yandex-team.ru> References: <20210325151217.262793-1-den-plotnikov@yandex-team.ru> 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=95.108.205.193; envelope-from=den-plotnikov@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: kwolf@redhat.com, qemu-block@nongnu.org, mst@redhat.com, raphael.norwitz@nutanix.com, yc-core@yandex-team.ru, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It is useful to use different connect/disconnect event handlers on device initialization and operation as seen from the further commit fixing a bug on device initialization. This patch refactors the code to make use of them: we don't rely any more on the VM state for choosing how to cleanup the device, instead we explicitly use the proper event handler depending on whether the device has been initialized. Signed-off-by: Denis Plotnikov Reviewed-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index b870a50e6b20..1af95ec6aae7 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -362,7 +362,18 @@ static void vhost_user_blk_disconnect(DeviceState *dev) vhost_dev_cleanup(&s->dev); } =20 -static void vhost_user_blk_event(void *opaque, QEMUChrEvent event); +static void vhost_user_blk_event(void *opaque, QEMUChrEvent event, + bool realized); + +static void vhost_user_blk_event_realize(void *opaque, QEMUChrEvent event) +{ + vhost_user_blk_event(opaque, event, false); +} + +static void vhost_user_blk_event_oper(void *opaque, QEMUChrEvent event) +{ + vhost_user_blk_event(opaque, event, true); +} =20 static void vhost_user_blk_chr_closed_bh(void *opaque) { @@ -371,11 +382,12 @@ static void vhost_user_blk_chr_closed_bh(void *opaque) VHostUserBlk *s =3D VHOST_USER_BLK(vdev); =20 vhost_user_blk_disconnect(dev); - qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, - NULL, opaque, NULL, true); + qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, + vhost_user_blk_event_oper, NULL, opaque, NULL, true); } =20 -static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) +static void vhost_user_blk_event(void *opaque, QEMUChrEvent event, + bool realized) { DeviceState *dev =3D opaque; VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -406,7 +418,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrE= vent event) * TODO: maybe it is a good idea to make the same fix * for other vhost-user devices. */ - if (runstate_is_running()) { + if (realized) { AioContext *ctx =3D qemu_get_current_aio_context(); =20 qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, NULL, @@ -473,8 +485,9 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); s->connected =3D false; =20 - qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_even= t, - NULL, (void *)dev, NULL, true); + qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, + vhost_user_blk_event_realize, NULL, (void *)d= ev, + NULL, true); =20 reconnect: if (qemu_chr_fe_wait_connected(&s->chardev, &err) < 0) { @@ -494,6 +507,10 @@ reconnect: goto reconnect; } =20 + /* we're fully initialized, now we can operate, so change the handler = */ + qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, + vhost_user_blk_event_oper, NULL, (void *)dev, + NULL, true); return; =20 virtio_err: --=20 2.25.1 From nobody Tue May 7 13:56:22 2024 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=1616685362; cv=none; d=zohomail.com; s=zohoarc; b=hnx2beTB5gnw3YetREpqYw0oNfyyh9IT/7hQ3UvGkagFFKbhl3niuflleOWUal+rvHX794wgszZE2SULpCTGphLpOr0a7Jcl5hSaw1Dsf2qZBVLoArjc25/1kTZlbPhOaiMOcx1PRDDMzdrvIQtTMrQfuLFuHdkhXtJRxdTXEWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685362; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=itg4Ry9/PNT5O6A6BfVOofOV+P9ACZcn+TZbuL6Y4k4=; b=eGvOCVRc2ydk7S3gN+7mibPtUo1BElwjyQFBUO8qaO2S/FNUSRl3Anw4/nKNU0g9McBjubGO7NMUYk7+TIM9jslgFDpkiNrwDQUQw3PMXQy/xvlcOcaHU0b2uXxsvKJX3YdFPwo4S9KafXtk+/FecE7QptDh1U93kgDVu6hlvzk= 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 161668536199425.64071953397513; Thu, 25 Mar 2021 08:16:01 -0700 (PDT) Received: from localhost ([::1]:49464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRgx-0004yL-EZ for importer@patchew.org; Thu, 25 Mar 2021 11:14:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRf5-0002oX-Do; Thu, 25 Mar 2021 11:12:39 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:42596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRf1-00022O-Oy; Thu, 25 Mar 2021 11:12:37 -0400 Received: from iva8-d077482f1536.qloud-c.yandex.net (iva8-d077482f1536.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:2f26:0:640:d077:482f]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 189C22E1EDD; Thu, 25 Mar 2021 18:12:30 +0300 (MSK) Received: from iva8-5ba4ca89b0c6.qloud-c.yandex.net (iva8-5ba4ca89b0c6.qloud-c.yandex.net [2a02:6b8:c0c:a8ae:0:640:5ba4:ca89]) by iva8-d077482f1536.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id 0qPe26HcVC-CTcek9RU; Thu, 25 Mar 2021 18:12:30 +0300 Received: from dynamic-iva.dhcp.yndx.net (dynamic-iva.dhcp.yndx.net [2a02:6b8:b080:8801::1:8]) by iva8-5ba4ca89b0c6.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ejfhBn90eX-CTpGLOE0; Thu, 25 Mar 2021 18:12:29 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1616685150; bh=itg4Ry9/PNT5O6A6BfVOofOV+P9ACZcn+TZbuL6Y4k4=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=R8drwq+09d+a0wDnywT/hVck/sC47Kwc/4Myr6d+Ov6JKCbqLzH7FFi7PfvfRYYWj dsXN6Gx+f09JRO+jdGQ54LGOgMXrPbJIXyZtwr0lNx2C8TzVYTghy5CDzpQdhGcOQS 4BZXFzZcew5VikGg6b8kmJokSny+ul3Q6BacEgM0= Authentication-Results: iva8-d077482f1536.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v3 2/3] vhost-user-blk: perform immediate cleanup if disconnect on initialization Date: Thu, 25 Mar 2021 18:12:16 +0300 Message-Id: <20210325151217.262793-3-den-plotnikov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210325151217.262793-1-den-plotnikov@yandex-team.ru> References: <20210325151217.262793-1-den-plotnikov@yandex-team.ru> 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=5.45.199.163; envelope-from=den-plotnikov@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: kwolf@redhat.com, qemu-block@nongnu.org, mst@redhat.com, raphael.norwitz@nutanix.com, yc-core@yandex-team.ru, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit 4bcad76f4c39 ("vhost-user-blk: delay vhost_user_blk_disconnect") introduced postponing vhost_dev cleanup aiming to eliminate qemu aborts because of connection problems with vhost-blk daemon. However, it introdues a new problem. Now, any communication errors during execution of vhost_dev_init() called by vhost_user_blk_device_realiz= e() lead to qemu abort on assert in vhost_dev_get_config(). This happens because vhost_user_blk_disconnect() is postponed but it should have dropped s->connected flag by the time vhost_user_blk_device_realize() performs a new connection opening. On the connection opening, vhost_dev initialization in vhost_user_blk_connect() relies on s->connection flag and if it's not dropped, it skips vhost_dev initialization and returns with success. Then, vhost_user_blk_device_realize()'s execution flow goes to vhost_dev_get_config() where it's aborted on the assert. To fix the problem this patch adds immediate cleanup on device initialization(in vhost_user_blk_device_realize()) using different event handlers for initialization and operation introduced in the previous patch. On initialization (in vhost_user_blk_device_realize()) we fully control the initialization process. At that point, nobody can use the device since it isn't initialized and we don't need to postpone any cleanups, so we can do cleaup right away when there is a communication problem with the vhost-blk daemon. On operation we leave it as is, since the disconnect may happen when the device is in use, so the device users may want to use vhost_dev's data to do rollback before vhost_dev is re-initialized (e.g. in vhost_dev_set_lo= g()). Signed-off-by: Denis Plotnikov Reviewed-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1af95ec6aae7..4e215f71f152 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -402,38 +402,38 @@ static void vhost_user_blk_event(void *opaque, QEMUCh= rEvent event, break; case CHR_EVENT_CLOSED: /* - * A close event may happen during a read/write, but vhost - * code assumes the vhost_dev remains setup, so delay the - * stop & clear. There are two possible paths to hit this - * disconnect event: - * 1. When VM is in the RUN_STATE_PRELAUNCH state. The - * vhost_user_blk_device_realize() is a caller. - * 2. In tha main loop phase after VM start. - * - * For p2 the disconnect event will be delayed. We can't - * do the same for p1, because we are not running the loop - * at this moment. So just skip this step and perform - * disconnect in the caller function. - * - * TODO: maybe it is a good idea to make the same fix - * for other vhost-user devices. + * Closing the connection should happen differently on device + * initialization and operation stages. + * On initalization, we want to re-start vhost_dev initialization + * from the very beginning right away when the connection is close= d, + * so we clean up vhost_dev on each connection closing. + * On operation, we want to postpone vhost_dev cleanup to let the + * other code perform its own cleanup sequence using vhost_dev data + * (e.g. vhost_dev_set_log). */ if (realized) { + /* + * A close event may happen during a read/write, but vhost + * code assumes the vhost_dev remains setup, so delay the + * stop & clear. + */ AioContext *ctx =3D qemu_get_current_aio_context(); =20 qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, NULL, NULL, NULL, false); aio_bh_schedule_oneshot(ctx, vhost_user_blk_chr_closed_bh, opa= que); - } =20 - /* - * Move vhost device to the stopped state. The vhost-user device - * will be clean up and disconnected in BH. This can be useful in - * the vhost migration code. If disconnect was caught there is an - * option for the general vhost code to get the dev state without - * knowing its type (in this case vhost-user). - */ - s->dev.started =3D false; + /* + * Move vhost device to the stopped state. The vhost-user devi= ce + * will be clean up and disconnected in BH. This can be useful= in + * the vhost migration code. If disconnect was caught there is= an + * option for the general vhost code to get the dev state with= out + * knowing its type (in this case vhost-user). + */ + s->dev.started =3D false; + } else { + vhost_user_blk_disconnect(dev); + } break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: --=20 2.25.1 From nobody Tue May 7 13:56:22 2024 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=1616685835; cv=none; d=zohomail.com; s=zohoarc; b=DvEY4/j0fcdXglmc3ML7F6xtkBgAoPEW1olC9vX5lsQbbL8Kiu/MHfNRBtX2Hxe6DOxqJUPK3N51vhbpKz1utTlcVduSjIY8WYnWNvHnqj6NKbIjIn/bknQ6rUGIlkJb/uKqa2CL54PLAQ+JizoDscXDN9SudquFeiMU2Q47ZvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685835; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J40X7fGjL6wxtX5+1zKmuMvVb84EJ3YemoNOHPHEgsg=; b=RKEUJPR3IAwEh0XaBY/b8L94jGgO3HRbjBIbHbJ0YFHLKCUhVY3hfQlQsee7o61cS2aklsakmgnqQNMCQH8Jwy+Fyd3eR8hjXaHEu1/YHgEZRw2UNiIzdgYXgxQcnmL92kOq/r3eXss4BU7nQWuYTXVEBIsumcgD1H8+8mckAgU= 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 1616685835868326.67206362975594; Thu, 25 Mar 2021 08:23:55 -0700 (PDT) Received: from localhost ([::1]:45446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRpy-0006rK-J6 for importer@patchew.org; Thu, 25 Mar 2021 11:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRf5-0002pI-Ik; Thu, 25 Mar 2021 11:12:39 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:36734) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRf2-000233-Ch; Thu, 25 Mar 2021 11:12:39 -0400 Received: from iva8-d077482f1536.qloud-c.yandex.net (iva8-d077482f1536.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:2f26:0:640:d077:482f]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 8EE3E2E16BC; Thu, 25 Mar 2021 18:12:31 +0300 (MSK) Received: from iva8-5ba4ca89b0c6.qloud-c.yandex.net (iva8-5ba4ca89b0c6.qloud-c.yandex.net [2a02:6b8:c0c:a8ae:0:640:5ba4:ca89]) by iva8-d077482f1536.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id Pmx4LxF5Hu-CVcGk4DP; Thu, 25 Mar 2021 18:12:31 +0300 Received: from dynamic-iva.dhcp.yndx.net (dynamic-iva.dhcp.yndx.net [2a02:6b8:b080:8801::1:8]) by iva8-5ba4ca89b0c6.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ejfhBn90eX-CUpGZwl9; Thu, 25 Mar 2021 18:12:30 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1616685151; bh=J40X7fGjL6wxtX5+1zKmuMvVb84EJ3YemoNOHPHEgsg=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=xq3sbP56uQV2uD1/MZX72fEfuw+6g+pouSjWfwM00lRz/NlnLlTzEhIc5KtZvCkKi d6XjxaFFGCtgTw9eolpwyKk+aXDXelazp6EA8OmnxEeqlLsUxqHG+ecCv2iJUD89dy tPfAWfpb9WMuo0N/UlEIivOb9CU51R/UmLW0KqYc= Authentication-Results: iva8-d077482f1536.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v3 3/3] vhost-user-blk: add immediate cleanup on shutdown Date: Thu, 25 Mar 2021 18:12:17 +0300 Message-Id: <20210325151217.262793-4-den-plotnikov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210325151217.262793-1-den-plotnikov@yandex-team.ru> References: <20210325151217.262793-1-den-plotnikov@yandex-team.ru> 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=95.108.205.193; envelope-from=den-plotnikov@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: kwolf@redhat.com, qemu-block@nongnu.org, mst@redhat.com, raphael.norwitz@nutanix.com, yc-core@yandex-team.ru, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Qemu crashes on shutdown if the chardev used by vhost-user-blk has been finalized before the vhost-user-blk. This happens with char-socket chardev operating in the listening mode (serv= er). The char-socket chardev emits "close" event at the end of finalizing when its internal data is destroyed. This calls vhost-user-blk event handler which in turn tries to manipulate with destroyed chardev by setting an empty event handler for vhost-user-blk cleanup postponing. This patch separates the shutdown case from the cleanup postponing removing the need to set an event handler. Signed-off-by: Denis Plotnikov --- hw/block/vhost-user-blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 4e215f71f152..0b5b9d44cdb0 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -411,7 +411,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrE= vent event, * other code perform its own cleanup sequence using vhost_dev data * (e.g. vhost_dev_set_log). */ - if (realized) { + if (realized && !runstate_check(RUN_STATE_SHUTDOWN)) { /* * A close event may happen during a read/write, but vhost * code assumes the vhost_dev remains setup, so delay the --=20 2.25.1