~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/pstore/ftrace.c

Version: ~ [ linux-5.4.2 ] ~ [ linux-5.3.15 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.88 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.158 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.206 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.206 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.78 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright 2012  Google, Inc.
  3  *
  4  * This software is licensed under the terms of the GNU General Public
  5  * License version 2, as published by the Free Software Foundation, and
  6  * may be copied, distributed, and modified under those terms.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11  * GNU General Public License for more details.
 12  */
 13 
 14 #include <linux/kernel.h>
 15 #include <linux/compiler.h>
 16 #include <linux/irqflags.h>
 17 #include <linux/percpu.h>
 18 #include <linux/smp.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>
 27 #include <asm/barrier.h>
 28 #include "internal.h"
 29 
 30 static void notrace pstore_ftrace_call(unsigned long ip,
 31                                        unsigned long parent_ip,
 32                                        struct ftrace_ops *op,
 33                                        struct pt_regs *regs)
 34 {
 35         unsigned long flags;
 36         struct pstore_ftrace_record rec = {};
 37 
 38         if (unlikely(oops_in_progress))
 39                 return;
 40 
 41         local_irq_save(flags);
 42 
 43         rec.ip = ip;
 44         rec.parent_ip = parent_ip;
 45         pstore_ftrace_encode_cpu(&rec, raw_smp_processor_id());
 46         psinfo->write_buf(PSTORE_TYPE_FTRACE, 0, NULL, 0, (void *)&rec,
 47                           sizeof(rec), psinfo);
 48 
 49         local_irq_restore(flags);
 50 }
 51 
 52 static struct ftrace_ops pstore_ftrace_ops __read_mostly = {
 53         .func   = pstore_ftrace_call,
 54 };
 55 
 56 static DEFINE_MUTEX(pstore_ftrace_lock);
 57 static bool pstore_ftrace_enabled;
 58 
 59 static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf,
 60                                         size_t count, loff_t *ppos)
 61 {
 62         u8 on;
 63         ssize_t ret;
 64 
 65         ret = kstrtou8_from_user(buf, count, 2, &on);
 66         if (ret)
 67                 return ret;
 68 
 69         mutex_lock(&pstore_ftrace_lock);
 70 
 71         if (!on ^ pstore_ftrace_enabled)
 72                 goto out;
 73 
 74         if (on)
 75                 ret = register_ftrace_function(&pstore_ftrace_ops);
 76         else
 77                 ret = unregister_ftrace_function(&pstore_ftrace_ops);
 78         if (ret) {
 79                 pr_err("%s: unable to %sregister ftrace ops: %zd\n",
 80                        __func__, on ? "" : "un", ret);
 81                 goto err;
 82         }
 83 
 84         pstore_ftrace_enabled = on;
 85 out:
 86         ret = count;
 87 err:
 88         mutex_unlock(&pstore_ftrace_lock);
 89 
 90         return ret;
 91 }
 92 
 93 static ssize_t pstore_ftrace_knob_read(struct file *f, char __user *buf,
 94                                        size_t count, loff_t *ppos)
 95 {
 96         char val[] = { '' + pstore_ftrace_enabled, '\n' };
 97 
 98         return simple_read_from_buffer(buf, count, ppos, val, sizeof(val));
 99 }
100 
101 static const struct file_operations pstore_knob_fops = {
102         .open   = simple_open,
103         .read   = pstore_ftrace_knob_read,
104         .write  = pstore_ftrace_knob_write,
105 };
106 
107 void pstore_register_ftrace(void)
108 {
109         struct dentry *dir;
110         struct dentry *file;
111 
112         if (!psinfo->write_buf)
113                 return;
114 
115         dir = debugfs_create_dir("pstore", NULL);
116         if (!dir) {
117                 pr_err("%s: unable to create pstore directory\n", __func__);
118                 return;
119         }
120 
121         file = debugfs_create_file("record_ftrace", 0600, dir, NULL,
122                                    &pstore_knob_fops);
123         if (!file) {
124                 pr_err("%s: unable to create record_ftrace file\n", __func__);
125                 goto err_file;
126         }
127 
128         return;
129 err_file:
130         debugfs_remove(dir);
131 }
132 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp