Skip to content
Snippets Groups Projects
Select Git revision
  • 7f2923c4f73f21cfd714d12a2d48de8c21f11cfe
  • vme-testing default
  • ci-test
  • master
  • remoteproc
  • am625-sk-ov5640
  • pcal6534-upstreaming
  • lps22df-upstreaming
  • msc-upstreaming
  • imx8mp
  • iio/noa1305
  • vme-next
  • vme-next-4.14-rc4
  • v4.14-rc4
  • v4.14-rc3
  • v4.14-rc2
  • v4.14-rc1
  • v4.13
  • vme-next-4.13-rc7
  • v4.13-rc7
  • v4.13-rc6
  • v4.13-rc5
  • v4.13-rc4
  • v4.13-rc3
  • v4.13-rc2
  • v4.13-rc1
  • v4.12
  • v4.12-rc7
  • v4.12-rc6
  • v4.12-rc5
  • v4.12-rc4
  • v4.12-rc3
32 results

stacktrace.c

Blame
  • user avatar
    Josh Poimboeuf authored and Jiri Kosina committed
    For live patching and possibly other use cases, a stack trace is only
    useful if it can be assured that it's completely reliable.  Add a new
    save_stack_trace_tsk_reliable() function to achieve that.
    
    Note that if the target task isn't the current task, and the target task
    is allowed to run, then it could be writing the stack while the unwinder
    is reading it, resulting in possible corruption.  So the caller of
    save_stack_trace_tsk_reliable() must ensure that the task is either
    'current' or inactive.
    
    save_stack_trace_tsk_reliable() relies on the x86 unwinder's detection
    of pt_regs on the stack.  If the pt_regs are not user-mode registers
    from a syscall, then they indicate an in-kernel interrupt or exception
    (e.g. preemption or a page fault), in which case the stack is considered
    unreliable due to the nature of frame pointers.
    
    It also relies on the x86 unwinder's detection of other issues, such as:
    
    - corrupted stack data
    - stack grows the wrong way
    - stack walk doesn't reach the bottom
    - user didn't provide a large enough entries array
    
    Such issues are reported by checking unwind_error() and !unwind_done().
    
    Also add CONFIG_HAVE_RELIABLE_STACKTRACE so arch-independent code can
    determine at build time whether the function is implemented.
    
    Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
    Reviewed-by: default avatarMiroslav Benes <mbenes@suse.cz>
    Acked-by: Ingo Molnar <mingo@kernel.org>	# for the x86 changes
    Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
    af085d90
    History
    stacktrace.c 1.79 KiB
    /*
     * kernel/stacktrace.c
     *
     * Stack trace management functions
     *
     *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
     */
    #include <linux/sched.h>
    #include <linux/kernel.h>
    #include <linux/export.h>
    #include <linux/kallsyms.h>
    #include <linux/stacktrace.h>
    
    void print_stack_trace(struct stack_trace *trace, int spaces)
    {
    	int i;
    
    	if (WARN_ON(!trace->entries))
    		return;
    
    	for (i = 0; i < trace->nr_entries; i++)
    		printk("%*c%pS\n", 1 + spaces, ' ', (void *)trace->entries[i]);
    }
    EXPORT_SYMBOL_GPL(print_stack_trace);
    
    int snprint_stack_trace(char *buf, size_t size,
    			struct stack_trace *trace, int spaces)
    {
    	int i;
    	int generated;
    	int total = 0;
    
    	if (WARN_ON(!trace->entries))
    		return 0;
    
    	for (i = 0; i < trace->nr_entries; i++) {
    		generated = snprintf(buf, size, "%*c%pS\n", 1 + spaces, ' ',
    				     (void *)trace->entries[i]);
    
    		total += generated;
    
    		/* Assume that generated isn't a negative number */
    		if (generated >= size) {
    			buf += size;
    			size = 0;
    		} else {
    			buf += generated;
    			size -= generated;
    		}
    	}
    
    	return total;
    }
    EXPORT_SYMBOL_GPL(snprint_stack_trace);
    
    /*
     * Architectures that do not implement save_stack_trace_*()
     * get these weak aliases and once-per-bootup warnings
     * (whenever this facility is utilized - for example by procfs):
     */
    __weak void
    save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
    {
    	WARN_ONCE(1, KERN_INFO "save_stack_trace_tsk() not implemented yet.\n");
    }
    
    __weak void
    save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
    {
    	WARN_ONCE(1, KERN_INFO "save_stack_trace_regs() not implemented yet.\n");
    }
    
    __weak int
    save_stack_trace_tsk_reliable(struct task_struct *tsk,
    			      struct stack_trace *trace)
    {
    	WARN_ONCE(1, KERN_INFO "save_stack_tsk_reliable() not implemented yet.\n");
    	return -ENOSYS;
    }