monitor: fix crash for platforms without a CPU 0
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.
--- 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
@@ -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
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.
Signed-off-by Cédric Le Goater <[email protected]>[dwg: Rewrote commit message to better explain background]Signed-off-by David Gibson <[email protected]>
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@@ -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;
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.
Signed-off-by Cédric Le Goater <[email protected]>[dwg: Rewrote commit message to better explain background]Signed-off-by David Gibson <[email protected]>--- 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
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
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.
Signed-off-by Cédric Le Goater <[email protected]>[dwg: Rewrote commit message to better explain background]Signed-off-by David Gibson <[email protected]>
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@@ -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;
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.
Signed-off-by Cédric Le Goater <[email protected]>[dwg: Rewrote commit message to better explain background]Signed-off-by David Gibson <[email protected]>--- 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@@ -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_cpuis 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_cpuassumption already exists elsewhere and those cases can be found easily using grep, I think this is OK. So:Reviewed-by Eduardo Habkost <[email protected]>BTW, it is also possible to crash QEMU by unplugging the current monitor CPU;
Ah... good point.
Quoted 7 lines
(qemu)
device_addqemu64-x86_64-cpu,socket-id=2,core-id=0,thread-id=0,id=mycpu (qemu) cpu 2
(qemu)device_delmycpu
(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
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.
Signed-off-by Cédric Le Goater <[email protected]>[dwg: Rewrote commit message to better explain background]Signed-off-by David Gibson <[email protected]>--- 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
Reviewed-by Luiz Capitulino <[email protected]>Quoted 14 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); }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