12 Nov, 2016

1 commit

  • Some drivers would like to record stacktraces in order to aide leak
    tracing. As stackdepot already provides a facility for only storing the
    unique traces, thereby reducing the memory required, export that
    functionality for use by drivers.

    The code was originally created for KASAN and moved under lib in commit
    cd11016e5f521 ("mm, kasan: stackdepot implementation. Enable stackdepot
    for SLAB") so that it could be shared with mm/. In turn, we want to
    share it now with drivers.

    Link: http://lkml.kernel.org/r/20161108133209.22704-1-chris@chris-wilson.co.uk
    Signed-off-by: Chris Wilson
    Cc: Andrey Ryabinin
    Cc: Alexander Potapenko
    Cc: Dmitry Vyukov
    Cc: Joonsoo Kim
    Cc: "Kirill A. Shutemov"
    Cc: Daniel Vetter
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Chris Wilson
     

28 Oct, 2016

1 commit

  • KASAN uses stackdepot to memorize stacks for all kmalloc/kfree calls.
    Current stackdepot capacity is 16MB (1024 top level entries x 4 pages on
    second level). Size of each stack is (num_frames + 3) * sizeof(long).
    Which gives us ~84K stacks. This capacity was chosen empirically and it
    is enough to run kernel normally.

    However, when lots of configs are enabled and a fuzzer tries to maximize
    code coverage, it easily hits the limit within tens of minutes. I've
    tested for long a time with number of top level entries bumped 4x
    (4096). And I think I've seen overflow only once. But I don't have all
    configs enabled and code coverage has not reached maximum yet. So bump
    it 8x to 8192.

    Since we have two-level table, memory cost of this is very moderate --
    currently the top-level table is 8KB, with this patch it is 64KB, which
    is negligible under KASAN.

    Here is some approx math.

    128MB allows us to memorize ~670K stacks (assuming stack is ~200b).
    I've grepped kernel for kmalloc|kfree|kmem_cache_alloc|kmem_cache_free|
    kzalloc|kstrdup|kstrndup|kmemdup and it gives ~60K matches. Most of
    alloc/free call sites are reachable with only one stack. But some
    utility functions can have large fanout. Assuming average fanout is 5x,
    total number of alloc/free stacks is ~300K.

    Link: http://lkml.kernel.org/r/1476458416-122131-1-git-send-email-dvyukov@google.com
    Signed-off-by: Dmitry Vyukov
    Cc: Andrey Ryabinin
    Cc: Alexander Potapenko
    Cc: Joonsoo Kim
    Cc: Baozeng Ding
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dmitry Vyukov
     

29 Jul, 2016

1 commit

  • This (large, atomic) allocation attempt can fail. We expect and handle
    that, so avoid the scary warning.

    Link: http://lkml.kernel.org/r/20160720151905.GB19146@node.shutemov.name
    Cc: Andrey Ryabinin
    Cc: Alexander Potapenko
    Cc: Michal Hocko
    Cc: Rik van Riel
    Cc: David Rientjes
    Cc: Mel Gorman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kirill A. Shutemov
     

06 May, 2016

1 commit

  • Recently, we allow to save the stacktrace whose hashed value is 0. It
    causes the problem that stackdepot could return 0 even if in success.
    User of stackdepot cannot distinguish whether it is success or not so we
    need to solve this problem. In this patch, 1 bit are added to handle
    and make valid handle none 0 by setting this bit. After that, valid
    handle will not be 0 and 0 handle will represent failure correctly.

    Fixes: 33334e25769c ("lib/stackdepot.c: allow the stack trace hash to be zero")
    Link: http://lkml.kernel.org/r/1462252403-1106-1-git-send-email-iamjoonsoo.kim@lge.com
    Signed-off-by: Joonsoo Kim
    Cc: Alexander Potapenko
    Cc: Andrey Ryabinin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joonsoo Kim
     

29 Apr, 2016

1 commit

  • Do not bail out from depot_save_stack() if the stack trace has zero hash.
    Initially depot_save_stack() silently dropped stack traces with zero
    hashes, however there's actually no point in reserving this zero value.

    Reported-by: Joonsoo Kim
    Signed-off-by: Alexander Potapenko
    Acked-by: Andrey Ryabinin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexander Potapenko
     

26 Mar, 2016

1 commit

  • Implement the stack depot and provide CONFIG_STACKDEPOT. Stack depot
    will allow KASAN store allocation/deallocation stack traces for memory
    chunks. The stack traces are stored in a hash table and referenced by
    handles which reside in the kasan_alloc_meta and kasan_free_meta
    structures in the allocated memory chunks.

    IRQ stack traces are cut below the IRQ entry point to avoid unnecessary
    duplication.

    Right now stackdepot support is only enabled in SLAB allocator. Once
    KASAN features in SLAB are on par with those in SLUB we can switch SLUB
    to stackdepot as well, thus removing the dependency on SLUB stack
    bookkeeping, which wastes a lot of memory.

    This patch is based on the "mm: kasan: stack depots" patch originally
    prepared by Dmitry Chernenkov.

    Joonsoo has said that he plans to reuse the stackdepot code for the
    mm/page_owner.c debugging facility.

    [akpm@linux-foundation.org: s/depot_stack_handle/depot_stack_handle_t]
    [aryabinin@virtuozzo.com: comment style fixes]
    Signed-off-by: Alexander Potapenko
    Signed-off-by: Andrey Ryabinin
    Cc: Christoph Lameter
    Cc: Pekka Enberg
    Cc: David Rientjes
    Cc: Joonsoo Kim
    Cc: Andrey Konovalov
    Cc: Dmitry Vyukov
    Cc: Steven Rostedt
    Cc: Konstantin Serebryany
    Cc: Dmitry Chernenkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexander Potapenko