From nobody Sun Feb 8 14:59:30 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=1587667346; cv=none; d=zohomail.com; s=zohoarc; b=Jy3gQA+e4zkaRxYBAQ33kFNPGzfSLZyDAr/D2T3txFh8YSgO2Z6ARAQO0OFTnqJyJygGYHDhg17l5s5Mx8jwRviFrnqceqXQtdjXFBJgGyHZD6mgz4XSJt8MmXVsz9VaFbyDEudz/MGOmdypICnA5C47WreDvBmTBOCQL1DQMOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587667346; 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=JRPA2qRfYLHHvtZ6OpHLn9WZva7jBBpSVFlB6entX5Y=; b=L2UZL+l7pxNqfEbMCjneGqmzt8OUB97sQP34kYtsF3paI32kKsyqX1KJocrxHX7c3YADK2AkPoTs9KY3fG8+fdrdIV6S4xutYGZafBu7W52waUZ0hkEhS0i1y8UxktaHWTCgpMagmhlgUhhXRYEWpXlhyoT7Xytwlyh7+4FljXQ= 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 1587667346527118.16067355932455; Thu, 23 Apr 2020 11:42:26 -0700 (PDT) Received: from localhost ([::1]:36610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgno-0003RW-Sy for importer@patchew.org; Thu, 23 Apr 2020 14:42:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32804) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgm2-0001Bz-CN for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRgm0-00048y-Sd for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:33 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:50932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRglv-00041N-3k; Thu, 23 Apr 2020 14:40:28 -0400 Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 6C43D2E1586; Thu, 23 Apr 2020 21:40:23 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp1g.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id giirV3zZcH-eKQes9BR; Thu, 23 Apr 2020 21:40:23 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:1313::1:e]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7hClKENKMK-eKXe8ef2; Thu, 23 Apr 2020 21:40:20 +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=1587667223; bh=JRPA2qRfYLHHvtZ6OpHLn9WZva7jBBpSVFlB6entX5Y=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=egp/1UxuO06glmcXb+S5IRXikEW/vosv7gz24c8OCQWXGyqMJFGdNmIT7NjPP/53f jr3wA2MWyZFJ4YHYK0Gkiod6TrfpwMDRMtaqs9V5YV3QjXk9HPvVxx9HlZckHjK2X9 rNttMD3WRlADluHQB5IuKmYrquHt7oFKveHNWeaU= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [RFC PATCH v1 1/7] contrib/vhost-user-blk: add option to simulate disconnect on init Date: Thu, 23 Apr 2020 21:39:32 +0300 Message-Id: <52a4ae2d18ee0d810355d84ab83623a2e9ffa405.1587667007.git.dimastep@yandex-team.ru> 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:1a2d::193; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:6b8:0:1a2d::193 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, 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" Add "--simulate-disconnect-stage" option for the testing purposes. This option can be used to test the vhost-user reconnect functionality: ./vhost-user-blk ... --simulate-disconnect-stage=3D In this case the daemon will "crash" in the middle of the VHOST comands communication. Case nums are as follows: 1 - make assert in the handler of the SET_VRING_CALL command 2 - make assert in the handler of the SET_VRING_NUM command Main purpose is to test QEMU reconnect functionality. Such fail injection should not lead to QEMU crash and should be handled successfully. Also update the "GOptionEntry entries" definition with the final NULL item according to API. Signed-off-by: Dima Stepanov --- contrib/libvhost-user/libvhost-user.c | 30 ++++++++++++++++++++++++++++++ contrib/libvhost-user/libvhost-user.h | 13 +++++++++++++ contrib/vhost-user-blk/vhost-user-blk.c | 14 +++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index 3bca996..5215214 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -73,6 +73,14 @@ #define VHOST_USER_VERSION 1 #define LIBVHOST_USER_DEBUG 0 =20 +/* + * Inject fail in different places in daemon. This will trigger different + * paths in QEMU. Main purpose is to test the reconnect functionality + * during vhost initialization step. + */ +#define VHOST_SDISCONNECT_SET_VRING_CALL 1 +#define VHOST_SDISCONNECT_SET_VRING_NUM 2 + #define DPRINT(...) \ do { \ if (LIBVHOST_USER_DEBUG) { \ @@ -861,6 +869,11 @@ vu_set_vring_num_exec(VuDev *dev, VhostUserMsg *vmsg) DPRINT("State.index: %d\n", index); DPRINT("State.num: %d\n", num); dev->vq[index].vring.num =3D num; + if (dev->simulate_init_disconnect =3D=3D VHOST_SDISCONNECT_SET_VRING_N= UM) { + DPRINT("Simulate vhost daemon crash during initialization.\n"); + assert(0); + return false; + } =20 return false; } @@ -1161,6 +1174,13 @@ vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vms= g) =20 DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64); =20 + /* Simulate crash during initialization. */ + if (dev->simulate_init_disconnect =3D=3D VHOST_SDISCONNECT_SET_VRING_C= ALL) { + DPRINT("Simulate vhost daemon crash during initialization.\n"); + assert(0); + return false; + } + if (!vu_check_queue_msg_file(dev, vmsg)) { return false; } @@ -2073,6 +2093,16 @@ vu_queue_empty(VuDev *dev, VuVirtq *vq) return vring_avail_idx(vq) =3D=3D vq->last_avail_idx; } =20 +/* + * Set the flag to simulate the vhost-user daemon crash during + * initialization. This is used to test reconnect functionality. + */ +void +vu_simulate_init_disconnect(VuDev *dev, int should_simulate) +{ + dev->simulate_init_disconnect =3D should_simulate; +} + static bool vring_notify(VuDev *dev, VuVirtq *vq) { diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/= libvhost-user.h index f30394f..9f75e86 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -388,6 +388,9 @@ struct VuDev { /* Postcopy data */ int postcopy_ufd; bool postcopy_listening; + + /* Fields to simulate test cases. */ + int simulate_init_disconnect; }; =20 typedef struct VuVirtqElement { @@ -645,4 +648,14 @@ void vu_queue_get_avail_bytes(VuDev *vdev, VuVirtq *vq= , unsigned int *in_bytes, bool vu_queue_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int in_bytes, unsigned int out_bytes); =20 +/** + * vu_simulate_init_disconnect: + * @dev: a VuDev context + * @should_simulate: expected simulation behaviour (true or false) + * + * Set the flag to simulate the vhost-user daemon crash during + * initialization. This is used to test reconnect functionality. + */ +void vu_simulate_init_disconnect(VuDev *dev, int should_simulate); + #endif /* LIBVHOST_USER_H */ diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index 6fd91c7..6ac37ca 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -581,6 +581,7 @@ static char *opt_socket_path; static char *opt_blk_file; static gboolean opt_print_caps; static gboolean opt_read_only; +static gboolean opt_simulate_disconnect; =20 static GOptionEntry entries[] =3D { { "print-capabilities", 'c', 0, G_OPTION_ARG_NONE, &opt_print_caps, @@ -592,7 +593,14 @@ static GOptionEntry entries[] =3D { {"blk-file", 'b', 0, G_OPTION_ARG_FILENAME, &opt_blk_file, "block device or file path", "PATH"}, { "read-only", 'r', 0, G_OPTION_ARG_NONE, &opt_read_only, - "Enable read-only", NULL } + "Enable read-only", NULL }, + { "simulate-disconnect-stage", 0, 0, G_OPTION_ARG_INT, + &opt_simulate_disconnect, + "Simulate disconnect during initialization for the testing purposes.= \n" + "\t1 - make assert in the handler of the SET_VRING_CALL command\n" + "\t2 - make assert in the handler of the SET_VRING_NUM command\n", + "CASENUM" }, + { NULL }, }; =20 int main(int argc, char **argv) @@ -656,6 +664,10 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } =20 + /* Set testing flags. */ + vu_simulate_init_disconnect(&vdev_blk->parent.parent, + opt_simulate_disconnect); + g_main_loop_run(vdev_blk->loop); g_main_loop_unref(vdev_blk->loop); g_option_context_free(context); --=20 2.7.4 From nobody Sun Feb 8 14:59:30 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=1587667482; cv=none; d=zohomail.com; s=zohoarc; b=JzU/OgCET6FY0QsfiqB4DVCJUag6HauOcLISLwfgr1Lq9+lNb1k4nLRY+BEvsY5XtcdVg2E3ZD5aBa8GQ9wiWkBf0smlx74hkK6cLKi37ioki9+hBDdnsFgyKW153A1iEgGcnA4B2dVGxRY8L5xE955R4h3qlKLwcQn2leBklTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587667482; 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=B7N/2dA22AZAvZEuIRWbfaStgxBZh00/dxecx4k5Xoo=; b=ec9W837bnLx2X/+CfPcQjIJDSUu1hxNwoyhPjAAG0A8sSzF5CAOUDcSC5g8h20iQnK5WfHgMBMTRs2NkQZhsgDQN10Rrrn4cdZPL+px7EQ0HZXWBUQ83agKOKOuJ9fst5eJ5mgA9UkQpTruP4USS0v6jM4PCfF1SVTbwgEVDCzU= 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 1587667482367451.82798097474426; Thu, 23 Apr 2020 11:44:42 -0700 (PDT) Received: from localhost ([::1]:36812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgq0-0007Yv-Vy for importer@patchew.org; Thu, 23 Apr 2020 14:44:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32864) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgm6-0001Ey-Fq for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRgm5-0004H3-Co for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:38 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:59726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRglz-00047x-DX; Thu, 23 Apr 2020 14:40:32 -0400 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id D93A42E15A0; Thu, 23 Apr 2020 21:40:28 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp2j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id 4Q2WEpocS5-ePHG0SlV; Thu, 23 Apr 2020 21:40:28 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:1313::1:e]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7hClKENKMK-ePXeQsK8; Thu, 23 Apr 2020 21:40:25 +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=1587667228; bh=B7N/2dA22AZAvZEuIRWbfaStgxBZh00/dxecx4k5Xoo=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=aNH86gMKIwBn1nP3+YXa+yUgGPoCL0SrDDFS/SoBX9HI/loBxTiScvTv/fv5mTivg OFdCdMBPeM3fhQZlz4G8S0vct+OiIakflnp7JN/vqUbpS5DZrXkdzgC6jObzBKPGxt mYOHEq7nSoVUPGhNwxTOd1XIzyWZXltIa9mOVlxQ= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [RFC PATCH v1 2/7] char-socket: return -1 in case of disconnect during tcp_chr_write Date: Thu, 23 Apr 2020 21:39:33 +0300 Message-Id: <045f356cec6f07300819d28457a2bb8876d1c887.1587667007.git.dimastep@yandex-team.ru> 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=95.108.205.193; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/23 14:40:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 95.108.205.193 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, 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" During testing of the vhost-user-blk reconnect functionality the qemu SIGSEGV was triggered: start qemu as: x86_64-softmmu/qemu-system-x86_64 -m 1024M -M q35 \ -object memory-backend-file,id=3Dram-node0,size=3D1024M,mem-path=3D/dev/= shm/qemu,share=3Don \ -numa node,cpus=3D0,memdev=3Dram-node0 \ -chardev socket,id=3Dchardev0,path=3D./vhost.sock,noserver,reconnect=3D1= \ -device vhost-user-blk-pci,chardev=3Dchardev0,num-queues=3D4 --enable-kvm start vhost-user-blk daemon: ./vhost-user-blk -s ./vhost.sock -b test-img.raw If vhost-user-blk will be killed during the vhost initialization process, for instance after getting VHOST_SET_VRING_CALL command, then QEMU will fail with the following backtrace: Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x00005555559272bb in vhost_user_read (dev=3D0x7fffef2d53e0, msg=3D0x7fffff= ffd5b0) at ./hw/virtio/vhost-user.c:260 260 CharBackend *chr =3D u->user->chr; #0 0x00005555559272bb in vhost_user_read (dev=3D0x7fffef2d53e0, msg=3D0x7= fffffffd5b0) at ./hw/virtio/vhost-user.c:260 #1 0x000055555592acb8 in vhost_user_get_config (dev=3D0x7fffef2d53e0, con= fig=3D0x7fffef2d5394 "", config_len=3D60) at ./hw/virtio/vhost-user.c:1645 #2 0x0000555555925525 in vhost_dev_get_config (hdev=3D0x7fffef2d53e0, con= fig=3D0x7fffef2d5394 "", config_len=3D60) at ./hw/virtio/vhost.c:1490 #3 0x00005555558cc46b in vhost_user_blk_device_realize (dev=3D0x7fffef2d5= 1a0, errp=3D0x7fffffffd8f0) at ./hw/block/vhost-user-blk.c:429 #4 0x0000555555920090 in virtio_device_realize (dev=3D0x7fffef2d51a0, err= p=3D0x7fffffffd948) at ./hw/virtio/virtio.c:3615 #5 0x0000555555a9779c in device_set_realized (obj=3D0x7fffef2d51a0, value= =3Dtrue, errp=3D0x7fffffffdb88) at ./hw/core/qdev.c:891 ... The problem is that vhost_user_write doesn't get an error after disconnect and try to call vhost_user_read(). The tcp_chr_write() routine should return -1 in case of disconnect. Indicate the EIO error if this routine is called in the disconnected state. Signed-off-by: Dima Stepanov --- chardev/char-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 185fe38..c128cca 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -175,14 +175,16 @@ static int tcp_chr_write(Chardev *chr, const uint8_t = *buf, int len) if (ret < 0 && errno !=3D EAGAIN) { if (tcp_chr_read_poll(chr) <=3D 0) { tcp_chr_disconnect_locked(chr); - return len; + /* Return an error since we made a disconnect. */ + return ret; } /* else let the read handler finish it properly */ } =20 return ret; } else { - /* XXX: indicate an error ? */ - return len; + /* Indicate an error. */ + errno =3D EIO; + return -1; } } =20 --=20 2.7.4 From nobody Sun Feb 8 14:59:30 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=1587667346; cv=none; d=zohomail.com; s=zohoarc; b=dmOzx6LI+pXc7RORIAMsguxwvbH7z/0jq7vahvu4cv3Xx0ilm4/JeWbdFhg5TTzpsQl9T7OX56sXUQnxYJwW/bGAt7k/9FY72OypTFtqLM1S/cabB87dIZ44YZW9AcZzouAtgVyuPh0iBIoGF2WcqArOsUw9YyFFzEAdSW4czhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587667346; 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=6AUSdMRun+4uomw8GjlwQJKUpFkMPJnEm3m4a1og08I=; b=Yhc8Iz3mfG6tCm2/KHUWnKT9MEBYPIfDZZTgadtcbzmbMX2kvjlTvZBjFNZs+YifygcX2ScLogV/wdEXe8tz11vEtRhKx5S9PKcXexJ4qZYhLx9MpLyjjy71b2DlMeZmoCxkuUArEPn1K3GpzwzUUQxkGZCK+c+fd5z/vqPb8+k= 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 1587667346278425.3182528816959; Thu, 23 Apr 2020 11:42:26 -0700 (PDT) Received: from localhost ([::1]:36608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgno-0003Ps-Uc for importer@patchew.org; Thu, 23 Apr 2020 14:42:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32868) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgm6-0001FF-RO for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRgm6-0004KE-FK for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:38 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:45238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRgm2-00048m-TR; Thu, 23 Apr 2020 14:40:36 -0400 Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 65C3C2E150C; Thu, 23 Apr 2020 21:40:32 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp1g.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id GEhWYPOk17-eUQmj5PB; Thu, 23 Apr 2020 21:40:32 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:1313::1:e]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7hClKENKMK-eUXeJJgf; Thu, 23 Apr 2020 21:40:30 +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=1587667232; bh=6AUSdMRun+4uomw8GjlwQJKUpFkMPJnEm3m4a1og08I=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=YiqtKcBHfLkbWDYhZ0Vcu+Ouj4kWCtgKHPx5Q2WwYgmVXB6mef08ag3YYDDzdlG63 2Z/PaAXBnSbhxgkqPrtC2hXs3Tv382XV4PAshynUzX1kbqhklJFRFCGqTWns+C6c78 fjaBdB3LtScf2B/NeHdQHtIl7tsKD5mlb6l5gPeA= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [RFC PATCH v1 3/7] char-socket: initialize reconnect timer only if close is emitted Date: Thu, 23 Apr 2020 21:39:34 +0300 Message-Id: <23b36a73ce1150cc501f436684ca558608de3322.1587667007.git.dimastep@yandex-team.ru> 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=77.88.29.217; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/23 14:40:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 77.88.29.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, 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" During vhost-user reconnect functionality testing the following assert was hit: qemu-system-x86_64: chardev/char-socket.c:125: qemu_chr_socket_restart_timer: Assertion `!s->reconnect_timer' failed. Aborted (core dumped) This is observed only if the connection is closed by the vhost-user-blk daemon during the initialization routine. In this case the tcp_chr_disconnect_locked() routine is called twice. First time it is called in the tcp_chr_write() routine, after getting the SIGPIPE signal. Second time it is called when vhost_user_blk_connect() routine return error. In general it looks correct, because the initialization routine can return error in many cases. The tcp_chr_disconnect_locked() routine could be fixed. The timer will be restarted only if the close event is emitted. Signed-off-by: Dima Stepanov --- chardev/char-socket.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index c128cca..83ca4d9 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -476,7 +476,7 @@ static void update_disconnected_filename(SocketChardev = *s) static void tcp_chr_disconnect_locked(Chardev *chr) { SocketChardev *s =3D SOCKET_CHARDEV(chr); - bool emit_close =3D s->state =3D=3D TCP_CHARDEV_STATE_CONNECTED; + bool was_connected =3D s->state =3D=3D TCP_CHARDEV_STATE_CONNECTED; =20 tcp_chr_free_connection(chr); =20 @@ -485,11 +485,11 @@ static void tcp_chr_disconnect_locked(Chardev *chr) chr, NULL, chr->gcontext); } update_disconnected_filename(s); - if (emit_close) { + if (was_connected) { qemu_chr_be_event(chr, CHR_EVENT_CLOSED); - } - if (s->reconnect_time) { - qemu_chr_socket_restart_timer(chr); + if (s->reconnect_time) { + qemu_chr_socket_restart_timer(chr); + } } } =20 --=20 2.7.4 From nobody Sun Feb 8 14:59:30 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=1587667471; cv=none; d=zohomail.com; s=zohoarc; b=hGSEcfM2uu7NjxExFQWpWzI0Unm00TZsviBUMknXrAGnSmzs1R7iNssMxSbeDmpq9VaMM1VCd7vR3UadKuZ/DeioDZ6O41Aq8KhqOp+pxc7Q3Hdt6lmv1PNpxZanuSbHOV+AdikjnRcBO94Zq866cIanBYd1H9quw7Ww4hQDT08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587667471; 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=/03BgTwU/psEMUgiBdmqNYh7VlIfn2pdgG96rmbifE4=; b=Nh1Yo9YBgR3X9ny+aKKWZYygpxMHiRLEvwfUjEaPOUchqh9pnowJMPLAB+gYtq66KqbLBMTIZpgdbKUfRHqWyNn3RInQzes4v2WC20jj+fJAGno3WS8Dj0wt7Y/WX+CirYV2YIECbFmUZfCZIMocDAT9oGjuLnDfFaYdbtwPb68= 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 1587667471047478.8689483610365; Thu, 23 Apr 2020 11:44:31 -0700 (PDT) Received: from localhost ([::1]:36800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgpp-0007HK-MK for importer@patchew.org; Thu, 23 Apr 2020 14:44:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32902) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgmB-0001Hq-2O for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRgm9-0004W6-Vv for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:42 -0400 Received: from forwardcorp1p.mail.yandex.net ([2a02:6b8:0:1472:2741:0:8b6:217]:46980) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRgm6-0004EK-Hx; Thu, 23 Apr 2020 14:40:38 -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 46DE32E150B; Thu, 23 Apr 2020 21:40:36 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp2j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id WNXL47K6ek-eXHeXm5I; Thu, 23 Apr 2020 21:40:36 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:1313::1:e]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7hClKENKMK-eXXeVA3o; Thu, 23 Apr 2020 21:40:33 +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=1587667236; bh=/03BgTwU/psEMUgiBdmqNYh7VlIfn2pdgG96rmbifE4=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=yYbBu7FWt+zJ+GVyTZuw4ERXVRJm6Bxpcz84NOQaz5eu9S451HXTVJKPYNxoOez19 Me7mjeDqe9tq7XXBzoiCv3riPhipup/k4JdvHrYer8KXddILJ4/o4sYlb+roPF7xdN xBJ1N+hrWOhdp/U11fbw/Y/e/NN+URRT8EsMVOW0= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [RFC PATCH v1 4/7] vhost: introduce wrappers to set guest notifiers for virtio device Date: Thu, 23 Apr 2020 21:39:35 +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/23 14:40:14 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, 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" Introduce new wrappers to set/reset guest notifiers for the virtio device in the vhost device module: vhost_dev_assign_guest_notifiers ->set_guest_notifiers(..., ..., true); vhost_dev_drop_guest_notifiers ->set_guest_notifiers(..., ..., false); This is a preliminary step to refactor code, so the set_guest_notifiers methods could be called based on the vhost device state. Update all vhost used devices to use these wrappers instead of direct method call. Signed-off-by: Dima Stepanov --- backends/cryptodev-vhost.c | 26 +++++++++++++++----------- backends/vhost-user.c | 16 +++++----------- hw/block/vhost-user-blk.c | 15 +++++---------- hw/net/vhost_net.c | 30 +++++++++++++++++------------- hw/scsi/vhost-scsi-common.c | 15 +++++---------- hw/virtio/vhost-user-fs.c | 17 +++++++---------- hw/virtio/vhost-vsock.c | 18 ++++++++---------- hw/virtio/vhost.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio.c | 13 +++++++++++++ include/hw/virtio/vhost.h | 4 ++++ include/hw/virtio/virtio.h | 1 + 11 files changed, 118 insertions(+), 75 deletions(-) diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 8337c9a..4522195 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -169,16 +169,13 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc, int cryptodev_vhost_start(VirtIODevice *dev, int total_queues) { VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(dev); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); - VirtioBusState *vbus =3D VIRTIO_BUS(qbus); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); int r, e; int i; CryptoDevBackend *b =3D vcrypto->cryptodev; CryptoDevBackendVhost *vhost_crypto; CryptoDevBackendClient *cc; =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(dev)) { error_report("binding does not support guest notifiers"); return -ENOSYS; } @@ -198,9 +195,13 @@ int cryptodev_vhost_start(VirtIODevice *dev, int total= _queues) } } =20 - r =3D k->set_guest_notifiers(qbus->parent, total_queues, true); + /* + * Since all the states are handled by one vhost device, + * use the first one in array. + */ + vhost_crypto =3D cryptodev_get_vhost(b->conf.peers.ccs[0], b, 0); + r =3D vhost_dev_assign_guest_notifiers(&vhost_crypto->dev, dev, total_= queues); if (r < 0) { - error_report("error binding guest notifier: %d", -r); goto err; } =20 @@ -232,7 +233,8 @@ err_start: vhost_crypto =3D cryptodev_get_vhost(cc, b, i); cryptodev_vhost_stop_one(vhost_crypto, dev); } - e =3D k->set_guest_notifiers(qbus->parent, total_queues, false); + vhost_crypto =3D cryptodev_get_vhost(b->conf.peers.ccs[0], b, 0); + e =3D vhost_dev_drop_guest_notifiers(&vhost_crypto->dev, dev, total_qu= eues); if (e < 0) { error_report("vhost guest notifier cleanup failed: %d", e); } @@ -242,9 +244,6 @@ err: =20 void cryptodev_vhost_stop(VirtIODevice *dev, int total_queues) { - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); - VirtioBusState *vbus =3D VIRTIO_BUS(qbus); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(dev); CryptoDevBackend *b =3D vcrypto->cryptodev; CryptoDevBackendVhost *vhost_crypto; @@ -259,7 +258,12 @@ void cryptodev_vhost_stop(VirtIODevice *dev, int total= _queues) cryptodev_vhost_stop_one(vhost_crypto, dev); } =20 - r =3D k->set_guest_notifiers(qbus->parent, total_queues, false); + /* + * Since all the states are handled by one vhost device, + * use the first one in array. + */ + vhost_crypto =3D cryptodev_get_vhost(b->conf.peers.ccs[0], b, 0); + r =3D vhost_dev_drop_guest_notifiers(&vhost_crypto->dev, dev, total_qu= eues); if (r < 0) { error_report("vhost guest notifier cleanup failed: %d", r); } diff --git a/backends/vhost-user.c b/backends/vhost-user.c index 2bf3406..e116bc6 100644 --- a/backends/vhost-user.c +++ b/backends/vhost-user.c @@ -60,15 +60,13 @@ vhost_user_backend_dev_init(VhostUserBackend *b, VirtIO= Device *vdev, void vhost_user_backend_start(VhostUserBackend *b) { - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(b->vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret, i ; =20 if (b->started) { return; } =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(b->vdev)) { error_report("binding does not support guest notifiers"); return; } @@ -78,9 +76,8 @@ vhost_user_backend_start(VhostUserBackend *b) return; } =20 - ret =3D k->set_guest_notifiers(qbus->parent, b->dev.nvqs, true); + ret =3D vhost_dev_assign_guest_notifiers(&b->dev, b->vdev, b->dev.nvqs= ); if (ret < 0) { - error_report("Error binding guest notifier"); goto err_host_notifiers; } =20 @@ -104,7 +101,7 @@ vhost_user_backend_start(VhostUserBackend *b) return; =20 err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, b->dev.nvqs, false); + vhost_dev_drop_guest_notifiers(&b->dev, b->vdev, b->dev.nvqs); err_host_notifiers: vhost_dev_disable_notifiers(&b->dev, b->vdev); } @@ -112,8 +109,6 @@ err_host_notifiers: void vhost_user_backend_stop(VhostUserBackend *b) { - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(b->vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret =3D 0; =20 if (!b->started) { @@ -122,9 +117,8 @@ vhost_user_backend_stop(VhostUserBackend *b) =20 vhost_dev_stop(&b->dev, b->vdev); =20 - if (k->set_guest_notifiers) { - ret =3D k->set_guest_notifiers(qbus->parent, - b->dev.nvqs, false); + if (virtio_device_guest_notifiers_initialized(b->vdev)) { + ret =3D vhost_dev_drop_guest_notifiers(&b->dev, b->vdev, b->dev.nv= qs); if (ret < 0) { error_report("vhost guest notifier cleanup failed: %d", ret); } diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 17df533..70d7842 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -109,11 +109,9 @@ const VhostDevConfigOps blk_ops =3D { static int vhost_user_blk_start(VirtIODevice *vdev) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int i, ret; =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(vdev)) { error_report("binding does not support guest notifiers"); return -ENOSYS; } @@ -124,9 +122,8 @@ static int vhost_user_blk_start(VirtIODevice *vdev) return ret; } =20 - ret =3D k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true); + ret =3D vhost_dev_assign_guest_notifiers(&s->dev, vdev, s->dev.nvqs); if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); goto err_host_notifiers; } =20 @@ -163,7 +160,7 @@ static int vhost_user_blk_start(VirtIODevice *vdev) return ret; =20 err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); + vhost_dev_drop_guest_notifiers(&s->dev, vdev, s->dev.nvqs); err_host_notifiers: vhost_dev_disable_notifiers(&s->dev, vdev); return ret; @@ -172,17 +169,15 @@ err_host_notifiers: static void vhost_user_blk_stop(VirtIODevice *vdev) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret; =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(vdev)) { return; } =20 vhost_dev_stop(&s->dev, vdev); =20 - ret =3D k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); + ret =3D vhost_dev_drop_guest_notifiers(&s->dev, vdev, s->dev.nvqs); if (ret < 0) { error_report("vhost guest notifier cleanup failed: %d", ret); return; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803..c13b444 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -303,19 +303,15 @@ static void vhost_net_stop_one(struct vhost_net *net, int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues) { - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); - VirtioBusState *vbus =3D VIRTIO_BUS(qbus); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + struct vhost_net *net; int r, e, i; =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(dev)) { error_report("binding does not support guest notifiers"); return -ENOSYS; } =20 for (i =3D 0; i < total_queues; i++) { - struct vhost_net *net; - net =3D get_vhost_net(ncs[i].peer); vhost_net_set_vq_index(net, i * 2); =20 @@ -328,9 +324,13 @@ int vhost_net_start(VirtIODevice *dev, NetClientState = *ncs, } } =20 - r =3D k->set_guest_notifiers(qbus->parent, total_queues * 2, true); + /* + * Since all the states are handled by one vhost_net device, + * use the first one in array. + */ + net =3D get_vhost_net(ncs[0].peer); + r =3D vhost_dev_assign_guest_notifiers(&net->dev, dev, total_queues * = 2); if (r < 0) { - error_report("Error binding guest notifier: %d", -r); goto err; } =20 @@ -357,7 +357,8 @@ err_start: while (--i >=3D 0) { vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); } - e =3D k->set_guest_notifiers(qbus->parent, total_queues * 2, false); + net =3D get_vhost_net(ncs[0].peer); + e =3D vhost_dev_drop_guest_notifiers(&net->dev, dev, total_queues * 2); if (e < 0) { fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", e); fflush(stderr); @@ -369,16 +370,19 @@ err: void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, int total_queues) { - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); - VirtioBusState *vbus =3D VIRTIO_BUS(qbus); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + struct vhost_net *net; int i, r; =20 for (i =3D 0; i < total_queues; i++) { vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); } =20 - r =3D k->set_guest_notifiers(qbus->parent, total_queues * 2, false); + /* + * Since all the states are handled by one vhost_net device, + * use the first one in array. + */ + net =3D get_vhost_net(ncs[0].peer); + r =3D vhost_dev_drop_guest_notifiers(&net->dev, dev, total_queues * 2); if (r < 0) { fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r); fflush(stderr); diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index 8ec49d7..8f51ec0 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -29,10 +29,8 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) { int ret, i; VirtIODevice *vdev =3D VIRTIO_DEVICE(vsc); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(vdev)) { error_report("binding does not support guest notifiers"); return -ENOSYS; } @@ -42,9 +40,8 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) return ret; } =20 - ret =3D k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, true); + ret =3D vhost_dev_assign_guest_notifiers(&vsc->dev, vdev, vsc->dev.nvq= s); if (ret < 0) { - error_report("Error binding guest notifier"); goto err_host_notifiers; } =20 @@ -66,7 +63,7 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) return ret; =20 err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false); + vhost_dev_drop_guest_notifiers(&vsc->dev, vdev, vsc->dev.nvqs); err_host_notifiers: vhost_dev_disable_notifiers(&vsc->dev, vdev); return ret; @@ -75,14 +72,12 @@ err_host_notifiers: void vhost_scsi_common_stop(VHostSCSICommon *vsc) { VirtIODevice *vdev =3D VIRTIO_DEVICE(vsc); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret =3D 0; =20 vhost_dev_stop(&vsc->dev, vdev); =20 - if (k->set_guest_notifiers) { - ret =3D k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false); + if (virtio_device_guest_notifiers_initialized(vdev)) { + ret =3D vhost_dev_drop_guest_notifiers(&vsc->dev, vdev, vsc->dev.n= vqs); if (ret < 0) { error_report("vhost guest notifier cleanup failed: %d", re= t); } diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 6136768..6b101fc 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -38,12 +38,10 @@ static void vuf_get_config(VirtIODevice *vdev, uint8_t = *config) static void vuf_start(VirtIODevice *vdev) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret; int i; =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(vdev)) { error_report("binding does not support guest notifiers"); return; } @@ -54,9 +52,9 @@ static void vuf_start(VirtIODevice *vdev) return; } =20 - ret =3D k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, true); + ret =3D vhost_dev_assign_guest_notifiers(&fs->vhost_dev, vdev, + fs->vhost_dev.nvqs); if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); goto err_host_notifiers; } =20 @@ -79,7 +77,7 @@ static void vuf_start(VirtIODevice *vdev) return; =20 err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false); + vhost_dev_drop_guest_notifiers(&fs->vhost_dev, vdev, fs->vhost_dev.nvq= s); err_host_notifiers: vhost_dev_disable_notifiers(&fs->vhost_dev, vdev); } @@ -87,17 +85,16 @@ err_host_notifiers: static void vuf_stop(VirtIODevice *vdev) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret; =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(vdev)) { return; } =20 vhost_dev_stop(&fs->vhost_dev, vdev); =20 - ret =3D k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false= ); + ret =3D vhost_dev_drop_guest_notifiers(&fs->vhost_dev, vdev, + fs->vhost_dev.nvqs); if (ret < 0) { error_report("vhost guest notifier cleanup failed: %d", ret); return; diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index 09b6b07..52489dd 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -75,12 +75,10 @@ static int vhost_vsock_set_running(VHostVSock *vsock, i= nt start) static void vhost_vsock_start(VirtIODevice *vdev) { VHostVSock *vsock =3D VHOST_VSOCK(vdev); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret; int i; =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(vdev)) { error_report("binding does not support guest notifiers"); return; } @@ -91,9 +89,9 @@ static void vhost_vsock_start(VirtIODevice *vdev) return; } =20 - ret =3D k->set_guest_notifiers(qbus->parent, vsock->vhost_dev.nvqs, tr= ue); + ret =3D vhost_dev_assign_guest_notifiers(&vsock->vhost_dev, + vdev, vsock->vhost_dev.nvqs); if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); goto err_host_notifiers; } =20 @@ -123,7 +121,8 @@ static void vhost_vsock_start(VirtIODevice *vdev) err_dev_start: vhost_dev_stop(&vsock->vhost_dev, vdev); err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, vsock->vhost_dev.nvqs, false); + vhost_dev_drop_guest_notifiers(&vsock->vhost_dev, + vdev, vsock->vhost_dev.nvqs); err_host_notifiers: vhost_dev_disable_notifiers(&vsock->vhost_dev, vdev); } @@ -131,11 +130,9 @@ err_host_notifiers: static void vhost_vsock_stop(VirtIODevice *vdev) { VHostVSock *vsock =3D VHOST_VSOCK(vdev); - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret; =20 - if (!k->set_guest_notifiers) { + if (!virtio_device_guest_notifiers_initialized(vdev)) { return; } =20 @@ -147,7 +144,8 @@ static void vhost_vsock_stop(VirtIODevice *vdev) =20 vhost_dev_stop(&vsock->vhost_dev, vdev); =20 - ret =3D k->set_guest_notifiers(qbus->parent, vsock->vhost_dev.nvqs, fa= lse); + ret =3D vhost_dev_drop_guest_notifiers(&vsock->vhost_dev, + vdev, vsock->vhost_dev.nvqs); if (ret < 0) { error_report("vhost guest notifier cleanup failed: %d", ret); return; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 01ebe12..fa3da9c 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1419,6 +1419,44 @@ void vhost_dev_disable_notifiers(struct vhost_dev *h= dev, VirtIODevice *vdev) virtio_device_release_ioeventfd(vdev); } =20 +/* + * Assign guest notifiers. + * Should be called after vhost_dev_enable_notifiers. + */ +int vhost_dev_assign_guest_notifiers(struct vhost_dev *hdev, + VirtIODevice *vdev, int nvqs) +{ + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + ret =3D k->set_guest_notifiers(qbus->parent, nvqs, true); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + } + + return ret; +} + +/* + * Drop guest notifiers. + * Should be called before vhost_dev_disable_notifiers. + */ +int vhost_dev_drop_guest_notifiers(struct vhost_dev *hdev, + VirtIODevice *vdev, int nvqs) +{ + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + ret =3D k->set_guest_notifiers(qbus->parent, nvqs, false); + if (ret < 0) { + error_report("Error reset guest notifier: %d", -ret); + } + + return ret; +} + /* Test and clear event pending status. * Should be called after unmask to avoid losing events. */ diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b6c8ef5..8a95618 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3812,6 +3812,19 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *v= dev) return virtio_bus_ioeventfd_enabled(vbus); } =20 +/* + * Check if set_guest_notifiers() method is set by the init routine. + * Return true if yes, otherwise return false. + */ +bool virtio_device_guest_notifiers_initialized(VirtIODevice *vdev) +{ + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + + return k->set_guest_notifiers; +} + + static const TypeInfo virtio_device_info =3D { .name =3D TYPE_VIRTIO_DEVICE, .parent =3D TYPE_DEVICE, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 085450c..4d0d2e2 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -100,6 +100,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevi= ce *vdev); void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vde= v); +int vhost_dev_assign_guest_notifiers(struct vhost_dev *hdev, + VirtIODevice *vdev, int nvqs); +int vhost_dev_drop_guest_notifiers(struct vhost_dev *hdev, + VirtIODevice *vdev, int nvqs); =20 /* Test and clear masked event pending status. * Should be called after unmask to avoid losing events. diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b69d517..d9a3d72 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -323,6 +323,7 @@ void virtio_queue_aio_set_host_notifier_handler(VirtQue= ue *vq, AioContext *ctx, VirtIOHandleAIOOutput hand= le_output); VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector); VirtQueue *virtio_vector_next_queue(VirtQueue *vq); +bool virtio_device_guest_notifiers_initialized(VirtIODevice *vdev); =20 static inline void virtio_add_feature(uint64_t *features, unsigned int fbi= t) { --=20 2.7.4 From nobody Sun Feb 8 14:59:30 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=1587667353; cv=none; d=zohomail.com; s=zohoarc; b=dK8pLK/8VYUR/nXbIbH6IYy2Tj4OG1WbVswSRkn4s/KCMUqy1tcBiOgr7zPHOlTMb+FvEKQiX+AkSWSXJu0szNoGsEsjhMAL/ZS+ozYe/6QCfM5WW6aSenEyyHytzd2jqYL4zxIVyKjeTTvZ6RTyrqP5PT6MyoPCXzVbQtUhJNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587667353; 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=R7NvJBb1VmfwJo6Y6QyCYiC8OzXJexIac2SYFJDTu1niT4M3Yf1A8Op9DhsWtT/sHFTo8WXNiuQlEINn3cVa2mOWP9agWD5MMwBRbPoTYz4xvpNLoMlKvXzuHRIebCxsrg8Ou/fRgDMSMrmnla+/OlEJL794M7dSa0Z9IqUXdtc= 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 1587667353237222.2207547754649; Thu, 23 Apr 2020 11:42:33 -0700 (PDT) Received: from localhost ([::1]:36628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgnv-0003mV-MJ for importer@patchew.org; Thu, 23 Apr 2020 14:42:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32934) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgmH-0001QP-Sd for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRgmF-0004cX-RP for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:49 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:39718) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRgmC-0004RL-By; Thu, 23 Apr 2020 14:40:44 -0400 Received: from mxbackcorp1j.mail.yandex.net (mxbackcorp1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::162]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id B9EA52E14D8; Thu, 23 Apr 2020 21:40:39 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp1j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id isFjwdZvjU-ebnqUoRv; Thu, 23 Apr 2020 21:40:39 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:1313::1:e]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7hClKENKMK-ebXe7FTd; Thu, 23 Apr 2020 21:40:37 +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=1587667239; bh=kUkFhpkmkerAUcEO23m978mFXGVV+mbiJpdw3pimI38=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=UIT+lm92VMZpQj/L6p8co1vHO9irvJwzojPjl5cG9z9xmmsYV7igt8q4T13iFTeMe CUNJYKJfvdUVfDUD0mPXKfwZEICkPNJmE7076evfyJ/ANPXmeFajrr/XOIrztdBtMR lQYWh6QNDOcOMayT4S8uxDFg9p5yeOpA6/9hcBxw= Authentication-Results: mxbackcorp1j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [RFC PATCH v1 5/7] vhost-user-blk: add mechanism to track the guest notifiers init state Date: Thu, 23 Apr 2020 21:39:36 +0300 Message-Id: <4bd32763095d015bc83f1f11a871d3a8e7b36e01.1587667007.git.dimastep@yandex-team.ru> 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:1619::183; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:6b8:0:1619::183 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, 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 From nobody Sun Feb 8 14:59:30 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=1587667601; cv=none; d=zohomail.com; s=zohoarc; b=B0JNFu610Fk2qGJ9WqL4NgB7gRNSU0MAFb80gaXDpKpTTGszpypIHKIBzgkRhmA3zikewiFoZNTJpeXGyQhtoSqppz3Hu25QWQK03mGFdw3GhWBVCfKWVnAjraEOH29pmD7qJrU0Peb+mSeyC/AhB3It1ogALJSs0WoSg/4UM4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587667601; 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=5FKUZYsWXSmWGJbzPGJ+rs4aPqD/ORGDojQy3boMTtI=; b=YFxqjXUy/veZbEyDPRTyvNd7w+0CXzknW0DBSDspr5+1y0pfYrrXNvStXynLGzIp85CUt9sf9XULbKZvUXysH8tmBgGCcqTsXBl9Pa41F1rzpCN4qjcqF7SEK4C2t/v4DOPxhjFU78PDMZvzn2YKFdmZ/MhyeiIhiaajcMKS8zM= 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 1587667601883432.90689497718836; Thu, 23 Apr 2020 11:46:41 -0700 (PDT) Received: from localhost ([::1]:36966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgrw-0002IY-KY for importer@patchew.org; Thu, 23 Apr 2020 14:46:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32968) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgmJ-0001WE-V7 for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRgmI-0004g3-Fm for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:51 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:39752) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRgmD-0004YU-RO; Thu, 23 Apr 2020 14:40:47 -0400 Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id ACA512E14E5; Thu, 23 Apr 2020 21:40:42 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp1o.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id pcbgbebQ4k-efJusTgp; Thu, 23 Apr 2020 21:40:42 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:1313::1:e]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7hClKENKMK-eeXeQske; Thu, 23 Apr 2020 21:40:40 +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=1587667242; bh=5FKUZYsWXSmWGJbzPGJ+rs4aPqD/ORGDojQy3boMTtI=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=rMobuxyHc5x4g6A2pejKni5IaV8SRrbf+O1fcjyDAZhhN4mT+0BG5n42RjHD/JB6O juaZ878nkfrXoMoLW7Ov+8gpAkyd1AyVlc/gdysTZtrZWE8e51cBlTNRe0lLcowl7N /KTorukp4wIxxpVLM8CqAqYt2W+D5i1zZ2/Wwp4w= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [RFC PATCH v1 6/7] vhost: check vring address before calling unmap Date: Thu, 23 Apr 2020 21:39:37 +0300 Message-Id: <696f43b4883f0ce1d3695458653da885f7693692.1587667007.git.dimastep@yandex-team.ru> 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:1619::183; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:6b8:0:1619::183 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, 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" Since disconnect can happen at any time during initialization not all vring buffers (for instance used vring) can be intialized successfully. If the buffer was not initialized then vhost_memory_unmap call will lead to SIGSEGV. Add checks for the vring address value before calling unmap. Also add assert() in the vhost_memory_unmap() routine. Signed-off-by: Dima Stepanov --- hw/virtio/vhost.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ddbdc53..3ee50c4 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -314,6 +314,8 @@ static void vhost_memory_unmap(struct vhost_dev *dev, v= oid *buffer, hwaddr len, int is_write, hwaddr access_len) { + assert(buffer); + if (!vhost_dev_has_iommu(dev)) { cpu_physical_memory_unmap(buffer, len, is_write, access_len); } @@ -1132,12 +1134,25 @@ static void vhost_virtqueue_stop(struct vhost_dev *= dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx= ), - 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), - 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), - 0, virtio_queue_get_desc_size(vdev, idx)); + /* + * Since the vhost-user disconnect can happen during initialization + * check if vring was initialized, before making unmap. + */ + if (vq->used) { + vhost_memory_unmap(dev, vq->used, + virtio_queue_get_used_size(vdev, idx), + 1, virtio_queue_get_used_size(vdev, idx)); + } + if (vq->avail) { + vhost_memory_unmap(dev, vq->avail, + virtio_queue_get_avail_size(vdev, idx), + 0, virtio_queue_get_avail_size(vdev, idx)); + } + if (vq->desc) { + vhost_memory_unmap(dev, vq->desc, + virtio_queue_get_desc_size(vdev, idx), + 0, virtio_queue_get_desc_size(vdev, idx)); + } } =20 static void vhost_eventfd_add(MemoryListener *listener, --=20 2.7.4 From nobody Sun Feb 8 14:59:30 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=1587667605; cv=none; d=zohomail.com; s=zohoarc; b=TC5ixzapc++FT0Vlu0HaJcqA11cRTKy0OfDSFDhnIi4Jl9c1YOJi4Usx8N/CsDI6V6kXazSYg7PrvUOqOsV+uq1DSkAYYemH/0oWZ4luQdUqbWiLb4rKbjEKB6Zm6fjs1Q1txlknu7lXCsoe80ZkI9g7FxfxsLnzKRvoEYAdIQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587667605; 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=Fv6pZWWviC9Gnz6pDjZHVEUsXW2GPb2wYw220Nlajio=; b=BQj7M3XboZq8sScGe1gGBTKxI7h3bvnzI4PuL3AxteIZg1C8mGF2cn2QEHrMRLJQ8Y/ak/p/xR5HTc116ZPhys3hip4QW6leuOdCZDE2C3r441ms2wxrZ6ass4Pjbj4tIeZLjSSfardcZN4niPzRwhWDZTfM0JAiO3PAIG502QA= 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 1587667605817904.9635519255238; Thu, 23 Apr 2020 11:46:45 -0700 (PDT) Received: from localhost ([::1]:36968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgs0-0002Sk-Hf for importer@patchew.org; Thu, 23 Apr 2020 14:46:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32974) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgmK-0001Y0-Gk for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRgmJ-0004io-TV for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:52 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:59924) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRgmH-0004c0-Bt; Thu, 23 Apr 2020 14:40:49 -0400 Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 8E8A22E15CB; Thu, 23 Apr 2020 21:40:46 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp1g.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id vIyfhVYIID-eiQCVYfP; Thu, 23 Apr 2020 21:40:46 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:1313::1:e]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7hClKENKMK-ehXewq95; Thu, 23 Apr 2020 21:40:43 +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=1587667246; bh=Fv6pZWWviC9Gnz6pDjZHVEUsXW2GPb2wYw220Nlajio=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=oqR/GfWbX7A3DDl+ut8AlJdXeTWoGoZ6mxLR8tsz5wAo6XhSD3pP6BhAmg/26HjZ/ sSp67J+CeKR/M8QUTiGtxLQWWgkPzud5Cng9m7m/feWaMT4MSkFCQB38DoxUNvUZ6B j2BloZ0FlBSaYTnG/gDTd0QHg86CRYYR88azjZNg= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [RFC PATCH v1 7/7] vhost: add device started check in migration set log Date: Thu, 23 Apr 2020 21:39:38 +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=95.108.205.193; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/23 14:40:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 95.108.205.193 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, 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" If vhost-user daemon is used as a backend for the vhost device, then we should consider a possibility of disconnect at any moment. If such disconnect happened in the vhost_migration_log() routine the vhost device structure will be clean up. At the start of the vhost_migration_log() function there is a check: if (!dev->started) { dev->log_enabled =3D enable; return 0; } To be consistent with this check add the same check after calling the vhost_dev_set_log() routine. This in general help not to break a migration due the assert() message. But it looks like that this code should be revised to handle these errors more carefully. In case of vhost-user device backend the fail paths should consider the state of the device. In this case we should skip some function calls during rollback on the error paths, so not to get the NULL dereference errors. Signed-off-by: Dima Stepanov --- hw/virtio/vhost.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 3ee50c4..d5ab96d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -787,6 +787,17 @@ static int vhost_dev_set_features(struct vhost_dev *de= v, static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log) { int r, i, idx; + + if (!dev->started) { + /* + * If vhost-user daemon is used as a backend for the + * device and the connection is broken, then the vhost_dev + * structure will be reset all its values to 0. + * Add additional check for the device state. + */ + return -1; + } + r =3D vhost_dev_set_features(dev, enable_log); if (r < 0) { goto err_features; @@ -801,12 +812,19 @@ static int vhost_dev_set_log(struct vhost_dev *dev, b= ool enable_log) } return 0; err_vq: - for (; i >=3D 0; --i) { + /* + * Disconnect with the vhost-user daemon can lead to the + * vhost_dev_cleanup() call which will clean up vhost_dev + * structure. + */ + for (; dev->started && (i >=3D 0); --i) { idx =3D dev->vhost_ops->vhost_get_vq_index(dev, dev->vq_index + i); vhost_virtqueue_set_addr(dev, dev->vqs + i, idx, dev->log_enabled); } - vhost_dev_set_features(dev, dev->log_enabled); + if (dev->started) { + vhost_dev_set_features(dev, dev->log_enabled); + } err_features: return r; } @@ -832,7 +850,15 @@ static int vhost_migration_log(MemoryListener *listene= r, int enable) } else { vhost_dev_log_resize(dev, vhost_get_log_size(dev)); r =3D vhost_dev_set_log(dev, true); - if (r < 0) { + /* + * The dev log resize can fail, because of disconnect + * with the vhost-user-blk daemon. Check the device + * state before calling the vhost_dev_set_log() + * function. + * Don't return error if device isn't started to be + * consistent with the check above. + */ + if (dev->started && r < 0) { return r; } } @@ -1739,7 +1765,12 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) fail_log: vhost_log_put(hdev, false); fail_vq: - while (--i >=3D 0) { + /* + * Disconnect with the vhost-user daemon can lead to the + * vhost_dev_cleanup() call which will clean up vhost_dev + * structure. + */ + while ((--i >=3D 0) && (hdev->started)) { vhost_virtqueue_stop(hdev, vdev, hdev->vqs + i, --=20 2.7.4