monitor: fix dangling CPU pointer
commit751f8cfe2a556b3ef49f6af2860e2d1d2a1ec66a
authorGreg Kurz <groug@kaod.org>
Tue, 17 Oct 2017 08:16:22 +0000 (17 10:16 +0200)
committerDr. David Alan Gilbert <dgilbert@redhat.com>
Mon, 30 Oct 2017 18:46:32 +0000 (30 18:46 +0000)
treefbfed86d4775e071c97f9f43f605af9ea7686191
parent554a39eb3268ef927ccd19ea642b886f0acf8ec2
monitor: fix dangling CPU pointer

If a CPU selected with the "cpu" command is hot-unplugged then "info cpus"
causes QEMU to exit:

(qemu) device_del cpu1
(qemu) info cpus
qemu:qemu_cpu_kick_thread: No such process

This happens because "cpu" stores the pointer to the selected CPU into
the monitor structure. When the CPU is hot-unplugged, we end up with a
dangling pointer. The "info cpus" command then does:

hmp_info_cpus()
 monitor_get_cpu_index()
  mon_get_cpu()
   cpu_synchronize_state() <--- called with dangling pointer

This could cause a QEMU crash as well.

This patch switches the monitor to store the QOM path instead of a
pointer to the current CPU. The path is then resolved when needed.
If the resolution fails, we assume that the CPU was removed and the
path is resetted to the default (ie, path of first_cpu).

Reported-by: Satheesh Rajendran <sathnaga@linux.vnet.ibm.com>
Suggested-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <150822818243.26242.12993827911736928961.stgit@bahia.lan>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
monitor.c