xref: /linux-6.15/kernel/livepatch/patch.h (revision c349cdca)
1*c349cdcaSJosh Poimboeuf #ifndef _LIVEPATCH_PATCH_H
2*c349cdcaSJosh Poimboeuf #define _LIVEPATCH_PATCH_H
3*c349cdcaSJosh Poimboeuf 
4*c349cdcaSJosh Poimboeuf #include <linux/livepatch.h>
5*c349cdcaSJosh Poimboeuf #include <linux/list.h>
6*c349cdcaSJosh Poimboeuf #include <linux/ftrace.h>
7*c349cdcaSJosh Poimboeuf 
8*c349cdcaSJosh Poimboeuf /**
9*c349cdcaSJosh Poimboeuf  * struct klp_ops - structure for tracking registered ftrace ops structs
10*c349cdcaSJosh Poimboeuf  *
11*c349cdcaSJosh Poimboeuf  * A single ftrace_ops is shared between all enabled replacement functions
12*c349cdcaSJosh Poimboeuf  * (klp_func structs) which have the same old_addr.  This allows the switch
13*c349cdcaSJosh Poimboeuf  * between function versions to happen instantaneously by updating the klp_ops
14*c349cdcaSJosh Poimboeuf  * struct's func_stack list.  The winner is the klp_func at the top of the
15*c349cdcaSJosh Poimboeuf  * func_stack (front of the list).
16*c349cdcaSJosh Poimboeuf  *
17*c349cdcaSJosh Poimboeuf  * @node:	node for the global klp_ops list
18*c349cdcaSJosh Poimboeuf  * @func_stack:	list head for the stack of klp_func's (active func is on top)
19*c349cdcaSJosh Poimboeuf  * @fops:	registered ftrace ops struct
20*c349cdcaSJosh Poimboeuf  */
21*c349cdcaSJosh Poimboeuf struct klp_ops {
22*c349cdcaSJosh Poimboeuf 	struct list_head node;
23*c349cdcaSJosh Poimboeuf 	struct list_head func_stack;
24*c349cdcaSJosh Poimboeuf 	struct ftrace_ops fops;
25*c349cdcaSJosh Poimboeuf };
26*c349cdcaSJosh Poimboeuf 
27*c349cdcaSJosh Poimboeuf struct klp_ops *klp_find_ops(unsigned long old_addr);
28*c349cdcaSJosh Poimboeuf 
29*c349cdcaSJosh Poimboeuf int klp_patch_object(struct klp_object *obj);
30*c349cdcaSJosh Poimboeuf void klp_unpatch_object(struct klp_object *obj);
31*c349cdcaSJosh Poimboeuf 
32*c349cdcaSJosh Poimboeuf #endif /* _LIVEPATCH_PATCH_H */
33