@@ -555,6 +555,17 @@ config STACKLEAK_TRACK_MIN_SIZE
frame size greater than or equal to this parameter. If unsure,
leave the default value 100.
+config STACKLEAK_METRICS
+ bool "Show STACKLEAK metrics in the /proc file system"
+ depends on GCC_PLUGIN_STACKLEAK
+ depends on PROC_FS
+ help
+ If this is set, STACKLEAK metrics for every task are available in
+ the /proc file system. In particular, /proc/<pid>/lowest_stack
+ shows the current lowest_stack value and its final value from the
+ previous syscall. That information can be useful for estimating
+ the STACKLEAK performance impact for your workloads.
+
config HAVE_CC_STACKPROTECTOR
bool
help
@@ -115,6 +115,10 @@ ENTRY(erase_kstack)
mov %esp, %ecx
sub %edi, %ecx
+#ifdef CONFIG_STACKLEAK_METRICS
+ mov %edi, TASK_prev_lowest_stack(%ebp)
+#endif
+
cmp $THREAD_SIZE_asm, %ecx
jb 3f
ud2
@@ -116,6 +116,10 @@ ENTRY(erase_kstack)
mov %esp, %ecx
sub %edi, %ecx
+#ifdef CONFIG_STACKLEAK_METRICS
+ mov %rdi, TASK_prev_lowest_stack(%r11)
+#endif
+
/* Check that the counter value is sane. */
cmp $THREAD_SIZE_asm, %rcx
jb 3f
@@ -479,6 +479,9 @@ struct thread_struct {
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
unsigned long lowest_stack;
+# ifdef CONFIG_STACKLEAK_METRICS
+ unsigned long prev_lowest_stack;
+# endif
#endif
unsigned int sig_on_uaccess_err:1;
@@ -40,6 +40,9 @@ void common(void) {
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
OFFSET(TASK_lowest_stack, task_struct, thread.lowest_stack);
OFFSET(TASK_thread_sp0, task_struct, thread.sp0);
+# ifdef CONFIG_STACKLEAK_METRICS
+ OFFSET(TASK_prev_lowest_stack, task_struct, thread.prev_lowest_stack);
+# endif
#endif
BLANK();
@@ -139,6 +139,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
p->thread.lowest_stack = (unsigned long)task_stack_page(p) +
2 * sizeof(unsigned long);
+# ifdef CONFIG_STACKLEAK_METRICS
+ p->thread.prev_lowest_stack = p->thread.lowest_stack;
+# endif
#endif
if (unlikely(p->flags & PF_KTHREAD)) {
@@ -286,6 +286,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
p->thread.lowest_stack = (unsigned long)task_stack_page(p) +
2 * sizeof(unsigned long);
+# ifdef CONFIG_STACKLEAK_METRICS
+ p->thread.prev_lowest_stack = p->thread.lowest_stack;
+# endif
#endif
savesegment(gs, p->thread.gsindex);
@@ -2884,6 +2884,17 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns,
}
#endif /* CONFIG_LIVEPATCH */
+#ifdef CONFIG_STACKLEAK_METRICS
+static int proc_lowest_stack(struct seq_file *m, struct pid_namespace *ns,
+ struct pid *pid, struct task_struct *task)
+{
+ seq_printf(m, "prev_lowest_stack: %pK\nlowest_stack: %pK\n",
+ (void *)task->thread.prev_lowest_stack,
+ (void *)task->thread.lowest_stack);
+ return 0;
+}
+#endif /* CONFIG_STACKLEAK_METRICS */
+
/*
* Thread groups
*/
@@ -2988,6 +2999,9 @@ static const struct pid_entry tgid_base_stuff[] = {
#ifdef CONFIG_LIVEPATCH
ONE("patch_state", S_IRUSR, proc_pid_patch_state),
#endif
+#ifdef CONFIG_STACKLEAK_METRICS
+ ONE("lowest_stack", S_IRUGO, proc_lowest_stack),
+#endif
};
static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)
Introduce CONFIG_STACKLEAK_METRICS providing STACKLEAK information about tasks via the /proc file system. In particular, /proc/<pid>/lowest_stack shows the current lowest_stack value and its final value from the previous syscall. That information can be useful for estimating the STACKLEAK performance impact for different workloads. Signed-off-by: Alexander Popov <alex.popov@linux.com> --- arch/Kconfig | 11 +++++++++++ arch/x86/entry/entry_32.S | 4 ++++ arch/x86/entry/entry_64.S | 4 ++++ arch/x86/include/asm/processor.h | 3 +++ arch/x86/kernel/asm-offsets.c | 3 +++ arch/x86/kernel/process_32.c | 3 +++ arch/x86/kernel/process_64.c | 3 +++ fs/proc/base.c | 14 ++++++++++++++ 8 files changed, 45 insertions(+)