From: Jesse <jdutton@neuraliq.com>
To: kvm@vger.kernel.org
Subject: [PATCH]: pointer to vmcs getting lost
Date: Fri, 01 Aug 2008 15:18:52 -0700 [thread overview]
Message-ID: <48938BCC.2030402@neuraliq.com> (raw)
Greetings,
I noticed a race condition when running two guests simultaneously and
debugging both guests (on 64-bit intel cpus). Periodically I would get
errors from the vmread, vmwrite, or vmresume instructions. Some research
revealed that these errors were being caused by having an invalid vmcs
loaded. Further, I found that the vmcs is a per_cpu variable, which I
believe means that any reference to it is invalid after a context
switch. (Corrections appreciated). This means that the vmcs must be
reloaded each time the process is switched to. The patch below fixed the
problem for me.
This patch does three things.
1. Extends the critical section in __vcpu_run to include the handling of
vmexits, where many of the vmread/writes occur.
2. Perform a vcpu_load after we enter the critical section, and after we
return from kvm_resched.
3. Move the call to kvm_guest_debug_pre into the critical section
(because it calls vmread/write).
I hope you find this useful. I am not on list, so please CC me on replies.
~Jesse Dutton
diff -ruNa kvm-72/kernel/x86.c kvm-72-changed/kernel/x86.c
--- kvm-72/kernel/x86.c 2008-07-27 06:20:10.000000000 -0700
+++ kvm-72-changed/kernel/x86.c 2008-07-31 15:25:25.000000000 -0700
@@ -2845,8 +2845,6 @@
vapic_enter(vcpu);
preempted:
- if (vcpu->guest_debug.enabled)
- kvm_x86_ops->guest_debug_pre(vcpu);
again:
if (vcpu->requests)
@@ -2878,7 +2876,12 @@
clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
kvm_inject_pending_timer_irqs(vcpu);
+ vcpu_put(vcpu);
preempt_disable();
+ vcpu_load(vcpu);
+
+ if (vcpu->guest_debug.enabled)
+ kvm_x86_ops->guest_debug_pre(vcpu);
kvm_x86_ops->prepare_guest_switch(vcpu);
kvm_load_guest_fpu(vcpu);
@@ -2941,7 +2944,6 @@
kvm_guest_exit();
- preempt_enable();
down_read(&vcpu->kvm->slots_lock);
@@ -2960,6 +2962,8 @@
r = kvm_x86_ops->handle_exit(kvm_run, vcpu);
+ preempt_enable();
+
if (r > 0) {
if (dm_request_for_irq_injection(vcpu, kvm_run)) {
r = -EINTR;
@@ -2974,7 +2978,9 @@
out:
up_read(&vcpu->kvm->slots_lock);
if (r > 0) {
+ vcpu_put(vcpu);
kvm_resched(vcpu);
+ vcpu_load(vcpu);
down_read(&vcpu->kvm->slots_lock);
goto preempted;
}
next reply other threads:[~2008-08-01 22:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-01 22:18 Jesse [this message]
2008-08-01 23:24 ` [PATCH]: pointer to vmcs getting lost Marcelo Tosatti
2008-08-01 23:36 ` Jesse
2008-08-02 16:31 ` Marcelo Tosatti
2008-08-03 0:11 ` Jesse
2008-08-11 11:48 ` Avi Kivity
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=48938BCC.2030402@neuraliq.com \
--to=jdutton@neuraliq.com \
--cc=kvm@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox