aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memory-failure.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/memory-failure.c')
-rw-r--r--mm/memory-failure.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 22d2b2028e54..117ef1598469 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -100,6 +100,49 @@ static int hwpoison_filter_flags(struct page *p)
100 return -EINVAL; 100 return -EINVAL;
101} 101}
102 102
103/*
104 * This allows stress tests to limit test scope to a collection of tasks
105 * by putting them under some memcg. This prevents killing unrelated/important
106 * processes such as /sbin/init. Note that the target task may share clean
107 * pages with init (eg. libc text), which is harmless. If the target task
108 * share _dirty_ pages with another task B, the test scheme must make sure B
109 * is also included in the memcg. At last, due to race conditions this filter
110 * can only guarantee that the page either belongs to the memcg tasks, or is
111 * a freed page.
112 */
113#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
114u64 hwpoison_filter_memcg;
115EXPORT_SYMBOL_GPL(hwpoison_filter_memcg);
116static int hwpoison_filter_task(struct page *p)
117{
118 struct mem_cgroup *mem;
119 struct cgroup_subsys_state *css;
120 unsigned long ino;
121
122 if (!hwpoison_filter_memcg)
123 return 0;
124
125 mem = try_get_mem_cgroup_from_page(p);
126 if (!mem)
127 return -EINVAL;
128
129 css = mem_cgroup_css(mem);
130 /* root_mem_cgroup has NULL dentries */
131 if (!css->cgroup->dentry)
132 return -EINVAL;
133
134 ino = css->cgroup->dentry->d_inode->i_ino;
135 css_put(css);
136
137 if (ino != hwpoison_filter_memcg)
138 return -EINVAL;
139
140 return 0;
141}
142#else
143static int hwpoison_filter_task(struct page *p) { return 0; }
144#endif
145
103int hwpoison_filter(struct page *p) 146int hwpoison_filter(struct page *p)
104{ 147{
105 if (hwpoison_filter_dev(p)) 148 if (hwpoison_filter_dev(p))
@@ -108,6 +151,9 @@ int hwpoison_filter(struct page *p)
108 if (hwpoison_filter_flags(p)) 151 if (hwpoison_filter_flags(p))
109 return -EINVAL; 152 return -EINVAL;
110 153
154 if (hwpoison_filter_task(p))
155 return -EINVAL;
156
111 return 0; 157 return 0;
112} 158}
113EXPORT_SYMBOL_GPL(hwpoison_filter); 159EXPORT_SYMBOL_GPL(hwpoison_filter);