Skip to contentSkip to conversation

Allow to call vm_stop from vcpu thread

PATCH Applied Gleb Natapov 3 participants 5 messages Jan 15, 2009 – Feb 5, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow to call vm_stop from vcpu thread

qemu/qemu-kvm.c +8 -4
index e4fba78..484a232 100644
@@ -296,11 +296,15 @@ static void pause_all_threads(void)
 {
     CPUState *penv = first_cpu;
 
-    assert(!cpu_single_env);
-
     while (penv) {
-        penv->kvm_cpu_state.stop = 1;
-        pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI);
+        if (penv != cpu_single_env) {
+            penv->kvm_cpu_state.stop = 1;
+            pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI);
+        } else {
+            penv->kvm_cpu_state.stop = 0;
+            penv->kvm_cpu_state.stopped = 1;
+            cpu_interrupt(penv, CPU_INTERRUPT_EXIT);
+        }
         penv = (CPUState *)penv->next_cpu;
     }
 

--
Gleb.

#1 lore raw
Quoted 14 lines · Gleb Natapov
qemu/qemu-kvm.c +0 -4
index e4fba78..484a232 100644
@@ -296,11 +296,15 @@ static void pause_all_threads(void)
 {
     CPUState *penv = first_cpu;
 
-    assert(!cpu_single_env);
-
     while (penv) {
-        penv->kvm_cpu_state.stop = 1;
-        pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI);

qemu/qemu-kvm.c static void pause_all_threads(void) · line 309

Quoted 10 lines
qemu/qemu-kvm.c +8 -0
+        if (penv != cpu_single_env) {
+            penv->kvm_cpu_state.stop = 1;
+            pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI);
+        } else {
+            penv->kvm_cpu_state.stop = 0;
+            penv->kvm_cpu_state.stopped = 1;
+            cpu_interrupt(penv, CPU_INTERRUPT_EXIT);
+        }
         penv = (CPUState *)penv->next_cpu;
     }

Who do you have in mind to use this? At least the debugging infrastructure could do so, but I do not recall ATM if there were limitations that the above change may not overcome. Maybe you could test your patch by changing (probably simplifying) the path from a breakpoint hit to vm_stop.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26
Corporate Competence Center Embedded Linux
#2 lore raw
Quoted 19 lines · Jan Kiszka
Quoted 18 lines · Gleb Natapov
qemu/qemu-kvm.c +4 -4
index e4fba78..484a232 100644
@@ -296,11 +296,15 @@ static void pause_all_threads(void)
 {
     CPUState *penv = first_cpu;
 
-    assert(!cpu_single_env);
-
     while (penv) {
-        penv->kvm_cpu_state.stop = 1;
-        pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI);
+        if (penv != cpu_single_env) {
+            penv->kvm_cpu_state.stop = 1;
+            pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI);
+        } else {
Quoted 8 lines

qemu/qemu-kvm.c static void pause_all_threads(void) · line 309

Quoted 6 lines
qemu/qemu-kvm.c +4 -0
+            penv->kvm_cpu_state.stop = 0;
+            penv->kvm_cpu_state.stopped = 1;
+            cpu_interrupt(penv, CPU_INTERRUPT_EXIT);
+        }
         penv = (CPUState *)penv->next_cpu;
     }

Who do you have in mind to use this? At least the debugging

I need this for ENOSPC patches. When IDE is in PIO mode KVM do synchronous writes from vcpu context. We have to be able to call vm_stop() if synchronous write returns ENOSPC.

Quoted 5 lines

infrastructure could do so, but I do not recall ATM if there were limitations that the above change may not overcome. Maybe you could test your patch by changing (probably simplifying) the path from a breakpoint hit to vm_stop.

I am testing it with my ENOSPC patches and 2 cpus and don't see any ill effects yet.

--
Gleb.

#3 lore raw
Quoted 31 lines · Gleb Natapov
Quoted 10 lines · Jan Kiszka
Quoted 9 lines · Gleb Natapov
qemu/qemu-kvm.c +0 -0
index e4fba78..484a232 100644
@@ -296,11 +296,15 @@ static void pause_all_threads(void)
 {
     CPUState *penv = first_cpu;
 
Quoted 16 lines
Quoted 5 lines
qemu/qemu-kvm.c +0 -4
-    assert(!cpu_single_env);
-
     while (penv) {
-        penv->kvm_cpu_state.stop = 1;
-        pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI);

qemu/qemu-kvm.c static void pause_all_threads(void) · line 309

Quoted 10 lines
qemu/qemu-kvm.c +8 -0
+        if (penv != cpu_single_env) {
+            penv->kvm_cpu_state.stop = 1;
+            pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI);
+        } else {
+            penv->kvm_cpu_state.stop = 0;
+            penv->kvm_cpu_state.stopped = 1;
+            cpu_interrupt(penv, CPU_INTERRUPT_EXIT);
+        }
         penv = (CPUState *)penv->next_cpu;
     }

Who do you have in mind to use this? At least the debugging

I need this for ENOSPC patches. When IDE is in PIO mode KVM do synchronous writes from vcpu context. We have to be able to call vm_stop() if synchronous write returns ENOSPC.

Quoted 7 lines
Quoted 5 lines

infrastructure could do so, but I do not recall ATM if there were limitations that the above change may not overcome. Maybe you could test your patch by changing (probably simplifying) the path from a breakpoint hit to vm_stop.

I am testing it with my ENOSPC patches and 2 cpus and don't see any ill effects yet.

Great! When done, a supplementary patch to overcome kvm_debug_cpu_requested would be welcome, too. :)

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26
Corporate Competence Center Embedded Linux