aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2013-04-16 15:49:18 -0400
committerGleb Natapov <gleb@redhat.com>2013-04-28 05:58:56 -0400
commit2a5bab1004729f3302c776e53ee7c895b98bb1ce (patch)
tree281519b89e9f766a3d83c6978850e9eb72b3e0df
parent064d1afaa5a60fc391d0b4b77599fc8f63f99cd3 (diff)
kvm: Allow build-time configuration of KVM device assignment
We hope to at some point deprecate KVM legacy device assignment in favor of VFIO-based assignment. Towards that end, allow legacy device assignment to be deconfigured. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Reviewed-by: Alexander Graf <agraf@suse.de> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Gleb Natapov <gleb@redhat.com>
-rw-r--r--arch/ia64/include/uapi/asm/kvm.h1
-rw-r--r--arch/ia64/kvm/Kconfig13
-rw-r--r--arch/ia64/kvm/Makefile6
-rw-r--r--arch/ia64/kvm/kvm-ia64.c2
-rw-r--r--arch/x86/include/uapi/asm/kvm.h1
-rw-r--r--arch/x86/kvm/Kconfig13
-rw-r--r--arch/x86/kvm/Makefile5
-rw-r--r--arch/x86/kvm/x86.c6
-rw-r--r--include/linux/kvm_host.h30
-rw-r--r--include/uapi/linux/kvm.h4
10 files changed, 40 insertions, 41 deletions
diff --git a/arch/ia64/include/uapi/asm/kvm.h b/arch/ia64/include/uapi/asm/kvm.h
index ec6c6b301238..99503c284400 100644
--- a/arch/ia64/include/uapi/asm/kvm.h
+++ b/arch/ia64/include/uapi/asm/kvm.h
@@ -27,7 +27,6 @@
27/* Select x86 specific features in <linux/kvm.h> */ 27/* Select x86 specific features in <linux/kvm.h> */
28#define __KVM_HAVE_IOAPIC 28#define __KVM_HAVE_IOAPIC
29#define __KVM_HAVE_IRQ_LINE 29#define __KVM_HAVE_IRQ_LINE
30#define __KVM_HAVE_DEVICE_ASSIGNMENT
31 30
32/* Architectural interrupt line count. */ 31/* Architectural interrupt line count. */
33#define KVM_NR_INTERRUPTS 256 32#define KVM_NR_INTERRUPTS 256
diff --git a/arch/ia64/kvm/Kconfig b/arch/ia64/kvm/Kconfig
index 043183a06409..990b86420cc6 100644
--- a/arch/ia64/kvm/Kconfig
+++ b/arch/ia64/kvm/Kconfig
@@ -21,8 +21,6 @@ config KVM
21 tristate "Kernel-based Virtual Machine (KVM) support" 21 tristate "Kernel-based Virtual Machine (KVM) support"
22 depends on BROKEN 22 depends on BROKEN
23 depends on HAVE_KVM && MODULES 23 depends on HAVE_KVM && MODULES
24 # for device assignment:
25 depends on PCI
26 depends on BROKEN 24 depends on BROKEN
27 select PREEMPT_NOTIFIERS 25 select PREEMPT_NOTIFIERS
28 select ANON_INODES 26 select ANON_INODES
@@ -51,6 +49,17 @@ config KVM_INTEL
51 Provides support for KVM on Itanium 2 processors equipped with the VT 49 Provides support for KVM on Itanium 2 processors equipped with the VT
52 extensions. 50 extensions.
53 51
52config KVM_DEVICE_ASSIGNMENT
53 bool "KVM legacy PCI device assignment support"
54 depends on KVM && PCI && IOMMU_API
55 default y
56 ---help---
57 Provide support for legacy PCI device assignment through KVM. The
58 kernel now also supports a full featured userspace device driver
59 framework through VFIO, which supersedes much of this support.
60
61 If unsure, say Y.
62
54source drivers/vhost/Kconfig 63source drivers/vhost/Kconfig
55 64
56endif # VIRTUALIZATION 65endif # VIRTUALIZATION
diff --git a/arch/ia64/kvm/Makefile b/arch/ia64/kvm/Makefile
index 511f64a78d56..1a4053789d01 100644
--- a/arch/ia64/kvm/Makefile
+++ b/arch/ia64/kvm/Makefile
@@ -49,10 +49,10 @@ ccflags-y := -Ivirt/kvm -Iarch/ia64/kvm/
49asflags-y := -Ivirt/kvm -Iarch/ia64/kvm/ 49asflags-y := -Ivirt/kvm -Iarch/ia64/kvm/
50 50
51common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \ 51common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \
52 coalesced_mmio.o irq_comm.o assigned-dev.o irqchip.o) 52 coalesced_mmio.o irq_comm.o)
53 53
54ifeq ($(CONFIG_IOMMU_API),y) 54ifeq ($(CONFIG_KVM_DEVICE_ASSIGNMENT),y)
55common-objs += $(addprefix ../../../virt/kvm/, iommu.o) 55common-objs += $(addprefix ../../../virt/kvm/, assigned-dev.o iommu.o)
56endif 56endif
57 57
58kvm-objs := $(common-objs) kvm-ia64.o kvm_fw.o 58kvm-objs := $(common-objs) kvm-ia64.o kvm_fw.o
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index 032c54d63c3d..dcc560729c20 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -1368,9 +1368,7 @@ void kvm_arch_sync_events(struct kvm *kvm)
1368void kvm_arch_destroy_vm(struct kvm *kvm) 1368void kvm_arch_destroy_vm(struct kvm *kvm)
1369{ 1369{
1370 kvm_iommu_unmap_guest(kvm); 1370 kvm_iommu_unmap_guest(kvm);
1371#ifdef KVM_CAP_DEVICE_ASSIGNMENT
1372 kvm_free_all_assigned_devices(kvm); 1371 kvm_free_all_assigned_devices(kvm);
1373#endif
1374 kfree(kvm->arch.vioapic); 1372 kfree(kvm->arch.vioapic);
1375 kvm_release_vm_pages(kvm); 1373 kvm_release_vm_pages(kvm);
1376} 1374}
diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
index a65ec29e6ffb..5d9a3033b3d7 100644
--- a/arch/x86/include/uapi/asm/kvm.h
+++ b/arch/x86/include/uapi/asm/kvm.h
@@ -29,7 +29,6 @@
29#define __KVM_HAVE_PIT 29#define __KVM_HAVE_PIT
30#define __KVM_HAVE_IOAPIC 30#define __KVM_HAVE_IOAPIC
31#define __KVM_HAVE_IRQ_LINE 31#define __KVM_HAVE_IRQ_LINE
32#define __KVM_HAVE_DEVICE_ASSIGNMENT
33#define __KVM_HAVE_MSI 32#define __KVM_HAVE_MSI
34#define __KVM_HAVE_USER_NMI 33#define __KVM_HAVE_USER_NMI
35#define __KVM_HAVE_GUEST_DEBUG 34#define __KVM_HAVE_GUEST_DEBUG
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index 9d50efdb719d..a47a3e54b964 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -21,8 +21,6 @@ config KVM
21 tristate "Kernel-based Virtual Machine (KVM) support" 21 tristate "Kernel-based Virtual Machine (KVM) support"
22 depends on HAVE_KVM 22 depends on HAVE_KVM
23 depends on HIGH_RES_TIMERS 23 depends on HIGH_RES_TIMERS
24 # for device assignment:
25 depends on PCI
26 # for TASKSTATS/TASK_DELAY_ACCT: 24 # for TASKSTATS/TASK_DELAY_ACCT:
27 depends on NET 25 depends on NET
28 select PREEMPT_NOTIFIERS 26 select PREEMPT_NOTIFIERS
@@ -83,6 +81,17 @@ config KVM_MMU_AUDIT
83 This option adds a R/W kVM module parameter 'mmu_audit', which allows 81 This option adds a R/W kVM module parameter 'mmu_audit', which allows
84 audit KVM MMU at runtime. 82 audit KVM MMU at runtime.
85 83
84config KVM_DEVICE_ASSIGNMENT
85 bool "KVM legacy PCI device assignment support"
86 depends on KVM && PCI && IOMMU_API
87 default y
88 ---help---
89 Provide support for legacy PCI device assignment through KVM. The
90 kernel now also supports a full featured userspace device driver
91 framework through VFIO, which supersedes much of this support.
92
93 If unsure, say Y.
94
86# OK, it's a little counter-intuitive to do this, but it puts it neatly under 95# OK, it's a little counter-intuitive to do this, but it puts it neatly under
87# the virtualization menu. 96# the virtualization menu.
88source drivers/vhost/Kconfig 97source drivers/vhost/Kconfig
diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index a797b8e43ade..d609e1d84048 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -7,8 +7,9 @@ CFLAGS_vmx.o := -I.
7 7
8kvm-y += $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \ 8kvm-y += $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \
9 coalesced_mmio.o irq_comm.o eventfd.o \ 9 coalesced_mmio.o irq_comm.o eventfd.o \
10 assigned-dev.o irqchip.o) 10 irqchip.o)
11kvm-$(CONFIG_IOMMU_API) += $(addprefix ../../../virt/kvm/, iommu.o) 11kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += $(addprefix ../../../virt/kvm/, \
12 assigned-dev.o iommu.o)
12kvm-$(CONFIG_KVM_ASYNC_PF) += $(addprefix ../../../virt/kvm/, async_pf.o) 13kvm-$(CONFIG_KVM_ASYNC_PF) += $(addprefix ../../../virt/kvm/, async_pf.o)
13 14
14kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \ 15kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 145b1c81011b..8747fef7fd59 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2501,7 +2501,6 @@ int kvm_dev_ioctl_check_extension(long ext)
2501 case KVM_CAP_USER_NMI: 2501 case KVM_CAP_USER_NMI:
2502 case KVM_CAP_REINJECT_CONTROL: 2502 case KVM_CAP_REINJECT_CONTROL:
2503 case KVM_CAP_IRQ_INJECT_STATUS: 2503 case KVM_CAP_IRQ_INJECT_STATUS:
2504 case KVM_CAP_ASSIGN_DEV_IRQ:
2505 case KVM_CAP_IRQFD: 2504 case KVM_CAP_IRQFD:
2506 case KVM_CAP_IOEVENTFD: 2505 case KVM_CAP_IOEVENTFD:
2507 case KVM_CAP_PIT2: 2506 case KVM_CAP_PIT2:
@@ -2519,9 +2518,12 @@ int kvm_dev_ioctl_check_extension(long ext)
2519 case KVM_CAP_XSAVE: 2518 case KVM_CAP_XSAVE:
2520 case KVM_CAP_ASYNC_PF: 2519 case KVM_CAP_ASYNC_PF:
2521 case KVM_CAP_GET_TSC_KHZ: 2520 case KVM_CAP_GET_TSC_KHZ:
2522 case KVM_CAP_PCI_2_3:
2523 case KVM_CAP_KVMCLOCK_CTRL: 2521 case KVM_CAP_KVMCLOCK_CTRL:
2524 case KVM_CAP_READONLY_MEM: 2522 case KVM_CAP_READONLY_MEM:
2523#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
2524 case KVM_CAP_ASSIGN_DEV_IRQ:
2525 case KVM_CAP_PCI_2_3:
2526#endif
2525 r = 1; 2527 r = 1;
2526 break; 2528 break;
2527 case KVM_CAP_COALESCED_MMIO: 2529 case KVM_CAP_COALESCED_MMIO:
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 309774715897..996661eb8e99 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -667,7 +667,6 @@ static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
667 667
668int kvm_arch_init_vm(struct kvm *kvm, unsigned long type); 668int kvm_arch_init_vm(struct kvm *kvm, unsigned long type);
669void kvm_arch_destroy_vm(struct kvm *kvm); 669void kvm_arch_destroy_vm(struct kvm *kvm);
670void kvm_free_all_assigned_devices(struct kvm *kvm);
671void kvm_arch_sync_events(struct kvm *kvm); 670void kvm_arch_sync_events(struct kvm *kvm);
672 671
673int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu); 672int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
@@ -736,7 +735,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
736/* For vcpu->arch.iommu_flags */ 735/* For vcpu->arch.iommu_flags */
737#define KVM_IOMMU_CACHE_COHERENCY 0x1 736#define KVM_IOMMU_CACHE_COHERENCY 0x1
738 737
739#ifdef CONFIG_IOMMU_API 738#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
740int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot); 739int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
741void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot); 740void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
742int kvm_iommu_map_guest(struct kvm *kvm); 741int kvm_iommu_map_guest(struct kvm *kvm);
@@ -745,7 +744,7 @@ int kvm_assign_device(struct kvm *kvm,
745 struct kvm_assigned_dev_kernel *assigned_dev); 744 struct kvm_assigned_dev_kernel *assigned_dev);
746int kvm_deassign_device(struct kvm *kvm, 745int kvm_deassign_device(struct kvm *kvm,
747 struct kvm_assigned_dev_kernel *assigned_dev); 746 struct kvm_assigned_dev_kernel *assigned_dev);
748#else /* CONFIG_IOMMU_API */ 747#else
749static inline int kvm_iommu_map_pages(struct kvm *kvm, 748static inline int kvm_iommu_map_pages(struct kvm *kvm,
750 struct kvm_memory_slot *slot) 749 struct kvm_memory_slot *slot)
751{ 750{
@@ -757,28 +756,11 @@ static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
757{ 756{
758} 757}
759 758
760static inline int kvm_iommu_map_guest(struct kvm *kvm)
761{
762 return -ENODEV;
763}
764
765static inline int kvm_iommu_unmap_guest(struct kvm *kvm) 759static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
766{ 760{
767 return 0; 761 return 0;
768} 762}
769 763#endif
770static inline int kvm_assign_device(struct kvm *kvm,
771 struct kvm_assigned_dev_kernel *assigned_dev)
772{
773 return 0;
774}
775
776static inline int kvm_deassign_device(struct kvm *kvm,
777 struct kvm_assigned_dev_kernel *assigned_dev)
778{
779 return 0;
780}
781#endif /* CONFIG_IOMMU_API */
782 764
783static inline void __guest_enter(void) 765static inline void __guest_enter(void)
784{ 766{
@@ -1032,11 +1014,13 @@ static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; }
1032 1014
1033#endif 1015#endif
1034 1016
1035#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT 1017#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
1036 1018
1037long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl, 1019long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
1038 unsigned long arg); 1020 unsigned long arg);
1039 1021
1022void kvm_free_all_assigned_devices(struct kvm *kvm);
1023
1040#else 1024#else
1041 1025
1042static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl, 1026static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
@@ -1045,6 +1029,8 @@ static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
1045 return -ENOTTY; 1029 return -ENOTTY;
1046} 1030}
1047 1031
1032static inline void kvm_free_all_assigned_devices(struct kvm *kvm) {}
1033
1048#endif 1034#endif
1049 1035
1050static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu) 1036static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index d4005192ad6e..965e5b52dee0 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -561,9 +561,7 @@ struct kvm_ppc_smmu_info {
561#define KVM_CAP_MP_STATE 14 561#define KVM_CAP_MP_STATE 14
562#define KVM_CAP_COALESCED_MMIO 15 562#define KVM_CAP_COALESCED_MMIO 15
563#define KVM_CAP_SYNC_MMU 16 /* Changes to host mmap are reflected in guest */ 563#define KVM_CAP_SYNC_MMU 16 /* Changes to host mmap are reflected in guest */
564#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
565#define KVM_CAP_DEVICE_ASSIGNMENT 17 564#define KVM_CAP_DEVICE_ASSIGNMENT 17
566#endif
567#define KVM_CAP_IOMMU 18 565#define KVM_CAP_IOMMU 18
568#ifdef __KVM_HAVE_MSI 566#ifdef __KVM_HAVE_MSI
569#define KVM_CAP_DEVICE_MSI 20 567#define KVM_CAP_DEVICE_MSI 20
@@ -581,9 +579,7 @@ struct kvm_ppc_smmu_info {
581#endif 579#endif
582#define KVM_CAP_IRQ_ROUTING 25 580#define KVM_CAP_IRQ_ROUTING 25
583#define KVM_CAP_IRQ_INJECT_STATUS 26 581#define KVM_CAP_IRQ_INJECT_STATUS 26
584#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
585#define KVM_CAP_DEVICE_DEASSIGNMENT 27 582#define KVM_CAP_DEVICE_DEASSIGNMENT 27
586#endif
587#ifdef __KVM_HAVE_MSIX 583#ifdef __KVM_HAVE_MSIX
588#define KVM_CAP_DEVICE_MSIX 28 584#define KVM_CAP_DEVICE_MSIX 28
589#endif 585#endif