hwpoison.txt 5.6 KB

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