2019-05-06 14:45:54

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 4.19 62/99] kmemleak: powerpc: skip scanning holes in the .bss section

[ Upstream commit 298a32b132087550d3fa80641ca58323c5dfd4d9 ]

Commit 2d4f567103ff ("KVM: PPC: Introduce kvm_tmp framework") adds
kvm_tmp[] into the .bss section and then free the rest of unused spaces
back to the page allocator.

kernel_init
kvm_guest_init
kvm_free_tmp
free_reserved_area
free_unref_page
free_unref_page_prepare

With DEBUG_PAGEALLOC=y, it will unmap those pages from kernel. As the
result, kmemleak scan will trigger a panic when it scans the .bss
section with unmapped pages.

This patch creates dedicated kmemleak objects for the .data, .bss and
potentially .data..ro_after_init sections to allow partial freeing via
the kmemleak_free_part() in the powerpc kvm_free_tmp() function.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Catalin Marinas <[email protected]>
Reported-by: Qian Cai <[email protected]>
Acked-by: Michael Ellerman <[email protected]> (powerpc)
Tested-by: Qian Cai <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Avi Kivity <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Radim Krcmar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
---
arch/powerpc/kernel/kvm.c | 7 +++++++
mm/kmemleak.c | 16 +++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 683b5b3805bd..cd381e2291df 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -22,6 +22,7 @@
#include <linux/kvm_host.h>
#include <linux/init.h>
#include <linux/export.h>
+#include <linux/kmemleak.h>
#include <linux/kvm_para.h>
#include <linux/slab.h>
#include <linux/of.h>
@@ -712,6 +713,12 @@ static void kvm_use_magic_page(void)

static __init void kvm_free_tmp(void)
{
+ /*
+ * Inform kmemleak about the hole in the .bss section since the
+ * corresponding pages will be unmapped with DEBUG_PAGEALLOC=y.
+ */
+ kmemleak_free_part(&kvm_tmp[kvm_tmp_index],
+ ARRAY_SIZE(kvm_tmp) - kvm_tmp_index);
free_reserved_area(&kvm_tmp[kvm_tmp_index],
&kvm_tmp[ARRAY_SIZE(kvm_tmp)], -1, NULL);
}
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 17dd883198ae..5912a26e041c 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1501,11 +1501,6 @@ static void kmemleak_scan(void)
}
rcu_read_unlock();

- /* data/bss scanning */
- scan_large_block(_sdata, _edata);
- scan_large_block(__bss_start, __bss_stop);
- scan_large_block(__start_ro_after_init, __end_ro_after_init);
-
#ifdef CONFIG_SMP
/* per-cpu sections scanning */
for_each_possible_cpu(i)
@@ -2036,6 +2031,17 @@ void __init kmemleak_init(void)
}
local_irq_restore(flags);

