From: "Michael S. Tsirkin" <mst@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, Avi Kivity <avi@redhat.com>
Subject: [PATCH] kvm: get rid of srcu idx
Date: Sun, 24 Oct 2010 19:16:10 +0200 [thread overview]
Message-ID: <20101024171610.GA24375@redhat.com> (raw)
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>
---
Lightly tested.
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 311f6da..edb9dfa 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -4672,7 +4729,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 +4801,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 +4844,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:
@@ -4809,6 +4866,7 @@ out:
static int __vcpu_run(struct kvm_vcpu *vcpu)
{
int r;
+ int srcu_idx;
struct kvm *kvm = vcpu->kvm;
if (unlikely(vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED)) {
@@ -4821,17 +4879,18 @@ 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 +4926,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);
@@ -4883,6 +4943,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
int r;
sigset_t sigsaved;
+ int srcu_idx;
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
@@ -4905,9 +4966,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;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index c13cc48..60eb9db 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -85,7 +85,6 @@ struct kvm_vcpu {
struct kvm_run *run;
unsigned long requests;
unsigned long guest_debug;
- int srcu_idx;
int fpu_active;
int guest_fpu_loaded, guest_xcr0_loaded;
next reply other threads:[~2010-10-24 17:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-24 17:16 Michael S. Tsirkin [this message]
2010-10-25 13:52 ` [PATCH] kvm: get rid of srcu idx Marcelo Tosatti
2010-10-25 13:20 ` Michael S. Tsirkin
2010-10-25 20:13 ` Marcelo Tosatti
2010-10-26 6:58 ` Gleb Natapov
2010-10-26 7:57 ` Avi Kivity
2010-10-26 8:01 ` Gleb Natapov
2010-10-26 8:06 ` Avi Kivity
2010-10-26 8:53 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101024171610.GA24375@redhat.com \
--to=mst@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.