Commit e1241e75 authored by Zheng Yejian's avatar Zheng Yejian
Browse files

livepatch/ppc64: Implement arch_klp_check_task_calltrace()

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9R2TB



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

Signed-off-by: default avatarZheng Yejian <zhengyejian1@huawei.com>
parent d6749cb4
Loading
Loading
Loading
Loading
+65 −37
Original line number Diff line number Diff line
@@ -234,14 +234,12 @@ static int klp_check_jump_func(struct stackframe *frame, void *ws_args)
	return 0;
}

static int do_check_calltrace(struct walk_stackframe_args *args,
static int check_task_calltrace(struct task_struct *t,
				struct walk_stackframe_args *args,
				int (*fn)(struct stackframe *, void *))
{
	struct task_struct *g, *t;
	unsigned long *stack;

	for_each_process_thread(g, t) {
	struct stackframe frame = { 0 };
	unsigned long *stack;

	if (t == current) {
		/*
@@ -254,8 +252,6 @@ static int do_check_calltrace(struct walk_stackframe_args *args,
		 * so similar
		 */
		stack = (unsigned long *)current_stack_pointer;
		} else if (klp_is_migration_thread(t->comm)) {
			continue;
	} else {
		/*
		 * Skip the first frame since it does not contain lr
@@ -266,7 +262,7 @@ static int do_check_calltrace(struct walk_stackframe_args *args,
		unsigned long s = *(unsigned long *)t->thread.ksp;

		if (!validate_sp(s, t, STACK_FRAME_OVERHEAD))
				continue;
			return 0;
		stack = (unsigned long *)s;
	}

@@ -278,10 +274,42 @@ static int do_check_calltrace(struct walk_stackframe_args *args,
		show_stack(t, NULL, KERN_INFO);
		return args->ret;
	}
	return 0;
}

static int do_check_calltrace(struct walk_stackframe_args *args,
			      int (*fn)(struct stackframe *, void *))
{
	int ret;
	struct task_struct *g, *t;

	for_each_process_thread(g, t) {
		if (klp_is_migration_thread(t->comm))
			continue;
		ret = check_task_calltrace(t, args, fn);
		if (ret)
			return ret;
	}
	return 0;
}

#ifdef CONFIG_LIVEPATCH_BREAKPOINT_NO_STOP_MACHINE
int arch_klp_check_task_calltrace(struct task_struct *t,
				  bool (*check_func)(void *, int *, unsigned long),
				  void *data)
{
	struct walk_stackframe_args args = {
		.data = data,
		.ret = 0,
		.check_func = check_func,
	};

	if (t == NULL)
		return -EINVAL;
	return check_task_calltrace(t, &args, klp_check_jump_func);
}
#endif

int arch_klp_check_calltrace(bool (*check_func)(void *, int *, unsigned long), void *data)
{
	struct walk_stackframe_args args = {