All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] delay timer_new to avoid memleaks
@ 2020-02-05  7:06 pannengyuan
  2020-02-05  7:06 ` [PATCH 1/3] armv7m_systick: " pannengyuan
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: pannengyuan @ 2020-02-05  7:06 UTC (permalink / raw)
  To: peter.maydell; +Cc: Pan Nengyuan, zhang.zhanghailiang, qemu-devel

From: Pan Nengyuan <pannengyuan@huawei.com>

This series delay timer_new into realize() to fix some memleaks when we call 'device-list-properties'.

Pan Nengyuan (3):
  armv7m_systick: delay timer_new to avoid memleaks
  stm32f2xx_timer: delay timer_new to avoid memleaks
  stellaris: delay timer_new to avoid memleaks

 hw/arm/stellaris.c         | 7 ++++++-
 hw/timer/armv7m_systick.c  | 6 ++++++
 hw/timer/stm32f2xx_timer.c | 5 +++++
 3 files changed, 17 insertions(+), 1 deletion(-)

-- 
2.21.0.windows.1




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] armv7m_systick: delay timer_new to avoid memleaks
  2020-02-05  7:06 [PATCH 0/3] delay timer_new to avoid memleaks pannengyuan
@ 2020-02-05  7:06 ` pannengyuan
  2020-02-05  7:06 ` [PATCH 2/3] stm32f2xx_timer: " pannengyuan
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: pannengyuan @ 2020-02-05  7:06 UTC (permalink / raw)
  To: peter.maydell
  Cc: Euler Robot, Pan Nengyuan, zhang.zhanghailiang, qemu-arm, qemu-devel

From: Pan Nengyuan <pannengyuan@huawei.com>

There is a memory leak when we call 'device_list_properties' with typename = armv7m_systick. It's easy to reproduce as follow:

  virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "armv7m_systick"}}'

This patch delay timer_new to fix this memleaks.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Cc: qemu-arm@nongnu.org
---
 hw/timer/armv7m_systick.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c
index 85d122dbcb..74c58bcf24 100644
--- a/hw/timer/armv7m_systick.c
+++ b/hw/timer/armv7m_systick.c
@@ -216,6 +216,11 @@ static void systick_instance_init(Object *obj)
     memory_region_init_io(&s->iomem, obj, &systick_ops, s, "systick", 0xe0);
     sysbus_init_mmio(sbd, &s->iomem);
     sysbus_init_irq(sbd, &s->irq);
+}
+
+static void systick_realize(DeviceState *dev, Error **errp)
+{
+    SysTickState *s = SYSTICK(dev);
     s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, systick_timer_tick, s);
 }
 
@@ -238,6 +243,7 @@ static void systick_class_init(ObjectClass *klass, void *data)
 
     dc->vmsd = &vmstate_systick;
     dc->reset = systick_reset;
+    dc->realize = systick_realize;
 }
 
 static const TypeInfo armv7m_systick_info = {
-- 
2.21.0.windows.1




^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] stm32f2xx_timer: delay timer_new to avoid memleaks
  2020-02-05  7:06 [PATCH 0/3] delay timer_new to avoid memleaks pannengyuan
  2020-02-05  7:06 ` [PATCH 1/3] armv7m_systick: " pannengyuan
@ 2020-02-05  7:06 ` pannengyuan
  2020-02-05 13:17   ` Philippe Mathieu-Daudé
  2020-02-05 18:49   ` Alistair Francis
  2020-02-05  7:06 ` [PATCH 3/3] stellaris: " pannengyuan
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 10+ messages in thread
From: pannengyuan @ 2020-02-05  7:06 UTC (permalink / raw)
  To: peter.maydell
  Cc: Euler Robot, Pan Nengyuan, zhang.zhanghailiang, Alistair Francis,
	qemu-devel

From: Pan Nengyuan <pannengyuan@huawei.com>

There is a memory leak when we call 'device_list_properties' with typename = stm32f2xx_timer. It's easy to reproduce as follow:

    virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "stm32f2xx_timer"}}'

This patch delay timer_new to fix this memleaks.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Cc: Alistair Francis <alistair@alistair23.me>
---
 hw/timer/stm32f2xx_timer.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
index fb370ce0f0..06ec8a02c2 100644
--- a/hw/timer/stm32f2xx_timer.c
+++ b/hw/timer/stm32f2xx_timer.c
@@ -314,7 +314,11 @@ static void stm32f2xx_timer_init(Object *obj)
     memory_region_init_io(&s->iomem, obj, &stm32f2xx_timer_ops, s,
                           "stm32f2xx_timer", 0x400);
     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
 
+static void stm32f2xx_timer_realize(DeviceState *dev, Error **errp)
+{
+    STM32F2XXTimerState *s = STM32F2XXTIMER(dev);
     s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, stm32f2xx_timer_interrupt, s);
 }
 
