Skip to contentSkip to conversation

env->kvm_cpu_state.init is always zero here.

PATCH In review Gleb Natapov 2 participants 14 messages Jun 14, 2009 – Jun 15, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 env->kvm_cpu_state.init is always zero here.

---
 qemu-kvm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
qemu-kvm.c +1 -1
index 2aeb17c..ec911ef 100644
@@ -412,7 +412,7 @@ static int kvm_main_loop_cpu(CPUState *env)
 	    if (env->kvm_cpu_state.sipi_needed)
 	        update_regs_for_sipi(env);
     }
-	if (!env->halted && !env->kvm_cpu_state.init)
+	if (!env->halted)
 	    kvm_cpu_exec(env);
 	env->exit_request = 0;
         env->exception_index = EXCP_INTERRUPT;
Signature · 1 line
1.6.2.1
#1 lore raw

PATCH 2/6 Do not use env->halted to decide where halted state should be handled.

Use kvm_irqchip_in_kernel() for that. If irq chip is not handled by userspace kernel should be entered even when CPU is halted.

---
 hw/apic.c  |    3 +--
 qemu-kvm.c |    6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)
hw/apic.c +1 -2
index c5d97b2..f186202 100644
@@ -467,8 +467,7 @@ static void apic_init_ipi(APICState *s)
 
     cpu_reset(s->cpu_env);
 
-    if (!(s->apicbase & MSR_IA32_APICBASE_BSP) &&
-        (!kvm_enabled() || !qemu_kvm_irqchip_in_kernel()))
+    if (!(s->apicbase & MSR_IA32_APICBASE_BSP))
         s->cpu_env->halted = 1;
 
     if (kvm_enabled() && !qemu_kvm_irqchip_in_kernel())
qemu-kvm.c +3 -3
index ec911ef..7676e02 100644
@@ -217,6 +217,8 @@ static int has_work(CPUState *env)
 {
     if (!vm_running || (env && env->kvm_cpu_state.stopped))
 	return 0;
+    if (kvm_irqchip_in_kernel(kvm_context))
+        return 1;
     if (!env->halted)
 	return 1;
     return kvm_arch_has_work(env);
@@ -390,8 +392,6 @@ static int kvm_main_loop_cpu(CPUState *env)
     setup_kernel_sigmask(env);
 
     pthread_mutex_lock(&qemu_mutex);
-    if (kvm_irqchip_in_kernel(kvm_context))
-	env->halted = 0;
 
     kvm_qemu_init_env(env);
 #ifdef TARGET_I386
@@ -412,7 +412,7 @@ static int kvm_main_loop_cpu(CPUState *env)
 	    if (env->kvm_cpu_state.sipi_needed)
 	        update_regs_for_sipi(env);
     }
-	if (!env->halted)
+	if (!env->halted || kvm_irqchip_in_kernel(kvm_context))
 	    kvm_cpu_exec(env);
 	env->exit_request = 0;
         env->exception_index = EXCP_INTERRUPT;
Signature · 1 line
1.6.2.1
#2 lore raw

PATCH 3/6 Call kvm_arch_load_regs() instead of kvm_load_registers()

In reply to Gleb Natapov

The call is done from vcpu thread.

---
 qemu-kvm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
qemu-kvm.c +1 -1
index 7676e02..5fa7154 100644
@@ -399,7 +399,7 @@ static int kvm_main_loop_cpu(CPUState *env)
 #endif
 
     cpu_single_env = env;
