All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/dma/xlnx_csu_dma: Fix ptimer resource leak
@ 2021-08-19 14:15 Philippe Mathieu-Daudé
  2021-08-19 14:21 ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-19 14:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Bin Meng, Xuzhou Cheng, Alistair Francis,
	qemu-arm, Edgar E. Iglesias, Philippe Mathieu-Daudé

Fixes: 35593573b25 ("hw/dma: Implement a Xilinx CSU DMA model")
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/dma/xlnx_csu_dma.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/dma/xlnx_csu_dma.c b/hw/dma/xlnx_csu_dma.c
index 797b4fed8f5..0c1c19cab5a 100644
--- a/hw/dma/xlnx_csu_dma.c
+++ b/hw/dma/xlnx_csu_dma.c
@@ -660,6 +660,13 @@ static void xlnx_csu_dma_realize(DeviceState *dev, Error **errp)
     s->r_size_last_word = 0;
 }
 
+static void xlnx_csu_dma_unrealize(DeviceState *dev)
+{
+    XlnxCSUDMA *s = XLNX_CSU_DMA(dev);
+
+    ptimer_free(s->src_timer);
+}
+
 static const VMStateDescription vmstate_xlnx_csu_dma = {
     .name = TYPE_XLNX_CSU_DMA,
     .version_id = 0,
@@ -700,6 +707,7 @@ static void xlnx_csu_dma_class_init(ObjectClass *klass, void *data)
 
     dc->reset = xlnx_csu_dma_reset;
     dc->realize = xlnx_csu_dma_realize;
+    dc->unrealize = xlnx_csu_dma_unrealize;
     dc->vmsd = &vmstate_xlnx_csu_dma;
     device_class_set_props(dc, xlnx_csu_dma_properties);
 
-- 
2.31.1



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

* Re: [PATCH] hw/dma/xlnx_csu_dma: Fix ptimer resource leak
  2021-08-19 14:15 [PATCH] hw/dma/xlnx_csu_dma: Fix ptimer resource leak Philippe Mathieu-Daudé
@ 2021-08-19 14:21 ` Peter Maydell
  2021-08-19 14:39   ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2021-08-19 14:21 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Bin Meng, Xuzhou Cheng, Alistair Francis, QEMU Developers,
	qemu-arm, Edgar E. Iglesias

On Thu, 19 Aug 2021 at 15:15, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> Fixes: 35593573b25 ("hw/dma: Implement a Xilinx CSU DMA model")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  hw/dma/xlnx_csu_dma.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/hw/dma/xlnx_csu_dma.c b/hw/dma/xlnx_csu_dma.c
> index 797b4fed8f5..0c1c19cab5a 100644
> --- a/hw/dma/xlnx_csu_dma.c
> +++ b/hw/dma/xlnx_csu_dma.c
> @@ -660,6 +660,13 @@ static void xlnx_csu_dma_realize(DeviceState *dev, Error **errp)
>      s->r_size_last_word = 0;
>  }

This is a sysbus device -- when can it ever get unrealized ?

-- PMM


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

* Re: [PATCH] hw/dma/xlnx_csu_dma: Fix ptimer resource leak
  2021-08-19 14:21 ` Peter Maydell
@ 2021-08-19 14:39   ` Philippe Mathieu-Daudé
  2021-08-19 14:53     ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-19 14:39 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Xuzhou Cheng, Bin Meng, qemu-arm, QEMU Developers, Alistair Francis

On 8/19/21 4:21 PM, Peter Maydell wrote:
> On Thu, 19 Aug 2021 at 15:15, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>
>> Fixes: 35593573b25 ("hw/dma: Implement a Xilinx CSU DMA model")
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>  hw/dma/xlnx_csu_dma.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/hw/dma/xlnx_csu_dma.c b/hw/dma/xlnx_csu_dma.c
>> index 797b4fed8f5..0c1c19cab5a 100644
>> --- a/hw/dma/xlnx_csu_dma.c
>> +++ b/hw/dma/xlnx_csu_dma.c
>> @@ -660,6 +660,13 @@ static void xlnx_csu_dma_realize(DeviceState *dev, Error **errp)
>>      s->r_size_last_word = 0;
>>  }
> 
> This is a sysbus device -- when can it ever get unrealized ?

Alright. Then we should add an assertion if a SysBusDevice has a
non-NULL unrealize() handler.



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

* Re: [PATCH] hw/dma/xlnx_csu_dma: Fix ptimer resource leak
  2021-08-19 14:39   ` Philippe Mathieu-Daudé
@ 2021-08-19 14:53     ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2021-08-19 14:53 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Xuzhou Cheng, Bin Meng, qemu-arm, QEMU Developers, Alistair Francis

On Thu, 19 Aug 2021 at 15:40, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> On 8/19/21 4:21 PM, Peter Maydell wrote:
> > On Thu, 19 Aug 2021 at 15:15, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> >>
> >> Fixes: 35593573b25 ("hw/dma: Implement a Xilinx CSU DMA model")
> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> >> ---
> >>  hw/dma/xlnx_csu_dma.c | 8 ++++++++
> >>  1 file changed, 8 insertions(+)
> >>
> >> diff --git a/hw/dma/xlnx_csu_dma.c b/hw/dma/xlnx_csu_dma.c
> >> index 797b4fed8f5..0c1c19cab5a 100644
> >> --- a/hw/dma/xlnx_csu_dma.c
> >> +++ b/hw/dma/xlnx_csu_dma.c
> >> @@ -660,6 +660,13 @@ static void xlnx_csu_dma_realize(DeviceState *dev, Error **errp)
> >>      s->r_size_last_word = 0;
> >>  }
> >
> > This is a sysbus device -- when can it ever get unrealized ?
>
> Alright. Then we should add an assertion if a SysBusDevice has a
> non-NULL unrealize() handler.

There are a few corner cases where a sysbus device can be
unrealized (eg if it is used as part of the implementation of
a hotpluggable device like a PCI card).

More generally, what are we trying to achieve here ?
I definitely agree that our current situation wrt freeing of
resources allocated during realize is liable to be a bit of a
mess, but I'm not sure trying to patch individual cases one
device at a time is likely to help.

A comprehensive attack on the problem would probably involve:
 * documentation
   + what should go in instance_init and what in realize?
   + where should deallocation go?
   + if realize fails and it has already allocated something,
     who deallocates that and how?
   + are there cases which don't need to care about ever being
     unrealized, and how should those be written?
   + helpful checklist of common functions that need deinit,
     and ones that don't because they do refcounting
 * figuring out a test setup that would let us test the
   init->realize->unrealize->deinit cycle for all devices,
   not just hotpluggable ones. (We do init->deinit as part
   of the QOM introspection test; I'm not sure how much
   leakage of what kinds we catch that way.)
 * looking at how many of our existing devices fail that,
   and whether we can have an exclusion-list or something so
   at least new code has "get this right" tested, and maybe
   we can whittle down the exclusion-list over time (and we
   can prioritize the devices where this is actually a user
   visible bug or that get maintained)

thanks
-- PMM


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

end of thread, other threads:[~2021-08-19 14:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 14:15 [PATCH] hw/dma/xlnx_csu_dma: Fix ptimer resource leak Philippe Mathieu-Daudé
2021-08-19 14:21 ` Peter Maydell
2021-08-19 14:39   ` Philippe Mathieu-Daudé
2021-08-19 14:53     ` 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.