@@ -325,6 +329,7 @@ static void stm32f2xx_timer_class_init(ObjectClass *klass, void *data)
     dc->reset = stm32f2xx_timer_reset;
     device_class_set_props(dc, stm32f2xx_timer_properties);
     dc->vmsd = &vmstate_stm32f2xx_timer;
+    dc->realize = stm32f2xx_timer_realize;
 }
 
 static const TypeInfo stm32f2xx_timer_info = {
-- 
2.21.0.windows.1




^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] stellaris: delay timer_new to avoid memleaks
  2020-02-05  7:06 [PATCH 0/3] delay timer_new to avoid memleaks pannengyuan
  2020-02-05  7:06 ` [PATCH 1/3] armv7m_systick: " pannengyuan
  2020-02-05  7:06 ` [PATCH 2/3] stm32f2xx_timer: " pannengyuan
@ 2020-02-05  7:06 ` pannengyuan
  2020-02-05 13:10   ` Philippe Mathieu-Daudé
  2020-02-05 13:16 ` [PATCH 0/3] " Philippe Mathieu-Daudé
  2020-02-07 13:42 ` Peter Maydell
  4 siblings, 1 reply; 10+ messages in thread
From: pannengyuan @ 2020-02-05  7:06 UTC (permalink / raw)
  To: peter.maydell
  Cc: Euler Robot, Pan Nengyuan, zhang.zhanghailiang, qemu-arm, qemu-devel

From: Pan Nengyuan <pannengyuan@huawei.com>

There is a memory leak when we call 'device_list_properties' with typename = stellaris-gptm. It's easy to reproduce as follow:

  virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "stellaris-gptm"}}'

This patch delay timer_new in realize to fix it.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Cc: qemu-arm@nongnu.org
---
 hw/arm/stellaris.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index bb025e0bd0..221a78674e 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -347,11 +347,15 @@ static void stellaris_gptm_init(Object *obj)
     sysbus_init_mmio(sbd, &s->iomem);
 
     s->opaque[0] = s->opaque[1] = s;
+}
+
+static void stellaris_gptm_realize(DeviceState *dev, Error **errp)
+{
+    gptm_state *s = STELLARIS_GPTM(dev);
     s->timer[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[0]);
     s->timer[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[1]);
 }
 
-
 /* System controller.  */
 
 typedef struct {
@@ -1536,6 +1540,7 @@ static void stellaris_gptm_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_stellaris_gptm;
+    dc->realize = stellaris_gptm_realize;
 }
 
 static const TypeInfo stellaris_gptm_info = {
-- 
2.21.0.windows.1




^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] stellaris: delay timer_new to avoid memleaks
  2020-02-05  7:06 ` [PATCH 3/3] stellaris: " pannengyuan
@ 2020-02-05 13:10   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-05 13:10 UTC (permalink / raw)
  To: pannengyuan, peter.maydell
  Cc: qemu-devel, qemu-arm, zhang.zhanghailiang, Euler Robot

On 2/5/20 8:06 AM, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
> 
> There is a memory leak when we call 'device_list_properties' with typename = stellaris-gptm. It's easy to reproduce as follow:
> 
>    virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "stellaris-gptm"}}'
> 
> This patch delay timer_new in realize to fix it.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Cc: qemu-arm@nongnu.org
> ---
>   hw/arm/stellaris.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
> index bb025e0bd0..221a78674e 100644
> --- a/hw/arm/stellaris.c
> +++ b/hw/arm/stellaris.c
> @@ -347,11 +347,15 @@ static void stellaris_gptm_init(Object *obj)
>       sysbus_init_mmio(sbd, &s->iomem);
>   
>       s->opaque[0] = s->opaque[1] = s;
> +}
> +
> +static void stellaris_gptm_realize(DeviceState *dev, Error **errp)
> +{
> +    gptm_state *s = STELLARIS_GPTM(dev);
>       s->timer[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[0]);
>       s->timer[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[1]);
>   }
>   
> -
>   /* System controller.  */
>   
>   typedef struct {
> @@ -1536,6 +1540,7 @@ static void stellaris_gptm_class_init(ObjectClass *klass, void *data)
>       DeviceClass *dc = DEVICE_CLASS(klass);
>   
>       dc->vmsd = &vmstate_stellaris_gptm;
> +    dc->realize = stellaris_gptm_realize;
>   }
>   
>   static const TypeInfo stellaris_gptm_info = {
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] delay timer_new to avoid memleaks
  2020-02-05  7:06 [PATCH 0/3] delay timer_new to avoid memleaks pannengyuan
                   ` (2 preceding siblings ...)
  2020-02-05  7:06 ` [PATCH 3/3] stellaris: " pannengyuan
@ 2020-02-05 13:16 ` Philippe Mathieu-Daudé
  2020-02-06  1:14   ` Pan Nengyuan
  2020-02-07 13:42 ` Peter Maydell
  4 siblings, 1 reply; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-05 13:16 UTC (permalink / raw)
  To: pannengyuan, peter.maydell; +Cc: zhang.zhanghailiang, qemu-devel

