From patchwork Fri Aug 17 06:58:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 1337511 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 9E2BADF266 for ; Fri, 17 Aug 2012 06:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030227Ab2HQG73 (ORCPT ); Fri, 17 Aug 2012 02:59:29 -0400 Received: from thoth.sbs.de ([192.35.17.2]:30491 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964805Ab2HQG7Y (ORCPT ); Fri, 17 Aug 2012 02:59:24 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id q7H6xLOF021000; Fri, 17 Aug 2012 08:59:21 +0200 Received: from mchn199C.mchp.siemens.de.com ([146.254.78.141]) by mail1.siemens.de (8.13.6/8.13.6) with SMTP id q7H6xF70015872; Fri, 17 Aug 2012 08:59:21 +0200 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, Alex Williamson , "Michael S. Tsirkin" Subject: [PATCH v2 09/20] pci-assign: Factor out kvm_device_msix_supported Date: Fri, 17 Aug 2012 08:58:57 +0200 Message-Id: <0a2a9cd2caeb8180753e319677a4c31373f88176.1345186746.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Encapsulate the ugly check if MSI-X assignment is supported in a separate helper function. Signed-off-by: Jan Kiszka --- hw/device-assignment.c | 5 +---- target-i386/kvm.c | 7 +++++++ target-i386/kvm_i386.h | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 1d0af34..80ac2fc 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -1283,10 +1283,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev) } /* Expose MSI-X capability */ pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0); - /* Would really like to test kvm_check_extension(, KVM_CAP_DEVICE_MSIX), - * but the kernel doesn't expose it. Instead do a dummy call to - * KVM_ASSIGN_SET_MSIX_NR to see if it exists. */ - if (pos != 0 && kvm_assign_set_msix_nr(kvm_state, NULL) == -EFAULT) { + if (pos != 0 && kvm_device_msix_supported(kvm_state)) { int bar_nr; uint32_t msix_table_entry; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 51be7b5..789b361 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -2155,6 +2155,13 @@ int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id) KVM_DEV_IRQ_HOST_MSI); } +bool kvm_device_msix_supported(KVMState *s) +{ + /* The kernel lacks a corresponding KVM_CAP, so we probe by calling + * KVM_ASSIGN_SET_MSIX_NR with an invalid parameter. */ + return kvm_vm_ioctl(s, KVM_ASSIGN_SET_MSIX_NR, NULL) == -EFAULT; +} + int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id) { return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_MSIX | diff --git a/target-i386/kvm_i386.h b/target-i386/kvm_i386.h index e827f5b..6f66b6d 100644 --- a/target-i386/kvm_i386.h +++ b/target-i386/kvm_i386.h @@ -27,6 +27,7 @@ int kvm_device_intx_deassign(KVMState *s, uint32_t dev_id, bool use_host_msi); int kvm_device_msi_assign(KVMState *s, uint32_t dev_id, int virq); int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id); +bool kvm_device_msix_supported(KVMState *s); int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id); #endif