• Vlastimil Babka's avatar
    lib/stackdepot: allow requesting early initialization dynamically · a5f1783b
    Vlastimil Babka authored
    In a later patch we want to add stackdepot support for object owner
    tracking in slub caches, which is enabled by slub_debug boot parameter.
    This creates a bootstrap problem as some caches are created early in
    boot when slab_is_available() is false and thus stack_depot_init()
    tries to use memblock. But, as reported by Hyeonggon Yoo [1] we are
    already beyond memblock_free_all(). Ideally memblock allocation should
    fail, yet it succeeds, but later the system crashes, which is a
    separately handled issue.
    
    To resolve this boostrap issue in a robust way, this patch adds another
    way to request stack_depot_early_init(), which happens at a well-defined
    point of time. In addition to build-time CONFIG_STACKDEPOT_ALWAYS_INIT,
    code that's e.g. processing boot parameters (which happens early enough)
    can call a new function stack_depot_want_early_init(), which sets a flag
    that stack_depot_early_init() will check.
    
    In this patch we also convert page_owner to this approach. While it
    doesn't have the bootstrap issue as slub, it's also a functionality
    enabled by a boot param and can thus request stack_depot_early_init()
    with memblock allocation instead of later initialization with
    kvmalloc().
    
    As suggested by Mike, make stack_depot_early_init() only attempt
    memblock allocation and stack_depot_init() only attempt kvmalloc().
    Also change the latter to kvcalloc(). In both cases we can lose the
    explicit array zeroing, which the allocations do already.
    
    As suggested by Marco, provide empty implementations of the init
    functions for !CONFIG_STACKDEPOT builds to simplify the callers.
    
    [1] https://lore.kernel.org/all/YhnUcqyeMgCrWZbd@ip-172-31-19-208.ap-northeast-1.compute.internal/Reported-by: default avatarHyeonggon Yoo <42.hyeyoo@gmail.com>
    Suggested-by: default avatarMike Rapoport <rppt@linux.ibm.com>
    Suggested-by: default avatarMarco Elver <elver@google.com>
    Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
    Reviewed-by: default avatarMarco Elver <elver@google.com>
    Reviewed-and-tested-by: default avatarHyeonggon Yoo <42.hyeyoo@gmail.com>
    Reviewed-by: default avatarMike Rapoport <rppt@linux.ibm.com>
    Acked-by: default avatarDavid Rientjes <rientjes@google.com>
    a5f1783b
stackdepot.c 13.6 KB