From patchwork Thu Dec 20 21:14:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 207711 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5865A2C008A for ; Fri, 21 Dec 2012 08:14:39 +1100 (EST) Received: from localhost ([::1]:54303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlnRt-0008Q9-1l for incoming@patchwork.ozlabs.org; Thu, 20 Dec 2012 16:14:37 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlnRj-0008Q0-VS for qemu-devel@nongnu.org; Thu, 20 Dec 2012 16:14:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TlnRh-0000kH-83 for qemu-devel@nongnu.org; Thu, 20 Dec 2012 16:14:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15617) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlnRh-0000jW-00 for qemu-devel@nongnu.org; Thu, 20 Dec 2012 16:14:25 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBKLENkG008122 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 20 Dec 2012 16:14:23 -0500 Received: from localhost (ovpn-112-23.ams2.redhat.com [10.36.112.23]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qBKLELM4017942; Thu, 20 Dec 2012 16:14:23 -0500 From: Stefan Hajnoczi To: Date: Thu, 20 Dec 2012 22:14:15 +0100 Message-Id: <1356038055-29507-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Alex Williamson , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] vfio-pci: Add missing kvm_enabled() checks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It's necessary to check kvm_enabled() since a QEMU binary can be compiled with KVM support but TCG can be used at run-time. kvm_check_extension() segfaults if kvm_state is NULL. Reported-by: Joe Terranova Signed-off-by: Stefan Hajnoczi --- hw/vfio_pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/vfio_pci.c b/hw/vfio_pci.c index fbfe670..677dc48 100644 --- a/hw/vfio_pci.c +++ b/hw/vfio_pci.c @@ -275,7 +275,8 @@ static void vfio_enable_intx_kvm(VFIODevice *vdev) int ret, argsz; int32_t *pfd; - if (!kvm_irqfds_enabled() || + if (!kvm_enabled() || + !kvm_irqfds_enabled() || vdev->intx.route.mode != PCI_INTX_ENABLED || !kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) { return; @@ -438,7 +439,8 @@ static int vfio_enable_intx(VFIODevice *vdev) * Only conditional to avoid generating error messages on platforms * where we won't actually use the result anyway. */ - if (kvm_irqfds_enabled() && + if (kvm_enabled() && + kvm_irqfds_enabled() && kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) { vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev, vdev->intx.pin);