+ /* register the data/bss sections */
+ create_object((unsigned long)_sdata, _edata - _sdata,
+ KMEMLEAK_GREY, GFP_ATOMIC);
+ create_object((unsigned long)__bss_start, __bss_stop - __bss_start,
+ KMEMLEAK_GREY, GFP_ATOMIC);
+ /* only register .data..ro_after_init if not within .data */
+ if (__start_ro_after_init < _sdata || __end_ro_after_init > _edata)
+ create_object((unsigned long)__start_ro_after_init,
+ __end_ro_after_init - __start_ro_after_init,
+ KMEMLEAK_GREY, GFP_ATOMIC);
+
/*
* This is the point where tracking allocations is safe. Automatic
* scanning is started during the late initcall. Add the early logged
--
2.20.1




2019-05-07 08:01:06

by Nobuhiro Iwamatsu

[permalink] [raw]
Subject: Re: [PATCH 4.19 62/99] kmemleak: powerpc: skip scanning holes in the .bss section

Hi,

On Mon, May 06, 2019 at 04:32:35PM +0200, Greg Kroah-Hartman wrote:
> [ Upstream commit 298a32b132087550d3fa80641ca58323c5dfd4d9 ]
>
> Commit 2d4f567103ff ("KVM: PPC: Introduce kvm_tmp framework") adds
> kvm_tmp[] into the .bss section and then free the rest of unused spaces
> back to the page allocator.
>
> kernel_init
> kvm_guest_init
> kvm_free_tmp
> free_reserved_area
> free_unref_page
> free_unref_page_prepare
>
> With DEBUG_PAGEALLOC=y, it will unmap those pages from kernel. As the
> result, kmemleak scan will trigger a panic when it scans the .bss
> section with unmapped pages.
>
> This patch creates dedicated kmemleak objects for the .data, .bss and
> potentially .data..ro_after_init sections to allow partial freeing via
> the kmemleak_free_part() in the powerpc kvm_free_tmp() function.
>
> Link: http://lkml.kernel.org/r/[email protected]
> Signed-off-by: Catalin Marinas <[email protected]>
> Reported-by: Qian Cai <[email protected]>
> Acked-by: Michael Ellerman <[email protected]> (powerpc)
> Tested-by: Qian Cai <[email protected]>
> Cc: Paul Mackerras <[email protected]>
> Cc: Benjamin Herrenschmidt <[email protected]>
> Cc: Avi Kivity <[email protected]>
> Cc: Paolo Bonzini <[email protected]>
> Cc: Radim Krcmar <[email protected]>
> Signed-off-by: Andrew Morton <[email protected]>
> Signed-off-by: Linus Torvalds <[email protected]>
> Signed-off-by: Sasha Levin <[email protected]>
> ---
> arch/powerpc/kernel/kvm.c | 7 +++++++
> mm/kmemleak.c | 16 +++++++++++-----
> 2 files changed, 18 insertions(+), 5 deletions(-)

This commit has other problems, so we also need the following commits:

commit dce5b0bdeec61bdbee56121ceb1d014151d5cab1
Author: Arnd Bergmann <[email protected]>
Date: Thu Apr 18 17:50:48 2019 -0700

mm/kmemleak.c: fix unused-function warning

The only references outside of the #ifdef have been removed, so now we
get a warning in non-SMP configurations:

mm/kmemleak.c:1404:13: error: unused function 'scan_large_block' [-Werror,-Wunused-function]

Add a new #ifdef around it.

Link: http://lkml.kernel.org/r/[email protected]
Fixes: 298a32b13208 ("kmemleak: powerpc: skip scanning holes in the .bss section")
Signed-off-by: Arnd Bergmann <[email protected]>
Acked-by: Catalin Marinas <[email protected]>
Cc: Vincent Whitchurch <[email protected]>
Cc: Michael Ellerman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>

Please apply this commit.

Best regards,
Nobuhiro

2019-05-07 12:52:39

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 4.19 62/99] kmemleak: powerpc: skip scanning holes in the .bss section

On Tue, May 07, 2019 at 04:58:09PM +0900, Nobuhiro Iwamatsu wrote:
> Hi,
>
> On Mon, May 06, 2019 at 04:32:35PM +0200, Greg Kroah-Hartman wrote:
> > [ Upstream commit 298a32b132087550d3fa80641ca58323c5dfd4d9 ]
> >
> > Commit 2d4f567103ff ("KVM: PPC: Introduce kvm_tmp framework") adds
> > kvm_tmp[] into the .bss section and then free the rest of unused spaces
> > back to the page allocator.
> >
> > kernel_init
> > kvm_guest_init
> > kvm_free_tmp
> > free_reserved_area
> > free_unref_page
> > free_unref_page_prepare
> >
> > With DEBUG_PAGEALLOC=y, it will unmap those pages from kernel. As the
> > result, kmemleak scan will trigger a panic when it scans the .bss
> > section with unmapped pages.
> >
> > This patch creates dedicated kmemleak objects for the .data, .bss and
> > potentially .data..ro_after_init sections to allow partial freeing via
> > the kmemleak_free_part() in the powerpc kvm_free_tmp() function.
> >
> > Link: http://lkml.kernel.org/r/[email protected]
> > Signed-off-by: Catalin Marinas <[email protected]>
> > Reported-by: Qian Cai <[email protected]>
> > Acked-by: Michael Ellerman <[email protected]> (powerpc)
> > Tested-by: Qian Cai <[email protected]>
> > Cc: Paul Mackerras <[email protected]>
> > Cc: Benjamin Herrenschmidt <[email protected]>
> > Cc: Avi Kivity <[email protected]>
> > Cc: Paolo Bonzini <[email protected]>
> > Cc: Radim Krcmar <[email protected]>
> > Signed-off-by: Andrew Morton <[email protected]>
> > Signed-off-by: Linus Torvalds <[email protected]>
> > Signed-off-by: Sasha Levin <[email protected]>
> > ---
> > arch/powerpc/kernel/kvm.c | 7 +++++++
> > mm/kmemleak.c | 16 +++++++++++-----
> > 2 files changed, 18 insertions(+), 5 deletions(-)
>
> This commit has other problems, so we also need the following commits:
>
> commit dce5b0bdeec61bdbee56121ceb1d014151d5cab1
> Author: Arnd Bergmann <[email protected]>
> Date: Thu Apr 18 17:50:48 2019 -0700
>
> mm/kmemleak.c: fix unused-function warning
>
> The only references outside of the #ifdef have been removed, so now we
> get a warning in non-SMP configurations:
>
> mm/kmemleak.c:1404:13: error: unused function 'scan_large_block' [-Werror,-Wunused-function]
>
> Add a new #ifdef around it.
>
> Link: http://lkml.kernel.org/r/[email protected]
> Fixes: 298a32b13208 ("kmemleak: powerpc: skip scanning holes in the .bss section")
> Signed-off-by: Arnd Bergmann <[email protected]>
> Acked-by: Catalin Marinas <[email protected]>
> Cc: Vincent Whitchurch <[email protected]>
> Cc: Michael Ellerman <[email protected]>
> Signed-off-by: Andrew Morton <[email protected]>
> Signed-off-by: Linus Torvalds <[email protected]>
>
> Please apply this commit.

Now queued up, thanks!

greg k-h