kernel/Makefile | 1 + kernel/backtrace.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 9 +++++++++ 3 files changed, 49 insertions(+) create mode 100644 kernel/backtrace.c
When the number of CPUs is large, the echo l > /proc/sysrq-trigger
prints a large number of logs. Users can use this interface to
trigger backtrace on specified CPUs.
Signed-off-by: Liu Chao <liuchao173@huawei.com>
---
kernel/Makefile | 1 +
kernel/backtrace.c | 39 +++++++++++++++++++++++++++++++++++++++
lib/Kconfig.debug | 9 +++++++++
3 files changed, 49 insertions(+)
create mode 100644 kernel/backtrace.c
diff --git a/kernel/Makefile b/kernel/Makefile
index 87866b037fbe..330647518ae3 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -116,6 +116,7 @@ obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o
obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call_inline.o
obj-$(CONFIG_CFI_CLANG) += cfi.o
+obj-$(CONFIG_BACKTRACE) += backtrace.o
obj-$(CONFIG_PERF_EVENTS) += events/
diff --git a/kernel/backtrace.c b/kernel/backtrace.c
new file mode 100644
index 000000000000..767ad46d1add
--- /dev/null
+++ b/kernel/backtrace.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/debugfs.h>
+#include <linux/nmi.h>
+
+static ssize_t backtrace_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct cpumask mask;
+ int err;
+
+ err = cpumask_parselist_user(buf, count, &mask);
+ if (err < 0 || cpumask_last(&mask) >= nr_cpu_ids) {
+ pr_err("backtrace: incorrect CPU range.\n");
+ return -EINVAL;
+ }
+
+ if (!trigger_cpumask_backtrace(&mask)) {
+ pr_err("backtrace: backtrace printing fails.\n");
+ return -EINVAL;
+ }
+
+ return count;
+}
+
+static const struct file_operations backtrace_fops = {
+ .owner = THIS_MODULE,
+ .write = backtrace_write,
+ .llseek = no_llseek,
+};
+
+static int __init backtrace_init(void)
+{
+ debugfs_create_file("backtrace", 0200, NULL, NULL,
+ &backtrace_fops);
+
+ return 0;
+}
+device_initcall(backtrace_init);
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 7312ae7c3cc5..326ea9e6eba7 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -698,6 +698,15 @@ source "lib/Kconfig.kgdb"
source "lib/Kconfig.ubsan"
source "lib/Kconfig.kcsan"
+config BACKTRACE
+ bool "Support trigger backtrace according cpulist"
+ depends on SMP && DEBUG_FS
+ help
+ When the number of CPUs is large, the echo l > /proc/sysrq-trigger
+ prints a large number of logs. Users can echo cpulist >
+ /sys/kernel/debug/backtrace to trigger backtrace on specified
+ CPUs.
+
endmenu
menu "Networking Debugging"
--
2.33.0
Hi Liu, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-nonmm-unstable] [also build test ERROR on linus/master v6.12-rc7 next-20241113] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Liu-Chao/Add-interface-to-trigger-backtrace-on-specified-CPUs/20241112-210050 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable patch link: https://lore.kernel.org/r/20241112125609.1406586-1-liuchao173%40huawei.com patch subject: [PATCH] Add interface to trigger backtrace on specified CPUs config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20241113/202411132108.ZvhAmel0-lkp@intel.com/config) compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 592c0fe55f6d9a811028b5f3507be91458ab2713) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241113/202411132108.ZvhAmel0-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202411132108.ZvhAmel0-lkp@intel.com/ All errors (new ones prefixed by >>): >> kernel/backtrace.c:29:12: error: use of undeclared identifier 'no_llseek'; did you mean 'noop_llseek'? 29 | .llseek = no_llseek, | ^~~~~~~~~ | noop_llseek include/linux/fs.h:3241:15: note: 'noop_llseek' declared here 3241 | extern loff_t noop_llseek(struct file *file, loff_t offset, int whence); | ^ 1 error generated. vim +29 kernel/backtrace.c 25 26 static const struct file_operations backtrace_fops = { 27 .owner = THIS_MODULE, 28 .write = backtrace_write, > 29 .llseek = no_llseek, 30 }; 31 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Hi Liu, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-nonmm-unstable] [also build test ERROR on linus/master v6.12-rc7 next-20241113] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Liu-Chao/Add-interface-to-trigger-backtrace-on-specified-CPUs/20241112-210050 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable patch link: https://lore.kernel.org/r/20241112125609.1406586-1-liuchao173%40huawei.com patch subject: [PATCH] Add interface to trigger backtrace on specified CPUs config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20241113/202411132038.ZTErSl6v-lkp@intel.com/config) compiler: arceb-elf-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241113/202411132038.ZTErSl6v-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202411132038.ZTErSl6v-lkp@intel.com/ All errors (new ones prefixed by >>): >> kernel/backtrace.c:29:19: error: 'no_llseek' undeclared here (not in a function); did you mean 'noop_llseek'? 29 | .llseek = no_llseek, | ^~~~~~~~~ | noop_llseek vim +29 kernel/backtrace.c 25 26 static const struct file_operations backtrace_fops = { 27 .owner = THIS_MODULE, 28 .write = backtrace_write, > 29 .llseek = no_llseek, 30 }; 31 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2024 Red Hat, Inc.