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