From patchwork Tue Nov 24 13:35:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 7691171 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7F9E39F2E9 for ; Tue, 24 Nov 2015 13:49:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B42C320830 for ; Tue, 24 Nov 2015 13:49:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D390E2082B for ; Tue, 24 Nov 2015 13:48:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753729AbbKXNsz (ORCPT ); Tue, 24 Nov 2015 08:48:55 -0500 Received: from mga14.intel.com ([192.55.52.115]:35891 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754067AbbKXNsj (ORCPT ); Tue, 24 Nov 2015 08:48:39 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 24 Nov 2015 05:48:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,338,1444719600"; d="scan'208";a="858388945" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.159.159]) by orsmga002.jf.intel.com with ESMTP; 24 Nov 2015 05:48:34 -0800 From: Lan Tianyu To: aik@ozlabs.ru, alex.williamson@redhat.com, amit.shah@redhat.com, anthony@codemonkey.ws, ard.biesheuvel@linaro.org, blauwirbel@gmail.com, cornelia.huck@de.ibm.com, eddie.dong@intel.com, nrupal.jani@intel.com, agraf@suse.de, kvm@vger.kernel.org, pbonzini@redhat.com, qemu-devel@nongnu.org, emil.s.tantilov@intel.com, gerlitz.or@gmail.com, donald.c.skidmore@intel.com, mark.d.rustad@intel.com, mst@redhat.com, kraxel@redhat.com, lcapitulino@redhat.com, quintela@redhat.com Cc: Lan Tianyu Subject: [RFC PATCH V2 03/10] Qemu/VFIO: Rework vfio_std_cap_max_size() function Date: Tue, 24 Nov 2015 21:35:20 +0800 Message-Id: <1448372127-28115-4-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1448372127-28115-1-git-send-email-tianyu.lan@intel.com> References: <1448372127-28115-1-git-send-email-tianyu.lan@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use new ioctl cmd VFIO_GET_PCI_CAP_INFO to get PCI cap table size. This helps to get accurate table size and faciliate to find free PCI config space regs for faked PCI capability. Current code assigns PCI config space regs from the start of last PCI capability table to pos 0xff to the last capability and occupy some free PCI config space regs. Signed-off-by: Lan Tianyu --- hw/vfio/pci.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5c3f8a7..29845e3 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2344,18 +2344,20 @@ static void vfio_unmap_bars(VFIOPCIDevice *vdev) /* * General setup */ -static uint8_t vfio_std_cap_max_size(PCIDevice *pdev, uint8_t pos) +static uint8_t vfio_std_cap_max_size(VFIOPCIDevice *vdev, uint8_t cap) { - uint8_t tmp, next = 0xff; + struct vfio_pci_cap_info reg_info = { + .argsz = sizeof(reg_info), + .index = VFIO_PCI_CAP_GET_SIZE, + .cap = cap + }; + int ret; - for (tmp = pdev->config[PCI_CAPABILITY_LIST]; tmp; - tmp = pdev->config[tmp + 1]) { - if (tmp > pos && tmp < next) { - next = tmp; - } - } + ret = ioctl(vdev->vbasedev.fd, VFIO_GET_PCI_CAP_INFO, ®_info); + if (ret || reg_info.size == 0) + error_report("vfio: Failed to find free PCI config reg: %m\n"); - return next - pos; + return reg_info.size; } static void vfio_set_word_bits(uint8_t *buf, uint16_t val, uint16_t mask) @@ -2521,7 +2523,7 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos) * Since QEMU doesn't actually handle many of the config accesses, * exact size doesn't seem worthwhile. */ - size = vfio_std_cap_max_size(pdev, pos); + size = vfio_std_cap_max_size(vdev, cap_id); /* * pci_add_capability always inserts the new capability at the head