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 10ecba29f4SPetr Mladek #define klp_for_each_patch_safe(patch, tmp_patch) \ 11ecba29f4SPetr Mladek list_for_each_entry_safe(patch, tmp_patch, &klp_patches, list) 12ecba29f4SPetr Mladek 13ecba29f4SPetr Mladek #define klp_for_each_patch(patch) \ 14ecba29f4SPetr Mladek list_for_each_entry(patch, &klp_patches, list) 15ecba29f4SPetr Mladek 16*7e35e4ebSPetr Mladek void klp_free_patch_async(struct klp_patch *patch); 17*7e35e4ebSPetr Mladek void klp_free_replaced_patches_async(struct klp_patch *new_patch); 18*7e35e4ebSPetr Mladek void klp_unpatch_replaced_patches(struct klp_patch *new_patch); 19d697bad5SPetr Mladek void klp_discard_nops(struct klp_patch *new_patch); 20958ef1e3SPetr Mladek klp_is_object_loaded(struct klp_object * obj)2193862e38SJoe Lawrencestatic inline bool klp_is_object_loaded(struct klp_object *obj) 2293862e38SJoe Lawrence { 2393862e38SJoe Lawrence return !obj->name || obj->mod; 2493862e38SJoe Lawrence } 2593862e38SJoe Lawrence klp_pre_patch_callback(struct klp_object * obj)2693862e38SJoe Lawrencestatic inline int klp_pre_patch_callback(struct klp_object *obj) 2793862e38SJoe Lawrence { 285aaf1ab5SPetr Mladek int ret = 0; 2993862e38SJoe Lawrence 305aaf1ab5SPetr Mladek if (obj->callbacks.pre_patch) 315aaf1ab5SPetr Mladek ret = (*obj->callbacks.pre_patch)(obj); 3293862e38SJoe Lawrence 3393862e38SJoe Lawrence obj->callbacks.post_unpatch_enabled = !ret; 3493862e38SJoe Lawrence 3593862e38SJoe Lawrence return ret; 3693862e38SJoe Lawrence } 3793862e38SJoe Lawrence klp_post_patch_callback(struct klp_object * obj)3893862e38SJoe Lawrencestatic inline void klp_post_patch_callback(struct klp_object *obj) 3993862e38SJoe Lawrence { 4093862e38SJoe Lawrence if (obj->callbacks.post_patch) 4193862e38SJoe Lawrence (*obj->callbacks.post_patch)(obj); 4293862e38SJoe Lawrence } 4393862e38SJoe Lawrence klp_pre_unpatch_callback(struct klp_object * obj)4493862e38SJoe Lawrencestatic inline void klp_pre_unpatch_callback(struct klp_object *obj) 4593862e38SJoe Lawrence { 4693862e38SJoe Lawrence if (obj->callbacks.pre_unpatch) 4793862e38SJoe Lawrence (*obj->callbacks.pre_unpatch)(obj); 4893862e38SJoe Lawrence } 4993862e38SJoe Lawrence klp_post_unpatch_callback(struct klp_object * obj)5093862e38SJoe Lawrencestatic inline void klp_post_unpatch_callback(struct klp_object *obj) 5193862e38SJoe Lawrence { 5293862e38SJoe Lawrence if (obj->callbacks.post_unpatch_enabled && 5393862e38SJoe Lawrence obj->callbacks.post_unpatch) 5493862e38SJoe Lawrence (*obj->callbacks.post_unpatch)(obj); 555aaf1ab5SPetr Mladek 565aaf1ab5SPetr Mladek obj->callbacks.post_unpatch_enabled = false; 5793862e38SJoe Lawrence } 5893862e38SJoe Lawrence 5910517429SJiri Kosina #endif /* _LIVEPATCH_CORE_H */ 60