110ffebbeSMauro Carvalho Chehab=========================================== 210ffebbeSMauro Carvalho ChehabFault injection capabilities infrastructure 310ffebbeSMauro Carvalho Chehab=========================================== 410ffebbeSMauro Carvalho Chehab 510ffebbeSMauro Carvalho ChehabSee also drivers/md/md-faulty.c and "every_nth" module option for scsi_debug. 610ffebbeSMauro Carvalho Chehab 710ffebbeSMauro Carvalho Chehab 810ffebbeSMauro Carvalho ChehabAvailable fault injection capabilities 910ffebbeSMauro Carvalho Chehab-------------------------------------- 1010ffebbeSMauro Carvalho Chehab 1110ffebbeSMauro Carvalho Chehab- failslab 1210ffebbeSMauro Carvalho Chehab 1310ffebbeSMauro Carvalho Chehab injects slab allocation failures. (kmalloc(), kmem_cache_alloc(), ...) 1410ffebbeSMauro Carvalho Chehab 1510ffebbeSMauro Carvalho Chehab- fail_page_alloc 1610ffebbeSMauro Carvalho Chehab 1710ffebbeSMauro Carvalho Chehab injects page allocation failures. (alloc_pages(), get_free_pages(), ...) 1810ffebbeSMauro Carvalho Chehab 192c739cedSAlbert van der Linde- fail_usercopy 202c739cedSAlbert van der Linde 212c739cedSAlbert van der Linde injects failures in user memory access functions. (copy_from_user(), get_user(), ...) 222c739cedSAlbert van der Linde 2310ffebbeSMauro Carvalho Chehab- fail_futex 2410ffebbeSMauro Carvalho Chehab 2510ffebbeSMauro Carvalho Chehab injects futex deadlock and uaddr fault errors. 2610ffebbeSMauro Carvalho Chehab 2710ffebbeSMauro Carvalho Chehab- fail_make_request 2810ffebbeSMauro Carvalho Chehab 2910ffebbeSMauro Carvalho Chehab injects disk IO errors on devices permitted by setting 3010ffebbeSMauro Carvalho Chehab /sys/block/<device>/make-it-fail or 31ed00aabdSChristoph Hellwig /sys/block/<device>/<partition>/make-it-fail. (submit_bio_noacct()) 3210ffebbeSMauro Carvalho Chehab 3310ffebbeSMauro Carvalho Chehab- fail_mmc_request 3410ffebbeSMauro Carvalho Chehab 3510ffebbeSMauro Carvalho Chehab injects MMC data errors on devices permitted by setting 3610ffebbeSMauro Carvalho Chehab debugfs entries under /sys/kernel/debug/mmc0/fail_mmc_request 3710ffebbeSMauro Carvalho Chehab 3810ffebbeSMauro Carvalho Chehab- fail_function 3910ffebbeSMauro Carvalho Chehab 4010ffebbeSMauro Carvalho Chehab injects error return on specific functions, which are marked by 4110ffebbeSMauro Carvalho Chehab ALLOW_ERROR_INJECTION() macro, by setting debugfs entries 4210ffebbeSMauro Carvalho Chehab under /sys/kernel/debug/fail_function. No boot option supported. 4310ffebbeSMauro Carvalho Chehab 4410ffebbeSMauro Carvalho Chehab- NVMe fault injection 4510ffebbeSMauro Carvalho Chehab 4610ffebbeSMauro Carvalho Chehab inject NVMe status code and retry flag on devices permitted by setting 4710ffebbeSMauro Carvalho Chehab debugfs entries under /sys/kernel/debug/nvme*/fault_inject. The default 4810ffebbeSMauro Carvalho Chehab status code is NVME_SC_INVALID_OPCODE with no retry. The status code and 4910ffebbeSMauro Carvalho Chehab retry flag can be set via the debugfs. 5010ffebbeSMauro Carvalho Chehab 5110ffebbeSMauro Carvalho Chehab 5210ffebbeSMauro Carvalho ChehabConfigure fault-injection capabilities behavior 5310ffebbeSMauro Carvalho Chehab----------------------------------------------- 5410ffebbeSMauro Carvalho Chehab 5510ffebbeSMauro Carvalho Chehabdebugfs entries 5610ffebbeSMauro Carvalho Chehab^^^^^^^^^^^^^^^ 5710ffebbeSMauro Carvalho Chehab 5810ffebbeSMauro Carvalho Chehabfault-inject-debugfs kernel module provides some debugfs entries for runtime 5910ffebbeSMauro Carvalho Chehabconfiguration of fault-injection capabilities. 6010ffebbeSMauro Carvalho Chehab 6110ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail*/probability: 6210ffebbeSMauro Carvalho Chehab 6310ffebbeSMauro Carvalho Chehab likelihood of failure injection, in percent. 6410ffebbeSMauro Carvalho Chehab 6510ffebbeSMauro Carvalho Chehab Format: <percent> 6610ffebbeSMauro Carvalho Chehab 6710ffebbeSMauro Carvalho Chehab Note that one-failure-per-hundred is a very high error rate 6810ffebbeSMauro Carvalho Chehab for some testcases. Consider setting probability=100 and configure 6910ffebbeSMauro Carvalho Chehab /sys/kernel/debug/fail*/interval for such testcases. 7010ffebbeSMauro Carvalho Chehab 7110ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail*/interval: 7210ffebbeSMauro Carvalho Chehab 7310ffebbeSMauro Carvalho Chehab specifies the interval between failures, for calls to 7410ffebbeSMauro Carvalho Chehab should_fail() that pass all the other tests. 7510ffebbeSMauro Carvalho Chehab 7610ffebbeSMauro Carvalho Chehab Note that if you enable this, by setting interval>1, you will 7710ffebbeSMauro Carvalho Chehab probably want to set probability=100. 7810ffebbeSMauro Carvalho Chehab 7910ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail*/times: 8010ffebbeSMauro Carvalho Chehab 81*00574752SWolfram Sang specifies how many times failures may happen at most. A value of -1 82*00574752SWolfram Sang means "no limit". Note, though, that this file only accepts unsigned 83*00574752SWolfram Sang values. So, if you want to specify -1, you better use 'printf' instead 84*00574752SWolfram Sang of 'echo', e.g.: $ printf %#x -1 > times 8510ffebbeSMauro Carvalho Chehab 8610ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail*/space: 8710ffebbeSMauro Carvalho Chehab 8810ffebbeSMauro Carvalho Chehab specifies an initial resource "budget", decremented by "size" 8910ffebbeSMauro Carvalho Chehab on each call to should_fail(,size). Failure injection is 9010ffebbeSMauro Carvalho Chehab suppressed until "space" reaches zero. 9110ffebbeSMauro Carvalho Chehab 9210ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail*/verbose 9310ffebbeSMauro Carvalho Chehab 9410ffebbeSMauro Carvalho Chehab Format: { 0 | 1 | 2 } 9510ffebbeSMauro Carvalho Chehab 9610ffebbeSMauro Carvalho Chehab specifies the verbosity of the messages when failure is 9710ffebbeSMauro Carvalho Chehab injected. '0' means no messages; '1' will print only a single 9810ffebbeSMauro Carvalho Chehab log line per failure; '2' will print a call trace too -- useful 9910ffebbeSMauro Carvalho Chehab to debug the problems revealed by fault injection. 10010ffebbeSMauro Carvalho Chehab 10110ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail*/task-filter: 10210ffebbeSMauro Carvalho Chehab 10310ffebbeSMauro Carvalho Chehab Format: { 'Y' | 'N' } 10410ffebbeSMauro Carvalho Chehab 10510ffebbeSMauro Carvalho Chehab A value of 'N' disables filtering by process (default). 10610ffebbeSMauro Carvalho Chehab Any positive value limits failures to only processes indicated by 10710ffebbeSMauro Carvalho Chehab /proc/<pid>/make-it-fail==1. 10810ffebbeSMauro Carvalho Chehab 10910ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail*/require-start, 11010ffebbeSMauro Carvalho Chehab /sys/kernel/debug/fail*/require-end, 11110ffebbeSMauro Carvalho Chehab /sys/kernel/debug/fail*/reject-start, 11210ffebbeSMauro Carvalho Chehab /sys/kernel/debug/fail*/reject-end: 11310ffebbeSMauro Carvalho Chehab 11410ffebbeSMauro Carvalho Chehab specifies the range of virtual addresses tested during 11510ffebbeSMauro Carvalho Chehab stacktrace walking. Failure is injected only if some caller 11610ffebbeSMauro Carvalho Chehab in the walked stacktrace lies within the required range, and 11710ffebbeSMauro Carvalho Chehab none lies within the rejected range. 11810ffebbeSMauro Carvalho Chehab Default required range is [0,ULONG_MAX) (whole of virtual address space). 11910ffebbeSMauro Carvalho Chehab Default rejected range is [0,0). 12010ffebbeSMauro Carvalho Chehab 12110ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail*/stacktrace-depth: 12210ffebbeSMauro Carvalho Chehab 12310ffebbeSMauro Carvalho Chehab specifies the maximum stacktrace depth walked during search 12410ffebbeSMauro Carvalho Chehab for a caller within [require-start,require-end) OR 12510ffebbeSMauro Carvalho Chehab [reject-start,reject-end). 12610ffebbeSMauro Carvalho Chehab 12710ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem: 12810ffebbeSMauro Carvalho Chehab 12910ffebbeSMauro Carvalho Chehab Format: { 'Y' | 'N' } 13010ffebbeSMauro Carvalho Chehab 13110ffebbeSMauro Carvalho Chehab default is 'N', setting it to 'Y' won't inject failures into 13210ffebbeSMauro Carvalho Chehab highmem/user allocations. 13310ffebbeSMauro Carvalho Chehab 13410ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/failslab/ignore-gfp-wait: 13510ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail_page_alloc/ignore-gfp-wait: 13610ffebbeSMauro Carvalho Chehab 13710ffebbeSMauro Carvalho Chehab Format: { 'Y' | 'N' } 13810ffebbeSMauro Carvalho Chehab 13910ffebbeSMauro Carvalho Chehab default is 'N', setting it to 'Y' will inject failures 14010ffebbeSMauro Carvalho Chehab only into non-sleep allocations (GFP_ATOMIC allocations). 14110ffebbeSMauro Carvalho Chehab 14210ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail_page_alloc/min-order: 14310ffebbeSMauro Carvalho Chehab 14410ffebbeSMauro Carvalho Chehab specifies the minimum page allocation order to be injected 14510ffebbeSMauro Carvalho Chehab failures. 14610ffebbeSMauro Carvalho Chehab 14710ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail_futex/ignore-private: 14810ffebbeSMauro Carvalho Chehab 14910ffebbeSMauro Carvalho Chehab Format: { 'Y' | 'N' } 15010ffebbeSMauro Carvalho Chehab 15110ffebbeSMauro Carvalho Chehab default is 'N', setting it to 'Y' will disable failure injections 15210ffebbeSMauro Carvalho Chehab when dealing with private (address space) futexes. 15310ffebbeSMauro Carvalho Chehab 15410ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail_function/inject: 15510ffebbeSMauro Carvalho Chehab 15610ffebbeSMauro Carvalho Chehab Format: { 'function-name' | '!function-name' | '' } 15710ffebbeSMauro Carvalho Chehab 15810ffebbeSMauro Carvalho Chehab specifies the target function of error injection by name. 15910ffebbeSMauro Carvalho Chehab If the function name leads '!' prefix, given function is 16010ffebbeSMauro Carvalho Chehab removed from injection list. If nothing specified ('') 16110ffebbeSMauro Carvalho Chehab injection list is cleared. 16210ffebbeSMauro Carvalho Chehab 16310ffebbeSMauro Carvalho Chehab- /sys/kernel/debug/fail_function/injectable: 16410ffebbeSMauro Carvalho Chehab 16510ffebbeSMauro Carvalho Chehab (read only) shows error injectable functions and what type of 16610ffebbeSMauro Carvalho Chehab error values can be specified. The error type will be one of 16710ffebbeSMauro Carvalho Chehab below; 16810ffebbeSMauro Carvalho Chehab - NULL: retval must be 0. 16910ffebbeSMauro Carvalho Chehab - ERRNO: retval must be -1 to -MAX_ERRNO (-4096). 17010ffebbeSMauro Carvalho Chehab - ERR_NULL: retval must be 0 or -1 to -MAX_ERRNO (-4096). 17110ffebbeSMauro Carvalho Chehab 172*00574752SWolfram Sang- /sys/kernel/debug/fail_function/<function-name>/retval: 17310ffebbeSMauro Carvalho Chehab 174*00574752SWolfram Sang specifies the "error" return value to inject to the given function. 175*00574752SWolfram Sang This will be created when the user specifies a new injection entry. 176*00574752SWolfram Sang Note that this file only accepts unsigned values. So, if you want to 177*00574752SWolfram Sang use a negative errno, you better use 'printf' instead of 'echo', e.g.: 178*00574752SWolfram Sang $ printf %#x -12 > retval 17910ffebbeSMauro Carvalho Chehab 18010ffebbeSMauro Carvalho ChehabBoot option 18110ffebbeSMauro Carvalho Chehab^^^^^^^^^^^ 18210ffebbeSMauro Carvalho Chehab 18310ffebbeSMauro Carvalho ChehabIn order to inject faults while debugfs is not available (early boot time), 18410ffebbeSMauro Carvalho Chehabuse the boot option:: 18510ffebbeSMauro Carvalho Chehab 18610ffebbeSMauro Carvalho Chehab failslab= 18710ffebbeSMauro Carvalho Chehab fail_page_alloc= 1882c739cedSAlbert van der Linde fail_usercopy= 18910ffebbeSMauro Carvalho Chehab fail_make_request= 19010ffebbeSMauro Carvalho Chehab fail_futex= 19110ffebbeSMauro Carvalho Chehab mmc_core.fail_request=<interval>,<probability>,<space>,<times> 19210ffebbeSMauro Carvalho Chehab 19310ffebbeSMauro Carvalho Chehabproc entries 19410ffebbeSMauro Carvalho Chehab^^^^^^^^^^^^ 19510ffebbeSMauro Carvalho Chehab 19610ffebbeSMauro Carvalho Chehab- /proc/<pid>/fail-nth, 19710ffebbeSMauro Carvalho Chehab /proc/self/task/<tid>/fail-nth: 19810ffebbeSMauro Carvalho Chehab 19910ffebbeSMauro Carvalho Chehab Write to this file of integer N makes N-th call in the task fail. 20010ffebbeSMauro Carvalho Chehab Read from this file returns a integer value. A value of '0' indicates 20110ffebbeSMauro Carvalho Chehab that the fault setup with a previous write to this file was injected. 20210ffebbeSMauro Carvalho Chehab A positive integer N indicates that the fault wasn't yet injected. 20310ffebbeSMauro Carvalho Chehab Note that this file enables all types of faults (slab, futex, etc). 20410ffebbeSMauro Carvalho Chehab This setting takes precedence over all other generic debugfs settings 20510ffebbeSMauro Carvalho Chehab like probability, interval, times, etc. But per-capability settings 20610ffebbeSMauro Carvalho Chehab (e.g. fail_futex/ignore-private) take precedence over it. 20710ffebbeSMauro Carvalho Chehab 20810ffebbeSMauro Carvalho Chehab This feature is intended for systematic testing of faults in a single 20910ffebbeSMauro Carvalho Chehab system call. See an example below. 21010ffebbeSMauro Carvalho Chehab 21110ffebbeSMauro Carvalho ChehabHow to add new fault injection capability 21210ffebbeSMauro Carvalho Chehab----------------------------------------- 21310ffebbeSMauro Carvalho Chehab 21410ffebbeSMauro Carvalho Chehab- #include <linux/fault-inject.h> 21510ffebbeSMauro Carvalho Chehab 21610ffebbeSMauro Carvalho Chehab- define the fault attributes 21710ffebbeSMauro Carvalho Chehab 21810ffebbeSMauro Carvalho Chehab DECLARE_FAULT_ATTR(name); 21910ffebbeSMauro Carvalho Chehab 22010ffebbeSMauro Carvalho Chehab Please see the definition of struct fault_attr in fault-inject.h 22110ffebbeSMauro Carvalho Chehab for details. 22210ffebbeSMauro Carvalho Chehab 22310ffebbeSMauro Carvalho Chehab- provide a way to configure fault attributes 22410ffebbeSMauro Carvalho Chehab 22510ffebbeSMauro Carvalho Chehab- boot option 22610ffebbeSMauro Carvalho Chehab 22710ffebbeSMauro Carvalho Chehab If you need to enable the fault injection capability from boot time, you can 22810ffebbeSMauro Carvalho Chehab provide boot option to configure it. There is a helper function for it: 22910ffebbeSMauro Carvalho Chehab 23010ffebbeSMauro Carvalho Chehab setup_fault_attr(attr, str); 23110ffebbeSMauro Carvalho Chehab 23210ffebbeSMauro Carvalho Chehab- debugfs entries 23310ffebbeSMauro Carvalho Chehab 2342c739cedSAlbert van der Linde failslab, fail_page_alloc, fail_usercopy, and fail_make_request use this way. 23510ffebbeSMauro Carvalho Chehab Helper functions: 23610ffebbeSMauro Carvalho Chehab 23710ffebbeSMauro Carvalho Chehab fault_create_debugfs_attr(name, parent, attr); 23810ffebbeSMauro Carvalho Chehab 23910ffebbeSMauro Carvalho Chehab- module parameters 24010ffebbeSMauro Carvalho Chehab 24110ffebbeSMauro Carvalho Chehab If the scope of the fault injection capability is limited to a 24210ffebbeSMauro Carvalho Chehab single kernel module, it is better to provide module parameters to 24310ffebbeSMauro Carvalho Chehab configure the fault attributes. 24410ffebbeSMauro Carvalho Chehab 24510ffebbeSMauro Carvalho Chehab- add a hook to insert failures 24610ffebbeSMauro Carvalho Chehab 24710ffebbeSMauro Carvalho Chehab Upon should_fail() returning true, client code should inject a failure: 24810ffebbeSMauro Carvalho Chehab 24910ffebbeSMauro Carvalho Chehab should_fail(attr, size); 25010ffebbeSMauro Carvalho Chehab 25110ffebbeSMauro Carvalho ChehabApplication Examples 25210ffebbeSMauro Carvalho Chehab-------------------- 25310ffebbeSMauro Carvalho Chehab 25410ffebbeSMauro Carvalho Chehab- Inject slab allocation failures into module init/exit code:: 25510ffebbeSMauro Carvalho Chehab 25610ffebbeSMauro Carvalho Chehab #!/bin/bash 25710ffebbeSMauro Carvalho Chehab 25810ffebbeSMauro Carvalho Chehab FAILTYPE=failslab 25910ffebbeSMauro Carvalho Chehab echo Y > /sys/kernel/debug/$FAILTYPE/task-filter 26010ffebbeSMauro Carvalho Chehab echo 10 > /sys/kernel/debug/$FAILTYPE/probability 26110ffebbeSMauro Carvalho Chehab echo 100 > /sys/kernel/debug/$FAILTYPE/interval 262*00574752SWolfram Sang printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times 26310ffebbeSMauro Carvalho Chehab echo 0 > /sys/kernel/debug/$FAILTYPE/space 26410ffebbeSMauro Carvalho Chehab echo 2 > /sys/kernel/debug/$FAILTYPE/verbose 26510ffebbeSMauro Carvalho Chehab echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait 26610ffebbeSMauro Carvalho Chehab 26710ffebbeSMauro Carvalho Chehab faulty_system() 26810ffebbeSMauro Carvalho Chehab { 26910ffebbeSMauro Carvalho Chehab bash -c "echo 1 > /proc/self/make-it-fail && exec $*" 27010ffebbeSMauro Carvalho Chehab } 27110ffebbeSMauro Carvalho Chehab 27210ffebbeSMauro Carvalho Chehab if [ $# -eq 0 ] 27310ffebbeSMauro Carvalho Chehab then 27410ffebbeSMauro Carvalho Chehab echo "Usage: $0 modulename [ modulename ... ]" 27510ffebbeSMauro Carvalho Chehab exit 1 27610ffebbeSMauro Carvalho Chehab fi 27710ffebbeSMauro Carvalho Chehab 27810ffebbeSMauro Carvalho Chehab for m in $* 27910ffebbeSMauro Carvalho Chehab do 28010ffebbeSMauro Carvalho Chehab echo inserting $m... 28110ffebbeSMauro Carvalho Chehab faulty_system modprobe $m 28210ffebbeSMauro Carvalho Chehab 28310ffebbeSMauro Carvalho Chehab echo removing $m... 28410ffebbeSMauro Carvalho Chehab faulty_system modprobe -r $m 28510ffebbeSMauro Carvalho Chehab done 28610ffebbeSMauro Carvalho Chehab 28710ffebbeSMauro Carvalho Chehab------------------------------------------------------------------------------ 28810ffebbeSMauro Carvalho Chehab 28910ffebbeSMauro Carvalho Chehab- Inject page allocation failures only for a specific module:: 29010ffebbeSMauro Carvalho Chehab 29110ffebbeSMauro Carvalho Chehab #!/bin/bash 29210ffebbeSMauro Carvalho Chehab 29310ffebbeSMauro Carvalho Chehab FAILTYPE=fail_page_alloc 29410ffebbeSMauro Carvalho Chehab module=$1 29510ffebbeSMauro Carvalho Chehab 29610ffebbeSMauro Carvalho Chehab if [ -z $module ] 29710ffebbeSMauro Carvalho Chehab then 29810ffebbeSMauro Carvalho Chehab echo "Usage: $0 <modulename>" 29910ffebbeSMauro Carvalho Chehab exit 1 30010ffebbeSMauro Carvalho Chehab fi 30110ffebbeSMauro Carvalho Chehab 30210ffebbeSMauro Carvalho Chehab modprobe $module 30310ffebbeSMauro Carvalho Chehab 30410ffebbeSMauro Carvalho Chehab if [ ! -d /sys/module/$module/sections ] 30510ffebbeSMauro Carvalho Chehab then 30610ffebbeSMauro Carvalho Chehab echo Module $module is not loaded 30710ffebbeSMauro Carvalho Chehab exit 1 30810ffebbeSMauro Carvalho Chehab fi 30910ffebbeSMauro Carvalho Chehab 31010ffebbeSMauro Carvalho Chehab cat /sys/module/$module/sections/.text > /sys/kernel/debug/$FAILTYPE/require-start 31110ffebbeSMauro Carvalho Chehab cat /sys/module/$module/sections/.data > /sys/kernel/debug/$FAILTYPE/require-end 31210ffebbeSMauro Carvalho Chehab 31310ffebbeSMauro Carvalho Chehab echo N > /sys/kernel/debug/$FAILTYPE/task-filter 31410ffebbeSMauro Carvalho Chehab echo 10 > /sys/kernel/debug/$FAILTYPE/probability 31510ffebbeSMauro Carvalho Chehab echo 100 > /sys/kernel/debug/$FAILTYPE/interval 316*00574752SWolfram Sang printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times 31710ffebbeSMauro Carvalho Chehab echo 0 > /sys/kernel/debug/$FAILTYPE/space 31810ffebbeSMauro Carvalho Chehab echo 2 > /sys/kernel/debug/$FAILTYPE/verbose 31910ffebbeSMauro Carvalho Chehab echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait 32010ffebbeSMauro Carvalho Chehab echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-highmem 32110ffebbeSMauro Carvalho Chehab echo 10 > /sys/kernel/debug/$FAILTYPE/stacktrace-depth 32210ffebbeSMauro Carvalho Chehab 32310ffebbeSMauro Carvalho Chehab trap "echo 0 > /sys/kernel/debug/$FAILTYPE/probability" SIGINT SIGTERM EXIT 32410ffebbeSMauro Carvalho Chehab 32510ffebbeSMauro Carvalho Chehab echo "Injecting errors into the module $module... (interrupt to stop)" 32610ffebbeSMauro Carvalho Chehab sleep 1000000 32710ffebbeSMauro Carvalho Chehab 32810ffebbeSMauro Carvalho Chehab------------------------------------------------------------------------------ 32910ffebbeSMauro Carvalho Chehab 33010ffebbeSMauro Carvalho Chehab- Inject open_ctree error while btrfs mount:: 33110ffebbeSMauro Carvalho Chehab 33210ffebbeSMauro Carvalho Chehab #!/bin/bash 33310ffebbeSMauro Carvalho Chehab 33410ffebbeSMauro Carvalho Chehab rm -f testfile.img 33510ffebbeSMauro Carvalho Chehab dd if=/dev/zero of=testfile.img bs=1M seek=1000 count=1 33610ffebbeSMauro Carvalho Chehab DEVICE=$(losetup --show -f testfile.img) 33710ffebbeSMauro Carvalho Chehab mkfs.btrfs -f $DEVICE 33810ffebbeSMauro Carvalho Chehab mkdir -p tmpmnt 33910ffebbeSMauro Carvalho Chehab 34010ffebbeSMauro Carvalho Chehab FAILTYPE=fail_function 34110ffebbeSMauro Carvalho Chehab FAILFUNC=open_ctree 34210ffebbeSMauro Carvalho Chehab echo $FAILFUNC > /sys/kernel/debug/$FAILTYPE/inject 343*00574752SWolfram Sang printf %#x -12 > /sys/kernel/debug/$FAILTYPE/$FAILFUNC/retval 34410ffebbeSMauro Carvalho Chehab echo N > /sys/kernel/debug/$FAILTYPE/task-filter 34510ffebbeSMauro Carvalho Chehab echo 100 > /sys/kernel/debug/$FAILTYPE/probability 34610ffebbeSMauro Carvalho Chehab echo 0 > /sys/kernel/debug/$FAILTYPE/interval 347*00574752SWolfram Sang printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times 34810ffebbeSMauro Carvalho Chehab echo 0 > /sys/kernel/debug/$FAILTYPE/space 34910ffebbeSMauro Carvalho Chehab echo 1 > /sys/kernel/debug/$FAILTYPE/verbose 35010ffebbeSMauro Carvalho Chehab 35110ffebbeSMauro Carvalho Chehab mount -t btrfs $DEVICE tmpmnt 35210ffebbeSMauro Carvalho Chehab if [ $? -ne 0 ] 35310ffebbeSMauro Carvalho Chehab then 35410ffebbeSMauro Carvalho Chehab echo "SUCCESS!" 35510ffebbeSMauro Carvalho Chehab else 35610ffebbeSMauro Carvalho Chehab echo "FAILED!" 35710ffebbeSMauro Carvalho Chehab umount tmpmnt 35810ffebbeSMauro Carvalho Chehab fi 35910ffebbeSMauro Carvalho Chehab 36010ffebbeSMauro Carvalho Chehab echo > /sys/kernel/debug/$FAILTYPE/inject 36110ffebbeSMauro Carvalho Chehab 36210ffebbeSMauro Carvalho Chehab rmdir tmpmnt 36310ffebbeSMauro Carvalho Chehab losetup -d $DEVICE 36410ffebbeSMauro Carvalho Chehab rm testfile.img 36510ffebbeSMauro Carvalho Chehab 36610ffebbeSMauro Carvalho Chehab 36710ffebbeSMauro Carvalho ChehabTool to run command with failslab or fail_page_alloc 36810ffebbeSMauro Carvalho Chehab---------------------------------------------------- 36910ffebbeSMauro Carvalho ChehabIn order to make it easier to accomplish the tasks mentioned above, we can use 37010ffebbeSMauro Carvalho Chehabtools/testing/fault-injection/failcmd.sh. Please run a command 37110ffebbeSMauro Carvalho Chehab"./tools/testing/fault-injection/failcmd.sh --help" for more information and 37210ffebbeSMauro Carvalho Chehabsee the following examples. 37310ffebbeSMauro Carvalho Chehab 37410ffebbeSMauro Carvalho ChehabExamples: 37510ffebbeSMauro Carvalho Chehab 37610ffebbeSMauro Carvalho ChehabRun a command "make -C tools/testing/selftests/ run_tests" with injecting slab 37710ffebbeSMauro Carvalho Chehaballocation failure:: 37810ffebbeSMauro Carvalho Chehab 37910ffebbeSMauro Carvalho Chehab # ./tools/testing/fault-injection/failcmd.sh \ 38010ffebbeSMauro Carvalho Chehab -- make -C tools/testing/selftests/ run_tests 38110ffebbeSMauro Carvalho Chehab 38210ffebbeSMauro Carvalho ChehabSame as above except to specify 100 times failures at most instead of one time 38310ffebbeSMauro Carvalho Chehabat most by default:: 38410ffebbeSMauro Carvalho Chehab 38510ffebbeSMauro Carvalho Chehab # ./tools/testing/fault-injection/failcmd.sh --times=100 \ 38610ffebbeSMauro Carvalho Chehab -- make -C tools/testing/selftests/ run_tests 38710ffebbeSMauro Carvalho Chehab 38810ffebbeSMauro Carvalho ChehabSame as above except to inject page allocation failure instead of slab 38910ffebbeSMauro Carvalho Chehaballocation failure:: 39010ffebbeSMauro Carvalho Chehab 39110ffebbeSMauro Carvalho Chehab # env FAILCMD_TYPE=fail_page_alloc \ 39210ffebbeSMauro Carvalho Chehab ./tools/testing/fault-injection/failcmd.sh --times=100 \ 39310ffebbeSMauro Carvalho Chehab -- make -C tools/testing/selftests/ run_tests 39410ffebbeSMauro Carvalho Chehab 39510ffebbeSMauro Carvalho ChehabSystematic faults using fail-nth 39610ffebbeSMauro Carvalho Chehab--------------------------------- 39710ffebbeSMauro Carvalho Chehab 39810ffebbeSMauro Carvalho ChehabThe following code systematically faults 0-th, 1-st, 2-nd and so on 39910ffebbeSMauro Carvalho Chehabcapabilities in the socketpair() system call:: 40010ffebbeSMauro Carvalho Chehab 40110ffebbeSMauro Carvalho Chehab #include <sys/types.h> 40210ffebbeSMauro Carvalho Chehab #include <sys/stat.h> 40310ffebbeSMauro Carvalho Chehab #include <sys/socket.h> 40410ffebbeSMauro Carvalho Chehab #include <sys/syscall.h> 40510ffebbeSMauro Carvalho Chehab #include <fcntl.h> 40610ffebbeSMauro Carvalho Chehab #include <unistd.h> 40710ffebbeSMauro Carvalho Chehab #include <string.h> 40810ffebbeSMauro Carvalho Chehab #include <stdlib.h> 40910ffebbeSMauro Carvalho Chehab #include <stdio.h> 41010ffebbeSMauro Carvalho Chehab #include <errno.h> 41110ffebbeSMauro Carvalho Chehab 41210ffebbeSMauro Carvalho Chehab int main() 41310ffebbeSMauro Carvalho Chehab { 41410ffebbeSMauro Carvalho Chehab int i, err, res, fail_nth, fds[2]; 41510ffebbeSMauro Carvalho Chehab char buf[128]; 41610ffebbeSMauro Carvalho Chehab 41710ffebbeSMauro Carvalho Chehab system("echo N > /sys/kernel/debug/failslab/ignore-gfp-wait"); 41810ffebbeSMauro Carvalho Chehab sprintf(buf, "/proc/self/task/%ld/fail-nth", syscall(SYS_gettid)); 41910ffebbeSMauro Carvalho Chehab fail_nth = open(buf, O_RDWR); 42010ffebbeSMauro Carvalho Chehab for (i = 1;; i++) { 42110ffebbeSMauro Carvalho Chehab sprintf(buf, "%d", i); 42210ffebbeSMauro Carvalho Chehab write(fail_nth, buf, strlen(buf)); 42310ffebbeSMauro Carvalho Chehab res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds); 42410ffebbeSMauro Carvalho Chehab err = errno; 42510ffebbeSMauro Carvalho Chehab pread(fail_nth, buf, sizeof(buf), 0); 42610ffebbeSMauro Carvalho Chehab if (res == 0) { 42710ffebbeSMauro Carvalho Chehab close(fds[0]); 42810ffebbeSMauro Carvalho Chehab close(fds[1]); 42910ffebbeSMauro Carvalho Chehab } 43010ffebbeSMauro Carvalho Chehab printf("%d-th fault %c: res=%d/%d\n", i, atoi(buf) ? 'N' : 'Y', 43110ffebbeSMauro Carvalho Chehab res, err); 43210ffebbeSMauro Carvalho Chehab if (atoi(buf)) 43310ffebbeSMauro Carvalho Chehab break; 43410ffebbeSMauro Carvalho Chehab } 43510ffebbeSMauro Carvalho Chehab return 0; 43610ffebbeSMauro Carvalho Chehab } 43710ffebbeSMauro Carvalho Chehab 43810ffebbeSMauro Carvalho ChehabAn example output:: 43910ffebbeSMauro Carvalho Chehab 44010ffebbeSMauro Carvalho Chehab 1-th fault Y: res=-1/23 44110ffebbeSMauro Carvalho Chehab 2-th fault Y: res=-1/23 44210ffebbeSMauro Carvalho Chehab 3-th fault Y: res=-1/12 44310ffebbeSMauro Carvalho Chehab 4-th fault Y: res=-1/12 44410ffebbeSMauro Carvalho Chehab 5-th fault Y: res=-1/23 44510ffebbeSMauro Carvalho Chehab 6-th fault Y: res=-1/23 44610ffebbeSMauro Carvalho Chehab 7-th fault Y: res=-1/23 44710ffebbeSMauro Carvalho Chehab 8-th fault Y: res=-1/12 44810ffebbeSMauro Carvalho Chehab 9-th fault Y: res=-1/12 44910ffebbeSMauro Carvalho Chehab 10-th fault Y: res=-1/12 45010ffebbeSMauro Carvalho Chehab 11-th fault Y: res=-1/12 45110ffebbeSMauro Carvalho Chehab 12-th fault Y: res=-1/12 45210ffebbeSMauro Carvalho Chehab 13-th fault Y: res=-1/12 45310ffebbeSMauro Carvalho Chehab 14-th fault Y: res=-1/12 45410ffebbeSMauro Carvalho Chehab 15-th fault Y: res=-1/12 45510ffebbeSMauro Carvalho Chehab 16-th fault N: res=0/12 456