Skip to contentSkip to conversation

s390x: cpu cleanups

PATCH Applied Igor Mammedov 2 participants 8 messages Oct 17, 2017

lore
Share & tools
lore
#0 lore raw

cover s390x: cpu cleanups

series includes remaining in my queue non cpu_model refactoring patches that fix and cleanup cpu_init code

CC Richard Henderson <[email protected]>
CC Alexander Graf <[email protected]>
CC Cornelia Huck <[email protected]>
CC Christian Borntraeger <[email protected]>

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
#1 lore raw

PATCH 1/2 s390x: fix cpu object referrence leak in s390x_new_cpu()

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.

---
 target/s390x/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/helper.c +1 -1
index 97adbcc..64d4c48 100644
@@ -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
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] s390x: fix cpu object referrence leak in s390x_new_cpu()

Quoted 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.

---
 target/s390x/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/helper.c +0 -0
index 97adbcc..64d4c48 100644

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.

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] s390x: fix cpu object referrence leak in s390x_new_cpu()

In reply to Igor Mammedov
Quoted 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.

---
 target/s390x/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/helper.c +0 -0
index 97adbcc..64d4c48 100644

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.

#4 lore raw

PATCH 2/2 s390x: move s390x_new_cpu() into board code

In reply to Igor Mammedov

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
index 7e864c8..b177be9 100644
@@ -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
index 32d3f11..f64db51 100644
@@ -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
index 64d4c48..52aa64b 100644
@@ -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
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] s390x: move s390x_new_cpu() into board code

Quoted 27 lines · On Tue, 17 Oct 2017 15:41:20 +0200 Igor Mammedov <[email protected]> wrote:

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
index 7e864c8..b177be9 100644
@@ -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
index 32d3f11..f64db51 100644

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
index 64d4c48..52aa64b 100644
@@ -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.

#6 lore raw

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
index 7e864c8..b177be9 100644
@@ -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
index 32d3f11..e593c71 100644
@@ -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
index 64d4c48..52aa64b 100644
@@ -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
#7 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] s390x: move s390x_new_cpu() into board code

Quoted 7 lines · On Tue, 17 Oct 2017 17:13:23 +0200 Igor Mammedov <[email protected]> wrote:

s390-virtio-ccw.c is the sole user of s390x_new_cpu(), so move this helper there.

---
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.