diff mbox

KVM: PPC: set IN_GUEST_MODE before checking requests

Message ID 1345683830-10768-1-git-send-email-scottwood@freescale.com (mailing list archive)
State New, archived
Headers show

Commit Message

Scott Wood Aug. 23, 2012, 1:03 a.m. UTC
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>
---
 arch/powerpc/kvm/booke.c   |    1 -
 arch/powerpc/kvm/powerpc.c |   14 +++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

Comments

Alexander Graf Sept. 25, 2012, 7:44 a.m. UTC | #1
On 23.08.2012, at 03:03, Scott Wood wrote:

> 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>

Does this patch address your comments on the previous pull request?

Applied to kvm-ppc-next.


Alex

> ---
> arch/powerpc/kvm/booke.c   |    1 -
> arch/powerpc/kvm/powerpc.c |   14 +++++++++-----
> 2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index 5f0476a..88711f8 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c
> @@ -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;
> }
> 
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 32d217c..3d460a0 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -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();
> @@ -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;
> 	}
> 
> -- 
> 1.7.9.5
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Scott Wood Sept. 25, 2012, 3:25 p.m. UTC | #2
On 09/25/2012 02:44:52 AM, Alexander Graf wrote:
> 
> On 23.08.2012, at 03:03, Scott Wood wrote:
> 
> > 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>
> 
> Does this patch address your comments on the previous pull request?

It addresses the comments on the vcpu->mode race... I don't remember if  
I had any other comments. :-)

-Scott
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 5f0476a..88711f8 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -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;
 }
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 32d217c..3d460a0 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -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();
@@ -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;
 	}