Re: [PATCH 1/1] livepatch: Rename KLP_* to KLP_TRANSITION_*

2024-05-09 Thread Petr Mladek
On Tue 2024-05-07 13:01:11, zhangwar...@gmail.com wrote:
> From: Wardenjohn 
> 
> 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.
> 
> Signed-off-by: Wardenjohn 

JFYI, the patch has been comitted into livepatching.git, branch for-10.

Best regards,
Petr



Re: [PATCH 1/1] livepatch: Rename KLP_* to KLP_TRANSITION_*

2024-05-09 Thread Miroslav Benes
On Tue, 7 May 2024, zhangwar...@gmail.com wrote:

> From: Wardenjohn 
> 
> 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.
> 
> Signed-off-by: Wardenjohn 

Acked-by: Miroslav Benes 

M



Re: [PATCH 1/1] livepatch: Rename KLP_* to KLP_TRANSITION_*

2024-05-07 Thread Josh Poimboeuf
On Tue, May 07, 2024 at 01:01:11PM +0800, zhangwar...@gmail.com wrote:
> From: Wardenjohn 
> 
> 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.
> 
> Signed-off-by: Wardenjohn 

Acked-by: Josh Poimboeuf 

-- 
Josh



Re: [PATCH 1/1] livepatch: Rename KLP_* to KLP_TRANSITION_*

2024-05-07 Thread Petr Mladek
On Tue 2024-05-07 13:01:11, zhangwar...@gmail.com wrote:
> From: Wardenjohn 
> 
> 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.
> 
> Signed-off-by: Wardenjohn 

Looks good to me:

Reviewed-by: Petr Mladek 
Tested-by: Petr Mladek 

Best Regards,
Petr



[PATCH 1/1] livepatch: Rename KLP_* to KLP_TRANSITION_*

2024-05-06 Thread zhangwarden
From: Wardenjohn 

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.

Signed-off-by: Wardenjohn 
---
 include/linux/livepatch.h |  6 ++--
 init/init_task.c  |  2 +-
 kernel/livepatch/core.c   |  4 +--
 kernel/livepatch/patch.c  |  4 +--
 kernel/livepatch/transition.c | 54 +--
 5 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index 9b9b38e89563..51a258c24ff5 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -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
+#define KLP_TRANSITION_UNPATCHED0
+#define KLP_TRANSITION_PATCHED  1
 
 /**
  * struct klp_func - function structure for live patching
diff --git a/init/init_task.c b/init/init_task.c
index 2558b719e053..eeb110c65fe2 100644
--- a/init/init_task.c
+++ b/init/init_task.c
@@ -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,
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index ecbc9b6aba3a..52426665eecc 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -973,7 +973,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 +1008,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
diff --git a/kernel/livepatch/patch.c b/kernel/livepatch/patch.c
index 4152c71507e2..90408500e5a3 100644
--- a/kernel/livepatch/patch.c
+++ b/kernel/livepatch/patch.c
@@ -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
diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
index e54c3d60a904..ba069459c101 100644
--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -23,7 +23,7 @@ static DEFINE_PER_CPU(unsigned long[MAX_STACK_ENTRIES], 
klp_stack_entries);
 
 struct klp_patch *klp_transition_patch;
 
-static int klp_target_state = KLP_UNDEFINED;
+static int klp_target_state = KLP_TRANSITION_IDLE;
 
 static unsigned int klp_signals_cnt;
 
@@ -96,16 +96,16 @@ static void klp_complete_transition(void)
 
pr_debug("'%s': completing %s transition\n",
 klp_transition_patch->mod->name,
-klp_target_state == KLP_PATCHED ? "patching" : "unpatching");
+klp_target_state == KLP_TRANSITION_PATCHED ? "patching" : 
"unpatching");
 
-   if (klp_transition_patch->replace && klp_target_state == KLP_PATCHED) {
+   if (klp_transition_patch->replace && klp_target_state == 
KLP_TRANSITION_PATCHED) {
klp_unpatch_replaced_patches(klp_transition_patch);
klp_discard_nops(klp_transition_patch);
}
 
-   if (klp_target_state == KLP_UNPATCHED) {
+   if (klp_target_state == KLP_TRANSITION_UNPATCHED) {
/*
-* All tasks have transitioned to KLP_UNPATCHED so we can now
+* All tasks have transitioned to KLP_TRANSITION_UNPATCHED so 
we can now
 * remove the new functions from the func_stack.
 */
klp_unpatch_objects(klp_transition_patch);
@@ -123,36 +123,36 @@ static void klp_complete_transition(void)
klp_for_each_func(obj, func)
func->transition = false;
 
-   /* Prevent klp_ftrace_handler() from seeing KLP_UNDEFINED state */
-   if (klp_target_state == KLP_PATCHED)
+   /* Prevent klp_ftrace_handler() from seeing KLP_TRANSITION_IDLE state */
+   if (klp_target_state == KLP_TRANSITION_PATCHED)
klp_syn

[PATCH 1/1] livepatch: Rename KLP_* to KLP_TRANSITION_*

2024-05-06 Thread zhangwarden
From: Wardenjohn 

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.

Signed-off-by: Wardenjohn 
---
 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(-)

diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index 9b9b38e89563..25db447367a3 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -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_UNPATCHED0 /* transitioning to unpatched state 
*/
+#define KLP_TRANSITION_PATCHED  1 /* transitioning to patched state */
 
 /**
  * struct klp_func - function structure for live patching
diff --git a/init/init_task.c b/init/init_task.c
index 2558b719e053..eeb110c65fe2 100644
--- a/init/init_task.c
+++ b/init/init_task.c
@@ -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,
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index ecbc9b6aba3a..39b767b22cd7 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -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
diff --git a/kernel/livepatch/patch.c b/kernel/livepatch/patch.c
index 4152c71507e2..90408500e5a3 100644
--- a/kernel/livepatch/patch.c
+++ b/kernel/livepatch/patch.c
@@ -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
diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
index e54c3d60a904..ba069459c101 100644
--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -23,7 +23,7 @@ static DEFINE_PER_CPU(unsigned long[MAX_STACK_ENTRIES], 
klp_stack_entries);
 
 struct klp_patch *klp_transition_patch;
 
-static int klp_target_state = KLP_UNDEFINED;
+static int klp_target_state = KLP_TRANSITION_IDLE;
 
 static unsigned int klp_signals_cnt;
 
@@ -96,16 +96,16 @@ static void klp_complete_transition(void)
 
pr_debug("'%s': completing %s transition\n",
 klp_transition_patch->mod->name,
-klp_target_state == KLP_PATCHED ? "patching" : "unpatching");
+klp_target_state == KLP_TRANSITION_PATCHED ? "patching" : 
"unpatching");
 
-   if (klp_transition_patch->replace && klp_target_state == KLP_PATCHED) {
+   if (klp_transition_patch->replace && klp_target_state == 
KLP_TRANSITION_PATCHED) {
klp_unpatch_replaced_patches(klp_transition_patch);
klp_discard_nops(klp_transition_patch);
}
 
-   if (klp_target_state == KLP_UNPATCHED) {
+   if (klp_target_state == KLP_TRANSITION_UNPATCHED) {
/*
-* All tasks have transitioned to KLP_UNPATCHED so we can now
+* All tasks have transitioned to KLP_TRANSITION_UNPATCHED so 
we can now
 * remove the new functions from the func_stack.
 */
klp_unpatch_objects(klp_transition_patch);
@@ -123,36 +123,36 @@ static void klp_complete_transition(void)