nvme-fault-injection.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_end_request. 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. mount /dev/nvme0n1 /mnt
  16. echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times
  17. echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability
  18. cp a.file /mnt
  19. Expected Result:
  20. cp: cannot stat ‘/mnt/a.file’: Input/output error
  21. Message from dmesg:
  22. FAULT_INJECTION: forcing a failure.
  23. name fault_inject, interval 1, probability 100, space 0, times 1
  24. CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.15.0-rc8+ #2
  25. Hardware name: innotek GmbH VirtualBox/VirtualBox,
  26. BIOS VirtualBox 12/01/2006
  27. Call Trace:
  28. <IRQ>
  29. dump_stack+0x5c/0x7d
  30. should_fail+0x148/0x170
  31. nvme_should_fail+0x2f/0x50 [nvme_core]
  32. nvme_process_cq+0xe7/0x1d0 [nvme]
  33. nvme_irq+0x1e/0x40 [nvme]
  34. __handle_irq_event_percpu+0x3a/0x190
  35. handle_irq_event_percpu+0x30/0x70
  36. handle_irq_event+0x36/0x60
  37. handle_fasteoi_irq+0x78/0x120
  38. handle_irq+0xa7/0x130
  39. ? tick_irq_enter+0xa8/0xc0
  40. do_IRQ+0x43/0xc0
  41. common_interrupt+0xa2/0xa2
  42. </IRQ>
  43. RIP: 0010:native_safe_halt+0x2/0x10
  44. RSP: 0018:ffffffff82003e90 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffdd
  45. RAX: ffffffff817a10c0 RBX: ffffffff82012480 RCX: 0000000000000000
  46. RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
  47. RBP: 0000000000000000 R08: 000000008e38ce64 R09: 0000000000000000
  48. R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff82012480
  49. R13: ffffffff82012480 R14: 0000000000000000 R15: 0000000000000000
  50. ? __sched_text_end+0x4/0x4
  51. default_idle+0x18/0xf0
  52. do_idle+0x150/0x1d0
  53. cpu_startup_entry+0x6f/0x80
  54. start_kernel+0x4c4/0x4e4
  55. ? set_init_arg+0x55/0x55
  56. secondary_startup_64+0xa5/0xb0
  57. print_req_error: I/O error, dev nvme0n1, sector 9240
  58. EXT4-fs error (device nvme0n1): ext4_find_entry:1436:
  59. inode #2: comm cp: reading directory lblock 0
  60. Example 2: Inject default status code with retry
  61. ------------------------------------------------
  62. mount /dev/nvme0n1 /mnt
  63. echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times
  64. echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability
  65. echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/status
  66. echo 0 > /sys/kernel/debug/nvme0n1/fault_inject/dont_retry
  67. cp a.file /mnt
  68. Expected Result:
  69. command success without error
  70. Message from dmesg:
  71. FAULT_INJECTION: forcing a failure.
  72. name fault_inject, interval 1, probability 100, space 0, times 1
  73. CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.15.0-rc8+ #4
  74. Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
  75. Call Trace:
  76. <IRQ>
  77. dump_stack+0x5c/0x7d
  78. should_fail+0x148/0x170
  79. nvme_should_fail+0x30/0x60 [nvme_core]
  80. nvme_loop_queue_response+0x84/0x110 [nvme_loop]
  81. nvmet_req_complete+0x11/0x40 [nvmet]
  82. nvmet_bio_done+0x28/0x40 [nvmet]
  83. blk_update_request+0xb0/0x310
  84. blk_mq_end_request+0x18/0x60
  85. flush_smp_call_function_queue+0x3d/0xf0
  86. smp_call_function_single_interrupt+0x2c/0xc0
  87. call_function_single_interrupt+0xa2/0xb0
  88. </IRQ>
  89. RIP: 0010:native_safe_halt+0x2/0x10
  90. RSP: 0018:ffffc9000068bec0 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff04
  91. RAX: ffffffff817a10c0 RBX: ffff88011a3c9680 RCX: 0000000000000000
  92. RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
  93. RBP: 0000000000000001 R08: 000000008e38c131 R09: 0000000000000000
  94. R10: 0000000000000000 R11: 0000000000000000 R12: ffff88011a3c9680
  95. R13: ffff88011a3c9680 R14: 0000000000000000 R15: 0000000000000000
  96. ? __sched_text_end+0x4/0x4
  97. default_idle+0x18/0xf0
  98. do_idle+0x150/0x1d0
  99. cpu_startup_entry+0x6f/0x80
  100. start_secondary+0x187/0x1e0
  101. secondary_startup_64+0xa5/0xb0