All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] hw/core/qdev-clock: add a reference on aliased clocks
@ 2020-10-20  9:10 Luc Michel
  2020-10-20  9:17 ` no-reply
  2020-10-23 11:23 ` Marc-André Lureau
  0 siblings, 2 replies; 4+ messages in thread
From: Luc Michel @ 2020-10-20  9:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Peter Maydell, Daniel P . Berrangé,
	Eduardo Habkost, Philippe Mathieu-Daudé,
	Markus Armbruster, Marc-André Lureau, Paolo Bonzini,
	Luc Michel

When aliasing a clock with the qdev_alias_clock() function, a new link
property is created on the device aliasing the clock. The link points
to the aliased clock and use the OBJ_PROP_LINK_STRONG flag. This
property is read only since it does not provide a check callback for
modifications.

The object_property_add_link() documentation stats that with
OBJ_PROP_LINK_STRONG properties, the linked object reference count get
decremented when the property is deleted. But it is _not_ incremented on
creation (object_property_add_link() does not actually know the link).

This commit increments the reference count on the aliased clock to
ensure the aliased clock stays alive during the property lifetime, and
to avoid a double-free memory error when the property gets deleted.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Luc Michel <luc@lmichel.fr>
---
 hw/core/qdev-clock.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
index 6a9a340d0f..eb05f2a13c 100644
--- a/hw/core/qdev-clock.c
+++ b/hw/core/qdev-clock.c
@@ -59,10 +59,18 @@ static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name,
     } else {
         object_property_add_link(OBJECT(dev), name,
                                  object_get_typename(OBJECT(clk)),
                                  (Object **) &ncl->clock,
                                  NULL, OBJ_PROP_LINK_STRONG);
+        /*
+         * Since the link property has the OBJ_PROP_LINK_STRONG flag, the clk
+         * object reference count gets decremented on property deletion.
+         * However object_property_add_link does not increment it since it
+         * doesn't know the linked object. Increment it here to ensure the
+         * aliased clock stays alive during this device life-time.
+         */
+        object_ref(OBJECT(clk));
     }
 
     ncl->clock = clk;
 
     QLIST_INSERT_HEAD(&dev->clocks, ncl, node);
-- 
2.28.0



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

* Re: [PATCH v2] hw/core/qdev-clock: add a reference on aliased clocks
  2020-10-20  9:10 [PATCH v2] hw/core/qdev-clock: add a reference on aliased clocks Luc Michel
@ 2020-10-20  9:17 ` no-reply
  2020-10-23 11:23 ` Marc-André Lureau
  1 sibling, 0 replies; 4+ messages in thread
From: no-reply @ 2020-10-20  9:17 UTC (permalink / raw)
  To: luc
  Cc: damien.hedde, peter.maydell, berrange, ehabkost, armbru, f4bug,
	qemu-devel, pbonzini, luc, marcandre.lureau

Patchew URL: https://patchew.org/QEMU/20201020091024.320381-1-luc@lmichel.fr/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20201020091024.320381-1-luc@lmichel.fr
Subject: [PATCH v2] hw/core/qdev-clock: add a reference on aliased clocks

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
error: RPC failed; result=7, HTTP code = 0
fatal: The remote end hung up unexpectedly
error: Could not fetch 3c8cf5a9c21ff8782164d1def7f44bd888713384
Traceback (most recent call last):
  File "patchew-tester/src/patchew-cli", line 521, in test_one
    git_clone_repo(clone, r["repo"], r["head"], logf, True)
  File "patchew-tester/src/patchew-cli", line 48, in git_clone_repo
    stdout=logf, stderr=logf)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'remote', 'add', '-f', '--mirror=fetch', '3c8cf5a9c21ff8782164d1def7f44bd888713384', 'https://github.com/patchew-project/qemu']' returned non-zero exit status 1.



