diff options
| -rw-r--r-- | Documentation/ramoops.txt | 4 | ||||
| -rw-r--r-- | fs/pstore/Kconfig | 1 | ||||
| -rw-r--r-- | fs/pstore/ftrace.c | 96 | ||||
| -rw-r--r-- | fs/pstore/internal.h | 6 | ||||
| -rw-r--r-- | fs/pstore/platform.c | 1 | ||||
| -rw-r--r-- | include/linux/pstore.h | 8 | ||||
| -rw-r--r-- | kernel/trace/trace_functions.c | 15 |
7 files changed, 105 insertions, 26 deletions
diff --git a/Documentation/ramoops.txt b/Documentation/ramoops.txt index 197ad59ab9bf..69b3cac4749d 100644 --- a/Documentation/ramoops.txt +++ b/Documentation/ramoops.txt | |||
| @@ -102,9 +102,7 @@ related hangs. The functions call chain log is stored in a "ftrace-ramoops" | |||
| 102 | file. Here is an example of usage: | 102 | file. Here is an example of usage: |
| 103 | 103 | ||
| 104 | # mount -t debugfs debugfs /sys/kernel/debug/ | 104 | # mount -t debugfs debugfs /sys/kernel/debug/ |
| 105 | # cd /sys/kernel/debug/tracing | 105 | # echo 1 > /sys/kernel/debug/pstore/record_ftrace |
| 106 | # echo function > current_tracer | ||
| 107 | # echo 1 > options/func_pstore | ||
| 108 | # reboot -f | 106 | # reboot -f |
| 109 | [...] | 107 | [...] |
| 110 | # mount -t pstore pstore /mnt/ | 108 | # mount -t pstore pstore /mnt/ |
diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index d39bb5cce883..ca71db69da07 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig | |||
| @@ -23,6 +23,7 @@ config PSTORE_FTRACE | |||
| 23 | bool "Persistent function tracer" | 23 | bool "Persistent function tracer" |
| 24 | depends on PSTORE | 24 | depends on PSTORE |
| 25 | depends on FUNCTION_TRACER | 25 | depends on FUNCTION_TRACER |
| 26 | depends on DEBUG_FS | ||
| 26 | help | 27 | help |
| 27 | With this option kernel traces function calls into a persistent | 28 | With this option kernel traces function calls into a persistent |
| 28 | ram buffer that can be decoded and dumped after reboot through | 29 | ram buffer that can be decoded and dumped after reboot through |
diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c index a130d484b7d3..2d57e1ac0115 100644 --- a/fs/pstore/ftrace.c +++ b/fs/pstore/ftrace.c | |||
| @@ -17,19 +17,113 @@ | |||
| 17 | #include <linux/percpu.h> | 17 | #include <linux/percpu.h> |
| 18 | #include <linux/smp.h> | 18 | #include <linux/smp.h> |
| 19 | #include <linux/atomic.h> | 19 | #include <linux/atomic.h> |
| 20 | #include <linux/types.h> | ||
| 21 | #include <linux/mutex.h> | ||
| 22 | #include <linux/ftrace.h> | ||
| 23 | #include <linux/fs.h> | ||
| 24 | #include <linux/debugfs.h> | ||
| 25 | #include <linux/err.h> | ||
| 26 | #include <linux/cache.h> | ||
| 20 | #include <asm/barrier.h> | 27 | #include <asm/barrier.h> |
| 21 | #include "internal.h" | 28 | #include "internal.h" |
| 22 | 29 | ||
| 23 | void notrace pstore_ftrace_call(unsigned long ip, unsigned long parent_ip) | 30 | static void notrace pstore_ftrace_call(unsigned long ip, |
| 31 | unsigned long parent_ip) | ||
| 24 | { | 32 | { |
| 33 | unsigned long flags; | ||
| 25 | struct pstore_ftrace_record rec = {}; | 34 | struct pstore_ftrace_record rec = {}; |
| 26 | 35 | ||
| 27 | if (unlikely(oops_in_progress)) | 36 | if (unlikely(oops_in_progress)) |
| 28 | return; | 37 | return; |
| 29 | 38 | ||
| 39 | local_irq_save(flags); | ||
| 40 | |||
| 30 | rec.ip = ip; | 41 | rec.ip = ip; |
| 31 | rec.parent_ip = parent_ip; | 42 | rec.parent_ip = parent_ip; |
| 32 | pstore_ftrace_encode_cpu(&rec, raw_smp_processor_id()); | 43 | pstore_ftrace_encode_cpu(&rec, raw_smp_processor_id()); |
| 33 | psinfo->write_buf(PSTORE_TYPE_FTRACE, 0, NULL, 0, (void *)&rec, | 44 | psinfo->write_buf(PSTORE_TYPE_FTRACE, 0, NULL, 0, (void *)&rec, |
| 34 | sizeof(rec), psinfo); | 45 | sizeof(rec), psinfo); |
| 46 | |||
| 47 | local_irq_restore(flags); | ||
| 48 | } | ||
| 49 | |||
| 50 | static struct ftrace_ops pstore_ftrace_ops __read_mostly = { | ||
| 51 | .func = pstore_ftrace_call, | ||
| 52 | }; | ||
| 53 | |||
| 54 | static DEFINE_MUTEX(pstore_ftrace_lock); | ||
| 55 | static bool pstore_ftrace_enabled; | ||
| 56 | |||
| 57 | static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf, | ||
| 58 | size_t count, loff_t *ppos) | ||
| 59 | { | ||
| 60 | u8 on; | ||
| 61 | ssize_t ret; | ||
| 62 | |||
| 63 | ret = kstrtou8_from_user(buf, count, 2, &on); | ||
| 64 | if (ret) | ||
| 65 | return ret; | ||
| 66 | |||
| 67 | mutex_lock(&pstore_ftrace_lock); | ||
| 68 | |||
| 69 | if (!on ^ pstore_ftrace_enabled) | ||
| 70 | goto out; | ||
| 71 | |||
| 72 | if (on) | ||
| 73 | ret = register_ftrace_function(&pstore_ftrace_ops); | ||
| 74 | else | ||
| 75 | ret = unregister_ftrace_function(&pstore_ftrace_ops); | ||
| 76 | if (ret) { | ||
| 77 | pr_err("%s: unable to %sregister ftrace ops: %zd\n", | ||
| 78 | __func__, on ? "" : "un", ret); | ||
| 79 | goto err; | ||
| 80 | } | ||
| 81 | |||
| 82 | pstore_ftrace_enabled = on; | ||
| 83 | out: | ||
| 84 | ret = count; | ||
| 85 | err: | ||
| 86 | mutex_unlock(&pstore_ftrace_lock); | ||
| 87 | |||
| 88 | return ret; | ||
| 89 | } | ||
| 90 | |||
| 91 | static ssize_t pstore_ftrace_knob_read(struct file *f, char __user *buf, | ||
| 92 | size_t count, loff_t *ppos) | ||
| 93 | { | ||
| 94 | char val[] = { '0' + pstore_ftrace_enabled, '\n' }; | ||
| 95 | |||
| 96 | return simple_read_from_buffer(buf, count, ppos, val, sizeof(val)); | ||
| 97 | } | ||
| 98 | |||
| 99 | static const struct file_operations pstore_knob_fops = { | ||
| 100 | .open = simple_open, | ||
| 101 | .read = pstore_ftrace_knob_read, | ||
| 102 | .write = pstore_ftrace_knob_write, | ||
| 103 | }; | ||
| 104 | |||
| 105 | void pstore_register_ftrace(void) | ||
| 106 | { | ||
| 107 | struct dentry *dir; | ||
| 108 | struct dentry *file; | ||
| 109 | |||
| 110 | if (!psinfo->write_buf) | ||
| 111 | return; | ||
| 112 | |||
| 113 | dir = debugfs_create_dir("pstore", NULL); | ||
| 114 | if (!dir) { | ||
| 115 | pr_err("%s: unable to create pstore directory\n", __func__); | ||
| 116 | return; | ||
| 117 | } | ||
| 118 | |||
| 119 | file = debugfs_create_file("record_ftrace", 0600, dir, NULL, | ||
| 120 | &pstore_knob_fops); | ||
| 121 | if (!file) { | ||
| 122 | pr_err("%s: unable to create record_ftrace file\n", __func__); | ||
| 123 | goto err_file; | ||
| 124 | } | ||
| 125 | |||
| 126 | return; | ||
| 127 | err_file: | ||
| 128 | debugfs_remove(dir); | ||
| 35 | } | 129 | } |
diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h index 0d0d3b7d5f12..4847f588b7d5 100644 --- a/fs/pstore/internal.h +++ b/fs/pstore/internal.h | |||
| @@ -39,6 +39,12 @@ pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec) | |||
| 39 | #endif | 39 | #endif |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | #ifdef CONFIG_PSTORE_FTRACE | ||
| 43 | extern void pstore_register_ftrace(void); | ||
| 44 | #else | ||
| 45 | static inline void pstore_register_ftrace(void) {} | ||
| 46 | #endif | ||
| 47 | |||
| 42 | extern struct pstore_info *psinfo; | 48 | extern struct pstore_info *psinfo; |
| 43 | 49 | ||
| 44 | extern void pstore_set_kmsg_bytes(int); | 50 | extern void pstore_set_kmsg_bytes(int); |
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 29996e8793a7..6c23eab7f76c 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c | |||
| @@ -236,6 +236,7 @@ int pstore_register(struct pstore_info *psi) | |||
| 236 | 236 | ||
| 237 | kmsg_dump_register(&pstore_dumper); | 237 | kmsg_dump_register(&pstore_dumper); |
| 238 | pstore_register_console(); | 238 | pstore_register_console(); |
| 239 | pstore_register_ftrace(); | ||
| 239 | 240 | ||
| 240 | if (pstore_update_ms >= 0) { | 241 | if (pstore_update_ms >= 0) { |
| 241 | pstore_timer.expires = jiffies + | 242 | pstore_timer.expires = jiffies + |
diff --git a/include/linux/pstore.h b/include/linux/pstore.h index c892587d9b81..ee3034a40884 100644 --- a/include/linux/pstore.h +++ b/include/linux/pstore.h | |||
| @@ -64,14 +64,6 @@ struct pstore_info { | |||
| 64 | void *data; | 64 | void *data; |
| 65 | }; | 65 | }; |
| 66 | 66 | ||
| 67 | |||
| 68 | #ifdef CONFIG_PSTORE_FTRACE | ||
| 69 | extern void pstore_ftrace_call(unsigned long ip, unsigned long parent_ip); | ||
| 70 | #else | ||
| 71 | static inline void pstore_ftrace_call(unsigned long ip, unsigned long parent_ip) | ||
| 72 | { } | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifdef CONFIG_PSTORE | 67 | #ifdef CONFIG_PSTORE |
| 76 | extern int pstore_register(struct pstore_info *); | 68 | extern int pstore_register(struct pstore_info *); |
| 77 | #else | 69 | #else |
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index a426f410c060..0ad83e3929d1 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c | |||
| @@ -13,7 +13,6 @@ | |||
| 13 | #include <linux/debugfs.h> | 13 | #include <linux/debugfs.h> |
| 14 | #include <linux/uaccess.h> | 14 | #include <linux/uaccess.h> |
| 15 | #include <linux/ftrace.h> | 15 | #include <linux/ftrace.h> |
| 16 | #include <linux/pstore.h> | ||
| 17 | #include <linux/fs.h> | 16 | #include <linux/fs.h> |
| 18 | 17 | ||
| 19 | #include "trace.h" | 18 | #include "trace.h" |
| @@ -75,10 +74,9 @@ function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) | |||
| 75 | preempt_enable_notrace(); | 74 | preempt_enable_notrace(); |
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | /* Our two options */ | 77 | /* Our option */ |
| 79 | enum { | 78 | enum { |
| 80 | TRACE_FUNC_OPT_STACK = 0x1, | 79 | TRACE_FUNC_OPT_STACK = 0x1, |
| 81 | TRACE_FUNC_OPT_PSTORE = 0x2, | ||
| 82 | }; | 80 | }; |
| 83 | 81 | ||
| 84 | static struct tracer_flags func_flags; | 82 | static struct tracer_flags func_flags; |
| @@ -106,12 +104,6 @@ function_trace_call(unsigned long ip, unsigned long parent_ip) | |||
| 106 | disabled = atomic_inc_return(&data->disabled); | 104 | disabled = atomic_inc_return(&data->disabled); |
| 107 | 105 | ||
| 108 | if (likely(disabled == 1)) { | 106 | if (likely(disabled == 1)) { |
| 109 | /* | ||
| 110 | * So far tracing doesn't support multiple buffers, so | ||
| 111 | * we make an explicit call for now. | ||
| 112 | */ | ||
| 113 | if (unlikely(func_flags.val & TRACE_FUNC_OPT_PSTORE)) | ||
| 114 | pstore_ftrace_call(ip, parent_ip); | ||
| 115 | pc = preempt_count(); | 107 | pc = preempt_count(); |
| 116 | trace_function(tr, ip, parent_ip, flags, pc); | 108 | trace_function(tr, ip, parent_ip, flags, pc); |
| 117 | } | 109 | } |
| @@ -177,9 +169,6 @@ static struct tracer_opt func_opts[] = { | |||
| 177 | #ifdef CONFIG_STACKTRACE | 169 | #ifdef CONFIG_STACKTRACE |
| 178 | { TRACER_OPT(func_stack_trace, TRACE_FUNC_OPT_STACK) }, | 170 | { TRACER_OPT(func_stack_trace, TRACE_FUNC_OPT_STACK) }, |
| 179 | #endif | 171 | #endif |
| 180 | #ifdef CONFIG_PSTORE_FTRACE | ||
| 181 | { TRACER_OPT(func_pstore, TRACE_FUNC_OPT_PSTORE) }, | ||
| 182 | #endif | ||
| 183 | { } /* Always set a last empty entry */ | 172 | { } /* Always set a last empty entry */ |
| 184 | }; | 173 | }; |
| 185 | 174 | ||
| @@ -232,8 +221,6 @@ static int func_set_flag(u32 old_flags, u32 bit, int set) | |||
| 232 | } | 221 | } |
| 233 | 222 | ||
| 234 | break; | 223 | break; |
| 235 | case TRACE_FUNC_OPT_PSTORE: | ||
| 236 | break; | ||
| 237 | default: | 224 | default: |
| 238 | return -EINVAL; | 225 | return -EINVAL; |
| 239 | } | 226 | } |
