Blame view

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

847ce401d   Wu Fengguang   HWPOISON: Add unp...
101
  /sys/debug/hwpoison/
f58ee00f1   Andi Kleen   HWPOISON: Add bri...
102

847ce401d   Wu Fengguang   HWPOISON: Add unp...
103
  corrupt-pfn
31d3d3484   Wu Fengguang   HWPOISON: limit h...
104
105
  Inject hwpoison fault at PFN echoed into this file. This does
  some early filtering to avoid corrupted unintended pages in test suites.
847ce401d   Wu Fengguang   HWPOISON: Add unp...
106
107
108
109
110
111
112
113
114
115
  
  unpoison-pfn
  
  Software-unpoison page at PFN echoed into this file. This
  way a page can be reused again.
  This only works for Linux injected failures, not for real
  memory failures.
  
  Note these injection interfaces are not stable and might change between
  kernel versions
f58ee00f1   Andi Kleen   HWPOISON: Add bri...
116

7c116f2b0   Wu Fengguang   HWPOISON: add fs/...
117
118
119
120
121
122
  corrupt-filter-dev-major
  corrupt-filter-dev-minor
  
  Only handle memory failures to pages associated with the file system defined
  by block device major/minor.  -1U is the wildcard value.
  This should be only used for testing with artificial injection.
4fd466eb4   Andi Kleen   HWPOISON: add mem...
123
124
125
126
127
128
  corrupt-filter-memcg
  
  Limit injection to pages owned by memgroup. Specified by inode number
  of the memcg.
  
  Example:
f6e07d380   Jörg Sommer   Documentation: up...
129
          mkdir /sys/fs/cgroup/mem/hwpoison
4fd466eb4   Andi Kleen   HWPOISON: add mem...
130
131
  
          usemem -m 100 -s 1000 &
f6e07d380   Jörg Sommer   Documentation: up...
132
          echo `jobs -p` > /sys/fs/cgroup/mem/hwpoison/tasks
4fd466eb4   Andi Kleen   HWPOISON: add mem...
133

f6e07d380   Jörg Sommer   Documentation: up...
134
          memcg_ino=$(ls -id /sys/fs/cgroup/mem/hwpoison | cut -f1 -d' ')
4fd466eb4   Andi Kleen   HWPOISON: add mem...
135
136
137
138
          echo $memcg_ino > /debug/hwpoison/corrupt-filter-memcg
  
          page-types -p `pidof init`   --hwpoison  # shall do nothing
          page-types -p `pidof usemem` --hwpoison  # poison its pages
478c5ffc0   Wu Fengguang   HWPOISON: add pag...
139
140
141
142
143
144
145
146
147
  
  corrupt-filter-flags-mask
  corrupt-filter-flags-value
  
  When specified, only poison pages if ((page_flags & mask) == value).
  This allows stress testing of many kinds of pages. The page_flags
  are the same as in /proc/kpageflags. The flag bits are defined in
  include/linux/kernel-page-flags.h and documented in
  Documentation/vm/pagemap.txt
f58ee00f1   Andi Kleen   HWPOISON: Add bri...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
  Architecture specific MCE injector
  
  x86 has mce-inject, mce-test
  
  Some portable hwpoison test programs in mce-test, see blow.
  
  ---
  
  References:
  
  http://halobates.de/mce-lc09-2.pdf
  	Overview presentation from LinuxCon 09
  
  git://git.kernel.org/pub/scm/utils/cpu/mce/mce-test.git
  	Test suite (hwpoison specific portable tests in tsrc)
  
  git://git.kernel.org/pub/scm/utils/cpu/mce/mce-inject.git
  	x86 specific injector
  
  
  ---
  
  Limitations:
  
  - Not all page types are supported and never will. Most kernel internal
  objects cannot be recovered, only LRU pages for now.
  - Right now hugepage support is missing.
  
  ---
  Andi Kleen, Oct 2009