183 lines · plain
1========2hwpoison3========4 5What is hwpoison?6=================7 8Upcoming Intel CPUs have support for recovering from some memory errors9(``MCA recovery``). This requires the OS to declare a page "poisoned",10kill the processes associated with it and avoid using it in the future.11 12This patchkit implements the necessary infrastructure in the VM.13 14To quote the overview comment::15 16 High level machine check handler. Handles pages reported by the17 hardware as being corrupted usually due to a 2bit ECC memory or cache18 failure.19 20 This focusses on pages detected as corrupted in the background.21 When the current CPU tries to consume corruption the currently22 running process can just be killed directly instead. This implies23 that if the error cannot be handled for some reason it's safe to24 just ignore it because no corruption has been consumed yet. Instead25 when that happens another machine check will happen.26 27 Handles page cache pages in various states. The tricky part28 here is that we can access any page asynchronous to other VM29 users, because memory failures could happen anytime and anywhere,30 possibly violating some of their assumptions. This is why this code31 has to be extremely careful. Generally it tries to use normal locking32 rules, as in get the standard locks, even if that means the33 error handling takes potentially a long time.34 35 Some of the operations here are somewhat inefficient and have non36 linear algorithmic complexity, because the data structures have not37 been optimized for this case. This is in particular the case38 for the mapping from a vma to a process. Since this case is expected39 to be rare we hope we can get away with this.40 41The code consists of a the high level handler in mm/memory-failure.c,42a new page poison bit and various checks in the VM to handle poisoned43pages.44 45The main target right now is KVM guests, but it works for all kinds46of applications. KVM support requires a recent qemu-kvm release.47 48For the KVM use there was need for a new signal type so that49KVM can inject the machine check into the guest with the proper50address. This in theory allows other applications to handle51memory failures too. The expectation is that most applications52won't do that, but some very specialized ones might.53 54Failure recovery modes55======================56 57There are two (actually three) modes memory failure recovery can be in:58 59vm.memory_failure_recovery sysctl set to zero:60 All memory failures cause a panic. Do not attempt recovery.61 62early kill63 (can be controlled globally and per process)64 Send SIGBUS to the application as soon as the error is detected65 This allows applications who can process memory errors in a gentle66 way (e.g. drop affected object)67 This is the mode used by KVM qemu.68 69late kill70 Send SIGBUS when the application runs into the corrupted page.71 This is best for memory error unaware applications and default72 Note some pages are always handled as late kill.73 74User control75============76 77vm.memory_failure_recovery78 See sysctl.txt79 80vm.memory_failure_early_kill81 Enable early kill mode globally82 83PR_MCE_KILL84 Set early/late kill mode/revert to system default85 86 arg1: PR_MCE_KILL_CLEAR:87 Revert to system default88 arg1: PR_MCE_KILL_SET:89 arg2 defines thread specific mode90 91 PR_MCE_KILL_EARLY:92 Early kill93 PR_MCE_KILL_LATE:94 Late kill95 PR_MCE_KILL_DEFAULT96 Use system global default97 98 Note that if you want to have a dedicated thread which handles99 the SIGBUS(BUS_MCEERR_AO) on behalf of the process, you should100 call prctl(PR_MCE_KILL_EARLY) on the designated thread. Otherwise,101 the SIGBUS is sent to the main thread.102 103PR_MCE_KILL_GET104 return current mode105 106Testing107=======108 109* madvise(MADV_HWPOISON, ....) (as root) - Poison a page in the110 process for testing111 112* hwpoison-inject module through debugfs ``/sys/kernel/debug/hwpoison/``113 114 corrupt-pfn115 Inject hwpoison fault at PFN echoed into this file. This does116 some early filtering to avoid corrupted unintended pages in test suites.117 118 unpoison-pfn119 Software-unpoison page at PFN echoed into this file. This way120 a page can be reused again. This only works for Linux121 injected failures, not for real memory failures. Once any hardware122 memory failure happens, this feature is disabled.123 124 Note these injection interfaces are not stable and might change between125 kernel versions126 127 corrupt-filter-dev-major, corrupt-filter-dev-minor128 Only handle memory failures to pages associated with the file129 system defined by block device major/minor. -1U is the130 wildcard value. This should be only used for testing with131 artificial injection.132 133 corrupt-filter-memcg134 Limit injection to pages owned by memgroup. Specified by inode135 number of the memcg.136 137 Example::138 139 mkdir /sys/fs/cgroup/mem/hwpoison140 141 usemem -m 100 -s 1000 &142 echo `jobs -p` > /sys/fs/cgroup/mem/hwpoison/tasks143 144 memcg_ino=$(ls -id /sys/fs/cgroup/mem/hwpoison | cut -f1 -d' ')145 echo $memcg_ino > /debug/hwpoison/corrupt-filter-memcg146 147 page-types -p `pidof init` --hwpoison # shall do nothing148 page-types -p `pidof usemem` --hwpoison # poison its pages149 150 corrupt-filter-flags-mask, corrupt-filter-flags-value151 When specified, only poison pages if ((page_flags & mask) ==152 value). This allows stress testing of many kinds of153 pages. The page_flags are the same as in /proc/kpageflags. The154 flag bits are defined in include/linux/kernel-page-flags.h and155 documented in Documentation/admin-guide/mm/pagemap.rst156 157* Architecture specific MCE injector158 159 x86 has mce-inject, mce-test160 161 Some portable hwpoison test programs in mce-test, see below.162 163References164==========165 166http://halobates.de/mce-lc09-2.pdf167 Overview presentation from LinuxCon 09168 169git://git.kernel.org/pub/scm/utils/cpu/mce/mce-test.git170 Test suite (hwpoison specific portable tests in tsrc)171 172git://git.kernel.org/pub/scm/utils/cpu/mce/mce-inject.git173 x86 specific injector174 175 176Limitations177===========178- Not all page types are supported and never will. Most kernel internal179 objects cannot be recovered, only LRU pages for now.180 181---182Andi Kleen, Oct 2009183