spapr/xics: fix migration of older machine types
v3 cover spapr/xics: fix migration of older machine types
v3: - preparatory cleanup in pnv (patch 1)
- rework ICPState realization and vmstate registration (patches 2,3,4)
- fix migration using dummy icp/server entries (patch 5)
v2: - some patches from v1 are already merged in ppc-for-2.10
- added a new fix to a potential memory leak (patch 1)
- consolidate dt_id computation (patch 3)
- see individual changelogs for patch 2 and 4
This series is based on:
https://github.com/dgibson/qemu.git ppc-for-2.10
This was lightly tested.
--
Greg
---
Greg Kurz (5):
pnv_core: drop reference on ICPState object during CPU realization
xics: add reset() handler to ICPStateClass
xics: setup cpu at realize time
xics: directly register ICPState objects to vmstate
spapr: fix migration of ICPState objects from/to older QEMU
hw/intc/xics.c | 86 ++++++++++++++++++++++------------------------ hw/intc/xics_kvm.c | 27 +------------- hw/ppc/pnv_core.c | 15 ++++---- hw/ppc/spapr.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_cpu_core.c | 21 +++++------ include/hw/ppc/spapr.h | 2 + include/hw/ppc/xics.h | 3 +- 7 files changed, 148 insertions(+), 94 deletions(-)
PATCH v3 1/5 pnv_core: drop reference on ICPState object during CPU realization
Similarly to what was done to spapr with commit 249127d0dfeb, this patch ensures that we don't keep an extra reference on the ICPState object. Also since the object was just created and not reparented yet, the call to object_property_add_child() should never fail: let's pass &error_abort to make this clear.
--- hw/ppc/pnv_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/ppc/pnv_core.c +2 -1
@@ -119,7 +119,8 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)Object *obj; obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj,NULL ); +object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); +object_unref (obj);object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort);object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) {
Re: [Qemu-devel] [PATCH v3 1/5] pnv_core: drop reference on ICPState object during CPU realization
Quoted 7 lines · Greg Kurz
Similarly to what was done to spapr with commit
249127d0dfeb, this patch ensures that we don't keep an extra reference on the ICPState object. Also since the object was just created and not reparented yet, the call toobject_property_add_child()should never fail: let's pass&error_abortto make this clear.Signed-off-by Greg Kurz <[email protected]>
Thanks,
C.
Quoted 19 lines
--- hw/ppc/pnv_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/ppc/pnv_core.c +2
-1@@ -119,7 +119,8 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)Object *obj; obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj,NULL ); +object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); +object_unref (obj);object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort);object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) {
David Gibson
AppliedRe: [Qemu-devel] [PATCH v3 1/5] pnv_core: drop reference on ICPState object during CPU realization
Quoted 10 lines · Cédric Le Goater
Quoted 7 lines · Greg Kurz
Similarly to what was done to spapr with commit
249127d0dfeb, this patch ensures that we don't keep an extra reference on the ICPState object. Also since the object was just created and not reparented yet, the call toobject_property_add_child()should never fail: let's pass&error_abortto make this clear.Signed-off-by Greg Kurz <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>
Applied to ppc-for-2.10, thanks.
Quoted 25 lines
Thanks,
C.
Quoted 19 lines
--- hw/ppc/pnv_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/ppc/pnv_core.c +2
-1@@ -119,7 +119,8 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)Object *obj; obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj,NULL ); +object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); +object_unref (obj);object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort);object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) {
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
PATCH v3 2/5 xics: add reset() handler to ICPStateClass
In reply to Greg KurzTaking into account that qemu_set_irq() returns immediatly if its first argument is NULL, icp_kvm_reset() largely duplicates icp_reset().
This patch introduces a reset() handler, so that the common logic can be implemented in icp_reset() only.
While there we can also drop icp_kvm_realize() and icp_kvm_unrealize(). This causes icp-kvm to be realized in icp_realize(), which sets icp->xics, but it has no impact.
--- hw/intc/xics.c | 5 +++++ hw/intc/xics_kvm.c | 27 ++------------------------- include/hw/ppc/xics.h | 1 + 3 files changed, 8 insertions(+), 25 deletions(-)
hw/intc/xics.c +5 -0
@@ -325,6 +325,7 @@ static const VMStateDescription vmstate_icp_server = {static void icp_reset (void *dev) {ICPState *icp =ICP (dev); +ICPStateClass *icpc =ICP_GET_CLASS (icp); icp->xirr =0 ; icp->pending_priority =0xff ;
@@ -332,6 +333,10 @@ static void icp_reset(void *dev)/* Make all outputs are deasserted */ qemu_set_irq (icp->output,0 ); + +if (icpc->reset) { + icpc->reset (icp); + } }static void icp_realize (DeviceState *dev,Error **errp)
hw/intc/xics_kvm.c +2 -25
@@ -110,19 +110,8 @@ static int icp_set_kvm_state(ICPState *icp, int version_id)return 0 ; } -static void icp_kvm_reset (void *dev) +static void icp_kvm_reset (ICPState *icp) { -ICPState *icp =ICP (dev); - - icp->xirr =0 ; - icp->pending_priority =0xff ; - icp->mfrr =0xff ; - -/* Make all outputs as deasserted only if the CPU thread is in use */ -if (icp->output) { -qemu_set_irq (icp->output,0 ); - } -icp_set_kvm_state (icp,1 ); }
@@ -159,26 +148,14 @@ static void icp_kvm_cpu_setup(ICPState *icp, PowerPCCPU *cpu)QLIST_INSERT_HEAD (&kvm_enabled_icps, enabled_icp, node); } -static void icp_kvm_realize (DeviceState *dev,Error **errp) -{ -qemu_register_reset (icp_kvm_reset, dev); -} - -static void icp_kvm_unrealize (DeviceState *dev,Error **errp) -{ -qemu_unregister_reset (icp_kvm_reset, dev); -} -static void icp_kvm_class_init (ObjectClass *klass,void *data) { -DeviceClass *dc =DEVICE_CLASS (klass);ICPStateClass *icpc =ICP_CLASS (klass); - dc->realize = icp_kvm_realize; - dc->unrealize = icp_kvm_unrealize; icpc->pre_save = icp_get_kvm_state; icpc->post_load = icp_set_kvm_state; icpc->cpu_setup = icp_kvm_cpu_setup; + icpc->reset = icp_kvm_reset; }static const TypeInfo icp_kvm_info = {
include/hw/ppc/xics.h +1 -0
@@ -69,6 +69,7 @@ struct ICPStateClass {void (*pre_save)(ICPState *s);int (*post_load)(ICPState *s,int version_id);void (*cpu_setup)(ICPState *icp,PowerPCCPU *cpu); +void (*reset)(ICPState *icp); };struct ICPState {
Re: [Qemu-devel] [PATCH v3 2/5] xics: add reset() handler to ICPStateClass
Quoted 11 lines · Greg Kurz
Taking into account that
qemu_set_irq()returns immediatly if its first argument is NULL,icp_kvm_reset()largely duplicatesicp_reset().This patch introduces a
reset()handler, so that the common logic can be implemented inicp_reset()only.While there we can also drop
icp_kvm_realize()andicp_kvm_unrealize(). This causes icp-kvm to be realized inicp_realize(), which setsicp->xics, but it has no impact.Signed-off-by Greg Kurz <[email protected]>
Quoted 5 lines
--- hw/intc/xics.c | 5 +++++ hw/intc/xics_kvm.c | 27 ++------------------------- include/hw/ppc/xics.h | 1 + 3 files changed, 8 insertions(+), 25 deletions(-)
another good cleanup !
Thanks,
C.
Quoted 90 lines
hw/intc/xics.c +5
-0@@ -325,6 +325,7 @@ static const VMStateDescription vmstate_icp_server = {static void icp_reset (void *dev) {ICPState *icp =ICP (dev); +ICPStateClass *icpc =ICP_GET_CLASS (icp); icp->xirr =0 ; icp->pending_priority =0xff ;@@ -332,6 +333,10 @@ static void icp_reset(void *dev)/* Make all outputs are deasserted */ qemu_set_irq (icp->output,0 ); + +if (icpc->reset) { + icpc->reset (icp); + } }static void icp_realize (DeviceState *dev,Error **errp)hw/intc/xics_kvm.c +2
-25@@ -110,19 +110,8 @@ static int icp_set_kvm_state(ICPState *icp, int version_id)return 0 ; } -static void icp_kvm_reset (void *dev) +static void icp_kvm_reset (ICPState *icp) { -ICPState *icp =ICP (dev); - - icp->xirr =0 ; - icp->pending_priority =0xff ; - icp->mfrr =0xff ; - -/* Make all outputs as deasserted only if the CPU thread is in use */ -if (icp->output) { -qemu_set_irq (icp->output,0 ); - } -icp_set_kvm_state (icp,1 ); }@@ -159,26 +148,14 @@ static void icp_kvm_cpu_setup(ICPState *icp, PowerPCCPU *cpu)QLIST_INSERT_HEAD (&kvm_enabled_icps, enabled_icp, node); } -static void icp_kvm_realize (DeviceState *dev,Error **errp) -{ -qemu_register_reset (icp_kvm_reset, dev); -} - -static void icp_kvm_unrealize (DeviceState *dev,Error **errp) -{ -qemu_unregister_reset (icp_kvm_reset, dev); -} -static void icp_kvm_class_init (ObjectClass *klass,void *data) { -DeviceClass *dc =DEVICE_CLASS (klass);ICPStateClass *icpc =ICP_CLASS (klass); - dc->realize = icp_kvm_realize; - dc->unrealize = icp_kvm_unrealize; icpc->pre_save = icp_get_kvm_state; icpc->post_load = icp_set_kvm_state; icpc->cpu_setup = icp_kvm_cpu_setup; + icpc->reset = icp_kvm_reset; }static const TypeInfo icp_kvm_info = {include/hw/ppc/xics.h +1
-0@@ -69,6 +69,7 @@ struct ICPStateClass {void (*pre_save)(ICPState *s);int (*post_load)(ICPState *s,int version_id);void (*cpu_setup)(ICPState *icp,PowerPCCPU *cpu); +void (*reset)(ICPState *icp); };struct ICPState {
Re: [Qemu-devel] [PATCH v3 2/5] xics: add reset() handler to ICPStateClass
Quoted 15 lines · Greg Kurz
Quoted 11 lines
Taking into account that
qemu_set_irq()returns immediatly if its first argument is NULL,icp_kvm_reset()largely duplicatesicp_reset().This patch introduces a
reset()handler, so that the common logic can be implemented inicp_reset()only.While there we can also drop
icp_kvm_realize()andicp_kvm_unrealize(). This causes icp-kvm to be realized inicp_realize(), which setsicp->xics, but it has no impact.Signed-off-by Greg Kurz <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>
Quoted 7 lines
Quoted 5 lines
--- hw/intc/xics.c | 5 +++++ hw/intc/xics_kvm.c | 27 ++------------------------- include/hw/ppc/xics.h | 1 + 3 files changed, 8 insertions(+), 25 deletions(-)another good cleanup !
I concur. Applied to ppc-for-2.10.
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
PATCH v3 3/5 xics: setup cpu at realize time
In reply to Greg KurzUntil recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in xics_cpu_setup() when plugging a CPU core.
Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes xics_cpu_setup() in icp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.
Since ICPState objects are freed when unrealized, xics_cpu_destroy() isn't needed anymore and can be safely dropped.
--- hw/intc/xics.c | 76 ++++++++++++++++++++--------------------------- hw/ppc/pnv_core.c | 16 ++++------ hw/ppc/spapr_cpu_core.c | 21 ++++++------- include/hw/ppc/xics.h | 2 - 4 files changed, 48 insertions(+), 67 deletions(-)
hw/intc/xics.c +32 -44
@@ -38,50 +38,6 @@#include "monitor/monitor.h" #include "hw/intc/intc.h" -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu) -{ -CPUState *cs =CPU (cpu); -ICPState *icp =ICP (cpu->intc); - -assert (icp); -assert (cs == icp->cs); - - icp->output =NULL ; - icp->cs =NULL ; -} - -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp) -{ -CPUState *cs =CPU (cpu); -CPUPPCState *env = &cpu->env; -ICPStateClass *icpc; - -assert (icp); - - cpu->intc =OBJECT (icp); - icp->cs = cs; - - icpc =ICP_GET_CLASS (icp); -if (icpc->cpu_setup) { - icpc->cpu_setup (icp, cpu); - } - -switch (PPC_INPUT (env)) { -case PPC_FLAGS_INPUT_POWER7 : - icp->output = env->irq_inputs[POWER7_INPUT_INT ]; -break ; - -case PPC_FLAGS_INPUT_970 : - icp->output = env->irq_inputs[PPC970_INPUT_INT ]; -break ; - -default : -error_report ("XICS interrupt controller does not support this CPU " -"bus model" ); -abort (); - } -} -void icp_pic_print_info (ICPState *icp,Monitor *mon) {int cpu_index = icp->cs ? icp->cs->cpu_index :-1 ;
@@ -343,6 +299,8 @@ static void icp_realize(DeviceState *dev, Error **errp) {ICPState *icp =ICP (dev);ICPStateClass *icpc =ICP_GET_CLASS (dev); +PowerPCCPU *cpu; +CPUPPCState *env;Object *obj;Error *err =NULL ;
@@ -355,6 +313,36 @@ static void icp_realize(DeviceState *dev, Error **errp) icp->xics =XICS_FABRIC (obj); + obj =object_property_get_link (OBJECT (dev),"cs" , &err); +if (!obj) { +error_setg (errp,"%s: required link 'xics' not found: %s" , + __func__,error_get_pretty (err)); +return ; + } + + cpu =POWERPC_CPU (obj); + cpu->intc =OBJECT (icp); + icp->cs =CPU (obj); + +if (icpc->cpu_setup) { + icpc->cpu_setup (icp, cpu); + } + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + icp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + icp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XICS interrupt controller does not support this CPU bus model" ); +return ; + } +if (icpc->realize) { icpc->realize (dev, errp); }
hw/ppc/pnv_core.c +7 -9
@@ -118,19 +118,19 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {error_propagate (errp, local_err);return ; } -object_property_set_bool (child, true,"realized" , &local_err); + obj =object_new (TYPE_PNV_ICP ); +object_property_add_child (child,"icp" , obj,NULL ); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }
@@ -141,8 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)error_propagate (errp, local_err);return ; } - -xics_cpu_setup (xi, cpu,ICP (obj)); }static void pnv_core_realize (DeviceState *dev,Error **errp)
hw/ppc/spapr_cpu_core.c +9 -12
@@ -53,9 +53,6 @@ static void spapr_cpu_reset(void *opaque)static void spapr_cpu_destroy (PowerPCCPU *cpu) { -sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); - -xics_cpu_destroy (XICS_FABRIC (spapr), cpu);qemu_unregister_reset (spapr_cpu_reset, cpu); }
@@ -140,28 +137,28 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj; +Object *obj =NULL ; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { goto error; } -object_property_set_bool (child, true,"realized" , &local_err); +spapr_cpu_init (spapr, cpu, &local_err);if (local_err) { goto error; } -spapr_cpu_init (spapr, cpu, &local_err); + obj =object_new (spapr->icp_type); +object_property_add_child (child,"icp" , obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { goto error; } -xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj));return ; error:
include/hw/ppc/xics.h +0 -2
@@ -183,8 +183,6 @@ void spapr_dt_xics(int nr_servers, void *fdt, uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server); -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp); -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu);/* Internal XICS interfaces */ void icp_set_cppr (ICPState *icp,uint8_t cppr);
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 7 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
Quoted 7 lines
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.
I like the idea but I think the assignment of ->cs attribute should be moved under icp_kvm_cpu_setup(), as it is only used under xics_kvm by the kvm_vcpu_ioctl() calls.
Ideally, we should also introduce :
struct KvmState {
ICPState parent_obj;
CPUState *cs;
};That would be cleaner, but that might introduce some migration compat issues again ...
Some minor comments below,
Thanks,
C.
Quoted 76 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/intc/xics.c | 76 ++++++++++++++++++++--------------------------- hw/ppc/pnv_core.c | 16 ++++------ hw/ppc/spapr_cpu_core.c | 21 ++++++------- include/hw/ppc/xics.h | 2 - 4 files changed, 48 insertions(+), 67 deletions(-)hw/intc/xics.c +2
-44@@ -38,50 +38,6 @@#include "monitor/monitor.h" #include "hw/intc/intc.h" -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu) -{ -CPUState *cs =CPU (cpu); -ICPState *icp =ICP (cpu->intc); - -assert (icp); -assert (cs == icp->cs); - - icp->output =NULL ; - icp->cs =NULL ; -} - -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp) -{ -CPUState *cs =CPU (cpu); -CPUPPCState *env = &cpu->env; -ICPStateClass *icpc; - -assert (icp); - - cpu->intc =OBJECT (icp); - icp->cs = cs; - - icpc =ICP_GET_CLASS (icp); -if (icpc->cpu_setup) { - icpc->cpu_setup (icp, cpu); - } - -switch (PPC_INPUT (env)) { -case PPC_FLAGS_INPUT_POWER7 : - icp->output = env->irq_inputs[POWER7_INPUT_INT ]; -break ; - -case PPC_FLAGS_INPUT_970 : - icp->output = env->irq_inputs[PPC970_INPUT_INT ]; -break ; - -default : -error_report ("XICS interrupt controller does not support this CPU " -"bus model" ); -abort (); - } -} -void icp_pic_print_info (ICPState *icp,Monitor *mon) {int cpu_index = icp->cs ? icp->cs->cpu_index :-1 ;@@ -343,6 +299,8 @@ static void icp_realize(DeviceState *dev, Error **errp) {ICPState *icp =ICP (dev);ICPStateClass *icpc =ICP_GET_CLASS (dev); +PowerPCCPU *cpu; +CPUPPCState *env;Object *obj;Error *err =NULL ;@@ -355,6 +313,36 @@ static void icp_realize(DeviceState *dev, Error **errp) icp->xics =XICS_FABRIC (obj);
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 325
Quoted 10 lines
hw/intc/xics.c +10
-0+ obj =object_property_get_link (OBJECT (dev),"cs" , &err); +if (!obj) { +error_setg (errp,"%s: required link 'xics' not found: %s" , + __func__,error_get_pretty (err)); +return ; + } + + cpu =POWERPC_CPU (obj); + cpu->intc =OBJECT (icp); + icp->cs =CPU (obj);
only xics_kvm needs ->cs.
Quoted 38 lines
hw/intc/xics.c +20
-0+ +if (icpc->cpu_setup) { + icpc->cpu_setup (icp, cpu); + } + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + icp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + icp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XICS interrupt controller does not support this CPU bus model" ); +return ; + } +if (icpc->realize) { icpc->realize (dev, errp); }hw/ppc/pnv_core.c +1
-5@@ -118,19 +118,19 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {
hw/ppc/pnv_core.c static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp) · line 131
Quoted 10 lines
hw/ppc/pnv_core.c +5
-1error_propagate (errp, local_err);return ; } -object_property_set_bool (child, true,"realized" , &local_err); + obj =object_new (TYPE_PNV_ICP ); +object_property_add_child (child,"icp" , obj,NULL ); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort);
may be link the cpu object instead ?
Quoted 48 lines
hw/ppc/pnv_core.c +1
-3+object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }@@ -141,8 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)error_propagate (errp, local_err);return ; } - -xics_cpu_setup (xi, cpu,ICP (obj)); }static void pnv_core_realize (DeviceState *dev,Error **errp)hw/ppc/spapr_cpu_core.c +3
-10@@ -53,9 +53,6 @@ static void spapr_cpu_reset(void *opaque)static void spapr_cpu_destroy (PowerPCCPU *cpu) { -sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); - -xics_cpu_destroy (XICS_FABRIC (spapr), cpu);qemu_unregister_reset (spapr_cpu_reset, cpu); }@@ -140,28 +137,28 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj; +Object *obj =NULL ; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { goto error; } -object_property_set_bool (child, true,"realized" , &local_err); +spapr_cpu_init (spapr, cpu, &local_err);
hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize_child(Object *child, Error **errp) · line 156
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +5
-1if (local_err) { goto error; } -spapr_cpu_init (spapr, cpu, &local_err); + obj =object_new (spapr->icp_type); +object_property_add_child (child,"icp" , obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort);
same here.
Quoted 23 lines
hw/ppc/spapr_cpu_core.c +1
-1+object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { goto error; } -xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj));return ; error:include/hw/ppc/xics.h +0
-2@@ -183,8 +183,6 @@ void spapr_dt_xics(int nr_servers, void *fdt, uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server); -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp); -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu);/* Internal XICS interfaces */ void icp_set_cppr (ICPState *icp,uint8_t cppr);
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 13 lines · On Wed, 7 Jun 2017 20:11:38 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 12 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.
Quoted 7 lines
Quoted 2 lines
Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.I like the idea but I think the assignment of ->cs attribute should be moved under
icp_kvm_cpu_setup(), as it is only used underxics_kvmby thekvm_vcpu_ioctl()calls.
Well, cs->cpu_index is also used for traces and to implement the 'info pic' monitor command.
Quoted 11 lines
Ideally, we should also introduce :
struct KvmState { ICPState parent_obj; CPUState *cs; };That would be cleaner, but that might introduce some migration compat issues again ...
No, as long as it doesn't change state, we're good. My concern is more about how to pass cs to xics_kvm and the cs->cpu_index to xics.
Quoted 82 lines
Some minor comments below,
Thanks,
C.
Quoted 76 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/intc/xics.c | 76 ++++++++++++++++++++--------------------------- hw/ppc/pnv_core.c | 16 ++++------ hw/ppc/spapr_cpu_core.c | 21 ++++++------- include/hw/ppc/xics.h | 2 - 4 files changed, 48 insertions(+), 67 deletions(-)hw/intc/xics.c +2
-44@@ -38,50 +38,6 @@#include "monitor/monitor.h" #include "hw/intc/intc.h" -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu) -{ -CPUState *cs =CPU (cpu); -ICPState *icp =ICP (cpu->intc); - -assert (icp); -assert (cs == icp->cs); - - icp->output =NULL ; - icp->cs =NULL ; -} - -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp) -{ -CPUState *cs =CPU (cpu); -CPUPPCState *env = &cpu->env; -ICPStateClass *icpc; - -assert (icp); - - cpu->intc =OBJECT (icp); - icp->cs = cs; - - icpc =ICP_GET_CLASS (icp); -if (icpc->cpu_setup) { - icpc->cpu_setup (icp, cpu); - } - -switch (PPC_INPUT (env)) { -case PPC_FLAGS_INPUT_POWER7 : - icp->output = env->irq_inputs[POWER7_INPUT_INT ]; -break ; - -case PPC_FLAGS_INPUT_970 : - icp->output = env->irq_inputs[PPC970_INPUT_INT ]; -break ; - -default : -error_report ("XICS interrupt controller does not support this CPU " -"bus model" ); -abort (); - } -} -void icp_pic_print_info (ICPState *icp,Monitor *mon) {int cpu_index = icp->cs ? icp->cs->cpu_index :-1 ;@@ -343,6 +299,8 @@ static void icp_realize(DeviceState *dev, Error **errp) {ICPState *icp =ICP (dev);ICPStateClass *icpc =ICP_GET_CLASS (dev); +PowerPCCPU *cpu; +CPUPPCState *env;Object *obj;Error *err =NULL ;@@ -355,6 +313,36 @@ static void icp_realize(DeviceState *dev, Error **errp) icp->xics =XICS_FABRIC (obj);
Quoted 13 lines
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 325
Quoted 10 lines
hw/intc/xics.c +10
-0+ obj =object_property_get_link (OBJECT (dev),"cs" , &err); +if (!obj) { +error_setg (errp,"%s: required link 'xics' not found: %s" , + __func__,error_get_pretty (err)); +return ; + } + + cpu =POWERPC_CPU (obj); + cpu->intc =OBJECT (icp); + icp->cs =CPU (obj);only
xics_kvmneeds ->cs.
yeah, maybe the base class should only have a cpu_index field:
icp->cpu_index = CPU(obj)->cpu_index;
Quoted 42 lines
Quoted 42 lines
hw/intc/xics.c +20
-0+ +if (icpc->cpu_setup) { + icpc->cpu_setup (icp, cpu); + } + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + icp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + icp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XICS interrupt controller does not support this CPU bus model" ); +return ; + } +if (icpc->realize) { icpc->realize (dev, errp); }hw/ppc/pnv_core.c +1
-5@@ -118,19 +118,19 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {error_propagate (errp, local_err);return ; }
Quoted 9 lines
hw/ppc/pnv_core.c static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp) · line 131
Quoted 6 lines
hw/ppc/pnv_core.c +5
-1-object_property_set_bool (child, true,"realized" , &local_err); + obj =object_new (TYPE_PNV_ICP ); +object_property_add_child (child,"icp" , obj,NULL ); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort);may be link the cpu object instead ?
I'm not sure to understand... isn't child supposed to be a CPU index here ?
Quoted 85 lines
Quoted 48 lines
hw/ppc/pnv_core.c +1
-3+object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }@@ -141,8 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)error_propagate (errp, local_err);return ; } - -xics_cpu_setup (xi, cpu,ICP (obj)); }static void pnv_core_realize (DeviceState *dev,Error **errp)hw/ppc/spapr_cpu_core.c +3
-10@@ -53,9 +53,6 @@ static void spapr_cpu_reset(void *opaque)static void spapr_cpu_destroy (PowerPCCPU *cpu) { -sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); - -xics_cpu_destroy (XICS_FABRIC (spapr), cpu);qemu_unregister_reset (spapr_cpu_reset, cpu); }@@ -140,28 +137,28 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj; +Object *obj =NULL ; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { goto error; } -object_property_set_bool (child, true,"realized" , &local_err); +spapr_cpu_init (spapr, cpu, &local_err);hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize_child(Object *child, Error **errp) · line 156
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +5
-1if (local_err) { goto error; } -spapr_cpu_init (spapr, cpu, &local_err); + obj =object_new (spapr->icp_type); +object_property_add_child (child,"icp" , obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort);same here.
Quoted 23 lines
hw/ppc/spapr_cpu_core.c +1
-1+object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { goto error; } -xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj));return ; error:include/hw/ppc/xics.h +0
-2@@ -183,8 +183,6 @@ void spapr_dt_xics(int nr_servers, void *fdt, uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server); -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp); -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu);/* Internal XICS interfaces */ void icp_set_cppr (ICPState *icp,uint8_t cppr);
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 19 lines · Greg Kurz
Quoted 16 lines · On Wed, 7 Jun 2017 20:11:38 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 14 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.
Quoted 7 lines
Quoted 4 lines
I like the idea but I think the assignment of ->cs attribute should be moved under
icp_kvm_cpu_setup(), as it is only used underxics_kvmby thekvm_vcpu_ioctl()calls.Well,
cs->cpu_indexis also used for traces and to implement the 'info pic' monitor command.
Right. I think it makes sense for the ICP to have a handle on it's associated CPU, even if we don't actually use it in all cases right now. So I have no problem with the property being in all ICPs; I think that will be cleaner than special casing xics_kvm. Especially if we have to un-special-case it sometime in future because we need to access the CPU object for some reason we haven't thought of yet.
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
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 28 lines · On Thu, 8 Jun 2017 11:53:29 +1000 David Gibson <[email protected]>…
Quoted 19 lines · Greg Kurz
Quoted 16 lines · On Wed, 7 Jun 2017 20:11:38 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 14 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.Quoted 7 lines
Quoted 4 lines
I like the idea but I think the assignment of ->cs attribute should be moved under
icp_kvm_cpu_setup(), as it is only used underxics_kvmby thekvm_vcpu_ioctl()calls.Well,
cs->cpu_indexis also used for traces and to implement the 'info pic' monitor command.
Quoted 7 lines
Right. I think it makes sense for the ICP to have a handle on it's associated CPU, even if we don't actually use it in all cases right now. So I have no problem with the property being in all ICPs; I think that will be cleaner than special casing
xics_kvm. Especially if we have to un-special-case it sometime in future because we need to access the CPU object for some reason we haven't thought of yet.
We had discussed with Cedric about that actually but when I started to write code, I had the impression that I would have to do convoluted things to get rid of the CPU handle in ICP.
Thanks for confirming this.
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 39 lines · Greg Kurz
Quoted 28 lines · On Thu, 8 Jun 2017 11:53:29 +1000 David Gibson <[email protected]>…
Quoted 19 lines · Greg Kurz
Quoted 16 lines · On Wed, 7 Jun 2017 20:11:38 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 14 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.Quoted 7 lines
Quoted 4 lines
I like the idea but I think the assignment of ->cs attribute should be moved under
icp_kvm_cpu_setup(), as it is only used underxics_kvmby thekvm_vcpu_ioctl()calls.Well,
cs->cpu_indexis also used for traces and to implement the 'info pic' monitor command.Quoted 7 lines
Right. I think it makes sense for the ICP to have a handle on it's associated CPU, even if we don't actually use it in all cases right now. So I have no problem with the property being in all ICPs; I think that will be cleaner than special casing
xics_kvm. Especially if we have to un-special-case it sometime in future because we need to access the CPU object for some reason we haven't thought of yet.
Quoted 3 lines
We had discussed with Cedric about that actually but when I started to write code, I had the impression that I would have to do convoluted things to get rid of the CPU handle in ICP.
There is nothing complex and it would surely simplify cpu_setup().
But, the main argument is that it might be useful to other platforms. So there is not much value in removing it. I am OK with that. I am less OK with using the index, even if it is useful for the migration state of ICP objects today.
We could be tempted to use more of cpu_index, like we have done in the past, and that was really complex to untangle. Let's be cautious.
C.
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 46 lines · On Thu, 8 Jun 2017 11:25:52 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 39 lines · Greg Kurz
Quoted 28 lines · On Thu, 8 Jun 2017 11:53:29 +1000 David Gibson <[email protected]>…
Quoted 19 lines · Greg Kurz
Quoted 16 lines · On Wed, 7 Jun 2017 20:11:38 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 14 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.Quoted 7 lines
Quoted 4 lines
I like the idea but I think the assignment of ->cs attribute should be moved under
icp_kvm_cpu_setup(), as it is only used underxics_kvmby thekvm_vcpu_ioctl()calls.Well,
cs->cpu_indexis also used for traces and to implement the 'info pic' monitor command.Quoted 7 lines
Right. I think it makes sense for the ICP to have a handle on it's associated CPU, even if we don't actually use it in all cases right now. So I have no problem with the property being in all ICPs; I think that will be cleaner than special casing
xics_kvm. Especially if we have to un-special-case it sometime in future because we need to access the CPU object for some reason we haven't thought of yet.Quoted 3 lines
We had discussed with Cedric about that actually but when I started to write code, I had the impression that I would have to do convoluted things to get rid of the CPU handle in ICP.
There is nothing complex and it would surely simplify
cpu_setup().
Quoted 8 lines
But, the main argument is that it might be useful to other platforms. So there is not much value in removing it. I am OK with that. I am less OK with using the index, even if it is useful for the migration state of ICP objects today.
We could be tempted to use more of
cpu_index, like we have done in the past, and that was really complex to untangle. Let's be cautious.
I agree. Maybe this could be hidden in a icpc->get_index() handler ?
Quoted 1 line
C.
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
In reply to Greg KurzQuoted 19 lines · Greg Kurz
Quoted 16 lines · On Wed, 7 Jun 2017 20:11:38 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 14 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.
Quoted 7 lines
Quoted 4 lines
I like the idea but I think the assignment of ->cs attribute should be moved under
icp_kvm_cpu_setup(), as it is only used underxics_kvmby thekvm_vcpu_ioctl()calls.Well,
cs->cpu_indexis also used for traces and to implement the 'info pic' monitor command.
yes. But, these are just printfs.
Quoted 8 lines
Quoted 8 lines
Ideally, we should also introduce :
struct KvmState { ICPState parent_obj; CPUState *cs; };
Quoted 6 lines
Quoted 3 lines
That would be cleaner, but that might introduce some migration compat issues again ...
No, as long as it doesn't change state, we're good. My concern is more about how to pass cs to
xics_kvm
That can be done in the cpu_setup handler.
Quoted 1 line
and the
cs->cpu_indexto xics.
The printfs are interesting to have but not vital.
David has a good point for keeping ->cs. So let's abandon the idea.
Quoted 96 lines
Quoted 82 lines
Some minor comments below,
Thanks,
C.
Quoted 76 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/intc/xics.c | 76 ++++++++++++++++++++--------------------------- hw/ppc/pnv_core.c | 16 ++++------ hw/ppc/spapr_cpu_core.c | 21 ++++++------- include/hw/ppc/xics.h | 2 - 4 files changed, 48 insertions(+), 67 deletions(-)hw/intc/xics.c +2
-44@@ -38,50 +38,6 @@#include "monitor/monitor.h" #include "hw/intc/intc.h" -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu) -{ -CPUState *cs =CPU (cpu); -ICPState *icp =ICP (cpu->intc); - -assert (icp); -assert (cs == icp->cs); - - icp->output =NULL ; - icp->cs =NULL ; -} - -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp) -{ -CPUState *cs =CPU (cpu); -CPUPPCState *env = &cpu->env; -ICPStateClass *icpc; - -assert (icp); - - cpu->intc =OBJECT (icp); - icp->cs = cs; - - icpc =ICP_GET_CLASS (icp); -if (icpc->cpu_setup) { - icpc->cpu_setup (icp, cpu); - } - -switch (PPC_INPUT (env)) { -case PPC_FLAGS_INPUT_POWER7 : - icp->output = env->irq_inputs[POWER7_INPUT_INT ]; -break ; - -case PPC_FLAGS_INPUT_970 : - icp->output = env->irq_inputs[PPC970_INPUT_INT ]; -break ; - -default : -error_report ("XICS interrupt controller does not support this CPU " -"bus model" ); -abort (); - } -} -void icp_pic_print_info (ICPState *icp,Monitor *mon) {int cpu_index = icp->cs ? icp->cs->cpu_index :-1 ;@@ -343,6 +299,8 @@ static void icp_realize(DeviceState *dev, Error **errp) {ICPState *icp =ICP (dev);ICPStateClass *icpc =ICP_GET_CLASS (dev); +PowerPCCPU *cpu; +CPUPPCState *env;Object *obj;Error *err =NULL ;@@ -355,6 +313,36 @@ static void icp_realize(DeviceState *dev, Error **errp) icp->xics =XICS_FABRIC (obj);Quoted 13 lines
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 325
Quoted 10 lines
hw/intc/xics.c +10
-0+ obj =object_property_get_link (OBJECT (dev),"cs" , &err); +if (!obj) { +error_setg (errp,"%s: required link 'xics' not found: %s" , + __func__,error_get_pretty (err)); +return ; + } + + cpu =POWERPC_CPU (obj); + cpu->intc =OBJECT (icp); + icp->cs =CPU (obj);only
xics_kvmneeds ->cs.
Quoted 3 lines
yeah, maybe the base class should only have a
cpu_indexfield:icp->cpu_index = CPU(obj)->cpu_index;
arg, no. please, let's not add another cpu index :)
Quoted 52 lines
Quoted 42 lines
Quoted 42 lines
hw/intc/xics.c +20
-0+ +if (icpc->cpu_setup) { + icpc->cpu_setup (icp, cpu); + } + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + icp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + icp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XICS interrupt controller does not support this CPU bus model" ); +return ; + } +if (icpc->realize) { icpc->realize (dev, errp); }hw/ppc/pnv_core.c +1
-5@@ -118,19 +118,19 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {error_propagate (errp, local_err);return ; }Quoted 9 lines
hw/ppc/pnv_core.c static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp) · line 131
Quoted 6 lines
hw/ppc/pnv_core.c +5
-1-object_property_set_bool (child, true,"realized" , &local_err); + obj =object_new (TYPE_PNV_ICP ); +object_property_add_child (child,"icp" , obj,NULL ); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort);may be link the cpu object instead ?
Quoted 1 line
I'm not sure to understand... isn't child supposed to be a CPU index here ?
I meant linking the 'PowerPCCPU *cpu' object and not the CPUState. That's minor.
Quoted 86 lines
Quoted 85 lines
Quoted 48 lines
hw/ppc/pnv_core.c +1
-3+object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }@@ -141,8 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)error_propagate (errp, local_err);return ; } - -xics_cpu_setup (xi, cpu,ICP (obj)); }static void pnv_core_realize (DeviceState *dev,Error **errp)hw/ppc/spapr_cpu_core.c +3
-10@@ -53,9 +53,6 @@ static void spapr_cpu_reset(void *opaque)static void spapr_cpu_destroy (PowerPCCPU *cpu) { -sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); - -xics_cpu_destroy (XICS_FABRIC (spapr), cpu);qemu_unregister_reset (spapr_cpu_reset, cpu); }@@ -140,28 +137,28 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj; +Object *obj =NULL ; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { goto error; } -object_property_set_bool (child, true,"realized" , &local_err); +spapr_cpu_init (spapr, cpu, &local_err);hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize_child(Object *child, Error **errp) · line 156
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +5
-1if (local_err) { goto error; } -spapr_cpu_init (spapr, cpu, &local_err); + obj =object_new (spapr->icp_type); +object_property_add_child (child,"icp" , obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort);same here.
Quoted 23 lines
hw/ppc/spapr_cpu_core.c +1
-1+object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { goto error; } -xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj));return ; error:include/hw/ppc/xics.h +0
-2@@ -183,8 +183,6 @@ void spapr_dt_xics(int nr_servers, void *fdt, uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server); -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp); -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu);/* Internal XICS interfaces */ void icp_set_cppr (ICPState *icp,uint8_t cppr);
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 8 lines · On Thu, 8 Jun 2017 07:50:08 +0200 Cédric Le Goater <[email protected]> wrote:
On 06/07/2017 10:55 PM, Greg Kurz wrote:
[...]Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
hw/ppc/pnv_core.c +5
-0+ obj =object_new (TYPE_PNV_ICP ); +object_property_add_child (child,"icp" , obj,NULL ); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort);
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
may be link the cpu object instead ?
I'm not sure to understand... isn't child supposed to be a CPU index here ?
I meant linking the 'PowerPCCPU *cpu' object and not the CPUState. That's minor.
Well, cpu == cs == child and object_property_add_const_link() expects an Object *. Passing child avoids a not-really-useful OBJECT() dynamic cast.
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
In reply to Greg KurzQuoted 11 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.
Ok, what enforces those ordering constraints?
Quoted 4 lines
Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.Signed-off-by Greg Kurz <[email protected]>
Looks pretty good, though a couple nits below.
Quoted 72 lines
--- hw/intc/xics.c | 76 ++++++++++++++++++++--------------------------- hw/ppc/pnv_core.c | 16 ++++------ hw/ppc/spapr_cpu_core.c | 21 ++++++------- include/hw/ppc/xics.h | 2 - 4 files changed, 48 insertions(+), 67 deletions(-)hw/intc/xics.c +2
-44@@ -38,50 +38,6 @@#include "monitor/monitor.h" #include "hw/intc/intc.h" -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu) -{ -CPUState *cs =CPU (cpu); -ICPState *icp =ICP (cpu->intc); - -assert (icp); -assert (cs == icp->cs); - - icp->output =NULL ; - icp->cs =NULL ; -} - -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp) -{ -CPUState *cs =CPU (cpu); -CPUPPCState *env = &cpu->env; -ICPStateClass *icpc; - -assert (icp); - - cpu->intc =OBJECT (icp); - icp->cs = cs; - - icpc =ICP_GET_CLASS (icp); -if (icpc->cpu_setup) { - icpc->cpu_setup (icp, cpu); - } - -switch (PPC_INPUT (env)) { -case PPC_FLAGS_INPUT_POWER7 : - icp->output = env->irq_inputs[POWER7_INPUT_INT ]; -break ; - -case PPC_FLAGS_INPUT_970 : - icp->output = env->irq_inputs[PPC970_INPUT_INT ]; -break ; - -default : -error_report ("XICS interrupt controller does not support this CPU " -"bus model" ); -abort (); - } -} -void icp_pic_print_info (ICPState *icp,Monitor *mon) {int cpu_index = icp->cs ? icp->cs->cpu_index :-1 ;@@ -343,6 +299,8 @@ static void icp_realize(DeviceState *dev, Error **errp) {ICPState *icp =ICP (dev);ICPStateClass *icpc =ICP_GET_CLASS (dev); +PowerPCCPU *cpu; +CPUPPCState *env;Object *obj;Error *err =NULL ;
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 316
Quoted 4 lines
hw/intc/xics.c +1
-0@@ -355,6 +313,36 @@ static void icp_realize(DeviceState *dev, Error **errp) icp->xics =XICS_FABRIC (obj); + obj =object_property_get_link (OBJECT (dev),"cs" , &err);
I don't like the name "cs" for an externally visible property. "cpu" would be better.
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 318
Quoted 2 lines
hw/intc/xics.c +2
-0+if (!obj) { + error_setg(errp, "%s: required link 'xics' not found: %s",
Copy/paste mistake in this message.
Quoted 136 lines
hw/intc/xics.c +27
-0+ __func__, error_get_pretty(err)); +return ; + } + + cpu =POWERPC_CPU (obj); + cpu->intc =OBJECT (icp); + icp->cs =CPU (obj); + +if (icpc->cpu_setup) { + icpc->cpu_setup (icp, cpu); + } + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + icp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + icp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XICS interrupt controller does not support this CPU bus model" ); +return ; + } +if (icpc->realize) { icpc->realize (dev, errp); }hw/ppc/pnv_core.c +7
-9@@ -118,19 +118,19 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {error_propagate (errp, local_err);return ; } -object_property_set_bool (child, true,"realized" , &local_err); + obj =object_new (TYPE_PNV_ICP ); +object_property_add_child (child,"icp" , obj,NULL ); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }@@ -141,8 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)error_propagate (errp, local_err);return ; } - -xics_cpu_setup (xi, cpu,ICP (obj)); }static void pnv_core_realize (DeviceState *dev,Error **errp)hw/ppc/spapr_cpu_core.c +9
-12@@ -53,9 +53,6 @@ static void spapr_cpu_reset(void *opaque)static void spapr_cpu_destroy (PowerPCCPU *cpu) { -sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); - -xics_cpu_destroy (XICS_FABRIC (spapr), cpu);qemu_unregister_reset (spapr_cpu_reset, cpu); }@@ -140,28 +137,28 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj; +Object *obj =NULL ; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { goto error; } -object_property_set_bool (child, true,"realized" , &local_err); +spapr_cpu_init (spapr, cpu, &local_err);if (local_err) { goto error; } -spapr_cpu_init (spapr, cpu, &local_err); + obj =object_new (spapr->icp_type); +object_property_add_child (child,"icp" , obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { goto error; } -xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj));return ; error:include/hw/ppc/xics.h +0
-2@@ -183,8 +183,6 @@ void spapr_dt_xics(int nr_servers, void *fdt, uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server); -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp); -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu);/* Internal XICS interfaces */ void icp_set_cppr (ICPState *icp,uint8_t cppr);
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
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 8 lines · On Thu, 8 Jun 2017 12:01:12 +1000 David Gibson <[email protected]>…
Quoted 7 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
Quoted 7 lines
Quoted 4 lines
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Ok, what enforces those ordering constraints?
I'm not sure about what you're asking... I had to re-order because xics_cpu_setup() used to be called after the vCPU is realized and put in PAPR mode.
Especially, we have these lines:
switch (PPC_INPUT(env)) {
case PPC_FLAGS_INPUT_POWER7:
icp->output = env->irq_inputs[POWER7_INPUT_INT];
break;
case PPC_FLAGS_INPUT_970:
icp->output = env->irq_inputs[PPC970_INPUT_INT];
break;They depend on env->irq_inputs being allocated. This happens on the
spapr_cpu_core_realize_child()
{
...
object_property_set_bool(child, true, "realized", &local_err);
object_property_set_bool()
object_property_set_qobject()
object_property_set()
property_set_bool()
device_set_realized()
ppc_cpu_realizefn()
init_ppc_proc()
init_proc_POWER8()
ppcPOWER7_irq_init()and, when using xics_kvm:
icp_kvm_cpu_setup()
{
...
ret = kvm_vcpu_enable_cap(cs, KVM_CAP_IRQ_XICS, 0, kernel_xics_fd, vcpu_id);This ioctl returns EINVAL because it fails the kvmppc_sanity_check() in KVM.
It depends on QEMU enabling KVM_CAP_PPC_PAPR for the vCPU, which happens in:
spapr_cpu_core_realize_child()
{
...
spapr_cpu_init(spapr, cpu, &local_err);
cpu_ppc_set_papr()
kvmppc_set_papr()Quoted 8 lines
Quoted 4 lines
Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.Signed-off-by Greg Kurz <[email protected]>Looks pretty good, though a couple nits below.
Thanks. I'm also thinking about going one step further and converting xics_kvm to use the icpc->realize() handler instead of icpc->cpu_setup(). Makes sense ?
Quoted 71 lines
Quoted 71 lines
--- hw/intc/xics.c | 76 ++++++++++++++++++++--------------------------- hw/ppc/pnv_core.c | 16 ++++------ hw/ppc/spapr_cpu_core.c | 21 ++++++------- include/hw/ppc/xics.h | 2 - 4 files changed, 48 insertions(+), 67 deletions(-)hw/intc/xics.c +2
-44@@ -38,50 +38,6 @@#include "monitor/monitor.h" #include "hw/intc/intc.h" -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu) -{ -CPUState *cs =CPU (cpu); -ICPState *icp =ICP (cpu->intc); - -assert (icp); -assert (cs == icp->cs); - - icp->output =NULL ; - icp->cs =NULL ; -} - -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp) -{ -CPUState *cs =CPU (cpu); -CPUPPCState *env = &cpu->env; -ICPStateClass *icpc; - -assert (icp); - - cpu->intc =OBJECT (icp); - icp->cs = cs; - - icpc =ICP_GET_CLASS (icp); -if (icpc->cpu_setup) { - icpc->cpu_setup (icp, cpu); - } - -switch (PPC_INPUT (env)) { -case PPC_FLAGS_INPUT_POWER7 : - icp->output = env->irq_inputs[POWER7_INPUT_INT ]; -break ; - -case PPC_FLAGS_INPUT_970 : - icp->output = env->irq_inputs[PPC970_INPUT_INT ]; -break ; - -default : -error_report ("XICS interrupt controller does not support this CPU " -"bus model" ); -abort (); - } -} -void icp_pic_print_info (ICPState *icp,Monitor *mon) {int cpu_index = icp->cs ? icp->cs->cpu_index :-1 ;@@ -343,6 +299,8 @@ static void icp_realize(DeviceState *dev, Error **errp) {ICPState *icp =ICP (dev);ICPStateClass *icpc =ICP_GET_CLASS (dev); +PowerPCCPU *cpu; +CPUPPCState *env;Object *obj;Error *err =NULL ;
Quoted 9 lines
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 316
Quoted 5 lines
hw/intc/xics.c +1
-0@@ -355,6 +313,36 @@ static void icp_realize(DeviceState *dev, Error **errp) icp->xics =XICS_FABRIC (obj); + obj =object_property_get_link (OBJECT (dev),"cs" , &err);I don't like the name "cs" for an externally visible property. "cpu" would be better.
Right. I'll fix this.
Quoted 5 lines
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 318
Quoted 2 lines
hw/intc/xics.c +2
-0+if (!obj) { + error_setg(errp, "%s: required link 'xics' not found: %s",Copy/paste mistake in this message.
Oops :)
Quoted 137 lines
Quoted 136 lines
hw/intc/xics.c +27
-0+ __func__, error_get_pretty(err)); +return ; + } + + cpu =POWERPC_CPU (obj); + cpu->intc =OBJECT (icp); + icp->cs =CPU (obj); + +if (icpc->cpu_setup) { + icpc->cpu_setup (icp, cpu); + } + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + icp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + icp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XICS interrupt controller does not support this CPU bus model" ); +return ; + } +if (icpc->realize) { icpc->realize (dev, errp); }hw/ppc/pnv_core.c +7
-9@@ -118,19 +118,19 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {error_propagate (errp, local_err);return ; } -object_property_set_bool (child, true,"realized" , &local_err); + obj =object_new (TYPE_PNV_ICP ); +object_property_add_child (child,"icp" , obj,NULL ); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }@@ -141,8 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)error_propagate (errp, local_err);return ; } - -xics_cpu_setup (xi, cpu,ICP (obj)); }static void pnv_core_realize (DeviceState *dev,Error **errp)hw/ppc/spapr_cpu_core.c +9
-12@@ -53,9 +53,6 @@ static void spapr_cpu_reset(void *opaque)static void spapr_cpu_destroy (PowerPCCPU *cpu) { -sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); - -xics_cpu_destroy (XICS_FABRIC (spapr), cpu);qemu_unregister_reset (spapr_cpu_reset, cpu); }@@ -140,28 +137,28 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj; +Object *obj =NULL ; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { goto error; } -object_property_set_bool (child, true,"realized" , &local_err); +spapr_cpu_init (spapr, cpu, &local_err);if (local_err) { goto error; } -spapr_cpu_init (spapr, cpu, &local_err); + obj =object_new (spapr->icp_type); +object_property_add_child (child,"icp" , obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { goto error; } -xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj));return ; error:include/hw/ppc/xics.h +0
-2@@ -183,8 +183,6 @@ void spapr_dt_xics(int nr_servers, void *fdt, uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server); -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp); -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu);/* Internal XICS interfaces */ void icp_set_cppr (ICPState *icp,uint8_t cppr);
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 74 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Jun 2017 12:01:12 +1000 David Gibson <[email protected]>…
Quoted 7 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
Quoted 7 lines
Quoted 4 lines
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Ok, what enforces those ordering constraints?
I'm not sure about what you're asking... I had to re-order because
xics_cpu_setup()used to be called after the vCPU is realized and put in PAPR mode.Especially, we have these lines:
switch (PPC_INPUT(env)) { case PPC_FLAGS_INPUT_POWER7: icp->output = env->irq_inputs[POWER7_INPUT_INT]; break; case PPC_FLAGS_INPUT_970: icp->output = env->irq_inputs[PPC970_INPUT_INT]; break;They depend on
env->irq_inputsbeing allocated. This happens on the
spapr_cpu_core_realize_child(){ ... object_property_set_bool(child, true, "realized", &local_err); object_property_set_bool() object_property_set_qobject() object_property_set() property_set_bool() device_set_realized() ppc_cpu_realizefn() init_ppc_proc() init_proc_POWER8() ppcPOWER7_irq_init()and, when using
xics_kvm:
icp_kvm_cpu_setup(){ ... ret = kvm_vcpu_enable_cap(cs, KVM_CAP_IRQ_XICS, 0, kernel_xics_fd, vcpu_id);This ioctl returns EINVAL because it fails the
kvmppc_sanity_check()in KVM.It depends on QEMU enabling
KVM_CAP_PPC_PAPRfor the vCPU, which happens in:
spapr_cpu_core_realize_child(){ ... spapr_cpu_init(spapr, cpu, &local_err); cpu_ppc_set_papr() kvmppc_set_papr()Quoted 6 lines
Quoted 4 lines
Since ICPState objects are freed when unrealized,
xics_cpu_destroy()isn't needed anymore and can be safely dropped.Signed-off-by Greg Kurz <[email protected]>
Quoted 6 lines
Quoted 2 lines
Looks pretty good, though a couple nits below.
Thanks. I'm also thinking about going one step further and converting
xics_kvmto use theicpc->realize()handler instead oficpc->cpu_setup(). Makes sense ?
It should be fine I think, now that a reset handler is defined.
C.
Quoted 229 lines
Quoted 71 lines
Quoted 71 lines
--- hw/intc/xics.c | 76 ++++++++++++++++++++--------------------------- hw/ppc/pnv_core.c | 16 ++++------ hw/ppc/spapr_cpu_core.c | 21 ++++++------- include/hw/ppc/xics.h | 2 - 4 files changed, 48 insertions(+), 67 deletions(-)hw/intc/xics.c +2
-44@@ -38,50 +38,6 @@#include "monitor/monitor.h" #include "hw/intc/intc.h" -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu) -{ -CPUState *cs =CPU (cpu); -ICPState *icp =ICP (cpu->intc); - -assert (icp); -assert (cs == icp->cs); - - icp->output =NULL ; - icp->cs =NULL ; -} - -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp) -{ -CPUState *cs =CPU (cpu); -CPUPPCState *env = &cpu->env; -ICPStateClass *icpc; - -assert (icp); - - cpu->intc =OBJECT (icp); - icp->cs = cs; - - icpc =ICP_GET_CLASS (icp); -if (icpc->cpu_setup) { - icpc->cpu_setup (icp, cpu); - } - -switch (PPC_INPUT (env)) { -case PPC_FLAGS_INPUT_POWER7 : - icp->output = env->irq_inputs[POWER7_INPUT_INT ]; -break ; - -case PPC_FLAGS_INPUT_970 : - icp->output = env->irq_inputs[PPC970_INPUT_INT ]; -break ; - -default : -error_report ("XICS interrupt controller does not support this CPU " -"bus model" ); -abort (); - } -} -void icp_pic_print_info (ICPState *icp,Monitor *mon) {int cpu_index = icp->cs ? icp->cs->cpu_index :-1 ;@@ -343,6 +299,8 @@ static void icp_realize(DeviceState *dev, Error **errp) {ICPState *icp =ICP (dev);ICPStateClass *icpc =ICP_GET_CLASS (dev); +PowerPCCPU *cpu; +CPUPPCState *env;Object *obj;Error *err =NULL ;Quoted 9 lines
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 316
Quoted 5 lines
hw/intc/xics.c +1
-0@@ -355,6 +313,36 @@ static void icp_realize(DeviceState *dev, Error **errp) icp->xics =XICS_FABRIC (obj); + obj =object_property_get_link (OBJECT (dev),"cs" , &err);I don't like the name "cs" for an externally visible property. "cpu" would be better.
Right. I'll fix this.
Quoted 5 lines
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 318
Quoted 2 lines
hw/intc/xics.c +2
-0+if (!obj) { + error_setg(errp, "%s: required link 'xics' not found: %s",Copy/paste mistake in this message.
Oops :)
Quoted 137 lines
Quoted 136 lines
hw/intc/xics.c +27
-0+ __func__, error_get_pretty(err)); +return ; + } + + cpu =POWERPC_CPU (obj); + cpu->intc =OBJECT (icp); + icp->cs =CPU (obj); + +if (icpc->cpu_setup) { + icpc->cpu_setup (icp, cpu); + } + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + icp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + icp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XICS interrupt controller does not support this CPU bus model" ); +return ; + } +if (icpc->realize) { icpc->realize (dev, errp); }hw/ppc/pnv_core.c +7
-9@@ -118,19 +118,19 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {error_propagate (errp, local_err);return ; } -object_property_set_bool (child, true,"realized" , &local_err); + obj =object_new (TYPE_PNV_ICP ); +object_property_add_child (child,"icp" , obj,NULL ); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (xi), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }@@ -141,8 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)error_propagate (errp, local_err);return ; } - -xics_cpu_setup (xi, cpu,ICP (obj)); }static void pnv_core_realize (DeviceState *dev,Error **errp)hw/ppc/spapr_cpu_core.c +9
-12@@ -53,9 +53,6 @@ static void spapr_cpu_reset(void *opaque)static void spapr_cpu_destroy (PowerPCCPU *cpu) { -sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); - -xics_cpu_destroy (XICS_FABRIC (spapr), cpu);qemu_unregister_reset (spapr_cpu_reset, cpu); }@@ -140,28 +137,28 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj; +Object *obj =NULL ; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { goto error; } -object_property_set_bool (child, true,"realized" , &local_err); +spapr_cpu_init (spapr, cpu, &local_err);if (local_err) { goto error; } -spapr_cpu_init (spapr, cpu, &local_err); + obj =object_new (spapr->icp_type); +object_property_add_child (child,"icp" , obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); +object_property_add_const_link (obj,"cs" , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { goto error; } -xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj));return ; error:include/hw/ppc/xics.h +0
-2@@ -183,8 +183,6 @@ void spapr_dt_xics(int nr_servers, void *fdt, uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server); -void xics_cpu_setup (XICSFabric *xi,PowerPCCPU *cpu,ICPState *icp); -void xics_cpu_destroy (XICSFabric *xi,PowerPCCPU *cpu);/* Internal XICS interfaces */ void icp_set_cppr (ICPState *icp,uint8_t cppr);
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
In reply to Greg KurzQuoted 16 lines · Greg Kurz
Quoted 13 lines · On Thu, 8 Jun 2017 12:01:12 +1000 David Gibson <[email protected]>…
Quoted 11 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.
Quoted 6 lines
Quoted 2 lines
Ok, what enforces those ordering constraints?
I'm not sure about what you're asking... I had to re-order because
xics_cpu_setup()used to be called after the vCPU is realized and put in PAPR mode.
Duh, sorry, I wasn't thinking to ask about realize order, since that's manual and you've re-ordered it to be correct.
You also mention that reset order matters, and I'm less clear on what guarantees that the reset handlers for the components get called in the right order.
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
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 24 lines · On Fri, 9 Jun 2017 12:24:52 +1000 David Gibson <[email protected]>…
Quoted 16 lines · Greg Kurz
Quoted 13 lines · On Thu, 8 Jun 2017 12:01:12 +1000 David Gibson <[email protected]>…
Quoted 11 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Quoted 6 lines
Quoted 2 lines
Ok, what enforces those ordering constraints?
I'm not sure about what you're asking... I had to re-order because
xics_cpu_setup()used to be called after the vCPU is realized and put in PAPR mode.
Quoted 7 lines
Duh, sorry, I wasn't thinking to ask about realize order, since that's manual and you've re-ordered it to be correct.
You also mention that reset order matters, and I'm less clear on what guarantees that the reset handlers for the components get called in the right order.
Oops... my bad, this is a mistake in the changelog. The KVM error I was seing isn't related to CPU reset as I was thinking first but to cpu_ppc_set_papr()... :-\
The last sentence should rather be something like:
"We also need to call spapr_cpu_init() before ICPState realization in
order to enable PAPR mode in KVM."
Can you fix this in your tree or should I send an updated version ?
Cheers,
--
Greg
Re: [Qemu-devel] [PATCH v3 3/5] xics: setup cpu at realize time
Quoted 39 lines · Greg Kurz
Quoted 24 lines · On Fri, 9 Jun 2017 12:24:52 +1000 David Gibson <[email protected]>…
Quoted 16 lines · Greg Kurz
Quoted 13 lines · On Thu, 8 Jun 2017 12:01:12 +1000 David Gibson <[email protected]>…
Quoted 11 lines · Greg Kurz
Until recently, spapr used to allocate ICPState objects for the lifetime of the machine. They would only be associated to vCPUs in
xics_cpu_setup()when plugging a CPU core.Now that ICPState objects have the same lifecycle as vCPUs, it is possible to associate them during realization.
This patch hence open-codes
xics_cpu_setup()inicp_realize(). The vCPU is passed as a property. Note that vCPU now needs to be realized first for the IRQs to be allocated. It also needs to resetted before ICPState realization in order to synchronize with KVM.Quoted 6 lines
Quoted 2 lines
Ok, what enforces those ordering constraints?
I'm not sure about what you're asking... I had to re-order because
xics_cpu_setup()used to be called after the vCPU is realized and put in PAPR mode.Quoted 7 lines
Duh, sorry, I wasn't thinking to ask about realize order, since that's manual and you've re-ordered it to be correct.
You also mention that reset order matters, and I'm less clear on what guarantees that the reset handlers for the components get called in the right order.
Oops... my bad, this is a mistake in the changelog. The KVM error I was seing isn't related to CPU reset as I was thinking first but to
cpu_ppc_set_papr()... :-\
Quoted 6 lines
The last sentence should rather be something like:
"We also need to call
spapr_cpu_init()before ICPState realization in
order to enable PAPR mode in KVM."Can you fix this in your tree or should I send an updated version ?
Uh.. too late, I already sent a pull request.
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
PATCH v3 4/5 xics: directly register ICPState objects to vmstate
In reply to Greg KurzThe ICPState objects are currently registered to vmstate as qdev objects. Their instance ids are hence computed automatically in the migration code, and thus depends on the order the CPU cores were plugged.
If the destination had its CPU cores plugged in a different order than the source, then ICPState objects will have different instance_ids and load the wrong state.
Since CPU objects have a reliable cpu_index which is already used as instance_id in vmstate, let's use it for ICPState as well.
--- hw/intc/xics.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/intc/xics.c +4 -1
@@ -348,10 +348,14 @@ static void icp_realize(DeviceState *dev, Error **errp) }qemu_register_reset (icp_reset, dev); +vmstate_register (NULL , icp->cs->cpu_index, &vmstate_icp_server, icp); }static void icp_unrealize (DeviceState *dev,Error **errp) { +ICPState *icp =ICP (dev); + +vmstate_unregister (NULL , &vmstate_icp_server, icp);qemu_unregister_reset (icp_reset, dev); }
@@ -359,7 +363,6 @@ static void icp_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_icp_server; dc->realize = icp_realize; dc->unrealize = icp_unrealize; }
Re: [Qemu-devel] [PATCH v3 4/5] xics: directly register ICPState objects to vmstate
Quoted 21 lines · Greg Kurz
The ICPState objects are currently registered to vmstate as qdev objects. Their instance ids are hence computed automatically in the migration code, and thus depends on the order the CPU cores were plugged.
If the destination had its CPU cores plugged in a different order than the source, then ICPState objects will have different
instance_idsand load the wrong state.Since CPU objects have a reliable
cpu_indexwhich is already used asinstance_idin vmstate, let's use it for ICPState as well.Signed-off-by Greg Kurz <[email protected]>--- hw/intc/xics.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)hw/intc/xics.c +0
-0
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 351
Quoted 4 lines
hw/intc/xics.c +1
-0@@ -348,10 +348,14 @@ static void icp_realize(DeviceState *dev, Error **errp) }qemu_register_reset (icp_reset, dev); +vmstate_register (NULL , icp->cs->cpu_index, &vmstate_icp_server, icp);
so, what I just said in the previous email regarding ->cs would break this patch. Forget about it.
Thanks,
C.
Quoted 19 lines
hw/intc/xics.c +3
-1}static void icp_unrealize (DeviceState *dev,Error **errp) { +ICPState *icp =ICP (dev); + +vmstate_unregister (NULL , &vmstate_icp_server, icp);qemu_unregister_reset (icp_reset, dev); }@@ -359,7 +363,6 @@ static void icp_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_icp_server; dc->realize = icp_realize; dc->unrealize = icp_unrealize; }
Re: [Qemu-devel] [PATCH v3 4/5] xics: directly register ICPState objects to vmstate
Quoted 24 lines · On Wed, 7 Jun 2017 20:14:01 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 23 lines · Greg Kurz
The ICPState objects are currently registered to vmstate as qdev objects. Their instance ids are hence computed automatically in the migration code, and thus depends on the order the CPU cores were plugged.
If the destination had its CPU cores plugged in a different order than the source, then ICPState objects will have different
instance_idsand load the wrong state.Since CPU objects have a reliable
cpu_indexwhich is already used asinstance_idin vmstate, let's use it for ICPState as well.Signed-off-by Greg Kurz <[email protected]>--- hw/intc/xics.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)hw/intc/xics.c +0
-0@@ -348,10 +348,14 @@ static void icp_realize(DeviceState *dev, Error **errp) }
Quoted 6 lines
hw/intc/xics.c static void icp_realize(DeviceState *dev, Error **errp) · line 351
Quoted 2 lines
hw/intc/xics.c +1
-0qemu_register_reset (icp_reset, dev); +vmstate_register (NULL , icp->cs->cpu_index, &vmstate_icp_server, icp);so, what I just said in the previous email regarding ->cs would break this patch. Forget about it.
Unless we have an icp->cpu_index like I mentioned in the other mail.
Quoted 27 lines
Reviewed-by Cédric Le Goater <[email protected]>Thanks,
C.
Quoted 19 lines
hw/intc/xics.c +3
-1}static void icp_unrealize (DeviceState *dev,Error **errp) { +ICPState *icp =ICP (dev); + +vmstate_unregister (NULL , &vmstate_icp_server, icp);qemu_unregister_reset (icp_reset, dev); }@@ -359,7 +363,6 @@ static void icp_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_icp_server; dc->realize = icp_realize; dc->unrealize = icp_unrealize; }
Re: [Qemu-devel] [PATCH v3 4/5] xics: directly register ICPState objects to vmstate
In reply to Greg KurzQuoted 8 lines · Greg Kurz
The ICPState objects are currently registered to vmstate as qdev objects. Their instance ids are hence computed automatically in the migration code, and thus depends on the order the CPU cores were plugged.
If the destination had its CPU cores plugged in a different order than the source, then ICPState objects will have different
instance_idsand load the wrong state.
Quoted 7 lines
Since CPU objects have a reliable
cpu_indexwhich is already used asinstance_idin vmstate, let's use it for ICPState as well.Signed-off-by Greg Kurz <[email protected]>--- hw/intc/xics.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
So, this is definitely a good idea w.r.t. future compatibility. But, won't it break migration compat as a once off, since the devices will be found under their new id instead of the qdev id?
Quoted 29 lines
hw/intc/xics.c +4
-1@@ -348,10 +348,14 @@ static void icp_realize(DeviceState *dev, Error **errp) }qemu_register_reset (icp_reset, dev); +vmstate_register (NULL , icp->cs->cpu_index, &vmstate_icp_server, icp); }static void icp_unrealize (DeviceState *dev,Error **errp) { +ICPState *icp =ICP (dev); + +vmstate_unregister (NULL , &vmstate_icp_server, icp);qemu_unregister_reset (icp_reset, dev); }@@ -359,7 +363,6 @@ static void icp_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_icp_server; dc->realize = icp_realize; dc->unrealize = icp_unrealize; }
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
Re: [Qemu-devel] [PATCH v3 4/5] xics: directly register ICPState objects to vmstate
Quoted 12 lines · On Thu, 8 Jun 2017 13:59:21 +1000 David Gibson <[email protected]>…
Quoted 11 lines · Greg Kurz
The ICPState objects are currently registered to vmstate as qdev objects. Their instance ids are hence computed automatically in the migration code, and thus depends on the order the CPU cores were plugged.
If the destination had its CPU cores plugged in a different order than the source, then ICPState objects will have different
instance_idsand load the wrong state.Since CPU objects have a reliable
cpu_indexwhich is already used asinstance_idin vmstate, let's use it for ICPState as well.
Quoted 9 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/intc/xics.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)So, this is definitely a good idea w.r.t. future compatibility. But, won't it break migration compat as a once off, since the devices will be found under their new id instead of the qdev id?
Older machine types used to allocate/realize all ICPState objects at machine init time and never release them. The qdev ids are thus 0,1,2... nr_servers and happen to map to cpu_index.
Quoted 30 lines
Quoted 29 lines
hw/intc/xics.c +4
-1@@ -348,10 +348,14 @@ static void icp_realize(DeviceState *dev, Error **errp) }qemu_register_reset (icp_reset, dev); +vmstate_register (NULL , icp->cs->cpu_index, &vmstate_icp_server, icp); }static void icp_unrealize (DeviceState *dev,Error **errp) { +ICPState *icp =ICP (dev); + +vmstate_unregister (NULL , &vmstate_icp_server, icp);qemu_unregister_reset (icp_reset, dev); }@@ -359,7 +363,6 @@ static void icp_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_icp_server; dc->realize = icp_realize; dc->unrealize = icp_unrealize; }
PATCH v3 5/5 spapr: fix migration of ICPState objects from/to older QEMU
In reply to Greg KurzCommit 5bc8d26de20c ("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICPState objects from the machine to CPU cores. This is an improvement since we no longer allocate ICPState objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions.
This patch allows spapr to register dummy "icp/server" entries to vmstate. These entries use a dedicated VMStateDescription that can swallow and discard state of an incoming migration stream, and that don't send anything on outgoing migration.
As for real ICPState objects, the instance_id is the cpu_index of the corresponding vCPU, which happens to be equal to the generated instance_id of older machine types.
The machine can unregister/register these entries when CPUs are dynamically plugged/unplugged.
This is only available for pseries-2.9 and older machines, thanks to a compat property.
---
v3: - new logic entirely implemented in hw/ppc/spapr.c
--- hw/ppc/spapr.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 2 + 2 files changed, 88 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +86 -2
@@ -124,9 +124,52 @@ error:return NULL ; } +static bool pre_2_10_vmstate_dummy_icp_needed (void *opaque) +{ +return false; +} + +static const VMStateDescription pre_2_10_vmstate_dummy_icp = { + .name ="icp/server" , + .version_id =1 , + .minimum_version_id =1 , + .needed = pre_2_10_vmstate_dummy_icp_needed, + .fields = (VMStateField []) { +VMSTATE_UNUSED (4 ),/* uint32_t xirr */ +VMSTATE_UNUSED (1 ),/* uint8_t pending_priority */ +VMSTATE_UNUSED (1 ),/* uint8_t mfrr */ +VMSTATE_END_OF_LIST () + }, +}; + +static void pre_2_10_vmstate_register_dummy_icp (sPAPRMachineState *spapr,int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (!*flag); +vmstate_register (NULL , i, &pre_2_10_vmstate_dummy_icp, flag); + *flag = true; +} + +static void pre_2_10_vmstate_unregister_dummy_icp (sPAPRMachineState *spapr, +int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (*flag); +vmstate_unregister (NULL , &pre_2_10_vmstate_dummy_icp, flag); + *flag = false; +} + +static inline int xics_nr_servers (void ) +{ +return DIV_ROUND_UP (max_cpus *kvmppc_smt_threads (), smp_threads); +} +static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (machine);if (kvm_enabled ()) { if (machine_kernel_irqchip_allowed(machine) &&
@@ -148,6 +191,15 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)return ; } } + +if (smc->pre_2_10_has_unused_icps) { +int i; + + spapr->pre_2_10_ignore_icp =g_malloc (xics_nr_servers ()); +for (i =0 ; i <xics_nr_servers (); i++) { +pre_2_10_vmstate_register_dummy_icp (spapr, i); + } + } } static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,
@@ -976,7 +1028,6 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,void *fdt;sPAPRPHBState *phb;char *buf; -int smt =kvmppc_smt_threads (); fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));
@@ -1016,7 +1067,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,_FDT (fdt_setprop_cell (fdt,0 ,"#size-cells" ,2 ));/* /interrupt controller */ -spapr_dt_xics (DIV_ROUND_UP (max_cpus * smt, smp_threads), fdt,PHANDLE_XICP ); +spapr_dt_xics (xics_nr_servers (), fdt,PHANDLE_XICP ); ret =spapr_populate_memory (spapr, fdt);if (ret <0 ) {
@@ -2800,9 +2851,24 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (ms);CPUCore *cc =CPU_CORE (dev);CPUArchId *core_slot =spapr_find_cpu_slot (ms, cc->core_id,NULL ); +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +CPUState *cs =CPU (sc->threads + i * size); + +pre_2_10_vmstate_register_dummy_icp (spapr, cs->cpu_index); + } + } +assert (core_slot); core_slot->cpu =NULL ;object_unparent (OBJECT (dev));
@@ -2912,6 +2978,21 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, } } core_slot->cpu =OBJECT (dev); + +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (dev); +void *obj = sc->threads + i * size; + + cs =CPU (obj); +pre_2_10_vmstate_unregister_dummy_icp (spapr, cs->cpu_index); + } + } } static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
@@ -3361,9 +3442,12 @@ static void spapr_machine_2_9_instance_options(MachineState *machine)static void spapr_machine_2_9_class_options (MachineClass *mc) { +sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc); +spapr_machine_2_10_class_options (mc);SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_9 ); mc->numa_auto_assign_ram = numa_legacy_auto_assign_ram; + smc->pre_2_10_has_unused_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);
include/hw/ppc/spapr.h +2 -0
@@ -53,6 +53,7 @@ struct sPAPRMachineClass {bool dr_lmb_enabled;/* enable dynamic-reconfig/hotplug of LMBs */ bool use_ohci_by_default;/* use USB-OHCI instead of XHCI */ const char *tcg_default_cpu;/* which (TCG) CPU to simulate by default */ +bool pre_2_10_has_unused_icps; void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,
@@ -90,6 +91,7 @@ struct sPAPRMachineState {sPAPROptionVector *ov5_cas;/* negotiated (via CAS) option vectors */ bool cas_reboot;bool cas_legacy_guest_workaround; +bool *pre_2_10_ignore_icp;Notifier epow_notifier; QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 34 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICPState objects from the machine to CPU cores. This is an improvement since we no longer allocate ICPState objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions.This patch allows spapr to register dummy "icp/server" entries to vmstate. These entries use a dedicated VMStateDescription that can swallow and discard state of an incoming migration stream, and that don't send anything on outgoing migration.
As for real ICPState objects, the
instance_idis thecpu_indexof the corresponding vCPU, which happens to be equal to the generatedinstance_idof older machine types.The machine can unregister/register these entries when CPUs are dynamically plugged/unplugged.
This is only available for pseries-2.9 and older machines, thanks to a compat property.
Signed-off-by Greg Kurz <[email protected]>---
v3: - new logic entirely implemented inhw/ppc/spapr.c--- hw/ppc/spapr.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 2 + 2 files changed, 88 insertions(+), 2 deletions(-)hw/ppc/spapr.c +0
-0
hw/ppc/spapr.c error: · line 130
Quoted 7 lines
hw/ppc/spapr.c +4
-0@@ -124,9 +124,52 @@ error:return NULL ; } +static bool pre_2_10_vmstate_dummy_icp_needed (void *opaque) +{ +return false; +}
Uh.. the needed function always returns false, how can that work?
Quoted 9 lines
hw/ppc/spapr.c +9
-0+ +static const VMStateDescription pre_2_10_vmstate_dummy_icp = { + .name ="icp/server" , + .version_id =1 , + .minimum_version_id =1 , + .needed = pre_2_10_vmstate_dummy_icp_needed, + .fields = (VMStateField []) { +VMSTATE_UNUSED (4 ),/* uint32_t xirr */ +VMSTATE_UNUSED (1 ),/* uint8_t pending_priority */
hw/ppc/spapr.c error: · line 149
Quoted 10 lines
hw/ppc/spapr.c +10
-0+ VMSTATE_UNUSED(1), /* uint8_t mfrr */ +VMSTATE_END_OF_LIST () + }, +}; + +static void pre_2_10_vmstate_register_dummy_icp (sPAPRMachineState *spapr,int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (!*flag);
Apart from this assert(), you never seem to test the values in the pre_2_10_ignore_icp() array, so it seems a bit pointless.
Quoted 5 lines
hw/ppc/spapr.c +5
-0+vmstate_register (NULL , i, &pre_2_10_vmstate_dummy_icp, flag); + *flag = true; +} + +static void pre_2_10_vmstate_unregister_dummy_icp(sPAPRMachineState *spapr,
hw/ppc/spapr.c error: · line 164
Quoted 10 lines
hw/ppc/spapr.c +10
-0+ int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (*flag); +vmstate_unregister (NULL , &pre_2_10_vmstate_dummy_icp, flag); + *flag = false; +} + +static inline int xics_nr_servers (void )
Maybe a different name to emphasise that this is only used for the backwards compat logic.
Quoted 12 lines
hw/ppc/spapr.c +5
-0+{ +return DIV_ROUND_UP (max_cpus *kvmppc_smt_threads (), smp_threads); +} +static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (machine);if (kvm_enabled ()) { if (machine_kernel_irqchip_allowed(machine) &&
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 200
Quoted 10 lines
hw/ppc/spapr.c +7
-0@@ -148,6 +191,15 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)return ; } } + +if (smc->pre_2_10_has_unused_icps) { +int i; + + spapr->pre_2_10_ignore_icp =g_malloc (xics_nr_servers ()); +for (i =0 ; i <xics_nr_servers (); i++) { +pre_2_10_vmstate_register_dummy_icp (spapr, i);
This registers a dummy ICP for every slot, some of which will have real cpus / icps. That doesn't seem right.
Quoted 103 lines
hw/ppc/spapr.c +36
-2+ } + } } static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,@@ -976,7 +1028,6 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,void *fdt;sPAPRPHBState *phb;char *buf; -int smt =kvmppc_smt_threads (); fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -1016,7 +1067,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,_FDT (fdt_setprop_cell (fdt,0 ,"#size-cells" ,2 ));/* /interrupt controller */ -spapr_dt_xics (DIV_ROUND_UP (max_cpus * smt, smp_threads), fdt,PHANDLE_XICP ); +spapr_dt_xics (xics_nr_servers (), fdt,PHANDLE_XICP ); ret =spapr_populate_memory (spapr, fdt);if (ret <0 ) {@@ -2800,9 +2851,24 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (ms);CPUCore *cc =CPU_CORE (dev);CPUArchId *core_slot =spapr_find_cpu_slot (ms, cc->core_id,NULL ); +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +CPUState *cs =CPU (sc->threads + i * size); + +pre_2_10_vmstate_register_dummy_icp (spapr, cs->cpu_index); + } + } +assert (core_slot); core_slot->cpu =NULL ;object_unparent (OBJECT (dev));@@ -2912,6 +2978,21 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, } } core_slot->cpu =OBJECT (dev); + +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (dev); +void *obj = sc->threads + i * size; + + cs =CPU (obj); +pre_2_10_vmstate_unregister_dummy_icp (spapr, cs->cpu_index); + } + } } static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,@@ -3361,9 +3442,12 @@ static void spapr_machine_2_9_instance_options(MachineState *machine)static void spapr_machine_2_9_class_options (MachineClass *mc) { +sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc); +spapr_machine_2_10_class_options (mc);SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_9 ); mc->numa_auto_assign_ram = numa_legacy_auto_assign_ram; + smc->pre_2_10_has_unused_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);include/hw/ppc/spapr.h +2
-0@@ -53,6 +53,7 @@ struct sPAPRMachineClass {bool dr_lmb_enabled;/* enable dynamic-reconfig/hotplug of LMBs */ bool use_ohci_by_default;/* use USB-OHCI instead of XHCI */ const char *tcg_default_cpu;/* which (TCG) CPU to simulate by default */ +bool pre_2_10_has_unused_icps; void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,@@ -90,6 +91,7 @@ struct sPAPRMachineState {sPAPROptionVector *ov5_cas;/* negotiated (via CAS) option vectors */ bool cas_reboot;bool cas_legacy_guest_workaround; +bool *pre_2_10_ignore_icp;Notifier epow_notifier; QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
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
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 38 lines · On Thu, 8 Jun 2017 14:08:57 +1000 David Gibson <[email protected]>…
Quoted 37 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICPState objects from the machine to CPU cores. This is an improvement since we no longer allocate ICPState objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions.This patch allows spapr to register dummy "icp/server" entries to vmstate. These entries use a dedicated VMStateDescription that can swallow and discard state of an incoming migration stream, and that don't send anything on outgoing migration.
As for real ICPState objects, the
instance_idis thecpu_indexof the corresponding vCPU, which happens to be equal to the generatedinstance_idof older machine types.The machine can unregister/register these entries when CPUs are dynamically plugged/unplugged.
This is only available for pseries-2.9 and older machines, thanks to a compat property.
Signed-off-by Greg Kurz <[email protected]>---
v3: - new logic entirely implemented inhw/ppc/spapr.c--- hw/ppc/spapr.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 2 + 2 files changed, 88 insertions(+), 2 deletions(-)hw/ppc/spapr.c +0
-0@@ -124,9 +124,52 @@ error:return NULL ; }
Quoted 7 lines
hw/ppc/spapr.c error: · line 130
Quoted 4 lines
hw/ppc/spapr.c +4
-0+static bool pre_2_10_vmstate_dummy_icp_needed (void *opaque) +{ +return false; +}Uh.. the needed function always returns false, how can that work?
The needed function is used for outgoing migration only:
bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque)
{
if (vmsd->needed && !vmsd->needed(opaque)) {
/* optional section not needed */
return false;
}
return true;
}The idea is that all ICPState objects that were created but not associated to a vCPU by pre-2.10 machine types don't need to be migrated at all, as their state hasn't changed.
We don't even create these unneeded ICPState objects here, but simply register their ids to vmstate.
Quoted 6 lines
hw/ppc/spapr.c error: · line 136
Quoted 6 lines
hw/ppc/spapr.c +6
-0+ +static const VMStateDescription pre_2_10_vmstate_dummy_icp = { + .name ="icp/server" , + .version_id =1 , + .minimum_version_id =1 , + .needed = pre_2_10_vmstate_dummy_icp_needed,
Outgoing migration:
- machine in older QEMU have unused ICPState objects (default state)
- machine in QEMU 2.10 doesn't even have extra ICPState objects
=> don't send anything
Quoted 4 lines
hw/ppc/spapr.c error: · line 140
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ .fields = (VMStateField[]) { +VMSTATE_UNUSED (4 ),/* uint32_t xirr */ +VMSTATE_UNUSED (1 ),/* uint8_t pending_priority */ +VMSTATE_UNUSED (1 ),/* uint8_t mfrr */
Incoming migration from older QEMU: we don't have the extra ICPState objects.
=> accept the state and discard it
Quoted 4 lines
Quoted 4 lines
hw/ppc/spapr.c +4
-0+VMSTATE_END_OF_LIST () + }, +}; +
Quoted 9 lines
hw/ppc/spapr.c error: · line 149
Quoted 5 lines
hw/ppc/spapr.c +5
-0+static void pre_2_10_vmstate_register_dummy_icp (sPAPRMachineState *spapr,int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.
There's the opposite check in pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)
Quoted 10 lines
Quoted 10 lines
hw/ppc/spapr.c +10
-0+vmstate_register (NULL , i, &pre_2_10_vmstate_dummy_icp, flag); + *flag = true; +} + +static void pre_2_10_vmstate_unregister_dummy_icp (sPAPRMachineState *spapr, +int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (*flag);
Quoted 9 lines
hw/ppc/spapr.c error: · line 164
Quoted 5 lines
hw/ppc/spapr.c +5
-0+vmstate_unregister (NULL , &pre_2_10_vmstate_dummy_icp, flag); + *flag = false; +} + +static inline int xics_nr_servers (void )Maybe a different name to emphasise that this is only used for the backwards compat logic.
It is also used to compute the "ibm,interrupt-server-ranges" DT prop.
/* /interrupt controller */
spapr_dt_xics(xics_nr_servers(), fdt, PHANDLE_XICP);Quoted 9 lines
Quoted 9 lines
hw/ppc/spapr.c +5
-0+{ +return DIV_ROUND_UP (max_cpus *kvmppc_smt_threads (), smp_threads); +} +static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (machine);
Quoted 17 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 200
Quoted 13 lines
hw/ppc/spapr.c +7
-0if (kvm_enabled ()) { if (machine_kernel_irqchip_allowed(machine) &&@@ -148,6 +191,15 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)return ; } } + +if (smc->pre_2_10_has_unused_icps) { +int i; + + spapr->pre_2_10_ignore_icp =g_malloc (xics_nr_servers ()); +for (i =0 ; i <xics_nr_servers (); i++) { +pre_2_10_vmstate_register_dummy_icp (spapr, i);This registers a dummy ICP for every slot, some of which will have real cpus / icps. That doesn't seem right.
This is initialization, before we even have actual CPUs. We start with dummy ICPs for every slot, but they get replaced by real ICPs when we plug CPU cores...... (see below)
Quoted 56 lines
Quoted 56 lines
hw/ppc/spapr.c +23
-2+ } + } } static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,@@ -976,7 +1028,6 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,void *fdt;sPAPRPHBState *phb;char *buf; -int smt =kvmppc_smt_threads (); fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -1016,7 +1067,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,_FDT (fdt_setprop_cell (fdt,0 ,"#size-cells" ,2 ));/* /interrupt controller */ -spapr_dt_xics (DIV_ROUND_UP (max_cpus * smt, smp_threads), fdt,PHANDLE_XICP ); +spapr_dt_xics (xics_nr_servers (), fdt,PHANDLE_XICP ); ret =spapr_populate_memory (spapr, fdt);if (ret <0 ) {@@ -2800,9 +2851,24 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (ms);CPUCore *cc =CPU_CORE (dev);CPUArchId *core_slot =spapr_find_cpu_slot (ms, cc->core_id,NULL ); +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +CPUState *cs =CPU (sc->threads + i * size); + +pre_2_10_vmstate_register_dummy_icp (spapr, cs->cpu_index); + } + } +assert (core_slot); core_slot->cpu =NULL ;object_unparent (OBJECT (dev));@@ -2912,6 +2978,21 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, } } core_slot->cpu =OBJECT (dev); + +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename);
Quoted 8 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 2993
Quoted 8 lines
hw/ppc/spapr.c +8
-0+int i; + +for (i =0 ; i < cc->nr_threads; i++) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (dev); +void *obj = sc->threads + i * size; + + cs =CPU (obj); +pre_2_10_vmstate_unregister_dummy_icp (spapr, cs->cpu_index);
...... here.
The opposite happens in spapr_core_unplug().
Quoted 40 lines
Quoted 39 lines
hw/ppc/spapr.c +5
-0+ } + } } static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,@@ -3361,9 +3442,12 @@ static void spapr_machine_2_9_instance_options(MachineState *machine)static void spapr_machine_2_9_class_options (MachineClass *mc) { +sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc); +spapr_machine_2_10_class_options (mc);SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_9 ); mc->numa_auto_assign_ram = numa_legacy_auto_assign_ram; + smc->pre_2_10_has_unused_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);include/hw/ppc/spapr.h +2
-0@@ -53,6 +53,7 @@ struct sPAPRMachineClass {bool dr_lmb_enabled;/* enable dynamic-reconfig/hotplug of LMBs */ bool use_ohci_by_default;/* use USB-OHCI instead of XHCI */ const char *tcg_default_cpu;/* which (TCG) CPU to simulate by default */ +bool pre_2_10_has_unused_icps; void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,@@ -90,6 +91,7 @@ struct sPAPRMachineState {sPAPROptionVector *ov5_cas;/* negotiated (via CAS) option vectors */ bool cas_reboot;bool cas_legacy_guest_workaround; +bool *pre_2_10_ignore_icp;Notifier epow_notifier; QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 103 lines · Greg Kurz
Quoted 38 lines · On Thu, 8 Jun 2017 14:08:57 +1000 David Gibson <[email protected]>…
Quoted 37 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICPState objects from the machine to CPU cores. This is an improvement since we no longer allocate ICPState objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions.This patch allows spapr to register dummy "icp/server" entries to vmstate. These entries use a dedicated VMStateDescription that can swallow and discard state of an incoming migration stream, and that don't send anything on outgoing migration.
As for real ICPState objects, the
instance_idis thecpu_indexof the corresponding vCPU, which happens to be equal to the generatedinstance_idof older machine types.The machine can unregister/register these entries when CPUs are dynamically plugged/unplugged.
This is only available for pseries-2.9 and older machines, thanks to a compat property.
Signed-off-by Greg Kurz <[email protected]>---
v3: - new logic entirely implemented inhw/ppc/spapr.c--- hw/ppc/spapr.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 2 + 2 files changed, 88 insertions(+), 2 deletions(-)hw/ppc/spapr.c +0
-0@@ -124,9 +124,52 @@ error:return NULL ; }Quoted 7 lines
hw/ppc/spapr.c error: · line 130
Quoted 4 lines
hw/ppc/spapr.c +4
-0+static bool pre_2_10_vmstate_dummy_icp_needed (void *opaque) +{ +return false; +}Uh.. the needed function always returns false, how can that work?
The needed function is used for outgoing migration only:
bool
vmstate_save_needed(const VMStateDescription *vmsd, void *opaque){ if (vmsd->needed && !vmsd->needed(opaque)) { /* optional section not needed */ return false; } return true; }The idea is that all ICPState objects that were created but not associated to a vCPU by pre-2.10 machine types don't need to be migrated at all, as their state hasn't changed.
We don't even create these unneeded ICPState objects here, but simply register their ids to vmstate.
Quoted 6 lines
hw/ppc/spapr.c error: · line 136
Quoted 6 lines
hw/ppc/spapr.c +6
-0+ +static const VMStateDescription pre_2_10_vmstate_dummy_icp = { + .name ="icp/server" , + .version_id =1 , + .minimum_version_id =1 , + .needed = pre_2_10_vmstate_dummy_icp_needed,Outgoing migration:
- machine in older QEMU have unused ICPState objects (default state)
- machine in QEMU 2.10 doesn't even have extra ICPState objects=> don't send anything
Quoted 4 lines
hw/ppc/spapr.c error: · line 140
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ .fields = (VMStateField[]) { +VMSTATE_UNUSED (4 ),/* uint32_t xirr */ +VMSTATE_UNUSED (1 ),/* uint8_t pending_priority */ +VMSTATE_UNUSED (1 ),/* uint8_t mfrr */ Incoming migration from older QEMU: we don't have the extra ICPState objects.
=> accept the state and discard it
Quoted 4 lines
Quoted 4 lines
hw/ppc/spapr.c +4
-0+VMSTATE_END_OF_LIST () + }, +}; +Quoted 9 lines
hw/ppc/spapr.c error: · line 149
Quoted 5 lines
hw/ppc/spapr.c +5
-0+static void pre_2_10_vmstate_register_dummy_icp (sPAPRMachineState *spapr,int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)
I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an assert() later, not so much.
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
hw/ppc/spapr.c +10
-0+vmstate_register (NULL , i, &pre_2_10_vmstate_dummy_icp, flag); + *flag = true; +} + +static void pre_2_10_vmstate_unregister_dummy_icp (sPAPRMachineState *spapr, +int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (*flag);Quoted 9 lines
hw/ppc/spapr.c error: · line 164
Quoted 5 lines
hw/ppc/spapr.c +5
-0+vmstate_unregister (NULL , &pre_2_10_vmstate_dummy_icp, flag); + *flag = false; +} + +static inline int xics_nr_servers (void )Maybe a different name to emphasise that this is only used for the backwards compat logic.
Quoted 4 lines
It is also used to compute the "ibm,interrupt-server-ranges" DT prop.
/* /interrupt controller */ spapr_dt_xics(xics_nr_servers(), fdt, PHANDLE_XICP);
Ah, good point. Maybe rename to "max server number" or something, since "nr_servers" isn't really accurate any more.
Quoted 141 lines
Quoted 9 lines
Quoted 9 lines
hw/ppc/spapr.c +5
-0+{ +return DIV_ROUND_UP (max_cpus *kvmppc_smt_threads (), smp_threads); +} +static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (machine);Quoted 17 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 200
Quoted 13 lines
hw/ppc/spapr.c +7
-0if (kvm_enabled ()) { if (machine_kernel_irqchip_allowed(machine) &&@@ -148,6 +191,15 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)return ; } } + +if (smc->pre_2_10_has_unused_icps) { +int i; + + spapr->pre_2_10_ignore_icp =g_malloc (xics_nr_servers ()); +for (i =0 ; i <xics_nr_servers (); i++) { +pre_2_10_vmstate_register_dummy_icp (spapr, i);This registers a dummy ICP for every slot, some of which will have real cpus / icps. That doesn't seem right.
This is initialization, before we even have actual CPUs. We start with dummy ICPs for every slot, but they get replaced by real ICPs when we plug CPU cores...... (see below)
Quoted 56 lines
Quoted 56 lines
hw/ppc/spapr.c +23
-2+ } + } } static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,@@ -976,7 +1028,6 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,void *fdt;sPAPRPHBState *phb;char *buf; -int smt =kvmppc_smt_threads (); fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -1016,7 +1067,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,_FDT (fdt_setprop_cell (fdt,0 ,"#size-cells" ,2 ));/* /interrupt controller */ -spapr_dt_xics (DIV_ROUND_UP (max_cpus * smt, smp_threads), fdt,PHANDLE_XICP ); +spapr_dt_xics (xics_nr_servers (), fdt,PHANDLE_XICP ); ret =spapr_populate_memory (spapr, fdt);if (ret <0 ) {@@ -2800,9 +2851,24 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (ms);CPUCore *cc =CPU_CORE (dev);CPUArchId *core_slot =spapr_find_cpu_slot (ms, cc->core_id,NULL ); +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +CPUState *cs =CPU (sc->threads + i * size); + +pre_2_10_vmstate_register_dummy_icp (spapr, cs->cpu_index); + } + } +assert (core_slot); core_slot->cpu =NULL ;object_unparent (OBJECT (dev));@@ -2912,6 +2978,21 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, } } core_slot->cpu =OBJECT (dev); + +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename);Quoted 8 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 2993
Quoted 8 lines
hw/ppc/spapr.c +8
-0+int i; + +for (i =0 ; i < cc->nr_threads; i++) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (dev); +void *obj = sc->threads + i * size; + + cs =CPU (obj); +pre_2_10_vmstate_unregister_dummy_icp (spapr, cs->cpu_index);...... here.
The opposite happens in
spapr_core_unplug().Quoted 40 lines
Quoted 39 lines
hw/ppc/spapr.c +5
-0+ } + } } static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,@@ -3361,9 +3442,12 @@ static void spapr_machine_2_9_instance_options(MachineState *machine)static void spapr_machine_2_9_class_options (MachineClass *mc) { +sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc); +spapr_machine_2_10_class_options (mc);SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_9 ); mc->numa_auto_assign_ram = numa_legacy_auto_assign_ram; + smc->pre_2_10_has_unused_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);include/hw/ppc/spapr.h +2
-0@@ -53,6 +53,7 @@ struct sPAPRMachineClass {bool dr_lmb_enabled;/* enable dynamic-reconfig/hotplug of LMBs */ bool use_ohci_by_default;/* use USB-OHCI instead of XHCI */ const char *tcg_default_cpu;/* which (TCG) CPU to simulate by default */ +bool pre_2_10_has_unused_icps; void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,@@ -90,6 +91,7 @@ struct sPAPRMachineState {sPAPROptionVector *ov5_cas;/* negotiated (via CAS) option vectors */ bool cas_reboot;bool cas_legacy_guest_workaround; +bool *pre_2_10_ignore_icp;Notifier epow_notifier; QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
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
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 104 lines · On Mon, 12 Jun 2017 22:24:56 +0800 David Gibson <[email protected]>…
Quoted 103 lines · Greg Kurz
Quoted 38 lines · On Thu, 8 Jun 2017 14:08:57 +1000 David Gibson <[email protected]>…
Quoted 37 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICPState objects from the machine to CPU cores. This is an improvement since we no longer allocate ICPState objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions.This patch allows spapr to register dummy "icp/server" entries to vmstate. These entries use a dedicated VMStateDescription that can swallow and discard state of an incoming migration stream, and that don't send anything on outgoing migration.
As for real ICPState objects, the
instance_idis thecpu_indexof the corresponding vCPU, which happens to be equal to the generatedinstance_idof older machine types.The machine can unregister/register these entries when CPUs are dynamically plugged/unplugged.
This is only available for pseries-2.9 and older machines, thanks to a compat property.
Signed-off-by Greg Kurz <[email protected]>---
v3: - new logic entirely implemented inhw/ppc/spapr.c--- hw/ppc/spapr.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 2 + 2 files changed, 88 insertions(+), 2 deletions(-)hw/ppc/spapr.c +0
-0@@ -124,9 +124,52 @@ error:return NULL ; }Quoted 7 lines
hw/ppc/spapr.c error: · line 130
Quoted 4 lines
hw/ppc/spapr.c +4
-0+static bool pre_2_10_vmstate_dummy_icp_needed (void *opaque) +{ +return false; +}Uh.. the needed function always returns false, how can that work?
The needed function is used for outgoing migration only:
bool
vmstate_save_needed(const VMStateDescription *vmsd, void *opaque){ if (vmsd->needed && !vmsd->needed(opaque)) { /* optional section not needed */ return false; } return true; }The idea is that all ICPState objects that were created but not associated to a vCPU by pre-2.10 machine types don't need to be migrated at all, as their state hasn't changed.
We don't even create these unneeded ICPState objects here, but simply register their ids to vmstate.
Quoted 6 lines
hw/ppc/spapr.c error: · line 136
Quoted 6 lines
hw/ppc/spapr.c +6
-0+ +static const VMStateDescription pre_2_10_vmstate_dummy_icp = { + .name ="icp/server" , + .version_id =1 , + .minimum_version_id =1 , + .needed = pre_2_10_vmstate_dummy_icp_needed,Outgoing migration:
- machine in older QEMU have unused ICPState objects (default state)
- machine in QEMU 2.10 doesn't even have extra ICPState objects=> don't send anything
Quoted 4 lines
hw/ppc/spapr.c error: · line 140
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ .fields = (VMStateField[]) { +VMSTATE_UNUSED (4 ),/* uint32_t xirr */ +VMSTATE_UNUSED (1 ),/* uint8_t pending_priority */ +VMSTATE_UNUSED (1 ),/* uint8_t mfrr */ Incoming migration from older QEMU: we don't have the extra ICPState objects.
=> accept the state and discard it
Quoted 13 lines
hw/ppc/spapr.c error: · line 149
Quoted 9 lines
hw/ppc/spapr.c +9
-0+VMSTATE_END_OF_LIST () + }, +}; + +static void pre_2_10_vmstate_register_dummy_icp (sPAPRMachineState *spapr,int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.
Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.
It is also passed as opaque argument to vmstate_register(), where it is used as a key when calling vmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 5 lines
hw/ppc/spapr.c +5
-0+vmstate_register (NULL , i, &pre_2_10_vmstate_dummy_icp, flag); + *flag = true; +} + +static void pre_2_10_vmstate_unregister_dummy_icp(sPAPRMachineState *spapr,hw/ppc/spapr.c error: · line 164
Quoted 10 lines
hw/ppc/spapr.c +10
-0+ int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (*flag); +vmstate_unregister (NULL , &pre_2_10_vmstate_dummy_icp, flag); + *flag = false; +} + +static inline int xics_nr_servers (void )Maybe a different name to emphasise that this is only used for the backwards compat logic.
Quoted 8 lines
Quoted 4 lines
It is also used to compute the "ibm,interrupt-server-ranges" DT prop.
/* /interrupt controller */ spapr_dt_xics(xics_nr_servers(), fdt, PHANDLE_XICP);Ah, good point. Maybe rename to "max server number" or something, since "
nr_servers" isn't really accurate any more.
Sure, I'll do that.
Quoted 144 lines
Quoted 141 lines
Quoted 9 lines
Quoted 9 lines
hw/ppc/spapr.c +5
-0+{ +return DIV_ROUND_UP (max_cpus *kvmppc_smt_threads (), smp_threads); +} +static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (machine);Quoted 17 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 200
Quoted 13 lines
hw/ppc/spapr.c +7
-0if (kvm_enabled ()) { if (machine_kernel_irqchip_allowed(machine) &&@@ -148,6 +191,15 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)return ; } } + +if (smc->pre_2_10_has_unused_icps) { +int i; + + spapr->pre_2_10_ignore_icp =g_malloc (xics_nr_servers ()); +for (i =0 ; i <xics_nr_servers (); i++) { +pre_2_10_vmstate_register_dummy_icp (spapr, i);This registers a dummy ICP for every slot, some of which will have real cpus / icps. That doesn't seem right.
This is initialization, before we even have actual CPUs. We start with dummy ICPs for every slot, but they get replaced by real ICPs when we plug CPU cores...... (see below)
Quoted 56 lines
Quoted 56 lines
hw/ppc/spapr.c +23
-2+ } + } } static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,@@ -976,7 +1028,6 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,void *fdt;sPAPRPHBState *phb;char *buf; -int smt =kvmppc_smt_threads (); fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -1016,7 +1067,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,_FDT (fdt_setprop_cell (fdt,0 ,"#size-cells" ,2 ));/* /interrupt controller */ -spapr_dt_xics (DIV_ROUND_UP (max_cpus * smt, smp_threads), fdt,PHANDLE_XICP ); +spapr_dt_xics (xics_nr_servers (), fdt,PHANDLE_XICP ); ret =spapr_populate_memory (spapr, fdt);if (ret <0 ) {@@ -2800,9 +2851,24 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (ms);CPUCore *cc =CPU_CORE (dev);CPUArchId *core_slot =spapr_find_cpu_slot (ms, cc->core_id,NULL ); +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +CPUState *cs =CPU (sc->threads + i * size); + +pre_2_10_vmstate_register_dummy_icp (spapr, cs->cpu_index); + } + } +assert (core_slot); core_slot->cpu =NULL ;object_unparent (OBJECT (dev));@@ -2912,6 +2978,21 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, } } core_slot->cpu =OBJECT (dev); + +if (spapr->pre_2_10_ignore_icp) { +sPAPRCPUCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (OBJECT (cc)); +const char *typename =object_class_get_name (scc->cpu_class); +size_t size =object_type_get_instance_size (typename);Quoted 8 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 2993
Quoted 8 lines
hw/ppc/spapr.c +8
-0+int i; + +for (i =0 ; i < cc->nr_threads; i++) { +sPAPRCPUCore *sc =SPAPR_CPU_CORE (dev); +void *obj = sc->threads + i * size; + + cs =CPU (obj); +pre_2_10_vmstate_unregister_dummy_icp (spapr, cs->cpu_index);...... here.
The opposite happens in
spapr_core_unplug().Quoted 40 lines
Quoted 39 lines
hw/ppc/spapr.c +5
-0+ } + } } static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,@@ -3361,9 +3442,12 @@ static void spapr_machine_2_9_instance_options(MachineState *machine)static void spapr_machine_2_9_class_options (MachineClass *mc) { +sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc); +spapr_machine_2_10_class_options (mc);SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_9 ); mc->numa_auto_assign_ram = numa_legacy_auto_assign_ram; + smc->pre_2_10_has_unused_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);include/hw/ppc/spapr.h +2
-0@@ -53,6 +53,7 @@ struct sPAPRMachineClass {bool dr_lmb_enabled;/* enable dynamic-reconfig/hotplug of LMBs */ bool use_ohci_by_default;/* use USB-OHCI instead of XHCI */ const char *tcg_default_cpu;/* which (TCG) CPU to simulate by default */ +bool pre_2_10_has_unused_icps; void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,@@ -90,6 +91,7 @@ struct sPAPRMachineState {sPAPROptionVector *ov5_cas;/* negotiated (via CAS) option vectors */ bool cas_reboot;bool cas_legacy_guest_workaround; +bool *pre_2_10_ignore_icp;Notifier epow_notifier; QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 115 lines · Greg Kurz
Quoted 104 lines · On Mon, 12 Jun 2017 22:24:56 +0800 David Gibson <[email protected]>…
Quoted 103 lines · Greg Kurz
Quoted 38 lines · On Thu, 8 Jun 2017 14:08:57 +1000 David Gibson <[email protected]>…
Quoted 37 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICPState objects from the machine to CPU cores. This is an improvement since we no longer allocate ICPState objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions.This patch allows spapr to register dummy "icp/server" entries to vmstate. These entries use a dedicated VMStateDescription that can swallow and discard state of an incoming migration stream, and that don't send anything on outgoing migration.
As for real ICPState objects, the
instance_idis thecpu_indexof the corresponding vCPU, which happens to be equal to the generatedinstance_idof older machine types.The machine can unregister/register these entries when CPUs are dynamically plugged/unplugged.
This is only available for pseries-2.9 and older machines, thanks to a compat property.
Signed-off-by Greg Kurz <[email protected]>---
v3: - new logic entirely implemented inhw/ppc/spapr.c--- hw/ppc/spapr.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 2 + 2 files changed, 88 insertions(+), 2 deletions(-)hw/ppc/spapr.c +0
-0@@ -124,9 +124,52 @@ error:return NULL ; }Quoted 7 lines
hw/ppc/spapr.c error: · line 130
Quoted 4 lines
hw/ppc/spapr.c +4
-0+static bool pre_2_10_vmstate_dummy_icp_needed (void *opaque) +{ +return false; +}Uh.. the needed function always returns false, how can that work?
The needed function is used for outgoing migration only:
bool
vmstate_save_needed(const VMStateDescription *vmsd, void *opaque){ if (vmsd->needed && !vmsd->needed(opaque)) { /* optional section not needed */ return false; } return true; }The idea is that all ICPState objects that were created but not associated to a vCPU by pre-2.10 machine types don't need to be migrated at all, as their state hasn't changed.
We don't even create these unneeded ICPState objects here, but simply register their ids to vmstate.
Quoted 6 lines
hw/ppc/spapr.c error: · line 136
Quoted 6 lines
hw/ppc/spapr.c +6
-0+ +static const VMStateDescription pre_2_10_vmstate_dummy_icp = { + .name ="icp/server" , + .version_id =1 , + .minimum_version_id =1 , + .needed = pre_2_10_vmstate_dummy_icp_needed,Outgoing migration:
- machine in older QEMU have unused ICPState objects (default state)
- machine in QEMU 2.10 doesn't even have extra ICPState objects=> don't send anything
Quoted 4 lines
hw/ppc/spapr.c error: · line 140
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ .fields = (VMStateField[]) { +VMSTATE_UNUSED (4 ),/* uint32_t xirr */ +VMSTATE_UNUSED (1 ),/* uint8_t pending_priority */ +VMSTATE_UNUSED (1 ),/* uint8_t mfrr */ Incoming migration from older QEMU: we don't have the extra ICPState objects.
=> accept the state and discard it
Quoted 13 lines
hw/ppc/spapr.c error: · line 149
Quoted 9 lines
hw/ppc/spapr.c +9
-0+VMSTATE_END_OF_LIST () + }, +}; + +static void pre_2_10_vmstate_register_dummy_icp (sPAPRMachineState *spapr,int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.
Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.
Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the cpu_index / XICS server number makes sense to identify the vmstate, but it looks like vmstate_unregister() doesn't take that.
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
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 23 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
hw/ppc/spapr.c error: · line 149
Quoted 5 lines
hw/ppc/spapr.c +5
-0+static void pre_2_10_vmstate_register_dummy_icp (sPAPRMachineState *spapr,int i) +{ +bool *flag = &spapr->pre_2_10_ignore_icp[i]; + +g_assert (!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.
Quoted 5 lines
Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.
Indeed... what about adding a vmstate_unregister_by_instance_id() then ?
Cc'ing Juan and David.
--
Greg
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 23 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Quoted 5 lines
Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ? It's simple, as long as you're not actually using the opaque anywhere it's easy.
Note from a quick glance at your patch; will this work migrating from this 2.10 -> 2.9 ? Are your dummy vmstate's really good enough for the 2.9 ?
Dave
Quoted 2 lines
--
Greg
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 35 lines · On Tue, 13 Jun 2017 10:00:03 +0100 "Dr. David Alan Gilbert"…
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 28 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.
Quoted 5 lines
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ?
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.
but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Quoted 4 lines
Note from a quick glance at your patch; will this work migrating from this 2.10 -> 2.9 ? Are your dummy vmstate's really good enough for the 2.9 ?
Yeah but I need to add some comments as David suggested.
The idea is that 2.9 used to create a bunch of objects at machine init, that only get used when CPUs are plugged. With 2.10, these objects are now created under the CPUs. When migrating from 2.10 to 2.9, we only need to send the real objects. The dummy vmstate entries don't send anything (.needed always returns false) since the corresponding objects in 2.9 aren't being used and still have their default state.
Quoted 9 lines
Dave
Quoted 2 lines
--
Greg--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 44 lines · * Greg Kurz ([email protected]) wrote:
Quoted 35 lines · On Tue, 13 Jun 2017 10:00:03 +0100 "Dr. David Alan Gilbert"…
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 28 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.Quoted 5 lines
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ?
Quoted 8 lines
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Yes, I don't think we're ever casting back from the (void *) to an int so it feels pretty safe to me.
Quoted 6 lines
Quoted 5 lines
Note from a quick glance at your patch; will this work migrating from this 2.10 -> 2.9 ? Are your dummy vmstate's really good enough for the 2.9 ?
Quoted 9 lines
Yeah but I need to add some comments as David suggested.
The idea is that 2.9 used to create a bunch of objects at machine init, that only get used when CPUs are plugged. With 2.10, these objects are now created under the CPUs. When migrating from 2.10 to 2.9, we only need to send the real objects. The dummy vmstate entries don't send anything (.needed always returns false) since the corresponding objects in 2.9 aren't being used and still have their default state.
OK, that'll probably work.
Dave
Quoted 10 lines
Quoted 9 lines
Dave
Quoted 2 lines
--
Greg--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 51 lines · On Tue, 13 Jun 2017 10:55:50 +0100 "Dr. David Alan Gilbert"…
Quoted 50 lines · * Greg Kurz ([email protected]) wrote:
Quoted 35 lines · On Tue, 13 Jun 2017 10:00:03 +0100 "Dr. David Alan Gilbert"…
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 28 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.Quoted 5 lines
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ?
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.
Quoted 6 lines
Quoted 2 lines
but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Yes, I don't think we're ever casting back from the (void *) to an int so it feels pretty safe to me.
Just one nit, gcc doesn't like it on 64-bit hosts:
hw/ppc/spapr.c: In function ‘pre_2_10_vmstate_register_dummy_icp’:hw/ppc/spapr.c:148:60: error: cast to pointer from integer of different
size [-Werror=int-to-pointer-cast]
vmstate_register(NULL, i, &pre_2_10_vmstate_dummy_icp, (void *) i);
I need to cast to (long) first.
Quoted 16 lines
Quoted 6 lines
Quoted 5 lines
Note from a quick glance at your patch; will this work migrating from this 2.10 -> 2.9 ? Are your dummy vmstate's really good enough for the 2.9 ?
Quoted 9 lines
Yeah but I need to add some comments as David suggested.
The idea is that 2.9 used to create a bunch of objects at machine init, that only get used when CPUs are plugged. With 2.10, these objects are now created under the CPUs. When migrating from 2.10 to 2.9, we only need to send the real objects. The dummy vmstate entries don't send anything (.needed always returns false) since the corresponding objects in 2.9 aren't being used and still have their default state.
Quoted 2 lines
OK, that'll probably work.
Thanks for this confirmation.
Quoted 16 lines
Dave
Quoted 10 lines
Quoted 9 lines
Dave
Quoted 2 lines
--
Greg--
Dr. David Alan Gilbert / [email protected] / Manchester, UK--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 61 lines · * Greg Kurz ([email protected]) wrote:
Quoted 51 lines · On Tue, 13 Jun 2017 10:55:50 +0100 "Dr. David Alan Gilbert"…
Quoted 50 lines · * Greg Kurz ([email protected]) wrote:
Quoted 35 lines · On Tue, 13 Jun 2017 10:00:03 +0100 "Dr. David Alan Gilbert"…
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 28 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.Quoted 5 lines
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ?
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.Quoted 6 lines
Quoted 2 lines
but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Yes, I don't think we're ever casting back from the (void *) to an int so it feels pretty safe to me.
Quoted 8 lines
Just one nit, gcc doesn't like it on 64-bit hosts:
hw/ppc/spapr.c: In function ‘pre_2_10_vmstate_register_dummy_icp’:hw/ppc/spapr.c:148:60: error: cast to pointer from integer of different
size [-Werror=int-to-pointer-cast]vmstate_register(NULL, i, &pre_2_10_vmstate_dummy_icp, (void *) i);I need to cast to (long) first.
Try casting to a uintptr_t first.
Dave
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 5 lines
Note from a quick glance at your patch; will this work migrating from this 2.10 -> 2.9 ? Are your dummy vmstate's really good enough for the 2.9 ?
Yeah but I need to add some comments as David suggested.
The idea is that 2.9 used to create a bunch of objects at machine init, that only get used when CPUs are plugged. With 2.10, these objects are now created under the CPUs. When migrating from 2.10 to 2.9, we only need to send the real objects. The dummy vmstate entries don't send anything (.needed always returns false) since the corresponding objects in 2.9 aren't being used and still have their default state.
Quoted 22 lines
Quoted 2 lines
OK, that'll probably work.
Thanks for this confirmation.
Quoted 16 lines
Dave
Quoted 10 lines
Quoted 9 lines
Dave
Quoted 2 lines
--
Greg--
Dr. David Alan Gilbert / [email protected] / Manchester, UK--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
On Tue, 13 Jun 2017 11:12:17 +0100
"Dr. David Alan Gilbert" <[email protected]> wrote:
[...]
Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
So what's the problem with a (void *)i ?
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.Quoted 6 lines
Quoted 2 lines
but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Yes, I don't think we're ever casting back from the (void *) to an int so it feels pretty safe to me.
Just one nit, gcc doesn't like it on 64-bit hosts:
Quoted 9 lines
Quoted 6 lines
hw/ppc/spapr.c: In function ‘pre_2_10_vmstate_register_dummy_icp’:hw/ppc/spapr.c:148:60: error: cast to pointer from integer of different
size [-Werror=int-to-pointer-cast]vmstate_register(NULL, i, &pre_2_10_vmstate_dummy_icp, (void *) i);I need to cast to (long) first.
Try casting to a
uintptr_tfirst.
Yeah, you're right. The standard doesn't guarantees whether pointers have the size of int or long. I'll use intptr_t.
Thanks for the suggestion.
Quoted 44 lines
Dave
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 5 lines
Note from a quick glance at your patch; will this work migrating from this 2.10 -> 2.9 ? Are your dummy vmstate's really good enough for the 2.9 ?
Yeah but I need to add some comments as David suggested.
The idea is that 2.9 used to create a bunch of objects at machine init, that only get used when CPUs are plugged. With 2.10, these objects are now created under the CPUs. When migrating from 2.10 to 2.9, we only need to send the real objects. The dummy vmstate entries don't send anything (.needed always returns false) since the corresponding objects in 2.9 aren't being used and still have their default state.
Quoted 22 lines
Quoted 2 lines
OK, that'll probably work.
Thanks for this confirmation.
Quoted 16 lines
Dave
Quoted 10 lines
Quoted 9 lines
Dave
Quoted 2 lines
--
Greg--
Dr. David Alan Gilbert / [email protected] / Manchester, UK--
Dr. David Alan Gilbert / [email protected] / Manchester, UK--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
In reply to Greg KurzQuoted 61 lines · Greg Kurz
Quoted 51 lines · On Tue, 13 Jun 2017 10:55:50 +0100 "Dr. David Alan Gilbert"…
Quoted 50 lines · * Greg Kurz ([email protected]) wrote:
Quoted 35 lines · On Tue, 13 Jun 2017 10:00:03 +0100 "Dr. David Alan Gilbert"…
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 28 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.Quoted 5 lines
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ?
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.Quoted 6 lines
Quoted 2 lines
but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Yes, I don't think we're ever casting back from the (void *) to an int so it feels pretty safe to me.
Quoted 8 lines
Just one nit, gcc doesn't like it on 64-bit hosts:
hw/ppc/spapr.c: In function ‘pre_2_10_vmstate_register_dummy_icp’:hw/ppc/spapr.c:148:60: error: cast to pointer from integer of different
size [-Werror=int-to-pointer-cast]vmstate_register(NULL, i, &pre_2_10_vmstate_dummy_icp, (void *) i);I need to cast to (long) first.
No, you need to cast to uintptr_t first.
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
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
In reply to Greg KurzQuoted 44 lines · Greg Kurz
Quoted 35 lines · On Tue, 13 Jun 2017 10:00:03 +0100 "Dr. David Alan Gilbert"…
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 28 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.Quoted 5 lines
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ?
Quoted 8 lines
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Right, that's probably the right short term approach.
Incidentally, for a somewhat safer-than-standard approach to this common problem, see https://ccodearchive.net/info/ptrint.html
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
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 47 lines · On Tue, 13 Jun 2017 18:01:46 +0800 David Gibson <[email protected]>…
Quoted 46 lines · Greg Kurz
Quoted 35 lines · On Tue, 13 Jun 2017 10:00:03 +0100 "Dr. David Alan Gilbert"…
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 28 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.Quoted 5 lines
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ?
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Right, that's probably the right short term approach.
I'm currently heading towards (void *)(intptr_t) i
Quoted 4 lines
Incidentally, for a somewhat safer-than-standard approach to this common problem, see https://ccodearchive.net/info/ptrint.html
Heh, your code :)
IIUC it is licensed under the terms of CC0, which I believe to be GPL compatible. Why not using it in QEMU ?
Re: [Qemu-devel] [PATCH v3 5/5] spapr: fix migration of ICPState objects from/to older QEMU
Quoted 63 lines · Greg Kurz
Quoted 47 lines · On Tue, 13 Jun 2017 18:01:46 +0800 David Gibson <[email protected]>…
Quoted 46 lines · Greg Kurz
Quoted 35 lines · On Tue, 13 Jun 2017 10:00:03 +0100 "Dr. David Alan Gilbert"…
Quoted 34 lines · * Greg Kurz ([email protected]) wrote:
Quoted 1 line · On Tue, 13 Jun 2017 16:06:31 +0800 David Gibson <[email protected]>…
On Tue, Jun 13, 2017 at 09:33:59AM +0200, Greg Kurz wrote:
[...]
Quoted 28 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void pre_2_10_vmstate_register_dummy_icp(sPAPRMachineState *spapr, int i) +{ + bool *flag = &spapr->pre_2_10_ignore_icp[i]; + + g_assert(!*flag);Apart from this
assert(), you never seem to test the values in thepre_2_10_ignore_icp()array, so it seems a bit pointless.Quoted 7 lines
Quoted 2 lines
There's the opposite check in
pre_2_10_vmstate_unregister_dummy_icp(). But I agree it isn't really useful... but more because of paranoia :)I'm all for paranoid assert()s if they can be made using data readily to hand. Adding a data structure just for the purpose of making an
assert()later, not so much.Quoted 4 lines
It is also passed as opaque argument to
vmstate_register(), where it is used as a key when callingvmstate_unregister(). I could possibly pass (void *) i instead, but I'm not a big fan of hijacking pointer arguments to pass numbers.Ah, I see your point. Creating an array, purely to generate arbitrary pointers is also kind of ugly, though. Really the
cpu_index/ XICS server number makes sense to identify the vmstate, but it looks likevmstate_unregister()doesn't take that.Quoted 5 lines
Quoted 3 lines
Indeed... what about adding a
vmstate_unregister_by_instance_id()then ?Cc'ing Juan and David.
So what's the problem with a (void *)i ?
https://stackoverflow.com/questions/8618637/what-does-it-mean-to-convert-int-to-void-or-vice-versa
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
It's simple, as long as you're
not actually using the opaque anywhere it's easy.but as you say, since the opaque isn't used anywhere, it is probably okay to pass (void *) i.
Right, that's probably the right short term approach.
I'm currently heading towards (void *)(intptr_t) i
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Incidentally, for a somewhat safer-than-standard approach to this common problem, see https://ccodearchive.net/info/ptrint.html
Heh, your code :)
IIUC it is licensed under the terms of CC0, which I believe to be GPL compatible. Why not using it in QEMU ?
Well, we could. I just haven't bothered to import it and convince people to use it.
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