aboutsummaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2008-05-08 18:47:01 -0400
committerAvi Kivity <avi@qumranet.com>2008-05-18 07:37:12 -0400
commite5c239cfd5b0ec22751c099dbf4d91f3c504a64f (patch)
treed0a63882f0592a4ce23a98478fb9c935213b2e16 /virt
parentbd25ed033af52c8c054d43a9cce9c5976266ae74 (diff)
KVM: Fix kvm_vcpu_block() task state race
There's still a race in kvm_vcpu_block(), if a wake_up_interruptible() call happens before the task state is set to TASK_INTERRUPTIBLE: CPU0 CPU1 kvm_vcpu_block add_wait_queue kvm_cpu_has_interrupt = 0 set interrupt if (waitqueue_active()) wake_up_interruptible() kvm_cpu_has_pending_timer kvm_arch_vcpu_runnable signal_pending set_current_state(TASK_INTERRUPTIBLE) schedule() Can be fixed by using prepare_to_wait() which sets the task state before testing for the wait condition. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index f7ba099049ea..2d29e260da3d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -758,25 +758,26 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
758 */ 758 */
759void kvm_vcpu_block(struct kvm_vcpu *vcpu) 759void kvm_vcpu_block(struct kvm_vcpu *vcpu)
760{ 760{
761 DECLARE_WAITQUEUE(wait, current); 761 DEFINE_WAIT(wait);
762 762
763 add_wait_queue(&vcpu->wq, &wait); 763 for (;;) {
764 764 prepare_to_wait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
765 /* 765
766 * We will block until either an interrupt or a signal wakes us up 766 if (kvm_cpu_has_interrupt(vcpu))
767 */ 767 break;
768 while (!kvm_cpu_has_interrupt(vcpu) 768 if (kvm_cpu_has_pending_timer(vcpu))
769 && !kvm_cpu_has_pending_timer(vcpu) 769 break;
770 && !signal_pending(current) 770 if (kvm_arch_vcpu_runnable(vcpu))
771 && !kvm_arch_vcpu_runnable(vcpu)) { 771 break;
772 set_current_state(TASK_INTERRUPTIBLE); 772 if (signal_pending(current))
773 break;
774
773 vcpu_put(vcpu); 775 vcpu_put(vcpu);
774 schedule(); 776 schedule();
775 vcpu_load(vcpu); 777 vcpu_load(vcpu);
776 } 778 }
777 779
778 __set_current_state(TASK_RUNNING); 780 finish_wait(&vcpu->wq, &wait);
779 remove_wait_queue(&vcpu->wq, &wait);
780} 781}
781 782
782void kvm_resched(struct kvm_vcpu *vcpu) 783void kvm_resched(struct kvm_vcpu *vcpu)