*** Replace KLP_* to KLP_TRANSITION_* ***
cover *** Replace KLP_* to KLP_TRANSITION_* ***
From: Wardenjohn <[email protected]>
As the previous described, renaming variables is not a good idead becase it will break userspace. This patch rename macros of KLP_* to KLP_TRANSITION_* to fix the confusing description of the klp transition state. With this marcos renamed, comments are not necessary at this point.
Wardenjohn (1):
livepatch: Rename KLP_* to KLP_TRANSITION_*
include/linux/livepatch.h | 6 ++-- init/init_task.c | 2 +- kernel/livepatch/core.c | 5 ++-- kernel/livepatch/patch.c | 4 +-- kernel/livepatch/transition.c | 54 +++++++++++++++++------------------ 5 files changed, 36 insertions(+), 35 deletions(-)
Signature · 1 line
2.37.3
PATCH 1/1 livepatch: Rename KLP_* to KLP_TRANSITION_*
From: Wardenjohn <[email protected]>
The original macros of KLP_* is about the state of the transition. Rename macros of KLP_* to KLP_TRANSITION_* to fix the confusing description of klp transition state.
--- include/linux/livepatch.h | 6 ++-- init/init_task.c | 2 +- kernel/livepatch/core.c | 5 ++-- kernel/livepatch/patch.c | 4 +-- kernel/livepatch/transition.c | 54 +++++++++++++++++------------------ 5 files changed, 36 insertions(+), 35 deletions(-)
include/linux/livepatch.h +3 -3
@@ -18,9 +18,9 @@#if IS_ENABLED (CONFIG_LIVEPATCH )/* task patch states */ -#define KLP_UNDEFINED -1 -#define KLP_UNPATCHED 0 -#define KLP_PATCHED 1 +#define KLP_TRANSITION_IDLE -1/* idle, no transition in progress */ +#define KLP_TRANSITION_UNPATCHED 0/* transitioning to unpatched state */ +#define KLP_TRANSITION_PATCHED 1/* transitioning to patched state */ /** * struct klp_func - function structure for live patching
init/init_task.c +1 -1
@@ -199,7 +199,7 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = { .trace_recursion = 0,#endif #ifdef CONFIG_LIVEPATCH - .patch_state = KLP_UNDEFINED, + .patch_state = KLP_TRANSITION_IDLE,#endif #ifdef CONFIG_SECURITY .security = NULL,
kernel/livepatch/core.c +3 -2
@@ -40,6 +40,7 @@ DEFINE_MUTEX(klp_mutex);/* * Actively used patches: enabled or in transition. Note that replaced * or disabled patches are not listed even though the related kernel +a * module still can be loaded. */ LIST_HEAD (klp_patches);
@@ -973,7 +974,7 @@ static int __klp_disable_patch(struct klp_patch *patch)if (klp_transition_patch)return -EBUSY ; -klp_init_transition (patch,KLP_UNPATCHED ); +klp_init_transition (patch,KLP_TRANSITION_UNPATCHED );klp_for_each_object (patch, obj)if (obj->patched)
@@ -1008,7 +1009,7 @@ static int __klp_enable_patch(struct klp_patch *patch)pr_notice ("enabling patch '%s'\n" , patch->mod->name); -klp_init_transition (patch,KLP_PATCHED ); +klp_init_transition (patch,KLP_TRANSITION_PATCHED );/* * Enforce the order of the func->transition writes in
kernel/livepatch/patch.c +2 -2
@@ -95,9 +95,9 @@ static void notrace klp_ftrace_handler(unsigned long ip, patch_state = current->patch_state; -WARN_ON_ONCE (patch_state ==KLP_UNDEFINED ); +WARN_ON_ONCE (patch_state ==KLP_TRANSITION_IDLE ); -if (patch_state ==KLP_UNPATCHED ) { +if (patch_state ==KLP_TRANSITION_UNPATCHED ) {/* * Use the previously patched version of the function. * If no previous patches exist, continue with the
kernel/livepatch/transition.c +27 -27
178 lines not on this page · raw message
Signature · 1 line
2.37.3
Quoted 6 lines
transition state. With this marcos renamed, comments are not necessary at this point.
Sorry for my careless, the comment still remains in the code. However, comment in the code do no harms here. Maybe it can be kept.
Josh Poimboeuf
maintainerQuoted 8 lines · zhang warden
Quoted 6 lines
transition state. With this marcos renamed, comments are not necessary at this point.
Sorry for my careless, the comment still remains in the code. However, comment in the code do no harms here. Maybe it can be kept.
The comments aren't actually correct.
For example, KLP_TRANSITION_UNPATCHED doesn't always mean "transitioning to unpatched state". Sometimes it means "transitioning *from* unpatched state".
Signature · 1 line
Josh
Quoted 11 lines · Josh Poimboeuf
Quoted 6 lines · zhang warden
Quoted 6 lines
transition state. With this marcos renamed, comments are not necessary at this point.
Quoted 11 lines
Quoted 2 lines
Sorry for my careless, the comment still remains in the code. However, comment in the code do no harms here. Maybe it can be kept.
The comments aren't actually correct.
For example,
KLP_TRANSITION_UNPATCHEDdoesn't always mean "transitioning to unpatched state". Sometimes it means "transitioning *from* unpatched state".Signature · 1 line
Josh
OK, I got it. I will remove the comment later. After all, comment is not necessary at this point after we rename the macros.
Josh Poimboeuf
maintainerQuoted 20 lines · zhang warden
Quoted 20 lines · Josh Poimboeuf
Quoted 8 lines · zhang warden
Quoted 6 lines
transition state. With this marcos renamed, comments are not necessary at this point.
Sorry for my careless, the comment still remains in the code. However, comment in the code do no harms here. Maybe it can be kept.
The comments aren't actually correct.
For example,
KLP_TRANSITION_UNPATCHEDdoesn't always mean "transitioning to unpatched state". Sometimes it means "transitioning *from* unpatched state".
Quoted 5 lines
Quoted 2 lines
Signature · 1 line
JoshOK, I got it. I will remove the comment later. After all, comment is not necessary at this point after we rename the macros.
Yeah, removing them altogether might be best, as the meaning of these can vary slightly depending on the operation (patching vs unpatching), and also depending on where it's stored (task->patch_state vs klp_target_state).
Signature · 1 line
Josh