Documentation: nvme: add an example for nvme fault injection
[linux-block.git] / Documentation / fault-injection / nvme-fault-injection.txt
CommitLineData
cf4182f3
TT
1NVMe Fault Injection
2====================
3Linux's fault injection framework provides a systematic way to support
4error injection via debugfs in the /sys/kernel/debug directory. When
5enabled, the default NVME_SC_INVALID_OPCODE with no retry will be
6injected into the nvme_end_request. Users can change the default status
7code and no retry flag via the debugfs. The list of Generic Command
8Status can be found in include/linux/nvme.h
9
10Following examples show how to inject an error into the nvme.
11
12First, enable CONFIG_FAULT_INJECTION_DEBUG_FS kernel config,
13recompile the kernel. After booting up the kernel, do the
14following.
15
16Example 1: Inject default status code with no retry
17---------------------------------------------------
18
19mount /dev/nvme0n1 /mnt
20echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times
21echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability
22cp a.file /mnt
23
24Expected Result:
25
26cp: cannot stat ‘/mnt/a.file’: Input/output error
27
28Message from dmesg:
29
30FAULT_INJECTION: forcing a failure.
31name fault_inject, interval 1, probability 100, space 0, times 1
32CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.15.0-rc8+ #2
33Hardware name: innotek GmbH VirtualBox/VirtualBox,
34BIOS VirtualBox 12/01/2006
35Call Trace:
36 <IRQ>
37 dump_stack+0x5c/0x7d
38 should_fail+0x148/0x170
39 nvme_should_fail+0x2f/0x50 [nvme_core]
40 nvme_process_cq+0xe7/0x1d0 [nvme]
41 nvme_irq+0x1e/0x40 [nvme]
42 __handle_irq_event_percpu+0x3a/0x190
43 handle_irq_event_percpu+0x30/0x70
44 handle_irq_event+0x36/0x60
45 handle_fasteoi_irq+0x78/0x120
46 handle_irq+0xa7/0x130
47 ? tick_irq_enter+0xa8/0xc0
48 do_IRQ+0x43/0xc0
49 common_interrupt+0xa2/0xa2
50 </IRQ>
51RIP: 0010:native_safe_halt+0x2/0x10
52RSP: 0018:ffffffff82003e90 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffdd
53RAX: ffffffff817a10c0 RBX: ffffffff82012480 RCX: 0000000000000000
54RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
55RBP: 0000000000000000 R08: 000000008e38ce64 R09: 0000000000000000
56R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff82012480
57R13: ffffffff82012480 R14: 0000000000000000 R15: 0000000000000000
58 ? __sched_text_end+0x4/0x4
59 default_idle+0x18/0xf0
60 do_idle+0x150/0x1d0
61 cpu_startup_entry+0x6f/0x80
62 start_kernel+0x4c4/0x4e4
63 ? set_init_arg+0x55/0x55
64 secondary_startup_64+0xa5/0xb0
65 print_req_error: I/O error, dev nvme0n1, sector 9240
66EXT4-fs error (device nvme0n1): ext4_find_entry:1436:
67inode #2: comm cp: reading directory lblock 0
68
69Example 2: Inject default status code with retry
70------------------------------------------------
71
72mount /dev/nvme0n1 /mnt
73echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times
74echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability
75echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/status
76echo 0 > /sys/kernel/debug/nvme0n1/fault_inject/dont_retry
77
78cp a.file /mnt
79
80Expected Result:
81
82command success without error
83
84Message from dmesg:
85
86FAULT_INJECTION: forcing a failure.
87name fault_inject, interval 1, probability 100, space 0, times 1
88CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.15.0-rc8+ #4
89Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
90Call Trace:
91 <IRQ>
92 dump_stack+0x5c/0x7d
93 should_fail+0x148/0x170
94 nvme_should_fail+0x30/0x60 [nvme_core]
95 nvme_loop_queue_response+0x84/0x110 [nvme_loop]
96 nvmet_req_complete+0x11/0x40 [nvmet]
97 nvmet_bio_done+0x28/0x40 [nvmet]
98 blk_update_request+0xb0/0x310
99 blk_mq_end_request+0x18/0x60
100 flush_smp_call_function_queue+0x3d/0xf0
101 smp_call_function_single_interrupt+0x2c/0xc0
102 call_function_single_interrupt+0xa2/0xb0
103 </IRQ>
104RIP: 0010:native_safe_halt+0x2/0x10
105RSP: 0018:ffffc9000068bec0 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff04
106RAX: ffffffff817a10c0 RBX: ffff88011a3c9680 RCX: 0000000000000000
107RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
108RBP: 0000000000000001 R08: 000000008e38c131 R09: 0000000000000000
109R10: 0000000000000000 R11: 0000000000000000 R12: ffff88011a3c9680
110R13: ffff88011a3c9680 R14: 0000000000000000 R15: 0000000000000000
111 ? __sched_text_end+0x4/0x4
112 default_idle+0x18/0xf0
113 do_idle+0x150/0x1d0
114 cpu_startup_entry+0x6f/0x80
115 start_secondary+0x187/0x1e0
116 secondary_startup_64+0xa5/0xb0
7e31d821
AM
117
118Example 3: Inject an error into the 10th admin command
119------------------------------------------------------
120
121echo 100 > /sys/kernel/debug/nvme0/fault_inject/probability
122echo 10 > /sys/kernel/debug/nvme0/fault_inject/space
123echo 1 > /sys/kernel/debug/nvme0/fault_inject/times
124nvme reset /dev/nvme0
125
126Expected Result:
127
128After NVMe controller reset, the reinitialization may or may not succeed.
129It depends on which admin command is actually forced to fail.
130
131Message from dmesg:
132
133nvme nvme0: resetting controller
134FAULT_INJECTION: forcing a failure.
135name fault_inject, interval 1, probability 100, space 1, times 1
136CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.2.0-rc2+ #2
137Hardware name: MSI MS-7A45/B150M MORTAR ARCTIC (MS-7A45), BIOS 1.50 04/25/2017
138Call Trace:
139 <IRQ>
140 dump_stack+0x63/0x85
141 should_fail+0x14a/0x170
142 nvme_should_fail+0x38/0x80 [nvme_core]
143 nvme_irq+0x129/0x280 [nvme]
144 ? blk_mq_end_request+0xb3/0x120
145 __handle_irq_event_percpu+0x84/0x1a0
146 handle_irq_event_percpu+0x32/0x80
147 handle_irq_event+0x3b/0x60
148 handle_edge_irq+0x7f/0x1a0
149 handle_irq+0x20/0x30
150 do_IRQ+0x4e/0xe0
151 common_interrupt+0xf/0xf
152 </IRQ>
153RIP: 0010:cpuidle_enter_state+0xc5/0x460
154Code: 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
155RSP: 0018:ffffffff88c03dd0 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffdc
156RAX: ffff9dac25a2ac80 RBX: ffffffff88d53760 RCX: 000000000000001f
157RDX: 0000000000000000 RSI: 000000002d958403 RDI: 0000000000000000
158RBP: ffffffff88c03e18 R08: fffffff75e35ffb7 R09: 00000a49a56c0b48
159R10: ffffffff88c03da0 R11: 0000000000001b0c R12: ffff9dac25a34d00
160R13: 0000000000000006 R14: 0000000000000006 R15: ffffffff88d53760
161 cpuidle_enter+0x2e/0x40
162 call_cpuidle+0x23/0x40
163 do_idle+0x201/0x280
164 cpu_startup_entry+0x1d/0x20
165 rest_init+0xaa/0xb0
166 arch_call_rest_init+0xe/0x1b
167 start_kernel+0x51c/0x53b
168 x86_64_start_reservations+0x24/0x26
169 x86_64_start_kernel+0x74/0x77
170 secondary_startup_64+0xa4/0xb0
171nvme nvme0: Could not set queue count (16385)
172nvme nvme0: IO queues not created