hwpoison.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. Note that if you want to have a dedicated thread which handles
  71. the SIGBUS(BUS_MCEERR_AO) on behalf of the process, you should
  72. call prctl(PR_MCE_KILL_EARLY) on the designated thread. Otherwise,
  73. the SIGBUS is sent to the main thread.
  74. PR_MCE_KILL_GET
  75. return current mode
  76. ---
  77. Testing:
  78. madvise(MADV_HWPOISON, ....)
  79. (as root)
  80. Poison a page in the process for testing
  81. hwpoison-inject module through debugfs
  82. /sys/debug/hwpoison/
  83. corrupt-pfn
  84. Inject hwpoison fault at PFN echoed into this file. This does
  85. some early filtering to avoid corrupted unintended pages in test suites.
  86. unpoison-pfn
  87. Software-unpoison page at PFN echoed into this file. This
  88. way a page can be reused again.
  89. This only works for Linux injected failures, not for real
  90. memory failures.
  91. Note these injection interfaces are not stable and might change between
  92. kernel versions
  93. corrupt-filter-dev-major
  94. corrupt-filter-dev-minor
  95. Only handle memory failures to pages associated with the file system defined
  96. by block device major/minor. -1U is the wildcard value.
  97. This should be only used for testing with artificial injection.
  98. corrupt-filter-memcg
  99. Limit injection to pages owned by memgroup. Specified by inode number
  100. of the memcg.
  101. Example:
  102. mkdir /sys/fs/cgroup/mem/hwpoison
  103. usemem -m 100 -s 1000 &
  104. echo `jobs -p` > /sys/fs/cgroup/mem/hwpoison/tasks
  105. memcg_ino=$(ls -id /sys/fs/cgroup/mem/hwpoison | cut -f1 -d' ')
  106. echo $memcg_ino > /debug/hwpoison/corrupt-filter-memcg
  107. page-types -p `pidof init` --hwpoison # shall do nothing
  108. page-types -p `pidof usemem` --hwpoison # poison its pages
  109. corrupt-filter-flags-mask
  110. corrupt-filter-flags-value
  111. When specified, only poison pages if ((page_flags & mask) == value).
  112. This allows stress testing of many kinds of pages. The page_flags
  113. are the same as in /proc/kpageflags. The flag bits are defined in
  114. include/linux/kernel-page-flags.h and documented in
  115. Documentation/vm/pagemap.txt
  116. Architecture specific MCE injector
  117. x86 has mce-inject, mce-test
  118. Some portable hwpoison test programs in mce-test, see blow.
  119. ---
  120. References:
  121. http://halobates.de/mce-lc09-2.pdf
  122. Overview presentation from LinuxCon 09
  123. git://git.kernel.org/pub/scm/utils/cpu/mce/mce-test.git
  124. Test suite (hwpoison specific portable tests in tsrc)
  125. git://git.kernel.org/pub/scm/utils/cpu/mce/mce-inject.git
  126. x86 specific injector
  127. ---
  128. Limitations:
  129. - Not all page types are supported and never will. Most kernel internal
  130. objects cannot be recovered, only LRU pages for now.
  131. - Right now hugepage support is missing.
  132. ---
  133. Andi Kleen, Oct 2009