aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorGleb Natapov <gleb@redhat.com>2009-03-23 05:23:18 -0400
committerAvi Kivity <avi@redhat.com>2009-06-10 04:48:31 -0400
commitfe4c7b1914ac46af751d256f5a20c2e12dcbaaae (patch)
tree4533d4a230e64bab951f2b4f7d7147e309a11ee5 /arch/x86
parent61c50edfcd40be9126579f9cec68c789b6089998 (diff)
KVM: reuse (pop|push)_irq from svm.c in vmx.c
The prioritized bit vector manipulation functions are useful in both vmx and svm. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kvm/svm.c25
-rw-r--r--arch/x86/kvm/vmx.c17
-rw-r--r--arch/x86/kvm/x86.h18
3 files changed, 24 insertions, 36 deletions
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 5b35ebd4ec88..aa528dbad070 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -19,6 +19,7 @@
19#include "irq.h" 19#include "irq.h"
20#include "mmu.h" 20#include "mmu.h"
21#include "kvm_cache_regs.h" 21#include "kvm_cache_regs.h"
22#include "x86.h"
22 23
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
@@ -132,24 +133,6 @@ static inline u32 svm_has(u32 feat)
132 return svm_features & feat; 133 return svm_features & feat;
133} 134}
134 135
135static inline u8 pop_irq(struct kvm_vcpu *vcpu)
136{
137 int word_index = __ffs(vcpu->arch.irq_summary);
138 int bit_index = __ffs(vcpu->arch.irq_pending[word_index]);
139 int irq = word_index * BITS_PER_LONG + bit_index;
140
141 clear_bit(bit_index, &vcpu->arch.irq_pending[word_index]);
142 if (!vcpu->arch.irq_pending[word_index])
143 clear_bit(word_index, &vcpu->arch.irq_summary);
144 return irq;
145}
146
147static inline void push_irq(struct kvm_vcpu *vcpu, u8 irq)
148{
149 set_bit(irq, vcpu->arch.irq_pending);
150 set_bit(irq / BITS_PER_LONG, &vcpu->arch.irq_summary);
151}
152
153static inline void clgi(void) 136static inline void clgi(void)
154{ 137{
155 asm volatile (__ex(SVM_CLGI)); 138 asm volatile (__ex(SVM_CLGI));
@@ -1116,7 +1099,7 @@ static int pf_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1116 if (!irqchip_in_kernel(kvm) && 1099 if (!irqchip_in_kernel(kvm) &&
1117 is_external_interrupt(exit_int_info)) { 1100 is_external_interrupt(exit_int_info)) {
1118 event_injection = true; 1101 event_injection = true;
1119 push_irq(&svm->vcpu, exit_int_info & SVM_EVTINJ_VEC_MASK); 1102 kvm_push_irq(&svm->vcpu, exit_int_info & SVM_EVTINJ_VEC_MASK);
1120 } 1103 }
1121 1104
1122 fault_address = svm->vmcb->control.exit_info_2; 1105 fault_address = svm->vmcb->control.exit_info_2;
@@ -2336,7 +2319,7 @@ static void kvm_reput_irq(struct vcpu_svm *svm)
2336 if ((control->int_ctl & V_IRQ_MASK) 2319 if ((control->int_ctl & V_IRQ_MASK)
2337 && !irqchip_in_kernel(svm->vcpu.kvm)) { 2320 && !irqchip_in_kernel(svm->vcpu.kvm)) {
2338 control->int_ctl &= ~V_IRQ_MASK; 2321 control->int_ctl &= ~V_IRQ_MASK;
2339 push_irq(&svm->vcpu, control->int_vector); 2322 kvm_push_irq(&svm->vcpu, control->int_vector);
2340 } 2323 }
2341 2324
2342 svm->vcpu.arch.interrupt_window_open = 2325 svm->vcpu.arch.interrupt_window_open =
@@ -2346,7 +2329,7 @@ static void kvm_reput_irq(struct vcpu_svm *svm)
2346 2329
2347static void svm_do_inject_vector(struct vcpu_svm *svm) 2330static void svm_do_inject_vector(struct vcpu_svm *svm)
2348{ 2331{
2349 svm_inject_irq(svm, pop_irq(&svm->vcpu)); 2332 svm_inject_irq(svm, kvm_pop_irq(&svm->vcpu));
2350} 2333}
2351 2334
2352static void do_interrupt_requests(struct kvm_vcpu *vcpu, 2335static void do_interrupt_requests(struct kvm_vcpu *vcpu,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b5eae7a00aad..2c0a2ed708d2 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2489,18 +2489,6 @@ static void vmx_update_window_states(struct kvm_vcpu *vcpu)
2489 GUEST_INTR_STATE_MOV_SS))); 2489 GUEST_INTR_STATE_MOV_SS)));
2490} 2490}
2491 2491
2492static void kvm_do_inject_irq(struct kvm_vcpu *vcpu)
2493{
2494 int word_index = __ffs(vcpu->arch.irq_summary);
2495 int bit_index = __ffs(vcpu->arch.irq_pending[word_index]);
2496 int irq = word_index * BITS_PER_LONG + bit_index;
2497
2498 clear_bit(bit_index, &vcpu->arch.irq_pending[word_index]);
2499 if (!vcpu->arch.irq_pending[word_index])
2500 clear_bit(word_index, &vcpu->arch.irq_summary);
2501 kvm_queue_interrupt(vcpu, irq);
2502}
2503
2504static void do_interrupt_requests(struct kvm_vcpu *vcpu, 2492static void do_interrupt_requests(struct kvm_vcpu *vcpu,
2505 struct kvm_run *kvm_run) 2493 struct kvm_run *kvm_run)
2506{ 2494{
@@ -2534,7 +2522,7 @@ static void do_interrupt_requests(struct kvm_vcpu *vcpu,
2534 2522
2535 if (vcpu->arch.interrupt_window_open) { 2523 if (vcpu->arch.interrupt_window_open) {
2536 if (vcpu->arch.irq_summary && !vcpu->arch.interrupt.pending) 2524 if (vcpu->arch.irq_summary && !vcpu->arch.interrupt.pending)
2537 kvm_do_inject_irq(vcpu); 2525 kvm_queue_interrupt(vcpu, kvm_pop_irq(vcpu));
2538 2526
2539 if (vcpu->arch.interrupt.pending) 2527 if (vcpu->arch.interrupt.pending)
2540 vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr); 2528 vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
@@ -2619,8 +2607,7 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2619 2607
2620 if (!irqchip_in_kernel(vcpu->kvm) && is_external_interrupt(vect_info)) { 2608 if (!irqchip_in_kernel(vcpu->kvm) && is_external_interrupt(vect_info)) {
2621 int irq = vect_info & VECTORING_INFO_VECTOR_MASK; 2609 int irq = vect_info & VECTORING_INFO_VECTOR_MASK;
2622 set_bit(irq, vcpu->arch.irq_pending); 2610 kvm_push_irq(vcpu, irq);
2623 set_bit(irq / BITS_PER_LONG, &vcpu->arch.irq_summary);
2624 } 2611 }
2625 2612
2626 if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR) 2613 if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR)
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 6a4be78a7384..2ab679102dcd 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -19,4 +19,22 @@ static inline void kvm_clear_interrupt_queue(struct kvm_vcpu *vcpu)
19 vcpu->arch.interrupt.pending = false; 19 vcpu->arch.interrupt.pending = false;
20} 20}
21 21
22static inline u8 kvm_pop_irq(struct kvm_vcpu *vcpu)
23{
24 int word_index = __ffs(vcpu->arch.irq_summary);
25 int bit_index = __ffs(vcpu->arch.irq_pending[word_index]);
26 int irq = word_index * BITS_PER_LONG + bit_index;
27
28 clear_bit(bit_index, &vcpu->arch.irq_pending[word_index]);
29 if (!vcpu->arch.irq_pending[word_index])
30 clear_bit(word_index, &vcpu->arch.irq_summary);
31 return irq;
32}
33
34static inline void kvm_push_irq(struct kvm_vcpu *vcpu, u8 irq)
35{
36 set_bit(irq, vcpu->arch.irq_pending);
37 set_bit(irq / BITS_PER_LONG, &vcpu->arch.irq_summary);
38}
39
22#endif 40#endif