From patchwork Mon Apr 1 23:58:23 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: 2373491 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 CD7D13FDDA for ; Tue, 2 Apr 2013 00:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759594Ab3DBAJm (ORCPT ); Mon, 1 Apr 2013 20:09:42 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:60182 "EHLO linux-iscsi.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759583Ab3DBAJl (ORCPT ); Mon, 1 Apr 2013 20:09:41 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 4092422D9D5; Mon, 1 Apr 2013 23:58:29 +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 2/3] virtio-pci: Add virtio_queue_valid checks ahead of virtio_queue_get_num Date: Mon, 1 Apr 2013 23:58:23 +0000 Message-Id: <1364860704-11896-3-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 a number of virtio_queue_valid() checks to virtio-pci ahead of virtio_queue_get_num() usage in order to skip operation upon the detection of an uninitialized VQ. There is one exception in virtio_ioport_read():VIRTIO_PCI_QUEUE_NUM, where virtio_queue_get_num() may still be called without a valid vdev->vq[n].vring.desc physical address. v2: Drop now unnecessary virtio_queue_get_num calls (mst) Cc: Michael S. Tsirkin Cc: Asias He Cc: Paolo Bonzini Signed-off-by: Nicholas Bellinger --- hw/virtio-pci.c | 34 +++++++++++++++------------------- 1 files changed, 15 insertions(+), 19 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 0d67b84..1369d9a 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -211,10 +211,9 @@ static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy) } for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) { - if (!virtio_queue_get_num(proxy->vdev, n)) { + if (!virtio_queue_valid(proxy->vdev, n)) { continue; } - r = virtio_pci_set_host_notifier_internal(proxy, n, true, true); if (r < 0) { goto assign_error; @@ -225,10 +224,9 @@ static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy) assign_error: while (--n >= 0) { - if (!virtio_queue_get_num(proxy->vdev, n)) { + if (!virtio_queue_valid(proxy->vdev, n)) { continue; } - r = virtio_pci_set_host_notifier_internal(proxy, n, false, false); assert(r >= 0); } @@ -246,10 +244,9 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy) } for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) { - if (!virtio_queue_get_num(proxy->vdev, n)) { + if (!virtio_queue_valid(proxy->vdev, n)) { continue; } - r = virtio_pci_set_host_notifier_internal(proxy, n, false, false); assert(r >= 0); } @@ -546,8 +543,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) MSIMessage msg; for (queue_no = 0; queue_no < nvqs; queue_no++) { - if (!virtio_queue_get_num(vdev, queue_no)) { - break; + if (!virtio_queue_valid(vdev, queue_no)) { + continue; } vector = virtio_queue_vector(vdev, queue_no); if (vector >= msix_nr_vectors_allocated(dev)) { @@ -593,8 +590,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) int queue_no; for (queue_no = 0; queue_no < nvqs; queue_no++) { - if (!virtio_queue_get_num(vdev, queue_no)) { - break; + if (!virtio_queue_valid(vdev, queue_no)) { + continue; } vector = virtio_queue_vector(vdev, queue_no); if (vector >= msix_nr_vectors_allocated(dev)) { @@ -665,8 +662,8 @@ static int kvm_virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector, int ret, queue_no; for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) { - if (!virtio_queue_get_num(vdev, queue_no)) { - break; + if (!virtio_queue_valid(vdev, queue_no)) { + continue; } if (virtio_queue_vector(vdev, queue_no) != vector) { continue; @@ -695,8 +692,8 @@ static void kvm_virtio_pci_vector_mask(PCIDevice *dev, unsigned vector) int queue_no; for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) { - if (!virtio_queue_get_num(vdev, queue_no)) { - break; + if (!virtio_queue_valid(vdev, queue_no)) { + continue; } if (virtio_queue_vector(vdev, queue_no) != vector) { continue; @@ -717,8 +714,8 @@ static void kvm_virtio_pci_vector_poll(PCIDevice *dev, VirtQueue *vq; for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) { - if (!virtio_queue_get_num(vdev, queue_no)) { - break; + if (!virtio_queue_valid(vdev, queue_no)) { + continue; } vector = virtio_queue_vector(vdev, queue_no); if (vector < vector_start || vector >= vector_end || @@ -790,10 +787,9 @@ static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) } for (n = 0; n < nvqs; n++) { - if (!virtio_queue_get_num(vdev, n)) { - break; + if (!virtio_queue_valid(vdev, n)) { + continue; } - r = virtio_pci_set_guest_notifier(d, n, assign, kvm_msi_via_irqfd_enabled()); if (r < 0) {