nvme-fault-injection.rst 6.4 KB

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