• Dmitry Vyukov's avatar
    mm: don't warn about large allocations for slab · 97764043
    Dmitry Vyukov authored
    commit 61448479a9f2c954cde0cfe778cb6bec5d0a748d upstream.
    
    Slub does not call kmalloc_slab() for sizes > KMALLOC_MAX_CACHE_SIZE,
    instead it falls back to kmalloc_large().
    
    For slab KMALLOC_MAX_CACHE_SIZE == KMALLOC_MAX_SIZE and it calls
    kmalloc_slab() for all allocations relying on NULL return value for
    over-sized allocations.
    
    This inconsistency leads to unwanted warnings from kmalloc_slab() for
    over-sized allocations for slab.  Returning NULL for failed allocations is
    the expected behavior.
    
    Make slub and slab code consistent by checking size >
    KMALLOC_MAX_CACHE_SIZE in slab before calling kmalloc_slab().
    
    While we are here also fix the check in kmalloc_slab().  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.  For example, in case of a newly introduced bug in slub code.
    
    Also move the check in kmalloc_slab() from function entry to the size >
    192 case.  This partially compensates for the additional check in slab
    code and makes slub code a bit faster (at least theoretically).
    
    Also drop __GFP_NOWARN in the warning check.  This warning means a bug in
    slab code itself, user-passed flags have nothing to do with it.
    
    Nothing of this affects slob.
    
    Link: http://lkml.kernel.org/r/20180927171502.226522-1-dvyukov@gmail.comSigned-off-by: 's avatarDmitry Vyukov <dvyukov@google.com>
    Reported-by: syzbot+87829a10073277282ad1@syzkaller.appspotmail.com
    Reported-by: syzbot+ef4e8fc3a06e9019bb40@syzkaller.appspotmail.com
    Reported-by: syzbot+6e438f4036df52cbb863@syzkaller.appspotmail.com
    Reported-by: syzbot+8574471d8734457d98aa@syzkaller.appspotmail.com
    Reported-by: syzbot+af1504df0807a083dbd9@syzkaller.appspotmail.com
    Acked-by: 's avatarChristoph Lameter <cl@linux.com>
    Acked-by: 's avatarVlastimil Babka <vbabka@suse.cz>
    Cc: Pekka Enberg <penberg@kernel.org>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    97764043