On 2/5/20 8:06 AM, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
> 
> This series delay timer_new into realize() to fix some memleaks when we call 'device-list-properties'.
> 
> Pan Nengyuan (3):
>    armv7m_systick: delay timer_new to avoid memleaks
>    stm32f2xx_timer: delay timer_new to avoid memleaks
>    stellaris: delay timer_new to avoid memleaks
> 
>   hw/arm/stellaris.c         | 7 ++++++-
>   hw/timer/armv7m_systick.c  | 6 ++++++
>   hw/timer/stm32f2xx_timer.c | 5 +++++
>   3 files changed, 17 insertions(+), 1 deletion(-)

You might want to look at Coccinelle [*] and write a spatch script to 
check/fix all the codebase at once. You can find some examples in 
scripts/coccinelle/.

[*] http://coccinelle.lip6.fr/



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] stm32f2xx_timer: delay timer_new to avoid memleaks
  2020-02-05  7:06 ` [PATCH 2/3] stm32f2xx_timer: " pannengyuan
@ 2020-02-05 13:17   ` Philippe Mathieu-Daudé
  2020-02-05 18:49   ` Alistair Francis
  1 sibling, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-05 13:17 UTC (permalink / raw)
  To: pannengyuan, peter.maydell
  Cc: qemu-devel, Alistair Francis, zhang.zhanghailiang, Euler Robot

On 2/5/20 8:06 AM, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
> 
> There is a memory leak when we call 'device_list_properties' with typename = stm32f2xx_timer. It's easy to reproduce as follow:
> 
>      virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "stm32f2xx_timer"}}'
> 
> This patch delay timer_new to fix this memleaks.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Cc: Alistair Francis <alistair@alistair23.me>
> ---
>   hw/timer/stm32f2xx_timer.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
> index fb370ce0f0..06ec8a02c2 100644
> --- a/hw/timer/stm32f2xx_timer.c
> +++ b/hw/timer/stm32f2xx_timer.c
> @@ -314,7 +314,11 @@ static void stm32f2xx_timer_init(Object *obj)
>       memory_region_init_io(&s->iomem, obj, &stm32f2xx_timer_ops, s,
>                             "stm32f2xx_timer", 0x400);
>       sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
> +}
>   
> +static void stm32f2xx_timer_realize(DeviceState *dev, Error **errp)
> +{
> +    STM32F2XXTimerState *s = STM32F2XXTIMER(dev);
>       s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, stm32f2xx_timer_interrupt, s);
>   }
>   
> @@ -325,6 +329,7 @@ static void stm32f2xx_timer_class_init(ObjectClass *klass, void *data)
>       dc->reset = stm32f2xx_timer_reset;
>       device_class_set_props(dc, stm32f2xx_timer_properties);
>       dc->vmsd = &vmstate_stm32f2xx_timer;
> +    dc->realize = stm32f2xx_timer_realize;
>   }
>   
>   static const TypeInfo stm32f2xx_timer_info = {
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] stm32f2xx_timer: delay timer_new to avoid memleaks
  2020-02-05  7:06 ` [PATCH 2/3] stm32f2xx_timer: " pannengyuan
  2020-02-05 13:17   ` Philippe Mathieu-Daudé
@ 2020-02-05 18:49   ` Alistair Francis
  1 sibling, 0 replies; 10+ messages in thread
From: Alistair Francis @ 2020-02-05 18:49 UTC (permalink / raw)
  To: pannengyuan
  Cc: qemu-devel@nongnu.org Developers, Peter Maydell,
	Alistair Francis, zhang.zhanghailiang, Euler Robot

