From nobody Sat May 18 19:48:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1695123890; cv=none; d=zohomail.com; s=zohoarc; b=miEkxz70xrP9UWGv/mO4fxU0yFT6aO5IAoHdaik3SNvZhYzThA3liST54nsdukbtkeSJ4bKfJkFvQKDigKIqrNthJMGCD5s1mbnWjfB8hBTYx6FgKWr7x7IOKIHbR1Ii8GckwHUCQRoIsnwM9ABkL4XglXvLTTEN5edk9w5Xtls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695123890; 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=1eP8kuKM1qKZ8jHbFZXOAaKaPzBH+J+kNlsheIRdgb4=; b=ioTdhUzHFngwmAwEpdXS2LJdnHMi6C8RtpyeICfio5DXSuzkAR9lUKXedCG1n7eswdF78bw/eOOvbeRkjAR+Pi+1st0ih8w7wvpELjAt8oKLhcZWuG+OMxOf4XK4FRAu8MafZ/hdCHN4hHsPMSH3pgOddl+9pbZPrnOl31lyFV4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695123890582132.6716384012327; Tue, 19 Sep 2023 04:44:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiZ8M-0007lN-BU; Tue, 19 Sep 2023 07:43:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiZ8K-0007jI-EG for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:12 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiZ8H-0004F5-Ly for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:12 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68cbbff84f6so4612244b3a.1 for ; Tue, 19 Sep 2023 04:41:07 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id z24-20020aa791d8000000b006887be16675sm8487030pfa.205.2023.09.19.04.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1695123666; x=1695728466; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1eP8kuKM1qKZ8jHbFZXOAaKaPzBH+J+kNlsheIRdgb4=; b=2FDAJ/Sjvj5cC34b2BOMzs+MSk8wJXfzy3liqTv0cKTuODnEKCrHil8btN0zvO1V52 kmdLLuLFdfxpG+uOa+iYPOC/5QGOZ0u4WjeqrrvKYsxQp3SwgaVARNH2WUuiYFbgHX+C 70HCgm088xPXa+Jca771ykN2ukA+oRcSVtramvIJLIlmvUJezj5Pn68UAY2VIW+meKgK 2y6z9fPrbls0iEbR5kbXpasn5Ld+/BsW+ZzQrtOMd9a9+KGC7w4uPnuG4potL+xk+rQs NA7uLpodbyXu62ocY8lROb8W0NdfXgmh8zdZKbdiKT/+buT8RknVTydmWctyiq1nst0E VJ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695123666; x=1695728466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1eP8kuKM1qKZ8jHbFZXOAaKaPzBH+J+kNlsheIRdgb4=; b=sY6S80TJDzPGsNCyqyQia19R15ZzsM+tzySH6hrv9GPEZ2O1EDc3cSvl9x7PG6alZu AUkFTyOPIHexEkpRo8GD8iy8Kv79Ue0LY4f3hWroYNHWMK27idppOA6C3mdfW923b9pE JQDNsyZJBXbxgzPA24uM/6s3TJaxpJaBYe8kmmS8A1WuJ3yPRbEx/crhI6TJe+NVy0OO nuZDPDF40uGu0uGx4pTgb6vWraGpztxYRKf5ae7VOrdAa831tV8TFIyUWRDoflS03lj9 lE8ITDTpY6oswQdecAy0xMQmgzVzGWcIH1A2LSuVfjb+Tw4ePQTFSf68B0gIOmZM8gAo Ew+g== X-Gm-Message-State: AOJu0YzwqcALDvDSf/ckeBOic9trGdD6LQiFxoiJHU+1eew3Nkp1XDPi Z/IAduWDx/zOe9s5CstcwxETHQ== X-Google-Smtp-Source: AGHT+IFXhLSk1J4/oFjctJ/Po8nD5YwHwMHiCnwaBvzK3FsmOjQgqT0VcPMdiBDJPHiaO5CfeKMAGg== X-Received: by 2002:a05:6a00:1d29:b0:68e:16ce:f2e3 with SMTP id a41-20020a056a001d2900b0068e16cef2e3mr3023975pfx.0.1695123666044; Tue, 19 Sep 2023 04:41:06 -0700 (PDT) From: Li Feng To: Markus Armbruster , "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v5 1/5] vhost-user-common: send get_inflight_fd once Date: Tue, 19 Sep 2023 19:40:22 +0800 Message-ID: <20230919114030.280414-2-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919114030.280414-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230919114030.280414-1-fengli@smartx.com> 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: none client-ip=2607:f8b0:4864:20::42d; envelope-from=fengli@smartx.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1695123890929100001 Content-Type: text/plain; charset="utf-8" Currently the get_inflight_fd will be sent every time the device is started= , and the backend will allocate shared memory to save the inflight state. If the backend finds that it receives the second get_inflight_fd, it will release = the previous shared memory, which breaks inflight working logic. This patch is a preparation for the following patches. Signed-off-by: Li Feng --- hw/scsi/vhost-scsi-common.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index a06f01af26..a61cd0e907 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -52,20 +52,28 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) =20 vsc->dev.acked_features =3D vdev->guest_features; =20 - assert(vsc->inflight =3D=3D NULL); - vsc->inflight =3D g_new0(struct vhost_inflight, 1); - ret =3D vhost_dev_get_inflight(&vsc->dev, - vs->conf.virtqueue_size, - vsc->inflight); + ret =3D vhost_dev_prepare_inflight(&vsc->dev, vdev); if (ret < 0) { - error_report("Error get inflight: %d", -ret); + error_report("Error setting inflight format: %d", -ret); goto err_guest_notifiers; } =20 - ret =3D vhost_dev_set_inflight(&vsc->dev, vsc->inflight); - if (ret < 0) { - error_report("Error set inflight: %d", -ret); - goto err_guest_notifiers; + if (vsc->inflight) { + if (!vsc->inflight->addr) { + ret =3D vhost_dev_get_inflight(&vsc->dev, + vs->conf.virtqueue_size, + vsc->inflight); + if (ret < 0) { + error_report("Error getting inflight: %d", -ret); + goto err_guest_notifiers; + } + } + + ret =3D vhost_dev_set_inflight(&vsc->dev, vsc->inflight); + if (ret < 0) { + error_report("Error setting inflight: %d", -ret); + goto err_guest_notifiers; + } } =20 ret =3D vhost_dev_start(&vsc->dev, vdev, true); @@ -85,9 +93,6 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) return ret; =20 err_guest_notifiers: - g_free(vsc->inflight); - vsc->inflight =3D NULL; - k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false); err_host_notifiers: vhost_dev_disable_notifiers(&vsc->dev, vdev); @@ -111,12 +116,6 @@ void vhost_scsi_common_stop(VHostSCSICommon *vsc) } assert(ret >=3D 0); =20 - if (vsc->inflight) { - vhost_dev_free_inflight(vsc->inflight); - g_free(vsc->inflight); - vsc->inflight =3D NULL; - } - vhost_dev_disable_notifiers(&vsc->dev, vdev); } =20 --=20 2.41.0 From nobody Sat May 18 19:48:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1695123828; cv=none; d=zohomail.com; s=zohoarc; b=QNZ0R4128Sc8Yv0qdSbr71WNBeUMFEzUN8DoQv10jo+D6DDj9CUR80LV3ytEnzldDlIu3Zb4c08ATGaq9uql+iDGFbt3SLzFP7aefuGTFMDtWKOvcCBLxAwmyUj31XvYo1VJNwYjt88C/orxNY+vXAfP6IJx1aFhtfa8aHBX7lY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695123828; 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=Ak3cZicP6FXgjNSZA0EnmzY0v3FARPxaB+bcgiWIe/k=; b=ADH/1+mtcbxh4E7DWYKvAQwxAhuxmRZUKkyhQwcQhKxbuq+KE1lAcz+h1/C/26M2rbn0aHK/PSwZqz71i6ErRsIuZf6xbO/D/tPVIumgIiwsHdAfQEanO1tFqDCLMSjpdchelJqr+eiK+JFsJ6bNK8Uxotrifp9mC3LxUIkPblE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695123828745893.6318380713861; Tue, 19 Sep 2023 04:43:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiZ8O-0007mK-3o; Tue, 19 Sep 2023 07:43:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiZ8L-0007kp-PQ for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:13 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiZ8J-0004Fd-A9 for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:13 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-68fb2e9ebcdso4145739b3a.2 for ; Tue, 19 Sep 2023 04:41:10 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id z24-20020aa791d8000000b006887be16675sm8487030pfa.205.2023.09.19.04.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1695123670; x=1695728470; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ak3cZicP6FXgjNSZA0EnmzY0v3FARPxaB+bcgiWIe/k=; b=PlhNhJ18J7/YO46NpeqxCYx04UYJ8bYnTehuSZ0CNkgLp37rxsHsmNgBNbHHdNzeb+ g9tiF5hxh84LKTEsF+j/cfACJsPzjgZ/Z2BRaQe1l085bnQWYTKrL6mEnBEPAHBIm6Dw vKfv6ygkXU1lncfKY4JhX5cTUo7C2sYl3pjDc+SJw8Q8k1vMK38Kt8XVx6HUX8ucxi0V 66eRvVkFOa1hKRymU1U51NzKBs27fbBAo89WWxslgL1dt9BfgQ5ztmB69BnWOr6W93Im 3VBXfoShZ1XDQt+1dqbtOOtyLGsXgFRwZpwVb0ky0YEQVIc1nWRtzOlASgJdvXu0cksj cZ5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695123670; x=1695728470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ak3cZicP6FXgjNSZA0EnmzY0v3FARPxaB+bcgiWIe/k=; b=NbAZ7WeTQb+mAQznHEK1hAYOb0p8zHwYLu8/Vi//kXKzP+DVy7jkAbzjVEkAr8rjNq TI16ptToXoW6SPmCs3lHeeluHm0IeB+ZA73yNNVDaa1uRYgL6tyHnIBzfTAp+5aP7B7u wdB9G8ymO8JylLKO5b1mh+0cZiSVYJJFmgGlBsiCQS5dqJICPyoYdNzawOymEVxROReb tMAGGkTfbsnq5ZOG36w81EDbbfkzL+F5ND5a6P961shzoFl1dfFsOadh4r+lAb+vMmJ5 RPHH276F4oPeFUJLmuiHBN2J8abd8wPriUPG7DJbDKXOjlSx2CKXa1aXKZhtT8b8uh/I Kdnw== X-Gm-Message-State: AOJu0YzLiIGwz720xU6WhnG5llMh57mlDrkPYahfgPxVEHeY0cPp7T7K kboYuWfwFHNOxibbheYs6mvh3g== X-Google-Smtp-Source: AGHT+IFqQdE9zR7dJmn8PVkbIaZPsz/mS2smwyJ0mv4zrKrqbOLPPiWN+FJb8sgzJQ8KZkA1mkcBRg== X-Received: by 2002:a05:6a20:12c4:b0:159:b45e:1c7d with SMTP id v4-20020a056a2012c400b00159b45e1c7dmr12504989pzg.15.1695123669748; Tue, 19 Sep 2023 04:41:09 -0700 (PDT) From: Li Feng To: Markus Armbruster , "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v5 2/5] vhost: move and rename the conn retry times Date: Tue, 19 Sep 2023 19:40:23 +0800 Message-ID: <20230919114030.280414-3-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919114030.280414-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230919114030.280414-1-fengli@smartx.com> 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: none client-ip=2607:f8b0:4864:20::42a; envelope-from=fengli@smartx.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1695123830884100003 Content-Type: text/plain; charset="utf-8" Multiple devices need this macro, move it to a common header. Signed-off-by: Li Feng Reviewed-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 4 +--- hw/virtio/vhost-user-gpio.c | 3 +-- include/hw/virtio/vhost.h | 2 ++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index eecf3f7a81..3c69fa47d5 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -32,8 +32,6 @@ #include "sysemu/sysemu.h" #include "sysemu/runstate.h" =20 -#define REALIZE_CONNECTION_RETRIES 3 - static const int user_feature_bits[] =3D { VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_SEG_MAX, @@ -482,7 +480,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) s->inflight =3D g_new0(struct vhost_inflight, 1); s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); =20 - retries =3D REALIZE_CONNECTION_RETRIES; + retries =3D VU_REALIZE_CONN_RETRIES; assert(!*errp); do { if (*errp) { diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index 3b013f2d0f..d9979aa5db 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -15,7 +15,6 @@ #include "standard-headers/linux/virtio_ids.h" #include "trace.h" =20 -#define REALIZE_CONNECTION_RETRIES 3 #define VHOST_NVQS 2 =20 /* Features required from VirtIO */ @@ -359,7 +358,7 @@ static void vu_gpio_device_realize(DeviceState *dev, Er= ror **errp) qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, vu_gpio_event, NU= LL, dev, NULL, true); =20 - retries =3D REALIZE_CONNECTION_RETRIES; + retries =3D VU_REALIZE_CONN_RETRIES; g_assert(!*errp); do { if (*errp) { diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 6a173cb9fa..ca3131b1af 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -8,6 +8,8 @@ #define VHOST_F_DEVICE_IOTLB 63 #define VHOST_USER_F_PROTOCOL_FEATURES 30 =20 +#define VU_REALIZE_CONN_RETRIES 3 + /* Generic structures common for any vhost based device. */ =20 struct vhost_inflight { --=20 2.41.0 From nobody Sat May 18 19:48:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1695123832; cv=none; d=zohomail.com; s=zohoarc; b=Sk80tpHJu5PF9vquoekn+BnKyM9pIR7IppemFXAKKBXimLlro1we2V6BYXDBTjGBAXQYqnjicV2Pr2akWsBJ4/o3T1Cgq4bFXeJs1RoMTdwWUIDswrs4LoQG+YcpERhmQHi+6juqgkbSozSO0zO0+zm52Cxt244Yk2Ad7DYD8J8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695123832; 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=+XH7wdtDBHjkJj1TRjhNqIG/+/Tyzm+qcFAhIy62ShA=; b=hhzDv7v9Ya2QtsZyk3GgKVw7VuuarmWWCtLll1f/UXinJYB2Yb9/sAwCKj/pI0FBSU/JcRh8QR/LJTOu9Hnrj4S3k6Pc7TDf1EjbCwVsWXiD1lFzpjLTLESAr44oODv+AqgjFhelECf7ehRoMuNNYzEHxn/u8zzqupzogfZdzao= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169512383232274.41199159607629; Tue, 19 Sep 2023 04:43:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiZ8Q-0007ph-Mx; Tue, 19 Sep 2023 07:43:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiZ8O-0007n7-UF for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:16 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiZ8M-0004G2-Tg for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:16 -0400 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-577a98f78b2so4000318a12.3 for ; Tue, 19 Sep 2023 04:41:14 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id z24-20020aa791d8000000b006887be16675sm8487030pfa.205.2023.09.19.04.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1695123673; x=1695728473; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+XH7wdtDBHjkJj1TRjhNqIG/+/Tyzm+qcFAhIy62ShA=; b=m+VHgC8GuF33xt1HtuIsSnrM2yMOh2e2RCXHVeFWNWvecP7qfppX7MzQgRrfNndIsx KYbpqwPSVsuNvaM7DMuc5sOtsKvbB9C8CiOhGKPM/djXd4YVpfTL1GPhQ/8vnJOt09ms kMW0LiqS4BtVJ+h2UrboEVRDuqaMuhflrf0LMIVxMocinujD+a233+VfhpobxeDrSFv9 k6h7ZUTQ+Moq8oglf0+7K2ykrC9/WwnQO2L0XnXI7xasanP/oXvVAlHA6+2u65tkCI2m Wg3FmrXEkqNIXUBxL0YZIr/kHgTSzBtyxumOM151f7VEAX2n/sRBaHvJz32xig65krCO mRbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695123673; x=1695728473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+XH7wdtDBHjkJj1TRjhNqIG/+/Tyzm+qcFAhIy62ShA=; b=PPiGUchNNWrEGqrxBr6c6DN6RDyddVbEN1vok+gO0gkh7EMRgPW1VrZAR+KChiWCH7 v31NTvwkCxpZB3WmhnRtyhaMiAwqDtgTZ2VoR+uIvHj9I1IG52e22k2iNq8VcqNW0Ybv kfzZ/2bHo9+M2luuynA9w5f0xzBbb5Bf+EfK+jP1VvhlqBarEf8U5qwuwmq519ZS11/F 0kAHZcMpxxBbZwgmQnELp7R8yrEI12I3slc68avZX3WokDktQKwc7T2e6D++AndzbxMy Y/kTlBdeFR/4/AG/lZh0riaAdWuhqDJn3y0HtGtiNOxi2SRd5Lv2PvaxPaPXcC7kAcge 7+CQ== X-Gm-Message-State: AOJu0YwxAqukLQvX4CKuNyJwoUDKuLmC2ozsF7IhSwA6yIDbKUAWjYVj oxUCQ3Yy2jg7ESGdF3WA/Xn2RA== X-Google-Smtp-Source: AGHT+IF3Gfj/mTjVpxJOB9WgXdMjLGeHU2hWgkHV/eOM6VvbIknyScBgvZDFZdYursL44iN+duHW4g== X-Received: by 2002:a05:6a20:104c:b0:155:5c28:ea74 with SMTP id gt12-20020a056a20104c00b001555c28ea74mr9989601pzc.12.1695123673346; Tue, 19 Sep 2023 04:41:13 -0700 (PDT) From: Li Feng To: Markus Armbruster , Raphael Norwitz , "Michael S. Tsirkin" , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v5 3/5] vhost-user-scsi: support reconnect to backend Date: Tue, 19 Sep 2023 19:40:24 +0800 Message-ID: <20230919114030.280414-4-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919114030.280414-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230919114030.280414-1-fengli@smartx.com> 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: none client-ip=2607:f8b0:4864:20::534; envelope-from=fengli@smartx.com; helo=mail-pg1-x534.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1695123834177100005 Content-Type: text/plain; charset="utf-8" If the backend crashes and restarts, the device is broken. This patch adds reconnect for vhost-user-scsi. This patch also improves the error messages, and reports some silent errors. Tested with spdk backend. Signed-off-by: Li Feng --- hw/scsi/vhost-scsi-common.c | 16 +- hw/scsi/vhost-scsi.c | 5 +- hw/scsi/vhost-user-scsi.c | 204 +++++++++++++++++++++++--- include/hw/virtio/vhost-scsi-common.h | 2 +- include/hw/virtio/vhost-user-scsi.h | 4 + 5 files changed, 201 insertions(+), 30 deletions(-) diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index a61cd0e907..4c8637045d 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -16,6 +16,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/module.h" #include "hw/virtio/vhost.h" @@ -25,7 +26,7 @@ #include "hw/virtio/virtio-access.h" #include "hw/fw-path-provider.h" =20 -int vhost_scsi_common_start(VHostSCSICommon *vsc) +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp) { int ret, i; VirtIODevice *vdev =3D VIRTIO_DEVICE(vsc); @@ -35,18 +36,19 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) VirtIOSCSICommon *vs =3D (VirtIOSCSICommon *)vsc; =20 if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); + error_setg(errp, "binding does not support guest notifiers"); return -ENOSYS; } =20 ret =3D vhost_dev_enable_notifiers(&vsc->dev, vdev); if (ret < 0) { + error_setg_errno(errp, -ret, "Error enabling host notifiers"); return ret; } =20 ret =3D k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, true); if (ret < 0) { - error_report("Error binding guest notifier"); + error_setg_errno(errp, -ret, "Error binding guest notifier"); goto err_host_notifiers; } =20 @@ -54,7 +56,7 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) =20 ret =3D vhost_dev_prepare_inflight(&vsc->dev, vdev); if (ret < 0) { - error_report("Error setting inflight format: %d", -ret); + error_setg_errno(errp, -ret, "Error setting inflight format"); goto err_guest_notifiers; } =20 @@ -64,21 +66,21 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) vs->conf.virtqueue_size, vsc->inflight); if (ret < 0) { - error_report("Error getting inflight: %d", -ret); + error_setg_errno(errp, -ret, "Error getting inflight"); goto err_guest_notifiers; } } =20 ret =3D vhost_dev_set_inflight(&vsc->dev, vsc->inflight); if (ret < 0) { - error_report("Error setting inflight: %d", -ret); + error_setg_errno(errp, -ret, "Error setting inflight"); goto err_guest_notifiers; } } =20 ret =3D vhost_dev_start(&vsc->dev, vdev, true); if (ret < 0) { - error_report("Error start vhost dev"); + error_setg_errno(errp, -ret, "Error starting vhost dev"); goto err_guest_notifiers; } =20 diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 443f67daa4..01a3ab4277 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -75,6 +75,7 @@ static int vhost_scsi_start(VHostSCSI *s) int ret, abi_version; VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); const VhostOps *vhost_ops =3D vsc->dev.vhost_ops; + Error *local_err =3D NULL; =20 ret =3D vhost_ops->vhost_scsi_get_abi_version(&vsc->dev, &abi_version); if (ret < 0) { @@ -88,14 +89,14 @@ static int vhost_scsi_start(VHostSCSI *s) return -ENOSYS; } =20 - ret =3D vhost_scsi_common_start(vsc); + ret =3D vhost_scsi_common_start(vsc, &local_err); if (ret < 0) { return ret; } =20 ret =3D vhost_scsi_set_endpoint(s); if (ret < 0) { - error_report("Error setting vhost-scsi endpoint"); + error_reportf_err(local_err, "Error setting vhost-scsi endpoint"); vhost_scsi_common_stop(vsc); } =20 diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index ee99b19e7a..dc109154ad 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -43,26 +43,56 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_RESET_DEVICE =3D 13, }; =20 +static int vhost_user_scsi_start(VHostUserSCSI *s, Error **errp) +{ + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + int ret; + + ret =3D vhost_scsi_common_start(vsc, errp); + s->started_vu =3D (ret < 0 ? false : true); + + return ret; +} + +static void vhost_user_scsi_stop(VHostUserSCSI *s) +{ + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + + if (!s->started_vu) { + return; + } + s->started_vu =3D false; + + vhost_scsi_common_stop(vsc); +} + static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status) { VHostUserSCSI *s =3D (VHostUserSCSI *)vdev; + DeviceState *dev =3D &s->parent_obj.parent_obj.parent_obj.parent_obj; VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); - bool start =3D (status & VIRTIO_CONFIG_S_DRIVER_OK) && vdev->vm_runnin= g; + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + bool should_start =3D virtio_device_should_start(vdev, status); + Error *local_err =3D NULL; + int ret; =20 - if (vhost_dev_is_started(&vsc->dev) =3D=3D start) { + if (!s->connected) { return; } =20 - if (start) { - int ret; + if (vhost_dev_is_started(&vsc->dev) =3D=3D should_start) { + return; + } =20 - ret =3D vhost_scsi_common_start(vsc); + if (should_start) { + ret =3D vhost_user_scsi_start(s, &local_err); if (ret < 0) { - error_report("unable to start vhost-user-scsi: %s", strerror(-= ret)); - exit(1); + error_reportf_err(local_err, "unable to start vhost-user-scsi:= %s", + strerror(-ret)); + qemu_chr_fe_disconnect(&vs->conf.chardev); } } else { - vhost_scsi_common_stop(vsc); + vhost_user_scsi_stop(s); } } =20 @@ -89,14 +119,127 @@ static void vhost_dummy_handle_output(VirtIODevice *v= dev, VirtQueue *vq) { } =20 +static int vhost_user_scsi_connect(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCSI *s =3D VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + int ret =3D 0; + + if (s->connected) { + return 0; + } + s->connected =3D true; + + vsc->dev.num_queues =3D vs->conf.num_queues; + vsc->dev.nvqs =3D VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; + vsc->dev.vqs =3D s->vhost_vqs; + vsc->dev.vq_index =3D 0; + vsc->dev.backend_features =3D 0; + + ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_U= SER, 0, + errp); + if (ret < 0) { + return ret; + } + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + ret =3D vhost_user_scsi_start(s, errp); + if (ret < 0) { + return ret; + } + } + + return 0; +} + +static void vhost_user_scsi_event(void *opaque, QEMUChrEvent event); + +static void vhost_user_scsi_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCSI *s =3D VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + + if (!s->connected) { + return; + } + s->connected =3D false; + + vhost_user_scsi_stop(s); + + vhost_dev_cleanup(&vsc->dev); + + /* Re-instate the event handler for new connections */ + qemu_chr_fe_set_handlers(&vs->conf.chardev, NULL, NULL, + vhost_user_scsi_event, NULL, dev, NULL, true); +} + +static void vhost_user_scsi_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCSI *s =3D VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + Error *local_err =3D NULL; + + switch (event) { + case CHR_EVENT_OPENED: + if (vhost_user_scsi_connect(dev, &local_err) < 0) { + error_report_err(local_err); + qemu_chr_fe_disconnect(&vs->conf.chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &vs->conf.chardev, &vsc->dev, + vhost_user_scsi_disconnect); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static int vhost_user_scsi_realize_connect(VHostUserSCSI *s, Error **errp) +{ + DeviceState *dev =3D &s->parent_obj.parent_obj.parent_obj.parent_obj; + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + int ret; + + s->connected =3D false; + + ret =3D qemu_chr_fe_wait_connected(&vs->conf.chardev, errp); + if (ret < 0) { + return ret; + } + + ret =3D vhost_user_scsi_connect(dev, errp); + if (ret < 0) { + qemu_chr_fe_disconnect(&vs->conf.chardev); + return ret; + } + assert(s->connected); + + return 0; +} + static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) { + ERRP_GUARD(); VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); VHostUserSCSI *s =3D VHOST_USER_SCSI(dev); VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); - struct vhost_virtqueue *vqs =3D NULL; Error *err =3D NULL; int ret; + int retries =3D VU_REALIZE_CONN_RETRIES; =20 if (!vs->conf.chardev.chr) { error_setg(errp, "vhost-user-scsi: missing chardev"); @@ -115,18 +258,28 @@ static void vhost_user_scsi_realize(DeviceState *dev,= Error **errp) goto free_virtio; } =20 - vsc->dev.nvqs =3D VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; - vsc->dev.vqs =3D g_new0(struct vhost_virtqueue, vsc->dev.nvqs); - vsc->dev.vq_index =3D 0; - vsc->dev.backend_features =3D 0; - vqs =3D vsc->dev.vqs; + vsc->inflight =3D g_new0(struct vhost_inflight, 1); + s->vhost_vqs =3D g_new0(struct vhost_virtqueue, + VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues); + + assert(!*errp); + do { + if (*errp) { + error_prepend(errp, "Reconnecting after error: "); + error_report_err(*errp); + *errp =3D NULL; + } + ret =3D vhost_user_scsi_realize_connect(s, errp); + } while (ret < 0 && retries--); =20 - ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { goto free_vhost; } =20 + /* we're fully initialized, now we can operate, so add the handler */ + qemu_chr_fe_set_handlers(&vs->conf.chardev, NULL, NULL, + vhost_user_scsi_event, NULL, (void *)dev, + NULL, true); /* Channel and lun both are 0 for bootable vhost-user-scsi disk */ vsc->channel =3D 0; vsc->lun =3D 0; @@ -135,8 +288,12 @@ static void vhost_user_scsi_realize(DeviceState *dev, = Error **errp) return; =20 free_vhost: + g_free(s->vhost_vqs); + s->vhost_vqs =3D NULL; + g_free(vsc->inflight); + vsc->inflight =3D NULL; vhost_user_cleanup(&s->vhost_user); - g_free(vqs); + free_virtio: virtio_scsi_common_unrealize(dev); } @@ -146,16 +303,23 @@ static void vhost_user_scsi_unrealize(DeviceState *de= v) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserSCSI *s =3D VHOST_USER_SCSI(dev); VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); - struct vhost_virtqueue *vqs =3D vsc->dev.vqs; + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); =20 /* This will stop the vhost backend. */ vhost_user_scsi_set_status(vdev, 0); + qemu_chr_fe_set_handlers(&vs->conf.chardev, NULL, NULL, NULL, NULL, NU= LL, + NULL, false); =20 vhost_dev_cleanup(&vsc->dev); - g_free(vqs); + g_free(s->vhost_vqs); + s->vhost_vqs =3D NULL; + + vhost_dev_free_inflight(vsc->inflight); + g_free(vsc->inflight); + vsc->inflight =3D NULL; =20 - virtio_scsi_common_unrealize(dev); vhost_user_cleanup(&s->vhost_user); + virtio_scsi_common_unrealize(dev); } =20 static Property vhost_user_scsi_properties[] =3D { diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhos= t-scsi-common.h index 18f115527c..c5d2c09455 100644 --- a/include/hw/virtio/vhost-scsi-common.h +++ b/include/hw/virtio/vhost-scsi-common.h @@ -39,7 +39,7 @@ struct VHostSCSICommon { struct vhost_inflight *inflight; }; =20 -int vhost_scsi_common_start(VHostSCSICommon *vsc); +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp); void vhost_scsi_common_stop(VHostSCSICommon *vsc); char *vhost_scsi_common_get_fw_dev_path(FWPathProvider *p, BusState *bus, DeviceState *dev); diff --git a/include/hw/virtio/vhost-user-scsi.h b/include/hw/virtio/vhost-= user-scsi.h index 521b08e559..b405ec952a 100644 --- a/include/hw/virtio/vhost-user-scsi.h +++ b/include/hw/virtio/vhost-user-scsi.h @@ -29,6 +29,10 @@ OBJECT_DECLARE_SIMPLE_TYPE(VHostUserSCSI, VHOST_USER_SCS= I) struct VHostUserSCSI { VHostSCSICommon parent_obj; VhostUserState vhost_user; + bool connected; + bool started_vu; + + struct vhost_virtqueue *vhost_vqs; }; =20 #endif /* VHOST_USER_SCSI_H */ --=20 2.41.0 From nobody Sat May 18 19:48:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1695123833; cv=none; d=zohomail.com; s=zohoarc; b=mNEfIw8/EsaJYGu3SkAFHcrBtAUj3UXFHpw22I2YGxgs07BUDgNoewJNIb5Nja8YsLO+nB1Q4oJSSeNDC+KYAs0B8aYdy/qFfUpJ6xYWAzc4XbynHtb8ipzWwbor1h/TdOVdb2SrDapjxCqftlXoM+LVPeLBzkBvxwsSJgJRHyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695123833; 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=HPRPD1pbMza8Qy14aglX4a9WyhzajqmGhD+mOHsf0R4=; b=G/2jTt26/HqamaASoLNznAHuqmKftQvbccsW+CCIqdKTXdg8xND0/kHb11F411MokB0D6g8SRFdnKPA80vc/rf/kqOCCH8W3CL9wpgVazUQ61IBM5Q89uZVS8l6beUE6qUrqG0LiTDyovUVfJvnvc+Q8Ym7RPmHK+qVldKQBpbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695123833444846.3819455875353; Tue, 19 Sep 2023 04:43:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiZ8U-0007rP-25; Tue, 19 Sep 2023 07:43:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiZ8R-0007q5-Qw for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:19 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiZ8Q-0004GS-BX for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:19 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68fac16ee5fso4740902b3a.1 for ; Tue, 19 Sep 2023 04:41:18 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id z24-20020aa791d8000000b006887be16675sm8487030pfa.205.2023.09.19.04.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1695123677; x=1695728477; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HPRPD1pbMza8Qy14aglX4a9WyhzajqmGhD+mOHsf0R4=; b=sXDdvsIKOYI6WDGVfZbGo6THa5Udot+nWRZGQL3kY0cry4iQaaVSE0mWLSzk/RAzJo f5ndTPy6pUOe6tWSK2YL8LEEjoEkMy6el5UbgOyCam9BDdRSdMuCzvTVcRpg2rvxh1iB anxZgbAZd1xSumclwS7UYvkqLFz6bD4oz3upQM+hOvu641R1UZ0JUZiE74muWulCaW+h PoEuUK1LPm1SRik8rhnb+cuWbJ28yN3onvEZj9WKZf1ycRgYpkbtkoBqKrxOwlCSM+9o skmSnk+q4f6cFJT8O6zE11WXLYh/yXsxo8JVUXUTqwX0G0WMFcrcv3J7CWZIMYXJz47X FbKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695123677; x=1695728477; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HPRPD1pbMza8Qy14aglX4a9WyhzajqmGhD+mOHsf0R4=; b=QqpY1mmvv4jks9/8bIm1F+eb4FT4XfTqR7mWDsKd93gNXMCCaoYps7siO0tvdBez5K oF/wEZyRqIYtVggUVH6e3fEV+q0CjUYMAAYF+PRQJ6rHdDfoOMjL45q9p8JE2cDzlM0p lqy3BrK3DVOaMdClNre+hrGdfKCQBXw7C7L1QM5JoPEUb8RplHeO0qVcZz9lbRKRhrW0 tkRfSog6RAh6LyiYbfEpVyMEtZ0oH/GRN3UfBNnPnqsDcLehg+BydArQ909hzQ/YAOwn bvf+8smzIamgvgLL7rIljeHt9StgvyZ6FIvVSGjcSwSaqMzoPhqJrwIiV515Z+/boO6X P5EQ== X-Gm-Message-State: AOJu0Yxs7pGMngI3DSWL/6ZJgM5c/5DjFrKC9unagx2gZeWKhDpkWLPE W/TAoExc9gOpYsCuc9X/Sq+fGdrYWHKdw5iTqRKJb62gU5Y= X-Google-Smtp-Source: AGHT+IGLhCT1WiQUD3MxhVzBqZJUtCW5aNOdZvJCjNJhqSVr1oHpo+i+po+25R7JkIPlvLRxpKzJVQ== X-Received: by 2002:a05:6a20:2446:b0:147:fd40:2482 with SMTP id t6-20020a056a20244600b00147fd402482mr11970103pzc.44.1695123676784; Tue, 19 Sep 2023 04:41:16 -0700 (PDT) From: Li Feng To: Markus Armbruster , "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v5 4/5] vhost-user-scsi: start vhost when guest kicks Date: Tue, 19 Sep 2023 19:40:25 +0800 Message-ID: <20230919114030.280414-5-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919114030.280414-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230919114030.280414-1-fengli@smartx.com> 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: none client-ip=2607:f8b0:4864:20::434; envelope-from=fengli@smartx.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1695123834331100008 Content-Type: text/plain; charset="utf-8" Let's keep the same behavior as vhost-user-blk. Some old guests kick virtqueue before setting VIRTIO_CONFIG_S_DRIVER_OK. Signed-off-by: Li Feng --- hw/scsi/vhost-user-scsi.c | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index dc109154ad..53a62c3170 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -115,8 +115,48 @@ static void vhost_user_scsi_reset(VirtIODevice *vdev) } } =20 -static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq) +static void vhost_user_scsi_handle_output(VirtIODevice *vdev, VirtQueue *v= q) { + VHostUserSCSI *s =3D (VHostUserSCSI *)vdev; + DeviceState *dev =3D &s->parent_obj.parent_obj.parent_obj.parent_obj; + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + + Error *local_err =3D NULL; + int i, ret; + + if (!vdev->start_on_kick) { + return; + } + + if (!s->connected) { + return; + } + + if (vhost_dev_is_started(&vsc->dev)) { + return; + } + + /* + * Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start + * vhost here instead of waiting for .set_status(). + */ + ret =3D vhost_user_scsi_start(s, &local_err); + if (ret < 0) { + error_reportf_err(local_err, "vhost-user-scsi: vhost start failed:= "); + qemu_chr_fe_disconnect(&vs->conf.chardev); + return; + } + + /* Kick right away to begin processing requests already in vring */ + for (i =3D 0; i < vsc->dev.nvqs; i++) { + VirtQueue *kick_vq =3D virtio_get_queue(vdev, i); + + if (!virtio_queue_get_desc_addr(vdev, i)) { + continue; + } + event_notifier_set(virtio_queue_get_host_notifier(kick_vq)); + } } =20 static int vhost_user_scsi_connect(DeviceState *dev, Error **errp) @@ -246,9 +286,9 @@ static void vhost_user_scsi_realize(DeviceState *dev, E= rror **errp) return; } =20 - virtio_scsi_common_realize(dev, vhost_dummy_handle_output, - vhost_dummy_handle_output, - vhost_dummy_handle_output, &err); + virtio_scsi_common_realize(dev, vhost_user_scsi_handle_output, + vhost_user_scsi_handle_output, + vhost_user_scsi_handle_output, &err); if (err !=3D NULL) { error_propagate(errp, err); return; --=20 2.41.0 From nobody Sat May 18 19:48:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1695123922; cv=none; d=zohomail.com; s=zohoarc; b=Ymu+KuFN10WDNlLM2VwvGV+UJDW6Fo+cdHXHc3wsu4SPuqrTOMAMRev/QkfYYU4+qoHfkPTa8AE1lV4DauTsZ2HVBLXIkys9YKuTBYzDpe5pZnwxOd4RRAVw7A61sdJIPongeiCmkC6RDx7YsbJ5BYhtG+E/QVOJbfOryzqsehU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695123922; 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=zEHWKIJ/jlcW2XJm2YoMaGjRhjLSx9EfJkS7TRjaaVY=; b=fD4GMDVTuK6oDc/ZOIzAt6yb4Xzdqj39YGwgsc7GTrrsE5PswCB2KuvRSqtkR+NRW0UPmT9NSvjEo3hEjdMnLwPvSJfUxfp0or0TSux/zp69SxnVVrvqVPuPfMEvZROhOlhLCOKOEnOZXit8ixkicUzC2cwHV4KXGHYbZ7wKEa4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695123922162176.47068855007137; Tue, 19 Sep 2023 04:45:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiZ8W-0007sk-Rw; Tue, 19 Sep 2023 07:43:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiZ8V-0007rx-G4 for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:23 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiZ8T-0004Go-S6 for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:43:23 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-690bd8f89baso875586b3a.2 for ; Tue, 19 Sep 2023 04:41:21 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id z24-20020aa791d8000000b006887be16675sm8487030pfa.205.2023.09.19.04.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:41:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1695123680; x=1695728480; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zEHWKIJ/jlcW2XJm2YoMaGjRhjLSx9EfJkS7TRjaaVY=; b=ukKaax96/pmwiLBVLBAagPrOMEqbJUx2Dck5RENMCUIKcRLcY2F8zKX3/WX18+MAkZ BY7bTwn2KyLGKJ1yPnD0fgT15HKHI1/+hQ6UNFt1fUd7wXvynmNP0kcVCn6v2jYajYgj yaZhzkeZVH0ODZ0qGu/mJeQ9Oue6/1ZuzPlSZP0sc0gnoU4xoM7XpT0UK8WhTrpe8Vj5 aBy1oCWY4ghanw9TxkH6N9oGSdR6AGaskpWiqulBAwO9FtqLiTmLk77TCA+MRqtW6qMa im8v4beSi0N+5+9oM3h4yE2+zm+7GCDvAuWENQKxi2ZBRSrLBTlVG5YFFlcSknwUyBds n0cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695123680; x=1695728480; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zEHWKIJ/jlcW2XJm2YoMaGjRhjLSx9EfJkS7TRjaaVY=; b=S513LsKzgTEXbc0KGaY4n9SkDxID+J77yBKDy/1XMQqoXNY57mpw+bilKupkVHN9H2 3vyLexe1Z5YTLXBVS2wX0VHHUY0Om/uyCQCz/KjhHqgn+DIYn77def6kXi1D16kejy1V MEa3RCZin4Rc6wfck/LUb9jFazRyHgMEceAj1QpXWfChI+LwgHqDICOEcIOOPojMXJui LZAhq0depN5Cu1XAHjt7WHl9jSvx5bBU6s1YifltPTRWFZFQxwefAz4perlqUnQSJOmp D0MU7EhDY036Xu5jlTPOrEKAnlaDijjuzlmDEFw+PXV/088U7DSsSn8iYcIsrC9D3VjU vYyQ== X-Gm-Message-State: AOJu0YwjPxfB6dFkeLzGFl4VcYOlAN4DJj7WA8CbwsSJAZ9TDdBSyKkb q0LRDJ+1GSvxZF5AvnTFrj+kcw== X-Google-Smtp-Source: AGHT+IEVY+j0o0niFXBzQToLnxkV6h5ezezXNBTG5QG3u7D4Qcb5c8wuxlSAtIw0klaTb34NWZEzZA== X-Received: by 2002:a05:6a00:10c4:b0:68f:e810:e86f with SMTP id d4-20020a056a0010c400b0068fe810e86fmr10294630pfu.28.1695123680352; Tue, 19 Sep 2023 04:41:20 -0700 (PDT) From: Li Feng To: Markus Armbruster , Raphael Norwitz , "Michael S. Tsirkin" , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v5 5/5] vhost-user: fix lost reconnect Date: Tue, 19 Sep 2023 19:40:26 +0800 Message-ID: <20230919114030.280414-6-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919114030.280414-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230919114030.280414-1-fengli@smartx.com> 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: none client-ip=2607:f8b0:4864:20::42d; envelope-from=fengli@smartx.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1695123923460100006 Content-Type: text/plain; charset="utf-8" When the vhost-user is reconnecting to the backend, and if the vhost-user f= ails at the get_features in vhost_dev_init(), then the reconnect will fail and it will not be retriggered forever. The reason is: When the vhost-user fails at get_features, the vhost_dev_cleanup will be ca= lled immediately. vhost_dev_cleanup calls 'memset(hdev, 0, sizeof(struct vhost_dev))'. The reconnect path is: vhost_user_blk_event vhost_user_async_close(.. vhost_user_blk_disconnect ..) qemu_chr_fe_set_handlers <----- clear the notifier callback schedule vhost_user_async_close_bh The vhost->vdev is null, so the vhost_user_blk_disconnect will not be called, then the event fd callback will not be reinstalled. All vhost-user devices have this issue, including vhost-user-blk/scsi. With this patch, if the vdev->vdev is null, the fd callback will still be reinstalled. Fixes: 71e076a07d ("hw/virtio: generalise CHR_EVENT_CLOSED handling") Signed-off-by: Li Feng --- hw/block/vhost-user-blk.c | 2 +- hw/scsi/vhost-user-scsi.c | 3 ++- hw/virtio/vhost-user-gpio.c | 2 +- hw/virtio/vhost-user.c | 9 +++++++-- include/hw/virtio/vhost-user.h | 3 ++- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 3c69fa47d5..95c758200d 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -391,7 +391,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrE= vent event) case CHR_EVENT_CLOSED: /* defer close until later to avoid circular close */ vhost_user_async_close(dev, &s->chardev, &s->dev, - vhost_user_blk_disconnect); + vhost_user_blk_disconnect, vhost_user_blk_e= vent); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 53a62c3170..0effbb4787 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -238,7 +238,8 @@ static void vhost_user_scsi_event(void *opaque, QEMUChr= Event event) case CHR_EVENT_CLOSED: /* defer close until later to avoid circular close */ vhost_user_async_close(dev, &vs->conf.chardev, &vsc->dev, - vhost_user_scsi_disconnect); + vhost_user_scsi_disconnect, + vhost_user_scsi_event); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index d9979aa5db..04c2cc79f4 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -283,7 +283,7 @@ static void vu_gpio_event(void *opaque, QEMUChrEvent ev= ent) case CHR_EVENT_CLOSED: /* defer close until later to avoid circular close */ vhost_user_async_close(dev, &gpio->chardev, &gpio->vhost_dev, - vu_gpio_disconnect); + vu_gpio_disconnect, vu_gpio_event); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 8dcf049d42..12c4a41f30 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -2643,6 +2643,7 @@ typedef struct { DeviceState *dev; CharBackend *cd; struct vhost_dev *vhost; + IOEventHandler *event_cb; } VhostAsyncCallback; =20 static void vhost_user_async_close_bh(void *opaque) @@ -2657,7 +2658,10 @@ static void vhost_user_async_close_bh(void *opaque) */ if (vhost->vdev) { data->cb(data->dev); - } + } else if (data->event_cb) { + qemu_chr_fe_set_handlers(data->cd, NULL, NULL, data->event_cb, + NULL, data->dev, NULL, true); + } =20 g_free(data); } @@ -2669,7 +2673,8 @@ static void vhost_user_async_close_bh(void *opaque) */ void vhost_user_async_close(DeviceState *d, CharBackend *chardev, struct vhost_dev *vhost, - vu_async_close_fn cb) + vu_async_close_fn cb, + IOEventHandler *event_cb) { if (!runstate_check(RUN_STATE_SHUTDOWN)) { /* diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index 191216a74f..649e9dd54f 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -84,6 +84,7 @@ typedef void (*vu_async_close_fn)(DeviceState *cb); =20 void vhost_user_async_close(DeviceState *d, CharBackend *chardev, struct vhost_dev *vhost, - vu_async_close_fn cb); + vu_async_close_fn cb, + IOEventHandler *event_cb); =20 #endif --=20 2.41.0