VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
457c899653991 (Thomas Gleixner    2019-05-19 13:08:55 +0100   1) // SPDX-License-Identifier: GPL-2.0-only
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800   2) #include <linux/kernel.h>
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800   3) #include <linux/init.h>
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800   4) #include <linux/random.h>
d43c36dc6b357 (Alexey Dobriyan    2009-10-07 17:09:06 +0400   5) #include <linux/sched.h>
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800   6) #include <linux/stat.h>
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800   7) #include <linux/types.h>
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800   8) #include <linux/fs.h>
8bc3bcc93a2b4 (Paul Gortmaker     2011-11-16 21:29:17 -0500   9) #include <linux/export.h>
f4f154fd920b2 (Akinobu Mita       2006-12-08 02:39:47 -0800  10) #include <linux/interrupt.h>
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  11) #include <linux/stacktrace.h>
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  12) #include <linux/fault-inject.h>
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  13) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  14) /*
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  15)  * setup_fault_attr() is a helper function for various __setup handlers, so it
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  16)  * returns 0 on error, because that is what __setup handlers do.
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  17)  */
6cba00eaa95c1 (Per Forlin         2011-09-13 23:03:28 +0200  18) int setup_fault_attr(struct fault_attr *attr, char *str)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  19) {
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  20) 	unsigned long probability;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  21) 	unsigned long interval;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  22) 	int times;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  23) 	int space;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  24) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  25) 	/* "<interval>,<probability>,<space>,<times>" */
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  26) 	if (sscanf(str, "%lu,%lu,%d,%d",
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  27) 			&interval, &probability, &space, &times) < 4) {
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  28) 		printk(KERN_WARNING
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  29) 			"FAULT_INJECTION: failed to parse arguments\n");
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  30) 		return 0;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  31) 	}
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  32) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  33) 	attr->probability = probability;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  34) 	attr->interval = interval;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  35) 	atomic_set(&attr->times, times);
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  36) 	atomic_set(&attr->space, space);
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  37) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  38) 	return 1;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  39) }
6cba00eaa95c1 (Per Forlin         2011-09-13 23:03:28 +0200  40) EXPORT_SYMBOL_GPL(setup_fault_attr);
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  41) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  42) static void fail_dump(struct fault_attr *attr)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  43) {
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  44) 	if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) {
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  45) 		printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n"
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  46) 		       "name %pd, interval %lu, probability %lu, "
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  47) 		       "space %d, times %d\n", attr->dname,
bb387002693ed (Florian Westphal   2015-10-22 13:32:27 -0700  48) 		       attr->interval, attr->probability,
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  49) 		       atomic_read(&attr->space),
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  50) 		       atomic_read(&attr->times));
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  51) 		if (attr->verbose > 1)
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  52) 			dump_stack();
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800  53) 	}
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  54) }
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  55) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  56) #define atomic_dec_not_zero(v)		atomic_add_unless((v), -1, 0)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  57) 
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800  58) static bool fail_task(struct fault_attr *attr, struct task_struct *task)
f4f154fd920b2 (Akinobu Mita       2006-12-08 02:39:47 -0800  59) {
f2ad37da80541 (Dmitry Vyukov      2017-05-08 15:56:51 -0700  60) 	return in_task() && task->make_it_fail;
f4f154fd920b2 (Akinobu Mita       2006-12-08 02:39:47 -0800  61) }
f4f154fd920b2 (Akinobu Mita       2006-12-08 02:39:47 -0800  62) 
a124c28ef85d9 (Don Mullis         2006-12-08 02:39:52 -0800  63) #define MAX_STACK_TRACE_DEPTH 32
a124c28ef85d9 (Don Mullis         2006-12-08 02:39:52 -0800  64) 
1df49008f4dde (Akinobu Mita       2007-02-20 13:57:56 -0800  65) #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  66) 
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800  67) static bool fail_stacktrace(struct fault_attr *attr)
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  68) {
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  69) 	int depth = attr->stacktrace_depth;
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  70) 	unsigned long entries[MAX_STACK_TRACE_DEPTH];
30191250c2b3e (Thomas Gleixner    2019-04-25 11:45:04 +0200  71) 	int n, nr_entries;
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  72) 	bool found = (attr->require_start == 0 && attr->require_end == ULONG_MAX);
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  73) 
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  74) 	if (depth == 0)
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  75) 		return found;
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  76) 
30191250c2b3e (Thomas Gleixner    2019-04-25 11:45:04 +0200  77) 	nr_entries = stack_trace_save(entries, depth, 1);
30191250c2b3e (Thomas Gleixner    2019-04-25 11:45:04 +0200  78) 	for (n = 0; n < nr_entries; n++) {
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  79) 		if (attr->reject_start <= entries[n] &&
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  80) 			       entries[n] < attr->reject_end)
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800  81) 			return false;
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  82) 		if (attr->require_start <= entries[n] &&
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  83) 			       entries[n] < attr->require_end)
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800  84) 			found = true;
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  85) 	}
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  86) 	return found;
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  87) }
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  88) 
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  89) #else
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  90) 
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800  91) static inline bool fail_stacktrace(struct fault_attr *attr)
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  92) {
1df49008f4dde (Akinobu Mita       2007-02-20 13:57:56 -0800  93) 	return true;
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  94) }
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  95) 
1df49008f4dde (Akinobu Mita       2007-02-20 13:57:56 -0800  96) #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
329409aeda064 (Akinobu Mita       2006-12-08 02:39:48 -0800  97) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  98) /*
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800  99)  * This code is stolen from failmalloc-1.0
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 100)  * http://www.nongnu.org/failmalloc/
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 101)  */
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 102) 
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800 103) bool should_fail(struct fault_attr *attr, ssize_t size)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 104) {
1203c8e6fb0aa (Akinobu Mita       2017-07-14 14:49:57 -0700 105) 	if (in_task()) {
1203c8e6fb0aa (Akinobu Mita       2017-07-14 14:49:57 -0700 106) 		unsigned int fail_nth = READ_ONCE(current->fail_nth);
1203c8e6fb0aa (Akinobu Mita       2017-07-14 14:49:57 -0700 107) 
9eeb52ae712e7 (Akinobu Mita       2017-08-10 15:23:53 -0700 108) 		if (fail_nth) {
9b4fb5cec031f (Will Deacon        2019-12-19 17:40:21 +0000 109) 			fail_nth--;
9b4fb5cec031f (Will Deacon        2019-12-19 17:40:21 +0000 110) 			WRITE_ONCE(current->fail_nth, fail_nth);
9b4fb5cec031f (Will Deacon        2019-12-19 17:40:21 +0000 111) 			if (!fail_nth)
9eeb52ae712e7 (Akinobu Mita       2017-08-10 15:23:53 -0700 112) 				goto fail;
1203c8e6fb0aa (Akinobu Mita       2017-07-14 14:49:57 -0700 113) 
9eeb52ae712e7 (Akinobu Mita       2017-08-10 15:23:53 -0700 114) 			return false;
9eeb52ae712e7 (Akinobu Mita       2017-08-10 15:23:53 -0700 115) 		}
e41d58185f144 (Dmitry Vyukov      2017-07-12 14:34:35 -0700 116) 	}
e41d58185f144 (Dmitry Vyukov      2017-07-12 14:34:35 -0700 117) 
f39cdaebb89dc (Anton Blanchard    2012-06-20 12:53:03 -0700 118) 	/* No need to check any other properties if the probability is 0 */
f39cdaebb89dc (Anton Blanchard    2012-06-20 12:53:03 -0700 119) 	if (attr->probability == 0)
f39cdaebb89dc (Anton Blanchard    2012-06-20 12:53:03 -0700 120) 		return false;
f39cdaebb89dc (Anton Blanchard    2012-06-20 12:53:03 -0700 121) 
f4f154fd920b2 (Akinobu Mita       2006-12-08 02:39:47 -0800 122) 	if (attr->task_filter && !fail_task(attr, current))
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800 123) 		return false;
f4f154fd920b2 (Akinobu Mita       2006-12-08 02:39:47 -0800 124) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 125) 	if (atomic_read(&attr->times) == 0)
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800 126) 		return false;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 127) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 128) 	if (atomic_read(&attr->space) > size) {
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 129) 		atomic_sub(size, &attr->space);
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800 130) 		return false;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 131) 	}
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 132) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 133) 	if (attr->interval > 1) {
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 134) 		attr->count++;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 135) 		if (attr->count % attr->interval)
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800 136) 			return false;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 137) 	}
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 138) 
f39fee5f11f7a (Akinobu Mita       2013-04-29 16:21:28 -0700 139) 	if (attr->probability <= prandom_u32() % 100)
f1729c28a37e4 (Don Mullis         2006-12-08 02:39:53 -0800 140) 		return false;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 141) 
f1729c28a37e4 (Don Mullis         2006-12-08 02:39:53 -0800 142) 	if (!fail_stacktrace(attr))
f1729c28a37e4 (Don Mullis         2006-12-08 02:39:53 -0800 143) 		return false;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 144) 
e41d58185f144 (Dmitry Vyukov      2017-07-12 14:34:35 -0700 145) fail:
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 146) 	fail_dump(attr);
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 147) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 148) 	if (atomic_read(&attr->times) != -1)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 149) 		atomic_dec_not_zero(&attr->times);
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 150) 
08b3df2d16cbe (Don Mullis         2006-12-08 02:39:51 -0800 151) 	return true;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 152) }
df87ecbf19109 (Per Forlin         2011-08-19 14:52:36 +0200 153) EXPORT_SYMBOL_GPL(should_fail);
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 154) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 155) #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 156) 
8b88b0998e35d (Christoph Hellwig  2008-02-08 04:20:26 -0800 157) static int debugfs_ul_set(void *data, u64 val)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 158) {
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 159) 	*(unsigned long *)data = val;
8b88b0998e35d (Christoph Hellwig  2008-02-08 04:20:26 -0800 160) 	return 0;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 161) }
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 162) 
8b88b0998e35d (Christoph Hellwig  2008-02-08 04:20:26 -0800 163) static int debugfs_ul_get(void *data, u64 *val)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 164) {
8b88b0998e35d (Christoph Hellwig  2008-02-08 04:20:26 -0800 165) 	*val = *(unsigned long *)data;
8b88b0998e35d (Christoph Hellwig  2008-02-08 04:20:26 -0800 166) 	return 0;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 167) }
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 168) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 169) DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n");
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 170) 
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 171) static void debugfs_create_ul(const char *name, umode_t mode,
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 172) 			      struct dentry *parent, unsigned long *value)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 173) {
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 174) 	debugfs_create_file(name, mode, parent, value, &fops_ul);
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 175) }
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 176) 
6ddb23c78aeef (Stephen Rothwell   2007-07-23 18:43:55 -0700 177) #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
a124c28ef85d9 (Don Mullis         2006-12-08 02:39:52 -0800 178) 
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 179) static int debugfs_stacktrace_depth_set(void *data, u64 val)
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 180) {
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 181) 	*(unsigned long *)data =
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 182) 		min_t(unsigned long, val, MAX_STACK_TRACE_DEPTH);
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 183) 
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 184) 	return 0;
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 185) }
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 186) 
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 187) DEFINE_SIMPLE_ATTRIBUTE(fops_stacktrace_depth, debugfs_ul_get,
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 188) 			debugfs_stacktrace_depth_set, "%llu\n");
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 189) 
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 190) static void debugfs_create_stacktrace_depth(const char *name, umode_t mode,
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 191) 					    struct dentry *parent,
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 192) 					    unsigned long *value)
a124c28ef85d9 (Don Mullis         2006-12-08 02:39:52 -0800 193) {
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 194) 	debugfs_create_file(name, mode, parent, value, &fops_stacktrace_depth);
a124c28ef85d9 (Don Mullis         2006-12-08 02:39:52 -0800 195) }
8307fc257cf39 (Akinobu Mita       2011-07-26 16:09:01 -0700 196) 
6ddb23c78aeef (Stephen Rothwell   2007-07-23 18:43:55 -0700 197) #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
a124c28ef85d9 (Don Mullis         2006-12-08 02:39:52 -0800 198) 
dd48c085c1cdf (Akinobu Mita       2011-08-03 16:21:01 -0700 199) struct dentry *fault_create_debugfs_attr(const char *name,
dd48c085c1cdf (Akinobu Mita       2011-08-03 16:21:01 -0700 200) 			struct dentry *parent, struct fault_attr *attr)
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 201) {
f4ae40a6a50a9 (Al Viro            2011-07-24 04:33:43 -0400 202) 	umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 203) 	struct dentry *dir;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 204) 
dd48c085c1cdf (Akinobu Mita       2011-08-03 16:21:01 -0700 205) 	dir = debugfs_create_dir(name, parent);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 206) 	if (IS_ERR(dir))
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 207) 		return dir;
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 208) 
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 209) 	debugfs_create_ul("probability", mode, dir, &attr->probability);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 210) 	debugfs_create_ul("interval", mode, dir, &attr->interval);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 211) 	debugfs_create_atomic_t("times", mode, dir, &attr->times);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 212) 	debugfs_create_atomic_t("space", mode, dir, &attr->space);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 213) 	debugfs_create_ul("verbose", mode, dir, &attr->verbose);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 214) 	debugfs_create_u32("verbose_ratelimit_interval_ms", mode, dir,
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 215) 			   &attr->ratelimit_state.interval);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 216) 	debugfs_create_u32("verbose_ratelimit_burst", mode, dir,
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 217) 			   &attr->ratelimit_state.burst);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 218) 	debugfs_create_bool("task-filter", mode, dir, &attr->task_filter);
1df49008f4dde (Akinobu Mita       2007-02-20 13:57:56 -0800 219) 
1df49008f4dde (Akinobu Mita       2007-02-20 13:57:56 -0800 220) #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 221) 	debugfs_create_stacktrace_depth("stacktrace-depth", mode, dir,
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 222) 					&attr->stacktrace_depth);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 223) 	debugfs_create_ul("require-start", mode, dir, &attr->require_start);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 224) 	debugfs_create_ul("require-end", mode, dir, &attr->require_end);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 225) 	debugfs_create_ul("reject-start", mode, dir, &attr->reject_start);
053cf51040ed0 (Greg Kroah-Hartman 2019-06-12 11:58:28 +0200 226) 	debugfs_create_ul("reject-end", mode, dir, &attr->reject_end);
1df49008f4dde (Akinobu Mita       2007-02-20 13:57:56 -0800 227) #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
1df49008f4dde (Akinobu Mita       2007-02-20 13:57:56 -0800 228) 
6adc4a22f20bb (Dmitry Monakhov    2014-12-12 16:58:00 -0800 229) 	attr->dname = dget(dir);
dd48c085c1cdf (Akinobu Mita       2011-08-03 16:21:01 -0700 230) 	return dir;
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 231) }
df87ecbf19109 (Per Forlin         2011-08-19 14:52:36 +0200 232) EXPORT_SYMBOL_GPL(fault_create_debugfs_attr);
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 233) 
6ff1cb355e628 (Akinobu Mita       2006-12-08 02:39:43 -0800 234) #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */