All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] powerpc: msi: mark bitmap with kmemleak_not_leak()
@ 2015-09-16 19:26 Denis Kirjanov
  2015-09-17  9:25 ` Catalin Marinas
  2015-10-12 11:21 ` [v3] " Michael Ellerman
  0 siblings, 2 replies; 4+ messages in thread
From: Denis Kirjanov @ 2015-09-16 19:26 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Michael Ellerman, Catalin Marinas, Denis Kirjanov

During the MSI bitmap test on boot kmemleak spews the following trace:

unreferenced object 0xc00000016e86c900 (size 64):
    comm "swapper/0", pid 1, jiffies 4294893173 (age 518.024s)
    hex dump (first 32 bytes):
	00 00 01 ff 7f ff 7f 37 00 00 00 00 00 00 00 00
	.......7........
	ff ff ff ff ff ff ff ff 01 ff ff ff ff
	ff ff ff
	................
	backtrace:
	[<c00000000003eebc>] .zalloc_maybe_bootmem+0x3c/0x380
	[<c000000000042d6c>] .msi_bitmap_alloc+0x3c/0xb0
	[<c000000000a9aff8>] .msi_bitmap_selftest+0x30/0x2b4
	[<c0000000000090f4>] .do_one_initcall+0xd4/0x270
	[<c000000000a8e250>] .kernel_init_freeable+0x1a0/0x280
	[<c000000000009b5c>] .kernel_init+0x1c/0x120
	[<c000000000007fbc>] .ret_from_kernel_thread+0x58/0x9c

Added a flag to msi_bitmap for tracking allocations
from slab and memblock so we can properly free/handle
memory in msi_bitmap_free().

Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>

Changes vor v2:
 - added a flag to msi_bitmap
 - kmemleak annotaion moved under CONFIG_MSI_BITMAP_SELFTEST

Changes vor v3:
 - correctly initialize bitmap_from_slab
 - put kmemleak_not_leak annotation right after the allocation
---
 arch/powerpc/include/asm/msi_bitmap.h |  1 +
 arch/powerpc/sysdev/msi_bitmap.c      | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/msi_bitmap.h b/arch/powerpc/include/asm/msi_bitmap.h
index 97ac3f4..47a8ebc 100644
--- a/arch/powerpc/include/asm/msi_bitmap.h
+++ b/arch/powerpc/include/asm/msi_bitmap.h
@@ -19,6 +19,7 @@ struct msi_bitmap {
 	unsigned long		*bitmap;
 	spinlock_t		lock;
 	unsigned int		irq_count;
+	bool		 	    bitmap_from_slab;
 };
 
 int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num);
diff --git a/arch/powerpc/sysdev/msi_bitmap.c b/arch/powerpc/sysdev/msi_bitmap.c
index 73b64c7..6f2f3d6 100644
--- a/arch/powerpc/sysdev/msi_bitmap.c
+++ b/arch/powerpc/sysdev/msi_bitmap.c
@@ -11,6 +11,7 @@
 #include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/bitmap.h>
+#include <linux/bootmem.h>
 #include <asm/msi_bitmap.h>
 #include <asm/setup.h>
 
@@ -122,7 +123,16 @@ int msi_bitmap_alloc(struct msi_bitmap *bmp, unsigned int irq_count,
 	size = BITS_TO_LONGS(irq_count) * sizeof(long);
 	pr_debug("msi_bitmap: allocator bitmap size is 0x%x bytes\n", size);
 
-	bmp->bitmap = zalloc_maybe_bootmem(size, GFP_KERNEL);
+	if (slab_is_available()) {
+		bmp->bitmap = kzalloc(size, GFP_KERNEL);
+		bmp->bitmap_from_slab = true;
+	} else {
+		bmp->bitmap = memblock_virt_alloc(size, 0);
+		bmp->bitmap_from_slab = false;
+		/* the bitmap won't be freed from memblock allocator */
+		kmemleak_not_leak(bmp->bitmap);
+	}
+
 	if (!bmp->bitmap) {
 		pr_debug("msi_bitmap: ENOMEM allocating allocator bitmap!\n");
 		return -ENOMEM;
@@ -138,7 +148,8 @@ int msi_bitmap_alloc(struct msi_bitmap *bmp, unsigned int irq_count,
 
 void msi_bitmap_free(struct msi_bitmap *bmp)
 {
-	/* we can't free the bitmap we don't know if it's bootmem etc. */
+	if (bmp->bitmap_from_slab)
+		kfree(bmp->bitmap);
 	of_node_put(bmp->of_node);
 	bmp->bitmap = NULL;
 }
@@ -203,8 +214,6 @@ static void __init test_basics(void)
 
 	/* Clients may WARN_ON bitmap == NULL for "not-allocated" */
 	WARN_ON(bmp.bitmap != NULL);
-
-	kfree(bmp.bitmap);
 }
 
 static void __init test_of_node(void)
-- 
2.4.0

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

* Re: [PATCH v3] powerpc: msi: mark bitmap with kmemleak_not_leak()
  2015-09-16 19:26 [PATCH v3] powerpc: msi: mark bitmap with kmemleak_not_leak() Denis Kirjanov
@ 2015-09-17  9:25 ` Catalin Marinas
  2015-10-02  8:50   ` Denis Kirjanov
  2015-10-12 11:21 ` [v3] " Michael Ellerman
  1 sibling, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2015-09-17  9:25 UTC (permalink / raw)
  To: Denis Kirjanov; +Cc: linuxppc-dev, Michael Ellerman

On Wed, Sep 16, 2015 at 10:26:14PM +0300, Denis Kirjanov wrote:
> During the MSI bitmap test on boot kmemleak spews the following trace:
>=20
> unreferenced object 0xc00000016e86c900 (size 64):
>     comm "swapper/0", pid 1, jiffies 4294893173 (age 518.024s)
>     hex dump (first 32 bytes):
> =0900 00 01 ff 7f ff 7f 37 00 00 00 00 00 00 00 00
> =09.......7........
> =09ff ff ff ff ff ff ff ff 01 ff ff ff ff
> =09ff ff ff
> =09................
> =09backtrace:
> =09[<c00000000003eebc>] .zalloc_maybe_bootmem+0x3c/0x380
> =09[<c000000000042d6c>] .msi_bitmap_alloc+0x3c/0xb0
> =09[<c000000000a9aff8>] .msi_bitmap_selftest+0x30/0x2b4
> =09[<c0000000000090f4>] .do_one_initcall+0xd4/0x270
> =09[<c000000000a8e250>] .kernel_init_freeable+0x1a0/0x280
> =09[<c000000000009b5c>] .kernel_init+0x1c/0x120
> =09[<c000000000007fbc>] .ret_from_kernel_thread+0x58/0x9c
>=20
> Added a flag to msi_bitmap for tracking allocations
> from slab and memblock so we can properly free/handle
> memory in msi_bitmap_free().
>=20
> Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

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

* Re: [PATCH v3] powerpc: msi: mark bitmap with kmemleak_not_leak()
  2015-09-17  9:25 ` Catalin Marinas
@ 2015-10-02  8:50   ` Denis Kirjanov
  0 siblings, 0 replies; 4+ messages in thread
From: Denis Kirjanov @ 2015-10-02  8:50 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev, Catalin Marinas

On 9/17/15, Catalin Marinas <catalin.marinas@arm.com> wrote:
> On Wed, Sep 16, 2015 at 10:26:14PM +0300, Denis Kirjanov wrote:
>> During the MSI bitmap test on boot kmemleak spews the following trace:
>>
>> unreferenced object 0xc00000016e86c900 (size 64):
>>     comm "swapper/0", pid 1, jiffies 4294893173 (age 518.024s)
>>     hex dump (first 32 bytes):
>> 	00 00 01 ff 7f ff 7f 37 00 00 00 00 00 00 00 00
>> 	.......7........
>> 	ff ff ff ff ff ff ff ff 01 ff ff ff ff
>> 	ff ff ff
>> 	................
>> 	backtrace:
>> 	[<c00000000003eebc>] .zalloc_maybe_bootmem+0x3c/0x380
>> 	[<c000000000042d6c>] .msi_bitmap_alloc+0x3c/0xb0
>> 	[<c000000000a9aff8>] .msi_bitmap_selftest+0x30/0x2b4
>> 	[<c0000000000090f4>] .do_one_initcall+0xd4/0x270
>> 	[<c000000000a8e250>] .kernel_init_freeable+0x1a0/0x280
>> 	[<c000000000009b5c>] .kernel_init+0x1c/0x120
>> 	[<c000000000007fbc>] .ret_from_kernel_thread+0x58/0x9c
>>
>> Added a flag to msi_bitmap for tracking allocations
>> from slab and memblock so we can properly free/handle
>> memory in msi_bitmap_free().
>>
>> Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>
>
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
>
Hi Michael,
could you please apply the patch to fixes branch as well?

Thanks!

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

* Re: [v3] powerpc: msi: mark bitmap with kmemleak_not_leak()
  2015-09-16 19:26 [PATCH v3] powerpc: msi: mark bitmap with kmemleak_not_leak() Denis Kirjanov
  2015-09-17  9:25 ` Catalin Marinas
@ 2015-10-12 11:21 ` Michael Ellerman
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2015-10-12 11:21 UTC (permalink / raw)
  To: Denis Kirjanov, linuxppc-dev; +Cc: Denis Kirjanov, Catalin Marinas

On Wed, 2015-16-09 at 19:26:14 UTC, Denis Kirjanov wrote:
> During the MSI bitmap test on boot kmemleak spews the following trace:
> 
> unreferenced object 0xc00000016e86c900 (size 64):
>     comm "swapper/0", pid 1, jiffies 4294893173 (age 518.024s)
>     hex dump (first 32 bytes):
> 	00 00 01 ff 7f ff 7f 37 00 00 00 00 00 00 00 00
> 	.......7........
> 	ff ff ff ff ff ff ff ff 01 ff ff ff ff
> 	ff ff ff
> 	................
> 	backtrace:
> 	[<c00000000003eebc>] .zalloc_maybe_bootmem+0x3c/0x380
> 	[<c000000000042d6c>] .msi_bitmap_alloc+0x3c/0xb0
> 	[<c000000000a9aff8>] .msi_bitmap_selftest+0x30/0x2b4
> 	[<c0000000000090f4>] .do_one_initcall+0xd4/0x270
> 	[<c000000000a8e250>] .kernel_init_freeable+0x1a0/0x280
> 	[<c000000000009b5c>] .kernel_init+0x1c/0x120
> 	[<c000000000007fbc>] .ret_from_kernel_thread+0x58/0x9c
> 
> Added a flag to msi_bitmap for tracking allocations
> from slab and memblock so we can properly free/handle
> memory in msi_bitmap_free().
> 
> Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/cb2d3883c6033831e2a93b39

cheers

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

end of thread, other threads:[~2015-10-12 11:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-16 19:26 [PATCH v3] powerpc: msi: mark bitmap with kmemleak_not_leak() Denis Kirjanov
2015-09-17  9:25 ` Catalin Marinas
2015-10-02  8:50   ` Denis Kirjanov
2015-10-12 11:21 ` [v3] " Michael Ellerman

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.