On Tue, Feb 4, 2020 at 11:09 PM <pannengyuan@huawei.com> wrote:
>
> From: Pan Nengyuan <pannengyuan@huawei.com>
>
> There is a memory leak when we call 'device_list_properties' with typename = stm32f2xx_timer. It's easy to reproduce as follow:
>
>     virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "stm32f2xx_timer"}}'
>
> This patch delay timer_new to fix this memleaks.
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Cc: Alistair Francis <alistair@alistair23.me>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/timer/stm32f2xx_timer.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
> index fb370ce0f0..06ec8a02c2 100644
> --- a/hw/timer/stm32f2xx_timer.c
> +++ b/hw/timer/stm32f2xx_timer.c
> @@ -314,7 +314,11 @@ static void stm32f2xx_timer_init(Object *obj)
>      memory_region_init_io(&s->iomem, obj, &stm32f2xx_timer_ops, s,
>                            "stm32f2xx_timer", 0x400);
>      sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
> +}
>
> +static void stm32f2xx_timer_realize(DeviceState *dev, Error **errp)
> +{
> +    STM32F2XXTimerState *s = STM32F2XXTIMER(dev);
>      s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, stm32f2xx_timer_interrupt, s);
>  }
>
> @@ -325,6 +329,7 @@ static void stm32f2xx_timer_class_init(ObjectClass *klass, void *data)
>      dc->reset = stm32f2xx_timer_reset;
>      device_class_set_props(dc, stm32f2xx_timer_properties);
>      dc->vmsd = &vmstate_stm32f2xx_timer;
> +    dc->realize = stm32f2xx_timer_realize;
>  }
>
>  static const TypeInfo stm32f2xx_timer_info = {
> --
> 2.21.0.windows.1
>
>
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] delay timer_new to avoid memleaks
  2020-02-05 13:16 ` [PATCH 0/3] " Philippe Mathieu-Daudé
@ 2020-02-06  1:14   ` Pan Nengyuan
  0 siblings, 0 replies; 10+ messages in thread
From: Pan Nengyuan @ 2020-02-06  1:14 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, peter.maydell
  Cc: zhang.zhanghailiang, qemu-devel



On 2/5/2020 9:16 PM, Philippe Mathieu-Daudé wrote:
> On 2/5/20 8:06 AM, pannengyuan@huawei.com wrote:
>> From: Pan Nengyuan <pannengyuan@huawei.com>
>>
>> This series delay timer_new into realize() to fix some memleaks when we call 'device-list-properties'.
>>
>> Pan Nengyuan (3):
>>    armv7m_systick: delay timer_new to avoid memleaks
>>    stm32f2xx_timer: delay timer_new to avoid memleaks
>>    stellaris: delay timer_new to avoid memleaks
>>
>>   hw/arm/stellaris.c         | 7 ++++++-
>>   hw/timer/armv7m_systick.c  | 6 ++++++
>>   hw/timer/stm32f2xx_timer.c | 5 +++++
>>   3 files changed, 17 insertions(+), 1 deletion(-)
> 
> You might want to look at Coccinelle [*] and write a spatch script to check/fix all the codebase at once. You can find some examples in scripts/coccinelle/.

Thanks for these tips. I will pay attention.

> 
> [*] http://coccinelle.lip6.fr/
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] delay timer_new to avoid memleaks
  2020-02-05  7:06 [PATCH 0/3] delay timer_new to avoid memleaks pannengyuan
                   ` (3 preceding siblings ...)
  2020-02-05 13:16 ` [PATCH 0/3] " Philippe Mathieu-Daudé
@ 2020-02-07 13:42 ` Peter Maydell
  4 siblings, 0 replies; 10+ messages in thread
From: Peter Maydell @ 2020-02-07 13:42 UTC (permalink / raw)
  To: pannengyuan; +Cc: zhanghailiang, QEMU Developers

On Wed, 5 Feb 2020 at 07:07, <pannengyuan@huawei.com> wrote:
>
> From: Pan Nengyuan <pannengyuan@huawei.com>
>
> This series delay timer_new into realize() to fix some memleaks when we call 'device-list-properties'.
>
> Pan Nengyuan (3):
>   armv7m_systick: delay timer_new to avoid memleaks
>   stm32f2xx_timer: delay timer_new to avoid memleaks
>   stellaris: delay timer_new to avoid memleaks
>
>  hw/arm/stellaris.c         | 7 ++++++-
>  hw/timer/armv7m_systick.c  | 6 ++++++
>  hw/timer/stm32f2xx_timer.c | 5 +++++
>  3 files changed, 17 insertions(+), 1 deletion(-)



Applied to target-arm.next, thanks.

-- PMM


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-02-07 13:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05  7:06 [PATCH 0/3] delay timer_new to avoid memleaks pannengyuan
2020-02-05  7:06 ` [PATCH 1/3] armv7m_systick: " pannengyuan
2020-02-05  7:06 ` [PATCH 2/3] stm32f2xx_timer: " pannengyuan
2020-02-05 13:17   ` Philippe Mathieu-Daudé
2020-02-05 18:49   ` Alistair Francis
2020-02-05  7:06 ` [PATCH 3/3] stellaris: " pannengyuan
2020-02-05 13:10   ` Philippe Mathieu-Daudé
2020-02-05 13:16 ` [PATCH 0/3] " Philippe Mathieu-Daudé
2020-02-06  1:14   ` Pan Nengyuan
2020-02-07 13:42 ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.