mirror of
https://github.com/torvalds/linux.git
synced 2024-11-18 01:51:53 +00:00
7e35e4eb7e
Pre/post (un)patch callbacks might manipulate the system state. Cumulative livepatches might need to take over the changes made by the replaced ones. For this they might need to access some data stored or referenced by the old livepatches. Therefore the replaced livepatches have to stay around until post_patch() callback is called. It is achieved by calling the free functions later. It is the same location where disabled livepatches have already been freed. Link: http://lkml.kernel.org/r/20191030154313.13263-2-pmladek@suse.com To: Jiri Kosina <jikos@kernel.org> Cc: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> Cc: Nicolai Stange <nstange@suse.de> Cc: live-patching@vger.kernel.org Cc: linux-kernel@vger.kernel.org Acked-by: Miroslav Benes <mbenes@suse.cz> Acked-by: Joe Lawrence <joe.lawrence@redhat.com> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Petr Mladek <pmladek@suse.com>
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LIVEPATCH_CORE_H
|
|
#define _LIVEPATCH_CORE_H
|
|
|
|
#include <linux/livepatch.h>
|
|
|
|
extern struct mutex klp_mutex;
|
|
extern struct list_head klp_patches;
|
|
|
|
#define klp_for_each_patch_safe(patch, tmp_patch) \
|
|
list_for_each_entry_safe(patch, tmp_patch, &klp_patches, list)
|
|
|
|
#define klp_for_each_patch(patch) \
|
|
list_for_each_entry(patch, &klp_patches, list)
|
|
|
|
void klp_free_patch_async(struct klp_patch *patch);
|
|
void klp_free_replaced_patches_async(struct klp_patch *new_patch);
|
|
void klp_unpatch_replaced_patches(struct klp_patch *new_patch);
|
|
void klp_discard_nops(struct klp_patch *new_patch);
|
|
|
|
static inline bool klp_is_object_loaded(struct klp_object *obj)
|
|
{
|
|
return !obj->name || obj->mod;
|
|
}
|
|
|
|
static inline int klp_pre_patch_callback(struct klp_object *obj)
|
|
{
|
|
int ret = 0;
|
|
|
|
if (obj->callbacks.pre_patch)
|
|
ret = (*obj->callbacks.pre_patch)(obj);
|
|
|
|
obj->callbacks.post_unpatch_enabled = !ret;
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline void klp_post_patch_callback(struct klp_object *obj)
|
|
{
|
|
if (obj->callbacks.post_patch)
|
|
(*obj->callbacks.post_patch)(obj);
|
|
}
|
|
|
|
static inline void klp_pre_unpatch_callback(struct klp_object *obj)
|
|
{
|
|
if (obj->callbacks.pre_unpatch)
|
|
(*obj->callbacks.pre_unpatch)(obj);
|
|
}
|
|
|
|
static inline void klp_post_unpatch_callback(struct klp_object *obj)
|
|
{
|
|
if (obj->callbacks.post_unpatch_enabled &&
|
|
obj->callbacks.post_unpatch)
|
|
(*obj->callbacks.post_unpatch)(obj);
|
|
|
|
obj->callbacks.post_unpatch_enabled = false;
|
|
}
|
|
|
|
#endif /* _LIVEPATCH_CORE_H */
|