From nobody Fri Oct 24 22:00:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519923255252756.4289079446042; Thu, 1 Mar 2018 08:54:15 -0800 (PST) Received: from localhost ([::1]:58113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erRT9-0004G9-6A for importer@patchew.org; Thu, 01 Mar 2018 11:54:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erRLL-0006HZ-0d for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:46:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erRLI-000107-Ow for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:46:07 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54614 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erRLI-0000zY-Hi for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:46:04 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15263818B108; Thu, 1 Mar 2018 16:46:04 +0000 (UTC) Received: from redhat.com (ovpn-123-220.rdu2.redhat.com [10.10.123.220]) by smtp.corp.redhat.com (Postfix) with SMTP id 8A8A69C06A; Thu, 1 Mar 2018 16:46:03 +0000 (UTC) Date: Thu, 1 Mar 2018 18:46:02 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1519922735-29054-8-git-send-email-mst@redhat.com> References: <1519922735-29054-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1519922735-29054-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 01 Mar 2018 16:46:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 01 Mar 2018 16:46:04 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 07/13] vhost: avoid to start/stop virtqueue which is not ready X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jia He , Peter Maydell , Jia He Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jia He In our Armv8a server, we try to configure the vhost scsi but fail to boot up the guest (-machine virt-2.10). The guest's boot failure is very early, even earlier than grub. There are 3 virtqueues (ctrl, event and cmd) for virtio scsi device, but ovmf and seabios will only set the physical address for the 3rd one (cmd). Then in vhost_virtqueue_start(), virtio_queue_get_desc_addr will be 0 for ctrl and event vq when qemu negotiates with ovmf. So vhost_memory_map fails with ENOMEM. This patch just fixs it by early quitting the virtqueue start/stop when virtio_queue_get_desc_addr is 0. Btw, after guest kernel starts, all the 3 queues will be initialized and set address correctly. Already tested on Arm64 and X86_64 qemu. Signed-off-by: Jia He Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 4a583a3..d02d12a 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -345,6 +345,10 @@ static int vhost_verify_ring_mappings(struct vhost_dev= *dev, for (i =3D 0; i < dev->nvqs; ++i) { struct vhost_virtqueue *vq =3D dev->vqs + i; =20 + if (vq->desc_phys =3D=3D 0) { + continue; + } + j =3D 0; r =3D vhost_verify_ring_part_mapping( vq->desc, vq->desc_phys, vq->desc_size, @@ -881,6 +885,11 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 + a =3D virtio_queue_get_desc_addr(vdev, idx); + if (a =3D=3D 0) { + /* Queue might not be ready for start */ + return 0; + } =20 vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); r =3D dev->vhost_ops->vhost_set_vring_num(dev, &state); @@ -906,7 +915,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, } =20 vq->desc_size =3D s =3D l =3D virtio_queue_get_desc_size(vdev, idx); - vq->desc_phys =3D a =3D virtio_queue_get_desc_addr(vdev, idx); + vq->desc_phys =3D a; vq->desc =3D vhost_memory_map(dev, a, &l, 0); if (!vq->desc || l !=3D s) { r =3D -ENOMEM; @@ -989,6 +998,13 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev, .index =3D vhost_vq_index, }; int r; + int a; + + a =3D virtio_queue_get_desc_addr(vdev, idx); + if (a =3D=3D 0) { + /* Don't stop the virtqueue which might have not been started */ + return; + } =20 r =3D dev->vhost_ops->vhost_get_vring_base(dev, &state); if (r < 0) { --=20 MST