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