Skip to contentSkip to conversation

cpu: skip unpluged cpu when querying cpus

PATCH In review linzhecheng 3 participants 3 messages Apr 11, 2018 – Apr 13, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu: skip unpluged cpu when querying cpus

From: XuYandong <[email protected]>

After vcpu1 thread exiting, vcpu0 thread (received notification) is still waiting for holding qemu_global_mutex in cpu_remove_sync, at this moment, vcpu1 is still in global cpus list. If main thread grab qemu_global_mutex in order to handle qmp command "info cpus", qmp_query_cpus visit unpluged vcpu1 will lead qemu process to exit.

---
 cpus.c | 5 +++++
 1 file changed, 5 insertions(+)
cpus.c +5 -0
index 2cb0af9..9b3a6c4 100644
@@ -2018,6 +2018,11 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 
     CPU_FOREACH(cpu) {
         CpuInfoList *info;
+
+        if (cpu->unplug) {
+            continue;
+        }
+
 #if defined(TARGET_I386)
         X86CPU *x86_cpu = X86_CPU(cpu);
         CPUX86State *env = &x86_cpu->env;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · On Wed, 11 Apr 2018 19:16:02 +0800 linzhecheng <[email protected]> wrote:

From: XuYandong <[email protected]>

After vcpu1 thread exiting, vcpu0 thread (received notification) is still waiting for holding qemu_global_mutex in cpu_remove_sync, at this moment, vcpu1 is still in global cpus list. If main thread grab qemu_global_mutex in order to handle qmp command "info cpus", qmp_query_cpus visit unpluged vcpu1 will lead qemu process to exit.

Add here exact error or better stack trace in case it crashes.

Quoted 10 lines
---
 cpus.c | 5 +++++
 1 file changed, 5 insertions(+)
cpus.c +0 -0
index 2cb0af9..9b3a6c4 100644

cpus.c CpuInfoList *qmp_query_cpus(Error **errp) · line 2024

Quoted 7 lines
cpus.c +4 -0
@@ -2018,6 +2018,11 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 
     CPU_FOREACH(cpu) {
         CpuInfoList *info;
+
+        if (cpu->unplug) {
+            continue;
+        }

Shouldn't be it done for qmp_query_cpus_fast() as well?

Quoted 4 lines
cpus.c +1 -0
+
 #if defined(TARGET_I386)
         X86CPU *x86_cpu = X86_CPU(cpu);
         CPUX86State *env = &x86_cpu->env;
#2 lore raw

Yes, we should add it at qmp_query_cpus_fast() .
In this case, qmp_query_cpus() may kick a vcpu thread that has stopped causing the qemu process to exit, qmp_query_cpus_fast() does not interrupt vCPU threads, but may return invalid vCPU information.

Quoted 47 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Wednesday, April 11, 2018 7:46 PM
To: linzhecheng <[email protected]>
Cc: [email protected]; xuyandong <[email protected]>; [email protected]; wangxin (U) <[email protected]>; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH] cpu: skip unpluged cpu when querying cpus

Quoted 4 lines · On Wed, 11 Apr 2018 19:16:02 +0800 linzhecheng <[email protected]> wrote:

From: XuYandong <[email protected]>

After vcpu1 thread exiting, vcpu0 thread (received notification) is still waiting for holding qemu_global_mutex in cpu_remove_sync, at this

moment, vcpu1 is still in global cpus list.

Quoted 2 lines

If main thread grab qemu_global_mutex in order to handle qmp command "info cpus", qmp_query_cpus visit unpluged vcpu1 will lead qemu process

to exit.
Add here exact error or better stack trace in case it crashes.

Quoted 10 lines
---
 cpus.c | 5 +++++
 1 file changed, 5 insertions(+)
cpus.c +0 -0
index 2cb0af9..9b3a6c4 100644

cpus.c CpuInfoList *qmp_query_cpus(Error **errp) · line 2024

Quoted 7 lines
cpus.c +4 -0
@@ -2018,6 +2018,11 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 
     CPU_FOREACH(cpu) {
         CpuInfoList *info;
+
+        if (cpu->unplug) {
+            continue;
+        }

Shouldn't be it done for qmp_query_cpus_fast() as well?

Quoted 4 lines
cpus.c +1 -0
+
 #if defined(TARGET_I386)
         X86CPU *x86_cpu = X86_CPU(cpu);
         CPUX86State *env = &x86_cpu->env;