Merge tag 'x86_asm_for_v6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
[linux-block.git] / include / linux / stackdepot.h
CommitLineData
c942fddf 1/* SPDX-License-Identifier: GPL-2.0-or-later */
cd11016e
AP
2/*
3 * A generic stack depot implementation
4 *
5 * Author: Alexander Potapenko <glider@google.com>
6 * Copyright (C) 2016 Google, Inc.
7 *
8 * Based on code by Dmitry Chernenkov.
cd11016e
AP
9 */
10
11#ifndef _LINUX_STACKDEPOT_H
12#define _LINUX_STACKDEPOT_H
13
7857ccdf
ME
14#include <linux/gfp.h>
15
cd11016e 16typedef u32 depot_stack_handle_t;
83a4f1ef
AP
17/*
18 * Number of bits in the handle that stack depot doesn't use. Users may store
19 * information in them.
20 */
21#define STACK_DEPOT_EXTRA_BITS 5
cd11016e 22
11ac25c6
ME
23depot_stack_handle_t __stack_depot_save(unsigned long *entries,
24 unsigned int nr_entries,
83a4f1ef 25 unsigned int extra_bits,
11ac25c6
ME
26 gfp_t gfp_flags, bool can_alloc);
27
2dba5eb1 28/*
a5f1783b
VB
29 * Every user of stack depot has to call stack_depot_init() during its own init
30 * when it's decided that it will be calling stack_depot_save() later. This is
31 * recommended for e.g. modules initialized later in the boot process, when
32 * slab_is_available() is true.
2dba5eb1
VB
33 *
34 * The alternative is to select STACKDEPOT_ALWAYS_INIT to have stack depot
35 * enabled as part of mm_init(), for subsystems where it's known at compile time
36 * that stack depot will be used.
a5f1783b
VB
37 *
38 * Another alternative is to call stack_depot_want_early_init(), when the
39 * decision to use stack depot is taken e.g. when evaluating kernel boot
40 * parameters, which precedes the enablement point in mm_init().
41 *
42 * stack_depot_init() and stack_depot_want_early_init() can be called regardless
43 * of CONFIG_STACKDEPOT and are no-op when disabled. The actual save/fetch/print
44 * functions should only be called from code that makes sure CONFIG_STACKDEPOT
45 * is enabled.
2dba5eb1 46 */
a5f1783b 47#ifdef CONFIG_STACKDEPOT
2dba5eb1
VB
48int stack_depot_init(void);
49
a5f1783b
VB
50void __init stack_depot_want_early_init(void);
51
52/* This is supposed to be called only from mm_init() */
53int __init stack_depot_early_init(void);
2dba5eb1 54#else
a5f1783b
VB
55static inline int stack_depot_init(void) { return 0; }
56
57static inline void stack_depot_want_early_init(void) { }
58
2dba5eb1
VB
59static inline int stack_depot_early_init(void) { return 0; }
60#endif
61
c0cfc337
TG
62depot_stack_handle_t stack_depot_save(unsigned long *entries,
63 unsigned int nr_entries, gfp_t gfp_flags);
cd11016e 64
c0cfc337
TG
65unsigned int stack_depot_fetch(depot_stack_handle_t handle,
66 unsigned long **entries);
cd11016e 67
83a4f1ef
AP
68unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle);
69
0f68d45e
IK
70int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,
71 int spaces);
72
505be481
IK
73void stack_depot_print(depot_stack_handle_t stack);
74
cd11016e 75#endif