From patchwork Fri Jan 29 06:38:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhai, Edwin" X-Patchwork-Id: 75664 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o0T6clC5011483 for ; Fri, 29 Jan 2010 06:38:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751143Ab0A2Gip (ORCPT ); Fri, 29 Jan 2010 01:38:45 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752540Ab0A2Gip (ORCPT ); Fri, 29 Jan 2010 01:38:45 -0500 Received: from mga09.intel.com ([134.134.136.24]:32646 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751062Ab0A2Gio (ORCPT ); Fri, 29 Jan 2010 01:38:44 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 28 Jan 2010 22:38:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.49,366,1262592000"; d="scan'208";a="488031154" Received: from edwin-gen.sh.intel.com (HELO [10.239.13.63]) ([10.239.13.63]) by orsmga002.jf.intel.com with ESMTP; 28 Jan 2010 22:38:31 -0800 Message-ID: <4B628274.5020005@intel.com> Date: Fri, 29 Jan 2010 14:38:44 +0800 From: "Zhai, Edwin" User-Agent: Thunderbird 2.0.0.17 (X11/20080914) MIME-Version: 1.0 To: Marcelo Tosatti CC: "kvm@vger.kernel.org" , "Zhai, Edwin" Subject: [PATCH] enable PCI multiple-segments for pass-through device Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 29 Jan 2010 06:38:48 +0000 (UTC) Index: linux-2.6/virt/kvm/assigned-dev.c =================================================================== --- linux-2.6.orig/virt/kvm/assigned-dev.c +++ linux-2.6/virt/kvm/assigned-dev.c @@ -526,7 +526,8 @@ static int kvm_vm_ioctl_assign_device(st r = -ENOMEM; goto out; } - dev = pci_get_bus_and_slot(assigned_dev->busnr, + dev = pci_get_domain_bus_and_slot(assigned_dev->segnr, + assigned_dev->busnr, assigned_dev->devfn); if (!dev) { printk(KERN_INFO "%s: host device not found\n", __func__); @@ -548,6 +549,7 @@ static int kvm_vm_ioctl_assign_device(st pci_reset_function(dev); match->assigned_dev_id = assigned_dev->assigned_dev_id; + match->host_segnr = assigned_dev->segnr; match->host_busnr = assigned_dev->busnr; match->host_devfn = assigned_dev->devfn; match->flags = assigned_dev->flags; Index: linux-2.6/virt/kvm/iommu.c =================================================================== --- linux-2.6.orig/virt/kvm/iommu.c +++ linux-2.6/virt/kvm/iommu.c @@ -106,7 +106,8 @@ int kvm_assign_device(struct kvm *kvm, r = iommu_attach_device(domain, &pdev->dev); if (r) { - printk(KERN_ERR "assign device %x:%x.%x failed", + printk(KERN_ERR "assign device %x:%x:%x.%x failed", + pci_domain_nr(pdev->bus), pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); @@ -127,7 +128,8 @@ int kvm_assign_device(struct kvm *kvm, goto out_unmap; } - printk(KERN_DEBUG "assign device: host bdf = %x:%x:%x\n", + printk(KERN_DEBUG "assign device %x:%x:%x.%x\n", + assigned_dev->host_segnr, assigned_dev->host_busnr, PCI_SLOT(assigned_dev->host_devfn), PCI_FUNC(assigned_dev->host_devfn)); @@ -154,7 +156,8 @@ int kvm_deassign_device(struct kvm *kvm, iommu_detach_device(domain, &pdev->dev); - printk(KERN_DEBUG "deassign device: host bdf = %x:%x:%x\n", + printk(KERN_DEBUG "deassign device %x:%x:%x.%x\n", + assigned_dev->host_segnr, assigned_dev->host_busnr, PCI_SLOT(assigned_dev->host_devfn), PCI_FUNC(assigned_dev->host_devfn)); Index: linux-2.6/include/linux/kvm.h =================================================================== --- linux-2.6.orig/include/linux/kvm.h +++ linux-2.6/include/linux/kvm.h @@ -691,8 +691,9 @@ struct kvm_assigned_pci_dev { __u32 busnr; __u32 devfn; __u32 flags; + __u32 segnr; union { - __u32 reserved[12]; + __u32 reserved[11]; }; }; Index: linux-2.6/include/linux/kvm_host.h =================================================================== --- linux-2.6.orig/include/linux/kvm_host.h +++ linux-2.6/include/linux/kvm_host.h @@ -400,6 +400,7 @@ struct kvm_assigned_dev_kernel { struct work_struct interrupt_work; struct list_head list; int assigned_dev_id; + int host_segnr; int host_busnr; int host_devfn; unsigned int entries_nr;