0001 NVMe Fault Injection
0002 ====================
0003 Linux's fault injection framework provides a systematic way to support
0004 error injection via debugfs in the /sys/kernel/debug directory. When
0005 enabled, the default NVME_SC_INVALID_OPCODE with no retry will be
0006 injected into the nvme_try_complete_req. Users can change the default status
0007 code and no retry flag via the debugfs. The list of Generic Command
0008 Status can be found in include/linux/nvme.h
0009
0010 Following examples show how to inject an error into the nvme.
0011
0012 First, enable CONFIG_FAULT_INJECTION_DEBUG_FS kernel config,
0013 recompile the kernel. After booting up the kernel, do the
0014 following.
0015
0016 Example 1: Inject default status code with no retry
0017 ---------------------------------------------------
0018
0019 ::
0020
0021 mount /dev/nvme0n1 /mnt
0022 echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times
0023 echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability
0024 cp a.file /mnt
0025
0026 Expected Result::
0027
0028 cp: cannot stat ‘/mnt/a.file’: Input/output error
0029
0030 Message from dmesg::
0031
0032 FAULT_INJECTION: forcing a failure.
0033 name fault_inject, interval 1, probability 100, space 0, times 1
0034 CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.15.0-rc8+ #2
0035 Hardware name: innotek GmbH VirtualBox/VirtualBox,
0036 BIOS VirtualBox 12/01/2006
0037 Call Trace:
0038 <IRQ>
0039 dump_stack+0x5c/0x7d
0040 should_fail+0x148/0x170
0041 nvme_should_fail+0x2f/0x50 [nvme_core]
0042 nvme_process_cq+0xe7/0x1d0 [nvme]
0043 nvme_irq+0x1e/0x40 [nvme]
0044 __handle_irq_event_percpu+0x3a/0x190
0045 handle_irq_event_percpu+0x30/0x70
0046 handle_irq_event+0x36/0x60
0047 handle_fasteoi_irq+0x78/0x120
0048 handle_irq+0xa7/0x130
0049 ? tick_irq_enter+0xa8/0xc0
0050 do_IRQ+0x43/0xc0
0051 common_interrupt+0xa2/0xa2
0052 </IRQ>
0053 RIP: 0010:native_safe_halt+0x2/0x10
0054 RSP: 0018:ffffffff82003e90 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffdd
0055 RAX: ffffffff817a10c0 RBX: ffffffff82012480 RCX: 0000000000000000
0056 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
0057 RBP: 0000000000000000 R08: 000000008e38ce64 R09: 0000000000000000
0058 R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff82012480
0059 R13: ffffffff82012480 R14: 0000000000000000 R15: 0000000000000000
0060 ? __sched_text_end+0x4/0x4
0061 default_idle+0x18/0xf0
0062 do_idle+0x150/0x1d0
0063 cpu_startup_entry+0x6f/0x80
0064 start_kernel+0x4c4/0x4e4
0065 ? set_init_arg+0x55/0x55
0066 secondary_startup_64+0xa5/0xb0
0067 print_req_error: I/O error, dev nvme0n1, sector 9240
0068 EXT4-fs error (device nvme0n1): ext4_find_entry:1436:
0069 inode #2: comm cp: reading directory lblock 0
0070
0071 Example 2: Inject default status code with retry
0072 ------------------------------------------------
0073
0074 ::
0075
0076 mount /dev/nvme0n1 /mnt
0077 echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times
0078 echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability
0079 echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/status
0080 echo 0 > /sys/kernel/debug/nvme0n1/fault_inject/dont_retry
0081
0082 cp a.file /mnt
0083
0084 Expected Result::
0085
0086 command success without error
0087
0088 Message from dmesg::
0089
0090 FAULT_INJECTION: forcing a failure.
0091 name fault_inject, interval 1, probability 100, space 0, times 1
0092 CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.15.0-rc8+ #4
0093 Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
0094 Call Trace:
0095 <IRQ>
0096 dump_stack+0x5c/0x7d
0097 should_fail+0x148/0x170
0098 nvme_should_fail+0x30/0x60 [nvme_core]
0099 nvme_loop_queue_response+0x84/0x110 [nvme_loop]
0100 nvmet_req_complete+0x11/0x40 [nvmet]
0101 nvmet_bio_done+0x28/0x40 [nvmet]
0102 blk_update_request+0xb0/0x310
0103 blk_mq_end_request+0x18/0x60
0104 flush_smp_call_function_queue+0x3d/0xf0
0105 smp_call_function_single_interrupt+0x2c/0xc0
0106 call_function_single_interrupt+0xa2/0xb0
0107 </IRQ>
0108 RIP: 0010:native_safe_halt+0x2/0x10
0109 RSP: 0018:ffffc9000068bec0 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff04
0110 RAX: ffffffff817a10c0 RBX: ffff88011a3c9680 RCX: 0000000000000000
0111 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
0112 RBP: 0000000000000001 R08: 000000008e38c131 R09: 0000000000000000
0113 R10: 0000000000000000 R11: 0000000000000000 R12: ffff88011a3c9680
0114 R13: ffff88011a3c9680 R14: 0000000000000000 R15: 0000000000000000
0115 ? __sched_text_end+0x4/0x4
0116 default_idle+0x18/0xf0
0117 do_idle+0x150/0x1d0
0118 cpu_startup_entry+0x6f/0x80
0119 start_secondary+0x187/0x1e0
0120 secondary_startup_64+0xa5/0xb0
0121
0122 Example 3: Inject an error into the 10th admin command
0123 ------------------------------------------------------
0124
0125 ::
0126
0127 echo 100 > /sys/kernel/debug/nvme0/fault_inject/probability
0128 echo 10 > /sys/kernel/debug/nvme0/fault_inject/space
0129 echo 1 > /sys/kernel/debug/nvme0/fault_inject/times
0130 nvme reset /dev/nvme0
0131
0132 Expected Result::
0133
0134 After NVMe controller reset, the reinitialization may or may not succeed.
0135 It depends on which admin command is actually forced to fail.
0136
0137 Message from dmesg::
0138
0139 nvme nvme0: resetting controller
0140 FAULT_INJECTION: forcing a failure.
0141 name fault_inject, interval 1, probability 100, space 1, times 1
0142 CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.2.0-rc2+ #2
0143 Hardware name: MSI MS-7A45/B150M MORTAR ARCTIC (MS-7A45), BIOS 1.50 04/25/2017
0144 Call Trace:
0145 <IRQ>
0146 dump_stack+0x63/0x85
0147 should_fail+0x14a/0x170
0148 nvme_should_fail+0x38/0x80 [nvme_core]
0149 nvme_irq+0x129/0x280 [nvme]
0150 ? blk_mq_end_request+0xb3/0x120
0151 __handle_irq_event_percpu+0x84/0x1a0
0152 handle_irq_event_percpu+0x32/0x80
0153 handle_irq_event+0x3b/0x60
0154 handle_edge_irq+0x7f/0x1a0
0155 handle_irq+0x20/0x30
0156 do_IRQ+0x4e/0xe0
0157 common_interrupt+0xf/0xf
0158 </IRQ>
0159 RIP: 0010:cpuidle_enter_state+0xc5/0x460
0160 Code: ff e8 8f 5f 86 ff 80 7d c7 00 74 17 9c 58 0f 1f 44 00 00 f6 c4 02 0f 85 69 03 00 00 31 ff e8 62 aa 8c ff fb 66 0f 1f 44 00 00 <45> 85 ed 0f 88 37 03 00 00 4c 8b 45 d0 4c 2b 45 b8 48 ba cf f7 53
0161 RSP: 0018:ffffffff88c03dd0 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffdc
0162 RAX: ffff9dac25a2ac80 RBX: ffffffff88d53760 RCX: 000000000000001f
0163 RDX: 0000000000000000 RSI: 000000002d958403 RDI: 0000000000000000
0164 RBP: ffffffff88c03e18 R08: fffffff75e35ffb7 R09: 00000a49a56c0b48
0165 R10: ffffffff88c03da0 R11: 0000000000001b0c R12: ffff9dac25a34d00
0166 R13: 0000000000000006 R14: 0000000000000006 R15: ffffffff88d53760
0167 cpuidle_enter+0x2e/0x40
0168 call_cpuidle+0x23/0x40
0169 do_idle+0x201/0x280
0170 cpu_startup_entry+0x1d/0x20
0171 rest_init+0xaa/0xb0
0172 arch_call_rest_init+0xe/0x1b
0173 start_kernel+0x51c/0x53b
0174 x86_64_start_reservations+0x24/0x26
0175 x86_64_start_kernel+0x74/0x77
0176 secondary_startup_64+0xa4/0xb0
0177 nvme nvme0: Could not set queue count (16385)
0178 nvme nvme0: IO queues not created