162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _LIVEPATCH_PATCH_H
362306a36Sopenharmony_ci#define _LIVEPATCH_PATCH_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/livepatch.h>
662306a36Sopenharmony_ci#include <linux/list.h>
762306a36Sopenharmony_ci#include <linux/ftrace.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/**
1062306a36Sopenharmony_ci * struct klp_ops - structure for tracking registered ftrace ops structs
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * A single ftrace_ops is shared between all enabled replacement functions
1362306a36Sopenharmony_ci * (klp_func structs) which have the same old_func.  This allows the switch
1462306a36Sopenharmony_ci * between function versions to happen instantaneously by updating the klp_ops
1562306a36Sopenharmony_ci * struct's func_stack list.  The winner is the klp_func at the top of the
1662306a36Sopenharmony_ci * func_stack (front of the list).
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * @node:	node for the global klp_ops list
1962306a36Sopenharmony_ci * @func_stack:	list head for the stack of klp_func's (active func is on top)
2062306a36Sopenharmony_ci * @fops:	registered ftrace ops struct
2162306a36Sopenharmony_ci */
2262306a36Sopenharmony_cistruct klp_ops {
2362306a36Sopenharmony_ci	struct list_head node;
2462306a36Sopenharmony_ci	struct list_head func_stack;
2562306a36Sopenharmony_ci	struct ftrace_ops fops;
2662306a36Sopenharmony_ci};
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_cistruct klp_ops *klp_find_ops(void *old_func);
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ciint klp_patch_object(struct klp_object *obj);
3162306a36Sopenharmony_civoid klp_unpatch_object(struct klp_object *obj);
3262306a36Sopenharmony_civoid klp_unpatch_objects(struct klp_patch *patch);
3362306a36Sopenharmony_civoid klp_unpatch_objects_dynamic(struct klp_patch *patch);
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#endif /* _LIVEPATCH_PATCH_H */
36