From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 2/5] KVM: reintroduce guest mode bit and unify remote request code
Date: Wed, 26 Aug 2009 22:20:02 -0300 [thread overview]
Message-ID: <20090827012955.208915957@localhost.localdomain> (raw)
In-Reply-To: 20090827012000.762063112@localhost.localdomain
[-- Attachment #1: reintroduce-guest-mode --]
[-- Type: text/plain, Size: 4840 bytes --]
Split KVM_REQ_KICKED in two bits: KVM_VCPU_KICKED, to indicate
whether a vcpu has been IPI'ed, and KVM_VCPU_GUEST_MODE, in a separate
vcpu_state variable.
Unify remote requests with kvm_vcpu_kick.
Synchronous requests wait on KVM_VCPU_GUEST_MODE, via wait_on_bit/wake_up_bit.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: kvm/arch/x86/kvm/x86.c
===================================================================
--- kvm.orig/arch/x86/kvm/x86.c
+++ kvm/arch/x86/kvm/x86.c
@@ -3586,11 +3586,14 @@ static int vcpu_enter_guest(struct kvm_v
local_irq_disable();
- clear_bit(KVM_REQ_KICK, &vcpu->requests);
- smp_mb__after_clear_bit();
+ set_bit(KVM_VCPU_GUEST_MODE, &vcpu->vcpu_state);
+ barrier();
if (vcpu->requests || need_resched() || signal_pending(current)) {
- set_bit(KVM_REQ_KICK, &vcpu->requests);
+ clear_bit(KVM_VCPU_KICKED, &vcpu->vcpu_state);
+ clear_bit(KVM_VCPU_GUEST_MODE, &vcpu->vcpu_state);
+ smp_mb__after_clear_bit();
+ wake_up_bit(&vcpu->vcpu_state, KVM_VCPU_GUEST_MODE);
local_irq_enable();
preempt_enable();
r = 1;
@@ -3642,7 +3645,10 @@ static int vcpu_enter_guest(struct kvm_v
set_debugreg(vcpu->arch.host_dr6, 6);
set_debugreg(vcpu->arch.host_dr7, 7);
- set_bit(KVM_REQ_KICK, &vcpu->requests);
+ clear_bit(KVM_VCPU_KICKED, &vcpu->vcpu_state);
+ clear_bit(KVM_VCPU_GUEST_MODE, &vcpu->vcpu_state);
+ smp_mb__after_clear_bit();
+ wake_up_bit(&vcpu->vcpu_state, KVM_VCPU_GUEST_MODE);
local_irq_enable();
++vcpu->stat.exits;
Index: kvm/include/linux/kvm_host.h
===================================================================
--- kvm.orig/include/linux/kvm_host.h
+++ kvm/include/linux/kvm_host.h
@@ -42,6 +42,9 @@
#define KVM_USERSPACE_IRQ_SOURCE_ID 0
+#define KVM_VCPU_GUEST_MODE 0
+#define KVM_VCPU_KICKED 1
+
struct kvm;
struct kvm_vcpu;
extern struct kmem_cache *kvm_vcpu_cache;
@@ -83,6 +86,7 @@ struct kvm_vcpu {
int cpu;
struct kvm_run *run;
unsigned long requests;
+ unsigned long vcpu_state;
unsigned long guest_debug;
int fpu_active;
int guest_fpu_loaded;
@@ -362,6 +366,7 @@ void kvm_arch_sync_events(struct kvm *kv
int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
+void kvm_vcpu_ipi(struct kvm_vcpu *vcpu);
int kvm_is_mmio_pfn(pfn_t pfn);
Index: kvm/virt/kvm/kvm_main.c
===================================================================
--- kvm.orig/virt/kvm/kvm_main.c
+++ kvm/virt/kvm/kvm_main.c
@@ -119,18 +119,26 @@ void vcpu_put(struct kvm_vcpu *vcpu)
void kvm_vcpu_kick(struct kvm_vcpu *vcpu)
{
- int me;
- int cpu = vcpu->cpu;
-
if (waitqueue_active(&vcpu->wq)) {
wake_up_interruptible(&vcpu->wq);
++vcpu->stat.halt_wakeup;
}
+ kvm_vcpu_ipi(vcpu);
+}
+
+void kvm_vcpu_ipi(struct kvm_vcpu *vcpu)
+{
+ int me;
+ int cpu = vcpu->cpu;
me = get_cpu();
- if (cpu != me && (unsigned)cpu < nr_cpu_ids && cpu_online(cpu))
- if (!test_and_set_bit(KVM_REQ_KICK, &vcpu->requests))
- smp_send_reschedule(cpu);
+ if (cpu != me && (unsigned)cpu < nr_cpu_ids && cpu_online(cpu)) {
+ if (test_bit(KVM_VCPU_GUEST_MODE, &vcpu->vcpu_state)) {
+ if (!test_and_set_bit(KVM_VCPU_KICKED,
+ &vcpu->vcpu_state))
+ smp_send_reschedule(cpu);
+ }
+ }
put_cpu();
}
@@ -168,6 +176,30 @@ static bool make_all_cpus_request(struct
return called;
}
+static int kvm_req_wait(void *unused)
+{
+ cpu_relax();
+ return 0;
+}
+
+static void kvm_vcpu_request(struct kvm_vcpu *vcpu, unsigned int req)
+{
+ set_bit(req, &vcpu->requests);
+ barrier();
+ kvm_vcpu_ipi(vcpu);
+ wait_on_bit(&vcpu->vcpu_state, KVM_VCPU_GUEST_MODE, kvm_req_wait,
+ TASK_UNINTERRUPTIBLE);
+}
+
+static void kvm_vcpus_request(struct kvm *kvm, unsigned int req)
+{
+ int i;
+ struct kvm_vcpu *vcpu;
+
+ kvm_for_each_vcpu(i, vcpu, kvm)
+ kvm_vcpu_request(vcpu, req);
+}
+
void kvm_flush_remote_tlbs(struct kvm *kvm)
{
if (make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
Index: kvm/arch/ia64/kvm/kvm-ia64.c
===================================================================
--- kvm.orig/arch/ia64/kvm/kvm-ia64.c
+++ kvm/arch/ia64/kvm/kvm-ia64.c
@@ -655,12 +655,13 @@ again:
host_ctx = kvm_get_host_context(vcpu);
guest_ctx = kvm_get_guest_context(vcpu);
- clear_bit(KVM_REQ_KICK, &vcpu->requests);
-
r = kvm_vcpu_pre_transition(vcpu);
if (r < 0)
goto vcpu_run_fail;
+ set_bit(KVM_VCPU_GUEST_MODE, &vcpu->vcpu_state);
+ barrier();
+
up_read(&vcpu->kvm->slots_lock);
kvm_guest_enter();
@@ -672,7 +673,10 @@ again:
kvm_vcpu_post_transition(vcpu);
vcpu->arch.launched = 1;
- set_bit(KVM_REQ_KICK, &vcpu->requests);
+ clear_bit(KVM_VCPU_KICKED, &vcpu->vcpu_state);
+ clear_bit(KVM_VCPU_GUEST_MODE, &vcpu->vcpu_state);
+ smp_mb__after_clear_bit();
+ wake_up_bit(&vcpu->vcpu_state, KVM_VCPU_GUEST_MODE);
local_irq_enable();
/*
--
next prev parent reply other threads:[~2009-08-27 1:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-27 1:20 [patch 0/5] unify remote request and kvm_vcpu_kick IPI mechanism Marcelo Tosatti
2009-08-27 1:20 ` [patch 1/5] KVM: move kvm_vcpu_kick to virt/kvm/kvm_main.c Marcelo Tosatti
2009-08-27 1:20 ` Marcelo Tosatti [this message]
2009-08-27 8:15 ` [patch 2/5] KVM: reintroduce guest mode bit and unify remote request code Avi Kivity
2009-08-27 12:45 ` Marcelo Tosatti
2009-08-27 13:24 ` Avi Kivity
2009-08-27 14:07 ` Marcelo Tosatti
2009-08-28 7:06 ` Avi Kivity
2009-08-28 7:22 ` Avi Kivity
2009-08-27 8:25 ` Avi Kivity
2009-08-27 12:58 ` Marcelo Tosatti
2009-08-27 1:20 ` [patch 3/5] KVM: switch REQ_TLB_FLUSH/REQ_MMU_RELOAD to kvm_vcpus_request Marcelo Tosatti
2009-08-27 1:20 ` [patch 4/5] KVM: remove make_all_cpus_request Marcelo Tosatti
2009-08-27 1:20 ` [patch 5/5] KVM: x86: drop duplicat kvm_flush_remote_tlbs Marcelo Tosatti
2009-08-27 15:54 ` [RFC] KVM: x86: conditionally acquire/release slots_lock on entry/exit Marcelo Tosatti
2009-08-27 16:27 ` Avi Kivity
2009-08-27 22:59 ` Marcelo Tosatti
2009-08-28 6:50 ` Avi Kivity
2009-09-10 22:30 ` Marcelo Tosatti
2009-09-13 15:42 ` Avi Kivity
2009-09-13 16:26 ` Paul E. McKenney
2009-09-13 22:49 ` Marcelo Tosatti
2009-09-14 5:03 ` Avi Kivity
2009-09-14 7:17 ` 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=20090827012955.208915957@localhost.localdomain \
--to=mtosatti@redhat.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