1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 210517429SJiri Kosina #ifndef _LIVEPATCH_CORE_H 310517429SJiri Kosina #define _LIVEPATCH_CORE_H 410517429SJiri Kosina 593862e38SJoe Lawrence #include <linux/livepatch.h> 693862e38SJoe Lawrence 710517429SJiri Kosina extern struct mutex klp_mutex; 868007289SPetr Mladek extern struct list_head klp_patches; 910517429SJiri Kosina 10*958ef1e3SPetr Mladek void klp_free_patch_start(struct klp_patch *patch); 11*958ef1e3SPetr Mladek 1293862e38SJoe Lawrence static inline bool klp_is_object_loaded(struct klp_object *obj) 1393862e38SJoe Lawrence { 1493862e38SJoe Lawrence return !obj->name || obj->mod; 1593862e38SJoe Lawrence } 1693862e38SJoe Lawrence 1793862e38SJoe Lawrence static inline int klp_pre_patch_callback(struct klp_object *obj) 1893862e38SJoe Lawrence { 195aaf1ab5SPetr Mladek int ret = 0; 2093862e38SJoe Lawrence 215aaf1ab5SPetr Mladek if (obj->callbacks.pre_patch) 225aaf1ab5SPetr Mladek ret = (*obj->callbacks.pre_patch)(obj); 2393862e38SJoe Lawrence 2493862e38SJoe Lawrence obj->callbacks.post_unpatch_enabled = !ret; 2593862e38SJoe Lawrence 2693862e38SJoe Lawrence return ret; 2793862e38SJoe Lawrence } 2893862e38SJoe Lawrence 2993862e38SJoe Lawrence static inline void klp_post_patch_callback(struct klp_object *obj) 3093862e38SJoe Lawrence { 3193862e38SJoe Lawrence if (obj->callbacks.post_patch) 3293862e38SJoe Lawrence (*obj->callbacks.post_patch)(obj); 3393862e38SJoe Lawrence } 3493862e38SJoe Lawrence 3593862e38SJoe Lawrence static inline void klp_pre_unpatch_callback(struct klp_object *obj) 3693862e38SJoe Lawrence { 3793862e38SJoe Lawrence if (obj->callbacks.pre_unpatch) 3893862e38SJoe Lawrence (*obj->callbacks.pre_unpatch)(obj); 3993862e38SJoe Lawrence } 4093862e38SJoe Lawrence 4193862e38SJoe Lawrence static inline void klp_post_unpatch_callback(struct klp_object *obj) 4293862e38SJoe Lawrence { 4393862e38SJoe Lawrence if (obj->callbacks.post_unpatch_enabled && 4493862e38SJoe Lawrence obj->callbacks.post_unpatch) 4593862e38SJoe Lawrence (*obj->callbacks.post_unpatch)(obj); 465aaf1ab5SPetr Mladek 475aaf1ab5SPetr Mladek obj->callbacks.post_unpatch_enabled = false; 4893862e38SJoe Lawrence } 4993862e38SJoe Lawrence 5010517429SJiri Kosina #endif /* _LIVEPATCH_CORE_H */ 51