All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 rfc] kvm: get rid of srcu idx
@ 2010-10-25  6:48 Michael S. Tsirkin
  0 siblings, 0 replies; only message in thread
From: Michael S. Tsirkin @ 2010-10-25  6:48 UTC (permalink / raw)
  Cc: Avi Kivity, Marcelo Tosatti, kvm

srcu_idx is easy to misuse as it can not be used
in nested srcu_read_lock calls.  Switch to local
index to make correctness easier to verify.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

This version is rebased to 2.6.36.

 arch/x86/kvm/x86.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4ca1d7f..fe8960d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4672,7 +4672,7 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu)
 	}
 }
 
-static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
+static int vcpu_enter_guest(struct kvm_vcpu *vcpu, int *srcu_idx)
 {
 	int r;
 	bool req_int_win = !irqchip_in_kernel(vcpu->kvm) &&
@@ -4744,7 +4744,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 		kvm_lapic_sync_to_vapic(vcpu);
 	}
 
-	srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
+	srcu_read_unlock(&vcpu->kvm->srcu, *srcu_idx);
 
 	kvm_guest_enter();
 
@@ -4787,7 +4787,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 
 	preempt_enable();
 
-	vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
+	*srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
 
 	/*
 	 * Profile KVM exit RIPs:
@@ -4808,7 +4808,7 @@ out:
 
 static int __vcpu_run(struct kvm_vcpu *vcpu)
 {
-	int r;
+	int srcu_idx, r;
 	struct kvm *kvm = vcpu->kvm;
 
 	if (unlikely(vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED)) {
@@ -4821,17 +4821,17 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
 		vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
 	}
 
-	vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
+	srcu_idx = srcu_read_lock(&kvm->srcu);
 	vapic_enter(vcpu);
 
 	r = 1;
 	while (r > 0) {
 		if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE)
-			r = vcpu_enter_guest(vcpu);
+			r = vcpu_enter_guest(vcpu, &srcu_idx);
 		else {
-			srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
+			srcu_read_unlock(&kvm->srcu, srcu_idx);
 			kvm_vcpu_block(vcpu);
-			vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
+			srcu_idx = srcu_read_lock(&kvm->srcu);
 			if (kvm_check_request(KVM_REQ_UNHALT, vcpu))
 			{
 				switch(vcpu->arch.mp_state) {
@@ -4866,13 +4866,13 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
 			++vcpu->stat.signal_exits;
 		}
 		if (need_resched()) {
-			srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
+			srcu_read_unlock(&kvm->srcu, srcu_idx);
 			kvm_resched(vcpu);
-			vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
+			srcu_idx = srcu_read_lock(&kvm->srcu);
 		}
 	}
 
-	srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
+	srcu_read_unlock(&kvm->srcu, srcu_idx);
 
 	vapic_exit(vcpu);
 
@@ -4905,9 +4905,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 			vcpu->mmio_read_completed = 1;
 			vcpu->mmio_needed = 0;
 		}
-		vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
+		srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
 		r = emulate_instruction(vcpu, 0, 0, EMULTYPE_NO_DECODE);
-		srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
+		srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx);
 		if (r != EMULATE_DONE) {
 			r = 0;
 			goto out;
-- 
1.7.3-rc1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-10-25  6:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-25  6:48 [PATCHv2 rfc] kvm: get rid of srcu idx Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.