From patchwork Mon Jul 31 12:10:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Feng X-Patchwork-Id: 13334499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15ED2C001E0 for ; Mon, 31 Jul 2023 12:13:13 +0000 (UTC) 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) 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) 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) From: Li Feng To: Raphael Norwitz , "Michael S. Tsirkin" , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?utf-8?q?Alex_Benn=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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, VirtIODevice *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); trace_vhost_dev_stop(hdev, vdev->name, vrings); From patchwork Mon Jul 31 12:10:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Feng X-Patchwork-Id: 13334504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97791C001DF for ; Mon, 31 Jul 2023 12:14:38 +0000 (UTC) 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) 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) 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) From: Li Feng To: "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?utf-8?q?Alex_Benn=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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) vsc->dev.acked_features = vdev->guest_features; - assert(vsc->inflight == NULL); - vsc->inflight = g_new0(struct vhost_inflight, 1); - ret = vhost_dev_get_inflight(&vsc->dev, - vs->conf.virtqueue_size, - vsc->inflight); + ret = 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; } - ret = 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 = 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 = vhost_dev_set_inflight(&vsc->dev, vsc->inflight); + if (ret < 0) { + error_report("Error setting inflight: %d", -ret); + goto err_guest_notifiers; + } } ret = vhost_dev_start(&vsc->dev, vdev, true); @@ -85,9 +93,6 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) return ret; err_guest_notifiers: - g_free(vsc->inflight); - vsc->inflight = 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 >= 0); - if (vsc->inflight) { - vhost_dev_free_inflight(vsc->inflight); - g_free(vsc->inflight); - vsc->inflight = NULL; - } - vhost_dev_disable_notifiers(&vsc->dev, vdev); } From patchwork Mon Jul 31 12:10:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Feng X-Patchwork-Id: 13334502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8EFC1C001DC for ; Mon, 31 Jul 2023 12:14:18 +0000 (UTC) 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) 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) 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) From: Li Feng To: "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?utf-8?q?Alex_Benn=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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" -#define REALIZE_CONNECTION_RETRIES 3 - static const int user_feature_bits[] = { 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 = g_new0(struct vhost_inflight, 1); s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues); - retries = REALIZE_CONNECTION_RETRIES; + retries = 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" -#define REALIZE_CONNECTION_RETRIES 3 #define VHOST_NVQS 2 /* Features required from VirtIO */ @@ -359,7 +358,7 @@ static void vu_gpio_device_realize(DeviceState *dev, Error **errp) qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, vu_gpio_event, NULL, dev, NULL, true); - retries = REALIZE_CONNECTION_RETRIES; + retries = 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 +#define VU_REALIZE_CONN_RETRIES 3 + /* Generic structures common for any vhost based device. */ struct vhost_inflight { From patchwork Mon Jul 31 12:10:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Feng X-Patchwork-Id: 13334500 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC792C001DC for ; Mon, 31 Jul 2023 12:13:32 +0000 (UTC) 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) 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) 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) From: Li Feng To: "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?utf-8?q?Alex_Benn=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = 13, }; +static int vhost_user_scsi_start(VHostUserSCSI *s) +{ + VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); + int ret; + + ret = vhost_scsi_common_start(vsc); + s->started_vu = (ret < 0 ? false : true); + + return ret; +} + +static void vhost_user_scsi_stop(VHostUserSCSI *s) +{ + VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); + + if (!s->started_vu) { + return; + } + s->started_vu = false; + + vhost_scsi_common_stop(vsc); +} + static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status) { VHostUserSCSI *s = (VHostUserSCSI *)vdev; + DeviceState *dev = &s->parent_obj.parent_obj.parent_obj.parent_obj; VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); - bool start = (status & VIRTIO_CONFIG_S_DRIVER_OK) && vdev->vm_running; + VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); + bool should_start = virtio_device_should_start(vdev, status); + int ret; - if (vhost_dev_is_started(&vsc->dev) == start) { + if (!s->connected) { return; } - if (start) { - int ret; + if (vhost_dev_is_started(&vsc->dev) == should_start) { + return; + } - ret = vhost_scsi_common_start(vsc); + if (should_start) { + ret = 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); } } @@ -89,14 +117,126 @@ static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq) { } +static int vhost_user_scsi_connect(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserSCSI *s = VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); + int ret = 0; + + if (s->connected) { + return 0; + } + s->connected = true; + + vsc->dev.num_queues = vs->conf.num_queues; + vsc->dev.nvqs = VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; + vsc->dev.vqs = s->vhost_vqs; + vsc->dev.vq_index = 0; + vsc->dev.backend_features = 0; + + ret = vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0, + errp); + if (ret < 0) { + return ret; + } + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + ret = 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 = VIRTIO_DEVICE(dev); + VHostUserSCSI *s = VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); + + if (!s->connected) { + return; + } + s->connected = 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 = opaque; + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserSCSI *s = VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); + Error *local_err = 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 = &s->parent_obj.parent_obj.parent_obj.parent_obj; + VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); + int ret; + + s->connected = false; + + ret = qemu_chr_fe_wait_connected(&vs->conf.chardev, errp); + if (ret < 0) { + return ret; + } + + ret = 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 = VIRTIO_SCSI_COMMON(dev); VHostUserSCSI *s = VHOST_USER_SCSI(dev); VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); - struct vhost_virtqueue *vqs = NULL; Error *err = NULL; int ret; + int retries = VU_REALIZE_CONN_RETRIES; 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; } - vsc->dev.nvqs = VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; - vsc->dev.vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs); - vsc->dev.vq_index = 0; - vsc->dev.backend_features = 0; - vqs = vsc->dev.vqs; + vsc->inflight = g_new0(struct vhost_inflight, 1); + s->vhost_vqs = 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 = NULL; + } + ret = vhost_user_scsi_realize_connect(s, errp); + } while (ret < 0 && retries--); - ret = vhost_dev_init(&vsc->dev, &s->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { goto free_vhost; } + /* 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 = 0; vsc->lun = 0; @@ -135,8 +285,12 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) return; free_vhost: + g_free(s->vhost_vqs); + s->vhost_vqs = NULL; + g_free(vsc->inflight); + vsc->inflight = 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 *dev) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserSCSI *s = VHOST_USER_SCSI(dev); VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); - struct vhost_virtqueue *vqs = vsc->dev.vqs; + VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); /* 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, NULL, + NULL, false); vhost_dev_cleanup(&vsc->dev); - g_free(vqs); + g_free(s->vhost_vqs); + s->vhost_vqs = NULL; + + vhost_dev_free_inflight(vsc->inflight); + g_free(vsc->inflight); + vsc->inflight = NULL; - virtio_scsi_common_unrealize(dev); vhost_user_cleanup(&s->vhost_user); + virtio_scsi_common_unrealize(dev); } static Property vhost_user_scsi_properties[] = { 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_SCSI) struct VHostUserSCSI { VHostSCSICommon parent_obj; VhostUserState vhost_user; + bool connected; + bool started_vu; + + struct vhost_virtqueue *vhost_vqs; }; #endif /* VHOST_USER_SCSI_H */ From patchwork Mon Jul 31 12:10:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Feng X-Patchwork-Id: 13334503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45A90C001DF for ; Mon, 31 Jul 2023 12:14:33 +0000 (UTC) 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) 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) 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) From: Li Feng To: "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?utf-8?q?Alex_Benn=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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) } } -static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq) +static void vhost_user_scsi_handle_output(VirtIODevice *vdev, VirtQueue *vq) { + VHostUserSCSI *s = (VHostUserSCSI *)vdev; + DeviceState *dev = &s->parent_obj.parent_obj.parent_obj.parent_obj; + VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); + + Error *local_err = 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 = 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 = 0; i < vsc->dev.nvqs; i++) { + VirtQueue *kick_vq = virtio_get_queue(vdev, i); + + if (!virtio_queue_get_desc_addr(vdev, i)) { + continue; + } + event_notifier_set(virtio_queue_get_host_notifier(kick_vq)); + } } static int vhost_user_scsi_connect(DeviceState *dev, Error **errp) @@ -243,9 +283,9 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) return; } - 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 != NULL) { error_propagate(errp, err); return;