Merge tag 'mm-stable-2024-05-17-19-19' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / include / linux / codetag.h
CommitLineData
916cc516
SB
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * code tagging framework
4 */
5#ifndef _LINUX_CODETAG_H
6#define _LINUX_CODETAG_H
7
8#include <linux/types.h>
9
10struct codetag_iterator;
11struct codetag_type;
12struct codetag_module;
13struct seq_buf;
14struct module;
15
16/*
17 * An instance of this structure is created in a special ELF section at every
18 * code location being tagged. At runtime, the special section is treated as
19 * an array of these.
20 */
21struct codetag {
22 unsigned int flags; /* used in later patches */
23 unsigned int lineno;
24 const char *modname;
25 const char *function;
26 const char *filename;
27} __aligned(8);
28
29union codetag_ref {
30 struct codetag *ct;
31};
32
33struct codetag_type_desc {
34 const char *section;
35 size_t tag_size;
a4735739
SB
36 void (*module_load)(struct codetag_type *cttype,
37 struct codetag_module *cmod);
47a92dfb 38 bool (*module_unload)(struct codetag_type *cttype,
a4735739 39 struct codetag_module *cmod);
916cc516
SB
40};
41
42struct codetag_iterator {
43 struct codetag_type *cttype;
44 struct codetag_module *cmod;
45 unsigned long mod_id;
46 struct codetag *ct;
47};
48
49#ifdef MODULE
50#define CT_MODULE_NAME KBUILD_MODNAME
51#else
52#define CT_MODULE_NAME NULL
53#endif
54
55#define CODE_TAG_INIT { \
56 .modname = CT_MODULE_NAME, \
57 .function = __func__, \
58 .filename = __FILE__, \
59 .lineno = __LINE__, \
60 .flags = 0, \
61}
62
63void codetag_lock_module_list(struct codetag_type *cttype, bool lock);
1438d349 64bool codetag_trylock_module_list(struct codetag_type *cttype);
916cc516
SB
65struct codetag_iterator codetag_get_ct_iter(struct codetag_type *cttype);
66struct codetag *codetag_next_ct(struct codetag_iterator *iter);
67
68void codetag_to_text(struct seq_buf *out, struct codetag *ct);
69
70struct codetag_type *
71codetag_register_type(const struct codetag_type_desc *desc);
72
a4735739
SB
73#if defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES)
74void codetag_load_module(struct module *mod);
47a92dfb 75bool codetag_unload_module(struct module *mod);
a4735739
SB
76#else
77static inline void codetag_load_module(struct module *mod) {}
47a92dfb 78static inline bool codetag_unload_module(struct module *mod) { return true; }
a4735739
SB
79#endif
80
916cc516 81#endif /* _LINUX_CODETAG_H */