Skip to content

Commit 8c06da6

Browse files
committed
Merge tag 'livepatching-for-6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching
Pull livepatching update from Petr Mladek: - Use more informative names for the livepatch transition states * tag 'livepatching-for-6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching: livepatch: Rename KLP_* to KLP_TRANSITION_*
2 parents a19264d + d927752 commit 8c06da6

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

include/linux/livepatch.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#if IS_ENABLED(CONFIG_LIVEPATCH)
1919

2020
/* task patch states */
21-
#define KLP_UNDEFINED -1
22-
#define KLP_UNPATCHED 0
23-
#define KLP_PATCHED 1
21+
#define KLP_TRANSITION_IDLE -1
22+
#define KLP_TRANSITION_UNPATCHED 0
23+
#define KLP_TRANSITION_PATCHED 1
2424

2525
/**
2626
* struct klp_func - function structure for live patching

init/init_task.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = {
199199
.trace_recursion = 0,
200200
#endif
201201
#ifdef CONFIG_LIVEPATCH
202-
.patch_state = KLP_UNDEFINED,
202+
.patch_state = KLP_TRANSITION_IDLE,
203203
#endif
204204
#ifdef CONFIG_SECURITY
205205
.security = NULL,

kernel/livepatch/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ static int __klp_disable_patch(struct klp_patch *patch)
973973
if (klp_transition_patch)
974974
return -EBUSY;
975975

976-
klp_init_transition(patch, KLP_UNPATCHED);
976+
klp_init_transition(patch, KLP_TRANSITION_UNPATCHED);
977977

978978
klp_for_each_object(patch, obj)
979979
if (obj->patched)
@@ -1008,7 +1008,7 @@ static int __klp_enable_patch(struct klp_patch *patch)
10081008

10091009
pr_notice("enabling patch '%s'\n", patch->mod->name);
10101010

1011-
klp_init_transition(patch, KLP_PATCHED);
1011+
klp_init_transition(patch, KLP_TRANSITION_PATCHED);
10121012

10131013
/*
10141014
* Enforce the order of the func->transition writes in

kernel/livepatch/patch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ static void notrace klp_ftrace_handler(unsigned long ip,
9595

9696
patch_state = current->patch_state;
9797

98-
WARN_ON_ONCE(patch_state == KLP_UNDEFINED);
98+
WARN_ON_ONCE(patch_state == KLP_TRANSITION_IDLE);
9999

100-
if (patch_state == KLP_UNPATCHED) {
100+
if (patch_state == KLP_TRANSITION_UNPATCHED) {
101101
/*
102102
* Use the previously patched version of the function.
103103
* If no previous patches exist, continue with the

kernel/livepatch/transition.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static DEFINE_PER_CPU(unsigned long[MAX_STACK_ENTRIES], klp_stack_entries);
2323

2424
struct klp_patch *klp_transition_patch;
2525

26-
static int klp_target_state = KLP_UNDEFINED;
26+
static int klp_target_state = KLP_TRANSITION_IDLE;
2727

2828
static unsigned int klp_signals_cnt;
2929

@@ -96,16 +96,16 @@ static void klp_complete_transition(void)
9696

9797
pr_debug("'%s': completing %s transition\n",
9898
klp_transition_patch->mod->name,
99-
klp_target_state == KLP_PATCHED ? "patching" : "unpatching");
99+
klp_target_state == KLP_TRANSITION_PATCHED ? "patching" : "unpatching");
100100

101-
if (klp_transition_patch->replace && klp_target_state == KLP_PATCHED) {
101+
if (klp_transition_patch->replace && klp_target_state == KLP_TRANSITION_PATCHED) {
102102
klp_unpatch_replaced_patches(klp_transition_patch);
103103
klp_discard_nops(klp_transition_patch);
104104
}
105105

106-
if (klp_target_state == KLP_UNPATCHED) {
106+
if (klp_target_state == KLP_TRANSITION_UNPATCHED) {
107107
/*
108-
* All tasks have transitioned to KLP_UNPATCHED so we can now
108+
* All tasks have transitioned to KLP_TRANSITION_UNPATCHED so we can now
109109
* remove the new functions from the func_stack.
110110
*/
111111
klp_unpatch_objects(klp_transition_patch);
@@ -123,36 +123,36 @@ static void klp_complete_transition(void)
123123
klp_for_each_func(obj, func)
124124
func->transition = false;
125125

