Skip to contentSkip to conversation

mm: don't warn about large allocations for slab

PATCH Superseded Dmitry Vyukov 3 participants 3 messages Sep 27, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: don't warn about large allocations for slab

From: Dmitry Vyukov <[email protected]>

This warning does not seem to be useful. Most of the time it fires when allocation size depends on syscall arguments. We could add __GFP_NOWARN to these allocation sites, but having a warning only to suppress it does not make lots of sense. Moreover, this warnings never fires for constant-size allocations and never for slub, because there are additional checks and fallback to kmalloc_large() for large allocations and kmalloc_large() does not warn. So the warning only fires for non-constant allocations and only with slab, which is odd to begin with. The warning leads to episodic unuseful syzbot reports. Remote it.

While we are here also fix the check. We should check against KMALLOC_MAX_CACHE_SIZE rather than KMALLOC_MAX_SIZE. It all kinda worked because for slab the constants are the same, and slub always checks the size against KMALLOC_MAX_CACHE_SIZE before kmalloc_slab(). But if we get there with size > KMALLOC_MAX_CACHE_SIZE anyhow bad things will happen.

Cc Christoph Lameter <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc David Rientjes <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Andrew Morton <[email protected]>
Reported-by [email protected]
Reported-by [email protected]
Reported-by [email protected]
Reported-by [email protected]
Reported-by [email protected]
---
 mm/slab_common.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/slab_common.c +1 -3
index 1f903589980f9..2733bddcfdc0c 100644
@@ -1023,10 +1023,8 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
 {
 	unsigned int index;
 
-	if (unlikely(size > KMALLOC_MAX_SIZE)) {
-		WARN_ON_ONCE(!(flags & __GFP_NOWARN));
+	if (unlikely(size > KMALLOC_MAX_CACHE_SIZE))
 		return NULL;
-	}
 
 	if (size <= 192) {
 		if (!size)
Signature · 1 line
2.19.0.605.g01d371f741-goog
#1 lore raw
Quoted 11 lines · Dmitry Vyukov

From: Dmitry Vyukov <[email protected]>

This warning does not seem to be useful. Most of the time it fires when allocation size depends on syscall arguments. We could add __GFP_NOWARN to these allocation sites, but having a warning only to suppress it does not make lots of sense. Moreover, this warnings never fires for constant-size allocations and never for slub, because there are additional checks and fallback to kmalloc_large() for large allocations and kmalloc_large() does not warn. So the warning only fires for non-constant allocations and only with slab, which is odd to begin with. The warning leads to episodic unuseful syzbot reports. Remote it.

/Remove/

If its only for slab then KMALLOC_MAX_CACHE_SIZE and KMALLOC_MAX_SIZE are the same value.

Quoted 6 lines

While we are here also fix the check. We should check against KMALLOC_MAX_CACHE_SIZE rather than KMALLOC_MAX_SIZE. It all kinda worked because for slab the constants are the same, and slub always checks the size against KMALLOC_MAX_CACHE_SIZE before kmalloc_slab(). But if we get there with size > KMALLOC_MAX_CACHE_SIZE anyhow bad things will happen.

Then the WARN_ON is correct just change the constant used. Ensure that SLAB does the same checks as SLUB.

#2 lore raw
Quoted 26 lines · Christopher Lameter
Quoted 11 lines · Dmitry Vyukov

From: Dmitry Vyukov <[email protected]>

This warning does not seem to be useful. Most of the time it fires when allocation size depends on syscall arguments. We could add __GFP_NOWARN to these allocation sites, but having a warning only to suppress it does not make lots of sense. Moreover, this warnings never fires for constant-size allocations and never for slub, because there are additional checks and fallback to kmalloc_large() for large allocations and kmalloc_large() does not warn. So the warning only fires for non-constant allocations and only with slab, which is odd to begin with. The warning leads to episodic unuseful syzbot reports. Remote it.

/Remove/

If its only for slab then KMALLOC_MAX_CACHE_SIZE and KMALLOC_MAX_SIZE are the same value.

Quoted 6 lines

While we are here also fix the check. We should check against KMALLOC_MAX_CACHE_SIZE rather than KMALLOC_MAX_SIZE. It all kinda worked because for slab the constants are the same, and slub always checks the size against KMALLOC_MAX_CACHE_SIZE before kmalloc_slab(). But if we get there with size > KMALLOC_MAX_CACHE_SIZE anyhow bad things will happen.

Quoted 2 lines

Then the WARN_ON is correct just change the constant used. Ensure that SLAB does the same checks as SLUB.

Mailed v2 which adds the checks to slab.

I think the warning is still slightly wrong. It means a bug in slab code, it has nothing to do with user-passed flags.