hwpoison.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. What is hwpoison?
  2. Upcoming Intel CPUs have support for recovering from some memory errors
  3. (``MCA recovery''). This requires the OS to declare a page "poisoned",
  4. kill the processes associated with it and avoid using it in the future.
  5. This patchkit implements the necessary infrastructure in the VM.
  6. To quote the overview comment:
  7. * High level machine check handler. Handles pages reported by the
  8. * hardware as being corrupted usually due to a 2bit ECC memory or cache
  9. * failure.
  10. *
  11. * This focusses on pages detected as corrupted in the background.
  12. * When the current CPU tries to consume corruption the currently
  13. * running process can just be killed directly instead. This implies
  14. * that if the error cannot be handled for some reason it's safe to
  15. * just ignore it because no corruption has been consumed yet. Instead
  16. * when that happens another machine check will happen.
  17. *
  18. * Handles page cache pages in various states. The tricky part
  19. * here is that we can access any page asynchronous to other VM
  20. * users, because memory failures could happen anytime and anywhere,
  21. * possibly violating some of their assumptions. This is why this code
  22. * has to be extremely careful. Generally it tries to use normal locking
  23. * rules, as in get the standard locks, even if that means the
  24. * error handling takes potentially a long time.
  25. *
  26. * Some of the operations here are somewhat inefficient and have non
  27. * linear algorithmic complexity, because the data structures have not
  28. * been optimized for this case. This is in particular the case
  29. * for the mapping from a vma to a process. Since this case is expected
  30. * to be rare we hope we can get away with this.
  31. The code consists of a the high level handler in mm/memory-failure.c,
  32. a new page poison bit and various checks in the VM to handle poisoned
  33. pages.
  34. The main target right now is KVM guests, but it works for all kinds
  35. of applications. KVM support requires a recent qemu-kvm release.
  36. For the KVM use there was need for a new signal type so that
  37. KVM can inject the machine check into the guest with the proper
  38. address. This in theory allows other applications to handle
  39. memory failures too. The expection is that near all applications
  40. won't do that, but some very specialized ones might.
  41. ---
  42. There are two (actually three) modi memory failure recovery can be in:
  43. vm.memory_failure_recovery sysctl set to zero:
  44. All memory failures cause a panic. Do not attempt recovery.
  45. (on x86 this can be also affected by the tolerant level of the
  46. MCE subsystem)
  47. early kill
  48. (can be controlled globally and per process)
  49. Send SIGBUS to the application as soon as the error is detected
  50. This allows applications who can process memory errors in a gentle
  51. way (e.g. drop affected object)
  52. This is the mode used by KVM qemu.
  53. late kill
  54. Send SIGBUS when the application runs into the corrupted page.
  55. This is best for memory error unaware applications and default
  56. Note some pages are always handled as late kill.
  57. ---
  58. User control:
  59. vm.memory_failure_recovery
  60. See sysctl.txt
  61. vm.memory_failure_early_kill
  62. Enable early kill mode globally
  63. PR_MCE_KILL
  64. Set early/late kill mode/revert to system default
  65. arg1: PR_MCE_KILL_CLEAR: Revert to system default
  66. arg1: PR_MCE_KILL_SET: arg2 defines thread specific mode
  67. PR_MCE_KILL_EARLY: Early kill
  68. PR_MCE_KILL_LATE: Late kill
  69. PR_MCE_KILL_DEFAULT: Use system global default
  70. PR_MCE_KILL_GET
  71. return current mode
  72. ---
  73. Testing:
  74. madvise(MADV_POISON, ....)
  75. (as root)
  76. Poison a page in the process for testing
  77. hwpoison-inject module through debugfs
  78. /sys/debug/hwpoison/corrupt-pfn
  79. Inject hwpoison fault at PFN echoed into this file
  80. Architecture specific MCE injector
  81. x86 has mce-inject, mce-test
  82. Some portable hwpoison test programs in mce-test, see blow.
  83. ---
  84. References:
  85. http://halobates.de/mce-lc09-2.pdf
  86. Overview presentation from LinuxCon 09
  87. git://git.kernel.org/pub/scm/utils/cpu/mce/mce-test.git
  88. Test suite (hwpoison specific portable tests in tsrc)
  89. git://git.kernel.org/pub/scm/utils/cpu/mce/mce-inject.git
  90. x86 specific injector
  91. ---
  92. Limitations:
  93. - Not all page types are supported and never will. Most kernel internal
  94. objects cannot be recovered, only LRU pages for now.
  95. - Right now hugepage support is missing.
  96. ---
  97. Andi Kleen, Oct 2009