aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2009-08-07 05:49:28 -0400
committerAvi Kivity <avi@redhat.com>2009-09-10 01:33:23 -0400
commit2af9194d1b683f91ae956afff9afb0b52a241371 (patch)
tree70e7bc17d9e715b19545ce6002dfedbf160f6964
parent256cd2ef4f5c125f5df2c81d8457f080a4684ae6 (diff)
KVM: SVM: add helper functions for global interrupt flag
This patch makes the code easier to read when it comes to setting, clearing and checking the status of the virtualized global interrupt flag for the VCPU. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--arch/x86/kvm/svm.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 10e718db990b..9f7277273a23 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -129,6 +129,21 @@ static inline bool is_nested(struct vcpu_svm *svm)
129 return svm->nested_vmcb; 129 return svm->nested_vmcb;
130} 130}
131 131
132static inline void enable_gif(struct vcpu_svm *svm)
133{
134 svm->vcpu.arch.hflags |= HF_GIF_MASK;
135}
136
137static inline void disable_gif(struct vcpu_svm *svm)
138{
139 svm->vcpu.arch.hflags &= ~HF_GIF_MASK;
140}
141
142static inline bool gif_set(struct vcpu_svm *svm)
143{
144 return !!(svm->vcpu.arch.hflags & HF_GIF_MASK);
145}
146
132static unsigned long iopm_base; 147static unsigned long iopm_base;
133 148
134struct kvm_ldttss_desc { 149struct kvm_ldttss_desc {
@@ -621,7 +636,9 @@ static void init_vmcb(struct vcpu_svm *svm)
621 force_new_asid(&svm->vcpu); 636 force_new_asid(&svm->vcpu);
622 637
623 svm->nested_vmcb = 0; 638 svm->nested_vmcb = 0;
624 svm->vcpu.arch.hflags = HF_GIF_MASK; 639 svm->vcpu.arch.hflags = 0;
640
641 enable_gif(svm);
625} 642}
626 643
627static int svm_vcpu_reset(struct kvm_vcpu *vcpu) 644static int svm_vcpu_reset(struct kvm_vcpu *vcpu)
@@ -1629,7 +1646,7 @@ static int nested_svm_vmexit_real(struct vcpu_svm *svm, void *arg1,
1629 svm->vmcb->save.cpl = 0; 1646 svm->vmcb->save.cpl = 0;
1630 svm->vmcb->control.exit_int_info = 0; 1647 svm->vmcb->control.exit_int_info = 0;
1631 1648
1632 svm->vcpu.arch.hflags &= ~HF_GIF_MASK; 1649 disable_gif(svm);
1633 /* Exit nested SVM mode */ 1650 /* Exit nested SVM mode */
1634 svm->nested_vmcb = 0; 1651 svm->nested_vmcb = 0;
1635 1652
@@ -1761,7 +1778,7 @@ static int nested_svm_vmrun(struct vcpu_svm *svm, void *arg1,
1761 svm->vmcb->control.event_inj = nested_vmcb->control.event_inj; 1778 svm->vmcb->control.event_inj = nested_vmcb->control.event_inj;
1762 svm->vmcb->control.event_inj_err = nested_vmcb->control.event_inj_err; 1779 svm->vmcb->control.event_inj_err = nested_vmcb->control.event_inj_err;
1763 1780
1764 svm->vcpu.arch.hflags |= HF_GIF_MASK; 1781 enable_gif(svm);
1765 1782
1766 return 0; 1783 return 0;
1767} 1784}
@@ -1850,7 +1867,7 @@ static int stgi_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1850 svm->next_rip = kvm_rip_read(&svm->vcpu) + 3; 1867 svm->next_rip = kvm_rip_read(&svm->vcpu) + 3;
1851 skip_emulated_instruction(&svm->vcpu); 1868 skip_emulated_instruction(&svm->vcpu);
1852 1869
1853 svm->vcpu.arch.hflags |= HF_GIF_MASK; 1870 enable_gif(svm);
1854 1871
1855 return 1; 1872 return 1;
1856} 1873}
@@ -1863,7 +1880,7 @@ static int clgi_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1863 svm->next_rip = kvm_rip_read(&svm->vcpu) + 3; 1880 svm->next_rip = kvm_rip_read(&svm->vcpu) + 3;
1864 skip_emulated_instruction(&svm->vcpu); 1881 skip_emulated_instruction(&svm->vcpu);
1865 1882
1866 svm->vcpu.arch.hflags &= ~HF_GIF_MASK; 1883 disable_gif(svm);
1867 1884
1868 /* After a CLGI no interrupts should come */ 1885 /* After a CLGI no interrupts should come */
1869 svm_clear_vintr(svm); 1886 svm_clear_vintr(svm);
@@ -2352,7 +2369,7 @@ static void svm_set_irq(struct kvm_vcpu *vcpu)
2352{ 2369{
2353 struct vcpu_svm *svm = to_svm(vcpu); 2370 struct vcpu_svm *svm = to_svm(vcpu);
2354 2371
2355 BUG_ON(!(svm->vcpu.arch.hflags & HF_GIF_MASK)); 2372 BUG_ON(!(gif_set(svm)));
2356 2373
2357 svm->vmcb->control.event_inj = vcpu->arch.interrupt.nr | 2374 svm->vmcb->control.event_inj = vcpu->arch.interrupt.nr |
2358 SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR; 2375 SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR;
@@ -2383,7 +2400,7 @@ static int svm_interrupt_allowed(struct kvm_vcpu *vcpu)
2383 struct vmcb *vmcb = svm->vmcb; 2400 struct vmcb *vmcb = svm->vmcb;
2384 return (vmcb->save.rflags & X86_EFLAGS_IF) && 2401 return (vmcb->save.rflags & X86_EFLAGS_IF) &&
2385 !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) && 2402 !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
2386 (svm->vcpu.arch.hflags & HF_GIF_MASK) && 2403 gif_set(svm) &&
2387 !is_nested(svm); 2404 !is_nested(svm);
2388} 2405}
2389 2406
@@ -2398,7 +2415,7 @@ static void enable_irq_window(struct kvm_vcpu *vcpu)
2398 * GIF becomes 1, because that's a separate STGI/VMRUN intercept. 2415 * GIF becomes 1, because that's a separate STGI/VMRUN intercept.
2399 * The next time we get that intercept, this function will be 2416 * The next time we get that intercept, this function will be
2400 * called again though and we'll get the vintr intercept. */ 2417 * called again though and we'll get the vintr intercept. */
2401 if (svm->vcpu.arch.hflags & HF_GIF_MASK) { 2418 if (gif_set(svm)) {
2402 svm_set_vintr(svm); 2419 svm_set_vintr(svm);
2403 svm_inject_irq(svm, 0x0); 2420 svm_inject_irq(svm, 0x0);
2404 } 2421 }