From patchwork Mon Apr 1 23:58:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 2373511 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 0D3A3402E1 for ; Tue, 2 Apr 2013 00:09:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759610Ab3DBAJo (ORCPT ); Mon, 1 Apr 2013 20:09:44 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:60188 "EHLO linux-iscsi.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759582Ab3DBAJn (ORCPT ); Mon, 1 Apr 2013 20:09:43 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 3466B22D9D6; Mon, 1 Apr 2013 23:58:31 +0000 (UTC) From: "Nicholas A. Bellinger" To: target-devel Cc: lf-virt , kvm-devel , qemu-devel , "Michael S. Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Asias He , Anthony Liguori , Nicholas Bellinger Subject: [PATCH-v2 3/3] vhost: Skip uninitialized VQs in vhost_virtqueue_[start, stop] Date: Mon, 1 Apr 2013 23:58:24 +0000 Message-Id: <1364860704-11896-4-git-send-email-nab@linux-iscsi.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1364860704-11896-1-git-send-email-nab@linux-iscsi.org> References: <1364860704-11896-1-git-send-email-nab@linux-iscsi.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nicholas Bellinger This patch adds virtio_queue_valid() checks in vhost_virtqueue_start() and vhost_virtqueue_stop() to avoid uninitialized VQs during vhost-scsi-pci seabios operation, where we currently expect only the request VQ to have been initialized before virtio-scsi LLD guest hand-off. Also, go ahead and skip the same uninitialized VQs during sanity checks within vhost_verify_ring_mappings() by checking vq->ring_[phys,size] directly. Cc: Michael S. Tsirkin Cc: Asias He Cc: Paolo Bonzini Signed-off-by: Nicholas Bellinger --- hw/vhost.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/hw/vhost.c b/hw/vhost.c index 4d6aee3..832cc89 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -314,6 +314,9 @@ static int vhost_verify_ring_mappings(struct vhost_dev *dev, hwaddr l; void *p; + if (!vq->ring_phys || !vq->ring_size) { + continue; + } if (!ranges_overlap(start_addr, size, vq->ring_phys, vq->ring_size)) { continue; } @@ -645,6 +648,10 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs); + if (!virtio_queue_valid(vdev, idx)) { + return 0; + } + vq->num = state.num = virtio_queue_get_num(vdev, idx); r = ioctl(dev->control, VHOST_SET_VRING_NUM, &state); if (r) { @@ -732,6 +739,11 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev, }; int r; assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs); + + if (!virtio_queue_valid(vdev, idx)) { + return; + } + r = ioctl(dev->control, VHOST_GET_VRING_BASE, &state); if (r < 0) { fprintf(stderr, "vhost VQ %d ring restore failed: %d\n", idx, r);