sched/irq: add a check for the interrupt stack in irq_dispatch

After irq_dispatch finished, the interrupt stack will be checked to
determine whether overflow occurs.
The relevant configuration reuses the configuration of stack overflow
detection during context switching.

Signed-off-by: guoshengyuan1 <guoshengyuan1@xiaomi.com>
This commit is contained in:
guoshengyuan1
2025-09-29 11:02:00 +08:00
committed by Xiang Xiao
parent a0ffe03ec5
commit ca7608c2ac
13 changed files with 78 additions and 32 deletions
+7 -3
View File
@@ -226,10 +226,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 3
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return arm_stack_check((void *)up_get_intstackbase(cpu),
STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
if (check_size == 0)
{
check_size = STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK);
}
return arm_stack_check((void *)up_get_intstackbase(cpu), check_size);
}
#endif
+7 -3
View File
@@ -236,10 +236,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 7
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return arm64_stack_check((void *)up_get_intstackbase(cpu),
STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
if (check_size == 0)
{
check_size = STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK);
}
return arm64_stack_check((void *)up_get_intstackbase(cpu), check_size);
}
#endif
+7 -3
View File
@@ -150,10 +150,14 @@ size_t up_check_tcbstack(FAR struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 3
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
uintptr_t start = (uintptr_t)g_intstackalloc;
return avr_stack_check(start, CONFIG_ARCH_INTERRUPTSTACK & ~3);
if (check_size == 0)
{
check_size = CONFIG_ARCH_INTERRUPTSTACK & ~3;
}
return avr_stack_check((uintptr_t)g_intstackalloc, check_size);
}
#endif
+7 -3
View File
@@ -144,10 +144,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
return ceva_stack_check((uintptr_t)tcb->stack_alloc_ptr, check_size);
}
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return ceva_stack_check((uintptr_t)g_intstackalloc,
g_intstackbase - g_intstackalloc);
if (check_size == 0)
{
check_size = g_intstackbase - g_intstackalloc;
}
return ceva_stack_check((uintptr_t)g_intstackalloc, check_size);
}
#endif /* CONFIG_STACK_COLORATION */
+7 -3
View File
@@ -121,10 +121,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 3
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return or1k_stack_check((uintptr_t)g_intstackalloc,
(CONFIG_ARCH_INTERRUPTSTACK & ~3));
if (check_size == 0)
{
check_size = CONFIG_ARCH_INTERRUPTSTACK & ~3;
}
return or1k_stack_check((uintptr_t)g_intstackalloc, check_size);
}
#endif
+7 -3
View File
@@ -182,10 +182,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 15
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return riscv_stack_check((uintptr_t)g_intstackalloc,
(CONFIG_ARCH_INTERRUPTSTACK & ~15));
if (check_size == 0)
{
check_size = CONFIG_ARCH_INTERRUPTSTACK & ~15;
}
return riscv_stack_check((uintptr_t)g_intstackalloc, check_size);
}
#endif
+7 -3
View File
@@ -206,10 +206,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 7
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return sparc_stack_check((void *)up_get_intstackbase(cpu),
STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
if (check_size == 0)
{
check_size = STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK);
}
return sparc_stack_check((void *)up_get_intstackbase(cpu), check_size);
}
#endif
+7 -3
View File
@@ -143,10 +143,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 15
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return tricore_stack_check((uintptr_t)g_intstackalloc,
(CONFIG_ARCH_INTERRUPTSTACK & ~15));
if (check_size == 0)
{
check_size = CONFIG_ARCH_INTERRUPTSTACK & ~15;
}
return tricore_stack_check((uintptr_t)g_intstackalloc, check_size);
}
#endif
+7 -3
View File
@@ -180,10 +180,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 3
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return x86_64_stack_check((void *)up_get_intstackbase(cpu),
STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
if (check_size == 0)
{
check_size = STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK);
}
return x86_64_stack_check((void *)up_get_intstackbase(cpu), check_size);
}
#endif
+7 -2
View File
@@ -164,9 +164,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t check_size)
}
#if CONFIG_ARCH_INTERRUPTSTACK > 15
size_t up_check_intstack(int cpu)
size_t up_check_intstack(int cpu, size_t check_size)
{
return xtensa_stack_check(up_get_intstackbase(cpu), INTSTACK_SIZE);
if (check_size == 0)
{
check_size = INTSTACK_SIZE;
}
return xtensa_stack_check(up_get_intstackbase(cpu), check_size);
}
#endif
+1 -1
View File
@@ -2565,7 +2565,7 @@ void irq_dispatch(int irq, FAR void *context);
struct tcb_s;
size_t up_check_tcbstack(FAR struct tcb_s *tcb, size_t check_size);
#if defined(CONFIG_ARCH_INTERRUPTSTACK) && CONFIG_ARCH_INTERRUPTSTACK > 3
size_t up_check_intstack(int cpu);
size_t up_check_intstack(int cpu, size_t check_size);
#endif
#endif
+5
View File
@@ -157,4 +157,9 @@ void irq_dispatch(int irq, FAR void *context)
kmm_checkcorruption();
}
#endif
#if defined(CONFIG_STACKCHECK_SOFTWARE) && CONFIG_STACKCHECK_MARGIN > 0
DEBUGASSERT(up_check_intstack(this_cpu(),
CONFIG_STACKCHECK_MARGIN) == 0);
#endif
}
+2 -2
View File
@@ -296,7 +296,7 @@ static void dump_stacks(FAR struct tcb_s *rtcb, uintptr_t sp)
intstack_base,
intstack_size,
#ifdef CONFIG_STACK_COLORATION
up_check_intstack(cpu)
up_check_intstack(cpu, 0)
#else
0
#endif
@@ -500,7 +500,7 @@ static void dump_tasks(void)
for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++)
{
# ifdef CONFIG_STACK_COLORATION
size_t stack_used = up_check_intstack(cpu);
size_t stack_used = up_check_intstack(cpu, 0);
size_t stack_filled = 0;
if (stack_used > 0)