Commit bd4298c7 authored by Yunfeng Ye's avatar Yunfeng Ye Committed by Will Deacon
Browse files

arm64: stacktrace: Factor out some common code into on_stack()



There are some common codes for stack checking, so factors it out into
the function on_stack().

No functional change.

Signed-off-by: default avatarYunfeng Ye <yeyunfeng@huawei.com>
Link: https://lore.kernel.org/r/07b3b0e6-3f58-4fed-07ea-7d17b7508948@huawei.com


Signed-off-by: default avatarWill Deacon <will@kernel.org>
parent b322c65f
Loading
Loading
Loading
Loading
+14 −26
Original line number Original line Diff line number Diff line
@@ -68,12 +68,10 @@ extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk);


DECLARE_PER_CPU(unsigned long *, irq_stack_ptr);
DECLARE_PER_CPU(unsigned long *, irq_stack_ptr);


static inline bool on_irq_stack(unsigned long sp,
static inline bool on_stack(unsigned long sp, unsigned long low,
				unsigned long high, enum stack_type type,
				struct stack_info *info)
				struct stack_info *info)
{
{
	unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr);
	unsigned long high = low + IRQ_STACK_SIZE;

	if (!low)
	if (!low)
		return false;
		return false;


@@ -83,12 +81,20 @@ static inline bool on_irq_stack(unsigned long sp,
	if (info) {
	if (info) {
		info->low = low;
		info->low = low;
		info->high = high;
		info->high = high;
		info->type = STACK_TYPE_IRQ;
		info->type = type;
	}
	}

	return true;
	return true;
}
}


static inline bool on_irq_stack(unsigned long sp,
				struct stack_info *info)
{
	unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr);
	unsigned long high = low + IRQ_STACK_SIZE;

	return on_stack(sp, low, high, STACK_TYPE_IRQ, info);
}

static inline bool on_task_stack(const struct task_struct *tsk,
static inline bool on_task_stack(const struct task_struct *tsk,
				 unsigned long sp,
				 unsigned long sp,
				 struct stack_info *info)
				 struct stack_info *info)
@@ -96,16 +102,7 @@ static inline bool on_task_stack(const struct task_struct *tsk,
	unsigned long low = (unsigned long)task_stack_page(tsk);
	unsigned long low = (unsigned long)task_stack_page(tsk);
	unsigned long high = low + THREAD_SIZE;
	unsigned long high = low + THREAD_SIZE;


	if (sp < low || sp >= high)
	return on_stack(sp, low, high, STACK_TYPE_TASK, info);
		return false;

	if (info) {
		info->low = low;
		info->high = high;
		info->type = STACK_TYPE_TASK;
	}

	return true;
}
}


#ifdef CONFIG_VMAP_STACK
#ifdef CONFIG_VMAP_STACK
@@ -117,16 +114,7 @@ static inline bool on_overflow_stack(unsigned long sp,
	unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack);
	unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack);
	unsigned long high = low + OVERFLOW_STACK_SIZE;
	unsigned long high = low + OVERFLOW_STACK_SIZE;


	if (sp < low || sp >= high)
	return on_stack(sp, low, high, STACK_TYPE_OVERFLOW, info);
		return false;

	if (info) {
		info->low = low;
		info->high = high;
		info->type = STACK_TYPE_OVERFLOW;
	}

	return true;
}
}
#else
#else
static inline bool on_overflow_stack(unsigned long sp,
static inline bool on_overflow_stack(unsigned long sp,
+2 −26
Original line number Original line Diff line number Diff line
@@ -95,19 +95,7 @@ static bool on_sdei_normal_stack(unsigned long sp, struct stack_info *info)
	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
	unsigned long high = low + SDEI_STACK_SIZE;
	unsigned long high = low + SDEI_STACK_SIZE;


	if (!low)
	return on_stack(sp, low, high, STACK_TYPE_SDEI_NORMAL, info);
		return false;

	if (sp < low || sp >= high)
		return false;

	if (info) {
		info->low = low;
		info->high = high;
		info->type = STACK_TYPE_SDEI_NORMAL;
	}

	return true;
}
}


static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info)
static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info)
@@ -115,19 +103,7 @@ static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info)
	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
	unsigned long high = low + SDEI_STACK_SIZE;
	unsigned long high = low + SDEI_STACK_SIZE;


	if (!low)
	return on_stack(sp, low, high, STACK_TYPE_SDEI_CRITICAL, info);
		return false;

	if (sp < low || sp >= high)
		return false;

	if (info) {
		info->low = low;
		info->high = high;
		info->type = STACK_TYPE_SDEI_CRITICAL;
	}

	return true;
}
}


bool _on_sdei_stack(unsigned long sp, struct stack_info *info)
bool _on_sdei_stack(unsigned long sp, struct stack_info *info)