-    kvm_load_registers(env);
+    kvm_arch_load_regs(env);
 
     while (1) {
 	while (!has_work(env))
Signature · 1 line
1.6.2.1
#3 lore raw

PATCH 4/6 Handle vcpu init/sipi by calling a function on vcpu

In reply to Gleb Natapov

Instead of having special case in vcpu event loop.

---
 cpu-defs.h |    2 --
 qemu-kvm.c |   51 +++++++++++++++++----------------------------------
 2 files changed, 17 insertions(+), 36 deletions(-)
cpu-defs.h +0 -2
index e17209a..7570096 100644
@@ -140,8 +140,6 @@ typedef struct CPUWatchpoint {
 struct qemu_work_item;
 
 struct KVMCPUState {
-    int sipi_needed;
-    int init;
     pthread_t thread;
     int signalled;
     int stop;
qemu-kvm.c +17 -34

78 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#9 lore raw

PATCH 5/6 Rename kvm_(load|save)_mpstate to kvm_arch_(load|save)_mpstate

In reply to Gleb Natapov

To be consistent with other function naming.

---
 qemu-kvm-ia64.c       |    4 ++--
 qemu-kvm-x86.c        |    4 ++--
 qemu-kvm.h            |    2 ++
 target-i386/machine.c |    6 +++---
 target-ia64/machine.c |    4 ++--
 5 files changed, 11 insertions(+), 9 deletions(-)
qemu-kvm-ia64.c +2 -2
index d33c1c3..234602c 100644
@@ -98,7 +98,7 @@ void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg)
 {
 }
 
-void kvm_save_mpstate(CPUState *env)
+void kvm_arch_save_mpstate(CPUState *env)
 {
 #ifdef KVM_CAP_MP_STATE
     int r;
@@ -112,7 +112,7 @@ void kvm_save_mpstate(CPUState *env)
 #endif
 }
 
-void kvm_load_mpstate(CPUState *env)
+void kvm_arch_load_mpstate(CPUState *env)
 {
 #ifdef KVM_CAP_MP_STATE
     struct kvm_mp_state mp_state = { .mp_state = env->mp_state };
qemu-kvm-x86.c +2 -2
index 729d600..8e6fb75 100644
@@ -295,7 +295,7 @@ void kvm_load_tsc(CPUState *env)
         perror("kvm_set_tsc FAILED.\n");
 }
 
-void kvm_save_mpstate(CPUState *env)
+void kvm_arch_save_mpstate(CPUState *env)
 {
 #ifdef KVM_CAP_MP_STATE
     int r;
@@ -309,7 +309,7 @@ void kvm_save_mpstate(CPUState *env)
 #endif
 }
 
-void kvm_load_mpstate(CPUState *env)
+void kvm_arch_load_mpstate(CPUState *env)
 {
 #ifdef KVM_CAP_MP_STATE
     struct kvm_mp_state mp_state = { .mp_state = env->mp_state };
qemu-kvm.h +2 -0
index fa40542..3b73fe9 100644
@@ -69,6 +69,8 @@ int kvm_arch_qemu_create_context(void);
 
 void kvm_arch_save_regs(CPUState *env);
 void kvm_arch_load_regs(CPUState *env);
+void kvm_arch_load_mpstate(CPUState *env);
+void kvm_arch_save_mpstate(CPUState *env);
 int kvm_arch_qemu_init_env(CPUState *cenv);
 void kvm_arch_pre_kvm_run(void *opaque, CPUState *env);
 void kvm_arch_post_kvm_run(void *opaque, CPUState *env);
target-i386/machine.c +3 -3
index 07df1e1..14942c0 100644
@@ -34,7 +34,7 @@ void cpu_save(QEMUFile *f, void *opaque)
 
     if (kvm_enabled()) {
         kvm_save_registers(env);
-        kvm_save_mpstate(env);
+        kvm_arch_save_mpstate(env);
     }
 
     for(i = 0; i < CPU_NB_REGS; i++)
@@ -369,12 +369,12 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
             kvm_load_tsc(env);
             if (version_id >= 5) {
                 qemu_get_be32s(f, &env->mp_state);
-                kvm_load_mpstate(env);
+                kvm_arch_load_mpstate(env);
             }
         } else {
             kvm_load_registers(env);
             kvm_load_tsc(env);
-            kvm_load_mpstate(env);
+            kvm_arch_load_mpstate(env);
         }
     }
     return 0;
target-ia64/machine.c +2 -2
index dd205c5..70ef379 100644
@@ -10,7 +10,7 @@ void cpu_save(QEMUFile *f, void *opaque)
 
     if (kvm_enabled()) {
         kvm_save_registers(env);
-        kvm_save_mpstate(env);
+        kvm_arch_save_mpstate(env);
     }
 }
 
