Lines Matching +full:patch +full:- +full:address
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * transition.c - Kernel Live Patching transition functions
5 * Copyright (C) 2015-2016 Josh Poimboeuf <jpoimboe@redhat.com>
14 #include "patch.h"
32 * schedule(). This helps CPU-bound kthreads get patched.
65 * We allow to patch also functions where RCU is not watching,
78 * The transition to the target patch state is complete. Clean up the data
89 klp_transition_patch->mod->name,
92 if (klp_transition_patch->replace && klp_target_state == KLP_TRANSITION_PATCHED) {
106 * from this patch on the ops->func_stack. Otherwise, after
107 * func->transition gets cleared, the handler may choose a
115 func->transition = false;
124 task->patch_state = KLP_TRANSITION_IDLE;
131 task->patch_state = KLP_TRANSITION_IDLE;
143 pr_notice("'%s': %s complete\n", klp_transition_patch->mod->name,
162 klp_transition_patch->mod->name);
170 * patch state.
192 * of func->transition, if klp_ftrace_handler() is called later on
196 task->patch_state = READ_ONCE(klp_target_state);
203 * to-be-patched or to-be-unpatched function.
208 unsigned long func_addr, func_size, address;
214 * Check for the to-be-unpatched function
217 func_addr = (unsigned long)func->new_func;
218 func_size = func->new_size;
221 * Check for the to-be-patched function
224 ops = klp_find_ops(func->old_func);
226 if (list_is_singular(&ops->func_stack)) {
228 func_addr = (unsigned long)func->old_func;
229 func_size = func->old_size;
235 func_addr = (unsigned long)prev->new_func;
236 func_size = prev->new_size;
241 address = entries[i];
243 if (address >= func_addr && address < func_addr + func_size)
244 return -EAGAIN;
251 * Determine whether it's safe to transition the task to the target patch state
252 * by looking for any to-be-patched or to-be-unpatched functions on its stack.
266 return -EINVAL;
270 if (!obj->patched)
275 *oldname = func->old_name;
276 return -EADDRINUSE;
289 return -EBUSY;
296 task->patch_state = klp_target_state;
301 * Try to safely switch a task to the target patch state. If it's currently
302 * running, or it's sleeping on a to-be-patched or to-be-unpatched function, or
311 if (task->patch_state == klp_target_state)
322 * Now try to check the stack for any to-be-patched or to-be-unpatched
323 * functions. If all goes well, switch the task to the target patch
335 case -EBUSY: /* klp_check_and_switch_task() */
337 __func__, task->comm, task->pid);
339 case -EINVAL: /* klp_check_and_switch_task() */
341 __func__, task->comm, task->pid);
343 case -EADDRINUSE: /* klp_check_and_switch_task() */
345 __func__, task->comm, task->pid, old_name);
350 __func__, ret, task->comm, task->pid);
384 * Sends a fake signal to all non-kthread tasks with TIF_PATCH_PENDING set.
405 if (task->flags & PF_KTHREAD) {
413 * Send fake signal to all non-kthread tasks which are
423 * Try to switch all remaining tasks to the target patch state by walking the
424 * stacks of sleeping tasks and looking for any to-be-patched or
425 * to-be-unpatched functions. If such functions are found, the task can't be
428 * If any tasks are still stuck in the initial patch state, schedule a retry.
434 struct klp_patch *patch;
440 * Try to switch the tasks to the target patch state by walking their
441 * stacks and looking for any to-be-patched or to-be-unpatched
446 * unless the patch includes changes to a very common function.
466 } else if (task->patch_state != klp_target_state) {
469 task->patch_state = klp_target_state;
491 patch = klp_transition_patch;
499 if (!patch->enabled)
500 klp_free_patch_async(patch);
501 else if (patch->replace)
502 klp_free_replaced_patches_async(patch);
506 * Start the transition to the specified target patch state so tasks can begin
517 klp_transition_patch->mod->name,
521 * Mark all normal tasks as needing a patch state update. They'll
527 if (task->patch_state != klp_target_state)
532 * Mark all idle tasks as needing a patch state update. They'll switch
538 if (task->patch_state != klp_target_state)
548 * Initialize the global target patch state and all tasks to the initial patch
552 void klp_init_transition(struct klp_patch *patch, int state)
562 klp_transition_patch = patch;
565 * Set the global target patch state which tasks will switch to. This
570 pr_debug("'%s': initializing %s transition\n", patch->mod->name,
574 * Initialize all tasks to the initial patch state to prepare them for
579 WARN_ON_ONCE(task->patch_state != KLP_TRANSITION_IDLE);
580 task->patch_state = initial_state;
589 WARN_ON_ONCE(task->patch_state != KLP_TRANSITION_IDLE);
590 task->patch_state = initial_state;
594 * Enforce the order of the task->patch_state initializations and the
595 * func->transition updates to ensure that klp_ftrace_handler() doesn't
596 * see a func in transition with a task->patch_state of KLP_TRANSITION_IDLE.
600 * __klp_sched_try_switch() don't set a task->patch_state to
616 klp_for_each_object(patch, obj)
618 func->transition = true;
623 * reverse the direction of the target patch state. This can be done to
625 * tasks which are stuck in the initial patch state.
633 klp_transition_patch->mod->name,
658 * All patching has stopped, now re-initialize the global variables to
661 klp_transition_patch->enabled = !klp_transition_patch->enabled;
668 * task->patch_state to the wrong value.
694 child->patch_state = current->patch_state;
708 struct klp_patch *patch;
724 klp_transition_patch->forced = true;
725 else if (klp_transition_patch->replace) {
726 klp_for_each_patch(patch) {
727 if (patch != klp_transition_patch)
728 patch->forced = true;