* [Qemu-devel] [PATCH] spapr: fix core unplug crash
@ 2016-07-08 13:12 Greg Kurz
2016-07-08 15:47 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2016-07-11 1:40 ` [Qemu-devel] " David Gibson
0 siblings, 2 replies; 5+ messages in thread
From: Greg Kurz @ 2016-07-08 13:12 UTC (permalink / raw)
To: David Gibson; +Cc: qemu-ppc, qemu-devel, Bharata B Rao
If the host has 8 threads/core and the guest is started with:
-smp cores=1,threads=4,maxcpus=12
It is possible to crash QEMU by doing:
(qemu) device_add host-spapr-cpu-core,core-id=16,id=foo
(qemu) device_del foo
Segmentation fault
This is caused because spapr_core_unplug() assumes cpu_dt_id == core_id.
Even if it happens to be the case when the host and guest have the same
number of threads per core, it is conceptually wrong and we may pass a
bogus id to spapr_dr_connector_by_id() and spapr_core_release() crashes.
Let's use cc->core_id, which is the id that was used to create th DR
connector.
Signed-off-by: Greg Kurz <groug@kaod.org>
---
hw/ppc/spapr_cpu_core.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 70b6b0b5ee17..106eaf45b399 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -126,11 +126,9 @@ static void spapr_core_release(DeviceState *dev, void *opaque)
void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
Error **errp)
{
- sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
- PowerPCCPU *cpu = POWERPC_CPU(core->threads);
- int id = ppc_get_vcpu_dt_id(cpu);
+ CPUCore *cc = CPU_CORE(dev);
sPAPRDRConnector *drc =
- spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id);
+ spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, cc->core_id);
sPAPRDRConnectorClass *drck;
Error *local_err = NULL;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr: fix core unplug crash
2016-07-08 13:12 [Qemu-devel] [PATCH] spapr: fix core unplug crash Greg Kurz
@ 2016-07-08 15:47 ` Greg Kurz
2016-07-10 14:47 ` Bharata B Rao
2016-07-11 1:42 ` David Gibson
2016-07-11 1:40 ` [Qemu-devel] " David Gibson
1 sibling, 2 replies; 5+ messages in thread
From: Greg Kurz @ 2016-07-08 15:47 UTC (permalink / raw)
To: David Gibson; +Cc: qemu-ppc, qemu-devel, Bharata B Rao
On Fri, 08 Jul 2016 15:12:07 +0200
Greg Kurz <groug@kaod.org> wrote:
> If the host has 8 threads/core and the guest is started with:
>
> -smp cores=1,threads=4,maxcpus=12
>
> It is possible to crash QEMU by doing:
>
> (qemu) device_add host-spapr-cpu-core,core-id=16,id=foo
> (qemu) device_del foo
> Segmentation fault
>
> This is caused because spapr_core_unplug() assumes cpu_dt_id == core_id.
> Even if it happens to be the case when the host and guest have the same
> number of threads per core, it is conceptually wrong and we may pass a
> bogus id to spapr_dr_connector_by_id() and spapr_core_release() crashes.
>
> Let's use cc->core_id, which is the id that was used to create th DR
> connector.
My bad, I got excited and pointed out the wrong culprit... it is cpu_index
again of course ! Please find an updated explanation to be put in the
changelog after "Segmentation fault":
========================================================================
This happens because spapr_core_unplug() assumes cpu_dt_id == core_id.
As long as cpu_dt_id is derived from the non-table cpu_index, this is
only true when you plug cores with contiguous ids.
It is safer to be consistent: the DR connector was created with an
index that is immediately written to cc->core_id, and spapr_core_plug()
also relies on cc->core_id.
Let's use it also in spapr_core_unplug().
========================================================================
>
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> hw/ppc/spapr_cpu_core.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index 70b6b0b5ee17..106eaf45b399 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -126,11 +126,9 @@ static void spapr_core_release(DeviceState *dev, void *opaque)
> void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
> Error **errp)
> {
> - sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
> - PowerPCCPU *cpu = POWERPC_CPU(core->threads);
> - int id = ppc_get_vcpu_dt_id(cpu);
> + CPUCore *cc = CPU_CORE(dev);
> sPAPRDRConnector *drc =
> - spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id);
> + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, cc->core_id);
> sPAPRDRConnectorClass *drck;
> Error *local_err = NULL;
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr: fix core unplug crash
2016-07-08 15:47 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
@ 2016-07-10 14:47 ` Bharata B Rao
2016-07-11 1:42 ` David Gibson
1 sibling, 0 replies; 5+ messages in thread
From: Bharata B Rao @ 2016-07-10 14:47 UTC (permalink / raw)
To: Greg Kurz; +Cc: David Gibson, qemu-ppc, qemu-devel
On Fri, Jul 08, 2016 at 05:47:01PM +0200, Greg Kurz wrote:
> On Fri, 08 Jul 2016 15:12:07 +0200
> Greg Kurz <groug@kaod.org> wrote:
>
> > If the host has 8 threads/core and the guest is started with:
> >
> > -smp cores=1,threads=4,maxcpus=12
> >
> > It is possible to crash QEMU by doing:
> >
> > (qemu) device_add host-spapr-cpu-core,core-id=16,id=foo
> > (qemu) device_del foo
> > Segmentation fault
> >
> > This is caused because spapr_core_unplug() assumes cpu_dt_id == core_id.
> > Even if it happens to be the case when the host and guest have the same
> > number of threads per core, it is conceptually wrong and we may pass a
> > bogus id to spapr_dr_connector_by_id() and spapr_core_release() crashes.
> >
> > Let's use cc->core_id, which is the id that was used to create th DR
> > connector.
>
> My bad, I got excited and pointed out the wrong culprit... it is cpu_index
> again of course ! Please find an updated explanation to be put in the
> changelog after "Segmentation fault":
>
> ========================================================================
> This happens because spapr_core_unplug() assumes cpu_dt_id == core_id.
> As long as cpu_dt_id is derived from the non-table cpu_index, this is
> only true when you plug cores with contiguous ids.
>
> It is safer to be consistent: the DR connector was created with an
> index that is immediately written to cc->core_id, and spapr_core_plug()
> also relies on cc->core_id.
>
> Let's use it also in spapr_core_unplug().
> ========================================================================
>
> >
> > Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
This prevents the crash, but unplug still fails and that will be fixed
only by having your patchset where device tree id is derived from
core index.
Regards,
Bharata.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr: fix core unplug crash
2016-07-08 15:47 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2016-07-10 14:47 ` Bharata B Rao
@ 2016-07-11 1:42 ` David Gibson
1 sibling, 0 replies; 5+ messages in thread
From: David Gibson @ 2016-07-11 1:42 UTC (permalink / raw)
To: Greg Kurz; +Cc: qemu-ppc, qemu-devel, Bharata B Rao
[-- Attachment #1: Type: text/plain, Size: 2894 bytes --]
On Fri, Jul 08, 2016 at 05:47:01PM +0200, Greg Kurz wrote:
> On Fri, 08 Jul 2016 15:12:07 +0200
> Greg Kurz <groug@kaod.org> wrote:
>
> > If the host has 8 threads/core and the guest is started with:
> >
> > -smp cores=1,threads=4,maxcpus=12
> >
> > It is possible to crash QEMU by doing:
> >
> > (qemu) device_add host-spapr-cpu-core,core-id=16,id=foo
> > (qemu) device_del foo
> > Segmentation fault
> >
> > This is caused because spapr_core_unplug() assumes cpu_dt_id == core_id.
> > Even if it happens to be the case when the host and guest have the same
> > number of threads per core, it is conceptually wrong and we may pass a
> > bogus id to spapr_dr_connector_by_id() and spapr_core_release() crashes.
> >
> > Let's use cc->core_id, which is the id that was used to create th DR
> > connector.
>
> My bad, I got excited and pointed out the wrong culprit... it is cpu_index
> again of course ! Please find an updated explanation to be put in the
> changelog after "Segmentation fault":
>
> ========================================================================
> This happens because spapr_core_unplug() assumes cpu_dt_id == core_id.
> As long as cpu_dt_id is derived from the non-table cpu_index, this is
> only true when you plug cores with contiguous ids.
>
> It is safer to be consistent: the DR connector was created with an
> index that is immediately written to cc->core_id, and spapr_core_plug()
> also relies on cc->core_id.
>
> Let's use it also in spapr_core_unplug().
> ========================================================================
Reworded in place, thanks.
>
> >
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> > hw/ppc/spapr_cpu_core.c | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> > index 70b6b0b5ee17..106eaf45b399 100644
> > --- a/hw/ppc/spapr_cpu_core.c
> > +++ b/hw/ppc/spapr_cpu_core.c
> > @@ -126,11 +126,9 @@ static void spapr_core_release(DeviceState *dev, void *opaque)
> > void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
> > Error **errp)
> > {
> > - sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
> > - PowerPCCPU *cpu = POWERPC_CPU(core->threads);
> > - int id = ppc_get_vcpu_dt_id(cpu);
> > + CPUCore *cc = CPU_CORE(dev);
> > sPAPRDRConnector *drc =
> > - spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id);
> > + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, cc->core_id);
> > sPAPRDRConnectorClass *drck;
> > Error *local_err = NULL;
> >
> >
> >
>
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] spapr: fix core unplug crash
2016-07-08 13:12 [Qemu-devel] [PATCH] spapr: fix core unplug crash Greg Kurz
2016-07-08 15:47 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
@ 2016-07-11 1:40 ` David Gibson
1 sibling, 0 replies; 5+ messages in thread
From: David Gibson @ 2016-07-11 1:40 UTC (permalink / raw)
To: Greg Kurz; +Cc: qemu-ppc, qemu-devel, Bharata B Rao
[-- Attachment #1: Type: text/plain, Size: 1941 bytes --]
On Fri, Jul 08, 2016 at 03:12:07PM +0200, Greg Kurz wrote:
> If the host has 8 threads/core and the guest is started with:
>
> -smp cores=1,threads=4,maxcpus=12
>
> It is possible to crash QEMU by doing:
>
> (qemu) device_add host-spapr-cpu-core,core-id=16,id=foo
> (qemu) device_del foo
> Segmentation fault
>
> This is caused because spapr_core_unplug() assumes cpu_dt_id == core_id.
> Even if it happens to be the case when the host and guest have the same
> number of threads per core, it is conceptually wrong and we may pass a
> bogus id to spapr_dr_connector_by_id() and spapr_core_release() crashes.
>
> Let's use cc->core_id, which is the id that was used to create th DR
> connector.
>
> Signed-off-by: Greg Kurz <groug@kaod.org>
Thanks, applied to ppc-for-2.7.
> ---
> hw/ppc/spapr_cpu_core.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index 70b6b0b5ee17..106eaf45b399 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -126,11 +126,9 @@ static void spapr_core_release(DeviceState *dev, void *opaque)
> void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
> Error **errp)
> {
> - sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
> - PowerPCCPU *cpu = POWERPC_CPU(core->threads);
> - int id = ppc_get_vcpu_dt_id(cpu);
> + CPUCore *cc = CPU_CORE(dev);
> sPAPRDRConnector *drc =
> - spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id);
> + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, cc->core_id);
> sPAPRDRConnectorClass *drck;
> Error *local_err = NULL;
>
>
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-07-11 2:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-08 13:12 [Qemu-devel] [PATCH] spapr: fix core unplug crash Greg Kurz
2016-07-08 15:47 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2016-07-10 14:47 ` Bharata B Rao
2016-07-11 1:42 ` David Gibson
2016-07-11 1:40 ` [Qemu-devel] " David Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).