From patchwork Thu Dec 1 07:38:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13061014 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 6F381C43217 for ; Thu, 1 Dec 2022 07:39:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0e9U-0007fV-SS; Thu, 01 Dec 2022 02:38:36 -0500 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 1p0e97-0007bc-Ty for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0e96-0007lb-5E for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669880291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dTf7rY4Lx8QooP0oUcumMYDzHQCYIG+RvvZZ42alNCI=; b=YsiKXJ90A7X103Qxgg8aChacJDpidsV4XXCSqV2oDztC/Qr4p8rU3xhs7FV6qfqFLzsqSV 3KTUhijEBrm0YLHVOoB8yFc/9Xejs3cfmp1SOiqNrY6YN5ohf88atS0a89jBdk3cPi1x4Y potORB6DvOcenUVj+D9rKVjGcCBz8lQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-203-IxtQUOFNOiKIhDwr5jOzDQ-1; Thu, 01 Dec 2022 02:38:08 -0500 X-MC-Unique: IxtQUOFNOiKIhDwr5jOzDQ-1 Received: by mail-wm1-f71.google.com with SMTP id v188-20020a1cacc5000000b003cf76c4ae66so2152293wme.7 for ; Wed, 30 Nov 2022 23:38:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dTf7rY4Lx8QooP0oUcumMYDzHQCYIG+RvvZZ42alNCI=; b=DiVlcyMC0rpFrjNHzWT7MztvAZMZ6//KmFyMkWece7+h5nvj6qhe3QOa0/46dytJ4P UH4qYbp8c495ZD2AiwX2aQpFvT14EomGG2JvCX/adEnh6sXdh4Lp8VThJytZqqvsw2Ki 06YtTLHZBP3MC5uHU69Yhpy8nBVQnMoELs8pEWDs74/ZAq9GwouuR5AMZCiyvyPJ0ZJB u9hdscMGuypXsqJutKrKh+x7RjQkk7MCyooN1WP2Eeg52DZMVUCHDROOuy0XTqx04LBL RPsY6I7tpkOzUkti6v05XOaeWT9GODiSaK+oWkA7zIt2zsfPZ+3BUgrfz8VPkTnE6Ael C6Kw== X-Gm-Message-State: ANoB5pkdrcq2piVm1bPt8ngJgPWP2Yvf9zDb/Fshn+uh3Xh0wy1c5K2o FH13C+iMaK8q0ekwBqgC4cNFU6wXUbpCnC2ZNmFy6JeUSV8t4Ha4puN9caRnjJHuAkxX6kyYsv6 MhMV9wAQnLap8+wzWmXPkWuTNG7MpmURO8rQgtpbGGKGEWiPO4O3p07KlovSa X-Received: by 2002:a1c:7715:0:b0:3cf:d18d:3bfe with SMTP id t21-20020a1c7715000000b003cfd18d3bfemr49937806wmi.203.1669880286735; Wed, 30 Nov 2022 23:38:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6RQRVRBwQ0Huug7WtoBiH1/9NdvlwamzgZzF3vtVo5bNsnLCiEjpWKoRsO+xOQCmrUrLcKgA== X-Received: by 2002:a1c:7715:0:b0:3cf:d18d:3bfe with SMTP id t21-20020a1c7715000000b003cfd18d3bfemr49937777wmi.203.1669880286462; Wed, 30 Nov 2022 23:38:06 -0800 (PST) Received: from redhat.com ([2.52.19.245]) by smtp.gmail.com with ESMTPSA id j11-20020a05600c42cb00b003cf37c5ddc0sm4076191wme.22.2022.11.30.23.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 23:38:06 -0800 (PST) Date: Thu, 1 Dec 2022 02:38:03 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Alex =?utf-8?q?Benn=C3=A9e?= , Thomas Huth , Viresh Kumar , Laurent Vivier , Paolo Bonzini Subject: [PULL 1/5] tests/qtests: override "force-legacy" for gpio virtio-mmio tests Message-ID: <20221201073725.44585-2-mst@redhat.com> References: <20221201073725.44585-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221201073725.44585-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Alex Bennée The GPIO device is a VIRTIO_F_VERSION_1 devices but running with a legacy MMIO interface we miss out that feature bit causing confusion. For the GPIO test force the mmio bus to support non-legacy so we can properly test it. Signed-off-by: Alex Bennée Reviewed-by: Michael S. Tsirkin Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1333 Message-Id: <20221130112439.2527228-2-alex.bennee@linaro.org> Acked-by: Thomas Huth Signed-off-by: Michael S. Tsirkin --- tests/qtest/libqos/virtio-gpio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qtest/libqos/virtio-gpio.c b/tests/qtest/libqos/virtio-gpio.c index 762aa6695b..f22d7b5eb5 100644 --- a/tests/qtest/libqos/virtio-gpio.c +++ b/tests/qtest/libqos/virtio-gpio.c @@ -154,7 +154,8 @@ static void virtio_gpio_register_nodes(void) QOSGraphEdgeOptions edge_opts = { }; /* vhost-user-gpio-device */ - edge_opts.extra_device_opts = "id=gpio0,chardev=chr-vhost-user-test"; + edge_opts.extra_device_opts = "id=gpio0,chardev=chr-vhost-user-test " + "-global virtio-mmio.force-legacy=false"; qos_node_create_driver("vhost-user-gpio-device", virtio_gpio_device_create); qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts); From patchwork Thu Dec 1 07:38:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13061017 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 2D4C0C43217 for ; Thu, 1 Dec 2022 07:40:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0e9j-0007iN-Fp; Thu, 01 Dec 2022 02:38:51 -0500 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 1p0e9B-0007bl-Ef for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0e98-0007mm-Vb for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669880294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tb9KGSUYRfX8CCqoogWF4MltmFMZNrMZT5bPAMhdkHY=; b=QKDHakgs7raTxn+uvA2FhhKW9kw3y+b2vCnIAZ7ahllH5PqbhpHdIpOdu727AmtCIuRESa 30bhxuVXKJaTSkkkK7WoG9A7GMYdD5frFjXdsGMdXGe1ekJJUtyr+PXLfSoHi2DvVjaVMT 7kG2N7Fbv+sQ7JSj9H28+3dwTArINng= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-575-wnEcNrZTPxqGF9yOoNeVwg-1; Thu, 01 Dec 2022 02:38:12 -0500 X-MC-Unique: wnEcNrZTPxqGF9yOoNeVwg-1 Received: by mail-wm1-f72.google.com with SMTP id h9-20020a1c2109000000b003cfd37aec58so480091wmh.1 for ; Wed, 30 Nov 2022 23:38:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tb9KGSUYRfX8CCqoogWF4MltmFMZNrMZT5bPAMhdkHY=; b=I8anIAmtuAgGGA4nAIbzwL97k1zm4G32zT9dBC5Ht/KHzvHfQza3vNFSPkq2KtHME5 GfSHEuYDJ3rd6/4nVkdmZQTKmaHfJxNYAPA7pZkIIyFS2vQ7s/MDzopnMzhhRtOdpE9i oHGZ7ELw2dT7v/tm8Ud625ebwoWEDzlD7Zzk95j3IHnEB58smmiAmZUkkGlP2QO5LdQ2 PHKJb48KoeXD550jJLgBeRmewMQG+PppGmCng+upsy3YZjod4wKS4W9/RKsZvsaabch3 KvVWnp3QobRtg+5pqGisuA2U5HU4zOMn6NfyCAskviYle8AjCGG0oZ1hatdHUKFOsS2X 3F8Q== X-Gm-Message-State: ANoB5pnMWKnDUeQUJy/X4QZd/sJJnadM7+2KBy92f0dJvbckqk2uPqiU C9JmURr36ORmOfV8ddhheK+9YDU0YvbiKccSnMRhPWTLU78Bn2TEUX147KRRlHxuFV0YmQCCFfi 5+sb1xGyAxoCz3LyCrBNvBBqbFLbZ0kAoRV+PSF0bSssc1LbHFFrSvOQ3UWdT X-Received: by 2002:adf:ebcf:0:b0:22e:3275:983e with SMTP id v15-20020adfebcf000000b0022e3275983emr40920282wrn.71.1669880291009; Wed, 30 Nov 2022 23:38:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf4KblABr8pQtncU6UjBa287RWNKemnvw0aKgZYFRK8RbpOxOqEKRvmbcZbfdFxl1/IQQUkeNw== X-Received: by 2002:adf:ebcf:0:b0:22e:3275:983e with SMTP id v15-20020adfebcf000000b0022e3275983emr40920242wrn.71.1669880290545; Wed, 30 Nov 2022 23:38:10 -0800 (PST) Received: from redhat.com ([2.52.19.245]) by smtp.gmail.com with ESMTPSA id t17-20020a05600c199100b003c7087f6c9asm8428896wmq.32.2022.11.30.23.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 23:38:09 -0800 (PST) Date: Thu, 1 Dec 2022 02:38:06 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefano Garzarella , German Maglione , Raphael Norwitz , Alex =?utf-8?q?Benn=C3=A9e?= , "Gonglei (Arei)" , Kevin Wolf , Hanna Reitz , Jason Wang , Paolo Bonzini , Fam Zheng , "Dr. David Alan Gilbert" , Stefan Hajnoczi , Viresh Kumar , Mathieu Poirier , qemu-block@nongnu.org, virtio-fs@redhat.com Subject: [PULL 2/5] vhost: enable vrings in vhost_dev_start() for vhost-user devices Message-ID: <20221201073725.44585-3-mst@redhat.com> References: <20221201073725.44585-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221201073725.44585-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella Commit 02b61f38d3 ("hw/virtio: incorporate backend features in features") properly negotiates VHOST_USER_F_PROTOCOL_FEATURES with the vhost-user backend, but we forgot to enable vrings as specified in docs/interop/vhost-user.rst: If ``VHOST_USER_F_PROTOCOL_FEATURES`` has not been negotiated, the ring starts directly in the enabled state. If ``VHOST_USER_F_PROTOCOL_FEATURES`` has been negotiated, the ring is initialized in a disabled state and is enabled by ``VHOST_USER_SET_VRING_ENABLE`` with parameter 1. Some vhost-user front-ends already did this by calling vhost_ops.vhost_set_vring_enable() directly: - backends/cryptodev-vhost.c - hw/net/virtio-net.c - hw/virtio/vhost-user-gpio.c But most didn't do that, so we would leave the vrings disabled and some backends would not work. We observed this issue with the rust version of virtiofsd [1], which uses the event loop [2] provided by the vhost-user-backend crate where requests are not processed if vring is not enabled. Let's fix this issue by enabling the vrings in vhost_dev_start() for vhost-user front-ends that don't already do this directly. Same thing also in vhost_dev_stop() where we disable vrings. [1] https://gitlab.com/virtio-fs/virtiofsd [2] https://github.com/rust-vmm/vhost/blob/240fc2966/crates/vhost-user-backend/src/event_loop.rs#L217 Fixes: 02b61f38d3 ("hw/virtio: incorporate backend features in features") Reported-by: German Maglione Tested-by: German Maglione Signed-off-by: Stefano Garzarella Acked-by: Raphael Norwitz Message-Id: <20221123131630.52020-1-sgarzare@redhat.com> Signed-off-by: Alex Bennée Reviewed-by: Michael S. Tsirkin Message-Id: <20221130112439.2527228-3-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 6 +++-- backends/cryptodev-vhost.c | 4 ++-- backends/vhost-user.c | 4 ++-- hw/block/vhost-user-blk.c | 4 ++-- hw/net/vhost_net.c | 8 +++---- hw/scsi/vhost-scsi-common.c | 4 ++-- hw/virtio/vhost-user-fs.c | 4 ++-- hw/virtio/vhost-user-gpio.c | 4 ++-- hw/virtio/vhost-user-i2c.c | 4 ++-- hw/virtio/vhost-user-rng.c | 4 ++-- hw/virtio/vhost-vsock-common.c | 4 ++-- hw/virtio/vhost.c | 44 ++++++++++++++++++++++++++++++---- hw/virtio/trace-events | 4 ++-- 13 files changed, 67 insertions(+), 31 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 353252ac3e..67a6807fac 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -184,24 +184,26 @@ static inline bool vhost_dev_is_started(struct vhost_dev *hdev) * vhost_dev_start() - start the vhost device * @hdev: common vhost_dev structure * @vdev: the VirtIODevice structure + * @vrings: true to have vrings enabled in this call * * Starts the vhost device. From this point VirtIO feature negotiation * can start and the device can start processing VirtIO transactions. * * Return: 0 on success, < 0 on error. */ -int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); +int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings); /** * vhost_dev_stop() - stop the vhost device * @hdev: common vhost_dev structure * @vdev: the VirtIODevice structure + * @vrings: true to have vrings disabled in this call * * Stop the vhost device. After the device is stopped the notifiers * can be disabled (@vhost_dev_disable_notifiers) and the device can * be torn down (@vhost_dev_cleanup). */ -void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); +void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings); /** * DOC: vhost device configuration handling diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index bc13e466b4..572f87b3be 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -94,7 +94,7 @@ cryptodev_vhost_start_one(CryptoDevBackendVhost *crypto, goto fail_notifiers; } - r = vhost_dev_start(&crypto->dev, dev); + r = vhost_dev_start(&crypto->dev, dev, false); if (r < 0) { goto fail_start; } @@ -111,7 +111,7 @@ static void cryptodev_vhost_stop_one(CryptoDevBackendVhost *crypto, VirtIODevice *dev) { - vhost_dev_stop(&crypto->dev, dev); + vhost_dev_stop(&crypto->dev, dev, false); vhost_dev_disable_notifiers(&crypto->dev, dev); } diff --git a/backends/vhost-user.c b/backends/vhost-user.c index 5dedb2d987..7bfcaef976 100644 --- a/backends/vhost-user.c +++ b/backends/vhost-user.c @@ -85,7 +85,7 @@ vhost_user_backend_start(VhostUserBackend *b) } b->dev.acked_features = b->vdev->guest_features; - ret = vhost_dev_start(&b->dev, b->vdev); + ret = vhost_dev_start(&b->dev, b->vdev, true); if (ret < 0) { error_report("Error start vhost dev"); goto err_guest_notifiers; @@ -120,7 +120,7 @@ vhost_user_backend_stop(VhostUserBackend *b) return; } - vhost_dev_stop(&b->dev, b->vdev); + vhost_dev_stop(&b->dev, b->vdev, true); if (k->set_guest_notifiers) { ret = k->set_guest_notifiers(qbus->parent, diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 0d5190accf..1177064631 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -178,7 +178,7 @@ static int vhost_user_blk_start(VirtIODevice *vdev, Error **errp) } s->dev.vq_index_end = s->dev.nvqs; - ret = vhost_dev_start(&s->dev, vdev); + ret = vhost_dev_start(&s->dev, vdev, true); if (ret < 0) { error_setg_errno(errp, -ret, "Error starting vhost"); goto err_guest_notifiers; @@ -213,7 +213,7 @@ static void vhost_user_blk_stop(VirtIODevice *vdev) return; } - vhost_dev_stop(&s->dev, vdev); + vhost_dev_stop(&s->dev, vdev, true); ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); if (ret < 0) { diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 26e4930676..043058ff43 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -259,7 +259,7 @@ static int vhost_net_start_one(struct vhost_net *net, goto fail_notifiers; } - r = vhost_dev_start(&net->dev, dev); + r = vhost_dev_start(&net->dev, dev, false); if (r < 0) { goto fail_start; } @@ -308,7 +308,7 @@ fail: if (net->nc->info->poll) { net->nc->info->poll(net->nc, true); } - vhost_dev_stop(&net->dev, dev); + vhost_dev_stop(&net->dev, dev, false); fail_start: vhost_dev_disable_notifiers(&net->dev, dev); fail_notifiers: @@ -329,7 +329,7 @@ static void vhost_net_stop_one(struct vhost_net *net, if (net->nc->info->poll) { net->nc->info->poll(net->nc, true); } - vhost_dev_stop(&net->dev, dev); + vhost_dev_stop(&net->dev, dev, false); if (net->nc->info->stop) { net->nc->info->stop(net->nc); } @@ -606,7 +606,7 @@ err_start: assert(r >= 0); } - vhost_dev_stop(&net->dev, vdev); + vhost_dev_stop(&net->dev, vdev, false); return r; } diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index 767f827e55..18ea5dcfa1 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -68,7 +68,7 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) goto err_guest_notifiers; } - ret = vhost_dev_start(&vsc->dev, vdev); + ret = vhost_dev_start(&vsc->dev, vdev, true); if (ret < 0) { error_report("Error start vhost dev"); goto err_guest_notifiers; @@ -101,7 +101,7 @@ void vhost_scsi_common_stop(VHostSCSICommon *vsc) VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); int ret = 0; - vhost_dev_stop(&vsc->dev, vdev); + vhost_dev_stop(&vsc->dev, vdev, true); if (k->set_guest_notifiers) { ret = k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false); diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index dc4014cdef..d97b179e6f 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -76,7 +76,7 @@ static void vuf_start(VirtIODevice *vdev) } fs->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&fs->vhost_dev, vdev); + ret = vhost_dev_start(&fs->vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost: %d", -ret); goto err_guest_notifiers; @@ -110,7 +110,7 @@ static void vuf_stop(VirtIODevice *vdev) return; } - vhost_dev_stop(&fs->vhost_dev, vdev); + vhost_dev_stop(&fs->vhost_dev, vdev, true); ret = k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false); if (ret < 0) { diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index 5851cb3bc9..0b40ebd15a 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -81,7 +81,7 @@ static int vu_gpio_start(VirtIODevice *vdev) */ vhost_ack_features(&gpio->vhost_dev, feature_bits, vdev->guest_features); - ret = vhost_dev_start(&gpio->vhost_dev, vdev); + ret = vhost_dev_start(&gpio->vhost_dev, vdev, false); if (ret < 0) { error_report("Error starting vhost-user-gpio: %d", ret); goto err_guest_notifiers; @@ -139,7 +139,7 @@ static void vu_gpio_stop(VirtIODevice *vdev) return; } - vhost_dev_stop(vhost_dev, vdev); + vhost_dev_stop(vhost_dev, vdev, false); ret = k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false); if (ret < 0) { diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c index 1c9f3d20dc..dc5c828ba6 100644 --- a/hw/virtio/vhost-user-i2c.c +++ b/hw/virtio/vhost-user-i2c.c @@ -46,7 +46,7 @@ static void vu_i2c_start(VirtIODevice *vdev) i2c->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&i2c->vhost_dev, vdev); + ret = vhost_dev_start(&i2c->vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost-user-i2c: %d", -ret); goto err_guest_notifiers; @@ -80,7 +80,7 @@ static void vu_i2c_stop(VirtIODevice *vdev) return; } - vhost_dev_stop(&i2c->vhost_dev, vdev); + vhost_dev_stop(&i2c->vhost_dev, vdev, true); ret = k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, false); if (ret < 0) { diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c index f9084cde58..201a39e220 100644 --- a/hw/virtio/vhost-user-rng.c +++ b/hw/virtio/vhost-user-rng.c @@ -47,7 +47,7 @@ static void vu_rng_start(VirtIODevice *vdev) } rng->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&rng->vhost_dev, vdev); + ret = vhost_dev_start(&rng->vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost-user-rng: %d", -ret); goto err_guest_notifiers; @@ -81,7 +81,7 @@ static void vu_rng_stop(VirtIODevice *vdev) return; } - vhost_dev_stop(&rng->vhost_dev, vdev); + vhost_dev_stop(&rng->vhost_dev, vdev, true); ret = k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, false); if (ret < 0) { diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c index a67a275de2..d21c72b401 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -70,7 +70,7 @@ int vhost_vsock_common_start(VirtIODevice *vdev) } vvc->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&vvc->vhost_dev, vdev); + ret = vhost_dev_start(&vvc->vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost: %d", -ret); goto err_guest_notifiers; @@ -105,7 +105,7 @@ void vhost_vsock_common_stop(VirtIODevice *vdev) return; } - vhost_dev_stop(&vvc->vhost_dev, vdev); + vhost_dev_stop(&vvc->vhost_dev, vdev, true); ret = k->set_guest_notifiers(qbus->parent, vvc->vhost_dev.nvqs, false); if (ret < 0) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index d1c4c20b8c..7fb008bc9e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1777,15 +1777,36 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size, return 0; } +static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable) +{ + if (!hdev->vhost_ops->vhost_set_vring_enable) { + return 0; + } + + /* + * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has not + * been negotiated, the rings start directly in the enabled state, and + * .vhost_set_vring_enable callback will fail since + * VHOST_USER_SET_VRING_ENABLE is not supported. + */ + if (hdev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER && + !virtio_has_feature(hdev->backend_features, + VHOST_USER_F_PROTOCOL_FEATURES)) { + return 0; + } + + return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable); +} + /* Host notifiers must be enabled at this point. */ -int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) +int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings) { int i, r; /* should only be called after backend is connected */ assert(hdev->vhost_ops); - trace_vhost_dev_start(hdev, vdev->name); + trace_vhost_dev_start(hdev, vdev->name, vrings); vdev->vhost_started = true; hdev->started = true; @@ -1830,10 +1851,16 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) goto fail_log; } } + if (vrings) { + r = vhost_dev_set_vring_enable(hdev, true); + if (r) { + goto fail_log; + } + } if (hdev->vhost_ops->vhost_dev_start) { r = hdev->vhost_ops->vhost_dev_start(hdev, true); if (r) { - goto fail_log; + goto fail_start; } } if (vhost_dev_has_iommu(hdev) && @@ -1848,6 +1875,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) } } return 0; +fail_start: + if (vrings) { + vhost_dev_set_vring_enable(hdev, false); + } fail_log: vhost_log_put(hdev, false); fail_vq: @@ -1866,18 +1897,21 @@ fail_features: } /* Host notifiers must be enabled at this point. */ -void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) +void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings) { int i; /* should only be called after backend is connected */ assert(hdev->vhost_ops); - trace_vhost_dev_stop(hdev, vdev->name); + trace_vhost_dev_stop(hdev, vdev->name, vrings); if (hdev->vhost_ops->vhost_dev_start) { hdev->vhost_ops->vhost_dev_start(hdev, false); } + if (vrings) { + vhost_dev_set_vring_enable(hdev, false); + } for (i = 0; i < hdev->nvqs; ++i) { vhost_virtqueue_stop(hdev, vdev, diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 820dadc26c..14fc5b9bb2 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -9,8 +9,8 @@ vhost_section(const char *name) "%s" vhost_reject_section(const char *name, int d) "%s:%d" vhost_iotlb_miss(void *dev, int step) "%p step %d" vhost_dev_cleanup(void *dev) "%p" -vhost_dev_start(void *dev, const char *name) "%p:%s" -vhost_dev_stop(void *dev, const char *name) "%p:%s" +vhost_dev_start(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" +vhost_dev_stop(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" # vhost-user.c From patchwork Thu Dec 1 07:38:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13061016 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 EC5A2C4321E for ; Thu, 1 Dec 2022 07:40:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0e9k-0007iW-8k; Thu, 01 Dec 2022 02:38:52 -0500 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 1p0e9f-0007gp-O6 for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0e9e-0007tV-3R for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669880324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y5/7MrH+QtrO6VCSQCLTGZeCpdV+HusT1OZ+wFAoJKk=; b=V/5DBSSt9MhybZnPip1aFESUn+Tnj6ayQBpJZuDzypLuHbKBYQJ+UJ4pYaPfdcX+vUn/0j EPfgxKd8TyxYBvA8u7e1QCUd+f2yXSWaKNmttsg8D0er1gGHoCS7oVd6vkT+sBkBZbLS+z 8T+eZNgn5nNRXIG89PE+YFDuNheg/QM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-602-YA28AxJqNkqJ4CbiuPJ6Dg-1; Thu, 01 Dec 2022 02:38:43 -0500 X-MC-Unique: YA28AxJqNkqJ4CbiuPJ6Dg-1 Received: by mail-wm1-f69.google.com with SMTP id c126-20020a1c3584000000b003cfffcf7c1aso2180285wma.0 for ; Wed, 30 Nov 2022 23:38:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y5/7MrH+QtrO6VCSQCLTGZeCpdV+HusT1OZ+wFAoJKk=; b=UPmaooHc7+xwdihBOS/sIAxe03ZDXLi9E+6VCqnv+2ICN8xs6kiobHc8dzhiLZJIX2 +rP8MVWY5haeCFJgvD8JlQcal3spzBKrQAYS8v2rdlIEW+ErBVeO81Skuv4YVKLFch/n 21Yj2ukJ8ULUjRf0QQ5CXuPwevRKy4s/2gXGT1z3U+QuMlHTblPyAi81fRDJYk9/TOSw v06/uPAK7wpXpbdXaTU5TZeGtgT/nygJokVPJD9V8TvSwkkx+Om3qwS2AYO6MVcxvOoQ 7ji2Gmax49rrVYp0O8UvpOFQzy7mCmnCH+2t6Ndc7sNgvsZfXhd0QDvbaj7Lu8T9EhiO ipow== X-Gm-Message-State: ANoB5pltSMCfWpGc97yfaLO20np/DrBu0EwfaVZg0dM7S/oWsmpoLKYN szQsQaqRLGaG3myo96OPqQQmQCN2oYxMI8T71qRrjrNdhKT/wcK22qRHlIL95+efqtILogIdey4 OjrHuxHGZ3AlMlYS9DdfBnjT9Rf2Sc04nNrvcTFvVSTiyxspuwMtzV/fgfh7O X-Received: by 2002:a05:600c:5127:b0:3cf:a4c4:777e with SMTP id o39-20020a05600c512700b003cfa4c4777emr41190359wms.72.1669880321908; Wed, 30 Nov 2022 23:38:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7G6wlgY2AMJFXxqpFt2wu8GN0DsCoXLNHLMY7vjAOmuYGsrE9W0hp50xccdfpSFdw3OPTPzA== X-Received: by 2002:a05:600c:5127:b0:3cf:a4c4:777e with SMTP id o39-20020a05600c512700b003cfa4c4777emr41190334wms.72.1669880321597; Wed, 30 Nov 2022 23:38:41 -0800 (PST) Received: from redhat.com ([2.52.19.245]) by smtp.gmail.com with ESMTPSA id q128-20020a1c4386000000b003c71358a42dsm11088186wma.18.2022.11.30.23.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 23:38:41 -0800 (PST) Date: Thu, 1 Dec 2022 02:38:39 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Alex =?utf-8?q?Benn=C3=A9e?= , Viresh Kumar Subject: [PULL 3/5] hw/virtio: add started_vu status field to vhost-user-gpio Message-ID: <20221201073725.44585-4-mst@redhat.com> References: <20221201073725.44585-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221201073725.44585-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Alex Bennée As per the fix to vhost-user-blk in f5b22d06fb (vhost: recheck dev state in the vhost_migration_log routine) we really should track the connection and starting separately. Signed-off-by: Alex Bennée Reviewed-by: Michael S. Tsirkin Message-Id: <20221130112439.2527228-4-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user-gpio.h | 10 ++++++++++ hw/virtio/vhost-user-gpio.c | 11 ++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-user-gpio.h index 4fe9aeecc0..a9305c5e6c 100644 --- a/include/hw/virtio/vhost-user-gpio.h +++ b/include/hw/virtio/vhost-user-gpio.h @@ -28,7 +28,17 @@ struct VHostUserGPIO { VhostUserState vhost_user; VirtQueue *command_vq; VirtQueue *interrupt_vq; + /** + * There are at least two steps of initialization of the + * vhost-user device. The first is a "connect" step and + * second is a "start" step. Make a separation between + * those initialization phases by using two fields. + * + * @connected: see vu_gpio_connect()/vu_gpio_disconnect() + * @started_vu: see vu_gpio_start()/vu_gpio_stop() + */ bool connected; + bool started_vu; /*< public >*/ }; diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index 0b40ebd15a..be9be08b4c 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -86,6 +86,7 @@ static int vu_gpio_start(VirtIODevice *vdev) error_report("Error starting vhost-user-gpio: %d", ret); goto err_guest_notifiers; } + gpio->started_vu = true; /* * guest_notifier_mask/pending not used yet, so just unmask @@ -126,16 +127,12 @@ static void vu_gpio_stop(VirtIODevice *vdev) struct vhost_dev *vhost_dev = &gpio->vhost_dev; int ret; - if (!k->set_guest_notifiers) { + if (!gpio->started_vu) { return; } + gpio->started_vu = false; - /* - * We can call vu_gpio_stop multiple times, for example from - * vm_state_notify and the final object finalisation. Check we - * aren't already stopped before doing so. - */ - if (!vhost_dev_is_started(vhost_dev)) { + if (!k->set_guest_notifiers) { return; } From patchwork Thu Dec 1 07:38:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13061018 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 5F290C43217 for ; Thu, 1 Dec 2022 07:40:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0e9i-0007hn-NH; Thu, 01 Dec 2022 02:38:50 -0500 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 1p0e9R-0007f1-RS for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0e9G-0007pA-8h for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669880300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VnRECOMNXc2EaNkRprFM4t7alhtILlwF0mf/C3kI0lo=; b=geO+NFKrZ0pjj+gECDW4j+vteoRoUEfcUO178fk7vSfY7iieU/akUfH6cZPhymB8UbTLHB H3j1Q2DtQLArqFL3LqP3nFwvkkYWF9xibpkKPubJ6lG7aRoTGnjX3IKDq1fn7yMLt1beKe P+PJdW6x7fk7iqDJY3VGor79Iicc2o4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-306-8IN1ry3UMFqj1fC1355clw-1; Thu, 01 Dec 2022 02:38:19 -0500 X-MC-Unique: 8IN1ry3UMFqj1fC1355clw-1 Received: by mail-wm1-f71.google.com with SMTP id l42-20020a05600c1d2a00b003cf8e70c1ecso2158706wms.4 for ; Wed, 30 Nov 2022 23:38:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VnRECOMNXc2EaNkRprFM4t7alhtILlwF0mf/C3kI0lo=; b=gZMVEJRp6aeg43BdyPmcIunLhQciqh0cY8I3ZeQKsNNocP6Yb/sqKOCXeoKNAN4knt F9zYsItAdKekji9kF9cGozo5sYDKFl9dErc0dPtVoEQt/YlgKtMNOx3vZYiuqDT6kCr/ AgwOW6sxQuQBEWdw6zzH/qGDzDUCf3JFV+eRQkokBI8ISvFY94roPmegmEqs+DubH7TX 3e25NaoTFQCl+abZX5dfBQy78y8EbrTcCGxvB1/ZR4F6ob4IHKM1/sa1//KDGtB1v7dx 5QZLZL+ECnSpO4BrfhaOnvn09dUFGyhj7mizKHOPMkXUP1Ih+xjOD8VU5ehxOvQH7T5W tHeA== X-Gm-Message-State: ANoB5pnrNKOREC/aTzg4DKXnoienLkbhQ67zZiLlsgDWTW2KuhAYKhVt f5+sxe1bw5geFvpxP5wsbg9RtcgQcDaHQK7mJw9/hH//IAGuZp9aS2PimcrBWI7fcBUFtt1OjpG 6/IGubTzp9HWM/Oacn2AF4PJt5H/q/YDS2M6U7RqEsO7hUmrPHbEXheW+TKR0 X-Received: by 2002:a7b:cd85:0:b0:3cf:931c:3cfa with SMTP id y5-20020a7bcd85000000b003cf931c3cfamr38644262wmj.203.1669880297228; Wed, 30 Nov 2022 23:38:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf4/AuBNmxlmgm00Bh28lEkt+kezylJVO13MctngbM6Av2JUMDxUTrQ4oorDkKcIwUO2Aw8HNA== X-Received: by 2002:a7b:cd85:0:b0:3cf:931c:3cfa with SMTP id y5-20020a7bcd85000000b003cf931c3cfamr38644241wmj.203.1669880296887; Wed, 30 Nov 2022 23:38:16 -0800 (PST) Received: from redhat.com ([2.52.19.245]) by smtp.gmail.com with ESMTPSA id h16-20020a05600c2cb000b003c6bbe910fdsm9645388wmc.9.2022.11.30.23.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 23:38:15 -0800 (PST) Date: Thu, 1 Dec 2022 02:38:13 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Alex =?utf-8?q?Benn=C3=A9e?= , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Viresh Kumar , qemu-block@nongnu.org Subject: [PULL 4/5] hw/virtio: generalise CHR_EVENT_CLOSED handling Message-ID: <20221201073725.44585-5-mst@redhat.com> References: <20221201073725.44585-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221201073725.44585-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Alex Bennée ..and use for both virtio-user-blk and virtio-user-gpio. This avoids the circular close by deferring shutdown due to disconnection until a later point. virtio-user-blk already had this mechanism in place so generalise it as a vhost-user helper function and use for both blk and gpio devices. While we are at it we also fix up vhost-user-gpio to re-establish the event handler after close down so we can reconnect later. Signed-off-by: Alex Bennée Reviewed-by: Michael S. Tsirkin Reviewed-by: Raphael Norwitz Message-Id: <20221130112439.2527228-5-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user.h | 18 +++++++++ hw/block/vhost-user-blk.c | 41 +++----------------- hw/virtio/vhost-user-gpio.c | 11 +++++- hw/virtio/vhost-user.c | 71 ++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 37 deletions(-) diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index c6e693cd3f..191216a74f 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -68,4 +68,22 @@ bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp); */ void vhost_user_cleanup(VhostUserState *user); +/** + * vhost_user_async_close() - cleanup vhost-user post connection drop + * @d: DeviceState for the associated device (passed to callback) + * @chardev: the CharBackend associated with the connection + * @vhost: the common vhost device + * @cb: the user callback function to complete the clean-up + * + * This function is used to handle the shutdown of a vhost-user + * connection to a backend. We handle this centrally to make sure we + * do all the steps and handle potential races due to VM shutdowns. + * Once the connection is disabled we call a backhalf to ensure + */ +typedef void (*vu_async_close_fn)(DeviceState *cb); + +void vhost_user_async_close(DeviceState *d, + CharBackend *chardev, struct vhost_dev *vhost, + vu_async_close_fn cb); + #endif diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1177064631..aff4d2b8cb 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -369,17 +369,10 @@ static void vhost_user_blk_disconnect(DeviceState *dev) vhost_user_blk_stop(vdev); vhost_dev_cleanup(&s->dev); -} -static void vhost_user_blk_chr_closed_bh(void *opaque) -{ - DeviceState *dev = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserBlk *s = VHOST_USER_BLK(vdev); - - vhost_user_blk_disconnect(dev); + /* Re-instate the event handler for new connections */ qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, - NULL, opaque, NULL, true); + NULL, dev, NULL, true); } static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) @@ -398,33 +391,9 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) } break; case CHR_EVENT_CLOSED: - if (!runstate_check(RUN_STATE_SHUTDOWN)) { - /* - * A close event may happen during a read/write, but vhost - * code assumes the vhost_dev remains setup, so delay the - * stop & clear. - */ - AioContext *ctx = qemu_get_current_aio_context(); - - qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, NULL, - NULL, NULL, false); - aio_bh_schedule_oneshot(ctx, vhost_user_blk_chr_closed_bh, opaque); - - /* - * Move vhost device to the stopped state. The vhost-user device - * will be clean up and disconnected in BH. This can be useful in - * the vhost migration code. If disconnect was caught there is an - * option for the general vhost code to get the dev state without - * knowing its type (in this case vhost-user). - * - * FIXME: this is sketchy to be reaching into vhost_dev - * now because we are forcing something that implies we - * have executed vhost_dev_stop() but that won't happen - * until vhost_user_blk_stop() gets called from the bh. - * Really this state check should be tracked locally. - */ - s->dev.started = false; - } + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &s->chardev, &s->dev, + vhost_user_blk_disconnect); 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 be9be08b4c..b7b82a1099 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -233,6 +233,8 @@ static int vu_gpio_connect(DeviceState *dev, Error **errp) return 0; } +static void vu_gpio_event(void *opaque, QEMUChrEvent event); + static void vu_gpio_disconnect(DeviceState *dev) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -245,6 +247,11 @@ static void vu_gpio_disconnect(DeviceState *dev) vu_gpio_stop(vdev); vhost_dev_cleanup(&gpio->vhost_dev); + + /* Re-instate the event handler for new connections */ + qemu_chr_fe_set_handlers(&gpio->chardev, + NULL, NULL, vu_gpio_event, + NULL, dev, NULL, true); } static void vu_gpio_event(void *opaque, QEMUChrEvent event) @@ -262,7 +269,9 @@ static void vu_gpio_event(void *opaque, QEMUChrEvent event) } break; case CHR_EVENT_CLOSED: - vu_gpio_disconnect(dev); + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &gpio->chardev, &gpio->vhost_dev, + vu_gpio_disconnect); 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 abe23d4ebe..8f635844af 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -21,6 +21,7 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" +#include "sysemu/runstate.h" #include "sysemu/cryptodev.h" #include "migration/migration.h" #include "migration/postcopy-ram.h" @@ -2670,6 +2671,76 @@ void vhost_user_cleanup(VhostUserState *user) user->chr = NULL; } + +typedef struct { + vu_async_close_fn cb; + DeviceState *dev; + CharBackend *cd; + struct vhost_dev *vhost; +} VhostAsyncCallback; + +static void vhost_user_async_close_bh(void *opaque) +{ + VhostAsyncCallback *data = opaque; + struct vhost_dev *vhost = data->vhost; + + /* + * If the vhost_dev has been cleared in the meantime there is + * nothing left to do as some other path has completed the + * cleanup. + */ + if (vhost->vdev) { + data->cb(data->dev); + } + + g_free(data); +} + +/* + * We only schedule the work if the machine is running. If suspended + * we want to keep all the in-flight data as is for migration + * purposes. + */ +void vhost_user_async_close(DeviceState *d, + CharBackend *chardev, struct vhost_dev *vhost, + vu_async_close_fn cb) +{ + if (!runstate_check(RUN_STATE_SHUTDOWN)) { + /* + * A close event may happen during a read/write, but vhost + * code assumes the vhost_dev remains setup, so delay the + * stop & clear. + */ + AioContext *ctx = qemu_get_current_aio_context(); + VhostAsyncCallback *data = g_new0(VhostAsyncCallback, 1); + + /* Save data for the callback */ + data->cb = cb; + data->dev = d; + data->cd = chardev; + data->vhost = vhost; + + /* Disable any further notifications on the chardev */ + qemu_chr_fe_set_handlers(chardev, + NULL, NULL, NULL, NULL, NULL, NULL, + false); + + aio_bh_schedule_oneshot(ctx, vhost_user_async_close_bh, data); + + /* + * Move vhost device to the stopped state. The vhost-user device + * will be clean up and disconnected in BH. This can be useful in + * the vhost migration code. If disconnect was caught there is an + * option for the general vhost code to get the dev state without + * knowing its type (in this case vhost-user). + * + * Note if the vhost device is fully cleared by the time we + * execute the bottom half we won't continue with the cleanup. + */ + vhost->started = false; + } +} + static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { if (!virtio_has_feature(dev->protocol_features, From patchwork Thu Dec 1 07:38:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13061019 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 DC7E1C4321E for ; Thu, 1 Dec 2022 07:40:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0e9i-0007gw-5G; Thu, 01 Dec 2022 02:38:50 -0500 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 1p0e9M-0007eD-3X for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0e9K-0007pr-6w for qemu-devel@nongnu.org; Thu, 01 Dec 2022 02:38:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669880303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vDKsvFO1e1bP8comV8KZ+aqVZb/5jzxai6mQsMShLUI=; b=IKQWRtASCUuNIEVCUtaMIAtgj1sg2YUhfs3zZiG8iSlOUTuloJ3gA2ey6VMBD71wjbYu3i H0CXNUjlaIAhWFc67aoByYuJjU4+z3DMcNm9DyhzgOM8XEwDgOFns52zegEFqyNP/4AnVV FOwtPoNpWnzUQ6KwYfBHk9tH2eko394= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-619-ATzeHzVHPaWu42GwEcHCow-1; Thu, 01 Dec 2022 02:38:22 -0500 X-MC-Unique: ATzeHzVHPaWu42GwEcHCow-1 Received: by mail-wm1-f72.google.com with SMTP id l42-20020a05600c1d2a00b003cf8e70c1ecso2158735wms.4 for ; Wed, 30 Nov 2022 23:38:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vDKsvFO1e1bP8comV8KZ+aqVZb/5jzxai6mQsMShLUI=; b=3eOgZMsFmXLDDztadZN7pPy1WS5k6WAFwNd8bMH7eCkInzvfwT+uq7mxCSSrRTd5ou vifLyx7DH0GvpNTGBSqLBDccuW3pe2hNO9aidfo8R4N/6FYLA6Xk6Eq6nHEyYoCpn016 xHVMkD90lw80o3sFjezMLrKnMpjoDM2La+qWvKpNzy+VCaYYg1qtiBFIBdlWRKqueIZI m/xHxCTVTdoUFqCnUSYDgjeuUrr0VO73EjPwPC0QD7wLDIPv3LAKSq1iIH+pprFwZpUB 4z/gm0POM/KoOu0I8Ljb+PfJV4dq7495gUlTlRb3ChbdKTSkWXDbB8WHiiNDmn0+7DMm iExw== X-Gm-Message-State: ANoB5pn3tIkSBmX/ylCOu31hPTtpHeHDwa+EXxw7IXKo+pmnOtr1zjFv SBsRuiHBXTMCKK/zIEkhJwdzOX4W0/LflrNnihvGEhqPw0Ep2rv1yrXkI8gmwX9t1pqtjuI1p1+ TfVWIuZ0+8GMj8OtC2tPi3dyu1ok02FXLbgnYbQb9X0B2/LGNh6fQ7e2LkD3G X-Received: by 2002:a05:600c:1c1f:b0:3cf:aa11:93a9 with SMTP id j31-20020a05600c1c1f00b003cfaa1193a9mr40192969wms.138.1669880301126; Wed, 30 Nov 2022 23:38:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf7LhsXhoeLzzSo23QBvqNmiaYVyC/xOmELvmp8Lln8lhT3QG92VODkZfhOsKCM1KtH39ReR9Q== X-Received: by 2002:a05:600c:1c1f:b0:3cf:aa11:93a9 with SMTP id j31-20020a05600c1c1f00b003cfaa1193a9mr40192949wms.138.1669880300784; Wed, 30 Nov 2022 23:38:20 -0800 (PST) Received: from redhat.com ([2.52.19.245]) by smtp.gmail.com with ESMTPSA id o3-20020a5d4743000000b00228cbac7a25sm3622178wrs.64.2022.11.30.23.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 23:38:20 -0800 (PST) Date: Thu, 1 Dec 2022 02:38:17 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Alex =?utf-8?q?Benn=C3=A9e?= , Christian Borntraeger Subject: [PULL 5/5] include/hw: VM state takes precedence in virtio_device_should_start Message-ID: <20221201073725.44585-6-mst@redhat.com> References: <20221201073725.44585-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221201073725.44585-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Alex Bennée The VM status should always preempt the device status for these checks. This ensures the device is in the correct state when we suspend the VM prior to migrations. This restores the checks to the order they where in before the refactoring moved things around. While we are at it lets improve our documentation of the various fields involved and document the two functions. Fixes: 9f6bcfd99f (hw/virtio: move vm_running check to virtio_device_started) Fixes: 259d69c00b (hw/virtio: introduce virtio_device_should_start) Signed-off-by: Alex Bennée Tested-by: Christian Borntraeger Reviewed-by: Michael S. Tsirkin Message-Id: <20221130112439.2527228-6-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index a973811cbf..acfd4df125 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -116,6 +116,13 @@ struct VirtIODevice bool broken; /* device in invalid state, needs reset */ bool use_disabled_flag; /* allow use of 'disable' flag when needed */ bool disabled; /* device in temporarily disabled state */ + /** + * @use_started: true if the @started flag should be used to check the + * current state of the VirtIO device. Otherwise status bits + * should be checked for a current status of the device. + * @use_started is only set via QMP and defaults to true for all + * modern machines (since 4.1). + */ bool use_started; bool started; bool start_on_kick; /* when virtio 1.0 feature has not been negotiated */ @@ -391,6 +398,16 @@ static inline bool virtio_is_big_endian(VirtIODevice *vdev) return false; } +/** + * virtio_device_started() - check if device started + * @vdev - the VirtIO device + * @status - the devices status bits + * + * Check if the device is started. For most modern machines this is + * tracked via the @vdev->started field (to support migration), + * otherwise we check for the final negotiated status bit that + * indicates everything is ready. + */ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) { if (vdev->use_started) { @@ -411,15 +428,11 @@ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) */ static inline bool virtio_device_should_start(VirtIODevice *vdev, uint8_t status) { - if (vdev->use_started) { - return vdev->started; - } - if (!vdev->vm_running) { return false; } - return status & VIRTIO_CONFIG_S_DRIVER_OK; + return virtio_device_started(vdev, status); } static inline void virtio_set_started(VirtIODevice *vdev, bool started)