提交 e354cbb2 编写于 作者: L Li Huafei 提交者: Jialin Zhang

livepatch: Narrow the scope of the 'text_mutex' lock

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6NVPT

--------------------------------

Currently, arch_klp_code_modify_{prepare, post_process} is implemented
only in the x86 architecture. It is used to hold the 'text_mutex' lock
before entering the stop_machine and modifying the code, and to release
the lock after exiting the stop_machine. klp_mem_prepare() needs to hold
the 'text_mutex' lock only when saving old instruction code on x86 to
ensure that it holds valid instructions.

Place klp_mem_prepare() before arch_klp_code_modify_prepare() and lock the
save instruction action separately to narrow the 'text_mutex' lock.
Signed-off-by: NLi Huafei <lihuafei1@huawei.com>
Reviewed-by: NXu Kuohai <xukuohai@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Signed-off-by: NZheng Yejian <zhengyejian1@huawei.com>
Reviewed-by: NXu Kuohai <xukuohai@huawei.com>
Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
上级 3b61044c
......@@ -386,8 +386,15 @@ void arch_klp_code_modify_post_process(void)
long arch_klp_save_old_code(struct arch_klp_data *arch_data, void *old_func)
{
return copy_from_kernel_nofault(arch_data->old_code,
long ret;
/* Prevent text modification */
mutex_lock(&text_mutex);
ret = copy_from_kernel_nofault(arch_data->old_code,
old_func, JMP_E9_INSN_SIZE);
mutex_unlock(&text_mutex);
return ret;
}
int arch_klp_patch_func(struct klp_func *func)
......
......@@ -1696,12 +1696,10 @@ static int __klp_enable_patch(struct klp_patch *patch)
}
#endif
arch_klp_code_modify_prepare();
ret = klp_mem_prepare(patch);
if (ret) {
arch_klp_code_modify_post_process();
if (ret)
return ret;
}
arch_klp_code_modify_prepare();
ret = stop_machine(klp_try_enable_patch, &patch_data, cpu_online_mask);
arch_klp_code_modify_post_process();
if (ret) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册