From nobody Sun May 12 12:49:28 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=1696826946; cv=none; d=zohomail.com; s=zohoarc; b=U33QWV2U3NhqpjpWlG8gKy7tc+RIDVgJZCIFAjbS6UdF7uyMJqShB+H/KIbbdc/dYLxdNJlajqILmdC/JugWmbfTCVdJc8tf7sj1pK2fo+p9imoCz5IcaafXZbGRbElOFU+DIft/k+nFE0CBuOPRVoRGq65roTtkC5L2WBamMMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696826946; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KtjO1lS5KyQU3h+Hf7ZgeU0iuEx8e6d6jY/0St+hkG8=; b=XSo/ngoSFPNnt/i4VEjTDbB0KntUR4qCEEgbbSO3/gfDP5Kmj2YKfso1xll+nDIGnlmz2sc8mpYV44rel1C7OKqxoEZxX8v3Gly4C6K2usiwOfGVMrbEL2+ftiMD+pCH10MJZG2LCYI22hf7K5tQuM2R/ZY+LA8PHGWHFrbfCEo= 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 169682694600674.4570901523191; Sun, 8 Oct 2023 21:49:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpiBY-0008Jc-EO; Mon, 09 Oct 2023 00:48:04 -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 1qpiBW-0008Iq-Gz for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:02 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpiBU-0003R1-Ew for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:02 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c5db4925f9so30053095ad.1 for ; Sun, 08 Oct 2023 21:48:00 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id l4-20020a170902ec0400b001c452f827casm8406010pld.257.2023.10.08.21.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 21:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1696826879; x=1697431679; 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=KtjO1lS5KyQU3h+Hf7ZgeU0iuEx8e6d6jY/0St+hkG8=; b=cAKNDxiBDIF8yQjNmg0FFHhW8DcLt6r+6o6+TEKCuGzddohX6l53/AeRx6BXV/BwDO nFcX7O7MibVtzgWqADkevBYMA4hzL5ZBQt00ATU4YT1DsNhXTU2YYYD36nkcTodHztIX M8lAKFRircZJ0TmZzjDtmTHO4dqfw6lLa7DglldzdRT5x0EKIxdzQ+10siYmTrBpPr8Y VMJYEuYJ+xNH3bEY4bA2sF0r8oprfr7wNazdl/9ebAPo/3S13PFLoLNPVSCNvAuDp85W 6OJ4MZVdHHM/N/enRQ4nYVT4v7k6CBoT4VyHK2qZ7o+Mps3dXc6L/m/Uz+1l097ijEC5 GcIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696826879; x=1697431679; 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=KtjO1lS5KyQU3h+Hf7ZgeU0iuEx8e6d6jY/0St+hkG8=; b=vWWHnwMEsmN+8hWtxAOqWhe61JqNH15vO8afmsK045IWV5oFgGd+iEi6LHIfLARki0 8Xf0AK1prqhZg8MS0S61JMP/rTNrO0gnVePv2Vj+fRCmVxOWmhHiuiQtw2Xhmm28UO4K 4LqgT8LM3ljO9Lca2eK4jma4gajhuuKFf9YLXmBQPspouMw4vHJjn4K1HORvCLiVWGrk j/ByQ4sOCbhHcsV7apwFrQNHUWCpaO2Cto5TGFbxyZQQnkwp0esS2ICyHxiM0No9xJGq S9ALqiQ1xYWtG3vcFurQoKA1fhTNmnhJJKbZmVu/zG8mAH9NEVjUsETbcovaybZ4lrEy zjnA== X-Gm-Message-State: AOJu0YyDUf7erCqovrX2OEYv5uCwKXRXdpztkrXz91KTezbSgr5zS7V8 QZs7YFDg0rtxL/IDt7LEIoOBwA== X-Google-Smtp-Source: AGHT+IG8LSVkwmWrms+Ntwayfs+IJoIub9rPb0DJggaa2lavuAkUx8+2eQrMXQS1SXwJ2VNoFKIzkg== X-Received: by 2002:a17:902:e852:b0:1c5:59dc:6e93 with SMTP id t18-20020a170902e85200b001c559dc6e93mr19645162plg.3.1696826879043; Sun, 08 Oct 2023 21:47:59 -0700 (PDT) From: Li Feng To: Markus Armbruster , Manos Pitsidianakis , 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 v8 1/5] vhost-user-common: send get_inflight_fd once Date: Mon, 9 Oct 2023 12:46:57 +0800 Message-ID: <20231009044735.941655-2-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009044735.941655-1-fengli@smartx.com> References: <20231009044735.941655-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::629; envelope-from=fengli@smartx.com; helo=mail-pl1-x629.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: 1696826947291100002 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 Reviewed-by: Raphael Norwitz --- 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 Sun May 12 12:49:28 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=1696826963; cv=none; d=zohomail.com; s=zohoarc; b=i4IDJ4//MN4EhMM5wNA5Yvr00/3Ej7Xr0YZY61qI1OHUdlv1Yv4/51R1R5iCP6Y51O23fUQg6EXICw5nNHGJoImMJf11FDEuwGjYikZwV88p/llLFXMw+GxzSl4+zjxBA3x2nAGa3o7oXJFrn1FHkiz3kAz1xWRzgWd3vWI9Rqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696826963; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=flzDQE1QokZHW+hOGv8gceXlgLhnm4s9nj6hmmZpjyU=; b=S7Z5qAgx5TxIzNX5kD7H/MG3+BCLiPfVMIiRIAvPQ7RkncWykW9JmVb+YoF3Z7aQRU1jePgVmbxvLQOIm5B9vHeCihfLdtPlzRuMgfimCLZ1jF//jdhqzG4jUvY9Q1Dmj6Obtf8cEPG9itWt/yahADtgVIgvFn1TFIB3j0PLEdI= 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 1696826963831422.2437549285419; Sun, 8 Oct 2023 21:49:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpiBo-0008Nq-2P; Mon, 09 Oct 2023 00:48:20 -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 1qpiBm-0008Mw-Il for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:19 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpiBZ-0003Rr-2N for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:18 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c760b34d25so26790685ad.3 for ; Sun, 08 Oct 2023 21:48:04 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id l4-20020a170902ec0400b001c452f827casm8406010pld.257.2023.10.08.21.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 21:48:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1696826883; x=1697431683; 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=flzDQE1QokZHW+hOGv8gceXlgLhnm4s9nj6hmmZpjyU=; b=X0PaMKLmQySOoUPUuMRFo2xkmXeqc/FadoJ2Nj8OAAqRk1fkWbKpurJAUurej2oYPv dxOouDWtiXm5bOnZcTEGfOj7VaGP/Jhe127xi0X6DRDpRQQk+lDWZoTWIISZXIQNx+Vh aN/Kxgr/swF/It34EPik6YL7fArmJfrsFFSnbvw0Q9YSHCLbj+bSCRiEkmmPGsMRMKQa QtaoW03zuoa3FQ+lHusbz0AfdMd7B1aYN6kiwj3ZXdRU6AQbfmuTU5P0CDtRPbU8Ge+6 O7ZSwm/EqHAJZEllHF9DK0thHG9ONOs8ekXaAzKUEJpXOer0ZERAcSSrA599Ts4kH0+j 2J8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696826883; x=1697431683; 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=flzDQE1QokZHW+hOGv8gceXlgLhnm4s9nj6hmmZpjyU=; b=eOK6waKj9d6NOcXblGN9OJE1shX87t/p5LR/O284Z8Gs/viXrM5xjemxXrKQmXJFVI D64nDhhXmHZAl0pl6/rypRyJcMM2J45Xd3t4IXYN0tykvPsYKbbcSWUoFds60aOOKgzr UumZ6HULQPrBZ5KCMeNf3m5rZeN5xeH0ckKlAu63IIWgE87hEPqaUF+kCXM9oErYQK/n EKyT2qZcZPzgCCgA2AqCE67VpCVg6DNhNZkjGXcwHZtLAbUQjYZXQ01NYr9MQTKy0Zb+ /C2eoERPKNf2TFnz6hX3PtRHoCcbYe7XW7iPLgcU8tNpf3djiKwaMwDLT1sNjvhvuDbb GqZA== X-Gm-Message-State: AOJu0YyFu+QIiZ5+02AVWU2wIKNkSTP9CB6pRyFVX0y/DoLRqgIFgHdP 04UKblDfK3NmbzMkqxO7IwfvqA== X-Google-Smtp-Source: AGHT+IGBUIkym2QQjiMwBtNmecbdrvYLDplF9Hal61fJtGzDF+MA33zBTpLp08K5z8gNzi5JfxbJMQ== X-Received: by 2002:a17:902:fe83:b0:1c5:bc83:556b with SMTP id x3-20020a170902fe8300b001c5bc83556bmr11041271plm.52.1696826883488; Sun, 08 Oct 2023 21:48:03 -0700 (PDT) From: Li Feng To: Markus Armbruster , Manos Pitsidianakis , "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 v8 2/5] vhost: move and rename the conn retry times Date: Mon, 9 Oct 2023 12:46:58 +0800 Message-ID: <20231009044735.941655-3-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009044735.941655-1-fengli@smartx.com> References: <20231009044735.941655-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::62d; envelope-from=fengli@smartx.com; helo=mail-pl1-x62d.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, 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: 1696826965641100005 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 3d7fae3984..fc784e4213 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 */ @@ -365,7 +364,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 Sun May 12 12:49:28 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=1696826966; cv=none; d=zohomail.com; s=zohoarc; b=DPF2Tl7QG6K3aVgeksGPatSMtWw9Cp41qSDPzOQPNI7bkErHczNsFqafWrw8rGG+ZUue1fV/YDGBxGsgPweB5FQjH1lJLlB9ET5JPC/FDL7FVjdSg1PoY3BrycYoJ21H9nzGuoiEJlNi4tr3aRvGid5lTwklf/OC7LHWXmtl0Ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696826966; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1FYU5sA17sQHPIYTTXCSOUPXZMptIqC+MmhAt8iBMeY=; b=IOIqsoaYsYWJNhOtI6P7LYACuhvhjGg2Rvl5wU6HF8ZrLy4MW8Q25ZDuEhFpJN+NTCKaIILUmNUW6uupN0+YTjkur884zrJqG80Sb61mB4tBgk3ZJwvmRtMVw78NvoWiPO6EG/5jc6B8aIJab9UW8rw4oanCiRK4QLtdGJ8SHKQ= 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 1696826966855166.24252800447948; Sun, 8 Oct 2023 21:49:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpiBv-0008Ql-EU; Mon, 09 Oct 2023 00:48:27 -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 1qpiBq-0008OW-Dn for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:22 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpiBe-0003SU-2K for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:22 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-577e62e2adfso2129080a12.2 for ; Sun, 08 Oct 2023 21:48:09 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id l4-20020a170902ec0400b001c452f827casm8406010pld.257.2023.10.08.21.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 21:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1696826889; x=1697431689; 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=1FYU5sA17sQHPIYTTXCSOUPXZMptIqC+MmhAt8iBMeY=; b=Vp8Us9JHCJDdLLJtS9ieh74cpdxqkkfIBbNxE/TZJ5IEN6nlDy6B1iL6RbpgjFsw36 VF9B3xtNAjWzN3nEsj+FLJYkY1m4QHFCh71tYTTck6hoaddUQWj+cHeW5KimvGhPazYg QYt9BxNPIKCMe+j4hbe9iceBdbVa7ll1Mb9kCGC3PmKZws475wRnlqahF2Vm2r9zGUq/ O8SXshR+UGigybKR6rhHBJTmzk3IiBQdhMru/LIn756ia4RUfHzbFZAPYEFeC5Y4cPGG VsQUcOzhXVSY6gBWgZxBgUmaZqm6zy61HTe2Q5V0a/b5w81noaRKERAZtDUGpNiO4NWS dszA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696826889; x=1697431689; 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=1FYU5sA17sQHPIYTTXCSOUPXZMptIqC+MmhAt8iBMeY=; b=j4kp4/Hyz9pthEkxgh2Q1OxREEAH2NlMcS70KlP9hkmR+yL9nlMTwcdMEQDzFl95/D s5MPdUMuHr/V77pC8bc7eZZ8Eu82s/UBxA3bgYxq/WDoIQZKAmCEUY21uXjpNTBQiOJb /eHmC8MlGAmeYSSQzScIrp6ALXlnv5DA0EdS1KHGOx1JbtRPgsVlKO9B2Pako07pXF0c +ynq/1sFfMIv2Avo9fmvqwDbH0RfKBv21BQtHvOZZwCMM1O25FiSBq3MQBLZKr8KOwsR kcbbuVtLS54tVlKTMRwX7qwrcI37CDnCVtwHla0Dlta+ggN91ei6b5IEEjlAoq9el3N/ lWIw== X-Gm-Message-State: AOJu0YzhjXkqfmNdm6QsEz/rEbYk5jSv17+dD8OnF/LgiKeekPvyOfol 2d/RN7ml2PkF/+F3c8LM9AxxkA== X-Google-Smtp-Source: AGHT+IHzaQ4EOU8w0fmElglqGUQOfBPicJ0DPL1u0TvvpteSPLygIVkKtbUlu2XvzsFMygUjGecTlA== X-Received: by 2002:a17:902:c112:b0:1c3:1f0c:fb82 with SMTP id 18-20020a170902c11200b001c31f0cfb82mr11154965pli.41.1696826888429; Sun, 08 Oct 2023 21:48:08 -0700 (PDT) From: Li Feng To: Markus Armbruster , Manos Pitsidianakis , 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 v8 3/5] vhost-user-scsi: support reconnect to backend Date: Mon, 9 Oct 2023 12:46:59 +0800 Message-ID: <20231009044735.941655-4-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009044735.941655-1-fengli@smartx.com> References: <20231009044735.941655-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::532; envelope-from=fengli@smartx.com; helo=mail-pg1-x532.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: 1696826967775100001 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 Reviewed-by: Manos Pitsidianakis --- hw/scsi/vhost-scsi-common.c | 16 +- hw/scsi/vhost-scsi.c | 6 +- hw/scsi/vhost-user-scsi.c | 201 +++++++++++++++++++++++--- include/hw/virtio/vhost-scsi-common.h | 2 +- include/hw/virtio/vhost-user-scsi.h | 6 + 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..95cadb93e7 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,15 @@ 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) { + error_reportf_err(local_err, "Error starting vhost-scsi"); 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 df6b66cc1a..1e5d853cdd 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -39,26 +39,56 @@ static const int user_feature_bits[] =3D { VHOST_INVALID_FEATURE_BIT }; =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); + + 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 DEVICE(vdev); 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 @@ -85,14 +115,124 @@ 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); + } + + return ret; +} + +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 DEVICE(s); + 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"); @@ -111,18 +251,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; @@ -131,8 +281,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); } @@ -142,16 +296,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..78fe616ccb 100644 --- a/include/hw/virtio/vhost-user-scsi.h +++ b/include/hw/virtio/vhost-user-scsi.h @@ -28,7 +28,13 @@ OBJECT_DECLARE_SIMPLE_TYPE(VHostUserSCSI, VHOST_USER_SCS= I) =20 struct VHostUserSCSI { VHostSCSICommon parent_obj; + + /* Properties */ + bool connected; + bool started_vu; + VhostUserState vhost_user; + struct vhost_virtqueue *vhost_vqs; }; =20 #endif /* VHOST_USER_SCSI_H */ --=20 2.41.0 From nobody Sun May 12 12:49:28 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=1696826954; cv=none; d=zohomail.com; s=zohoarc; b=K3QKcEIsoZNnMl0GPD4qpbmZSo4tvg5QvqDZL0h8WiWMbSAW71qSJ9jC3QNlycOpgEuOeVbAlG1zacUjvhgB+z27PkyYxF1ZTa+jQ1xG0nk6rUryd46lCcJsogJcIOy+6YsxAGM0VlE8xhWlsdbsUJPjAf5pTcsUnxqCwVYRh3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696826954; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KG8VQi2GXb0p0w8Q2r0ivPYIxJV3b+oHVY+rlGAvLEo=; b=Pl8ZSYxgxLdja15ZgcSWhCkvP5fZM3c/s0qYw/EtnCwhXXzwz5FW0xDMGHWn3fbxb5ycL5hTg58hHKEBlbRiWeoewofCPFgey2i5bT2Y7RpvBQIGdjOqOJJqNgz9YGuN4xKU8Q/zxeRhv9qzB83jQRWiLhbDLA23aa+m3DqXzV0= 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 1696826954063128.77756026877114; Sun, 8 Oct 2023 21:49:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpiBo-0008Ns-BC; Mon, 09 Oct 2023 00:48:20 -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 1qpiBm-0008Mx-KE for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:19 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpiBi-0003Sx-EG for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:18 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1c7373cff01so37510935ad.1 for ; Sun, 08 Oct 2023 21:48:13 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id l4-20020a170902ec0400b001c452f827casm8406010pld.257.2023.10.08.21.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 21:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1696826892; x=1697431692; 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=KG8VQi2GXb0p0w8Q2r0ivPYIxJV3b+oHVY+rlGAvLEo=; b=AqRmcdmzuW85TeDob8M4LzYD9smAYwxWUr5AW6B+8LcTnOBKCSeFxPy1NDmNy3Fbwd uZRJa5+5edO6KHPhZeM71AIDo/iv9AEpc9vVhQMGxhfGquJj/bolj36jhw6K2QFY9Vjj XepRIK9pUOm5Nv80DuXxmySHOrOfiHsWodjxos7JIce9Nqv3gVJH5NYdvXpjbbFhfFL4 ayZpnk70fSAgKGTKU0Z94iK8IgE3JVyQQX3e3gon66c/Efu+sXZIAtoG9tGCC0Fc84yy T9/Brj70CtYR2SXbBzqb5cER01H8DjXrHrjSdw9PJRCr5H3gUVRxZ9/skyCjAmvi5Qh9 09jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696826892; x=1697431692; 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=KG8VQi2GXb0p0w8Q2r0ivPYIxJV3b+oHVY+rlGAvLEo=; b=DjkIQGB4vmucYSyZte3Dot8QRRJ1Cu0M2ri3hWX20wIvp4AG0Eq4kd6WuvUUFiO2jP SXWWGHZtW5uq/3FeGl7eajLgdta5PlOxzfgPIsgTPmHqxUEDroZFS0v13tT+1ps+s8Jg 26DbC5cncxgWZVG5PFXQVMVMI1pc7Z+dg7d60D8RaQ8I3aQwWhZ8ECmnFmffx5eoAGal wfqQUDewwGs37wavnQ8/VxF+UCf5Qlry4X/q/DHo4D0ln3ogyg3cc51lYipLcYrv4qcA FAVFE0W/3fIW3BCw666jQx24ozm51rXgWnGAPbe2bcIUhxe1ZYG4DrMHCq6MmbbQezJZ epog== X-Gm-Message-State: AOJu0YwzR2xO/ZhDLRanfwO/mUt3Ab+5R0vIaTP6EV+XBjaVvOQI/Frw Ogd+w9Qiau0WkvyvMLLD03HYlQ== X-Google-Smtp-Source: AGHT+IHzCWw1VUfFvi7nXfBkrQ7JKilnCoROzCoevVpVQnYNuwh2f48GSM4FrAZ/o68fxOTFp2KnIA== X-Received: by 2002:a17:902:ec90:b0:1c7:27a1:a9e5 with SMTP id x16-20020a170902ec9000b001c727a1a9e5mr18458878plg.33.1696826892040; Sun, 08 Oct 2023 21:48:12 -0700 (PDT) From: Li Feng To: Markus Armbruster , Manos Pitsidianakis , "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 v8 4/5] vhost-user-scsi: start vhost when guest kicks Date: Mon, 9 Oct 2023 12:47:00 +0800 Message-ID: <20231009044735.941655-5-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009044735.941655-1-fengli@smartx.com> References: <20231009044735.941655-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::62b; envelope-from=fengli@smartx.com; helo=mail-pl1-x62b.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: 1696826955321100001 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 Reviewed-by: Raphael Norwitz --- 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 1e5d853cdd..2457b950e1 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -111,8 +111,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 DEVICE(vdev); + 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) @@ -239,9 +279,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 Sun May 12 12:49:28 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=1696826963; cv=none; d=zohomail.com; s=zohoarc; b=VUP3Ef3DVUzmCiXH4jUh0Gx0UyB9SyrBcMMlGzEKZtekICcxtEjFcPV/ue0M+5jME2JdfvfZq8FSq5z44bO47I63C657v0+GWF3QpQcAPr2fwOa125O640uopsZn4FPqUtEK0N6kiRZR8E+COH69cnZ5/SWBoz1LQOVoHqLS7iU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696826963; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Vgl7M3mhj7Pxor3wgDZDJWDAgFxGD3ZOBxs//ou5GXo=; b=T9rn8OqjNyNWTNssP9NdUgppTtrMSzqM/qVgZVJ73IqyL4tYLXa2yiPubliiYb9NUVFdnzjH1evbC6fLrKPokc81CratsgRjYqkl4UnTvezW291PeMq/1zeTC33PJvd/gbid5x7rX62vwRyw+4hqAH7cCbCHQEGqN7MUe5x7MZk= 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 1696826963197198.04329142263657; Sun, 8 Oct 2023 21:49:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpiBu-0008Pn-9w; Mon, 09 Oct 2023 00:48:26 -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 1qpiBq-0008OY-Rp for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:22 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpiBm-0003TS-6t for qemu-devel@nongnu.org; Mon, 09 Oct 2023 00:48:22 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c434c33ec0so23526375ad.3 for ; Sun, 08 Oct 2023 21:48:16 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id l4-20020a170902ec0400b001c452f827casm8406010pld.257.2023.10.08.21.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 21:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1696826896; x=1697431696; 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=Vgl7M3mhj7Pxor3wgDZDJWDAgFxGD3ZOBxs//ou5GXo=; b=l/234esQliHP+9ccfVrh6FQ14Rt2ZChcmsnSK3g77neGfuUfUA5mGjS9EiHZxDoFSz qUCDVThqGbCEbVDbUg3VaOGuwCNKJSmvVgafQEewtjKy3tapRZPOw2/1wkfhPhE1CG+t CzbNzRx4azdLxO/aTdMP2G+2ss/LHKYsVyIGLl6G5oUfQoRHuMNUfYOOmEIcPV/434Hl eugsi9dQGSAsZUrukKwAIamvMJvl6Ee/UOv35KIUrSyagwAYdxXodCv3erGYn2Fo1+HN FLJWiSdOMA0/dy8bhLNid3DzE9R3c4/71b3zcW8I9S1nfjAoKsuSr9eXkUTYiAg3OOkz Xosg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696826896; x=1697431696; 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=Vgl7M3mhj7Pxor3wgDZDJWDAgFxGD3ZOBxs//ou5GXo=; b=imUhySqrgOTQ+bn7LAmmZ9f8v2yscGLdtyW91za9ZorjJa9vTh/6sl4vNHg9vsifIS GlD8iZNvw71iVm7uGo0I7NKRRYmhAFxlBei1ukgpXNDibeEj5IGBLG6CrN01QB/GS5S7 2jEGagnk3A2MnHNmC0BK/LkBWoTq3He4QKunYz7JLd9C5jBCfJjkKgEQLHe7a31+k259 e5MtuYpROw4GRP07vmzCmXt4uCGdSt1q3l6vIMwuakU+4m3m4O93xTr3XxUSULoqfHWb qNoWiV67fmf38HBmDp37kyQjUaDT8n3jjvhE+jCYH4MqBGwkloU6RUsLTOJHxRs1ypUO xMFQ== X-Gm-Message-State: AOJu0Yz9VKz0t8oJpiruYTOVCLorWFFw/xtpwl/Gp1v8ZfzCO1cbK5pr cPdspGkK2gV0E8vFz/kmM3eEsg== X-Google-Smtp-Source: AGHT+IFMBtekZC4tW/u4SlyJZjEekDYkyfpyc2WFf99+whJSKaHq2rS45zebxCsA2gKSd/+RE44rPA== X-Received: by 2002:a17:902:7008:b0:1c5:cbfb:c16f with SMTP id y8-20020a170902700800b001c5cbfbc16fmr11277377plk.25.1696826895678; Sun, 08 Oct 2023 21:48:15 -0700 (PDT) From: Li Feng To: Markus Armbruster , Manos Pitsidianakis , "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 v8 5/5] vhost-user: fix lost reconnect Date: Mon, 9 Oct 2023 12:47:01 +0800 Message-ID: <20231009044735.941655-6-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009044735.941655-1-fengli@smartx.com> References: <20231009044735.941655-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::631; envelope-from=fengli@smartx.com; helo=mail-pl1-x631.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: 1696826963592100001 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 Reviewed-by: Raphael Norwitz --- 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 | 10 ++++++++-- include/hw/virtio/vhost-user.h | 3 ++- 5 files changed, 14 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 2457b950e1..61e4050682 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -231,7 +231,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 fc784e4213..aff2d7eff6 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -289,7 +289,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 3766b415f8..7395bfc531 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -2765,6 +2765,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) @@ -2779,7 +2780,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); } @@ -2791,7 +2795,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)) { /* @@ -2807,6 +2812,7 @@ void vhost_user_async_close(DeviceState *d, data->dev =3D d; data->cd =3D chardev; data->vhost =3D vhost; + data->event_cb =3D event_cb; =20 /* Disable any further notifications on the chardev */ qemu_chr_fe_set_handlers(chardev, diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index 9f9ddf878d..6b06ecb1bd 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -106,6 +106,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