LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Mathieu Malaterre <malat@debian.org>
Cc: linuxppc-dev <linuxppc-dev@lists.ozlabs.org>
Subject: Re: kmemleak: 1157 new suspected memory leaks (see /sys/kernel/debug/kmemleak)
Date: Wed, 29 May 2019 18:04:23 +0100	[thread overview]
Message-ID: <20190529170423.3a56t7vtioznzbnx@mbp> (raw)
In-Reply-To: <CA+7wUszCdg_xRRh_DX=wAoWnpZTyc7dG=RsiEUCYJN=p_yBX6A@mail.gmail.com>

On Tue, May 28, 2019 at 09:14:12PM +0200, Mathieu Malaterre wrote:
> On Tue, May 28, 2019 at 7:21 AM Michael Ellerman <mpe@ellerman.id.au> wrote:
> > Mathieu Malaterre <malat@debian.org> writes:
> > > Is there a way to dump more context (somewhere in of tree
> > > flattening?). I cannot make sense of the following:
> >
> > Hmm. Not that I know of.
> >
> > Those don't look related to OF flattening/unflattening. That's just
> > sysfs setup based on the unflattened device tree.
> >
> > The allocations are happening in safe_name() AFAICS.
> >
> > int __of_add_property_sysfs(struct device_node *np, struct property *pp)
> > {
> >         ...
> >         pp->attr.attr.name = safe_name(&np->kobj, pp->name);
> >
> > And the free is in __of_sysfs_remove_bin_file():
> >
> > void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop)
> > {
> >         if (!IS_ENABLED(CONFIG_SYSFS))
> >                 return;
> >
> >         sysfs_remove_bin_file(&np->kobj, &prop->attr);
> >         kfree(prop->attr.attr.name);
> >
> 
> Right. That helped a lot !
> 
> > There is this check which could be failing leading to us not calling the
> > free at all:
> >
> > void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
> > {
> >         /* at early boot, bail here and defer setup to of_init() */
> >         if (of_kset && of_node_is_attached(np))
> >                 __of_sysfs_remove_bin_file(np, prop);
> > }
> >
> >
> > So maybe stick a printk() in there to see if you're hitting that
> > condition, eg something like:
> >
> >         if (of_kset && of_node_is_attached(np))
> >                 __of_sysfs_remove_bin_file(np, prop);
> >         else
> >                 printk("%s: leaking prop %s on node %pOF\n", __func__, prop->attr.attr.name, np);
> >
> 
> If I understand correctly those are false positive. I was first
> starting to consider using something like kmemleak_not_leak, but I
> remember that I have been using kmemleak for a couple of years now.
> Those reports starting to show up only recently.
> 
> Catalin, do you have an idea why on a non-SMP machine kmemleak reports
> leaks from:
> 
> [...]
> void __init of_core_init(void)
> {
> [...]
>  for_each_of_allnodes(np)
>     __of_attach_node_sysfs(np);

It's likely that they are false positives but usually, rather than just
adding a kmemleak_not_leak(), it's better to figure out why kmemleak
reports them. The strings allocated above through kstrdup() can't be
tracked starting with the root objects. I think for the of stuff, this
should be the of_root pointer.

Is it only with non-SMP that this happens? I can't reproduce it on arm64
to be able to dig further.

Even better if you could bisect to the commit that's causing this.

-- 
Catalin

      reply	other threads:[~2019-05-29 17:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23  8:38 kmemleak: 1157 new suspected memory leaks (see /sys/kernel/debug/kmemleak) Mathieu Malaterre
2019-05-28  5:21 ` Michael Ellerman
2019-05-28 19:14   ` Mathieu Malaterre
2019-05-29 17:04     ` Catalin Marinas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190529170423.3a56t7vtioznzbnx@mbp \
    --to=catalin.marinas@arm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=malat@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox