All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] slab: make GFP_SLAB_BUG_MASK information more human readable
@ 2016-06-10  8:43 ` Michal Hocko
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2016-06-10  8:43 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Cristopher Lameter, David Rientjes, Joonsoo Kim, Pekka Enberg,
	linux-mm, LKML, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

printk offers %pGg for quite some time so let's use it to get a human
readable list of invalid flags.

The original output would be
[  429.191962] gfp: 2

after the change
[  429.191962] Unexpected gfp: 0x2 (__GFP_HIGHMEM)

Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/slab.c | 3 ++-
 mm/slub.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 763096a247f6..03fb724d6e48 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2686,7 +2686,8 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep,
 	 * critical path in kmem_cache_alloc().
 	 */
 	if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
-		pr_emerg("gfp: %u\n", flags & GFP_SLAB_BUG_MASK);
+		gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
+		pr_emerg("Unexpected gfp: %#x (%pGg)\n", invalid_mask, &invalid_mask);
 		BUG();
 	}
 	local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK);
diff --git a/mm/slub.c b/mm/slub.c
index cbf4e0e07d41..dd5a9eee7df5 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1628,7 +1628,8 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
 {
 	if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
-		pr_emerg("gfp: %u\n", flags & GFP_SLAB_BUG_MASK);
+		gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
+		pr_emerg("Unexpected gfp: %#x (%pGg)\n", invalid_mask, &invalid_mask);
 		BUG();
 	}
 
-- 
2.8.1

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

* [PATCH 1/2] slab: make GFP_SLAB_BUG_MASK information more human readable
@ 2016-06-10  8:43 ` Michal Hocko
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2016-06-10  8:43 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Cristopher Lameter, David Rientjes, Joonsoo Kim, Pekka Enberg,
	linux-mm, LKML, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

printk offers %pGg for quite some time so let's use it to get a human
readable list of invalid flags.

The original output would be
[  429.191962] gfp: 2

after the change
[  429.191962] Unexpected gfp: 0x2 (__GFP_HIGHMEM)

Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/slab.c | 3 ++-
 mm/slub.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 763096a247f6..03fb724d6e48 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2686,7 +2686,8 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep,
 	 * critical path in kmem_cache_alloc().
 	 */
 	if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
-		pr_emerg("gfp: %u\n", flags & GFP_SLAB_BUG_MASK);
+		gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
+		pr_emerg("Unexpected gfp: %#x (%pGg)\n", invalid_mask, &invalid_mask);
 		BUG();
 	}
 	local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK);
diff --git a/mm/slub.c b/mm/slub.c
index cbf4e0e07d41..dd5a9eee7df5 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1628,7 +1628,8 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
 {
 	if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
-		pr_emerg("gfp: %u\n", flags & GFP_SLAB_BUG_MASK);
+		gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
+		pr_emerg("Unexpected gfp: %#x (%pGg)\n", invalid_mask, &invalid_mask);
 		BUG();
 	}
 
-- 
2.8.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [PATCH 2/2] slab: do not panic on invalid gfp_mask
  2016-06-10  8:43 ` Michal Hocko
@ 2016-06-10  8:43   ` Michal Hocko
  -1 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2016-06-10  8:43 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Cristopher Lameter, David Rientjes, Joonsoo Kim, Pekka Enberg,
	linux-mm, LKML, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

both SLAB and SLUB BUG() when a caller provides an invalid gfp_mask.
This is a rather harsh way to announce a non-critical issue. Allocator
is free to ignore invalid flags. Let's simply replace BUG() by
dump_stack to tell the offender and fixup the mask to move on with the
allocation request.

This is an example for kmalloc(GFP_KERNEL|__GFP_HIGHMEM) from a test
module.
[   31.914753] Unexpected gfp: 0x2 (__GFP_HIGHMEM). Fixing up to gfp: 0x24000c0 (GFP_KERNEL). Fix your code!
[   31.914754] CPU: 0 PID: 2916 Comm: insmod Tainted: G           O    4.6.0-slabgfp2-00002-g4cdfc2ef4892-dirty #936
[   31.914755] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Debian-1.8.2-1 04/01/2014
[   31.914756]  0000000000000000 ffff88000d777c00 ffffffff8130e2fb ffff88000ec006c0
[   31.914758]  000000000000000c ffff88000d777c58 ffffffff811791dd 0000000000000246
[   31.914759]  0000000000000246 0000000000000046 00000002024000c0 ffff88000fa1d888
[   31.914759] Call Trace:
[   31.914760]  [<ffffffff8130e2fb>] dump_stack+0x67/0x90
[   31.914762]  [<ffffffff811791dd>] cache_alloc_refill+0x201/0x617
[   31.914763]  [<ffffffff81179b3f>] kmem_cache_alloc_trace+0xa7/0x24a
[   31.914764]  [<ffffffffa0005000>] ? 0xffffffffa0005000
[   31.914765]  [<ffffffffa0005020>] mymodule_init+0x20/0x1000 [test_slab]
[   31.914767]  [<ffffffff81000402>] do_one_initcall+0xe7/0x16c
[   31.914768]  [<ffffffff810b02de>] ? rcu_read_lock_sched_held+0x61/0x69
[   31.914769]  [<ffffffff81179c2f>] ? kmem_cache_alloc_trace+0x197/0x24a
[   31.914771]  [<ffffffff81125edc>] do_init_module+0x5f/0x1d9
[   31.914772]  [<ffffffff810d2c66>] load_module+0x1a3d/0x1f21
[   31.914774]  [<ffffffff81622931>] ? retint_kernel+0x2d/0x2d
[   31.914775]  [<ffffffff810d3232>] SyS_init_module+0xe8/0x10e
[   31.914776]  [<ffffffff810d3232>] ? SyS_init_module+0xe8/0x10e
[   31.914778]  [<ffffffff81001d08>] do_syscall_64+0x68/0x13f
[   31.914779]  [<ffffffff8162201a>] entry_SYSCALL64_slow_path+0x25/0x25

Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/slab.c | 6 ++++--
 mm/slub.c | 5 +++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 03fb724d6e48..fc9496bdd038 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2687,8 +2687,10 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep,
 	 */
 	if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
 		gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
-		pr_emerg("Unexpected gfp: %#x (%pGg)\n", invalid_mask, &invalid_mask);
-		BUG();
+		flags &= ~GFP_SLAB_BUG_MASK;
+		pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix your code!\n",
+				invalid_mask, &invalid_mask, flags, &flags);
+		dump_stack();
 	}
 	local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK);
 
diff --git a/mm/slub.c b/mm/slub.c
index dd5a9eee7df5..ca60b414e569 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1629,8 +1629,9 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
 {
 	if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
 		gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
-		pr_emerg("Unexpected gfp: %#x (%pGg)\n", invalid_mask, &invalid_mask);
-		BUG();
+		flags &= ~GFP_SLAB_BUG_MASK;
+		pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix your code!\n",
+				invalid_mask, &invalid_mask, flags, &flags);
 	}
 
 	return allocate_slab(s,
-- 
2.8.1

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

* [PATCH 2/2] slab: do not panic on invalid gfp_mask
@ 2016-06-10  8:43   ` Michal Hocko
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2016-06-10  8:43 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Cristopher Lameter, David Rientjes, Joonsoo Kim, Pekka Enberg,
	linux-mm, LKML, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

both SLAB and SLUB BUG() when a caller provides an invalid gfp_mask.
This is a rather harsh way to announce a non-critical issue. Allocator
is free to ignore invalid flags. Let's simply replace BUG() by
dump_stack to tell the offender and fixup the mask to move on with the
allocation request.

This is an example for kmalloc(GFP_KERNEL|__GFP_HIGHMEM) from a test
module.
[   31.914753] Unexpected gfp: 0x2 (__GFP_HIGHMEM). Fixing up to gfp: 0x24000c0 (GFP_KERNEL). Fix your code!
[   31.914754] CPU: 0 PID: 2916 Comm: insmod Tainted: G           O    4.6.0-slabgfp2-00002-g4cdfc2ef4892-dirty #936
[   31.914755] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Debian-1.8.2-1 04/01/2014
[   31.914756]  0000000000000000 ffff88000d777c00 ffffffff8130e2fb ffff88000ec006c0
[   31.914758]  000000000000000c ffff88000d777c58 ffffffff811791dd 0000000000000246
[   31.914759]  0000000000000246 0000000000000046 00000002024000c0 ffff88000fa1d888
[   31.914759] Call Trace:
[   31.914760]  [<ffffffff8130e2fb>] dump_stack+0x67/0x90
[   31.914762]  [<ffffffff811791dd>] cache_alloc_refill+0x201/0x617
[   31.914763]  [<ffffffff81179b3f>] kmem_cache_alloc_trace+0xa7/0x24a
[   31.914764]  [<ffffffffa0005000>] ? 0xffffffffa0005000
[   31.914765]  [<ffffffffa0005020>] mymodule_init+0x20/0x1000 [test_slab]
[   31.914767]  [<ffffffff81000402>] do_one_initcall+0xe7/0x16c
[   31.914768]  [<ffffffff810b02de>] ? rcu_read_lock_sched_held+0x61/0x69
[   31.914769]  [<ffffffff81179c2f>] ? kmem_cache_alloc_trace+0x197/0x24a
[   31.914771]  [<ffffffff81125edc>] do_init_module+0x5f/0x1d9
[   31.914772]  [<ffffffff810d2c66>] load_module+0x1a3d/0x1f21
[   31.914774]  [<ffffffff81622931>] ? retint_kernel+0x2d/0x2d
[   31.914775]  [<ffffffff810d3232>] SyS_init_module+0xe8/0x10e
[   31.914776]  [<ffffffff810d3232>] ? SyS_init_module+0xe8/0x10e
[   31.914778]  [<ffffffff81001d08>] do_syscall_64+0x68/0x13f
[   31.914779]  [<ffffffff8162201a>] entry_SYSCALL64_slow_path+0x25/0x25

Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/slab.c | 6 ++++--
 mm/slub.c | 5 +++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 03fb724d6e48..fc9496bdd038 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2687,8 +2687,10 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep,
 	 */
 	if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
 		gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
-		pr_emerg("Unexpected gfp: %#x (%pGg)\n", invalid_mask, &invalid_mask);
-		BUG();
+		flags &= ~GFP_SLAB_BUG_MASK;
+		pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix your code!\n",
+				invalid_mask, &invalid_mask, flags, &flags);
+		dump_stack();
 	}
 	local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK);
 
diff --git a/mm/slub.c b/mm/slub.c
index dd5a9eee7df5..ca60b414e569 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1629,8 +1629,9 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
 {
 	if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
 		gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
-		pr_emerg("Unexpected gfp: %#x (%pGg)\n", invalid_mask, &invalid_mask);
-		BUG();
+		flags &= ~GFP_SLAB_BUG_MASK;
+		pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix your code!\n",
+				invalid_mask, &invalid_mask, flags, &flags);
 	}
 
 	return allocate_slab(s,
-- 
2.8.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2016-06-10  8:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-10  8:43 [PATCH 1/2] slab: make GFP_SLAB_BUG_MASK information more human readable Michal Hocko
2016-06-10  8:43 ` Michal Hocko
2016-06-10  8:43 ` [PATCH 2/2] slab: do not panic on invalid gfp_mask Michal Hocko
2016-06-10  8:43   ` Michal Hocko

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.