* [PATCH] mm: kmemleak: Ignore kmemleak scanning on CMA regions
@ 2021-11-26 2:47 Calvin Zhang
2021-11-28 0:07 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Calvin Zhang @ 2021-11-26 2:47 UTC (permalink / raw)
To: Christoph Hellwig, Marek Szyprowski, Robin Murphy, Rob Herring,
Frank Rowand, Catalin Marinas, Andrew Morton
Cc: devicetree, linux-kernel, linux-mm, iommu, Calvin Zhang
Just like this:
commit 620951e27457 ("mm/cma: make kmemleak ignore CMA regions").
Add kmemleak_ignore_phys() for CMA created from of reserved node.
Signed-off-by: Calvin Zhang <calvinzhang.cool@gmail.com>
---
kernel/dma/contiguous.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 3d63d91cba5c..66bd9a59615e 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -50,6 +50,7 @@
#include <linux/sizes.h>
#include <linux/dma-map-ops.h>
#include <linux/cma.h>
+#include <linux/kmemleak.h>
#ifdef CONFIG_CMA_SIZE_MBYTES
#define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES
@@ -426,6 +427,9 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
pr_err("Reserved memory: unable to setup CMA region\n");
return err;
}
+
+ kmemleak_ignore_phys(rmem->base);
+
/* Architecture specific contiguous memory fixup. */
dma_contiguous_early_fixup(rmem->base, rmem->size);
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: kmemleak: Ignore kmemleak scanning on CMA regions
2021-11-26 2:47 [PATCH] mm: kmemleak: Ignore kmemleak scanning on CMA regions Calvin Zhang
@ 2021-11-28 0:07 ` Andrew Morton
2021-11-28 1:50 ` Calvin Zhang
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2021-11-28 0:07 UTC (permalink / raw)
To: Calvin Zhang
Cc: Christoph Hellwig, Marek Szyprowski, Robin Murphy, Rob Herring,
Frank Rowand, Catalin Marinas, devicetree, linux-kernel,
linux-mm, iommu
On Fri, 26 Nov 2021 10:47:11 +0800 Calvin Zhang <calvinzhang.cool@gmail.com> wrote:
> Just like this:
> commit 620951e27457 ("mm/cma: make kmemleak ignore CMA regions").
>
> Add kmemleak_ignore_phys() for CMA created from of reserved node.
Could we please have a full, standalone changelog for this patch?
The 620951e27457 changelog says "Without this, the kernel crashes...".
Does your patch also fix a crash? If so under what circumstances and
should we backport this fix into -stable kernels?
Etcetera.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: kmemleak: Ignore kmemleak scanning on CMA regions
2021-11-28 0:07 ` Andrew Morton
@ 2021-11-28 1:50 ` Calvin Zhang
2021-12-02 18:11 ` Catalin Marinas
0 siblings, 1 reply; 5+ messages in thread
From: Calvin Zhang @ 2021-11-28 1:50 UTC (permalink / raw)
To: Andrew Morton
Cc: Christoph Hellwig, Marek Szyprowski, Robin Murphy, Rob Herring,
Frank Rowand, Catalin Marinas, devicetree, linux-kernel,
linux-mm, iommu
On Sat, Nov 27, 2021 at 04:07:18PM -0800, Andrew Morton wrote:
>On Fri, 26 Nov 2021 10:47:11 +0800 Calvin Zhang <calvinzhang.cool@gmail.com> wrote:
>
>> Just like this:
>> commit 620951e27457 ("mm/cma: make kmemleak ignore CMA regions").
>>
>> Add kmemleak_ignore_phys() for CMA created from of reserved node.
>
>Could we please have a full, standalone changelog for this patch?
Yes, I will add.
>
>The 620951e27457 changelog says "Without this, the kernel crashes...".
>Does your patch also fix a crash? If so under what circumstances and
>should we backport this fix into -stable kernels?
No crash occurred. 620951e27457 avoids crashes caused by accessing
highmem and it was fixed later. Now kmemleak_alloc_phys() and
kmemleak_ignore_phys() skip highmem. This patch is based on the
point that CMA regions don't contain pointers to other kmemleak
objects, and ignores CMA regions from reserved memory as what
620951e27457 did.
--
Thanks
Calvin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: kmemleak: Ignore kmemleak scanning on CMA regions
2021-11-28 1:50 ` Calvin Zhang
@ 2021-12-02 18:11 ` Catalin Marinas
2021-12-03 0:52 ` Calvin Zhang
0 siblings, 1 reply; 5+ messages in thread
From: Catalin Marinas @ 2021-12-02 18:11 UTC (permalink / raw)
To: Calvin Zhang
Cc: Andrew Morton, Christoph Hellwig, Marek Szyprowski, Robin Murphy,
Rob Herring, Frank Rowand, devicetree, linux-kernel, linux-mm,
iommu
On Sun, Nov 28, 2021 at 09:50:53AM +0800, Calvin Zhang wrote:
> On Sat, Nov 27, 2021 at 04:07:18PM -0800, Andrew Morton wrote:
> >On Fri, 26 Nov 2021 10:47:11 +0800 Calvin Zhang <calvinzhang.cool@gmail.com> wrote:
> >> Just like this:
> >> commit 620951e27457 ("mm/cma: make kmemleak ignore CMA regions").
> >>
> >> Add kmemleak_ignore_phys() for CMA created from of reserved node.
[...]
> >The 620951e27457 changelog says "Without this, the kernel crashes...".
> >Does your patch also fix a crash? If so under what circumstances and
> >should we backport this fix into -stable kernels?
>
> No crash occurred. 620951e27457 avoids crashes caused by accessing
> highmem and it was fixed later. Now kmemleak_alloc_phys() and
> kmemleak_ignore_phys() skip highmem. This patch is based on the
> point that CMA regions don't contain pointers to other kmemleak
> objects, and ignores CMA regions from reserved memory as what
> 620951e27457 did.
Note that kmemleak_ignore() only works if there was a prior
kmemleak_alloc() on that address range. With the previous commit we get
this via the memblock_alloc_range() but I fail to see one on the
rmem_cma_setup() path.
--
Catalin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: kmemleak: Ignore kmemleak scanning on CMA regions
2021-12-02 18:11 ` Catalin Marinas
@ 2021-12-03 0:52 ` Calvin Zhang
0 siblings, 0 replies; 5+ messages in thread
From: Calvin Zhang @ 2021-12-03 0:52 UTC (permalink / raw)
To: Catalin Marinas
Cc: Andrew Morton, Christoph Hellwig, Marek Szyprowski, Robin Murphy,
Rob Herring, Frank Rowand, devicetree, linux-kernel, linux-mm,
iommu
On Thu, Dec 02, 2021 at 06:11:12PM +0000, Catalin Marinas wrote:
>On Sun, Nov 28, 2021 at 09:50:53AM +0800, Calvin Zhang wrote:
>> On Sat, Nov 27, 2021 at 04:07:18PM -0800, Andrew Morton wrote:
>> >On Fri, 26 Nov 2021 10:47:11 +0800 Calvin Zhang <calvinzhang.cool@gmail.com> wrote:
>> >> Just like this:
>> >> commit 620951e27457 ("mm/cma: make kmemleak ignore CMA regions").
>> >>
>> >> Add kmemleak_ignore_phys() for CMA created from of reserved node.
>[...]
>> >The 620951e27457 changelog says "Without this, the kernel crashes...".
>> >Does your patch also fix a crash? If so under what circumstances and
>> >should we backport this fix into -stable kernels?
>>
>> No crash occurred. 620951e27457 avoids crashes caused by accessing
>> highmem and it was fixed later. Now kmemleak_alloc_phys() and
>> kmemleak_ignore_phys() skip highmem. This patch is based on the
>> point that CMA regions don't contain pointers to other kmemleak
>> objects, and ignores CMA regions from reserved memory as what
>> 620951e27457 did.
>
>Note that kmemleak_ignore() only works if there was a prior
>kmemleak_alloc() on that address range. With the previous commit we get
>this via the memblock_alloc_range() but I fail to see one on the
>rmem_cma_setup() path.
rmem is from memblock_reserve() or early_init_dt_alloc_reserved_memory_arch()
kmemleak_alloc() is not called in the first case. And It's bad to add one.
I think all the reserved regions should be allocated from memblock without
kmemleak_alloc() and let rmem handler choose to add it as kmemleak object
by kmemleak_alloc(). Because MEMBLOCK_ALLOC_NOLEAKTRACE conflicts with range
parameter in memlbock_alloc_* series, all reserved regions and default CMA
region are allocated with kmemleak_alloc().
I think it's better to add memblock_alloc_* series a spearate flag paramter
(like "NOLEAKTRACE") instead of encoding MEMBLOCK_ALLOC_NOLEAKTRACE in `end`
parameter.
--
Calvin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-12-03 0:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 2:47 [PATCH] mm: kmemleak: Ignore kmemleak scanning on CMA regions Calvin Zhang
2021-11-28 0:07 ` Andrew Morton
2021-11-28 1:50 ` Calvin Zhang
2021-12-02 18:11 ` Catalin Marinas
2021-12-03 0:52 ` Calvin Zhang
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).