From nobody Mon Feb 9 08:50:50 2026 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=1690805593; cv=none; d=zohomail.com; s=zohoarc; b=oChOlRF9zTB9sYZuQrhfwWCaWp76KaSH8cofawyayUzgrpKr5GKmgYOgwvZoWkYL2x5KfWrc8AnEBNmsc6HvmsbKzPfPEnhVNqjn42XCvh8PqdSLXQr24Csdw2+LU1LkvtZLzzLKScV57LO5Oh5S2qh6q1bjy0+DVbenreZuvTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805593; 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=EmF2rPUr8kcukZB0aZbqQbeTdRQhvpW4qihewNCbxJ8=; b=Kb6FIoZlGKw3FOTsMDiE+IY99H4rrwxmO105OshXuFTRhO4z/LNnLjfAvG+pN/ZZO7lqeakbA4XGaTsiSTh+W5mwAB/4jGC/Nz6n8m4TVq7dAUXM7SKEqoOhzYHhAC0zVkVwmmvkDWUBAStRnMQSwEUKk6t6tX3osJFcOzeYde4= 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 1690805593524247.82210235212574; Mon, 31 Jul 2023 05:13:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQRlk-0003AP-6c; Mon, 31 Jul 2023 08:13:00 -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 1qQRlh-00038z-L0 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:12:57 -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 1qQRle-00053R-8E for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:12:57 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-686efb9ee0cso4389242b3a.3 for ; Mon, 31 Jul 2023 05:10:53 -0700 (PDT) Received: from localhost.localdomain.gitgo.cc ([47.75.78.161]) by smtp.gmail.com with ESMTPSA id a10-20020a62bd0a000000b005d22639b577sm7385690pff.165.2023.07.31.05.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1690805452; x=1691410252; 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=EmF2rPUr8kcukZB0aZbqQbeTdRQhvpW4qihewNCbxJ8=; b=pOFSpZF7CJ50fLdrkGKuhXeJbet6VUS/U5k2naveKlfWLRo/uzCSGF+Ho6/wtTguTA SmBpt3bZNkxaGLBaWcsPj9bdZ7ryqC0CJ3JpP4JpG3kQvhG4IY5OMnFnBdy7D3cMCbSG qSnEkVgi6eAEEv82G9TM+dmz/yEnPS6u/XXPwIgJf70WbnxOtQ4/J39jDEZ2XoxUTHTQ M262T3Npr5f+2QtS8oPCWb71hYrZDutQhkCn9+Aq5WFgU+QOK17exfCz18cpTNeyrxG2 4PUR5YeJqotadjmspOhCnNYRcW6Qnyyayuk+y1ULAIHyyjW8/44yvzBzCah+/BQxPbid hAZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805452; x=1691410252; 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=EmF2rPUr8kcukZB0aZbqQbeTdRQhvpW4qihewNCbxJ8=; b=W1lXlN/oXvRjpobDxhoT8tz/YP+NTvJeK/lxInE5iqixTxQt6jQTxVcAxBu7rGmtwo ko58oTLGW6r/KvIQwYVUwpCFxDLPxUolYylGYRw7jiQQfH3DngRYFkGkN4HRRCPuYFFX VI/skaQD1BFJ+JXg0j8zU8pEmuMSJ4w8V6t01I7abZFYOawZ3QD6hfnF94VoHP9EVXLP 9IfLFjxmXp7tONYWCJO/+nDLP/mbqJNCnvPggIFzWVJ4YJEJd7WvW8lb7QsQGUaR161q LYFrx+CJNntVLgQbz2w4vqHzEn8cX6VsTGsYfCyXjZkt2lL4V3FEAfGwk1/pp5yffDN/ TVdA== X-Gm-Message-State: ABy/qLbrpH5hkRpJvnXXEbM2Bi1w5sVVcZk+8oWb+O/VJ6MOVoHQdjaH wDy2JnsAByyRE/yEyXRMftPPdw== X-Google-Smtp-Source: APBJJlGuWp2D80lSbIybokl43feIX4m1gFG4J/5s6SQ7bn38kaDUmY3kJJQd7N2lfPmlN0u8s5boXw== X-Received: by 2002:a05:6a20:7352:b0:122:c6c4:36b1 with SMTP id v18-20020a056a20735200b00122c6c436b1mr11873001pzc.4.1690805452229; Mon, 31 Jul 2023 05:10:52 -0700 (PDT) From: Li Feng To: 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 v3 1/5] vhost: fix the fd leak Date: Mon, 31 Jul 2023 20:10:06 +0800 Message-ID: <20230731121018.2856310-2-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230731121018.2856310-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230731121018.2856310-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, T_SCC_BODY_TEXT_LINE=-0.01 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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1690805594842100001 Content-Type: text/plain; charset="utf-8" When the vhost-user reconnect to the backend, the notifer should be cleanup. Otherwise, the fd resource will be exhausted. Fixes: f9a09ca3ea ("vhost: add support for configure interrupt") Signed-off-by: Li Feng Reviewed-by: Raphael Norwitz Tested-by: Fiona Ebner --- hw/virtio/vhost.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index abf0d03c8d..e2f6ffb446 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -2044,6 +2044,8 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) event_notifier_test_and_clear( &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier); event_notifier_test_and_clear(&vdev->config_notifier); + event_notifier_cleanup( + &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier); =20 trace_vhost_dev_stop(hdev, vdev->name, vrings); =20 --=20 2.41.0 From nobody Mon Feb 9 08:50:50 2026 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=1690805678; cv=none; d=zohomail.com; s=zohoarc; b=BMfmXkx1aZW6AjOQ1YaWtpAFeJRNI54jZbrcwa0mey34FvOpzG3AzAdT/WEncznRZMf/OV5so/hGyQvYeZfvBUFgoG+wfsiUITkbt4iVQ1i4EdlBW5LHb+FRK3z9jt1/MMNEMsOFBH8Wi/OuqfwtntJ+n1xjR08ScTNd4rWirmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805678; 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=luL3rooWLmi7vlzgtNshJXevn0LY393D0QAkyU10iyEkF8XVy7PtFORx9+sZyfv2uOeoEKbXQ6k5lWNcIB0LsKuydR3nA6EklLw5v7QTi24tGRhNixmYBgmvUSzZwl8qZ8QZGFpq9ApqsF645Nv/az16XiGvNCzHjJZ/yNzYz48= 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 1690805678788304.8463346293423; Mon, 31 Jul 2023 05:14:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQRll-0003Ak-F7; Mon, 31 Jul 2023 08:13:01 -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 1qQRlk-0003AK-12 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:13:00 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQRli-00055j-Et for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:12:59 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686d8c8fc65so3021911b3a.0 for ; Mon, 31 Jul 2023 05:10:57 -0700 (PDT) Received: from localhost.localdomain.gitgo.cc ([47.75.78.161]) by smtp.gmail.com with ESMTPSA id a10-20020a62bd0a000000b005d22639b577sm7385690pff.165.2023.07.31.05.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1690805456; x=1691410256; 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=l6MwkPcoFSeTJtfcu+Qss2SrtxKQFDz3+RtMs0xBMXV2jwqvSSXEJvTv9hVm0TcbGn sbImZ9xPsYSNjowgscDTLA/x4tv2i/IyPXsfKYZ9w3JaunHyrjsGxKVNSh64T8VNf8bG 0+PD4HfVhomqz17ti+0S3ST6CzEL+guoixpOPiilaavAY6gTprofFABGP7MdE83UV3qC GqCLeCJLyyFkasu+fHfUsVIfwgS2OR27h+uHa0tZMbDjEaIw/0rQoa5vGPImllwfzbQi HKcbC5nfaCES4PScugIQ1ZTtDD9/w+BeGH5SaP4nchT5N/u1i37dLo4HWeJyKSXeUmAX s0pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805456; x=1691410256; 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=V9s1y02s/UWiosZpXsZATc0Ug/wOvdBE5dLQ3LSrOykIYnwlHYez8bQGgwXgmeJ1zt y7JjpVN6341v0xgfe3ZeE/EL8SDIzvBX8PYKnbUGvHLpd3CrWRBbxnsQTM7wmUNOjgk0 6puUP/uLlZmCx2lAhLNT3E5Zx2hujcW8iJiQt5qipZI63u03ImzHw8d6diPbFuEbyRgq EdUScfEmzerZou6jZUpWElgnZcjS5ojcUUDR6jDklZtyc92Jseb43FHg3PjrrZziWcUt 9rKs1pgHc1e4W6nMhfAXun5lDiJtYzcH6/nJQmveSz1nWoz3NZLsqMRi6vB2zLcViGl6 89YA== X-Gm-Message-State: ABy/qLZKN5D6h1UZaPFTtH6WmTUfpGBMiNy1xXago+I5+9QHlmVbW5Vd YNEcVUi61TOhjTwUMHSYpkfknw== X-Google-Smtp-Source: APBJJlGqTzcfJy5apNff7q34wYIt59/evlmKT3SBg7bE55FG3aKWyl+4cOVca8XTAG5y5BMaSqhx7g== X-Received: by 2002:a05:6a20:7d9d:b0:137:8ddf:464b with SMTP id v29-20020a056a207d9d00b001378ddf464bmr9827745pzj.36.1690805456203; Mon, 31 Jul 2023 05:10:56 -0700 (PDT) From: Li Feng To: "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 v3 2/5] vhost-user-common: send get_inflight_fd once Date: Mon, 31 Jul 2023 20:10:07 +0800 Message-ID: <20230731121018.2856310-3-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230731121018.2856310-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230731121018.2856310-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::42b; envelope-from=fengli@smartx.com; helo=mail-pf1-x42b.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, T_SCC_BODY_TEXT_LINE=-0.01 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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1690805680857100001 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 Mon Feb 9 08:50:50 2026 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=1690805658; cv=none; d=zohomail.com; s=zohoarc; b=MZD8dzpixtuhxPCo3XD16YpR/tMJtEFe3YegpQ75nUyIN6K+3myzJy26OimXdHh2UjvRHw9ARIv3y46nrl9IoveGAQj7CLCq32Ei7q/nWdkWFpy6vhmY0V+taRaZuZHSEnqDiBoOsZf3OcO9u+5kGlt4DksXYTI7ckUD3F+ny70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805658; 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=ZQMdXhOH+4pTH/FN/P8Exhd3eHd1flcESJgZzlwZ3ESZAnKsKa5+05yJtNA5Emykt8x/57XW14zdMPqUchpB94QnUGYLAu1pd556jmktet5+cK0q7dbLElCVbI3X496NnYSsCaIZ+VyqTo9CtIlNbJ296jKfNyGUaTBJgzci+Qw= 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 1690805658573882.5299816200284; Mon, 31 Jul 2023 05:14:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQRlr-0003Bh-OP; Mon, 31 Jul 2023 08:13:07 -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 1qQRlp-0003BJ-N6 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:13:05 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQRln-00057T-MD for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:13:05 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686b9964ae2so2930067b3a.3 for ; Mon, 31 Jul 2023 05:11:03 -0700 (PDT) Received: from localhost.localdomain.gitgo.cc ([47.75.78.161]) by smtp.gmail.com with ESMTPSA id a10-20020a62bd0a000000b005d22639b577sm7385690pff.165.2023.07.31.05.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1690805462; x=1691410262; 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=eRsbn0DpQuI8VzGSPbN4slKZhVelHKMtMqKaM/jG0nlqcka8rq8mldubonQvknEftg KAYlP0sptRWa6aTcKHGhDvx9R2uh3RMQw+qQ8D8suhaUAxsJTTC0t0GYFBLZ4KcAOzCQ H5aq06MiGjGPX9eDDj8judUu2RxxwbCPzjzLxF0XE0ZnGcMOAFaXWAHtPt0V+J7MbdEg BxSzKi8vKH+5lzlSlDIVsM2uWa+tNduUvWmrFrMPWr2GHF9k/FWbQpEafH93TifBt27r TM4pQY/UX1BNmQFKUL8zV8IdcJI7LGYxDoBelbgknVM6N9QMGjRQVESZCqVLES+LifC+ 1KUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805462; x=1691410262; 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=PzidI5oyROwlNHUMZ6Hn71z4RVD+Evh7YDSp6hntXY6bmzeuyMwnF8/nMEcPOvLpbp 9+QUOAhJ0t1wi4EFy4Fmh/GdlJLGYzHUC3Z9VoxxAM8wxycIpOmACDNmjg2yCifBwFOs Mfz7dPPijCYSL0Dyr+uWpaqFyCyJl48nXHx2AjIXojIBPmZb9/8a82hewRaRn9Il1nUV s+jrMHKR/+Sbo2Dg56DweFkEkDr7FhkxZ/aUWGHNGpYX5hf9nU1TIU0SkNH+WCWzKCHN pobKrxP+O+BYASOYIMtq3iUbLqz5Dqkm+h/vauh7ozNlsfhth1Dpap4XaaccGLVKJA1u MHzg== X-Gm-Message-State: ABy/qLY+3TqGf2rG2dYOBrC++F9G4BgrxEYx5Nt+QzWTlmpLQpqRH7ye rzrwaRfiwlRt9dp7Zlo8o01ANg== X-Google-Smtp-Source: APBJJlFkujDJqHf+XhSC3dGTeqUXhbgeutYq/nGrPpy5ViqSJe9W7kSOCeeUdQEDlgegCCQmcHWLRQ== X-Received: by 2002:aa7:88c3:0:b0:687:20d6:faea with SMTP id k3-20020aa788c3000000b0068720d6faeamr6727330pff.15.1690805462016; Mon, 31 Jul 2023 05:11:02 -0700 (PDT) From: Li Feng To: "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 v3 3/5] vhost: move and rename the conn retry times Date: Mon, 31 Jul 2023 20:10:08 +0800 Message-ID: <20230731121018.2856310-4-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230731121018.2856310-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230731121018.2856310-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::42e; envelope-from=fengli@smartx.com; helo=mail-pf1-x42e.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, T_SCC_BODY_TEXT_LINE=-0.01 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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1690805660266100003 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 Mon Feb 9 08:50:50 2026 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=1690805613; cv=none; d=zohomail.com; s=zohoarc; b=Pvo1rebqWXV2c4ZikYQbMfRqR8ftERms+Hajj3SCY64nD3hG59xajJxSjZXFOA9d7D9o/7aIgabApBLc/Bkqkg/VZgZfY7EX440sdDLSgmmmB6Q6AeRXWyDUm+Yx+Qf4l9LSuLCom8QP2N48N1939rteKTpzYcWUGWhWeNSDg2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805613; 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=U6hnNimq9gNOgoPdgNvDGfaGEO+kLFO1RzZStHFpC58=; b=HOAMTOTgtmMfTWsOOwObaRnvBOcOVkQBJk/EViqgowVowIs8CWbeudF34zCsS1MVVjB+g4241bY/jEARIMk3D9MpqrpPioVzJt6P/qDRnpTTXILjqhFXLDAfxQWRq86EVp6gg/P/LGQr9m6sL1JIufNpH8dhK4MjhmkibJ0vhmA= 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 1690805613464121.26742232364325; Mon, 31 Jul 2023 05:13:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQRm1-0003Gl-1I; Mon, 31 Jul 2023 08:13:17 -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 1qQRly-0003FE-Fb for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:13:15 -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 1qQRlv-000595-RB for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:13:14 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-686b9964ae2so2930148b3a.3 for ; Mon, 31 Jul 2023 05:11:10 -0700 (PDT) Received: from localhost.localdomain.gitgo.cc ([47.75.78.161]) by smtp.gmail.com with ESMTPSA id a10-20020a62bd0a000000b005d22639b577sm7385690pff.165.2023.07.31.05.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1690805470; x=1691410270; 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=U6hnNimq9gNOgoPdgNvDGfaGEO+kLFO1RzZStHFpC58=; b=EUUf5xO39D5qtB5YEtBmWSgAcEXm/XvUhQBuXkb2EWPhW3WJNEcjYxxag+IInPfiAV epA64C88qKLSZUwe01nmceDsGSDwuT54fV6X8UBkXI5TSHvLEKVrIGHTukK+flNjbWXD QS7z+bdRkTgkIay7VGXWeZB3nrv3dSs1FKUATgXxprOFrun4GvESTbm8bAJcfcYBKERI 9zkwbbwwrQfxvjAri/LEL8Xdod1veH3SDvv7tzwWlPRt0iHTKmLFVKgej7l6yDgC8h5b 58JaEmFkt+kI9nEgUEhNfMesKU43qXV17QxpsrkrtbGSrBhR3NNtL8DH9xQz0zann4JQ G4Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805470; x=1691410270; 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=U6hnNimq9gNOgoPdgNvDGfaGEO+kLFO1RzZStHFpC58=; b=kl1xHCgM4TfaRqX4aFZduI+4DbFv5LAaDIYoCyCDqKqeYsztIQWiwni/nLbx4zoiur 76bEUHIu08YvnDGUeHRZ2oXIrlForGVveiCZdxoLc+pCGbKhBYRIFQ76YKKV8XBQxvl8 RwQzm1W58sW6bWTq4GSbL9m//zz1IzKTT99V0cmZfJg2wBvfIt/uilFM2jTqKKklFNo2 h4D+alxaRJ4lRGHKt6Z8/JdQMNNLotiKtyViC5r0dewp5HLJf4qo47+JZiTx3T+qju8h 2detDZTBRSz3uwF683i4C1ez3NKg+UOEd6VBqZQsjN6VhB1kUvs0tRPc/+K26j/xFySb PEoA== X-Gm-Message-State: ABy/qLYsz8btH7DTCpB70QRBpGZLMD7j1k9O0wU7TMss10q3b6LaDHmw vFT/G9D6OZZHnjkN4gexYLe4vA== X-Google-Smtp-Source: APBJJlFPyD51QNitsaut6fZI7lVWk8EHlHKu8thh48KNkDkHVJuXY3eezMaEr782mY/KaZe4DYuCuw== X-Received: by 2002:a05:6a20:644:b0:138:60e:9c4 with SMTP id 4-20020a056a20064400b00138060e09c4mr6306011pzm.23.1690805469665; Mon, 31 Jul 2023 05:11:09 -0700 (PDT) From: Li Feng To: "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 v3 4/5] vhost-user-scsi: support reconnect to backend Date: Mon, 31 Jul 2023 20:10:09 +0800 Message-ID: <20230731121018.2856310-5-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230731121018.2856310-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230731121018.2856310-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, T_SCC_BODY_TEXT_LINE=-0.01 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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1690805615569100003 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. Tested with spdk backend. Signed-off-by: Li Feng Reviewed-by: Raphael Norwitz --- hw/scsi/vhost-user-scsi.c | 199 +++++++++++++++++++++++++--- include/hw/virtio/vhost-user-scsi.h | 4 + 2 files changed, 184 insertions(+), 19 deletions(-) diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index ee99b19e7a..5bf012461b 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -43,26 +43,54 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_RESET_DEVICE =3D 13, }; =20 +static int vhost_user_scsi_start(VHostUserSCSI *s) +{ + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + int ret; + + ret =3D vhost_scsi_common_start(vsc); + 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); + 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); if (ret < 0) { error_report("unable to start vhost-user-scsi: %s", strerror(-= ret)); - exit(1); + qemu_chr_fe_disconnect(&vs->conf.chardev); } } else { - vhost_scsi_common_stop(vsc); + vhost_user_scsi_stop(s); } } =20 @@ -89,14 +117,126 @@ 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); + 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) { 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 +255,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 +285,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 +300,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-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 Mon Feb 9 08:50:50 2026 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=1690805673; cv=none; d=zohomail.com; s=zohoarc; b=BFJCbT21mTIdMcztC+SeV2pAyCqlkZFHRyoD4sCPtqG27BevY3c3MvL0uVeg56oD6+GGWa7jmmg9Fl2ztaGw+gLSaUXeyINBZmauKQS51UBEzz3z7w+NT9hGJIXBq8+EUvWASZ0XvEaqh3F6813WPqoz02RHiV6D42Tg+wCvDvg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805673; 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=9PoeHQ72MxcC2TaPE9HsDberM+yq2oYNtqnB7MFftuE=; b=Ob5tQmfuQcMYbLsYqsq0lVjOZOxLAlHAJqfbesZKaHLVIFx2zfnewMfqajQL3Tw+8yt7D/+p8Md4H6KMycIOm8H0Uo7s4Eia9gojID9f8vHAHmFAfvECI+lTNBuqxnOtVHdGW53Ao9h1D53mQ871TYjxAgT7ZDwnq4XYv3M9p4A= 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 1690805673433119.43971761440855; Mon, 31 Jul 2023 05:14:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQRm6-0003RP-QK; Mon, 31 Jul 2023 08:13: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 1qQRm4-0003MU-5J for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:13:20 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQRm2-00059q-4C for qemu-devel@nongnu.org; Mon, 31 Jul 2023 08:13:19 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-686b9964ae2so2930204b3a.3 for ; Mon, 31 Jul 2023 05:11:17 -0700 (PDT) Received: from localhost.localdomain.gitgo.cc ([47.75.78.161]) by smtp.gmail.com with ESMTPSA id a10-20020a62bd0a000000b005d22639b577sm7385690pff.165.2023.07.31.05.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1690805476; x=1691410276; 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=9PoeHQ72MxcC2TaPE9HsDberM+yq2oYNtqnB7MFftuE=; b=pISqWFbCwW9ucqWlz66+soLewmbIPUhI8FE2tBVSQJGxtRVdwdQts9r3x7OhIeTffh l7S1B2v5+WQgIAE/96wfoEpdc0h0AQEkjo8M+rbagzh4MlmsUgThzw9Vp6v2k5DJr327 7A3joGei3XMEr4CiUMKV+IfOuiyhn6y0GSLQYNohGgMbCAeX7xQYTqaz9FOT885uszn2 ZLbPtvglVO9NHqInthjSzcGn4Mc2Qqc0GiM5PRE5Kg/9ptB4iCgHRLn+LF/dFRsKnO5b GVhUGKygfTOv3+UA8B/k7DnpeCB6Wl+n6dpk/EKNS2t58CEnzpxRR84Uyvj23Pwuob6H vSJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805476; x=1691410276; 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=9PoeHQ72MxcC2TaPE9HsDberM+yq2oYNtqnB7MFftuE=; b=Td7K3oF+4mapJLZD7BYhyoCOiaiqDgdIVMMeF22DfS7dkD0iZJn7Y/mQSdyNFpIBx1 oyEwITI6GOvKNSx7qGwLCYOqfOu2CKeUOBjhaxUoBjLyJy8qMxkEB2Rej56Kmyxalblv zRuNa8WAww8/YF4pzkJSzqT6h5OYBEeYh8VntO9hg9zO44BI9h7FdcdeAirxdkxh4qFY ouD0loQ3Kq51hJKe3MMUjwk79gIGFTFbcSBcZNxKn3SLhswPBtoDjhfA2qXkJcUNlyPZ cgDNNHUooARzyUGo4qtKDHew+mmXwvptJtUWYM3Z6a6lzYU3PuuI5ixMnlYLu34pYrQ9 +1oQ== X-Gm-Message-State: ABy/qLbRnRROAcUcAGWqi88tkSY8+C+l104vtPnYF+JesbXNjVb71PnM mYHQn15wMgiwSEfO4a9IjKJuFw== X-Google-Smtp-Source: APBJJlGvs5vbuz3clvEV1NOqCyUvCsVXlIsFRSq9+nYD0/K6ffo41A3QvOpsdxDarHmIXPIEEb6l5A== X-Received: by 2002:a05:6a20:7492:b0:133:c12a:4d6 with SMTP id p18-20020a056a20749200b00133c12a04d6mr9289657pzd.1.1690805476490; Mon, 31 Jul 2023 05:11:16 -0700 (PDT) From: Li Feng To: "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 v3 5/5] vhost-user-scsi: start vhost when guest kicks Date: Mon, 31 Jul 2023 20:10:10 +0800 Message-ID: <20230731121018.2856310-6-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230731121018.2856310-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230731121018.2856310-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::42f; envelope-from=fengli@smartx.com; helo=mail-pf1-x42f.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, T_SCC_BODY_TEXT_LINE=-0.01 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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1690805673762100001 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 5bf012461b..a7fa8e8df2 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -113,8 +113,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); + 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) @@ -243,9 +283,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