]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
KVM: x86: move device assignment out of kvm_host.h
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 24 Nov 2014 14:27:17 +0000 (15:27 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 24 Nov 2014 15:53:50 +0000 (16:53 +0100)
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>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/assigned-dev.c
arch/x86/kvm/assigned-dev.h [new file with mode: 0644]
arch/x86/kvm/iommu.c
arch/x86/kvm/x86.c
include/linux/kvm_host.h

index d549cf8bfb697f29f3b7c1fae593936c8c2fe6cf..76ff3e2d8fd28e7c74ca77b8f6d5b7c1a88e1f83 100644 (file)
@@ -1112,27 +1112,4 @@ int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data);
 void kvm_handle_pmu_event(struct kvm_vcpu *vcpu);
 void kvm_deliver_pmi(struct kvm_vcpu *vcpu);
 
-#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
-int kvm_iommu_map_guest(struct kvm *kvm);
-int kvm_iommu_unmap_guest(struct kvm *kvm);
-
-long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
-                                 unsigned long arg);
-
-void kvm_free_all_assigned_devices(struct kvm *kvm);
-#else
-static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
-{
-       return 0;
-}
-
-static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
-                                               unsigned long arg)
-{
-       return -ENOTTY;
-}
-
-static inline void kvm_free_all_assigned_devices(struct kvm *kvm) {}
-#endif
-
 #endif /* _ASM_X86_KVM_HOST_H */
index e05000e200d22bf7e7edf1ba6a3d8dbc1d1c9a6b..6eb5c20ee3739855a5d3fe52aa9a253b677552fd 100644 (file)
 #include <linux/namei.h>
 #include <linux/fs.h>
 #include "irq.h"
+#include "assigned-dev.h"
+
+struct kvm_assigned_dev_kernel {
+       struct kvm_irq_ack_notifier ack_notifier;
+       struct list_head list;
+       int assigned_dev_id;
+       int host_segnr;
+       int host_busnr;
+       int host_devfn;
+       unsigned int entries_nr;
+       int host_irq;
+       bool host_irq_disabled;
+       bool pci_2_3;
+       struct msix_entry *host_msix_entries;
+       int guest_irq;
+       struct msix_entry *guest_msix_entries;
+       unsigned long irq_requested_type;
+       int irq_source_id;
+       int flags;
+       struct pci_dev *dev;
+       struct kvm *kvm;
+       spinlock_t intx_lock;
+       spinlock_t intx_mask_lock;
+       char irq_name[32];
+       struct pci_saved_state *pci_saved_state;
+};
 
 static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *head,
                                                      int assigned_dev_id)
@@ -748,7 +774,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
                if (r)
                        goto out_list_del;
        }
-       r = kvm_assign_device(kvm, match);
+       r = kvm_assign_device(kvm, match->dev);
        if (r)
                goto out_list_del;
 
@@ -790,7 +816,7 @@ static int kvm_vm_ioctl_deassign_device(struct kvm *kvm,
                goto out;
        }
 
-       kvm_deassign_device(kvm, match);
+       kvm_deassign_device(kvm, match->dev);
 
        kvm_free_assigned_device(kvm, match);
 
diff --git a/arch/x86/kvm/assigned-dev.h b/arch/x86/kvm/assigned-dev.h
new file mode 100644 (file)
index 0000000..a428c1a
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef ARCH_X86_KVM_ASSIGNED_DEV_H
+#define ARCH_X86_KVM_ASSIGNED_DEV_H
+
+#include <linux/kvm_host.h>
+
+#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
+int kvm_assign_device(struct kvm *kvm, struct pci_dev *pdev);
+int kvm_deassign_device(struct kvm *kvm, struct pci_dev *pdev);
+
+int kvm_iommu_map_guest(struct kvm *kvm);
+int kvm_iommu_unmap_guest(struct kvm *kvm);
+
+long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
+                                 unsigned long arg);
+
+void kvm_free_all_assigned_devices(struct kvm *kvm);
+#else
+static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
+{
+       return 0;
+}
+
+static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
+                                               unsigned long arg)
+{
+       return -ENOTTY;
+}
+
+static inline void kvm_free_all_assigned_devices(struct kvm *kvm) {}
+#endif /* CONFIG_KVM_DEVICE_ASSIGNMENT */
+
+#endif /* ARCH_X86_KVM_ASSIGNED_DEV_H */
index c1e6ae989a432165f9d6871626929ed2ecb578e8..17b73eeac8a499ce1490a0c5b3a497085048378b 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/dmar.h>
 #include <linux/iommu.h>
 #include <linux/intel-iommu.h>