@@ -20,7 +20,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
 
     if (kvm_enabled()) {
         kvm_load_registers(env);
-        kvm_load_mpstate(env);
+        kvm_arch_load_mpstate(env);
     }
     return 0;
 }
Signature · 1 line
1.6.2.1
#10 lore raw

PATCH 6/6 Retrieve mp state info in cpu_synchronize_state()

In reply to Gleb Natapov

And set env->halted based on the value to show accurate vcpu state in QEMU monitor.

---
 qemu-kvm.c |   27 +++++++++++++++++++++++++++
 qemu-kvm.h |    2 ++
 2 files changed, 29 insertions(+), 0 deletions(-)
qemu-kvm.c +27 -0
index af3fd91..41dcdc3 100644
@@ -187,6 +187,33 @@ void kvm_save_registers(CPUState *env)
         on_vcpu(env, kvm_do_save_registers, env);
 }
 
+static void kvm_do_load_mpstate(void *_env)
+{
+    CPUState *env = _env;
+
+    kvm_arch_load_mpstate(env);
+}
+
+void kvm_load_mpstate(CPUState *env)
+{
+    if (kvm_enabled() && qemu_system_ready)
+        on_vcpu(env, kvm_do_load_mpstate, env);
+}
+
+static void kvm_do_save_mpstate(void *_env)
+{
+    CPUState *env = _env;
+
+    kvm_arch_save_mpstate(env);
+    env->halted = (env->mp_state == KVM_MP_STATE_HALTED);
+}
+
+void kvm_save_mpstate(CPUState *env)
+{
+    if (kvm_enabled())
+        on_vcpu(env, kvm_do_save_mpstate, env);
+}
+
 int kvm_cpu_exec(CPUState *env)
 {
     int r;
qemu-kvm.h +2 -0
index 3b73fe9..22452e9 100644
@@ -221,11 +221,13 @@ static inline int kvm_sync_vcpus(void) { return 0; }
 static inline void kvm_arch_get_registers(CPUState *env)
 {
     kvm_save_registers(env);
+    kvm_save_mpstate(env);
 }
 
 static inline void kvm_arch_put_registers(CPUState *env)
 {
     kvm_load_registers(env);
+    kvm_load_mpstate(env);
 }
 
 static inline void cpu_synchronize_state(CPUState *env, int modified)
Signature · 1 line
1.6.2.1
#11 lore raw
In reply to Gleb Natapov
Quoted 11 lines · Gleb Natapov
---
  qemu-kvm.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
qemu-kvm.c +0 -0
index 2aeb17c..ec911ef 100644

qemu-kvm.c static int kvm_main_loop_cpu(CPUState *env) · line 418

Quoted 8 lines
qemu-kvm.c +1 -1
@@ -412,7 +412,7 @@ static int kvm_main_loop_cpu(CPUState *env)
  	    if (env->kvm_cpu_state.sipi_needed)
  	        update_regs_for_sipi(env);
      }
-	if (!env->halted&&  !env->kvm_cpu_state.init)
+	if (!env->halted)
  	    kvm_cpu_exec(env);
  	env->exit_request = 0;
          env->exception_index = EXCP_INTERRUPT;

Are you sure? Can't a reset reenable it?

Signature · 1 line
error compiling committee.c: too many arguments to function
#12 lore raw
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Gleb Natapov
---
  qemu-kvm.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 17 lines
Quoted 6 lines
qemu-kvm.c +0 -0
index 2aeb17c..ec911ef 100644

qemu-kvm.c static int kvm_main_loop_cpu(CPUState *env) · line 418

Quoted 8 lines
qemu-kvm.c +1 -1
@@ -412,7 +412,7 @@ static int kvm_main_loop_cpu(CPUState *env)
  	    if (env->kvm_cpu_state.sipi_needed)
  	        update_regs_for_sipi(env);
      }
-	if (!env->halted&&  !env->kvm_cpu_state.init)
+	if (!env->halted)
  	    kvm_cpu_exec(env);
  	env->exit_request = 0;
          env->exception_index = EXCP_INTERRUPT;

