hwpoison.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ========
  2. hwpoison
  3. ========
  4. What is hwpoison?
  5. =================
  6. Upcoming Intel CPUs have support for recovering from some memory errors
  7. (``MCA recovery``). This requires the OS to declare a page "poisoned",
  8. kill the processes associated with it and avoid using it in the future.
  9. This patchkit implements the necessary infrastructure in the VM.
  10. To quote the overview comment::
  11. High level machine check handler. Handles pages reported by the
  12. hardware as being corrupted usually due to a 2bit ECC memory or cache
  13. failure.
  14. This focusses on pages detected as corrupted in the background.
  15. When the current CPU tries to consume corruption the currently
  16. running process can just be killed directly instead. This implies
  17. that if the error cannot be handled for some reason it's safe to
  18. just ignore it because no corruption has been consumed yet. Instead
  19. when that happens another machine check will happen.
  20. Handles page cache pages in various states. The tricky part
  21. here is that we can access any page asynchronous to other VM
  22. users, because memory failures could happen anytime and anywhere,
  23. possibly violating some of their assumptions. This is why this code
  24. has to be extremely careful. Generally it tries to use normal locking
  25. rules, as in get the standard locks, even if that means the
  26. error handling takes potentially a long time.
  27. Some of the operations here are somewhat inefficient and have non
  28. linear algorithmic complexity, because the data structures have not
  29. been optimized for this case. This is in particular the case
  30. for the mapping from a vma to a process. Since this case is expected
  31. to be rare we hope we can get away with this.
  32. The code consists of a the high level handler in mm/memory-failure.c,
  33. a new page poison bit and various checks in the VM to handle poisoned
  34. pages.
  35. The main target right now is KVM guests, but it works for all kinds
  36. of applications. KVM support requires a recent qemu-kvm release.
  37. For the KVM use there was need for a new signal type so that
  38. KVM can inject the machine check into the guest with the proper
  39. address. This in theory allows other applications to handle
  40. memory failures too. The expectation is that most applications
  41. won't do that, but some very specialized ones might.
  42. Failure recovery modes
  43. ======================
  44. There are two (actually three) modes memory failure recovery can be in:
  45. vm.memory_failure_recovery sysctl set to zero:
  46. All memory failures cause a panic. Do not attempt recovery.
  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. User control
  58. ============
  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:
  66. Revert to system default
  67. arg1: PR_MCE_KILL_SET:
  68. arg2 defines thread specific mode
  69. PR_MCE_KILL_EARLY:
  70. Early kill
  71. PR_MCE_KILL_LATE:
  72. Late kill
  73. PR_MCE_KILL_DEFAULT
  74. Use system global default
  75. Note that if you want to have a dedicated thread which handles
  76. the SIGBUS(BUS_MCEERR_AO) on behalf of the process, you should
  77. call prctl(PR_MCE_KILL_EARLY) on the designated thread. Otherwise,
  78. the SIGBUS is sent to the main thread.
  79. PR_MCE_KILL_GET
  80. return current mode
  81. Testing
  82. =======
  83. * madvise(MADV_HWPOISON, ....) (as root) - Poison a page in the
  84. process for testing
  85. * hwpoison-inject module through debugfs ``/sys/kernel/debug/hwpoison/``
  86. corrupt-pfn
  87. Inject hwpoison fault at PFN echoed into this file. This does
  88. some early filtering to avoid corrupted unintended pages in test suites.
  89. unpoison-pfn
  90. Software-unpoison page at PFN echoed into this file. This way
  91. a page can be reused again. This only works for Linux
  92. injected failures, not for real memory failures. Once any hardware
  93. memory failure happens, this feature is disabled.
  94. Note these injection interfaces are not stable and might change between
  95. kernel versions
  96. corrupt-filter-dev-major, corrupt-filter-dev-minor
  97. Only handle memory failures to pages associated with the file
  98. system defined by block device major/minor. -1U is the
  99. wildcard value. This should be only used for testing with
  100. artificial injection.
  101. corrupt-filter-memcg
  102. Limit injection to pages owned by memgroup. Specified by inode
  103. number of the memcg.
  104. Example::
  105. mkdir /sys/fs/cgroup/mem/hwpoison
  106. usemem -m 100 -s 1000 &
  107. echo `jobs -p` > /sys/fs/cgroup/mem/hwpoison/tasks
  108. memcg_ino=$(ls -id /sys/fs/cgroup/mem/hwpoison | cut -f1 -d' ')
  109. echo $memcg_ino > /debug/hwpoison/corrupt-filter-memcg
  110. page-types -p `pidof init` --hwpoison # shall do nothing
  111. page-types -p `pidof usemem` --hwpoison # poison its pages
  112. corrupt-filter-flags-mask, corrupt-filter-flags-value
  113. When specified, only poison pages if ((page_flags & mask) ==
  114. value). This allows stress testing of many kinds of
  115. pages. The page_flags are the same as in /proc/kpageflags. The
  116. flag bits are defined in include/linux/kernel-page-flags.h and
  117. documented in Documentation/admin-guide/mm/pagemap.rst
  118. * Architecture specific MCE injector
  119. x86 has mce-inject, mce-test
  120. Some portable hwpoison test programs in mce-test, see below.
  121. References
  122. ==========
  123. http://halobates.de/mce-lc09-2.pdf
  124. Overview presentation from LinuxCon 09
  125. git://git.kernel.org/pub/scm/utils/cpu/mce/mce-test.git
  126. Test suite (hwpoison specific portable tests in tsrc)
  127. git://git.kernel.org/pub/scm/utils/cpu/mce/mce-inject.git
  128. x86 specific injector
  129. Limitations
  130. ===========
  131. - Not all page types are supported and never will. Most kernel internal
  132. objects cannot be recovered, only LRU pages for now.
  133. ---
  134. Andi Kleen, Oct 2009