diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-26 18:47:52 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-26 18:47:52 -0400 |
commit | d3f12d36f148f101c568bdbce795e41cd9ceadf3 (patch) | |
tree | 4d58ff7605a530fb052c95378d507e2350755825 /virt/kvm/kvm_main.c | |
parent | 39b566eedbe9e35d38502cc5e62ef7abf1aff9c9 (diff) | |
parent | 16175a796d061833aacfbd9672235f2d2725df65 (diff) |
Merge branch 'kvm-updates/2.6.30' of git://git.kernel.org/pub/scm/virt/kvm/kvm
* 'kvm-updates/2.6.30' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (113 commits)
KVM: VMX: Don't allow uninhibited access to EFER on i386
KVM: Correct deassign device ioctl to IOW
KVM: ppc: e500: Fix the bug that KVM is unstable in SMP
KVM: ppc: e500: Fix the bug that mas0 update to wrong value when read TLB entry
KVM: Fix missing smp tlb flush in invlpg
KVM: Get support IRQ routing entry counts
KVM: fix sparse warnings: Should it be static?
KVM: fix sparse warnings: context imbalance
KVM: is_long_mode() should check for EFER.LMA
KVM: VMX: Update necessary state when guest enters long mode
KVM: ia64: Fix the build errors due to lack of macros related to MSI.
ia64: Move the macro definitions related to MSI to one header file.
KVM: fix kvm_vm_ioctl_deassign_device
KVM: define KVM_CAP_DEVICE_DEASSIGNMENT
KVM: ppc: Add emulation of E500 register mmucsr0
KVM: Report IRQ injection status for MSI delivered interrupts
KVM: MMU: Fix another largepage memory leak
KVM: SVM: set accessed bit for VMCB segment selectors
KVM: Report IRQ injection status to userspace.
KVM: MMU: remove assertion in kvm_mmu_alloc_page
...
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r-- | virt/kvm/kvm_main.c | 141 |
1 files changed, 68 insertions, 73 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 29a667ce35b0..605697e9c4dd 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -47,10 +47,6 @@ | |||
47 | #include <asm/uaccess.h> | 47 | #include <asm/uaccess.h> |
48 | #include <asm/pgtable.h> | 48 | #include <asm/pgtable.h> |
49 | 49 | ||
50 | #ifdef CONFIG_X86 | ||
51 | #include <asm/msidef.h> | ||
52 | #endif | ||
53 | |||
54 | #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET | 50 | #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET |
55 | #include "coalesced_mmio.h" | 51 | #include "coalesced_mmio.h" |
56 | #endif | 52 | #endif |
@@ -85,57 +81,6 @@ static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl, | |||
85 | static bool kvm_rebooting; | 81 | static bool kvm_rebooting; |
86 | 82 | ||
87 | #ifdef KVM_CAP_DEVICE_ASSIGNMENT | 83 | #ifdef KVM_CAP_DEVICE_ASSIGNMENT |
88 | |||
89 | #ifdef CONFIG_X86 | ||
90 | static void assigned_device_msi_dispatch(struct kvm_assigned_dev_kernel *dev) | ||
91 | { | ||
92 | int vcpu_id; | ||
93 | struct kvm_vcpu *vcpu; | ||
94 | struct kvm_ioapic *ioapic = ioapic_irqchip(dev->kvm); | ||
95 | int dest_id = (dev->guest_msi.address_lo & MSI_ADDR_DEST_ID_MASK) | ||
96 | >> MSI_ADDR_DEST_ID_SHIFT; | ||
97 | int vector = (dev->guest_msi.data & MSI_DATA_VECTOR_MASK) | ||
98 | >> MSI_DATA_VECTOR_SHIFT; | ||
99 | int dest_mode = test_bit(MSI_ADDR_DEST_MODE_SHIFT, | ||
100 | (unsigned long *)&dev->guest_msi.address_lo); | ||
101 | int trig_mode = test_bit(MSI_DATA_TRIGGER_SHIFT, | ||
102 | (unsigned long *)&dev->guest_msi.data); | ||
103 | int delivery_mode = test_bit(MSI_DATA_DELIVERY_MODE_SHIFT, | ||
104 | (unsigned long *)&dev->guest_msi.data); | ||
105 | u32 deliver_bitmask; | ||
106 | |||
107 | BUG_ON(!ioapic); | ||
108 | |||
109 | deliver_bitmask = kvm_ioapic_get_delivery_bitmask(ioapic, | ||
110 | dest_id, dest_mode); | ||
111 | /* IOAPIC delivery mode value is the same as MSI here */ | ||
112 | switch (delivery_mode) { | ||
113 | case IOAPIC_LOWEST_PRIORITY: | ||
114 | vcpu = kvm_get_lowest_prio_vcpu(ioapic->kvm, vector, | ||
115 | deliver_bitmask); | ||
116 | if (vcpu != NULL) | ||
117 | kvm_apic_set_irq(vcpu, vector, trig_mode); | ||
118 | else | ||
119 | printk(KERN_INFO "kvm: null lowest priority vcpu!\n"); | ||
120 | break; | ||
121 | case IOAPIC_FIXED: | ||
122 | for (vcpu_id = 0; deliver_bitmask != 0; vcpu_id++) { | ||
123 | if (!(deliver_bitmask & (1 << vcpu_id))) | ||
124 | continue; | ||
125 | deliver_bitmask &= ~(1 << vcpu_id); | ||
126 | vcpu = ioapic->kvm->vcpus[vcpu_id]; | ||
127 | if (vcpu) | ||
128 | kvm_apic_set_irq(vcpu, vector, trig_mode); | ||
129 | } | ||
130 | break; | ||
131 | default: | ||
132 | printk(KERN_INFO "kvm: unsupported MSI delivery mode\n"); | ||
133 | } | ||
134 | } | ||
135 | #else | ||
136 | static void assigned_device_msi_dispatch(struct kvm_assigned_dev_kernel *dev) {} | ||
137 | #endif | ||
138 | |||
139 | static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *head, | 84 | static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *head, |
140 | int assigned_dev_id) | 85 | int assigned_dev_id) |
141 | { | 86 | { |
@@ -162,13 +107,10 @@ static void kvm_assigned_dev_interrupt_work_handler(struct work_struct *work) | |||
162 | * finer-grained lock, update this | 107 | * finer-grained lock, update this |
163 | */ | 108 | */ |
164 | mutex_lock(&assigned_dev->kvm->lock); | 109 | mutex_lock(&assigned_dev->kvm->lock); |
165 | if (assigned_dev->irq_requested_type & KVM_ASSIGNED_DEV_GUEST_INTX) | 110 | kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id, |
166 | kvm_set_irq(assigned_dev->kvm, | 111 | assigned_dev->guest_irq, 1); |
167 | assigned_dev->irq_source_id, | 112 | |
168 | assigned_dev->guest_irq, 1); | 113 | if (assigned_dev->irq_requested_type & KVM_ASSIGNED_DEV_GUEST_MSI) { |
169 | else if (assigned_dev->irq_requested_type & | ||
170 | KVM_ASSIGNED_DEV_GUEST_MSI) { | ||
171 | assigned_device_msi_dispatch(assigned_dev); | ||
172 | enable_irq(assigned_dev->host_irq); | 114 | enable_irq(assigned_dev->host_irq); |
173 | assigned_dev->host_irq_disabled = false; | 115 | assigned_dev->host_irq_disabled = false; |
174 | } | 116 | } |
@@ -331,18 +273,24 @@ static int assigned_device_update_msi(struct kvm *kvm, | |||
331 | { | 273 | { |
332 | int r; | 274 | int r; |
333 | 275 | ||
276 | adev->guest_irq = airq->guest_irq; | ||
334 | if (airq->flags & KVM_DEV_IRQ_ASSIGN_ENABLE_MSI) { | 277 | if (airq->flags & KVM_DEV_IRQ_ASSIGN_ENABLE_MSI) { |
335 | /* x86 don't care upper address of guest msi message addr */ | 278 | /* x86 don't care upper address of guest msi message addr */ |
336 | adev->irq_requested_type |= KVM_ASSIGNED_DEV_GUEST_MSI; | 279 | adev->irq_requested_type |= KVM_ASSIGNED_DEV_GUEST_MSI; |
337 | adev->irq_requested_type &= ~KVM_ASSIGNED_DEV_GUEST_INTX; | 280 | adev->irq_requested_type &= ~KVM_ASSIGNED_DEV_GUEST_INTX; |
338 | adev->guest_msi.address_lo = airq->guest_msi.addr_lo; | ||
339 | adev->guest_msi.data = airq->guest_msi.data; | ||
340 | adev->ack_notifier.gsi = -1; | 281 | adev->ack_notifier.gsi = -1; |
341 | } else if (msi2intx) { | 282 | } else if (msi2intx) { |
342 | adev->irq_requested_type |= KVM_ASSIGNED_DEV_GUEST_INTX; | 283 | adev->irq_requested_type |= KVM_ASSIGNED_DEV_GUEST_INTX; |
343 | adev->irq_requested_type &= ~KVM_ASSIGNED_DEV_GUEST_MSI; | 284 | adev->irq_requested_type &= ~KVM_ASSIGNED_DEV_GUEST_MSI; |
344 | adev->guest_irq = airq->guest_irq; | ||
345 | adev->ack_notifier.gsi = airq->guest_irq; | 285 | adev->ack_notifier.gsi = airq->guest_irq; |
286 | } else { | ||
287 | /* | ||
288 | * Guest require to disable device MSI, we disable MSI and | ||
289 | * re-enable INTx by default again. Notice it's only for | ||
290 | * non-msi2intx. | ||
291 | */ | ||
292 | assigned_device_update_intx(kvm, adev, airq); | ||
293 | return 0; | ||
346 | } | 294 | } |
347 | 295 | ||
348 | if (adev->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI) | 296 | if (adev->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI) |
@@ -379,6 +327,7 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm, | |||
379 | { | 327 | { |
380 | int r = 0; | 328 | int r = 0; |
381 | struct kvm_assigned_dev_kernel *match; | 329 | struct kvm_assigned_dev_kernel *match; |
330 | u32 current_flags = 0, changed_flags; | ||
382 | 331 | ||
383 | mutex_lock(&kvm->lock); | 332 | mutex_lock(&kvm->lock); |
384 | 333 | ||
@@ -416,8 +365,13 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm, | |||
416 | } | 365 | } |
417 | } | 366 | } |
418 | 367 | ||
419 | if ((!msi2intx && | 368 | if ((match->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI) && |
420 | (assigned_irq->flags & KVM_DEV_IRQ_ASSIGN_ENABLE_MSI)) || | 369 | (match->irq_requested_type & KVM_ASSIGNED_DEV_GUEST_MSI)) |
370 | current_flags |= KVM_DEV_IRQ_ASSIGN_ENABLE_MSI; | ||
371 | |||
372 | changed_flags = assigned_irq->flags ^ current_flags; | ||
373 | |||
374 | if ((changed_flags & KVM_DEV_IRQ_ASSIGN_MSI_ACTION) || | ||
421 | (msi2intx && match->dev->msi_enabled)) { | 375 | (msi2intx && match->dev->msi_enabled)) { |
422 | #ifdef CONFIG_X86 | 376 | #ifdef CONFIG_X86 |
423 | r = assigned_device_update_msi(kvm, match, assigned_irq); | 377 | r = assigned_device_update_msi(kvm, match, assigned_irq); |
@@ -563,7 +517,7 @@ static int kvm_vm_ioctl_deassign_device(struct kvm *kvm, | |||
563 | goto out; | 517 | goto out; |
564 | } | 518 | } |
565 | 519 | ||
566 | if (assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU) | 520 | if (match->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU) |
567 | kvm_deassign_device(kvm, match); | 521 | kvm_deassign_device(kvm, match); |
568 | 522 | ||
569 | kvm_free_assigned_device(kvm, match); | 523 | kvm_free_assigned_device(kvm, match); |
@@ -581,8 +535,10 @@ static inline int valid_vcpu(int n) | |||
581 | 535 | ||
582 | inline int kvm_is_mmio_pfn(pfn_t pfn) | 536 | inline int kvm_is_mmio_pfn(pfn_t pfn) |
583 | { | 537 | { |
584 | if (pfn_valid(pfn)) | 538 | if (pfn_valid(pfn)) { |
585 | return PageReserved(pfn_to_page(pfn)); | 539 | struct page *page = compound_head(pfn_to_page(pfn)); |
540 | return PageReserved(page); | ||
541 | } | ||
586 | 542 | ||
587 | return true; | 543 | return true; |
588 | } | 544 | } |
@@ -828,6 +784,10 @@ static struct kvm *kvm_create_vm(void) | |||
828 | 784 | ||
829 | if (IS_ERR(kvm)) | 785 | if (IS_ERR(kvm)) |
830 | goto out; | 786 | goto out; |
787 | #ifdef CONFIG_HAVE_KVM_IRQCHIP | ||
788 | INIT_LIST_HEAD(&kvm->irq_routing); | ||
789 | INIT_HLIST_HEAD(&kvm->mask_notifier_list); | ||
790 | #endif | ||
831 | 791 | ||
832 | #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET | 792 | #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET |
833 | page = alloc_page(GFP_KERNEL | __GFP_ZERO); | 793 | page = alloc_page(GFP_KERNEL | __GFP_ZERO); |
@@ -909,6 +869,7 @@ static void kvm_destroy_vm(struct kvm *kvm) | |||
909 | spin_lock(&kvm_lock); | 869 | spin_lock(&kvm_lock); |
910 | list_del(&kvm->vm_list); | 870 | list_del(&kvm->vm_list); |
911 | spin_unlock(&kvm_lock); | 871 | spin_unlock(&kvm_lock); |
872 | kvm_free_irq_routing(kvm); | ||
912 | kvm_io_bus_destroy(&kvm->pio_bus); | 873 | kvm_io_bus_destroy(&kvm->pio_bus); |
913 | kvm_io_bus_destroy(&kvm->mmio_bus); | 874 | kvm_io_bus_destroy(&kvm->mmio_bus); |
914 | #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET | 875 | #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET |
@@ -1755,13 +1716,13 @@ out_free2: | |||
1755 | r = 0; | 1716 | r = 0; |
1756 | break; | 1717 | break; |
1757 | } | 1718 | } |
1758 | case KVM_DEBUG_GUEST: { | 1719 | case KVM_SET_GUEST_DEBUG: { |
1759 | struct kvm_debug_guest dbg; | 1720 | struct kvm_guest_debug dbg; |
1760 | 1721 | ||
1761 | r = -EFAULT; | 1722 | r = -EFAULT; |
1762 | if (copy_from_user(&dbg, argp, sizeof dbg)) | 1723 | if (copy_from_user(&dbg, argp, sizeof dbg)) |
1763 | goto out; | 1724 | goto out; |
1764 | r = kvm_arch_vcpu_ioctl_debug_guest(vcpu, &dbg); | 1725 | r = kvm_arch_vcpu_ioctl_set_guest_debug(vcpu, &dbg); |
1765 | if (r) | 1726 | if (r) |
1766 | goto out; | 1727 | goto out; |
1767 | r = 0; | 1728 | r = 0; |
@@ -1929,6 +1890,36 @@ static long kvm_vm_ioctl(struct file *filp, | |||
1929 | break; | 1890 | break; |
1930 | } | 1891 | } |
1931 | #endif | 1892 | #endif |
1893 | #ifdef KVM_CAP_IRQ_ROUTING | ||
1894 | case KVM_SET_GSI_ROUTING: { | ||
1895 | struct kvm_irq_routing routing; | ||
1896 | struct kvm_irq_routing __user *urouting; | ||
1897 | struct kvm_irq_routing_entry *entries; | ||
1898 | |||
1899 | r = -EFAULT; | ||
1900 | if (copy_from_user(&routing, argp, sizeof(routing))) | ||
1901 | goto out; | ||
1902 | r = -EINVAL; | ||
1903 | if (routing.nr >= KVM_MAX_IRQ_ROUTES) | ||
1904 | goto out; | ||
1905 | if (routing.flags) | ||
1906 | goto out; | ||
1907 | r = -ENOMEM; | ||
1908 | entries = vmalloc(routing.nr * sizeof(*entries)); | ||
1909 | if (!entries) | ||
1910 | goto out; | ||
1911 | r = -EFAULT; | ||
1912 | urouting = argp; | ||
1913 | if (copy_from_user(entries, urouting->entries, | ||
1914 | routing.nr * sizeof(*entries))) | ||
1915 | goto out_free_irq_routing; | ||
1916 | r = kvm_set_irq_routing(kvm, entries, routing.nr, | ||
1917 | routing.flags); | ||
1918 | out_free_irq_routing: | ||
1919 | vfree(entries); | ||
1920 | break; | ||
1921 | } | ||
1922 | #endif | ||
1932 | default: | 1923 | default: |
1933 | r = kvm_arch_vm_ioctl(filp, ioctl, arg); | 1924 | r = kvm_arch_vm_ioctl(filp, ioctl, arg); |
1934 | } | 1925 | } |
@@ -1995,6 +1986,10 @@ static long kvm_dev_ioctl_check_extension_generic(long arg) | |||
1995 | case KVM_CAP_USER_MEMORY: | 1986 | case KVM_CAP_USER_MEMORY: |
1996 | case KVM_CAP_DESTROY_MEMORY_REGION_WORKS: | 1987 | case KVM_CAP_DESTROY_MEMORY_REGION_WORKS: |
1997 | return 1; | 1988 | return 1; |
1989 | #ifdef CONFIG_HAVE_KVM_IRQCHIP | ||
1990 | case KVM_CAP_IRQ_ROUTING: | ||
1991 | return KVM_MAX_IRQ_ROUTES; | ||
1992 | #endif | ||
1998 | default: | 1993 | default: |
1999 | break; | 1994 | break; |
2000 | } | 1995 | } |