Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 1 | =========================================== |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 2 | Fault injection capabilities infrastructure |
| 3 | =========================================== |
| 4 | |
Masanari Iida | 1892ce4 | 2017-12-23 01:41:21 +0900 | [diff] [blame] | 5 | See also drivers/md/md-faulty.c and "every_nth" module option for scsi_debug. |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 6 | |
| 7 | |
| 8 | Available fault injection capabilities |
| 9 | -------------------------------------- |
| 10 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 11 | - failslab |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 12 | |
| 13 | injects slab allocation failures. (kmalloc(), kmem_cache_alloc(), ...) |
| 14 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 15 | - fail_page_alloc |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 16 | |
| 17 | injects page allocation failures. (alloc_pages(), get_free_pages(), ...) |
| 18 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 19 | - fail_futex |
Davidlohr Bueso | ab51fba | 2015-06-29 23:26:02 -0700 | [diff] [blame] | 20 | |
| 21 | injects futex deadlock and uaddr fault errors. |
| 22 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 23 | - fail_make_request |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 24 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 25 | injects disk IO errors on devices permitted by setting |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 26 | /sys/block/<device>/make-it-fail or |
Christoph Hellwig | ed00aab | 2020-07-01 10:59:44 +0200 | [diff] [blame] | 27 | /sys/block/<device>/<partition>/make-it-fail. (submit_bio_noacct()) |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 28 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 29 | - fail_mmc_request |
Per Forlin | 1e4cb22 | 2011-08-19 14:52:38 +0200 | [diff] [blame] | 30 | |
| 31 | injects MMC data errors on devices permitted by setting |
| 32 | debugfs entries under /sys/kernel/debug/mmc0/fail_mmc_request |
| 33 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 34 | - fail_function |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 35 | |
| 36 | injects error return on specific functions, which are marked by |
| 37 | ALLOW_ERROR_INJECTION() macro, by setting debugfs entries |
| 38 | under /sys/kernel/debug/fail_function. No boot option supported. |
| 39 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 40 | - NVMe fault injection |
Thomas Tai | cf4182f | 2018-02-08 13:38:30 -0500 | [diff] [blame] | 41 | |
| 42 | inject NVMe status code and retry flag on devices permitted by setting |
| 43 | debugfs entries under /sys/kernel/debug/nvme*/fault_inject. The default |
| 44 | status code is NVME_SC_INVALID_OPCODE with no retry. The status code and |
| 45 | retry flag can be set via the debugfs. |
| 46 | |
| 47 | |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 48 | Configure fault-injection capabilities behavior |
| 49 | ----------------------------------------------- |
| 50 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 51 | debugfs entries |
| 52 | ^^^^^^^^^^^^^^^ |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 53 | |
| 54 | fault-inject-debugfs kernel module provides some debugfs entries for runtime |
| 55 | configuration of fault-injection capabilities. |
| 56 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 57 | - /sys/kernel/debug/fail*/probability: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 58 | |
| 59 | likelihood of failure injection, in percent. |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 60 | |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 61 | Format: <percent> |
| 62 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 63 | Note that one-failure-per-hundred is a very high error rate |
| 64 | for some testcases. Consider setting probability=100 and configure |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 65 | /sys/kernel/debug/fail*/interval for such testcases. |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 66 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 67 | - /sys/kernel/debug/fail*/interval: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 68 | |
| 69 | specifies the interval between failures, for calls to |
| 70 | should_fail() that pass all the other tests. |
| 71 | |
| 72 | Note that if you enable this, by setting interval>1, you will |
| 73 | probably want to set probability=100. |
| 74 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 75 | - /sys/kernel/debug/fail*/times: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 76 | |
| 77 | specifies how many times failures may happen at most. |
| 78 | A value of -1 means "no limit". |
| 79 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 80 | - /sys/kernel/debug/fail*/space: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 81 | |
| 82 | specifies an initial resource "budget", decremented by "size" |
| 83 | on each call to should_fail(,size). Failure injection is |
| 84 | suppressed until "space" reaches zero. |
| 85 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 86 | - /sys/kernel/debug/fail*/verbose |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 87 | |
| 88 | Format: { 0 | 1 | 2 } |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 89 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 90 | specifies the verbosity of the messages when failure is |
| 91 | injected. '0' means no messages; '1' will print only a single |
| 92 | log line per failure; '2' will print a call trace too -- useful |
| 93 | to debug the problems revealed by fault injection. |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 94 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 95 | - /sys/kernel/debug/fail*/task-filter: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 96 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 97 | Format: { 'Y' | 'N' } |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 98 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 99 | A value of 'N' disables filtering by process (default). |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 100 | Any positive value limits failures to only processes indicated by |
| 101 | /proc/<pid>/make-it-fail==1. |
| 102 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 103 | - /sys/kernel/debug/fail*/require-start, |
| 104 | /sys/kernel/debug/fail*/require-end, |
| 105 | /sys/kernel/debug/fail*/reject-start, |
| 106 | /sys/kernel/debug/fail*/reject-end: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 107 | |
| 108 | specifies the range of virtual addresses tested during |
| 109 | stacktrace walking. Failure is injected only if some caller |
Akinobu Mita | 329409a | 2006-12-08 02:39:48 -0800 | [diff] [blame] | 110 | in the walked stacktrace lies within the required range, and |
| 111 | none lies within the rejected range. |
| 112 | Default required range is [0,ULONG_MAX) (whole of virtual address space). |
| 113 | Default rejected range is [0,0). |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 114 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 115 | - /sys/kernel/debug/fail*/stacktrace-depth: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 116 | |
| 117 | specifies the maximum stacktrace depth walked during search |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 118 | for a caller within [require-start,require-end) OR |
| 119 | [reject-start,reject-end). |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 120 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 121 | - /sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 122 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 123 | Format: { 'Y' | 'N' } |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 124 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 125 | default is 'N', setting it to 'Y' won't inject failures into |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 126 | highmem/user allocations. |
| 127 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 128 | - /sys/kernel/debug/failslab/ignore-gfp-wait: |
| 129 | - /sys/kernel/debug/fail_page_alloc/ignore-gfp-wait: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 130 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 131 | Format: { 'Y' | 'N' } |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 132 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 133 | default is 'N', setting it to 'Y' will inject failures |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 134 | only into non-sleep allocations (GFP_ATOMIC allocations). |
| 135 | |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 136 | - /sys/kernel/debug/fail_page_alloc/min-order: |
Akinobu Mita | 5411499 | 2007-07-15 23:40:23 -0700 | [diff] [blame] | 137 | |
| 138 | specifies the minimum page allocation order to be injected |
| 139 | failures. |
| 140 | |
Davidlohr Bueso | ab51fba | 2015-06-29 23:26:02 -0700 | [diff] [blame] | 141 | - /sys/kernel/debug/fail_futex/ignore-private: |
| 142 | |
| 143 | Format: { 'Y' | 'N' } |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 144 | |
Davidlohr Bueso | ab51fba | 2015-06-29 23:26:02 -0700 | [diff] [blame] | 145 | default is 'N', setting it to 'Y' will disable failure injections |
| 146 | when dealing with private (address space) futexes. |
| 147 | |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 148 | - /sys/kernel/debug/fail_function/inject: |
| 149 | |
| 150 | Format: { 'function-name' | '!function-name' | '' } |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 151 | |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 152 | specifies the target function of error injection by name. |
| 153 | If the function name leads '!' prefix, given function is |
| 154 | removed from injection list. If nothing specified ('') |
| 155 | injection list is cleared. |
| 156 | |
| 157 | - /sys/kernel/debug/fail_function/injectable: |
| 158 | |
| 159 | (read only) shows error injectable functions and what type of |
| 160 | error values can be specified. The error type will be one of |
| 161 | below; |
| 162 | - NULL: retval must be 0. |
| 163 | - ERRNO: retval must be -1 to -MAX_ERRNO (-4096). |
| 164 | - ERR_NULL: retval must be 0 or -1 to -MAX_ERRNO (-4096). |
| 165 | |
| 166 | - /sys/kernel/debug/fail_function/<functiuon-name>/retval: |
| 167 | |
| 168 | specifies the "error" return value to inject to the given |
| 169 | function for given function. This will be created when |
| 170 | user specifies new injection entry. |
| 171 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 172 | Boot option |
| 173 | ^^^^^^^^^^^ |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 174 | |
| 175 | In order to inject faults while debugfs is not available (early boot time), |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 176 | use the boot option:: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 177 | |
| 178 | failslab= |
| 179 | fail_page_alloc= |
Per Forlin | 1e4cb22 | 2011-08-19 14:52:38 +0200 | [diff] [blame] | 180 | fail_make_request= |
Davidlohr Bueso | ab51fba | 2015-06-29 23:26:02 -0700 | [diff] [blame] | 181 | fail_futex= |
Per Forlin | 199e3f4 | 2011-09-13 23:03:30 +0200 | [diff] [blame] | 182 | mmc_core.fail_request=<interval>,<probability>,<space>,<times> |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 183 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 184 | proc entries |
| 185 | ^^^^^^^^^^^^ |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 186 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 187 | - /proc/<pid>/fail-nth, |
| 188 | /proc/self/task/<tid>/fail-nth: |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 189 | |
Akinobu Mita | 9049f2f | 2017-07-14 14:49:52 -0700 | [diff] [blame] | 190 | Write to this file of integer N makes N-th call in the task fail. |
Akinobu Mita | bfc7409 | 2017-07-14 14:49:54 -0700 | [diff] [blame] | 191 | Read from this file returns a integer value. A value of '0' indicates |
| 192 | that the fault setup with a previous write to this file was injected. |
| 193 | A positive integer N indicates that the fault wasn't yet injected. |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 194 | Note that this file enables all types of faults (slab, futex, etc). |
| 195 | This setting takes precedence over all other generic debugfs settings |
| 196 | like probability, interval, times, etc. But per-capability settings |
| 197 | (e.g. fail_futex/ignore-private) take precedence over it. |
| 198 | |
| 199 | This feature is intended for systematic testing of faults in a single |
| 200 | system call. See an example below. |
| 201 | |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 202 | How to add new fault injection capability |
| 203 | ----------------------------------------- |
| 204 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 205 | - #include <linux/fault-inject.h> |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 206 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 207 | - define the fault attributes |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 208 | |
Laurent Gauthier | 2d87948 | 2019-01-05 00:08:34 +0100 | [diff] [blame] | 209 | DECLARE_FAULT_ATTR(name); |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 210 | |
| 211 | Please see the definition of struct fault_attr in fault-inject.h |
| 212 | for details. |
| 213 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 214 | - provide a way to configure fault attributes |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 215 | |
| 216 | - boot option |
| 217 | |
| 218 | If you need to enable the fault injection capability from boot time, you can |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 219 | provide boot option to configure it. There is a helper function for it: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 220 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 221 | setup_fault_attr(attr, str); |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 222 | |
| 223 | - debugfs entries |
| 224 | |
| 225 | failslab, fail_page_alloc, and fail_make_request use this way. |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 226 | Helper functions: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 227 | |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 228 | fault_create_debugfs_attr(name, parent, attr); |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 229 | |
| 230 | - module parameters |
| 231 | |
| 232 | If the scope of the fault injection capability is limited to a |
| 233 | single kernel module, it is better to provide module parameters to |
| 234 | configure the fault attributes. |
| 235 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 236 | - add a hook to insert failures |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 237 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 238 | Upon should_fail() returning true, client code should inject a failure: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 239 | |
Don Mullis | 5d0ffa2 | 2006-12-08 02:39:50 -0800 | [diff] [blame] | 240 | should_fail(attr, size); |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 241 | |
| 242 | Application Examples |
| 243 | -------------------- |
| 244 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 245 | - Inject slab allocation failures into module init/exit code:: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 246 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 247 | #!/bin/bash |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 248 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 249 | FAILTYPE=failslab |
| 250 | echo Y > /sys/kernel/debug/$FAILTYPE/task-filter |
| 251 | echo 10 > /sys/kernel/debug/$FAILTYPE/probability |
| 252 | echo 100 > /sys/kernel/debug/$FAILTYPE/interval |
| 253 | echo -1 > /sys/kernel/debug/$FAILTYPE/times |
| 254 | echo 0 > /sys/kernel/debug/$FAILTYPE/space |
| 255 | echo 2 > /sys/kernel/debug/$FAILTYPE/verbose |
| 256 | echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 257 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 258 | faulty_system() |
| 259 | { |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 260 | bash -c "echo 1 > /proc/self/make-it-fail && exec $*" |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 261 | } |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 262 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 263 | if [ $# -eq 0 ] |
| 264 | then |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 265 | echo "Usage: $0 modulename [ modulename ... ]" |
| 266 | exit 1 |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 267 | fi |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 268 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 269 | for m in $* |
| 270 | do |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 271 | echo inserting $m... |
| 272 | faulty_system modprobe $m |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 273 | |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 274 | echo removing $m... |
| 275 | faulty_system modprobe -r $m |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 276 | done |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 277 | |
| 278 | ------------------------------------------------------------------------------ |
| 279 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 280 | - Inject page allocation failures only for a specific module:: |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 281 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 282 | #!/bin/bash |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 283 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 284 | FAILTYPE=fail_page_alloc |
| 285 | module=$1 |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 286 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 287 | if [ -z $module ] |
| 288 | then |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 289 | echo "Usage: $0 <modulename>" |
| 290 | exit 1 |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 291 | fi |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 292 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 293 | modprobe $module |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 294 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 295 | if [ ! -d /sys/module/$module/sections ] |
| 296 | then |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 297 | echo Module $module is not loaded |
| 298 | exit 1 |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 299 | fi |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 300 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 301 | cat /sys/module/$module/sections/.text > /sys/kernel/debug/$FAILTYPE/require-start |
| 302 | cat /sys/module/$module/sections/.data > /sys/kernel/debug/$FAILTYPE/require-end |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 303 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 304 | echo N > /sys/kernel/debug/$FAILTYPE/task-filter |
| 305 | echo 10 > /sys/kernel/debug/$FAILTYPE/probability |
| 306 | echo 100 > /sys/kernel/debug/$FAILTYPE/interval |
| 307 | echo -1 > /sys/kernel/debug/$FAILTYPE/times |
| 308 | echo 0 > /sys/kernel/debug/$FAILTYPE/space |
| 309 | echo 2 > /sys/kernel/debug/$FAILTYPE/verbose |
| 310 | echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait |
| 311 | echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-highmem |
| 312 | echo 10 > /sys/kernel/debug/$FAILTYPE/stacktrace-depth |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 313 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 314 | trap "echo 0 > /sys/kernel/debug/$FAILTYPE/probability" SIGINT SIGTERM EXIT |
Akinobu Mita | 1858487 | 2007-07-15 23:40:24 -0700 | [diff] [blame] | 315 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 316 | echo "Injecting errors into the module $module... (interrupt to stop)" |
| 317 | sleep 1000000 |
Akinobu Mita | de1ba09 | 2006-12-08 02:39:42 -0800 | [diff] [blame] | 318 | |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 319 | ------------------------------------------------------------------------------ |
| 320 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 321 | - Inject open_ctree error while btrfs mount:: |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 322 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 323 | #!/bin/bash |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 324 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 325 | rm -f testfile.img |
| 326 | dd if=/dev/zero of=testfile.img bs=1M seek=1000 count=1 |
| 327 | DEVICE=$(losetup --show -f testfile.img) |
| 328 | mkfs.btrfs -f $DEVICE |
| 329 | mkdir -p tmpmnt |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 330 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 331 | FAILTYPE=fail_function |
| 332 | FAILFUNC=open_ctree |
| 333 | echo $FAILFUNC > /sys/kernel/debug/$FAILTYPE/inject |
| 334 | echo -12 > /sys/kernel/debug/$FAILTYPE/$FAILFUNC/retval |
| 335 | echo N > /sys/kernel/debug/$FAILTYPE/task-filter |
| 336 | echo 100 > /sys/kernel/debug/$FAILTYPE/probability |
| 337 | echo 0 > /sys/kernel/debug/$FAILTYPE/interval |
| 338 | echo -1 > /sys/kernel/debug/$FAILTYPE/times |
| 339 | echo 0 > /sys/kernel/debug/$FAILTYPE/space |
| 340 | echo 1 > /sys/kernel/debug/$FAILTYPE/verbose |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 341 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 342 | mount -t btrfs $DEVICE tmpmnt |
| 343 | if [ $? -ne 0 ] |
| 344 | then |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 345 | echo "SUCCESS!" |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 346 | else |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 347 | echo "FAILED!" |
| 348 | umount tmpmnt |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 349 | fi |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 350 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 351 | echo > /sys/kernel/debug/$FAILTYPE/inject |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 352 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 353 | rmdir tmpmnt |
| 354 | losetup -d $DEVICE |
| 355 | rm testfile.img |
Masami Hiramatsu | 4b1a29a | 2018-01-13 02:56:03 +0900 | [diff] [blame] | 356 | |
| 357 | |
Akinobu Mita | c24aa64 | 2012-07-30 14:43:20 -0700 | [diff] [blame] | 358 | Tool to run command with failslab or fail_page_alloc |
| 359 | ---------------------------------------------------- |
| 360 | In order to make it easier to accomplish the tasks mentioned above, we can use |
| 361 | tools/testing/fault-injection/failcmd.sh. Please run a command |
| 362 | "./tools/testing/fault-injection/failcmd.sh --help" for more information and |
| 363 | see the following examples. |
| 364 | |
| 365 | Examples: |
| 366 | |
| 367 | Run a command "make -C tools/testing/selftests/ run_tests" with injecting slab |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 368 | allocation failure:: |
Akinobu Mita | c24aa64 | 2012-07-30 14:43:20 -0700 | [diff] [blame] | 369 | |
| 370 | # ./tools/testing/fault-injection/failcmd.sh \ |
| 371 | -- make -C tools/testing/selftests/ run_tests |
| 372 | |
| 373 | Same as above except to specify 100 times failures at most instead of one time |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 374 | at most by default:: |
Akinobu Mita | c24aa64 | 2012-07-30 14:43:20 -0700 | [diff] [blame] | 375 | |
| 376 | # ./tools/testing/fault-injection/failcmd.sh --times=100 \ |
| 377 | -- make -C tools/testing/selftests/ run_tests |
| 378 | |
| 379 | Same as above except to inject page allocation failure instead of slab |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 380 | allocation failure:: |
Akinobu Mita | c24aa64 | 2012-07-30 14:43:20 -0700 | [diff] [blame] | 381 | |
| 382 | # env FAILCMD_TYPE=fail_page_alloc \ |
| 383 | ./tools/testing/fault-injection/failcmd.sh --times=100 \ |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 384 | -- make -C tools/testing/selftests/ run_tests |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 385 | |
| 386 | Systematic faults using fail-nth |
| 387 | --------------------------------- |
| 388 | |
| 389 | The following code systematically faults 0-th, 1-st, 2-nd and so on |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 390 | capabilities in the socketpair() system call:: |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 391 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 392 | #include <sys/types.h> |
| 393 | #include <sys/stat.h> |
| 394 | #include <sys/socket.h> |
| 395 | #include <sys/syscall.h> |
| 396 | #include <fcntl.h> |
| 397 | #include <unistd.h> |
| 398 | #include <string.h> |
| 399 | #include <stdlib.h> |
| 400 | #include <stdio.h> |
| 401 | #include <errno.h> |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 402 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 403 | int main() |
| 404 | { |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 405 | int i, err, res, fail_nth, fds[2]; |
| 406 | char buf[128]; |
| 407 | |
| 408 | system("echo N > /sys/kernel/debug/failslab/ignore-gfp-wait"); |
| 409 | sprintf(buf, "/proc/self/task/%ld/fail-nth", syscall(SYS_gettid)); |
| 410 | fail_nth = open(buf, O_RDWR); |
Akinobu Mita | 9049f2f | 2017-07-14 14:49:52 -0700 | [diff] [blame] | 411 | for (i = 1;; i++) { |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 412 | sprintf(buf, "%d", i); |
| 413 | write(fail_nth, buf, strlen(buf)); |
| 414 | res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds); |
| 415 | err = errno; |
Akinobu Mita | bfc7409 | 2017-07-14 14:49:54 -0700 | [diff] [blame] | 416 | pread(fail_nth, buf, sizeof(buf), 0); |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 417 | if (res == 0) { |
| 418 | close(fds[0]); |
| 419 | close(fds[1]); |
| 420 | } |
Akinobu Mita | bfc7409 | 2017-07-14 14:49:54 -0700 | [diff] [blame] | 421 | printf("%d-th fault %c: res=%d/%d\n", i, atoi(buf) ? 'N' : 'Y', |
| 422 | res, err); |
| 423 | if (atoi(buf)) |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 424 | break; |
| 425 | } |
| 426 | return 0; |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 427 | } |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 428 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 429 | An example output:: |
Dmitry Vyukov | e41d5818 | 2017-07-12 14:34:35 -0700 | [diff] [blame] | 430 | |
Mauro Carvalho Chehab | 10ffebb | 2019-06-12 14:52:44 -0300 | [diff] [blame] | 431 | 1-th fault Y: res=-1/23 |
| 432 | 2-th fault Y: res=-1/23 |
| 433 | 3-th fault Y: res=-1/12 |
| 434 | 4-th fault Y: res=-1/12 |
| 435 | 5-th fault Y: res=-1/23 |
| 436 | 6-th fault Y: res=-1/23 |
| 437 | 7-th fault Y: res=-1/23 |
| 438 | 8-th fault Y: res=-1/12 |
| 439 | 9-th fault Y: res=-1/12 |
| 440 | 10-th fault Y: res=-1/12 |
| 441 | 11-th fault Y: res=-1/12 |
| 442 | 12-th fault Y: res=-1/12 |
| 443 | 13-th fault Y: res=-1/12 |
| 444 | 14-th fault Y: res=-1/12 |
| 445 | 15-th fault Y: res=-1/12 |
| 446 | 16-th fault N: res=0/12 |