Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * External livepatch interfaces for patch creation tooling
4 */
5
6#ifndef _LINUX_LIVEPATCH_EXTERNAL_H_
7#define _LINUX_LIVEPATCH_EXTERNAL_H_
8
9#include <linux/types.h>
10
11#define KLP_RELOC_SEC_PREFIX ".klp.rela."
12#define KLP_SYM_PREFIX ".klp.sym."
13
14#define __KLP_PRE_PATCH_PREFIX __klp_pre_patch_callback_
15#define __KLP_POST_PATCH_PREFIX __klp_post_patch_callback_
16#define __KLP_PRE_UNPATCH_PREFIX __klp_pre_unpatch_callback_
17#define __KLP_POST_UNPATCH_PREFIX __klp_post_unpatch_callback_
18
19#define KLP_PRE_PATCH_PREFIX __stringify(__KLP_PRE_PATCH_PREFIX)
20#define KLP_POST_PATCH_PREFIX __stringify(__KLP_POST_PATCH_PREFIX)
21#define KLP_PRE_UNPATCH_PREFIX __stringify(__KLP_PRE_UNPATCH_PREFIX)
22#define KLP_POST_UNPATCH_PREFIX __stringify(__KLP_POST_UNPATCH_PREFIX)
23
24struct klp_object;
25
26typedef int (*klp_pre_patch_t)(struct klp_object *obj);
27typedef void (*klp_post_patch_t)(struct klp_object *obj);
28typedef void (*klp_pre_unpatch_t)(struct klp_object *obj);
29typedef void (*klp_post_unpatch_t)(struct klp_object *obj);
30
31/**
32 * struct klp_callbacks - pre/post live-(un)patch callback structure
33 * @pre_patch: executed before code patching
34 * @post_patch: executed after code patching
35 * @pre_unpatch: executed before code unpatching
36 * @post_unpatch: executed after code unpatching
37 * @post_unpatch_enabled: flag indicating if post-unpatch callback
38 * should run
39 *
40 * All callbacks are optional. Only the pre-patch callback, if provided,
41 * will be unconditionally executed. If the parent klp_object fails to
42 * patch for any reason, including a non-zero error status returned from
43 * the pre-patch callback, no further callbacks will be executed.
44 */
45struct klp_callbacks {
46 klp_pre_patch_t pre_patch;
47 klp_post_patch_t post_patch;
48 klp_pre_unpatch_t pre_unpatch;
49 klp_post_unpatch_t post_unpatch;
50 bool post_unpatch_enabled;
51};
52
53/*
54 * 'struct klp_{func,object}_ext' are compact "external" representations of
55 * 'struct klp_{func,object}'. They are used by objtool for livepatch
56 * generation. The structs are then read by the livepatch module and converted
57 * to the real structs before calling klp_enable_patch().
58 *
59 * TODO make these the official API for klp_enable_patch(). That should
60 * simplify livepatch's interface as well as its data structure lifetime
61 * management.
62 */
63struct klp_func_ext {
64 const char *old_name;
65 void *new_func;
66 unsigned long sympos;
67};
68
69struct klp_object_ext {
70 const char *name;
71 struct klp_func_ext *funcs;
72 struct klp_callbacks callbacks;
73 unsigned int nr_funcs;
74};
75
76#endif /* _LINUX_LIVEPATCH_EXTERNAL_H_ */