From nobody Thu Apr 3 11:41:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=smartx.com ARC-Seal: i=1; a=rsa-sha256; t=1743057910; cv=none; d=zohomail.com; s=zohoarc; b=PS+azENqCzKo0DcRbV08jod1E92MnaLJHlHgdHpcSDDaKhxBodc1qNAdSwP4JAX+zC621m5DTozn2xZrgYwlz0csAGDnHxNIit3D/huze/J27zliIEet7F95J8xPelcI+UQGhlSHrvnw5NeMu2t2hbGzs2DDBn190UWHH2ss35Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1743057910; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4NXX1X4hRiRNZUknx8LsP9b/fPPtl0kWy3TtPAhKCeU=; b=EaR8/Ip7GZoV3D70dzNF3G67IBkZN+BgwFbGdTbXYb7wo6Eejy4kIMkQWQJ3OwyeqLvDjgggc6/BEGbyYEgjvuaj5ycMefKYX77DfFV2pWbp1bXHzjgKipOFmyV4kKiiO1P8qfsx0xk8U0MtUoVkhhRKS9MC6/oTHZ1kG33D2qw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1743057909961685.8925719012374; Wed, 26 Mar 2025 23:45:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1txgyN-0002Uc-3m; Thu, 27 Mar 2025 02:44:15 -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 1txgyK-0002To-SY for qemu-devel@nongnu.org; Thu, 27 Mar 2025 02:44:12 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1txgyI-0004Fw-II for qemu-devel@nongnu.org; Thu, 27 Mar 2025 02:44:12 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-22435603572so12615485ad.1 for ; Wed, 26 Mar 2025 23:44:10 -0700 (PDT) Received: from fedora.smartx.com ([2001:df0:a640:1::4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22780f4599fsm121983015ad.67.2025.03.26.23.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Mar 2025 23:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1743057849; x=1743662649; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4NXX1X4hRiRNZUknx8LsP9b/fPPtl0kWy3TtPAhKCeU=; b=XG1lz4C5yat9FB3R1xnvmFDgvGFcFMntF9uHuu7uEMlK02lTcvaGS0zVWxuqpux8tO HOpoXwsQhKOJStAWhAk97A6OHsExK6bnyDqxHo1rqpMz9adrJeyi9B74b8ZUMmywUMRT VV6uIX0OhSFprG5rvPE8FjSrZtb+FuFW++GbQu64Vts+kpGv6xD5h7RhRzObh/216RHl 681eaEGCoX/kC8H5Rv5aHtMoQzgJV3373jutwDcQiv3c7GGkzhoZy1E7KdDVCIY8HHcK hyM+KmI+2DSGsNrGGQ0A1vnmOhgNek0K/DuvYr0C4KpbPONS9kALkTQ7r2jECmwuGrBh TxBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743057849; x=1743662649; 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=4NXX1X4hRiRNZUknx8LsP9b/fPPtl0kWy3TtPAhKCeU=; b=CzHA2+rpGwJLSqncuu9nbtSndKkaQiPXXZwC9f64TmQozmW28EPhvU54cAHKuFlr5q 1cVO2SrO9Ptm6a3oeGXPrHjkrggHXYcZEJm3fgeCp5wtGkbwF9NEmUroSLCbG8/xbhtV vd4O3/u1F3kYgTMPLJXKN7kBfFUAyu1nuwSsHmCMghoUij5cKdt16MWN838kgctvdrjp ID2FQg+ShSLplf0LyS97WztJBXaZopC8/cWzO+LlPGjbib49KHmkoU2pRX/hRAjz6+hd eQyWDG4Mysk8yfnC+jbZ8tC8hZc+WbHYK2qQrNcZqxuy+IS0UrK7CVYqiZREeGH4GONm A0tQ== X-Gm-Message-State: AOJu0YxBIvD+8b4Rc6MRTxv5oPlicdIQLgVk0zqEbHWgC7RoJgnqNI26 Ui5XhNeHkRrlX1S1X4LniYOMJNObzPi0l9Io4HfYiYDTReqe6ji9kAbj0Z4lDcCLm0YwevnZjEV FyJM= X-Gm-Gg: ASbGncstnDKzC4WBHd8YUG0VP7RhqrBpb4QDh6qycNoX1HI5lEvmKiURjLbRaLQBY7h jsZXW4Ij1UaC0k6rGoitmjrdg7KLYeGJB6FuPNqT5K1vFgcz18T/VB4KinQSCaYGe7L+P1/U+Rh O0QgJm9IdfBzeSPUluzZvtwhGaIW111ot6plieL7mRQ9k+zGX66JFnZZSekyV9eGVx5lbnoOq5b dA0KWiN8CjNdZmp2qSX1T/J+XNqxWJ7OwriE+crPUk5ZsUmAUwIk4m3WkhinQL1Uc47v/JR+eox +KQ98yt3ZQurzJVbGT2UVG250e+qIRs= X-Google-Smtp-Source: AGHT+IHaOhLpe6TbeM+DqsxZp8oHnSg44s7BnhqVeoz3PH/V5XigwqmHEVGhiMCVf2y/Ww08jEXj4A== X-Received: by 2002:a17:902:daca:b0:223:fabd:4f99 with SMTP id d9443c01a7336-2280482a885mr40124565ad.5.1743057848723; Wed, 26 Mar 2025 23:44:08 -0700 (PDT) From: Haoqian He To: qemu-devel@nongnu.org, sgarzare@redhat.com, mst@redhat.com, raphael@enfabrica.net Cc: fengli@smartx.com, yuhua@smartx.com, Kevin Wolf , Hanna Reitz , Stefan Hajnoczi , Laurent Vivier , Amit Shah , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Gerd Hoffmann , Jason Wang , Fam Zheng , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , mzamazal@redhat.com (reviewer:vhost-user-scmi), David Hildenbrand , "Gonglei (Arei)" , Eric Auger , Richard Henderson , qemu-block@nongnu.org (open list:Block layer core), virtio-fs@lists.linux.dev (open list:virtiofs) Subject: [PATCH v3 2/3] vhost: return failure if stop virtqueue failed in vhost_dev_stop Date: Thu, 27 Mar 2025 02:43:46 -0400 Message-ID: <20250327064348.3595732-3-haoqian.he@smartx.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250327064348.3595732-1-haoqian.he@smartx.com> References: <20250314101535.1059308-1-haoqian.he@smartx.com> <20250327064348.3595732-1-haoqian.he@smartx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=haoqian.he@smartx.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1743057911744019100 Content-Type: text/plain; charset="utf-8" This patch captures the error of vhost_virtqueue_stop() in vhost_dev_stop() and returns the error upward. Specifically, if QEMU is disconnected from the vhost backend, some actions in vhost_dev_stop() will fail, such as sending vhost-user messages to the backend (GET_VRING_BASE, SET_VRING_ENABLE) and vhost_reset_status. Considering that both set_vring_enable and vhost_reset_status require setti= ng the specific virtio feature bit, we can capture vhost_virtqueue_stop()'s error to indicate that QEMU has lost connection with the backend. This patch is the pre patch for 'vhost-user: return failure if backend cras= hes when live migration', which makes the live migration aware of the loss of connection with the vhost-user backend and aborts the live migration. Signed-off-by: Haoqian He --- hw/virtio/vhost.c | 23 +++++++++++++---------- include/hw/virtio/vhost.h | 8 +++++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 6aa72fd434..bdd945c18d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1368,10 +1368,10 @@ fail_alloc_desc: return r; } =20 -void vhost_virtqueue_stop(struct vhost_dev *dev, - struct VirtIODevice *vdev, - struct vhost_virtqueue *vq, - unsigned idx) +int vhost_virtqueue_stop(struct vhost_dev *dev, + struct VirtIODevice *vdev, + struct vhost_virtqueue *vq, + unsigned idx) { int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_state state =3D { @@ -1381,7 +1381,7 @@ void vhost_virtqueue_stop(struct vhost_dev *dev, =20 if (virtio_queue_get_desc_addr(vdev, idx) =3D=3D 0) { /* Don't stop the virtqueue which might have not been started */ - return; + return 0; } =20 r =3D dev->vhost_ops->vhost_get_vring_base(dev, &state); @@ -1412,6 +1412,7 @@ void vhost_virtqueue_stop(struct vhost_dev *dev, 0, virtio_queue_get_avail_size(vdev, idx)); vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), 0, virtio_queue_get_desc_size(vdev, idx)); + return r; } =20 static int vhost_virtqueue_set_busyloop_timeout(struct vhost_dev *dev, @@ -2136,9 +2137,10 @@ fail_features: } =20 /* Host notifiers must be enabled at this point. */ -void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vring= s) +int vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings) { int i; + int rc =3D 0; =20 /* should only be called after backend is connected */ assert(hdev->vhost_ops); @@ -2157,10 +2159,10 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIOD= evice *vdev, bool vrings) vhost_dev_set_vring_enable(hdev, false); } for (i =3D 0; i < hdev->nvqs; ++i) { - vhost_virtqueue_stop(hdev, - vdev, - hdev->vqs + i, - hdev->vq_index + i); + rc |=3D vhost_virtqueue_stop(hdev, + vdev, + hdev->vqs + i, + hdev->vq_index + i); } if (hdev->vhost_ops->vhost_reset_status) { hdev->vhost_ops->vhost_reset_status(hdev); @@ -2177,6 +2179,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) hdev->started =3D false; vdev->vhost_started =3D false; hdev->vdev =3D NULL; + return rc; } =20 int vhost_net_set_backend(struct vhost_dev *hdev, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index a9469d50bc..fd96ec9c39 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -232,8 +232,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevi= ce *vdev, bool vrings); * 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). + * + * Return: 0 on success, !=3D 0 on error when stopping dev. */ -void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vring= s); +int vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings= ); =20 /** * DOC: vhost device configuration handling @@ -333,8 +335,8 @@ int vhost_device_iotlb_miss(struct vhost_dev *dev, uint= 64_t iova, int write); =20 int vhost_virtqueue_start(struct vhost_dev *dev, struct VirtIODevice *vdev, struct vhost_virtqueue *vq, unsigned idx); -void vhost_virtqueue_stop(struct vhost_dev *dev, struct VirtIODevice *vdev, - struct vhost_virtqueue *vq, unsigned idx); +int vhost_virtqueue_stop(struct vhost_dev *dev, struct VirtIODevice *vdev, + struct vhost_virtqueue *vq, unsigned idx); =20 void vhost_dev_reset_inflight(struct vhost_inflight *inflight); void vhost_dev_free_inflight(struct vhost_inflight *inflight); --=20 2.44.0