fault-injection.txt 5.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Fault injection capabilities infrastructure
===========================================

See also drivers/md/faulty.c and "every_nth" module option for scsi_debug.


Available fault injection capabilities
--------------------------------------

o failslab

  injects slab allocation failures. (kmalloc(), kmem_cache_alloc(), ...)

o fail_page_alloc

  injects page allocation failures. (alloc_pages(), get_free_pages(), ...)

o fail_make_request

20
  injects disk IO errors on devices permitted by setting
21 22 23 24 25 26 27 28 29 30 31
  /sys/block/<device>/make-it-fail or
  /sys/block/<device>/<partition>/make-it-fail. (generic_make_request())

Configure fault-injection capabilities behavior
-----------------------------------------------

o debugfs entries

fault-inject-debugfs kernel module provides some debugfs entries for runtime
configuration of fault-injection capabilities.

32
- /debug/fail*/probability:
33 34 35 36

	likelihood of failure injection, in percent.
	Format: <percent>

37 38 39
	Note that one-failure-per-hundred is a very high error rate
	for some testcases.  Consider setting probability=100 and configure
	/debug/fail*/interval for such testcases.
40

41
- /debug/fail*/interval:
42 43 44 45 46 47 48

	specifies the interval between failures, for calls to
	should_fail() that pass all the other tests.

	Note that if you enable this, by setting interval>1, you will
	probably want to set probability=100.

49
- /debug/fail*/times:
50 51 52 53

	specifies how many times failures may happen at most.
	A value of -1 means "no limit".

54
- /debug/fail*/space:
55 56 57 58 59

	specifies an initial resource "budget", decremented by "size"
	on each call to should_fail(,size).  Failure injection is
	suppressed until "space" reaches zero.

60
- /debug/fail*/verbose
61 62

	Format: { 0 | 1 | 2 }
63 64 65 66
	specifies the verbosity of the messages when failure is
	injected.  '0' means no messages; '1' will print only a single
	log line per failure; '2' will print a call trace too -- useful
	to debug the problems revealed by fault injection.
67

68
- /debug/fail*/task-filter:
69

70 71
	Format: { 'Y' | 'N' }
	A value of 'N' disables filtering by process (default).
72 73 74
	Any positive value limits failures to only processes indicated by
	/proc/<pid>/make-it-fail==1.

75 76 77 78
- /debug/fail*/require-start:
- /debug/fail*/require-end:
- /debug/fail*/reject-start:
- /debug/fail*/reject-end:
79 80 81

	specifies the range of virtual addresses tested during
	stacktrace walking.  Failure is injected only if some caller
82 83 84 85
	in the walked stacktrace lies within the required range, and
	none lies within the rejected range.
	Default required range is [0,ULONG_MAX) (whole of virtual address space).
	Default rejected range is [0,0).
86

87
- /debug/fail*/stacktrace-depth:
88 89

	specifies the maximum stacktrace depth walked during search
90 91
	for a caller within [require-start,require-end) OR
	[reject-start,reject-end).
92 93 94

- /debug/fail_page_alloc/ignore-gfp-highmem:

95 96
	Format: { 'Y' | 'N' }
	default is 'N', setting it to 'Y' won't inject failures into
97 98 99 100 101
	highmem/user allocations.

- /debug/failslab/ignore-gfp-wait:
- /debug/fail_page_alloc/ignore-gfp-wait:

102 103
	Format: { 'Y' | 'N' }
	default is 'N', setting it to 'Y' will inject failures
104 105
	only into non-sleep allocations (GFP_ATOMIC allocations).

106 107 108 109 110
- /debug/fail_page_alloc/min-order:

	specifies the minimum page allocation order to be injected
	failures.

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
o Boot option

In order to inject faults while debugfs is not available (early boot time),
use the boot option:

	failslab=
	fail_page_alloc=
	fail_make_request=<interval>,<probability>,<space>,<times>

How to add new fault injection capability
-----------------------------------------

o #include <linux/fault-inject.h>

o define the fault attributes

  DECLARE_FAULT_INJECTION(name);

  Please see the definition of struct fault_attr in fault-inject.h
  for details.

132
o provide a way to configure fault attributes
133 134 135 136

- boot option

  If you need to enable the fault injection capability from boot time, you can
137
  provide boot option to configure it. There is a helper function for it:
138

139
	setup_fault_attr(attr, str);
140 141 142 143

- debugfs entries

  failslab, fail_page_alloc, and fail_make_request use this way.
144
  Helper functions:
145

146 147
	init_fault_attr_entries(entries, attr, name);
	void cleanup_fault_attr_entries(entries);
148 149 150 151 152 153 154 155 156

- module parameters

  If the scope of the fault injection capability is limited to a
  single kernel module, it is better to provide module parameters to
  configure the fault attributes.

o add a hook to insert failures

157
  Upon should_fail() returning true, client code should inject a failure.
158

159
	should_fail(attr, size);
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

Application Examples
--------------------

o inject slab allocation failures into module init/cleanup code

------------------------------------------------------------------------------
#!/bin/bash

FAILCMD=Documentation/fault-injection/failcmd.sh
BLACKLIST="root_plug evbug"

FAILNAME=failslab
echo Y > /debug/$FAILNAME/task-filter
echo 10 > /debug/$FAILNAME/probability
echo 100 > /debug/$FAILNAME/interval
echo -1 > /debug/$FAILNAME/times
echo 2 > /debug/$FAILNAME/verbose
echo 1 > /debug/$FAILNAME/ignore-gfp-wait

blacklist()
{
	echo $BLACKLIST | grep $1 > /dev/null 2>&1
}

oops()
{
	dmesg | grep BUG > /dev/null 2>&1
}

find /lib/modules/`uname -r` -name '*.ko' -exec basename {} .ko \; |
	while read i
	do
		oops && exit 1

		if ! blacklist $i
		then
			echo inserting $i...
			bash $FAILCMD modprobe $i
		fi
	done

lsmod | awk '{ if ($3 == 0) { print $1 } }' |
	while read i
	do
		oops && exit 1

		if ! blacklist $i
		then
			echo removing $i...
			bash $FAILCMD modprobe -r $i
		fi
	done

------------------------------------------------------------------------------

o inject slab allocation failures only for a specific module

------------------------------------------------------------------------------
#!/bin/bash

FAILMOD=Documentation/fault-injection/failmodule.sh

echo injecting errors into the module $1...

modprobe $1
bash $FAILMOD failslab $1 10
echo 25 > /debug/failslab/probability

------------------------------------------------------------------------------