s390x: cpu cleanups
PATCH 1/2 s390x: fix cpu object referrence leak in s390x_new_cpu()
In reply to Igor Mammedovobject_new() returns cpu with refcnt == 1 and after realize refcnt == 2*. s390x_new_cpu() as an owner of the first refcnt should have released it on exit in both cases (on error and success) to avoid it leaking. Do so for both cases.
--- target/s390x/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/helper.c +1 -1
@@ -80,9 +80,9 @@ S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp)object_property_set_bool (OBJECT (cpu), true,"realized" , &err); out: +object_unref (OBJECT (cpu));if (err) {error_propagate (errp, err); -object_unref (OBJECT (cpu)); cpu =NULL ; }return cpu;
Signature · 1 line
2.7.4
cover s390x: cpu cleanups
series includes remaining in my queue non cpu_model refactoring patches that fix and cleanup cpu_init code
Igor Mammedov (2):
s390x: fix cpu object referrence leak in s390x_new_cpu()
s390x: move s390x_new_cpu() into board code
target/s390x/cpu.h | 1 - hw/s390x/s390-virtio-ccw.c | 21 +++++++++++++++++++++ target/s390x/helper.c | 20 -------------------- 3 files changed, 21 insertions(+), 21 deletions(-)
Signature · 1 line
2.7.4
PATCH 2/2 s390x: move s390x_new_cpu() into board code
s390-virtio-ccw.c is the sole user of s390x_new_cpu(), so move this helper there.
--- target/s390x/cpu.h | 1 - hw/s390x/s390-virtio-ccw.c | 21 +++++++++++++++++++++ target/s390x/helper.c | 20 -------------------- 3 files changed, 21 insertions(+), 21 deletions(-)
target/s390x/cpu.h +0 -1
@@ -695,7 +695,6 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);/* helper.c */ #define cpu_init (cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model) -S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp);#define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU#define S390_CPU_TYPE_NAME (name) (name S390_CPU_TYPE_SUFFIX)
hw/s390x/s390-virtio-ccw.c +21 -0
@@ -52,6 +52,27 @@ S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)return S390_CPU (ms->possible_cpus->cpus[cpu_addr].cpu); } +static +S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp) +{ +S390CPU *cpu =S390_CPU (object_new (typename)); +Error *err =NULL ; + +object_property_set_int (OBJECT (cpu), core_id,"core-id" , &err); +if (err !=NULL ) { + goto out; + } +object_property_set_bool (OBJECT (cpu), true,"realized" , &err); + +out: +object_unref (OBJECT (cpu)); +if (err) { +error_propagate (errp, err); + cpu =NULL ; + } +return cpu; +} +static void s390_init_cpus (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine);
target/s390x/helper.c +0 -20
@@ -68,26 +68,6 @@ void s390x_cpu_timer(void *opaque) }#endif -S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp) -{ -S390CPU *cpu =S390_CPU (object_new (typename)); -Error *err =NULL ; - -object_property_set_int (OBJECT (cpu), core_id,"core-id" , &err); -if (err !=NULL ) { - goto out; - } -object_property_set_bool (OBJECT (cpu), true,"realized" , &err); - -out: -object_unref (OBJECT (cpu)); -if (err) { -error_propagate (errp, err); - cpu =NULL ; - } -return cpu; -} -#ifndef CONFIG_USER_ONLY hwaddr s390_cpu_get_phys_page_debug (CPUState *cs,vaddr vaddr)
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/2] s390x: fix cpu object referrence leak in s390x_new_cpu()
In reply to Igor MammedovQuoted 15 lines · On Tue, 17 Oct 2017 15:41:19 +0200 Igor Mammedov <[email protected]> wrote:
object_new()returns cpu with refcnt == 1 and after realize refcnt == 2*.s390x_new_cpu()as an owner of the first refcnt should have released it on exit in both cases (on error and success) to avoid it leaking. Do so for both cases.Signed-off-by Igor Mammedov <[email protected]>--- target/s390x/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/helper.c +0
-0
target/s390x/helper.c S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp) · line 88
Quoted 10 lines
target/s390x/helper.c +1
-1@@ -80,9 +80,9 @@ S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp)object_property_set_bool (OBJECT (cpu), true,"realized" , &err); out: +object_unref (OBJECT (cpu));if (err) {error_propagate (errp, err); -object_unref (OBJECT (cpu)); cpu =NULL ; }return cpu;
Looks reasonable.
Re: [Qemu-devel] [PATCH 2/2] s390x: move s390x_new_cpu() into board code
In reply to Igor MammedovQuoted 27 lines · On Tue, 17 Oct 2017 15:41:20 +0200 Igor Mammedov <[email protected]> wrote:
s390-virtio-ccw.cis the sole user ofs390x_new_cpu(), so move this helper there.Signed-off-by Igor Mammedov <[email protected]>--- target/s390x/cpu.h | 1 - hw/s390x/s390-virtio-ccw.c | 21 +++++++++++++++++++++ target/s390x/helper.c | 20 -------------------- 3 files changed, 21 insertions(+), 21 deletions(-)target/s390x/cpu.h +0
-1@@ -695,7 +695,6 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);/* helper.c */ #define cpu_init (cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model) -S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp);#define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU#define S390_CPU_TYPE_NAME (name) (name S390_CPU_TYPE_SUFFIX)hw/s390x/s390-virtio-ccw.c +0
-0
hw/s390x/s390-virtio-ccw.c S390CPU *s390_cpu_addr2state(uint16_t cpu_addr) · line 56
Quoted 5 lines
hw/s390x/s390-virtio-ccw.c +2
-0@@ -52,6 +52,27 @@ S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)return S390_CPU (ms->possible_cpus->cpus[cpu_addr].cpu); } +static +S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp)
I don't like this wrap; better wrap the argument list.
Quoted 43 lines
hw/s390x/s390-virtio-ccw.c +19
-0+{ +S390CPU *cpu =S390_CPU (object_new (typename)); +Error *err =NULL ; + +object_property_set_int (OBJECT (cpu), core_id,"core-id" , &err); +if (err !=NULL ) { + goto out; + } +object_property_set_bool (OBJECT (cpu), true,"realized" , &err); + +out: +object_unref (OBJECT (cpu)); +if (err) { +error_propagate (errp, err); + cpu =NULL ; + } +return cpu; +} +static void s390_init_cpus (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine);target/s390x/helper.c +0
-13@@ -68,26 +68,6 @@ void s390x_cpu_timer(void *opaque) }#endif -S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp) -{ -S390CPU *cpu =S390_CPU (object_new (typename)); -Error *err =NULL ; - -object_property_set_int (OBJECT (cpu), core_id,"core-id" , &err); -if (err !=NULL ) { - goto out; - } -object_property_set_bool (OBJECT (cpu), true,"realized" , &err); - -out: -object_unref (OBJECT (cpu));
target/s390x/helper.c void s390x_cpu_timer(void *opaque) · line 73
Quoted 10 lines
target/s390x/helper.c +0
-7-if (err) { -error_propagate (errp, err); - cpu =NULL ; - } -return cpu; -} -#ifndef CONFIG_USER_ONLY hwaddr s390_cpu_get_phys_page_debug (CPUState *cs,vaddr vaddr)
Otherwise, looks sane.
PATCH v2 2/2 s390x: move s390x_new_cpu() into board code
s390-virtio-ccw.c is the sole user of s390x_new_cpu(), so move this helper there.
---
CC: Cornelia Huck <[email protected]>
v2:
- style fix: wrap the argument list
--- target/s390x/cpu.h | 1 - hw/s390x/s390-virtio-ccw.c | 21 +++++++++++++++++++++ target/s390x/helper.c | 20 -------------------- 3 files changed, 21 insertions(+), 21 deletions(-)
target/s390x/cpu.h +0 -1
@@ -695,7 +695,6 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);/* helper.c */ #define cpu_init (cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model) -S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp);#define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU#define S390_CPU_TYPE_NAME (name) (name S390_CPU_TYPE_SUFFIX)
hw/s390x/s390-virtio-ccw.c +21 -0
@@ -52,6 +52,27 @@ S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)return S390_CPU (ms->possible_cpus->cpus[cpu_addr].cpu); } +static S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id, +Error **errp) +{ +S390CPU *cpu =S390_CPU (object_new (typename)); +Error *err =NULL ; + +object_property_set_int (OBJECT (cpu), core_id,"core-id" , &err); +if (err !=NULL ) { + goto out; + } +object_property_set_bool (OBJECT (cpu), true,"realized" , &err); + +out: +object_unref (OBJECT (cpu)); +if (err) { +error_propagate (errp, err); + cpu =NULL ; + } +return cpu; +} +static void s390_init_cpus (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine);
target/s390x/helper.c +0 -20
@@ -68,26 +68,6 @@ void s390x_cpu_timer(void *opaque) }#endif -S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp) -{ -S390CPU *cpu =S390_CPU (object_new (typename)); -Error *err =NULL ; - -object_property_set_int (OBJECT (cpu), core_id,"core-id" , &err); -if (err !=NULL ) { - goto out; - } -object_property_set_bool (OBJECT (cpu), true,"realized" , &err); - -out: -object_unref (OBJECT (cpu)); -if (err) { -error_propagate (errp, err); - cpu =NULL ; - } -return cpu; -} -#ifndef CONFIG_USER_ONLY hwaddr s390_cpu_get_phys_page_debug (CPUState *cs,vaddr vaddr)
Signature · 1 line
2.7.4
Cornelia Huck
AppliedRe: [Qemu-devel] [PATCH 1/2] s390x: fix cpu object referrence leak in s390x_new_cpu()
In reply to Igor MammedovQuoted 15 lines · On Tue, 17 Oct 2017 15:41:19 +0200 Igor Mammedov <[email protected]> wrote:
object_new()returns cpu with refcnt == 1 and after realize refcnt == 2*.s390x_new_cpu()as an owner of the first refcnt should have released it on exit in both cases (on error and success) to avoid it leaking. Do so for both cases.Signed-off-by Igor Mammedov <[email protected]>--- target/s390x/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/helper.c +0
-0
target/s390x/helper.c S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp) · line 88
Quoted 10 lines
target/s390x/helper.c +1
-1@@ -80,9 +80,9 @@ S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp)object_property_set_bool (OBJECT (cpu), true,"realized" , &err); out: +object_unref (OBJECT (cpu));if (err) {error_propagate (errp, err); -object_unref (OBJECT (cpu)); cpu =NULL ; }return cpu;
Thanks, applied.
Cornelia Huck
AppliedRe: [Qemu-devel] [PATCH v2 2/2] s390x: move s390x_new_cpu() into board code
In reply to Igor MammedovQuoted 7 lines · On Tue, 17 Oct 2017 17:13:23 +0200 Igor Mammedov <[email protected]> wrote:
s390-virtio-ccw.cis the sole user ofs390x_new_cpu(), so move this helper there.Signed-off-by Igor Mammedov <[email protected]>---
CC: Cornelia Huck <[email protected]>
Quoted 8 lines
v2:
- style fix: wrap the argument list--- target/s390x/cpu.h | 1 - hw/s390x/s390-virtio-ccw.c | 21 +++++++++++++++++++++ target/s390x/helper.c | 20 -------------------- 3 files changed, 21 insertions(+), 21 deletions(-)
Thanks, applied.