spapr/xics: fix migration of older machine types
cover spapr/xics: fix migration of older machine types
Recent work on XICS broke migration of older machine types. The target fails with:
qemu-system-ppc64: Unknown savevm section or instance 'icp/server' 1
qemu-system-ppc64: load of migration failed: Invalid argument
This happens because the current code no longer pre-allocates ICP objects at machine init time.
This series restore the previous behavior for older machine types (patch 6). Since the fix adds an error path to cover the case when realization of the ICP objects fails, the series first does some cleanup on the way errors are handled (patch 1-5).
I could successfully migrate older machines back and forth with QEMU 2.9:
- pseries-2.9
- pseries-2.9 with hotplugged CPUs
- pseries-2.6 (pre CPU hotplug support)
This series is based on:
https://github.com/dgibson/qemu.git ppc-for-2.10
--
Greg
---
Greg Kurz (6):
ppc/xics: simplify prototype of xics_spapr_init()
spapr: fix error path of required kernel-irqchip
spapr: fix error reporting in xics_system_init()
spapr: sanitize error handling in spapr_ics_create()
spapr-cpu-core: release ICP object when realization fails
spapr: fix migration of ICP objects from/to older QEMU
hw/intc/xics_spapr.c | 3 +- hw/ppc/spapr.c | 75 ++++++++++++++++++++++++++++++++++++++--------- hw/ppc/spapr_cpu_core.c | 40 ++++++++++++++++--------- include/hw/ppc/spapr.h | 2 + include/hw/ppc/xics.h | 2 + 5 files changed, 90 insertions(+), 32 deletions(-)
PATCH 1/6 ppc/xics: simplify prototype of xics_spapr_init()
This function only does hypercall and RTAS-call registration, and thus never returns an error. This patch adapt the prototype to reflect that.
--- hw/intc/xics_spapr.c | 3 +-- hw/ppc/spapr.c | 2 +- include/hw/ppc/xics.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)
hw/intc/xics_spapr.c +1 -2
@@ -229,7 +229,7 @@ static void rtas_int_on(PowerPCCPU *cpu, sPAPRMachineState *spapr,rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); } -int xics_spapr_init (sPAPRMachineState *spapr,Error **errp) +void xics_spapr_init (sPAPRMachineState *spapr) {/* Registration of global state belongs into realize */ spapr_rtas_register (RTAS_IBM_SET_XIVE ,"ibm,set-xive" , rtas_set_xive);
@@ -243,7 +243,6 @@ int xics_spapr_init(sPAPRMachineState *spapr, Error **errp)spapr_register_hypercall (H_XIRR_X , h_xirr_x);spapr_register_hypercall (H_EOI , h_eoi);spapr_register_hypercall (H_IPOLL , h_ipoll); -return 0 ; }#define ICS_IRQ_FREE (ics, srcno) \
hw/ppc/spapr.c +1 -1
@@ -139,7 +139,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) }if (!spapr->ics) { -xics_spapr_init (spapr, errp); +xics_spapr_init (spapr); spapr->icp_type =TYPE_ICP ; spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, errp); }
include/hw/ppc/xics.h +1 -1
@@ -206,6 +206,6 @@ void icp_resend(ICPState *ss);typedef struct sPAPRMachineState sPAPRMachineState ;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp); -int xics_spapr_init (sPAPRMachineState *spapr,Error **errp); +void xics_spapr_init (sPAPRMachineState *spapr);#endif /* XICS_H */
Re: [Qemu-devel] [PATCH 1/6] ppc/xics: simplify prototype of xics_spapr_init()
Quoted 4 lines · Greg Kurz
This function only does hypercall and RTAS-call registration, and thus never returns an error. This patch adapt the prototype to reflect that.
Signed-off-by Greg Kurz <[email protected]>
Quoted 53 lines
--- hw/intc/xics_spapr.c | 3 +-- hw/ppc/spapr.c | 2 +- include/hw/ppc/xics.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)hw/intc/xics_spapr.c +1
-2@@ -229,7 +229,7 @@ static void rtas_int_on(PowerPCCPU *cpu, sPAPRMachineState *spapr,rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); } -int xics_spapr_init (sPAPRMachineState *spapr,Error **errp) +void xics_spapr_init (sPAPRMachineState *spapr) {/* Registration of global state belongs into realize */ spapr_rtas_register (RTAS_IBM_SET_XIVE ,"ibm,set-xive" , rtas_set_xive);@@ -243,7 +243,6 @@ int xics_spapr_init(sPAPRMachineState *spapr, Error **errp)spapr_register_hypercall (H_XIRR_X , h_xirr_x);spapr_register_hypercall (H_EOI , h_eoi);spapr_register_hypercall (H_IPOLL , h_ipoll); -return 0 ; }#define ICS_IRQ_FREE (ics, srcno) \hw/ppc/spapr.c +1
-1@@ -139,7 +139,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) }if (!spapr->ics) { -xics_spapr_init (spapr, errp); +xics_spapr_init (spapr); spapr->icp_type =TYPE_ICP ; spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, errp); }include/hw/ppc/xics.h +1
-1@@ -206,6 +206,6 @@ void icp_resend(ICPState *ss);typedef struct sPAPRMachineState sPAPRMachineState ;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp); -int xics_spapr_init (sPAPRMachineState *spapr,Error **errp); +void xics_spapr_init (sPAPRMachineState *spapr);#endif /* XICS_H */
Re: [Qemu-devel] [PATCH 1/6] ppc/xics: simplify prototype of xics_spapr_init()
In reply to Greg KurzQuoted 4 lines · Greg Kurz
This function only does hypercall and RTAS-call registration, and thus never returns an error. This patch adapt the prototype to reflect that.
Signed-off-by Greg Kurz <[email protected]>
Quoted 54 lines
--- hw/intc/xics_spapr.c | 3 +-- hw/ppc/spapr.c | 2 +- include/hw/ppc/xics.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)hw/intc/xics_spapr.c +1
-2@@ -229,7 +229,7 @@ static void rtas_int_on(PowerPCCPU *cpu, sPAPRMachineState *spapr,rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); } -int xics_spapr_init (sPAPRMachineState *spapr,Error **errp) +void xics_spapr_init (sPAPRMachineState *spapr) {/* Registration of global state belongs into realize */ spapr_rtas_register (RTAS_IBM_SET_XIVE ,"ibm,set-xive" , rtas_set_xive);@@ -243,7 +243,6 @@ int xics_spapr_init(sPAPRMachineState *spapr, Error **errp)spapr_register_hypercall (H_XIRR_X , h_xirr_x);spapr_register_hypercall (H_EOI , h_eoi);spapr_register_hypercall (H_IPOLL , h_ipoll); -return 0 ; }#define ICS_IRQ_FREE (ics, srcno) \hw/ppc/spapr.c +1
-1@@ -139,7 +139,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) }if (!spapr->ics) { -xics_spapr_init (spapr, errp); +xics_spapr_init (spapr); spapr->icp_type =TYPE_ICP ; spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, errp); }include/hw/ppc/xics.h +1
-1@@ -206,6 +206,6 @@ void icp_resend(ICPState *ss);typedef struct sPAPRMachineState sPAPRMachineState ;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp); -int xics_spapr_init (sPAPRMachineState *spapr,Error **errp); +void xics_spapr_init (sPAPRMachineState *spapr);#endif /* XICS_H */
David Gibson
AppliedRe: [Qemu-devel] [PATCH 1/6] ppc/xics: simplify prototype of xics_spapr_init()
In reply to Greg KurzQuoted 4 lines · Greg Kurz
This function only does hypercall and RTAS-call registration, and thus never returns an error. This patch adapt the prototype to reflect that.
Signed-off-by Greg Kurz <[email protected]>
Applied to ppc-for-2.10, thanks.
Quoted 53 lines
--- hw/intc/xics_spapr.c | 3 +-- hw/ppc/spapr.c | 2 +- include/hw/ppc/xics.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)hw/intc/xics_spapr.c +1
-2@@ -229,7 +229,7 @@ static void rtas_int_on(PowerPCCPU *cpu, sPAPRMachineState *spapr,rtas_st (rets,0 ,RTAS_OUT_SUCCESS ); } -int xics_spapr_init (sPAPRMachineState *spapr,Error **errp) +void xics_spapr_init (sPAPRMachineState *spapr) {/* Registration of global state belongs into realize */ spapr_rtas_register (RTAS_IBM_SET_XIVE ,"ibm,set-xive" , rtas_set_xive);@@ -243,7 +243,6 @@ int xics_spapr_init(sPAPRMachineState *spapr, Error **errp)spapr_register_hypercall (H_XIRR_X , h_xirr_x);spapr_register_hypercall (H_EOI , h_eoi);spapr_register_hypercall (H_IPOLL , h_ipoll); -return 0 ; }#define ICS_IRQ_FREE (ics, srcno) \hw/ppc/spapr.c +1
-1@@ -139,7 +139,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) }if (!spapr->ics) { -xics_spapr_init (spapr, errp); +xics_spapr_init (spapr); spapr->icp_type =TYPE_ICP ; spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, errp); }include/hw/ppc/xics.h +1
-1@@ -206,6 +206,6 @@ void icp_resend(ICPState *ss);typedef struct sPAPRMachineState sPAPRMachineState ;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp); -int xics_spapr_init (sPAPRMachineState *spapr,Error **errp); +void xics_spapr_init (sPAPRMachineState *spapr);#endif /* XICS_H */
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 2/6 spapr: fix error path of required kernel-irqchip
In reply to Greg KurzQEMU should exit if the user explicitely asked for kernel-irqchip support and "xics-kvm" initialization fails.
The changelog of commit 34f2af3d3edf ("spapr: Clean up misuse of qdev_init() in xics-kvm creation") reads:
While there, improve the error message when we can't satisfy an explicit user request for "xics-kvm", and exit(1) instead of abort(). Simplify the abort when we can't create "xics".
This patch adds the missing call to exit().
--- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+)
hw/ppc/spapr.c +1 -0
@@ -133,6 +133,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)if (machine_kernel_irqchip_required (machine) && !spapr->ics) {error_reportf_err (err,"kernel_irqchip requested but unavailable: " ); +exit (EXIT_FAILURE ); }else {error_free (err); }
Re: [Qemu-devel] [PATCH 2/6] spapr: fix error path of required kernel-irqchip
Quoted 6 lines · Greg Kurz
QEMU should exit if the user explicitely asked for kernel-irqchip support and "xics-kvm" initialization fails.
The changelog of commit
34f2af3d3edf("spapr: Clean up misuse ofqdev_init()in xics-kvm creation") reads:
Quoted 7 lines
While there, improve the error message when we can't satisfy an explicit user request for "xics-kvm", and exit(1) instead of
abort(). Simplify the abort when we can't create "xics".This patch adds the missing call to
exit().Signed-off-by Greg Kurz <[email protected]>
Quoted 17 lines
--- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+)hw/ppc/spapr.c +1
-0@@ -133,6 +133,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)if (machine_kernel_irqchip_required (machine) && !spapr->ics) {error_reportf_err (err,"kernel_irqchip requested but unavailable: " ); +exit (EXIT_FAILURE ); }else {error_free (err); }
Re: [Qemu-devel] [PATCH 2/6] spapr: fix error path of required kernel-irqchip
In reply to Greg KurzQuoted 23 lines · Greg Kurz
QEMU should exit if the user explicitely asked for kernel-irqchip support and "xics-kvm" initialization fails.
The changelog of commit
34f2af3d3edf("spapr: Clean up misuse ofqdev_init()in xics-kvm creation") reads:While there, improve the error message when we can't satisfy an explicit user request for "xics-kvm", and exit(1) instead of
abort(). Simplify the abort when we can't create "xics".This patch adds the missing call to
exit().Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+)hw/ppc/spapr.c +0
-0
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 139
Quoted 7 lines
hw/ppc/spapr.c +1
-0@@ -133,6 +133,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)if (machine_kernel_irqchip_required (machine) && !spapr->ics) {error_reportf_err (err,"kernel_irqchip requested but unavailable: " ); +exit (EXIT_FAILURE ); }else {error_free (err); }
This doesn't look right. We have an errp pointer in the caller. So on failure we should error_propagate(), rather than deciding for ourselves that exiting is the right course of action.
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 2/6] spapr: fix error path of required kernel-irqchip
Quoted 28 lines · On Tue, 16 May 2017 14:35:55 +1000 David Gibson <[email protected]>…
Quoted 27 lines · Greg Kurz
QEMU should exit if the user explicitely asked for kernel-irqchip support and "xics-kvm" initialization fails.
The changelog of commit
34f2af3d3edf("spapr: Clean up misuse ofqdev_init()in xics-kvm creation") reads:While there, improve the error message when we can't satisfy an explicit user request for "xics-kvm", and exit(1) instead of
abort(). Simplify the abort when we can't create "xics".This patch adds the missing call to
exit().Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+)hw/ppc/spapr.c +1
-0@@ -133,6 +133,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)if (machine_kernel_irqchip_required (machine) && !spapr->ics) {error_reportf_err (err,"kernel_irqchip requested but unavailable: " ); +exit (EXIT_FAILURE ); }else {
Quoted 9 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 139
Quoted 3 lines
hw/ppc/spapr.c +0
-0error_free (err); }This doesn't look right. We have an errp pointer in the caller. So on failure we should
error_propagate(), rather than deciding for ourselves that exiting is the right course of action.
I generally agree with that but can the caller cope with the fact that the user passed -machine accel=kvm,kernel_irqchip=on and this cannot be satisfied ?
Re: [Qemu-devel] [PATCH 2/6] spapr: fix error path of required kernel-irqchip
Quoted 41 lines · Greg Kurz
Quoted 28 lines · On Tue, 16 May 2017 14:35:55 +1000 David Gibson <[email protected]>…
Quoted 27 lines · Greg Kurz
QEMU should exit if the user explicitely asked for kernel-irqchip support and "xics-kvm" initialization fails.
The changelog of commit
34f2af3d3edf("spapr: Clean up misuse ofqdev_init()in xics-kvm creation") reads:While there, improve the error message when we can't satisfy an explicit user request for "xics-kvm", and exit(1) instead of
abort(). Simplify the abort when we can't create "xics".This patch adds the missing call to
exit().Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+)hw/ppc/spapr.c +1
-0@@ -133,6 +133,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)if (machine_kernel_irqchip_required (machine) && !spapr->ics) {error_reportf_err (err,"kernel_irqchip requested but unavailable: " ); +exit (EXIT_FAILURE ); }else {Quoted 9 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 139
Quoted 3 lines
hw/ppc/spapr.c +0
-0error_free (err); }This doesn't look right. We have an errp pointer in the caller. So on failure we should
error_propagate(), rather than deciding for ourselves that exiting is the right course of action.
Quoted 3 lines
I generally agree with that but can the caller cope with the fact that the user passed -machine accel=kvm,kernel_irqchip=on and this cannot be satisfied ?
AFAICT the only caller passes &error_fatal, so, yes..
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 2/6] spapr: fix error path of required kernel-irqchip
Quoted 42 lines · On Tue, 16 May 2017 16:08:46 +1000 David Gibson <[email protected]>…
Quoted 41 lines · Greg Kurz
Quoted 37 lines · On Tue, 16 May 2017 14:35:55 +1000 David Gibson <[email protected]>…
Quoted 23 lines · Greg Kurz
QEMU should exit if the user explicitely asked for kernel-irqchip support and "xics-kvm" initialization fails.
The changelog of commit
34f2af3d3edf("spapr: Clean up misuse ofqdev_init()in xics-kvm creation") reads:While there, improve the error message when we can't satisfy an explicit user request for "xics-kvm", and exit(1) instead of
abort(). Simplify the abort when we can't create "xics".This patch adds the missing call to
exit().Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+)hw/ppc/spapr.c +0
-0hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 139
Quoted 7 lines
hw/ppc/spapr.c +1
-0@@ -133,6 +133,7 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)if (machine_kernel_irqchip_required (machine) && !spapr->ics) {error_reportf_err (err,"kernel_irqchip requested but unavailable: " ); +exit (EXIT_FAILURE ); }else {error_free (err); }This doesn't look right. We have an errp pointer in the caller. So on failure we should
error_propagate(), rather than deciding for ourselves that exiting is the right course of action.
Quoted 6 lines
Quoted 3 lines
I generally agree with that but can the caller cope with the fact that the user passed -machine accel=kvm,kernel_irqchip=on and this cannot be satisfied ?
AFAICT the only caller passes
&error_fatal, so, yes..
Ok, then I'll rewrite xics_system_init() so that it propagates the error message instead of printing it to the monitor.
PATCH 3/6 spapr: fix error reporting in xics_system_init()
In reply to Greg KurzThe xics_system_init() function passes its errp argument to xics_kvm_init(). If the call fails and the user requested in-kernel irqchip, it then ends up passing a NULL Error * to error_reportf_err() and the error message is silently dropped.
Passing an errp argument is generally wrong, unless you really just need to convey an error to the caller.
This patch converts xics_system_init() to *only* pass a pointer to its own Error * and then to propagate it with error_propagate(), as recommended in error.h.
The local_err name is used for consistency with the rest of the code.
--- hw/ppc/spapr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
hw/ppc/spapr.c +10 -7
@@ -121,29 +121,32 @@ static ICSState *spapr_ics_create(sPAPRMachineState *spapr,static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +Error *local_err =NULL ;if (kvm_enabled ()) { -Error *err =NULL ; -if (machine_kernel_irqchip_allowed (machine) && - !xics_kvm_init (spapr, errp)) { + !xics_kvm_init (spapr, &local_err)) { spapr->icp_type =TYPE_KVM_ICP ; - spapr->ics =spapr_ics_create (spapr,TYPE_ICS_KVM , nr_irqs, &err); + spapr->ics =spapr_ics_create (spapr,TYPE_ICS_KVM , nr_irqs, + &local_err); }if (machine_kernel_irqchip_required (machine) && !spapr->ics) { -error_reportf_err (err, +error_reportf_err (local_err,"kernel_irqchip requested but unavailable: " );exit (EXIT_FAILURE ); }else { -error_free (err); +error_free (local_err); } }if (!spapr->ics) {xics_spapr_init (spapr); spapr->icp_type =TYPE_ICP ; - spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, errp); + spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, + &local_err); } + +error_propagate (errp, local_err); } static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,
Re: [Qemu-devel] [PATCH 3/6] spapr: fix error reporting in xics_system_init()
Quoted 8 lines · Greg Kurz
The
xics_system_init()function passes its errp argument toxics_kvm_init(). If the call fails and the user requested in-kernel irqchip, it then ends up passing a NULL Error * toerror_reportf_err()and the error message is silently dropped.Passing an errp argument is generally wrong, unless you really just need to convey an error to the caller.
Quoted 7 lines
This patch converts
xics_system_init()to *only* pass a pointer to its own Error * and then to propagate it witherror_propagate(), as recommended inerror.h.The
local_errname is used for consistency with the rest of the code.Signed-off-by Greg Kurz <[email protected]>
Thanks for the fix.
C.
Quoted 49 lines
--- hw/ppc/spapr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)hw/ppc/spapr.c +10
-7@@ -121,29 +121,32 @@ static ICSState *spapr_ics_create(sPAPRMachineState *spapr,static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +Error *local_err =NULL ;if (kvm_enabled ()) { -Error *err =NULL ; -if (machine_kernel_irqchip_allowed (machine) && - !xics_kvm_init (spapr, errp)) { + !xics_kvm_init (spapr, &local_err)) { spapr->icp_type =TYPE_KVM_ICP ; - spapr->ics =spapr_ics_create (spapr,TYPE_ICS_KVM , nr_irqs, &err); + spapr->ics =spapr_ics_create (spapr,TYPE_ICS_KVM , nr_irqs, + &local_err); }if (machine_kernel_irqchip_required (machine) && !spapr->ics) { -error_reportf_err (err, +error_reportf_err (local_err,"kernel_irqchip requested but unavailable: " );exit (EXIT_FAILURE ); }else { -error_free (err); +error_free (local_err); } }if (!spapr->ics) {xics_spapr_init (spapr); spapr->icp_type =TYPE_ICP ; - spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, errp); + spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, + &local_err); } + +error_propagate (errp, local_err); } static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,
Re: [Qemu-devel] [PATCH 3/6] spapr: fix error reporting in xics_system_init()
In reply to Greg KurzQuoted 8 lines · Greg Kurz
The
xics_system_init()function passes its errp argument toxics_kvm_init(). If the call fails and the user requested in-kernel irqchip, it then ends up passing a NULL Error * toerror_reportf_err()and the error message is silently dropped.Passing an errp argument is generally wrong, unless you really just need to convey an error to the caller.
Quoted 7 lines
This patch converts
xics_system_init()to *only* pass a pointer to its own Error * and then to propagate it witherror_propagate(), as recommended inerror.h.The
local_errname is used for consistency with the rest of the code.Signed-off-by Greg Kurz <[email protected]>
The change is good, but will need updating to work with the problem in the previous patch.
Quoted 49 lines
--- hw/ppc/spapr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)hw/ppc/spapr.c +10
-7@@ -121,29 +121,32 @@ static ICSState *spapr_ics_create(sPAPRMachineState *spapr,static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +Error *local_err =NULL ;if (kvm_enabled ()) { -Error *err =NULL ; -if (machine_kernel_irqchip_allowed (machine) && - !xics_kvm_init (spapr, errp)) { + !xics_kvm_init (spapr, &local_err)) { spapr->icp_type =TYPE_KVM_ICP ; - spapr->ics =spapr_ics_create (spapr,TYPE_ICS_KVM , nr_irqs, &err); + spapr->ics =spapr_ics_create (spapr,TYPE_ICS_KVM , nr_irqs, + &local_err); }if (machine_kernel_irqchip_required (machine) && !spapr->ics) { -error_reportf_err (err, +error_reportf_err (local_err,"kernel_irqchip requested but unavailable: " );exit (EXIT_FAILURE ); }else { -error_free (err); +error_free (local_err); } }if (!spapr->ics) {xics_spapr_init (spapr); spapr->icp_type =TYPE_ICP ; - spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, errp); + spapr->ics =spapr_ics_create (spapr,TYPE_ICS_SIMPLE , nr_irqs, + &local_err); } + +error_propagate (errp, local_err); } static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 4/6 spapr: sanitize error handling in spapr_ics_create()
In reply to Greg KurzThe spapr_ics_create() function handles errors in a rather convoluted way, with two local Error * variables. Moreover, failing to parent the ICS object to the machine should be considered as a bug but it is currently ignored.
This patch addresses both issues.
--- hw/ppc/spapr.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
hw/ppc/spapr.c +12 -7
@@ -101,21 +101,26 @@ static ICSState *spapr_ics_create(sPAPRMachineState *spapr,const char *type_ics, int nr_irqs, Error **errp) { - Error *err = NULL, *local_err = NULL; + Error *local_err = NULL;Object *obj; obj =object_new (type_ics); -object_property_add_child (OBJECT (spapr),"ics" , obj,NULL ); +object_property_add_child (OBJECT (spapr),"ics" , obj, &error_abort);object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_int (obj, nr_irqs,"nr-irqs" , &err); +object_property_set_int (obj, nr_irqs,"nr-irqs" , &local_err); +if (local_err) { + goto error; + }object_property_set_bool (obj, true,"realized" , &local_err); -error_propagate (&err, local_err); -if (err) { -error_propagate (errp, err); -return NULL ; +if (local_err) { + goto error; }return ICS_SIMPLE (obj); + +error: +error_propagate (errp, local_err); +return NULL ; }static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp)
Re: [Qemu-devel] [PATCH 4/6] spapr: sanitize error handling in spapr_ics_create()
Quoted 4 lines · Greg Kurz
The
spapr_ics_create()function handles errors in a rather convoluted way, with two local Error * variables. Moreover, failing to parent the ICS object to the machine should be considered as a bug but it is currently ignored.
I am not sure what should be done for object_property_add_child() errors but QEMU generally uses NULL for 'Error **'. It might be wrong though.
As for the local error handling, it is following what is described in qapi/error.h. Isn't it ?
Cheers,
C.
Quoted 46 lines
This patch addresses both issues.
Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)hw/ppc/spapr.c +12
-7@@ -101,21 +101,26 @@ static ICSState *spapr_ics_create(sPAPRMachineState *spapr,const char *type_ics, int nr_irqs, Error **errp) { - Error *err = NULL, *local_err = NULL; + Error *local_err = NULL;Object *obj; obj =object_new (type_ics); -object_property_add_child (OBJECT (spapr),"ics" , obj,NULL ); +object_property_add_child (OBJECT (spapr),"ics" , obj, &error_abort);object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_int (obj, nr_irqs,"nr-irqs" , &err); +object_property_set_int (obj, nr_irqs,"nr-irqs" , &local_err); +if (local_err) { + goto error; + }object_property_set_bool (obj, true,"realized" , &local_err); -error_propagate (&err, local_err); -if (err) { -error_propagate (errp, err); -return NULL ; +if (local_err) { + goto error; }return ICS_SIMPLE (obj); + +error: +error_propagate (errp, local_err); +return NULL ; }static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp)
Re: [Qemu-devel] [PATCH 4/6] spapr: sanitize error handling in spapr_ics_create()
Quoted 6 lines · On Mon, 15 May 2017 13:59:33 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 4 lines · Greg Kurz
The
spapr_ics_create()function handles errors in a rather convoluted way, with two local Error * variables. Moreover, failing to parent the ICS object to the machine should be considered as a bug but it is currently ignored.
Quoted 7 lines
I am not sure what should be done for
object_property_add_child()errors but QEMU generally uses NULL for 'Error **'. It might be wrong though.As for the local error handling, it is following what is described in
qapi/error.h. Isn't it ?
Yes, it does follow the "Receive and accumulate multiple errors" recommandation, but does it make sense to realize the ICS object if we failed to set nr-irqs ?
Quoted 52 lines
Cheers,
C.
Quoted 46 lines
This patch addresses both issues.
Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)hw/ppc/spapr.c +12
-7@@ -101,21 +101,26 @@ static ICSState *spapr_ics_create(sPAPRMachineState *spapr,const char *type_ics, int nr_irqs, Error **errp) { - Error *err = NULL, *local_err = NULL; + Error *local_err = NULL;Object *obj; obj =object_new (type_ics); -object_property_add_child (OBJECT (spapr),"ics" , obj,NULL ); +object_property_add_child (OBJECT (spapr),"ics" , obj, &error_abort);object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_int (obj, nr_irqs,"nr-irqs" , &err); +object_property_set_int (obj, nr_irqs,"nr-irqs" , &local_err); +if (local_err) { + goto error; + }object_property_set_bool (obj, true,"realized" , &local_err); -error_propagate (&err, local_err); -if (err) { -error_propagate (errp, err); -return NULL ; +if (local_err) { + goto error; }return ICS_SIMPLE (obj); + +error: +error_propagate (errp, local_err); +return NULL ; }static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp)
Re: [Qemu-devel] [PATCH 4/6] spapr: sanitize error handling in spapr_ics_create()
Quoted 13 lines · Greg Kurz
Quoted 10 lines · On Mon, 15 May 2017 13:59:33 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 4 lines · Greg Kurz
The
spapr_ics_create()function handles errors in a rather convoluted way, with two local Error * variables. Moreover, failing to parent the ICS object to the machine should be considered as a bug but it is currently ignored.I am not sure what should be done for
object_property_add_child()errors but QEMU generally uses NULL for 'Error **'. It might be wrong though.
Quoted 7 lines
Quoted 3 lines
As for the local error handling, it is following what is described in
qapi/error.h. Isn't it ?Yes, it does follow the "Receive and accumulate multiple errors" recommandation, but does it make sense to realize the ICS object if we failed to set nr-irqs ?
Nor is it necessary to have two different local error variables.
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
David Gibson
AppliedRe: [Qemu-devel] [PATCH 4/6] spapr: sanitize error handling in spapr_ics_create()
In reply to Greg KurzQuoted 8 lines · Greg Kurz
The
spapr_ics_create()function handles errors in a rather convoluted way, with two local Error * variables. Moreover, failing to parent the ICS object to the machine should be considered as a bug but it is currently ignored.This patch addresses both issues.
Signed-off-by Greg Kurz <[email protected]>
Applied to ppc-for-2.10
Quoted 43 lines
--- hw/ppc/spapr.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)hw/ppc/spapr.c +12
-7@@ -101,21 +101,26 @@ static ICSState *spapr_ics_create(sPAPRMachineState *spapr,const char *type_ics, int nr_irqs, Error **errp) { - Error *err = NULL, *local_err = NULL; + Error *local_err = NULL;Object *obj; obj =object_new (type_ics); -object_property_add_child (OBJECT (spapr),"ics" , obj,NULL ); +object_property_add_child (OBJECT (spapr),"ics" , obj, &error_abort);object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_int (obj, nr_irqs,"nr-irqs" , &err); +object_property_set_int (obj, nr_irqs,"nr-irqs" , &local_err); +if (local_err) { + goto error; + }object_property_set_bool (obj, true,"realized" , &local_err); -error_propagate (&err, local_err); -if (err) { -error_propagate (errp, err); -return NULL ; +if (local_err) { + goto error; }return ICS_SIMPLE (obj); + +error: +error_propagate (errp, local_err); +return NULL ; }static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp)
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 5/6 spapr-cpu-core: release ICP object when realization fails
In reply to Greg KurzWhile here we introduce a single error path to avoid code duplication.
--- hw/ppc/spapr_cpu_core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
hw/ppc/spapr_cpu_core.c +8 -8
@@ -147,25 +147,25 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort);object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -error_propagate (errp, local_err); -return ; + goto error; }object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { -object_unparent (obj); -error_propagate (errp, local_err); -return ; + goto error; }spapr_cpu_init (spapr, cpu, &local_err);if (local_err) { -object_unparent (obj); -error_propagate (errp, local_err); -return ; + goto error; }xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj)); +return ; + +error: +object_unparent (obj); +error_propagate (errp, local_err); }static void spapr_cpu_core_realize (DeviceState *dev,Error **errp)
Re: [Qemu-devel] [PATCH 5/6] spapr-cpu-core: release ICP object when realization fails
Quoted 12 lines · Greg Kurz
While here we introduce a single error path to avoid code duplication.
Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr_cpu_core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)hw/ppc/spapr_cpu_core.c +0
-0
hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize_child(Object *child, Error **errp) · line 150
Quoted 6 lines
hw/ppc/spapr_cpu_core.c +1
-2@@ -147,25 +147,25 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort);object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -error_propagate (errp, local_err); -return ; + goto error;
the error: statement below adds an object_unparent(). is that ok ?
C.
Quoted 28 lines
hw/ppc/spapr_cpu_core.c +7
-6}object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { -object_unparent (obj); -error_propagate (errp, local_err); -return ; + goto error; }spapr_cpu_init (spapr, cpu, &local_err);if (local_err) { -object_unparent (obj); -error_propagate (errp, local_err); -return ; + goto error; }xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj)); +return ; + +error: +object_unparent (obj); +error_propagate (errp, local_err); }static void spapr_cpu_core_realize (DeviceState *dev,Error **errp)
Re: [Qemu-devel] [PATCH 5/6] spapr-cpu-core: release ICP object when realization fails
Quoted 8 lines · On Mon, 15 May 2017 14:02:34 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 7 lines · Greg Kurz
While here we introduce a single error path to avoid code duplication.
Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr_cpu_core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Quoted 14 lines
hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize_child(Object *child, Error **errp) · line 150
Quoted 11 lines
hw/ppc/spapr_cpu_core.c +1
-2@@ -147,25 +147,25 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort);object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -error_propagate (errp, local_err); -return ; + goto error;the error: statement below adds an
object_unparent(). is that ok ?
Yes, this is the purpose of the patch actually.
The ICP object gets parented to the CPU a few lines above, so I guess we should unparent in this error path as well.
Maybe I should rename the patch to "unparent ICP object when realization fails" ?
Quoted 31 lines
C.
Quoted 28 lines
hw/ppc/spapr_cpu_core.c +7
-6}object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { -object_unparent (obj); -error_propagate (errp, local_err); -return ; + goto error; }spapr_cpu_init (spapr, cpu, &local_err);if (local_err) { -object_unparent (obj); -error_propagate (errp, local_err); -return ; + goto error; }xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj)); +return ; + +error: +object_unparent (obj); +error_propagate (errp, local_err); }static void spapr_cpu_core_realize (DeviceState *dev,Error **errp)
David Gibson
AppliedRe: [Qemu-devel] [PATCH 5/6] spapr-cpu-core: release ICP object when realization fails
In reply to Greg KurzQuoted 3 lines · Greg Kurz
While here we introduce a single error path to avoid code duplication.
Signed-off-by Greg Kurz <[email protected]>
Applied to ppc=for-2.10.
Quoted 43 lines
--- hw/ppc/spapr_cpu_core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)hw/ppc/spapr_cpu_core.c +8
-8@@ -147,25 +147,25 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort);object_property_set_bool (obj, true,"realized" , &local_err);if (local_err) { -error_propagate (errp, local_err); -return ; + goto error; }object_property_set_bool (child, true,"realized" , &local_err);if (local_err) { -object_unparent (obj); -error_propagate (errp, local_err); -return ; + goto error; }spapr_cpu_init (spapr, cpu, &local_err);if (local_err) { -object_unparent (obj); -error_propagate (errp, local_err); -return ; + goto error; }xics_cpu_setup (XICS_FABRIC (spapr), cpu,ICP (obj)); +return ; + +error: +object_unparent (obj); +error_propagate (errp, local_err); }static void spapr_cpu_core_realize (DeviceState *dev,Error **errp)
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 6/6 spapr: fix migration of ICP objects from/to older QEMU
In reply to Greg KurzCommit 5bc8d26de20c ("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP 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 introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects.
While here, we also ensure that object_property_add_child() errors cause QEMU to abort for newer machines.
--- hw/ppc/spapr.c | 36 ++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 28 ++++++++++++++++++++-------- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 58 insertions(+), 8 deletions(-)
hw/ppc/spapr.c +36 -0
@@ -126,6 +126,7 @@ error:static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr);Error *local_err =NULL ;if (kvm_enabled ()) {
@@ -151,6 +152,38 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) &local_err); } +if (!spapr->ics) { + goto out; + } + +if (smc->must_pre_allocate_icps) { +int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads); +int i; + + spapr->legacy_icps =g_malloc0 (nr_servers *sizeof (ICPState)); + +for (i =0 ; i < nr_servers; i++) { +void * obj = &spapr->legacy_icps[i]; + +object_initialize (obj,sizeof (ICPState), spapr->icp_type); +object_property_add_child (OBJECT (spapr),"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); +if (local_err) { +while (i--) { +object_unparent (obj); + } +g_free (spapr->legacy_icps); +break ; + } + } + } + +out:error_propagate (errp, local_err); }
@@ -3256,8 +3289,11 @@ 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 ); + smc->must_pre_allocate_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);
hw/ppc/spapr_cpu_core.c +20 -8
@@ -119,6 +119,7 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)size_t size =object_type_get_instance_size (typename);CPUCore *cc =CPU_CORE (dev);int i; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());for (i =0 ; i < cc->nr_threads; i++) {void *obj = sc->threads + i * size;
@@ -127,7 +128,9 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);spapr_cpu_destroy (cpu); -object_unparent (cpu->intc); +if (!spapr->legacy_icps) { +object_unparent (cpu->intc); + }cpu_remove_sync (cs);object_unparent (obj); }
@@ -142,12 +145,19 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj,NULL ); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); -if (local_err) { - goto error; +if (spapr->legacy_icps) { +int index = cpu->parent_obj.cpu_index; + + obj =OBJECT (&spapr->legacy_icps[index]); + }else { + obj =object_new (spapr->icp_type); +object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), + &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } }object_property_set_bool (child, true,"realized" , &local_err);
@@ -164,7 +174,9 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)return ; error: -object_unparent (obj); +if (!spapr->legacy_icps) { +object_unparent (obj); + }error_propagate (errp, local_err); }
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 must_pre_allocate_icps;/* only for pseries-2.9 and older */ void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,
@@ -109,6 +110,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +ICPState *legacy_icps; };#define H_SUCCESS 0
Re: [Qemu-devel] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
Quoted 9 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP 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 introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects.
I think this is a quite elegant way to a handle the migration regression. Thanks for taking care of it.
Have you tried to simply reparent the ICPs objects to OBJECT(spapr) instead of the OBJECT(cpu) ?
See some minor comments below.
Quoted 23 lines
While here, we also ensure that
object_property_add_child()errors cause QEMU to abort for newer machines.Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 36 ++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 28 ++++++++++++++++++++-------- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 58 insertions(+), 8 deletions(-)hw/ppc/spapr.c +1
-0@@ -126,6 +126,7 @@ error:static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr);Error *local_err =NULL ;if (kvm_enabled ()) {
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 159
Quoted 8 lines
hw/ppc/spapr.c +5
-0@@ -151,6 +152,38 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) &local_err); } +if (!spapr->ics) { + goto out; + } + +if (smc->must_pre_allocate_icps) {
I am not sure I like 'must', I think 'pre_allocate_icps' should be enough ? or simply 'allocate_legacy_icps' ?
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 161
Quoted 2 lines
hw/ppc/spapr.c +2
-0+int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads);
may be we should reintroduce nr_servers at the machine level ?
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 167
Quoted 6 lines
hw/ppc/spapr.c +6
-0+int i; + + spapr->legacy_icps =g_malloc0 (nr_servers *sizeof (ICPState)); + +for (i =0 ; i < nr_servers; i++) { +void * obj = &spapr->legacy_icps[i];
'void *'
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 171
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ +object_initialize (obj,sizeof (ICPState), spapr->icp_type); +object_property_add_child (OBJECT (spapr),"icp[*]" , obj, + &error_abort);
David does not like the "icp[*]" syntax.
Quoted 111 lines
hw/ppc/spapr.c +18
-0+object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), + &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +while (i--) { +object_unparent (obj); + } +g_free (spapr->legacy_icps); +break ; + } + } + } + +out:error_propagate (errp, local_err); }@@ -3256,8 +3289,11 @@ 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 ); + smc->must_pre_allocate_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);hw/ppc/spapr_cpu_core.c +20
-8@@ -119,6 +119,7 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)size_t size =object_type_get_instance_size (typename);CPUCore *cc =CPU_CORE (dev);int i; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());for (i =0 ; i < cc->nr_threads; i++) {void *obj = sc->threads + i * size;@@ -127,7 +128,9 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);spapr_cpu_destroy (cpu); -object_unparent (cpu->intc); +if (!spapr->legacy_icps) { +object_unparent (cpu->intc); + }cpu_remove_sync (cs);object_unparent (obj); }@@ -142,12 +145,19 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj,NULL ); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); -if (local_err) { - goto error; +if (spapr->legacy_icps) { +int index = cpu->parent_obj.cpu_index; + + obj =OBJECT (&spapr->legacy_icps[index]); + }else { + obj =object_new (spapr->icp_type); +object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), + &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } }object_property_set_bool (child, true,"realized" , &local_err);@@ -164,7 +174,9 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)return ; error: -object_unparent (obj); +if (!spapr->legacy_icps) { +object_unparent (obj); + }error_propagate (errp, local_err); }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 must_pre_allocate_icps;/* only for pseries-2.9 and older */ void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,@@ -109,6 +110,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +ICPState *legacy_icps; };#define H_SUCCESS 0
Re: [Qemu-devel] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
Quoted 11 lines · On Mon, 15 May 2017 14:22:32 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 9 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP 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 introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects.
Quoted 6 lines
I think this is a quite elegant way to a handle the migration regression. Thanks for taking care of it.
Have you tried to simply reparent the ICPs objects to OBJECT(spapr) instead of the OBJECT(cpu) ?
Do you mean to reparent unconditionally to OBJECT(spapr) for all machine versions ? I'm not sure this would be beneficial, but I might be missing something...
Quoted 28 lines
See some minor comments below.
Quoted 26 lines
While here, we also ensure that
object_property_add_child()errors cause QEMU to abort for newer machines.Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 36 ++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 28 ++++++++++++++++++++-------- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 58 insertions(+), 8 deletions(-)hw/ppc/spapr.c +1
-0@@ -126,6 +126,7 @@ error:static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr);Error *local_err =NULL ;if (kvm_enabled ()) {@@ -151,6 +152,38 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) &local_err); }
Quoted 9 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 159
Quoted 5 lines
hw/ppc/spapr.c +5
-0+if (!spapr->ics) { + goto out; + } + +if (smc->must_pre_allocate_icps) {I am not sure I like 'must', I think '
pre_allocate_icps' should be enough ? or simply 'allocate_legacy_icps' ?
Ok. I'll go for the latter if it's ok with David.
Quoted 5 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 161
Quoted 2 lines
hw/ppc/spapr.c +2
-0+int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads);may be we should reintroduce
nr_serversat the machine level ?
I had reintroduced it but then I realized it was only used in this function.
Quoted 9 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 167
Quoted 6 lines
hw/ppc/spapr.c +6
-0+int i; + + spapr->legacy_icps =g_malloc0 (nr_servers *sizeof (ICPState)); + +for (i =0 ; i < nr_servers; i++) { +void * obj = &spapr->legacy_icps[i];'void *'
Yeah, patchew already yelled at me :)
Quoted 7 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 171
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ +object_initialize (obj,sizeof (ICPState), spapr->icp_type); +object_property_add_child (OBJECT (spapr),"icp[*]" , obj, + &error_abort);David does not like the "icp[*]" syntax.
Ah... I wasn't aware of that. But I agree that I should probably create the object names based on 'i', rather than relying on the more complex logic in object_property_add().
Quoted 112 lines
Quoted 111 lines
hw/ppc/spapr.c +18
-0+object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), + &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +while (i--) { +object_unparent (obj); + } +g_free (spapr->legacy_icps); +break ; + } + } + } + +out:error_propagate (errp, local_err); }@@ -3256,8 +3289,11 @@ 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 ); + smc->must_pre_allocate_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);hw/ppc/spapr_cpu_core.c +20
-8@@ -119,6 +119,7 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)size_t size =object_type_get_instance_size (typename);CPUCore *cc =CPU_CORE (dev);int i; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());for (i =0 ; i < cc->nr_threads; i++) {void *obj = sc->threads + i * size;@@ -127,7 +128,9 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);spapr_cpu_destroy (cpu); -object_unparent (cpu->intc); +if (!spapr->legacy_icps) { +object_unparent (cpu->intc); + }cpu_remove_sync (cs);object_unparent (obj); }@@ -142,12 +145,19 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj,NULL ); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); -if (local_err) { - goto error; +if (spapr->legacy_icps) { +int index = cpu->parent_obj.cpu_index; + + obj =OBJECT (&spapr->legacy_icps[index]); + }else { + obj =object_new (spapr->icp_type); +object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), + &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } }object_property_set_bool (child, true,"realized" , &local_err);@@ -164,7 +174,9 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)return ; error: -object_unparent (obj); +if (!spapr->legacy_icps) { +object_unparent (obj); + }error_propagate (errp, local_err); }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 must_pre_allocate_icps;/* only for pseries-2.9 and older */ void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,@@ -109,6 +110,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +ICPState *legacy_icps; };#define H_SUCCESS 0
Re: [Qemu-devel] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
Quoted 17 lines · Greg Kurz
Quoted 14 lines · On Mon, 15 May 2017 14:22:32 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 9 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP 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 introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects.
I think this is a quite elegant way to a handle the migration regression. Thanks for taking care of it.
Quoted 6 lines
Quoted 3 lines
Have you tried to simply reparent the ICPs objects to OBJECT(spapr) instead of the OBJECT(cpu) ?
Do you mean to reparent unconditionally to OBJECT(spapr) for all machine versions ?
only in the case of smc->must_pre_allocate_icps
Quoted 2 lines
I'm not sure this would be beneficial, but I might be missing something...
I think that we would not need to allocate the legacy_icps array. Parenting the icp object to the spapr machine should be enough. I might be wrong. my expertise on the migration stream is very basic.
C.
Re: [Qemu-devel] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
Quoted 27 lines · On Mon, 15 May 2017 18:09:04 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 17 lines · Greg Kurz
Quoted 14 lines · On Mon, 15 May 2017 14:22:32 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 9 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP 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 introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects.
I think this is a quite elegant way to a handle the migration regression. Thanks for taking care of it.
Quoted 6 lines
Quoted 3 lines
Have you tried to simply reparent the ICPs objects to OBJECT(spapr) instead of the OBJECT(cpu) ?
Do you mean to reparent unconditionally to OBJECT(spapr) for all machine versions ?
only in the case of
smc->must_pre_allocate_icps
Quoted 8 lines
Quoted 2 lines
I'm not sure this would be beneficial, but I might be missing something...
I think that we would not need to allocate the
legacy_icpsarray. Parenting the icp object to the spapr machine should be enough. I might be wrong. my expertise on the migration stream is very basic.
I don't think this would work because an older QEMU would still send state for objects that don't exist in the destination.
Quoted 2 lines
C.
Re: [Qemu-devel] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
Quoted 33 lines · Greg Kurz
Quoted 30 lines · On Mon, 15 May 2017 18:09:04 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 17 lines · Greg Kurz
Quoted 14 lines · On Mon, 15 May 2017 14:22:32 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 9 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP 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 introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects.
I think this is a quite elegant way to a handle the migration regression. Thanks for taking care of it.
Quoted 6 lines
Quoted 3 lines
Have you tried to simply reparent the ICPs objects to OBJECT(spapr) instead of the OBJECT(cpu) ?
Do you mean to reparent unconditionally to OBJECT(spapr) for all machine versions ?
only in the case of
smc->must_pre_allocate_icpsQuoted 2 lines
I'm not sure this would be beneficial, but I might be missing something...
Quoted 8 lines
Quoted 5 lines
I think that we would not need to allocate the
legacy_icpsarray. Parenting the icp object to the spapr machine should be enough. I might be wrong. my expertise on the migration stream is very basic.I don't think this would work because an older QEMU would still send state for objects that don't exist in the destination.
Right. We could create "dummy" objects that receive the ICP data, then discard it. But it's probably more trouble than it's worty.
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 6/6] spapr: fix migration of ICP objects from/to older QEMU
In reply to Greg KurzQuoted 8 lines
Quoted 5 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 161
Quoted 2 lines
hw/ppc/spapr.c +2
-0+int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads);may be we should reintroduce
nr_serversat the machine level ?I had reintroduced it but then I realized it was only used in this function.
nr_servers is also used when the device tree is populated with the interrupt controller nodes. No big deal.
C.
Re: [Qemu-devel] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
Quoted 12 lines · On Mon, 15 May 2017 18:11:27 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 161
Quoted 2 lines
hw/ppc/spapr.c +2
-0+int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads);may be we should reintroduce
nr_serversat the machine level ?I had reintroduced it but then I realized it was only used in this function.
nr_serversis also used when the device tree is populated with the interrupt controller nodes. No big deal.
Ah yes you're right. Maybe this can be factored out in a followup patch.
Quoted 2 lines
C.
Re: [Qemu-devel] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
In reply to Cédric Le GoaterQuoted 11 lines · Cédric Le Goater
Quoted 8 lines
Quoted 5 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 161
Quoted 2 lines
hw/ppc/spapr.c +2
-0+int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads);may be we should reintroduce
nr_serversat the machine level ?I had reintroduced it but then I realized it was only used in this function.
nr_serversis also used when the device tree is populated with the interrupt controller nodes. No big deal.
Which is guest visible, so we should really make that stay the same for older machine types. I'd like to avoid re-introducing nr_servers as a property if we can, but maybe we can't.
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 6/6] spapr: fix migration of ICP objects from/to older QEMU
Quoted 10 lines · On Wed, 17 May 2017 14:18:16 +1000 David Gibson <[email protected]>…
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines
Quoted 5 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 161
Quoted 2 lines
hw/ppc/spapr.c +2
-0+int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads);may be we should reintroduce
nr_serversat the machine level ?I had reintroduced it but then I realized it was only used in this function.
Quoted 7 lines
Quoted 2 lines
nr_serversis also used when the device tree is populated with the interrupt controller nodes. No big deal.Which is guest visible, so we should really make that stay the same for older machine types. I'd like to avoid re-introducing
nr_serversas a property if we can, but maybe we can't.
Yes we can :) or at least maybe, if you can shed light on a guest visible change introduced by this commit in 2.8:
commit 9b9a19080a6e548b91420ce7925f2ac81ef63ae8
Author: David Gibson <[email protected]> Date: Thu Oct 20 16:07:56 2016 +1100
pseries: Move construction of /interrupt-controller fdt node
It changes the "ibm,interrupt-server-ranges" property in the device tree from
{0, cpu_to_be32(max_cpus)}to
{0, cpu_to_be32(xics->nr_servers)}ie, {0, cpu_to_be32(DIV_ROUND_UP(max_cpus * smt, smp_threads))}
And indeed, if I start QEMU with
-smp cores=2,threads=4,maxcpus=16 -machine type=pseries-2.7,accel=kvm
the following is exposed to the guest with 2.7:
ibm,interrupt-server-ranges
00000000 00000010
and with 2.8 we get:
ibm,interrupt-server-ranges
00000000 00000020
LoPAPR B.6.9.1.1 says that the range (ie, the second number) "shall be the number of contiguous server#s supported by the unit (this also corresponds to the number of “reg” entries)". I'm inclined to think this maps to max_cpus but I may be wrong... any clues ?
Cheers,
--
Greg
Re: [Qemu-devel] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
Quoted 53 lines · Greg Kurz
Quoted 10 lines · On Wed, 17 May 2017 14:18:16 +1000 David Gibson <[email protected]>…
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines
Quoted 5 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 161
Quoted 2 lines
hw/ppc/spapr.c +2
-0+int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads);may be we should reintroduce
nr_serversat the machine level ?I had reintroduced it but then I realized it was only used in this function.
Quoted 7 lines
Quoted 2 lines
nr_serversis also used when the device tree is populated with the interrupt controller nodes. No big deal.Which is guest visible, so we should really make that stay the same for older machine types. I'd like to avoid re-introducing
nr_serversas a property if we can, but maybe we can't.Yes we can :) or at least maybe, if you can shed light on a guest visible change introduced by this commit in 2.8:
commit
9b9a19080a6e548b91420ce7925f2ac81ef63ae8Author: David Gibson <[email protected]> Date: Thu Oct 20 16:07:56 2016 +1100pseries: Move construction of /interrupt-controller fdt node
It changes the "ibm,interrupt-server-ranges" property in the device tree from
{0, cpu_to_be32(max_cpus)}to
{0, cpu_to_be32(xics->nr_servers)}ie, {0,
cpu_to_be32(DIV_ROUND_UP(max_cpus * smt, smp_threads))}And indeed, if I start QEMU with
-smp cores=2,threads=4,maxcpus=16 -machine type=pseries-2.7,accel=kvm
the following is exposed to the guest with 2.7:
ibm,interrupt-server-ranges
00000000 00000010and with 2.8 we get:
Quoted 7 lines
ibm,interrupt-server-ranges
00000000 00000020LoPAPR B.6.9.1.1 says that the range (ie, the second number) "shall be the number of contiguous server#s supported by the unit (this also corresponds to the number of “reg” entries)". I'm inclined to think this maps to
max_cpusbut I may be wrong... any clues ?
So, yes, it's a guest visible change in some configurations, but in those configurations the previous behaviour was sufficiently broken that I think that's preferable to not changing it.
Basically the ibm,interrupt-server-ranges property gives the total range of valid server IDs. The server IDs assigned to each thread are based on the dt_id, and are spaced by the number of host threads, not the number of guest threads. That means that with 2.7, the last cpus would have advertised ibm,ppc-interrupt-server#s properties with values outside the range given by ibm,interrupt-server-ranages, which is definitely wrong.
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 6/6] spapr: fix migration of ICP objects from/to older QEMU
In reply to Greg KurzQuoted 4 lines · Greg Kurz
Quoted 1 line · On Mon, 15 May 2017 14:22:32 +0200 Cédric Le Goater <[email protected]> wrote:
On 05/15/2017 01:40 PM, Greg Kurz wrote:
[snip]
Quoted 11 lines
Quoted 7 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 171
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ +object_initialize (obj,sizeof (ICPState), spapr->icp_type); +object_property_add_child (OBJECT (spapr),"icp[*]" , obj, + &error_abort);David does not like the "icp[*]" syntax.
Ah... I wasn't aware of that. But I agree that I should probably create the object names based on 'i', rather than relying on the more complex logic in
object_property_add().
Right, the non-obviousness of what the indicies will end up being is exactly why I dislike the "[*]" syntax. Especially here, where it's clearly important that the QOM paths end up exactly like in older qemu versions, I think it's better to be explicit.
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 6/6] spapr: fix migration of ICP objects from/to older QEMU
In reply to Cédric Le GoaterQuoted 11 lines · Cédric Le Goater
Quoted 9 lines · Greg Kurz
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP 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 introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects.
Quoted 5 lines
I think this is a quite elegant way to a handle the migration regression. Thanks for taking care of it.
Have you tried to simply reparent the ICPs objects to OBJECT(spapr) instead of the OBJECT(cpu) ?
I actually kind of hate changing the QOM tree structure based on machine type compatibility. Unfortunately, since we're matching up the migration state based (essentially) on QOM path, I don't see any easy alternative. I really wish there was a mechanism for defining "alias paths" or something to handle this kind of migration compatibility shim.
Quoted 28 lines
See some minor comments below.
Quoted 26 lines
While here, we also ensure that
object_property_add_child()errors cause QEMU to abort for newer machines.Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 36 ++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 28 ++++++++++++++++++++-------- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 58 insertions(+), 8 deletions(-)hw/ppc/spapr.c +1
-0@@ -126,6 +126,7 @@ error:static void xics_system_init (MachineState *machine,int nr_irqs,Error **errp) {sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr);Error *local_err =NULL ;if (kvm_enabled ()) {@@ -151,6 +152,38 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) &local_err); }
Quoted 8 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 159
Quoted 5 lines
hw/ppc/spapr.c +5
-0+if (!spapr->ics) { + goto out; + } + +if (smc->must_pre_allocate_icps) {I am not sure I like 'must', I think '
pre_allocate_icps' should be enough ? or simply 'allocate_legacy_icps' ?
I'd actually prefer to make it explicit that this is a migration compatibility shim and call it something like 'pre_2_10_icp_allocation'.
Quoted 8 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 161
Quoted 2 lines
hw/ppc/spapr.c +2
-0+int smt =kvmppc_smt_threads (); +int nr_servers =DIV_ROUND_UP (max_cpus * smt, smp_threads);may be we should reintroduce
nr_serversat the machine level ?Quoted 3 lines
hw/ppc/spapr.c +3
-0+int i; + + spapr->legacy_icps =g_malloc0 (nr_servers *sizeof (ICPState));
This isn't technically safe, although you'll probably get away with it. spapr->icp_type is parameterized, which means it could be a sub-class with a larger state structure than base ICPState.
Quoted 124 lines
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 167
Quoted 2 lines
hw/ppc/spapr.c +2
-0+for (i =0 ; i < nr_servers; i++) { +void * obj = &spapr->legacy_icps[i];'void *'
hw/ppc/spapr.c static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) · line 171
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ +object_initialize (obj,sizeof (ICPState), spapr->icp_type); +object_property_add_child (OBJECT (spapr),"icp[*]" , obj, + &error_abort);David does not like the "icp[*]" syntax.
Quoted 111 lines
hw/ppc/spapr.c +18
-0+object_unref (obj); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), + &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +while (i--) { +object_unparent (obj); + } +g_free (spapr->legacy_icps); +break ; + } + } + } + +out:error_propagate (errp, local_err); }@@ -3256,8 +3289,11 @@ 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 ); + smc->must_pre_allocate_icps = true; } DEFINE_SPAPR_MACHINE(2_9, "2.9", false);hw/ppc/spapr_cpu_core.c +20
-8@@ -119,6 +119,7 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)size_t size =object_type_get_instance_size (typename);CPUCore *cc =CPU_CORE (dev);int i; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());for (i =0 ; i < cc->nr_threads; i++) {void *obj = sc->threads + i * size;@@ -127,7 +128,9 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);spapr_cpu_destroy (cpu); -object_unparent (cpu->intc); +if (!spapr->legacy_icps) { +object_unparent (cpu->intc); + }cpu_remove_sync (cs);object_unparent (obj); }@@ -142,12 +145,19 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj,NULL ); -object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); -if (local_err) { - goto error; +if (spapr->legacy_icps) { +int index = cpu->parent_obj.cpu_index; + + obj =OBJECT (&spapr->legacy_icps[index]); + }else { + obj =object_new (spapr->icp_type); +object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), + &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } }object_property_set_bool (child, true,"realized" , &local_err);@@ -164,7 +174,9 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)return ; error: -object_unparent (obj); +if (!spapr->legacy_icps) { +object_unparent (obj); + }error_propagate (errp, local_err); }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 must_pre_allocate_icps;/* only for pseries-2.9 and older */ void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,@@ -109,6 +110,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +ICPState *legacy_icps; };#define H_SUCCESS 0
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] [Qemu-ppc] [PATCH 6/6] spapr: fix migration of ICP objects from/to older QEMU
In reply to Greg KurzQuoted 6 lines · On Mon, 15 May 2017 13:40:04 +0200 Greg Kurz <[email protected]> wrote:
Commit
5bc8d26de20c("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions.
Quoted 7 lines
This patch introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects.
While here, we also ensure that
object_property_add_child()errors cause QEMU to abort for newer machines.
Looking at the code again...
Quoted 6 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/ppc/spapr.c | 36 ++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 28 ++++++++++++++++++++-------- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 58 insertions(+), 8 deletions(-)
[...]
hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize_child(Object *child, Error **errp) · line 146
Quoted 6 lines
hw/ppc/spapr_cpu_core.c +0
-2@@ -142,12 +145,19 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)PowerPCCPU *cpu =POWERPC_CPU (cs);Object *obj; - obj =object_new (spapr->icp_type); -object_property_add_child (OBJECT (cpu),"icp" , obj,NULL );
... I now realize that we're lacking
object_unref(obj);
and the ref count of the ICP object can never go down to zero...
I'll fix that in a preparatory patch for v2.
Quoted 53 lines
hw/ppc/spapr_cpu_core.c +16
-5-object_property_add_const_link (obj,"xics" ,OBJECT (spapr), &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); -if (local_err) { - goto error; +if (spapr->legacy_icps) { +int index = cpu->parent_obj.cpu_index; + + obj =OBJECT (&spapr->legacy_icps[index]); + }else { + obj =object_new (spapr->icp_type); +object_property_add_child (OBJECT (cpu),"icp" , obj, &error_abort); +object_property_add_const_link (obj,"xics" ,OBJECT (spapr), + &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } }object_property_set_bool (child, true,"realized" , &local_err);@@ -164,7 +174,9 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)return ; error: -object_unparent (obj); +if (!spapr->legacy_icps) { +object_unparent (obj); + }error_propagate (errp, local_err); }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 must_pre_allocate_icps;/* only for pseries-2.9 and older */ void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64,@@ -109,6 +110,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +ICPState *legacy_icps; };#define H_SUCCESS 0
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [Qemu-devel] [PATCH 0/6] spapr/xics: fix migration of older machine types
Message-id: [email protected]
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
3c3824a spapr: fix migration of ICP objects from/to older QEMU 280164f spapr-cpu-core: release ICP object when realization fails 5bc72eb spapr: sanitize error handling in spapr_ics_create() fa15d00 spapr: fix error reporting in xics_system_init() ecbe234 spapr: fix error path of required kernel-irqchip b7cf73d ppc/xics: simplify prototype of xics_spapr_init()
=== OUTPUT BEGIN ===
Checking PATCH 1/6: ppc/xics: simplify prototype of xics_spapr_init()... Checking PATCH 2/6: spapr: fix error path of required kernel-irqchip... Checking PATCH 3/6: spapr: fix error reporting in xics_system_init()... Checking PATCH 4/6: spapr: sanitize error handling in spapr_ics_create()... Checking PATCH 5/6: spapr-cpu-core: release ICP object when realization fails... Checking PATCH 6/6: spapr: fix migration of ICP objects from/to older QEMU...
ERROR: "foo* bar" should be "foo *bar"
#50: FILE: hw/ppc/spapr.c:167:
+ void* obj = &spapr->legacy_icps[i];
total: 1 errors, 0 warnings, 122 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 44 lines · On Mon, 15 May 2017 05:13:34 -0700 (PDT) [email protected] wrote:
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [Qemu-devel] [PATCH 0/6] spapr/xics: fix migration of older machine types
Message-id: [email protected]
Type: series=== TEST SCRIPT BEGIN ===
#!/bin/bashBASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0git config --local diff.renamelimit 0
git config --local diff.renames Truecommits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..." if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then failed=1 echo fi n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===Updating
3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
3c3824a spapr: fix migration of ICP objects from/to older QEMU 280164f spapr-cpu-core: release ICP object when realization fails 5bc72eb spapr: sanitize error handling inspapr_ics_create()fa15d00 spapr: fix error reporting inxics_system_init()ecbe234 spapr: fix error path of required kernel-irqchip b7cf73d ppc/xics: simplify prototype ofxics_spapr_init()
Quoted 11 lines
=== OUTPUT BEGIN ===
Checking PATCH 1/6: ppc/xics: simplify prototype ofxics_spapr_init()... Checking PATCH 2/6: spapr: fix error path of required kernel-irqchip... Checking PATCH 3/6: spapr: fix error reporting inxics_system_init()... Checking PATCH 4/6: spapr: sanitize error handling inspapr_ics_create()... Checking PATCH 5/6: spapr-cpu-core: release ICP object when realization fails... Checking PATCH 6/6: spapr: fix migration of ICP objects from/to older QEMU...
ERROR: "foo* bar" should be "foo *bar"
#50: FILE:hw/ppc/spapr.c:167:
+ void* obj = &spapr->legacy_icps[i];
Oops, I'll fix that.
Quoted 14 lines
total: 1 errors, 0 warnings, 122 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]