Commit ab9f4ecb authored by Zhai, Edwin's avatar Zhai, Edwin Committed by Marcelo Tosatti

KVM: enable PCI multiple-segments for pass-through device

Enable optional parameter (default 0) - PCI segment (or domain) besides
BDF, when assigning PCI device to guest.
Signed-off-by: default avatarZhai Edwin <edwin.zhai@intel.com>
Acked-by: default avatarChris Wright <chrisw@sous-sol.org>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent 6d3e435e
...@@ -1569,6 +1569,7 @@ int kvm_dev_ioctl_check_extension(long ext) ...@@ -1569,6 +1569,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_HYPERV: case KVM_CAP_HYPERV:
case KVM_CAP_HYPERV_VAPIC: case KVM_CAP_HYPERV_VAPIC:
case KVM_CAP_HYPERV_SPIN: case KVM_CAP_HYPERV_SPIN:
case KVM_CAP_PCI_SEGMENT:
r = 1; r = 1;
break; break;
case KVM_CAP_COALESCED_MMIO: case KVM_CAP_COALESCED_MMIO:
......
...@@ -500,6 +500,7 @@ struct kvm_ioeventfd { ...@@ -500,6 +500,7 @@ struct kvm_ioeventfd {
#define KVM_CAP_HYPERV 44 #define KVM_CAP_HYPERV 44
#define KVM_CAP_HYPERV_VAPIC 45 #define KVM_CAP_HYPERV_VAPIC 45
#define KVM_CAP_HYPERV_SPIN 46 #define KVM_CAP_HYPERV_SPIN 46
#define KVM_CAP_PCI_SEGMENT 47
#ifdef KVM_CAP_IRQ_ROUTING #ifdef KVM_CAP_IRQ_ROUTING
...@@ -694,8 +695,9 @@ struct kvm_assigned_pci_dev { ...@@ -694,8 +695,9 @@ struct kvm_assigned_pci_dev {
__u32 busnr; __u32 busnr;
__u32 devfn; __u32 devfn;
__u32 flags; __u32 flags;
__u32 segnr;
union { union {
__u32 reserved[12]; __u32 reserved[11];
}; };
}; };
......
...@@ -400,6 +400,7 @@ struct kvm_assigned_dev_kernel { ...@@ -400,6 +400,7 @@ struct kvm_assigned_dev_kernel {
struct work_struct interrupt_work; struct work_struct interrupt_work;
struct list_head list; struct list_head list;
int assigned_dev_id; int assigned_dev_id;
int host_segnr;
int host_busnr; int host_busnr;
int host_devfn; int host_devfn;
unsigned int entries_nr; unsigned int entries_nr;
......
...@@ -526,7 +526,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -526,7 +526,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
r = -ENOMEM; r = -ENOMEM;
goto out; 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); assigned_dev->devfn);
if (!dev) { if (!dev) {
printk(KERN_INFO "%s: host device not found\n", __func__); printk(KERN_INFO "%s: host device not found\n", __func__);
...@@ -548,6 +549,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -548,6 +549,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
pci_reset_function(dev); pci_reset_function(dev);
match->assigned_dev_id = assigned_dev->assigned_dev_id; match->assigned_dev_id = assigned_dev->assigned_dev_id;
match->host_segnr = assigned_dev->segnr;
match->host_busnr = assigned_dev->busnr; match->host_busnr = assigned_dev->busnr;
match->host_devfn = assigned_dev->devfn; match->host_devfn = assigned_dev->devfn;
match->flags = assigned_dev->flags; match->flags = assigned_dev->flags;
......
...@@ -106,7 +106,8 @@ int kvm_assign_device(struct kvm *kvm, ...@@ -106,7 +106,8 @@ int kvm_assign_device(struct kvm *kvm,
r = iommu_attach_device(domain, &pdev->dev); r = iommu_attach_device(domain, &pdev->dev);
if (r) { 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, pdev->bus->number,
PCI_SLOT(pdev->devfn), PCI_SLOT(pdev->devfn),
PCI_FUNC(pdev->devfn)); PCI_FUNC(pdev->devfn));
...@@ -127,7 +128,8 @@ int kvm_assign_device(struct kvm *kvm, ...@@ -127,7 +128,8 @@ int kvm_assign_device(struct kvm *kvm,
goto out_unmap; 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, assigned_dev->host_busnr,
PCI_SLOT(assigned_dev->host_devfn), PCI_SLOT(assigned_dev->host_devfn),
PCI_FUNC(assigned_dev->host_devfn)); PCI_FUNC(assigned_dev->host_devfn));
...@@ -154,7 +156,8 @@ int kvm_deassign_device(struct kvm *kvm, ...@@ -154,7 +156,8 @@ int kvm_deassign_device(struct kvm *kvm,
iommu_detach_device(domain, &pdev->dev); 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, assigned_dev->host_busnr,
PCI_SLOT(assigned_dev->host_devfn), PCI_SLOT(assigned_dev->host_devfn),
PCI_FUNC(assigned_dev->host_devfn)); PCI_FUNC(assigned_dev->host_devfn));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment