aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2014-11-24 09:27:17 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2014-11-24 10:53:50 -0500
commitc9eab58f6466cef3d9cd760a96e4de5e060e5195 (patch)
tree42f8f5d3830d4601d986e73e29d071f29f491185 /arch/x86
parentb65d6e17fe2239c9b2051727903955d922083fbf (diff)
KVM: x86: move device assignment out of kvm_host.h
Create a new header, and hide the device assignment functions there. Move struct kvm_assigned_dev_kernel to assigned-dev.c by modifying arch/x86/kvm/iommu.c to take a PCI device struct. Based on a patch by Radim Krcmar <rkrcmark@redhat.com>. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/include/asm/kvm_host.h23
-rw-r--r--arch/x86/kvm/assigned-dev.c30
-rw-r--r--arch/x86/kvm/assigned-dev.h32
-rw-r--r--arch/x86/kvm/iommu.c11
-rw-r--r--arch/x86/kvm/x86.c1
5 files changed, 64 insertions, 33 deletions
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index d549cf8bfb69..76ff3e2d8fd2 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1112,27 +1112,4 @@ int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data);
1112void kvm_handle_pmu_event(struct kvm_vcpu *vcpu); 1112void kvm_handle_pmu_event(struct kvm_vcpu *vcpu);
1113void kvm_deliver_pmi(struct kvm_vcpu *vcpu); 1113void kvm_deliver_pmi(struct kvm_vcpu *vcpu);
1114 1114
1115#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
1116int kvm_iommu_map_guest(struct kvm *kvm);
1117int kvm_iommu_unmap_guest(struct kvm *kvm);
1118
1119long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
1120 unsigned long arg);
1121
1122void kvm_free_all_assigned_devices(struct kvm *kvm);
1123#else
1124static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
1125{
1126 return 0;
1127}
1128
1129static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
1130 unsigned long arg)
1131{
1132 return -ENOTTY;
1133}
1134
1135static inline void kvm_free_all_assigned_devices(struct kvm *kvm) {}
1136#endif
1137
1138#endif /* _ASM_X86_KVM_HOST_H */ 1115#endif /* _ASM_X86_KVM_HOST_H */
diff --git a/arch/x86/kvm/assigned-dev.c b/arch/x86/kvm/assigned-dev.c
index e05000e200d2..6eb5c20ee373 100644
--- a/arch/x86/kvm/assigned-dev.c
+++ b/arch/x86/kvm/assigned-dev.c
@@ -20,6 +20,32 @@
20#include <linux/namei.h> 20#include <linux/namei.h>
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include "irq.h" 22#include "irq.h"
23#include "assigned-dev.h"
24
25struct kvm_assigned_dev_kernel {
26 struct kvm_irq_ack_notifier ack_notifier;
27 struct list_head list;
28 int assigned_dev_id;
29 int host_segnr;
30 int host_busnr;
31 int host_devfn;
32 unsigned int entries_nr;
33 int host_irq;
34 bool host_irq_disabled;
35 bool pci_2_3;
36 struct msix_entry *host_msix_entries;
37 int guest_irq;
38 struct msix_entry *guest_msix_entries;
39 unsigned long irq_requested_type;
40 int irq_source_id;
41 int flags;
42 struct pci_dev *dev;
43 struct kvm *kvm;
44 spinlock_t intx_lock;
45 spinlock_t intx_mask_lock;
46 char irq_name[32];
47 struct pci_saved_state *pci_saved_state;
48};
23 49
24static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *head, 50static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *head,
25 int assigned_dev_id) 51 int assigned_dev_id)
@@ -748,7 +774,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
748 if (r) 774 if (r)
749 goto out_list_del; 775 goto out_list_del;
750 } 776 }
751 r = kvm_assign_device(kvm, match); 777 r = kvm_assign_device(kvm, match->dev);
752 if (r) 778 if (r)
753 goto out_list_del; 779 goto out_list_del;
754 780
@@ -790,7 +816,7 @@ static int kvm_vm_ioctl_deassign_device(struct kvm *kvm,
790 goto out; 816 goto out;
791 } 817 }
792 818
793 kvm_deassign_device(kvm, match); 819 kvm_deassign_device(kvm, match->dev);
794 820
795 kvm_free_assigned_device(kvm, match); 821 kvm_free_assigned_device(kvm, match);
796 822
diff --git a/arch/x86/kvm/assigned-dev.h b/arch/x86/kvm/assigned-dev.h
new file mode 100644
index 000000000000..a428c1a211b2
--- /dev/null
+++ b/arch/x86/kvm/assigned-dev.h
@@ -0,0 +1,32 @@
1#ifndef ARCH_X86_KVM_ASSIGNED_DEV_H
2#define ARCH_X86_KVM_ASSIGNED_DEV_H
3
4#include <linux/kvm_host.h>
5
6#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
7int kvm_assign_device(struct kvm *kvm, struct pci_dev *pdev);
8int kvm_deassign_device(struct kvm *kvm, struct pci_dev *pdev);
9
10int kvm_iommu_map_guest(struct kvm *kvm);
11int kvm_iommu_unmap_guest(struct kvm *kvm);
12
13long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
14 unsigned long arg);
15
16void kvm_free_all_assigned_devices(struct kvm *kvm);
17#else
18static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
19{
20 return 0;
21}
22
23static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
24 unsigned long arg)
25{
26 return -ENOTTY;
27}
28
29static inline void kvm_free_all_assigned_devices(struct kvm *kvm) {}
30#endif /* CONFIG_KVM_DEVICE_ASSIGNMENT */
31
32#endif /* ARCH_X86_KVM_ASSIGNED_DEV_H */
diff --git a/arch/x86/kvm/iommu.c b/arch/x86/kvm/iommu.c
index c1e6ae989a43..17b73eeac8a4 100644
--- a/arch/x86/kvm/iommu.c
+++ b/arch/x86/kvm/iommu.c
@@ -31,6 +31,7 @@
31#include <linux/dmar.h> 31#include <linux/dmar.h>
32#include <linux/iommu.h> 32#include <linux/iommu.h>
33#include <linux/intel-iommu.h> 33#include <linux/intel-iommu.h>
34#include "assigned-dev.h"
34 35
35static bool allow_unsafe_assigned_interrupts; 36static bool allow_unsafe_assigned_interrupts;
36module_param_named(allow_unsafe_assigned_interrupts, 37module_param_named(allow_unsafe_assigned_interrupts,
@@ -169,10 +170,8 @@ static int kvm_iommu_map_memslots(struct kvm *kvm)
169 return r; 170 return r;
170} 171}
171 172
172int kvm_assign_device(struct kvm *kvm, 173int kvm_assign_device(struct kvm *kvm, struct pci_dev *pdev)
173 struct kvm_assigned_dev_kernel *assigned_dev)
174{ 174{
175 struct pci_dev *pdev = NULL;
176 struct iommu_domain *domain = kvm->arch.iommu_domain; 175 struct iommu_domain *domain = kvm->arch.iommu_domain;
177 int r; 176 int r;
178 bool noncoherent; 177 bool noncoherent;
@@ -181,7 +180,6 @@ int kvm_assign_device(struct kvm *kvm,
181 if (!domain) 180 if (!domain)
182 return 0; 181 return 0;
183 182
184 pdev = assigned_dev->dev;
185 if (pdev == NULL) 183 if (pdev == NULL)
186 return -ENODEV; 184 return -ENODEV;
187 185
@@ -212,17 +210,14 @@ out_unmap:
212 return r; 210 return r;
213} 211}
214 212
215int kvm_deassign_device(struct kvm *kvm, 213int kvm_deassign_device(struct kvm *kvm, struct pci_dev *pdev)
216 struct kvm_assigned_dev_kernel *assigned_dev)
217{ 214{
218 struct iommu_domain *domain = kvm->arch.iommu_domain; 215 struct iommu_domain *domain = kvm->arch.iommu_domain;
219 struct pci_dev *pdev = NULL;
220 216
221 /* check if iommu exists and in use */ 217 /* check if iommu exists and in use */
222 if (!domain) 218 if (!domain)
223 return 0; 219 return 0;
224 220
225 pdev = assigned_dev->dev;
226 if (pdev == NULL) 221 if (pdev == NULL)
227 return -ENODEV; 222 return -ENODEV;
228 223
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 782e4eaf4561..c42bca47f7f5 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -27,6 +27,7 @@
27#include "kvm_cache_regs.h" 27#include "kvm_cache_regs.h"
28#include "x86.h" 28#include "x86.h"
29#include "cpuid.h" 29#include "cpuid.h"
30#include "assigned-dev.h"
30 31
31#include <linux/clocksource.h> 32#include <linux/clocksource.h>
32#include <linux/interrupt.h> 33#include <linux/interrupt.h>