KVM: PPC: Book3S HV: Fix conditions for starting vcpu

"Linux Kernel Mailing List" <[email protected]> Sat, 10 Feb 2018 22:00:24 +0000 (UTC)
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/c0093f1a38a0fd6c32a2269f0533bb13fb95143d
Commit:     c0093f1a38a0fd6c32a2269f0533bb13fb95143d
Parent:     4fcf361dbdbdb43038bb173e2391c4073e713745
Refname:    refs/heads/master
Author:     Paul Mackerras <[email protected]>
AuthorDate: Mon Nov 20 16:12:25 2017 +1100
Committer:  Paul Mackerras <[email protected]>
CommitDate: Thu Nov 23 14:23:22 2017 +1100

    KVM: PPC: Book3S HV: Fix conditions for starting vcpu
    
    This corrects the test that determines whether a vcpu that has just
    become able to run in the guest (e.g. it has just finished handling
    a hypercall or hypervisor page fault) and whose virtual core is
    already running somewhere as a "piggybacked" vcore can start
    immediately or not.  (A piggybacked vcore is one which is executing
    along with another vcore as a result of dynamic micro-threading.)
    
    Previously the test tried to lock the piggybacked vcore using
    spin_trylock, which would always fail because the vcore was already
    locked, and so the vcpu would have to wait until its vcore exited
    the guest before it could enter.
    
    In fact the vcpu can enter if its vcore is in VCORE_PIGGYBACK state
    and not already exiting (or exited) the guest, so the test in
    VCORE_PIGGYBACK state is basically the same as for VCORE_RUNNING
    state.
    
    Coverity detected this as a double unlock issue, which it isn't
    because the spin_trylock would always fail.  This will fix the
    apparent double unlock as well.
    
    Signed-off-by: Paul Mackerras <[email protected]>
---
 arch/powerpc/kvm/book3s_hv.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 597498d6db2e..c4f0bebfc5ba 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3175,17 +3175,8 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 	 * this thread straight away and have it join in.
 	 */
 	if (!signal_pending(current)) {
-		if (vc->vcore_state == VCORE_PIGGYBACK) {
-			if (spin_trylock(&vc->lock)) {
-				if (vc->vcore_state == VCORE_RUNNING &&
-				    !VCORE_IS_EXITING(vc)) {
-					kvmppc_create_dtl_entry(vcpu, vc);
-					kvmppc_start_thread(vcpu, vc);
-					trace_kvm_guest_enter(vcpu);
-				}
-				spin_unlock(&vc->lock);
-			}
-		} else if (vc->vcore_state == VCORE_RUNNING &&
+		if ((vc->vcore_state == VCORE_PIGGYBACK ||
+		     vc->vcore_state == VCORE_RUNNING) &&
 			   !VCORE_IS_EXITING(vc)) {
 			kvmppc_create_dtl_entry(vcpu, vc);
 			kvmppc_start_thread(vcpu, vc);
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html