From: Mike Rapoport <rppt@linux.ibm.com>
To: Rob Herring <robh+dt@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Robin Murphy <robin.murphy@arm.com>,
Marc Gonzalez <marc.w.gonzalez@free.fr>,
Frank Rowand <frowand.list@gmail.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
Mark Rutland <mark.rutland@arm.com>,
Arnd Bergmann <arnd@arndb.de>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Oscar Salvador <osalvador@suse.de>,
Wei Yang <richard.weiyang@gmail.com>,
Michal Hocko <mhocko@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Sri Krishna chowdary <schowdary@nvidia.com>,
Qian Cai <cai@lca.pw>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: kmemleak panic
Date: Mon, 21 Jan 2019 19:42:35 +0200 [thread overview]
Message-ID: <20190121174234.GC26461@rapoport-lnx> (raw)
In-Reply-To: <CAL_JsqKQb34zVNTzo9DLNiDwmWGxkrKezSOjwCUPAvgzUoLYjg@mail.gmail.com>
On Mon, Jan 21, 2019 at 09:42:07AM -0600, Rob Herring wrote:
> +Mike Rapoport
>
> On Mon, Jan 21, 2019 at 8:37 AM Catalin Marinas <catalin.marinas@arm.com> wrote:
> >
> > On Mon, Jan 21, 2019 at 07:35:11AM -0600, Rob Herring wrote:
> > > On Mon, Jan 21, 2019 at 6:19 AM Robin Murphy <robin.murphy@arm.com> wrote:
> > > >
> > > > On 21/01/2019 11:57, Marc Gonzalez wrote:
> > > > [...]
> > > > > # echo dump=0xffffffc021e00000 > /sys/kernel/debug/kmemleak
> > > > > kmemleak: Object 0xffffffc021e00000 (size 2097152):
> > > > > kmemleak: comm "swapper/0", pid 0, jiffies 4294892296
> > > > > kmemleak: min_count = 0
> > > > > kmemleak: count = 0
> > > > > kmemleak: flags = 0x1
> > > > > kmemleak: checksum = 0
> > > > > kmemleak: backtrace:
> > > > > kmemleak_alloc_phys+0x48/0x60
> > > > > memblock_alloc_range_nid+0x8c/0xa4
> > > > > memblock_alloc_base_nid+0x4c/0x60
> > > > > __memblock_alloc_base+0x3c/0x4c
> > > > > early_init_dt_alloc_reserved_memory_arch+0x54/0xa4
> > > > > fdt_init_reserved_mem+0x308/0x3ec
> > > > > early_init_fdt_scan_reserved_mem+0x88/0xb0
> > > > > arm64_memblock_init+0x1dc/0x254
> > > > > setup_arch+0x1c8/0x4ec
> > > > > start_kernel+0x84/0x44c
> > > > > 0xffffffffffffffff
> > > >
> > > > OK, so via the __va(phys) call in kmemleak_alloc_phys(), you end up with
> > > > the linear map address of a no-map reservation, which unsurprisingly
> > > > turns out not to be mapped. Is there a way to tell kmemleak that it
> > > > can't scan within a particular object?
> > >
> > > There was this patch posted[1]. I never got a reply, so it hasn't been applied.
> > >
> > > https://patchwork.ozlabs.org/patch/995367/
> >
> > Thanks Rob, I wasn't aware of this patch (or I just missed it at the
> > time).
> >
> > I wonder whether kmemleak should simply remove ranges passed to
> > memblock_remove(), or at least mark them as no-scan.
I'm not sure that would be possible. Normal use of memblock_remove() is as
a counterpart of memblock_add() which does not involve kmemleak.
As memblock_remove() essentially hides range of the physical memory from
the system, it's not clear how it can communicate to kmemleak what region
should not be scanned.
> Seems reasonable to me, but of course that impacts a lot of other
> cases. Maybe Mike R has some thoughts?
If I understood correctly, the trouble comes from no-map range allocated in
early_init_dt_alloc_reserved_memory_arch().
There's indeed imbalance, because memblock_alloc() does kmemleak_alloc(), but
memblock_remove() does not do kmemleak_free().
I think the best way is to replace __memblock_alloc_base() with
memblock_find_in_range(), e.g something like:
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 1977ee0adcb1..6807a1cffe55 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -37,21 +37,16 @@ int __init __weak early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
*/
end = !end ? MEMBLOCK_ALLOC_ANYWHERE : end;
align = !align ? SMP_CACHE_BYTES : align;
- base = __memblock_alloc_base(size, align, end);
+ base = memblock_find_in_range(size, align, start, end);
if (!base)
return -ENOMEM;
- /*
- * Check if the allocated region fits in to start..end window
- */
- if (base < start) {
- memblock_free(base, size);
- return -ENOMEM;
- }
-
*res_base = base;
if (nomap)
return memblock_remove(base, size);
+ else
+ return memblock_reserve(base, size);
+
return 0;
}
> Rob
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2019-01-21 17:42 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <f6fbf528-8213-e3b8-6990-9fcf9dec04d6@free.fr>
[not found] ` <20190118143434.GE118707@arrakis.emea.arm.com>
2019-01-18 15:36 ` kmemleak panic Marc Gonzalez
2019-01-18 16:14 ` Qian Cai
2019-01-18 17:05 ` Marc Gonzalez
2019-01-18 17:38 ` Qian Cai
2019-01-19 10:21 ` Marc Gonzalez
2019-01-18 19:12 ` Robin Murphy
2019-01-19 13:28 ` Catalin Marinas
2019-01-21 11:57 ` Marc Gonzalez
2019-01-21 12:19 ` Robin Murphy
2019-01-21 13:35 ` Rob Herring
2019-01-21 13:54 ` Marc Gonzalez
2019-01-22 8:20 ` Prateek Patel
2019-01-21 14:37 ` Catalin Marinas
2019-01-21 15:42 ` Rob Herring
2019-01-21 15:53 ` Robin Murphy
2019-01-21 17:42 ` Mike Rapoport [this message]
2019-01-22 14:02 ` Marc Gonzalez
2019-01-22 14:12 ` Marc Gonzalez
2019-01-23 5:54 ` Mike Rapoport
2019-01-23 7:05 ` Prateek Patel
2019-01-23 7:28 ` Marek Szyprowski
2019-01-23 12:31 ` [PATCH v2] of: fix kmemleak crash (was: Re: kmemleak panic) Mike Rapoport
2019-02-01 16:23 ` [PATCH v2] of: fix kmemleak crash Marc Gonzalez
2019-02-04 10:10 ` Marc Gonzalez
2019-02-04 15:25 ` Greg Kroah-Hartman
2019-02-04 16:41 ` Rob Herring
2019-02-04 14:37 ` [RESEND PATCH v2] of: fix kmemleak crash caused by imbalance in early memory reservation Marc Gonzalez
2019-02-11 16:47 ` Marc Gonzalez
2019-02-12 16:03 ` Rob Herring
2019-02-12 21:50 ` Stephen Rothwell
2019-02-12 21:52 ` Andrew Morton
2019-02-12 22:12 ` Rob Herring
2019-02-13 6:57 ` Mike Rapoport
2019-02-13 9:27 ` Marc Gonzalez
2019-02-13 16:30 ` Mike Rapoport
2019-03-06 2:12 ` Guenter Roeck
2019-03-06 13:39 ` Rob Herring
2019-03-06 16:18 ` Guenter Roeck
2019-01-21 12:22 ` kmemleak panic Marc Gonzalez
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=20190121174234.GC26461@rapoport-lnx \
--to=rppt@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=ard.biesheuvel@linaro.org \
--cc=arnd@arndb.de \
--cc=bjorn.andersson@linaro.org \
--cc=cai@lca.pw \
--cc=catalin.marinas@arm.com \
--cc=frowand.list@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=marc.w.gonzalez@free.fr \
--cc=mark.rutland@arm.com \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
--cc=richard.weiyang@gmail.com \
--cc=robh+dt@kernel.org \
--cc=robin.murphy@arm.com \
--cc=schowdary@nvidia.com \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).