Skip to contentSkip to conversation

monitor: fix crash for platforms without a CPU 0

PATCH In review David Gibson 4 participants 6 messages Sep 21, 2016 – Sep 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 monitor: fix crash for platforms without a CPU 0

Now that we allow CPU hot unplug on a few platforms, we can end up in a situation where we don't have a CPU with index 0. Or at least we could, if we didn't have code to explicitly prohibit unplug of CPU 0.

Longer term we want to allow CPU 0 unplug, this patch is an early step in allowing this, by removing an assumption in the monitor code that CPU 0 always exists.

[dwg: Rewrote commit message to better explain background]
---
 monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Anyone want to volunteer to take this through their tree? If not, I can take it through my ppc tree.

monitor.c +1 -1
index 8bb8bbf..83c4edf 100644
@@ -1025,7 +1025,7 @@ int monitor_set_cpu(int cpu_index)
 CPUState *mon_get_cpu(void)
 {
     if (!cur_mon->mon_cpu) {
-        monitor_set_cpu(0);
+        monitor_set_cpu(first_cpu->cpu_index);
     }
     cpu_synchronize_state(cur_mon->mon_cpu);
     return cur_mon->mon_cpu;
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · On Wed, 21 Sep 2016 15:29:26 +1000 David Gibson <[email protected]>…

Now that we allow CPU hot unplug on a few platforms, we can end up in a situation where we don't have a CPU with index 0. Or at least we could, if we didn't have code to explicitly prohibit unplug of CPU 0.

Longer term we want to allow CPU 0 unplug, this patch is an early step in allowing this, by removing an assumption in the monitor code that CPU 0 always exists.

[dwg: Rewrote commit message to better explain background]
Quoted 20 lines
---
 monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Anyone want to volunteer to take this through their tree? If not, I can take it through my ppc tree.

monitor.c +1 -1
index 8bb8bbf..83c4edf 100644
@@ -1025,7 +1025,7 @@ int monitor_set_cpu(int cpu_index)
 CPUState *mon_get_cpu(void)
 {
     if (!cur_mon->mon_cpu) {
-        monitor_set_cpu(0);
+        monitor_set_cpu(first_cpu->cpu_index);
     }
     cpu_synchronize_state(cur_mon->mon_cpu);
     return cur_mon->mon_cpu;
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Gibson
Quoted 23 lines · David Gibson

Now that we allow CPU hot unplug on a few platforms, we can end up in a situation where we don't have a CPU with index 0. Or at least we could, if we didn't have code to explicitly prohibit unplug of CPU 0.

Longer term we want to allow CPU 0 unplug, this patch is an early step in allowing this, by removing an assumption in the monitor code that CPU 0 always exists.

[dwg: Rewrote commit message to better explain background]
---
 monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Anyone want to volunteer to take this through their tree? If not, I can take it through my ppc tree.

monitor.c +0 -0
index 8bb8bbf..83c4edf 100644

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

Quoted 5 lines
monitor.c +1 -1
@@ -1025,7 +1025,7 @@ int monitor_set_cpu(int cpu_index)
 CPUState *mon_get_cpu(void)
 {
     if (!cur_mon->mon_cpu) {
-        monitor_set_cpu(0);
+        monitor_set_cpu(first_cpu->cpu_index);

So, we are replacing the "CPU 0 always exists" assumption with a "first_cpu is always non-NULL" assumption.

But considering that the first_cpu assumption already exists elsewhere and those cases can be found easily using grep, I think this is OK. So:

BTW, it is also possible to crash QEMU by unplugging the current monitor CPU;

(qemu) device_add qemu64-x86_64-cpu,socket-id=2,core-id=0,thread-id=0,id=mycpu (qemu) cpu 2
(qemu) device_del mycpu
(qemu) info registers
qemu:qemu_cpu_kick_thread: No such process
$

Signature · 1 line
Eduardo
#3 lore raw
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · David Gibson

Now that we allow CPU hot unplug on a few platforms, we can end up in a situation where we don't have a CPU with index 0. Or at least we could, if we didn't have code to explicitly prohibit unplug of CPU 0.

Longer term we want to allow CPU 0 unplug, this patch is an early step in allowing this, by removing an assumption in the monitor code that CPU 0 always exists.

[dwg: Rewrote commit message to better explain background]
---
 monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Anyone want to volunteer to take this through their tree? If not, I can take it through my ppc tree.

Quoted 13 lines

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

Quoted 10 lines
monitor.c +1 -1
index 8bb8bbf..83c4edf 100644
@@ -1025,7 +1025,7 @@ int monitor_set_cpu(int cpu_index)
 CPUState *mon_get_cpu(void)
 {
     if (!cur_mon->mon_cpu) {
-        monitor_set_cpu(0);
+        monitor_set_cpu(first_cpu->cpu_index);

So, we are replacing the "CPU 0 always exists" assumption with a "first_cpu is always non-NULL" assumption.

Well, we're replacing "CPU 0 is always present" assumption with "At least one CPU is always present", which is a strictly weaker constraint.

Quoted 8 lines

But considering that the first_cpu assumption already exists elsewhere and those cases can be found easily using grep, I think this is OK. So:

BTW, it is also possible to crash QEMU by unplugging the current monitor CPU;

Ah... good point.

Quoted 7 lines

(qemu) device_add qemu64-x86_64-cpu,socket-id=2,core-id=0,thread-id=0,id=mycpu (qemu) cpu 2
(qemu) device_del mycpu
(qemu) info registers
qemu:qemu_cpu_kick_thread: No such process
$

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Reviewed-by on v1 1/1
#4 lore raw
In reply to David Gibson
Quoted 11 lines · On Wed, 21 Sep 2016 15:29:26 +1000 David Gibson <[email protected]>…

Now that we allow CPU hot unplug on a few platforms, we can end up in a situation where we don't have a CPU with index 0. Or at least we could, if we didn't have code to explicitly prohibit unplug of CPU 0.

Longer term we want to allow CPU 0 unplug, this patch is an early step in allowing this, by removing an assumption in the monitor code that CPU 0 always exists.

[dwg: Rewrote commit message to better explain background]
Quoted 6 lines
---
 monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Anyone want to volunteer to take this through their tree? If not, I can take it through my ppc tree.

Please do.

Quoted 14 lines
monitor.c +1 -1
index 8bb8bbf..83c4edf 100644
@@ -1025,7 +1025,7 @@ int monitor_set_cpu(int cpu_index)
 CPUState *mon_get_cpu(void)
 {
     if (!cur_mon->mon_cpu) {
-        monitor_set_cpu(0);
+        monitor_set_cpu(first_cpu->cpu_index);
     }
     cpu_synchronize_state(cur_mon->mon_cpu);
     return cur_mon->mon_cpu;
#5 lore raw
Quoted 18 lines · Luiz Capitulino
Quoted 15 lines · On Wed, 21 Sep 2016 15:29:26 +1000 David Gibson <[email protected]>…

Now that we allow CPU hot unplug on a few platforms, we can end up in a situation where we don't have a CPU with index 0. Or at least we could, if we didn't have code to explicitly prohibit unplug of CPU 0.

Longer term we want to allow CPU 0 unplug, this patch is an early step in allowing this, by removing an assumption in the monitor code that CPU 0 always exists.

[dwg: Rewrote commit message to better explain background]
---
 monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines
Quoted 2 lines

Anyone want to volunteer to take this through their tree? If not, I can take it through my ppc tree.

Please do.

Ok, merged to ppc-for-2.8.

Quoted 18 lines
Quoted 14 lines
monitor.c +1 -1
index 8bb8bbf..83c4edf 100644
@@ -1025,7 +1025,7 @@ int monitor_set_cpu(int cpu_index)
 CPUState *mon_get_cpu(void)
 {
     if (!cur_mon->mon_cpu) {
-        monitor_set_cpu(0);
+        monitor_set_cpu(first_cpu->cpu_index);
     }
     cpu_synchronize_state(cur_mon->mon_cpu);
     return cur_mon->mon_cpu;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson