diff options
author | Sheng Yang <sheng@linux.intel.com> | 2008-10-15 08:15:06 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2008-10-28 08:21:34 -0400 |
commit | 5550af4df179e52753d3a43a788a113ad8cd95cd (patch) | |
tree | f19274a4f7e345e70e7da713f44c1dcccdb134e8 /virt/kvm | |
parent | 6ad9f15c94822c3f067a7d443f3b414e08b34460 (diff) |
KVM: Fix guest shared interrupt with in-kernel irqchip
Every call of kvm_set_irq() should offer an irq_source_id, which is
allocated by kvm_request_irq_source_id(). Based on irq_source_id, we
identify the irq source and implement logical OR for shared level
interrupts.
The allocated irq_source_id can be freed by kvm_free_irq_source_id().
Currently, we support at most sizeof(unsigned long) different irq sources.
[Amit: - rebase to kvm.git HEAD
- move definition of KVM_USERSPACE_IRQ_SOURCE_ID to common file
- move kvm_request_irq_source_id to the update_irq ioctl]
[Xiantao: - Add kvm/ia64 stuff and make it work for kvm/ia64 guests]
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'virt/kvm')
-rw-r--r-- | virt/kvm/irq_comm.c | 42 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 12 |
2 files changed, 47 insertions, 7 deletions
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c index d0169f5e6047..55ad76ee2d09 100644 --- a/virt/kvm/irq_comm.c +++ b/virt/kvm/irq_comm.c | |||
@@ -25,15 +25,23 @@ | |||
25 | #include "ioapic.h" | 25 | #include "ioapic.h" |
26 | 26 | ||
27 | /* This should be called with the kvm->lock mutex held */ | 27 | /* This should be called with the kvm->lock mutex held */ |
28 | void kvm_set_irq(struct kvm *kvm, int irq, int level) | 28 | void kvm_set_irq(struct kvm *kvm, int irq_source_id, int irq, int level) |
29 | { | 29 | { |
30 | unsigned long *irq_state = (unsigned long *)&kvm->arch.irq_states[irq]; | ||
31 | |||
32 | /* Logical OR for level trig interrupt */ | ||
33 | if (level) | ||
34 | set_bit(irq_source_id, irq_state); | ||
35 | else | ||
36 | clear_bit(irq_source_id, irq_state); | ||
37 | |||
30 | /* Not possible to detect if the guest uses the PIC or the | 38 | /* Not possible to detect if the guest uses the PIC or the |
31 | * IOAPIC. So set the bit in both. The guest will ignore | 39 | * IOAPIC. So set the bit in both. The guest will ignore |
32 | * writes to the unused one. | 40 | * writes to the unused one. |
33 | */ | 41 | */ |
34 | kvm_ioapic_set_irq(kvm->arch.vioapic, irq, level); | 42 | kvm_ioapic_set_irq(kvm->arch.vioapic, irq, !!(*irq_state)); |
35 | #ifdef CONFIG_X86 | 43 | #ifdef CONFIG_X86 |
36 | kvm_pic_set_irq(pic_irqchip(kvm), irq, level); | 44 | kvm_pic_set_irq(pic_irqchip(kvm), irq, !!(*irq_state)); |
37 | #endif | 45 | #endif |
38 | } | 46 | } |
39 | 47 | ||
@@ -58,3 +66,31 @@ void kvm_unregister_irq_ack_notifier(struct kvm *kvm, | |||
58 | { | 66 | { |
59 | hlist_del(&kian->link); | 67 | hlist_del(&kian->link); |
60 | } | 68 | } |
69 | |||
70 | /* The caller must hold kvm->lock mutex */ | ||
71 | int kvm_request_irq_source_id(struct kvm *kvm) | ||
72 | { | ||
73 | unsigned long *bitmap = &kvm->arch.irq_sources_bitmap; | ||
74 | int irq_source_id = find_first_zero_bit(bitmap, | ||
75 | sizeof(kvm->arch.irq_sources_bitmap)); | ||
76 | if (irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) { | ||
77 | printk(KERN_WARNING "kvm: exhaust allocatable IRQ sources!\n"); | ||
78 | irq_source_id = -EFAULT; | ||
79 | } else | ||
80 | set_bit(irq_source_id, bitmap); | ||
81 | return irq_source_id; | ||
82 | } | ||
83 | |||
84 | void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) | ||
85 | { | ||
86 | int i; | ||
87 | |||
88 | if (irq_source_id <= 0 || | ||
89 | irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) { | ||
90 | printk(KERN_ERR "kvm: IRQ source ID out of range!\n"); | ||
91 | return; | ||
92 | } | ||
93 | for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++) | ||
94 | clear_bit(irq_source_id, &kvm->arch.irq_states[i]); | ||
95 | clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap); | ||
96 | } | ||
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index cf0ab8ed3845..a87f45edfae8 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -105,14 +105,12 @@ static void kvm_assigned_dev_interrupt_work_handler(struct work_struct *work) | |||
105 | */ | 105 | */ |
106 | mutex_lock(&assigned_dev->kvm->lock); | 106 | mutex_lock(&assigned_dev->kvm->lock); |
107 | kvm_set_irq(assigned_dev->kvm, | 107 | kvm_set_irq(assigned_dev->kvm, |
108 | assigned_dev->irq_source_id, | ||
108 | assigned_dev->guest_irq, 1); | 109 | assigned_dev->guest_irq, 1); |
109 | mutex_unlock(&assigned_dev->kvm->lock); | 110 | mutex_unlock(&assigned_dev->kvm->lock); |
110 | kvm_put_kvm(assigned_dev->kvm); | 111 | kvm_put_kvm(assigned_dev->kvm); |
111 | } | 112 | } |
112 | 113 | ||
113 | /* FIXME: Implement the OR logic needed to make shared interrupts on | ||
114 | * this line behave properly | ||
115 | */ | ||
116 | static irqreturn_t kvm_assigned_dev_intr(int irq, void *dev_id) | 114 | static irqreturn_t kvm_assigned_dev_intr(int irq, void *dev_id) |
117 | { | 115 | { |
118 | struct kvm_assigned_dev_kernel *assigned_dev = | 116 | struct kvm_assigned_dev_kernel *assigned_dev = |
@@ -134,7 +132,7 @@ static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian) | |||
134 | 132 | ||
135 | dev = container_of(kian, struct kvm_assigned_dev_kernel, | 133 | dev = container_of(kian, struct kvm_assigned_dev_kernel, |
136 | ack_notifier); | 134 | ack_notifier); |
137 | kvm_set_irq(dev->kvm, dev->guest_irq, 0); | 135 | kvm_set_irq(dev->kvm, dev->irq_source_id, dev->guest_irq, 0); |
138 | enable_irq(dev->host_irq); | 136 | enable_irq(dev->host_irq); |
139 | } | 137 | } |
140 | 138 | ||
@@ -146,6 +144,7 @@ static void kvm_free_assigned_device(struct kvm *kvm, | |||
146 | free_irq(assigned_dev->host_irq, (void *)assigned_dev); | 144 | free_irq(assigned_dev->host_irq, (void *)assigned_dev); |
147 | 145 | ||
148 | kvm_unregister_irq_ack_notifier(kvm, &assigned_dev->ack_notifier); | 146 | kvm_unregister_irq_ack_notifier(kvm, &assigned_dev->ack_notifier); |
147 | kvm_free_irq_source_id(kvm, assigned_dev->irq_source_id); | ||
149 | 148 | ||
150 | if (cancel_work_sync(&assigned_dev->interrupt_work)) | 149 | if (cancel_work_sync(&assigned_dev->interrupt_work)) |
151 | /* We had pending work. That means we will have to take | 150 | /* We had pending work. That means we will have to take |
@@ -215,6 +214,11 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm, | |||
215 | match->ack_notifier.gsi = assigned_irq->guest_irq; | 214 | match->ack_notifier.gsi = assigned_irq->guest_irq; |
216 | match->ack_notifier.irq_acked = kvm_assigned_dev_ack_irq; | 215 | match->ack_notifier.irq_acked = kvm_assigned_dev_ack_irq; |
217 | kvm_register_irq_ack_notifier(kvm, &match->ack_notifier); | 216 | kvm_register_irq_ack_notifier(kvm, &match->ack_notifier); |
217 | r = kvm_request_irq_source_id(kvm); | ||
218 | if (r < 0) | ||
219 | goto out_release; | ||
220 | else | ||
221 | match->irq_source_id = r; | ||
218 | 222 | ||
219 | /* Even though this is PCI, we don't want to use shared | 223 | /* Even though this is PCI, we don't want to use shared |
220 | * interrupts. Sharing host devices with guest-assigned devices | 224 | * interrupts. Sharing host devices with guest-assigned devices |