From patchwork Wed Feb 28 09:35:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10247805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F79160365 for ; Wed, 28 Feb 2018 14:51:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1290E288DE for ; Wed, 28 Feb 2018 14:51:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 070E128927; Wed, 28 Feb 2018 14:51:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 15DA828D98 for ; Wed, 28 Feb 2018 14:51:02 +0000 (UTC) Received: from localhost ([::1]:44754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er34N-00038I-UD for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Feb 2018 09:50:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqyA8-0001lP-CN for qemu-devel@nongnu.org; Wed, 28 Feb 2018 04:36:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqyA5-0000Zp-8O for qemu-devel@nongnu.org; Wed, 28 Feb 2018 04:36:36 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:38542) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eqyA5-0000ZO-2r for qemu-devel@nongnu.org; Wed, 28 Feb 2018 04:36:33 -0500 Received: by mail-pg0-x243.google.com with SMTP id l24so738669pgc.5 for ; Wed, 28 Feb 2018 01:36:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=xsRHHwTpJ8GM/K33a/cL3Hwqups3DMjZ/B+i9YoL3UI=; b=IWOLSEfmz7SHIy8vWpz0hbAu54edHIKviafm040Qs3J9ybwuowvQMpNVb2WLwVmp7r GereBoh3/+lOV2huByWdoomfI/8/aSTpJmcV3SUOtolEQIAGH324qiZs+BCy4GC9PO6d 9ZxIJsJuBxwJ6TcGHgMABpYSdWSb3LA54cmAtxBJtH47qmjTi01tWFJxrTi45Slo1EvG tvlMZ0jGVgGr4vlFZ55+c3l67/blHH6Cv7Flt+WYesxSzK2IT5k9RRFLOpirndywhyot eJ85XlfcGs+Mp6z2KVfTVM71tYYPY63VQ4wbeacmxy5vqO+qxqi22TXC/j4qTlT0OP7A lHNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xsRHHwTpJ8GM/K33a/cL3Hwqups3DMjZ/B+i9YoL3UI=; b=a+ob/Nnliq+mlP4D5aIO3iqxEkZBUbKO+E9w6B75FMmF1L9GcJ0D/gZ2TzDqtert6W E6e1p5d3fL+4RiKC51lzBzESPHS/vyaQq0hnfhx4yHQhOzClj5BMQowDpxYUU3l0S819 Oz9+eHcDVop7FJuXSRwu1M7qsaZZI8RQuFLq0TyyBxPXe0lsz/wqHqCjw30vVGGyxy+x okGhG0zDKfvhm2kJiFsex4ISdbHdUOBAkIfEidK96c7eNpowl/iGtQ3Va+YKGFDhopPi LmihFNm8MONBs3PFpTSHdDBiQfz51Vf2VAQ175dwcmDelqapteG/zF9+trZbmNHyPE33 kivw== X-Gm-Message-State: APf1xPBPvtqaduSvD/TWyTxOpD1uv8PTEfh2eteXOovBEgRya9DICIIh 850KsCinz2GgUdummz7sHeo= X-Google-Smtp-Source: AH8x224evd2bbtSKXPz6g1I+WKDOEnh7mLG8p1LOho5Xkiny02F67lYnjKDSr+F+lIka7ASYXcQftA== X-Received: by 10.101.90.75 with SMTP id z11mr13486924pgs.29.1519810591913; Wed, 28 Feb 2018 01:36:31 -0800 (PST) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id e127sm2686177pfe.157.2018.02.28.01.36.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Feb 2018 01:36:31 -0800 (PST) From: Jia He To: "Michael S. Tsirkin" , qemu-devel@nongnu.org Date: Wed, 28 Feb 2018 01:35:28 -0800 Message-Id: <1519810529-4034-1-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 X-Mailman-Approved-At: Wed, 28 Feb 2018 09:50:03 -0500 Subject: [Qemu-devel] [PATCH 1/2] 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 , Jia He , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 4a44e6e..00f2512 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 = 0; i < dev->nvqs; ++i) { struct vhost_virtqueue *vq = dev->vqs + i; + if (vq->desc_phys == 0) { + continue; + } + j = 0; r = 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 = virtio_get_queue(vdev, idx); + a = virtio_queue_get_desc_addr(vdev, idx); + if (a == 0) { + /* Queue might not be ready for start */ + return 0; + } vq->num = state.num = virtio_queue_get_num(vdev, idx); r = dev->vhost_ops->vhost_set_vring_num(dev, &state); @@ -906,7 +915,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, } vq->desc_size = s = l = virtio_queue_get_desc_size(vdev, idx); - vq->desc_phys = a = virtio_queue_get_desc_addr(vdev, idx); + vq->desc_phys = a; vq->desc = vhost_memory_map(dev, a, &l, 0); if (!vq->desc || l != s) { r = -ENOMEM; @@ -989,6 +998,13 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev, .index = vhost_vq_index, }; int r; + int a; + + a = virtio_queue_get_desc_addr(vdev, idx); + if (a == 0) { + /* Don't stop the virtqueue which might have not been started */ + return; + } r = dev->vhost_ops->vhost_get_vring_base(dev, &state); if (r < 0) {