[PATCH 3/4] House svm.c's pop_irq and push_irq helpers into generic header

Rusty Russell
2007-07-30T06:36:08Z

Everyone can use push_irq() and pop_irq(), so move them to common code.

Signed-off-by: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>

diff -r a26d2ddb1eee drivers/kvm/kvm.h
--- a/drivers/kvm/kvm.h Fri Jul 27 18:08:57 2007 +1000
+++ b/drivers/kvm/kvm.h Fri Jul 27 18:09:38 2007 +1000
@@ -725,6 +725,24 @@ static inline u32 get_rdx_init_val(void)
return 0x600; /* P6 family */
}

+static inline u8 pop_irq(struct kvm_vcpu *vcpu)
+{
+ int word_index = __ffs(vcpu->irq_summary);
+ int bit_index = __ffs(vcpu->irq_pending[word_index]);
+ int irq = word_index * BITS_PER_LONG + bit_index;
+
+ clear_bit(bit_index, &vcpu->irq_pending[word_index]);
+ if (!vcpu->irq_pending[word_index])
+ clear_bit(word_index, &vcpu->irq_summary);
+ return irq;
+}
+
+static inline void push_irq(struct kvm_vcpu *vcpu, u8 irq)
+{
+ set_bit(irq, vcpu->irq_pending);
+ set_bit(irq / BITS_PER_LONG, &vcpu->irq_summary);
+}
+
#define ASM_VMX_VMCLEAR_RAX ".byte 0x66, 0x0f, 0xc7, 0x30"
#define ASM_VMX_VMLAUNCH ".byte 0x0f, 0x01, 0xc2"
#define ASM_VMX_VMRESUME ".byte 0x0f, 0x01, 0xc3"
diff -r a26d2ddb1eee drivers/kvm/kvm_main.c
--- a/drivers/kvm/kvm_main.c Fri Jul 27 18:08:57 2007 +1000
+++ b/drivers/kvm/kvm_main.c Fri Jul 27 18:12:19 2007 +1000
@@ -2299,10 +2299,7 @@ static int kvm_vcpu_ioctl_interrupt(stru
if (irq->irq < 0 || irq->irq >= 256)
return -EINVAL;
vcpu_load(vcpu);
-
- set_bit(irq->irq, vcpu->irq_pending);
- set_bit(irq->irq / BITS_PER_LONG, &vcpu->irq_summary);
-
+ push_irq(vcpu, irq->irq);
vcpu_put(vcpu);

return 0;
diff -r a26d2ddb1eee drivers/kvm/svm.c
--- a/drivers/kvm/svm.c Fri Jul 27 18:08:57 2007 +1000
+++ b/drivers/kvm/svm.c Fri Jul 27 18:09:03 2007 +1000
@@ -110,24 +110,6 @@ static unsigned get_addr_size(struct vcp

return (cs_attrib & SVM_SELECTOR_L_MASK) ? 8 :
(cs_attrib & SVM_SELECTOR_DB_MASK) ? 4 : 2;
-}
-
-static inline u8 pop_irq(struct kvm_vcpu *vcpu)
-{
- int word_index = __ffs(vcpu->irq_summary);
- int bit_index = __ffs(vcpu->irq_pending[word_index]);
- int irq = word_index * BITS_PER_LONG + bit_index;
-
- clear_bit(bit_index, &vcpu->irq_pending[word_index]);
- if (!vcpu->irq_pending[word_index])
- clear_bit(word_index, &vcpu->irq_summary);
- return irq;
-}
-
-static inline void push_irq(struct kvm_vcpu *vcpu, u8 irq)
-{
- set_bit(irq, vcpu->irq_pending);
- set_bit(irq / BITS_PER_LONG, &vcpu->irq_summary);
}

static inline void clgi(void)
diff -r a26d2ddb1eee drivers/kvm/vmx.c
--- a/drivers/kvm/vmx.c Fri Jul 27 18:08:57 2007 +1000
+++ b/drivers/kvm/vmx.c Fri Jul 27 18:10:43 2007 +1000
@@ -1525,13 +1525,7 @@ static void inject_rmode_irq(struct kvm_

static void kvm_do_inject_irq(struct kvm_vcpu *vcpu)
{
- int word_index = __ffs(vcpu->irq_summary);
- int bit_index = __ffs(vcpu->irq_pending[word_index]);
- int irq = word_index * BITS_PER_LONG + bit_index;
-
- clear_bit(bit_index, &vcpu->irq_pending[word_index]);
- if (!vcpu->irq_pending[word_index])
- clear_bit(word_index, &vcpu->irq_summary);
+ int irq = pop_irq(vcpu);

if (vcpu->rmode.active) {
inject_rmode_irq(vcpu, irq);
@@ -1622,11 +1616,8 @@ static int handle_exception(struct kvm_v
"intr info 0x%x\n", __FUNCTION__, vect_info, intr_info);
}

- if (is_external_interrupt(vect_info)) {
- int irq = vect_info & VECTORING_INFO_VECTOR_MASK;
- set_bit(irq, vcpu->irq_pending);
- set_bit(irq / BITS_PER_LONG, &vcpu->irq_summary);
- }
+ if (is_external_interrupt(vect_info))
+ push_irq(vcpu, vect_info & VECTORING_INFO_VECTOR_MASK);

if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == 0x200) { /* nmi */
asm ("int $2");