126-
/* Prevent klp_ftrace_handler() from seeing KLP_UNDEFINED state */
127-
if (klp_target_state == KLP_PATCHED)
126+
/* Prevent klp_ftrace_handler() from seeing KLP_TRANSITION_IDLE state */
127+
if (klp_target_state == KLP_TRANSITION_PATCHED)
128128
klp_synchronize_transition();
129129

130130
read_lock(&tasklist_lock);
131131
for_each_process_thread(g, task) {
132132
WARN_ON_ONCE(test_tsk_thread_flag(task, TIF_PATCH_PENDING));
133-
task->patch_state = KLP_UNDEFINED;
133+
task->patch_state = KLP_TRANSITION_IDLE;
134134
}
135135
read_unlock(&tasklist_lock);
136136

137137
for_each_possible_cpu(cpu) {
138138
task = idle_task(cpu);
139139
WARN_ON_ONCE(test_tsk_thread_flag(task, TIF_PATCH_PENDING));
140-
task->patch_state = KLP_UNDEFINED;
140+
task->patch_state = KLP_TRANSITION_IDLE;
141141
}
142142

143143
klp_for_each_object(klp_transition_patch, obj) {
144144
if (!klp_is_object_loaded(obj))
145145
continue;
146-
if (klp_target_state == KLP_PATCHED)
146+
if (klp_target_state == KLP_TRANSITION_PATCHED)
147147
klp_post_patch_callback(obj);
148-
else if (klp_target_state == KLP_UNPATCHED)
148+
else if (klp_target_state == KLP_TRANSITION_UNPATCHED)
149149
klp_post_unpatch_callback(obj);
150150
}
151151

152152
pr_notice("'%s': %s complete\n", klp_transition_patch->mod->name,
153-
klp_target_state == KLP_PATCHED ? "patching" : "unpatching");
153+
klp_target_state == KLP_TRANSITION_PATCHED ? "patching" : "unpatching");
154154

155-
klp_target_state = KLP_UNDEFINED;
155+
klp_target_state = KLP_TRANSITION_IDLE;
156156
klp_transition_patch = NULL;
157157
}
158158

@@ -164,13 +164,13 @@ static void klp_complete_transition(void)
164164
*/
165165
void klp_cancel_transition(void)
166166
{
167-
if (WARN_ON_ONCE(klp_target_state != KLP_PATCHED))
167+
if (WARN_ON_ONCE(klp_target_state != KLP_TRANSITION_PATCHED))
168168
return;
169169

170170
pr_debug("'%s': canceling patching transition, going to unpatch\n",
171171
klp_transition_patch->mod->name);
172172

173-
klp_target_state = KLP_UNPATCHED;
173+
klp_target_state = KLP_TRANSITION_UNPATCHED;
174174
klp_complete_transition();
175175
}
176176

