]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - lib/dump_stack.c
UBUNTU: SAUCE: mfd: intel-lpss: add quirk for Dell XPS 13 7390 2-in-1
[mirror_ubuntu-bionic-kernel.git] / lib / dump_stack.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * Provide a default dump_stack() function for architectures
4 * which don't implement their own.
5 */
6
7#include <linux/kernel.h>
8bc3bcc9 8#include <linux/export.h>
196779b9 9#include <linux/sched.h>
b17b0153 10#include <linux/sched/debug.h>
b58d9774
AT
11#include <linux/smp.h>
12#include <linux/atomic.h>
13
14static void __dump_stack(void)
15{
16 dump_stack_print_info(KERN_DEFAULT);
17 show_stack(NULL, NULL);
18}
1da177e4 19
196779b9
TH
20/**
21 * dump_stack - dump the current task information and its stack trace
22 *
23 * Architectures can override this implementation by implementing its own.
24 */
b58d9774
AT
25#ifdef CONFIG_SMP
26static atomic_t dump_lock = ATOMIC_INIT(-1);
27
722a9f92 28asmlinkage __visible void dump_stack(void)
1da177e4 29{
d7ce3692 30 unsigned long flags;
b58d9774
AT
31 int was_locked;
32 int old;
33 int cpu;
34
35 /*
36 * Permit this cpu to perform nested stack dumps while serialising
37 * against other CPUs
38 */
b58d9774 39retry:
d7ce3692 40 local_irq_save(flags);
b58d9774
AT
41 cpu = smp_processor_id();
42 old = atomic_cmpxchg(&dump_lock, -1, cpu);
43 if (old == -1) {
44 was_locked = 0;
45 } else if (old == cpu) {
46 was_locked = 1;
47 } else {
d7ce3692 48 local_irq_restore(flags);
b58d9774
AT
49 cpu_relax();
50 goto retry;
51 }
52
53 __dump_stack();
54
55 if (!was_locked)
56 atomic_set(&dump_lock, -1);
57
d7ce3692 58 local_irq_restore(flags);
b58d9774
AT
59}
60#else
722a9f92 61asmlinkage __visible void dump_stack(void)
b58d9774
AT
62{
63 __dump_stack();
1da177e4 64}
b58d9774 65#endif
1da177e4 66EXPORT_SYMBOL(dump_stack);