aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYang Zhang <yang.z.zhang@Intel.com>2013-04-11 07:25:13 -0400
committerMarcelo Tosatti <mtosatti@redhat.com>2013-04-16 15:32:40 -0400
commit3d81bc7e96d6bca0b8f8b7d1bf6ea72caa3aac57 (patch)
tree3e8d83b8d80c87c38cc0bb1d3caef6286ad9dd48
parent01e439be7753c163932538276f04f95cb1b66697 (diff)
KVM: Call common update function when ioapic entry changed.
Both TMR and EOI exit bitmap need to be updated when ioapic changed or vcpu's id/ldr/dfr changed. So use common function instead eoi exit bitmap specific function. Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com> Reviewed-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r--arch/ia64/kvm/lapic.h6
-rw-r--r--arch/x86/kvm/lapic.c2
-rw-r--r--arch/x86/kvm/vmx.c3
-rw-r--r--arch/x86/kvm/x86.c11
-rw-r--r--include/linux/kvm_host.h4
-rw-r--r--virt/kvm/ioapic.c22
-rw-r--r--virt/kvm/ioapic.h6
-rw-r--r--virt/kvm/irq_comm.c4
-rw-r--r--virt/kvm/kvm_main.c4
9 files changed, 32 insertions, 30 deletions
diff --git a/arch/ia64/kvm/lapic.h b/arch/ia64/kvm/lapic.h
index c3e2935b6db4..c5f92a926a9a 100644
--- a/arch/ia64/kvm/lapic.h
+++ b/arch/ia64/kvm/lapic.h
@@ -27,10 +27,4 @@ int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq);
27#define kvm_apic_present(x) (true) 27#define kvm_apic_present(x) (true)
28#define kvm_lapic_enabled(x) (true) 28#define kvm_lapic_enabled(x) (true)
29 29
30static inline bool kvm_apic_vid_enabled(void)
31{
32 /* IA64 has no apicv supporting, do nothing here */
33 return false;
34}
35
36#endif 30#endif
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 67962188c775..34a8ca845280 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -217,7 +217,7 @@ out:
217 if (old) 217 if (old)
218 kfree_rcu(old, rcu); 218 kfree_rcu(old, rcu);
219 219
220 kvm_ioapic_make_eoibitmap_request(kvm); 220 kvm_vcpu_request_scan_ioapic(kvm);
221} 221}
222 222
223static inline void kvm_apic_set_id(struct kvm_lapic *apic, u8 id) 223static inline void kvm_apic_set_id(struct kvm_lapic *apic, u8 id)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 7607c6c09c74..8535519d0352 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6414,6 +6414,9 @@ static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
6414 6414
6415static void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap) 6415static void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
6416{ 6416{
6417 if (!vmx_vm_has_apicv(vcpu->kvm))
6418 return;
6419
6417 vmcs_write64(EOI_EXIT_BITMAP0, eoi_exit_bitmap[0]); 6420 vmcs_write64(EOI_EXIT_BITMAP0, eoi_exit_bitmap[0]);
6418 vmcs_write64(EOI_EXIT_BITMAP1, eoi_exit_bitmap[1]); 6421 vmcs_write64(EOI_EXIT_BITMAP1, eoi_exit_bitmap[1]);
6419 vmcs_write64(EOI_EXIT_BITMAP2, eoi_exit_bitmap[2]); 6422 vmcs_write64(EOI_EXIT_BITMAP2, eoi_exit_bitmap[2]);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1562671a8e18..87a05df3eae4 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5661,13 +5661,16 @@ static void kvm_gen_update_masterclock(struct kvm *kvm)
5661#endif 5661#endif
5662} 5662}
5663 5663
5664static void update_eoi_exitmap(struct kvm_vcpu *vcpu) 5664static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
5665{ 5665{
5666 u64 eoi_exit_bitmap[4]; 5666 u64 eoi_exit_bitmap[4];
5667 5667
5668 if (!kvm_apic_hw_enabled(vcpu->arch.apic))
5669 return;
5670
5668 memset(eoi_exit_bitmap, 0, 32); 5671 memset(eoi_exit_bitmap, 0, 32);
5669 5672
5670 kvm_ioapic_calculate_eoi_exitmap(vcpu, eoi_exit_bitmap); 5673 kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap);
5671 kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap); 5674 kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
5672} 5675}
5673 5676
@@ -5724,8 +5727,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
5724 kvm_handle_pmu_event(vcpu); 5727 kvm_handle_pmu_event(vcpu);
5725 if (kvm_check_request(KVM_REQ_PMI, vcpu)) 5728 if (kvm_check_request(KVM_REQ_PMI, vcpu))
5726 kvm_deliver_pmi(vcpu); 5729 kvm_deliver_pmi(vcpu);
5727 if (kvm_check_request(KVM_REQ_EOIBITMAP, vcpu)) 5730 if (kvm_check_request(KVM_REQ_SCAN_IOAPIC, vcpu))
5728 update_eoi_exitmap(vcpu); 5731 vcpu_scan_ioapic(vcpu);
5729 } 5732 }
5730 5733
5731 if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) { 5734 if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) {
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 4a76aca31478..93a50054d46c 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -126,7 +126,7 @@ static inline bool is_error_page(struct page *page)
126#define KVM_REQ_MASTERCLOCK_UPDATE 19 126#define KVM_REQ_MASTERCLOCK_UPDATE 19
127#define KVM_REQ_MCLOCK_INPROGRESS 20 127#define KVM_REQ_MCLOCK_INPROGRESS 20
128#define KVM_REQ_EPR_EXIT 21 128#define KVM_REQ_EPR_EXIT 21
129#define KVM_REQ_EOIBITMAP 22 129#define KVM_REQ_SCAN_IOAPIC 22
130 130
131#define KVM_USERSPACE_IRQ_SOURCE_ID 0 131#define KVM_USERSPACE_IRQ_SOURCE_ID 0
132#define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1 132#define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1
@@ -575,7 +575,7 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
575void kvm_flush_remote_tlbs(struct kvm *kvm); 575void kvm_flush_remote_tlbs(struct kvm *kvm);
576void kvm_reload_remote_mmus(struct kvm *kvm); 576void kvm_reload_remote_mmus(struct kvm *kvm);
577void kvm_make_mclock_inprogress_request(struct kvm *kvm); 577void kvm_make_mclock_inprogress_request(struct kvm *kvm);
578void kvm_make_update_eoibitmap_request(struct kvm *kvm); 578void kvm_make_scan_ioapic_request(struct kvm *kvm);
579 579
580long kvm_arch_dev_ioctl(struct file *filp, 580long kvm_arch_dev_ioctl(struct file *filp,
581 unsigned int ioctl, unsigned long arg); 581 unsigned int ioctl, unsigned long arg);
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
index 97c67a50f904..f2157a985a1f 100644
--- a/virt/kvm/ioapic.c
+++ b/virt/kvm/ioapic.c
@@ -193,15 +193,13 @@ static void update_handled_vectors(struct kvm_ioapic *ioapic)
193 smp_wmb(); 193 smp_wmb();
194} 194}
195 195
196void kvm_ioapic_calculate_eoi_exitmap(struct kvm_vcpu *vcpu, 196void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
197 u64 *eoi_exit_bitmap)
198{ 197{
199 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; 198 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;
200 union kvm_ioapic_redirect_entry *e; 199 union kvm_ioapic_redirect_entry *e;
201 int index; 200 int index;
202 201
203 spin_lock(&ioapic->lock); 202 spin_lock(&ioapic->lock);
204 /* traverse ioapic entry to set eoi exit bitmap*/
205 for (index = 0; index < IOAPIC_NUM_PINS; index++) { 203 for (index = 0; index < IOAPIC_NUM_PINS; index++) {
206 e = &ioapic->redirtbl[index]; 204 e = &ioapic->redirtbl[index];
207 if (!e->fields.mask && 205 if (!e->fields.mask &&
@@ -215,16 +213,22 @@ void kvm_ioapic_calculate_eoi_exitmap(struct kvm_vcpu *vcpu,
215 } 213 }
216 spin_unlock(&ioapic->lock); 214 spin_unlock(&ioapic->lock);
217} 215}
218EXPORT_SYMBOL_GPL(kvm_ioapic_calculate_eoi_exitmap);
219 216
220void kvm_ioapic_make_eoibitmap_request(struct kvm *kvm) 217#ifdef CONFIG_X86
218void kvm_vcpu_request_scan_ioapic(struct kvm *kvm)
221{ 219{
222 struct kvm_ioapic *ioapic = kvm->arch.vioapic; 220 struct kvm_ioapic *ioapic = kvm->arch.vioapic;
223 221
224 if (!kvm_apic_vid_enabled(kvm) || !ioapic) 222 if (!ioapic)
225 return; 223 return;
226 kvm_make_update_eoibitmap_request(kvm); 224 kvm_make_scan_ioapic_request(kvm);
227} 225}
226#else
227void kvm_vcpu_request_scan_ioapic(struct kvm *kvm)
228{
229 return;
230}
231#endif
228 232
229static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val) 233static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
230{ 234{
@@ -267,7 +271,7 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
267 if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG 271 if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG
268 && ioapic->irr & (1 << index)) 272 && ioapic->irr & (1 << index))
269 ioapic_service(ioapic, index, false); 273 ioapic_service(ioapic, index, false);
270 kvm_ioapic_make_eoibitmap_request(ioapic->kvm); 274 kvm_vcpu_request_scan_ioapic(ioapic->kvm);
271 break; 275 break;
272 } 276 }
273} 277}
@@ -586,7 +590,7 @@ int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state)
586 spin_lock(&ioapic->lock); 590 spin_lock(&ioapic->lock);
587 memcpy(ioapic, state, sizeof(struct kvm_ioapic_state)); 591 memcpy(ioapic, state, sizeof(struct kvm_ioapic_state));
588 update_handled_vectors(ioapic); 592 update_handled_vectors(ioapic);
589 kvm_ioapic_make_eoibitmap_request(kvm); 593 kvm_vcpu_request_scan_ioapic(kvm);
590 kvm_rtc_eoi_tracking_restore_all(ioapic); 594 kvm_rtc_eoi_tracking_restore_all(ioapic);
591 spin_unlock(&ioapic->lock); 595 spin_unlock(&ioapic->lock);
592 return 0; 596 return 0;
diff --git a/virt/kvm/ioapic.h b/virt/kvm/ioapic.h
index 554157bbb586..674a388612b4 100644
--- a/virt/kvm/ioapic.h
+++ b/virt/kvm/ioapic.h
@@ -96,9 +96,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
96 struct kvm_lapic_irq *irq, unsigned long *dest_map); 96 struct kvm_lapic_irq *irq, unsigned long *dest_map);
97int kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state); 97int kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
98int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state); 98int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
99void kvm_ioapic_make_eoibitmap_request(struct kvm *kvm); 99void kvm_vcpu_request_scan_ioapic(struct kvm *kvm);
100void kvm_ioapic_calculate_eoi_exitmap(struct kvm_vcpu *vcpu, 100void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
101 u64 *eoi_exit_bitmap);
102
103 101
104#endif 102#endif
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index 8efb580edfef..25ab48007adb 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -285,7 +285,7 @@ void kvm_register_irq_ack_notifier(struct kvm *kvm,
285 mutex_lock(&kvm->irq_lock); 285 mutex_lock(&kvm->irq_lock);
286 hlist_add_head_rcu(&kian->link, &kvm->irq_ack_notifier_list); 286 hlist_add_head_rcu(&kian->link, &kvm->irq_ack_notifier_list);
287 mutex_unlock(&kvm->irq_lock); 287 mutex_unlock(&kvm->irq_lock);
288 kvm_ioapic_make_eoibitmap_request(kvm); 288 kvm_vcpu_request_scan_ioapic(kvm);
289} 289}
290 290
291void kvm_unregister_irq_ack_notifier(struct kvm *kvm, 291void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
@@ -295,7 +295,7 @@ void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
295 hlist_del_init_rcu(&kian->link); 295 hlist_del_init_rcu(&kian->link);
296 mutex_unlock(&kvm->irq_lock); 296 mutex_unlock(&kvm->irq_lock);
297 synchronize_rcu(); 297 synchronize_rcu();
298 kvm_ioapic_make_eoibitmap_request(kvm); 298 kvm_vcpu_request_scan_ioapic(kvm);
299} 299}
300 300
301int kvm_request_irq_source_id(struct kvm *kvm) 301int kvm_request_irq_source_id(struct kvm *kvm)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index ac3182eed462..65a9e0716a8d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -217,9 +217,9 @@ void kvm_make_mclock_inprogress_request(struct kvm *kvm)
217 make_all_cpus_request(kvm, KVM_REQ_MCLOCK_INPROGRESS); 217 make_all_cpus_request(kvm, KVM_REQ_MCLOCK_INPROGRESS);
218} 218}
219 219
220void kvm_make_update_eoibitmap_request(struct kvm *kvm) 220void kvm_make_scan_ioapic_request(struct kvm *kvm)
221{ 221{
222 make_all_cpus_request(kvm, KVM_REQ_EOIBITMAP); 222 make_all_cpus_request(kvm, KVM_REQ_SCAN_IOAPIC);
223} 223}
224 224
225int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id) 225int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)