From nobody Fri Apr 4 22:52:55 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=1741947438; cv=none; d=zohomail.com; s=zohoarc; b=fkJIqmOoLIP1IB7Kb7miEZGG8HkqIG3HdT+7UMA3WfYsgg00kZ0C3zay+jUzRT9J60dwvOna9fIXCT8hBz7uYHp2pj2sQ2ge8fPlHCky1d5qzmlgcYs1EhfpMxZnpmqcnajfT2JYzWVcdpwncTWNh6gIuydIzptKBhJFeGdxCSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741947438; 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=Eh6xZmod1XJzdJDqa+dorzqnDF3twPcYJbdIGQ8yqlo=; b=jhYz/n9Ct8lO8QYqM06Qnz9gkH4Db69YcdDi9a8LJg4na2vDHgcVQZiS5bxhrcXrZr84bMyXvbuoRh2pK8ZY/3lvuGUPQuJXFRNnx2nJ9g5U/ZuWgyrffF92aucwny5bBZmgbX3ZRE8X4buXco3GN11bPdnUHGgUvSV9x/8efQU= 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 17419474388211006.5684178448713; Fri, 14 Mar 2025 03:17:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tt25h-00063t-Ec; Fri, 14 Mar 2025 06:16:33 -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 1tt25E-0005oe-PB for qemu-devel@nongnu.org; Fri, 14 Mar 2025 06:16:06 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tt25A-000356-9L for qemu-devel@nongnu.org; Fri, 14 Mar 2025 06:16:03 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2239aa5da08so37674415ad.3 for ; Fri, 14 Mar 2025 03:15:59 -0700 (PDT) Received: from fedora.smartx.com ([103.85.74.92]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7371169549fsm2698898b3a.131.2025.03.14.03.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 03:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1741947357; x=1742552157; 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=Eh6xZmod1XJzdJDqa+dorzqnDF3twPcYJbdIGQ8yqlo=; b=kZYZGZBzqVujGHqanFRetPGum5+sGR+1Grh5XCqARcGGYKlRkjSAs7ff+lEovnnSJ/ nWlkleYQb2W+kAG1QaZtWQLHQERfyEpZ1+6yTPgBx/nRkwxBexEKHRh8ouXaVfmGoNRy nuosdtQ9CJmCFyF9ZwQ/gFk2GSCWZ22Y3MOaMbInAshvNkVIoZxIMDm21NZpsOUHwfnO 5GZRGAVw/iIRZtmJOEnmD7IzkKlRizZjKz+yuRt5LxW1JBDbGbl05juUXOnvPMIxjzSU u3d9PJvotFBjp5e95DxFvDZoTyclfGDJAcem5eAG4SlFIgkRR1r+x60bMBoF8Rh87wRi +Exg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741947357; x=1742552157; 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=Eh6xZmod1XJzdJDqa+dorzqnDF3twPcYJbdIGQ8yqlo=; b=TWm//psX1TM1lxUrXLBZS8yFybPNKUrP1Bkf2vLFfRv/dtGLVd1xo+uOSLyrLEtXHA e3UrHInrI03K+QS+41U5d1AzSrkxuDJNiCuAIONWmXrsHwHKB/qhIDEHCFOdw0abVt74 SXuDRl8Sb14M2bjpM7MLpYCXXBVzArxHRKoYaDvnA/kN0rbpPCkzl7D4hZI4MgXT6T1N If96GhZXkpOgVcoZbV6saM2q3tzpgS0V8sDbVfSsewQhEV99lg8p3lxerVUuvNen1s9R FjFAt4VysRpPmw00lGDkMeuF4eDGMjPrvLSvTvT6WM4Qxa3HNchSt9jTMeWjgBabKUht YZPA== X-Gm-Message-State: AOJu0Yw4D0ro3gpJjPJm0QxeNdTQXu/xDzm4M/w5HoFSHbHoom/rYSYZ hd8UJjfLBR9rlKXj4iFnBScoaZ5qLKupWvuw0iwBsI+ZPcxIOrH2gAq53WtOukvDWVNnLbquXwx V4YNwIn4Xymo= X-Gm-Gg: ASbGncvpi4ymkPB+BpGOaXRAC2QxtuqC2EoJrUQwYt2gq6U7xknTFKHVVvsmxYXl8T9 XW8Rlpmhwg1bW0ZFRGo12o9HgjjEfyjAiP94DljwuyLmZIoVy0tev5ldFxOUN2mo0Rlk9jbXoA8 j4sOsb4lYctPWVncCnpNSQoxOyAwItCc29FEQCHRKt5/Z757SSpo3y4FkxOP03GUYQLAsCtBGAY YzT3mSz0liWUxWLqsU7/nzjprFinypN4lmawQXah0pOfKSscSUnGnGCpf6g1dQ86gFrAGKFHnPf DqjI0ziBWqrhyFlDFQxojRMGLJ1Xf0IP2tVCVXfbiFZQJ95wPJoM X-Google-Smtp-Source: AGHT+IELjadHM3CDZrgwr1snAkeKV/1wkKjaE7JoNZxBM7Ewnps9JWQB+8uU43QbznIX0azeh46AuA== X-Received: by 2002:a05:6a00:2e85:b0:736:7960:981f with SMTP id d2e1a72fcca58-73722354755mr3047213b3a.8.1741947357100; Fri, 14 Mar 2025 03:15:57 -0700 (PDT) From: Haoqian He To: qemu-devel@nongnu.org Cc: fengli@smartx.com, yuhua@smartx.com, Raphael Norwitz , "Michael S. Tsirkin" , Stefano Garzarella , Kevin Wolf , Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini , Fam Zheng , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Richard Henderson , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v2 2/3] vhost: return failure if stop virtqueue failed in vhost_dev_stop Date: Fri, 14 Mar 2025 06:15:33 -0400 Message-ID: <20250314101535.1059308-3-haoqian.he@smartx.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250314101535.1059308-1-haoqian.he@smartx.com> References: <20250309090708.3928953-1-haoqian.he@smartx.com> <20250314101535.1059308-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::62e; envelope-from=haoqian.he@smartx.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1741947440997019000 Content-Type: text/plain; charset="utf-8" The backend maybe crash when vhost_dev_stop and GET_VRING_BASE would fail, we can return failure to indicate the connection with the backend is broken. Signed-off-by: Haoqian He --- hw/virtio/vhost.c | 27 +++++++++++++++------------ include/hw/virtio/vhost.h | 8 +++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 6aa72fd434..c82bbbe4cc 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1368,23 +1368,23 @@ 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 { .index =3D vhost_vq_index, }; - int r; + int r =3D 0; =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); + r |=3D dev->vhost_ops->vhost_get_vring_base(dev, &state); if (r < 0) { VHOST_OPS_DEBUG(r, "vhost VQ %u ring restore failed: %d", idx, r); /* Connection to the backend is broken, so let's sync internal @@ -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.48.1