The full log is available at
http://patchew.org/logs/20201020091024.320381-1-luc@lmichel.fr/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [PATCH v2] hw/core/qdev-clock: add a reference on aliased clocks
  2020-10-20  9:10 [PATCH v2] hw/core/qdev-clock: add a reference on aliased clocks Luc Michel
  2020-10-20  9:17 ` no-reply
@ 2020-10-23 11:23 ` Marc-André Lureau
  2020-10-23 12:01   ` Luc Michel
  1 sibling, 1 reply; 4+ messages in thread
From: Marc-André Lureau @ 2020-10-23 11:23 UTC (permalink / raw)
  To: Luc Michel
  Cc: Damien Hedde, Peter Maydell, Daniel P . Berrangé,
	Eduardo Habkost, Markus Armbruster, Philippe Mathieu-Daudé,
	QEMU, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 2373 bytes --]

Hi

On Tue, Oct 20, 2020 at 1:11 PM Luc Michel <luc@lmichel.fr> wrote:

> When aliasing a clock with the qdev_alias_clock() function, a new link
> property is created on the device aliasing the clock. The link points
> to the aliased clock and use the OBJ_PROP_LINK_STRONG flag. This
> property is read only since it does not provide a check callback for
> modifications.
>
> The object_property_add_link() documentation stats that with
> OBJ_PROP_LINK_STRONG properties, the linked object reference count get
> decremented when the property is deleted. But it is _not_ incremented on
> creation (object_property_add_link() does not actually know the link).
>
> This commit increments the reference count on the aliased clock to
> ensure the aliased clock stays alive during the property lifetime, and
> to avoid a double-free memory error when the property gets deleted.
>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Signed-off-by: Luc Michel <luc@lmichel.fr>
> ---
>

In principle, that makes sense. But I don't see any users of that API yet.

It would have been nice to have some unit tests for qdev-clock.h..

 hw/core/qdev-clock.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
> index 6a9a340d0f..eb05f2a13c 100644
> --- a/hw/core/qdev-clock.c
> +++ b/hw/core/qdev-clock.c
> @@ -59,10 +59,18 @@ static NamedClockList *qdev_init_clocklist(DeviceState
> *dev, const char *name,
>      } else {
>          object_property_add_link(OBJECT(dev), name,
>                                   object_get_typename(OBJECT(clk)),
>                                   (Object **) &ncl->clock,
>                                   NULL, OBJ_PROP_LINK_STRONG);
> +        /*
> +         * Since the link property has the OBJ_PROP_LINK_STRONG flag, the
> clk
> +         * object reference count gets decremented on property deletion.
> +         * However object_property_add_link does not increment it since it
> +         * doesn't know the linked object. Increment it here to ensure the
> +         * aliased clock stays alive during this device life-time.
> +         */
> +        object_ref(OBJECT(clk));
>      }
>
>      ncl->clock = clk;
>
>      QLIST_INSERT_HEAD(&dev->clocks, ncl, node);
> --
> 2.28.0
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3271 bytes --]

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

* Re: [PATCH v2] hw/core/qdev-clock: add a reference on aliased clocks
  2020-10-23 11:23 ` Marc-André Lureau
@ 2020-10-23 12:01   ` Luc Michel
  0 siblings, 0 replies; 4+ messages in thread
From: Luc Michel @ 2020-10-23 12:01 UTC (permalink / raw)
  To: Marc-André Lureau, Peter Maydell
  Cc: Damien Hedde, Daniel P . Berrangé,
	Eduardo Habkost, QEMU, Markus Armbruster,
	Philippe Mathieu-Daudé,
	Paolo Bonzini

On 15:23 Fri 23 Oct     , Marc-André Lureau wrote:
> Hi
> 
> On Tue, Oct 20, 2020 at 1:11 PM Luc Michel <luc@lmichel.fr> wrote:
> 
> > When aliasing a clock with the qdev_alias_clock() function, a new link
> > property is created on the device aliasing the clock. The link points
> > to the aliased clock and use the OBJ_PROP_LINK_STRONG flag. This
> > property is read only since it does not provide a check callback for
> > modifications.
> >
> > The object_property_add_link() documentation stats that with
> > OBJ_PROP_LINK_STRONG properties, the linked object reference count get
> > decremented when the property is deleted. But it is _not_ incremented on
> > creation (object_property_add_link() does not actually know the link).
> >
> > This commit increments the reference count on the aliased clock to
> > ensure the aliased clock stays alive during the property lifetime, and
> > to avoid a double-free memory error when the property gets deleted.
> >
> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > Signed-off-by: Luc Michel <luc@lmichel.fr>
> > ---
> >
> 
> In principle, that makes sense. But I don't see any users of that API yet.
Yes, Peter encountered a double-free error because of this missing
object_ref when he applied my Raspberry PI CPRMAN series, which makes
use of qdev_alias_clock.

Peter: do you consider taking this patch to be able to pick up the
CPRMAN series again?

> 
> It would have been nice to have some unit tests for qdev-clock.h..
Yes I agree.

-- 
Luc

> 
>  hw/core/qdev-clock.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
> > index 6a9a340d0f..eb05f2a13c 100644
> > --- a/hw/core/qdev-clock.c
> > +++ b/hw/core/qdev-clock.c
> > @@ -59,10 +59,18 @@ static NamedClockList *qdev_init_clocklist(DeviceState
> > *dev, const char *name,
> >      } else {
> >          object_property_add_link(OBJECT(dev), name,
> >                                   object_get_typename(OBJECT(clk)),
> >                                   (Object **) &ncl->clock,
> >                                   NULL, OBJ_PROP_LINK_STRONG);
> > +        /*
> > +         * Since the link property has the OBJ_PROP_LINK_STRONG flag, the
> > clk
> > +         * object reference count gets decremented on property deletion.
> > +         * However object_property_add_link does not increment it since it
> > +         * doesn't know the linked object. Increment it here to ensure the
> > +         * aliased clock stays alive during this device life-time.
> > +         */
> > +        object_ref(OBJECT(clk));
> >      }
> >
> >      ncl->clock = clk;
> >
> >      QLIST_INSERT_HEAD(&dev->clocks, ncl, node);
> > --
> > 2.28.0
> >
> >
> >
> 
> -- 
> Marc-André Lureau

-- 


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

end of thread, other threads:[~2020-10-23 12:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-20  9:10 [PATCH v2] hw/core/qdev-clock: add a reference on aliased clocks Luc Michel
2020-10-20  9:17 ` no-reply
2020-10-23 11:23 ` Marc-André Lureau
2020-10-23 12:01   ` Luc Michel

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.