Are you sure? Can't a reset reenable it?

The thing is used only with userspace irq chip. If env->kvm_cpu_state.init == 1 update_regs_for_init() is called three line above and it will set kvm_cpu_state.init to zero.

--
Gleb.

#4 lore raw

Re: [PATCH 4/6] Handle vcpu init/sipi by calling a function on vcpu

In reply to Gleb Natapov
Quoted 3 lines · Gleb Natapov

Instead of having special case in vcpu event loop.

I'm a little worried about two vcpus INITing each other simultaneously and deadlocking. INIT/SIPI are async events, the initiator should not wait for them.

Signature · 1 line
error compiling committee.c: too many arguments to function
#13 lore raw
In reply to Gleb Natapov
Quoted 27 lines · Gleb Natapov
Quoted 7 lines · Avi Kivity
Quoted 5 lines · Gleb Natapov
---
   qemu-kvm.c |    2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 18 lines
Quoted 7 lines
qemu-kvm.c +0 -0
index 2aeb17c..ec911ef 100644

qemu-kvm.c static int kvm_main_loop_cpu(CPUState *env) · line 418

Quoted 8 lines
qemu-kvm.c +1 -1
@@ -412,7 +412,7 @@ static int kvm_main_loop_cpu(CPUState *env)
   	    if (env->kvm_cpu_state.sipi_needed)
   	        update_regs_for_sipi(env);
       }
-	if (!env->halted&&   !env->kvm_cpu_state.init)
+	if (!env->halted)
   	    kvm_cpu_exec(env);
   	env->exit_request = 0;
           env->exception_index = EXCP_INTERRUPT;

Are you sure? Can't a reset reenable it?

Quoted 4 lines

The thing is used only with userspace irq chip. If env->kvm_cpu_state.init == 1 update_regs_for_init() is called three line above and it will set kvm_cpu_state.init to zero.

Right, and nothing can sleep in between.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw

Re: [PATCH 4/6] Handle vcpu init/sipi by calling a function on vcpu

In reply to Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 3 lines · Gleb Natapov

Instead of having special case in vcpu event loop.

I'm a little worried about two vcpus INITing each other simultaneously and deadlocking. INIT/SIPI are async events, the initiator should not wait for them.

I thought to add on_vcpu_async() for that (if this case is worth warring about).

--
Gleb.

#6 lore raw

Re: [PATCH 4/6] Handle vcpu init/sipi by calling a function on vcpu

Quoted 8 lines · Gleb Natapov
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Gleb Natapov

Instead of having special case in vcpu event loop.

Quoted 7 lines
Quoted 5 lines

I'm a little worried about two vcpus INITing each other simultaneously and deadlocking. INIT/SIPI are async events, the initiator should not wait for them.

I thought to add on_vcpu_async() for that (if this case is worth warring about).

A generic on_vcpu_async() would need to allocate, that might be expoitable.

Signature · 1 line
error compiling committee.c: too many arguments to function
#7 lore raw

Re: [PATCH 4/6] Handle vcpu init/sipi by calling a function on vcpu

Quoted 14 lines · Avi Kivity
Quoted 13 lines · Gleb Natapov
Quoted 11 lines · Avi Kivity
Quoted 4 lines · Gleb Natapov

Instead of having special case in vcpu event loop.

I'm a little worried about two vcpus INITing each other simultaneously and deadlocking. INIT/SIPI are async events, the initiator should not wait for them.

Quoted 5 lines
Quoted 2 lines

I thought to add on_vcpu_async() for that (if this case is worth warring about).

A generic on_vcpu_async() would need to allocate, that might be expoitable.

Then what about processing events while waiting in on_vcpu()?

--
Gleb.

#8 lore raw

Re: [PATCH 4/6] Handle vcpu init/sipi by calling a function on vcpu

Quoted 6 lines · Gleb Natapov
Quoted 3 lines

A generic on_vcpu_async() would need to allocate, that might be expoitable.

Then what about processing events while waiting in on_vcpu()?

Could work, but prefer a simpler solution.

Signature · 1 line
error compiling committee.c: too many arguments to function