+#include "assigned-dev.h"
 
 static bool allow_unsafe_assigned_interrupts;
 module_param_named(allow_unsafe_assigned_interrupts,
@@ -169,10 +170,8 @@ static int kvm_iommu_map_memslots(struct kvm *kvm)
        return r;
 }
 
-int kvm_assign_device(struct kvm *kvm,
-                     struct kvm_assigned_dev_kernel *assigned_dev)
+int kvm_assign_device(struct kvm *kvm, struct pci_dev *pdev)
 {
-       struct pci_dev *pdev = NULL;
        struct iommu_domain *domain = kvm->arch.iommu_domain;
        int r;
        bool noncoherent;
@@ -181,7 +180,6 @@ int kvm_assign_device(struct kvm *kvm,
        if (!domain)
                return 0;
 
-       pdev = assigned_dev->dev;
        if (pdev == NULL)
                return -ENODEV;
 
@@ -212,17 +210,14 @@ out_unmap:
        return r;
 }
 
-int kvm_deassign_device(struct kvm *kvm,
-                       struct kvm_assigned_dev_kernel *assigned_dev)
+int kvm_deassign_device(struct kvm *kvm, struct pci_dev *pdev)
 {
        struct iommu_domain *domain = kvm->arch.iommu_domain;
-       struct pci_dev *pdev = NULL;
 
        /* check if iommu exists and in use */
        if (!domain)
                return 0;
 
-       pdev = assigned_dev->dev;
        if (pdev == NULL)
                return -ENODEV;
 
index 782e4eaf456163172f9fc127db477475162896ef..c42bca47f7f55456fda5798f554d435d526fa250 100644 (file)
@@ -27,6 +27,7 @@
 #include "kvm_cache_regs.h"
 #include "x86.h"
 #include "cpuid.h"
+#include "assigned-dev.h"
 
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
index aa56894ce83965c832a7f156e0e12a5bdb54fc7c..231dd9472226639569f9f9cb7aefc26279bfbb01 100644 (file)
@@ -718,31 +718,6 @@ struct kvm_irq_ack_notifier {
        void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
 };
 
-struct kvm_assigned_dev_kernel {
-       struct kvm_irq_ack_notifier ack_notifier;
-       struct list_head list;
-       int assigned_dev_id;
-       int host_segnr;
-       int host_busnr;
-       int host_devfn;
-       unsigned int entries_nr;
-       int host_irq;
-       bool host_irq_disabled;
-       bool pci_2_3;
-       struct msix_entry *host_msix_entries;
-       int guest_irq;
-       struct msix_entry *guest_msix_entries;
-       unsigned long irq_requested_type;
-       int irq_source_id;
-       int flags;
-       struct pci_dev *dev;
-       struct kvm *kvm;
-       spinlock_t intx_lock;
-       spinlock_t intx_mask_lock;
-       char irq_name[32];
-       struct pci_saved_state *pci_saved_state;
-};
-
 int kvm_irq_map_gsi(struct kvm *kvm,
                    struct kvm_kernel_irq_routing_entry *entries, int gsi);
 int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin);
@@ -764,10 +739,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
 int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
 void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
-int kvm_assign_device(struct kvm *kvm,
-                     struct kvm_assigned_dev_kernel *assigned_dev);
-int kvm_deassign_device(struct kvm *kvm,
-                       struct kvm_assigned_dev_kernel *assigned_dev);
 #else
 static inline int kvm_iommu_map_pages(struct kvm *kvm,
                                      struct kvm_memory_slot *slot)