[PATCH 1/1] sched/headers: don't count canary as free space on stack.

From: Maninder Singh
Date: Mon Apr 27 2020 - 06:17:32 EST


currently if all stack is used except canary and thread_info space,
stack usage prints about free space.

[11.7426] X (1260) used greatest stack depth: 4 bytes left

It is because canary is accounted as usable stack, so removing
that from accounting.

[12.8717] X (1270) used greatest stack depth: 0 bytes left

Signed-off-by: vaneet Narang <v.narang@xxxxxxxxxxx>
Signed-off-by: Maninder Singh <maninder1.s@xxxxxxxxxxx>
---
include/linux/sched/task_stack.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h
index 2413427..3174938 100644
--- a/include/linux/sched/task_stack.h
+++ b/include/linux/sched/task_stack.h
@@ -100,10 +100,11 @@ static inline unsigned long stack_not_used(struct task_struct *p)
# endif
} while (!*n);

+ /* Don't count canary as usable stack */
# ifdef CONFIG_STACK_GROWSUP
- return (unsigned long)end_of_stack(p) - (unsigned long)n;
+ return (unsigned long)end_of_stack(p) - (unsigned long)(n + 1);
# else
- return (unsigned long)n - (unsigned long)end_of_stack(p);
+ return (unsigned long)(n - 1) - (unsigned long)end_of_stack(p);
# endif
}
#endif
--
1.9.1