From patchwork Mon Oct 29 20:00:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1665411 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id CBD37DFB7A for ; Mon, 29 Oct 2012 20:01:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758680Ab2J2UBY (ORCPT ); Mon, 29 Oct 2012 16:01:24 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:41403 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758465Ab2J2UBX (ORCPT ); Mon, 29 Oct 2012 16:01:23 -0400 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9TK0xGJ010118 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 29 Oct 2012 20:01:00 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9TK0uEb008280 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 29 Oct 2012 20:00:57 GMT Received: from abhmt115.oracle.com (abhmt115.oracle.com [141.146.116.67]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q9TK0uGZ013574; Mon, 29 Oct 2012 15:00:56 -0500 Received: from localhost.localdomain (/50.145.178.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 29 Oct 2012 13:00:55 -0700 From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, kirill.shutemov@linux.intel.com, Sasha Levin Subject: [PATCH] kvm tools: don't crash on virtio MSI-X reset Date: Mon, 29 Oct 2012 16:00:30 -0400 Message-Id: <1351540830-3590-1-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 1.7.12.4 X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Handle VIRTIO_MSI_NO_VECTOR by not trying to use it as a valid vector. We still need to remove the GSI and everything, but this is enough to prevent crashes and keep everything working properly for now. Reported-by: Kirill A. Shutemov Signed-off-by: Sasha Levin --- tools/kvm/virtio/pci.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c index 3acaa3a..adc8efc 100644 --- a/tools/kvm/virtio/pci.c +++ b/tools/kvm/virtio/pci.c @@ -146,6 +146,8 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v switch (offset) { case VIRTIO_MSI_CONFIG_VECTOR: vec = vpci->config_vector = ioport__read16(data); + if (vec == VIRTIO_MSI_NO_VECTOR) + break; gsi = irq__add_msix_route(kvm, &vpci->msix_table[vec].msg); @@ -154,6 +156,9 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v case VIRTIO_MSI_QUEUE_VECTOR: vec = vpci->vq_vector[vpci->queue_selector] = ioport__read16(data); + if (vec == VIRTIO_MSI_NO_VECTOR) + break; + gsi = irq__add_msix_route(kvm, &vpci->msix_table[vec].msg); vpci->gsis[vpci->queue_selector] = gsi; if (vdev->ops->notify_vq_gsi) @@ -253,7 +258,7 @@ int virtio_pci__signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq) struct virtio_pci *vpci = vdev->virtio; int tbl = vpci->vq_vector[vq]; - if (virtio_pci__msix_enabled(vpci)) { + if (virtio_pci__msix_enabled(vpci) && tbl != VIRTIO_MSI_NO_VECTOR) { if (vpci->pci_hdr.msix.ctrl & cpu_to_le16(PCI_MSIX_FLAGS_MASKALL) || vpci->msix_table[tbl].ctrl & cpu_to_le16(PCI_MSIX_ENTRY_CTRL_MASKBIT)) { @@ -277,7 +282,7 @@ int virtio_pci__signal_config(struct kvm *kvm, struct virtio_device *vdev) struct virtio_pci *vpci = vdev->virtio; int tbl = vpci->config_vector; - if (virtio_pci__msix_enabled(vpci)) { + if (virtio_pci__msix_enabled(vpci) && tbl != VIRTIO_MSI_NO_VECTOR) { if (vpci->pci_hdr.msix.ctrl & cpu_to_le16(PCI_MSIX_FLAGS_MASKALL) || vpci->msix_table[tbl].ctrl & cpu_to_le16(PCI_MSIX_ENTRY_CTRL_MASKBIT)) { @@ -286,7 +291,7 @@ int virtio_pci__signal_config(struct kvm *kvm, struct virtio_device *vdev) } if (vpci->features & VIRTIO_PCI_F_SIGNAL_MSI) - virtio_pci__signal_msi(kvm, vpci, vpci->config_vector); + virtio_pci__signal_msi(kvm, vpci, tbl); else kvm__irq_trigger(kvm, vpci->config_gsi); } else {