Skip to content

Commit

Permalink
KVM: PPC: set IN_GUEST_MODE before checking requests
Browse files Browse the repository at this point in the history
Avoid a race as described in the code comment.

Also remove a related smp_wmb() from booke's kvmppc_prepare_to_enter().
I can't see any reason for it, and the book3s_pr version doesn't have it.

Signed-off-by: Scott Wood <scottwood@freescale.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
  • Loading branch information
Scott Wood authored and Alexander Graf committed Oct 5, 2012
1 parent adbb48a commit 5bd1cf1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion arch/powerpc/kvm/booke.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)

out:
vcpu->mode = OUTSIDE_GUEST_MODE;
smp_wmb();
return ret;
}

Expand Down
14 changes: 9 additions & 5 deletions arch/powerpc/kvm/powerpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
break;
}

vcpu->mode = IN_GUEST_MODE;

/*
* Reading vcpu->requests must happen after setting vcpu->mode,
* so we don't miss a request because the requester sees
* OUTSIDE_GUEST_MODE and assumes we'll be checking requests
* before next entering the guest (and thus doesn't IPI).
*/
smp_mb();

if (vcpu->requests) {
/* Make sure we process requests preemptable */
local_irq_enable();
Expand Down Expand Up @@ -111,11 +120,6 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
#endif

kvm_guest_enter();

/* Going into guest context! Yay! */
vcpu->mode = IN_GUEST_MODE;
smp_wmb();

break;
}

Expand Down

0 comments on commit 5bd1cf1

Please sign in to comment.