Skip to contentSkip to conversation

monitor: Don't return CPU marked for unplug as monitor CPU

PATCH In review Bharata B Rao 2 participants 2 messages Oct 16, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 monitor: Don't return CPU marked for unplug as monitor CPU

The following sequence of steps kill the QEMU:

- Hotplug a CPU
- Change the default CPU to the newly hotplugged cpu using "cpu" HMP command.
- Hot unplug the CPU
- Run "info cpus"

Fix this by not letting monitor_get_cpu() to return a CPU which is marked for unplug.

---
 monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor.c +1 -1
index fe0d1bd..8d60e57 100644
@@ -1053,7 +1053,7 @@ int monitor_set_cpu(int cpu_index)
 
 CPUState *mon_get_cpu(void)
 {
-    if (!cur_mon->mon_cpu) {
+    if (!cur_mon->mon_cpu || cur_mon->mon_cpu->unplug) {
         if (!first_cpu) {
             return NULL;
         }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 21 lines · On Mon, 16 Oct 2017 12:33:26 +0530 Bharata B Rao <[email protected]>…

The following sequence of steps kill the QEMU:

- Hotplug a CPU
- Change the default CPU to the newly hotplugged cpu using "cpu" HMP command.
- Hot unplug the CPU
- Run "info cpus"

Fix this by not letting monitor_get_cpu() to return a CPU which is marked for unplug.

---
 monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor.c +0 -0
index fe0d1bd..8d60e57 100644

monitor.c int monitor_set_cpu(int cpu_index) · line 1056

Quoted 5 lines
monitor.c +1 -1
@@ -1053,7 +1053,7 @@ int monitor_set_cpu(int cpu_index)
 
 CPUState *mon_get_cpu(void)
 {
-    if (!cur_mon->mon_cpu) {
+    if (!cur_mon->mon_cpu || cur_mon->mon_cpu->unplug) {

mon_cpu could be freed so it would cause use after free, Greg was looking into the same issue see his patch:
"PATCH] monitor: fix dangling CPU pointer"

Quoted 3 lines
monitor.c +0 -0
         if (!first_cpu) {
             return NULL;
         }