@@ -218,7 +218,7 @@ static int klp_check_stack_func(struct klp_func *func, unsigned long *entries,
218218
struct klp_ops *ops;
219219
int i;
220220

221-
if (klp_target_state == KLP_UNPATCHED) {
221+
if (klp_target_state == KLP_TRANSITION_UNPATCHED) {
222222
/*
223223
* Check for the to-be-unpatched function
224224
* (the func itself).
@@ -455,7 +455,7 @@ void klp_try_complete_transition(void)
455455
struct klp_patch *patch;
456456
bool complete = true;
457457

458-
WARN_ON_ONCE(klp_target_state == KLP_UNDEFINED);
458+
WARN_ON_ONCE(klp_target_state == KLP_TRANSITION_IDLE);
459459

460460
/*
461461
* Try to switch the tasks to the target patch state by walking their
@@ -532,11 +532,11 @@ void klp_start_transition(void)
532532
struct task_struct *g, *task;
533533
unsigned int cpu;
534534

535-
WARN_ON_ONCE(klp_target_state == KLP_UNDEFINED);
535+
WARN_ON_ONCE(klp_target_state == KLP_TRANSITION_IDLE);
536536

537537
pr_notice("'%s': starting %s transition\n",
538538
klp_transition_patch->mod->name,
539-
klp_target_state == KLP_PATCHED ? "patching" : "unpatching");
539+
klp_target_state == KLP_TRANSITION_PATCHED ? "patching" : "unpatching");
540540

541541
/*
542542
* Mark all normal tasks as needing a patch state update. They'll
@@ -578,7 +578,7 @@ void klp_init_transition(struct klp_patch *patch, int state)
578578
struct klp_func *func;
579579
int initial_state = !state;
580580

581-
WARN_ON_ONCE(klp_target_state != KLP_UNDEFINED);
581+
WARN_ON_ONCE(klp_target_state != KLP_TRANSITION_IDLE);
582582

583583
klp_transition_patch = patch;
584584

@@ -589,15 +589,15 @@ void klp_init_transition(struct klp_patch *patch, int state)
589589
klp_target_state = state;
590590

591591
pr_debug("'%s': initializing %s transition\n", patch->mod->name,
592-
klp_target_state == KLP_PATCHED ? "patching" : "unpatching");
592+
klp_target_state == KLP_TRANSITION_PATCHED ? "patching" : "unpatching");
593593

594594
/*
595595
* Initialize all tasks to the initial patch state to prepare them for
596596
* switching to the target state.
597597
*/
598598
read_lock(&tasklist_lock);
599599
for_each_process_thread(g, task) {
600-
WARN_ON_ONCE(task->patch_state != KLP_UNDEFINED);
600+
WARN_ON_ONCE(task->patch_state != KLP_TRANSITION_IDLE);
601601
task->patch_state = initial_state;
602602
}
603603
read_unlock(&tasklist_lock);
@@ -607,19 +607,19 @@ void klp_init_transition(struct klp_patch *patch, int state)
607607
*/
608608
for_each_possible_cpu(cpu) {
609609
task = idle_task(cpu);
610-
WARN_ON_ONCE(task->patch_state != KLP_UNDEFINED);
610+
WARN_ON_ONCE(task->patch_state != KLP_TRANSITION_IDLE);
611611
task->patch_state = initial_state;
612612
}
613613

614614
/*
615615
* Enforce the order of the task->patch_state initializations and the
616616
* func->transition updates to ensure that klp_ftrace_handler() doesn't
617-
* see a func in transition with a task->patch_state of KLP_UNDEFINED.
617+
* see a func in transition with a task->patch_state of KLP_TRANSITION_IDLE.
618618
*
619619
* Also enforce the order of the klp_target_state write and future
620620
* TIF_PATCH_PENDING writes to ensure klp_update_patch_state() and
621621
* __klp_sched_try_switch() don't set a task->patch_state to
622-
* KLP_UNDEFINED.
622+
* KLP_TRANSITION_IDLE.
623623
*/
624624
smp_wmb();
625625

@@ -652,7 +652,7 @@ void klp_reverse_transition(void)
652652

653653
pr_debug("'%s': reversing transition from %s\n",
654654
klp_transition_patch->mod->name,
655-
klp_target_state == KLP_PATCHED ? "patching to unpatching" :
655+
klp_target_state == KLP_TRANSITION_PATCHED ? "patching to unpatching" :
656656
"unpatching to patching");
657657

658658
/*
@@ -741,7 +741,7 @@ void klp_force_transition(void)
741741
klp_update_patch_state(idle_task(cpu));
742742

743743
/* Set forced flag for patches being removed. */
744-
if (klp_target_state == KLP_UNPATCHED)
744+
if (klp_target_state == KLP_TRANSITION_UNPATCHED)
745745
klp_transition_patch->forced = true;
746746
else if (klp_transition_patch->replace) {
747747
klp_for_each_patch(patch) {

0 commit comments

Comments
 (0)