diff options
-rw-r--r-- | include/asm-generic/mman-common.h | 1 | ||||
-rw-r--r-- | mm/madvise.c | 30 |
2 files changed, 31 insertions, 0 deletions
diff --git a/include/asm-generic/mman-common.h b/include/asm-generic/mman-common.h index 3b69ad34189a..c325d1ef42ab 100644 --- a/include/asm-generic/mman-common.h +++ b/include/asm-generic/mman-common.h | |||
@@ -34,6 +34,7 @@ | |||
34 | #define MADV_REMOVE 9 /* remove these pages & resources */ | 34 | #define MADV_REMOVE 9 /* remove these pages & resources */ |
35 | #define MADV_DONTFORK 10 /* don't inherit across fork */ | 35 | #define MADV_DONTFORK 10 /* don't inherit across fork */ |
36 | #define MADV_DOFORK 11 /* do inherit across fork */ | 36 | #define MADV_DOFORK 11 /* do inherit across fork */ |
37 | #define MADV_HWPOISON 100 /* poison a page for testing */ | ||
37 | 38 | ||
38 | /* compatibility flags */ | 39 | /* compatibility flags */ |
39 | #define MAP_FILE 0 | 40 | #define MAP_FILE 0 |
diff --git a/mm/madvise.c b/mm/madvise.c index 76eb4193acdd..8dbd38b8e4a4 100644 --- a/mm/madvise.c +++ b/mm/madvise.c | |||
@@ -207,6 +207,32 @@ static long madvise_remove(struct vm_area_struct *vma, | |||
207 | return error; | 207 | return error; |
208 | } | 208 | } |
209 | 209 | ||
210 | #ifdef CONFIG_MEMORY_FAILURE | ||
211 | /* | ||
212 | * Error injection support for memory error handling. | ||
213 | */ | ||
214 | static int madvise_hwpoison(unsigned long start, unsigned long end) | ||
215 | { | ||
216 | int ret = 0; | ||
217 | |||
218 | if (!capable(CAP_SYS_ADMIN)) | ||
219 | return -EPERM; | ||
220 | for (; start < end; start += PAGE_SIZE) { | ||
221 | struct page *p; | ||
222 | int ret = get_user_pages(current, current->mm, start, 1, | ||
223 | 0, 0, &p, NULL); | ||
224 | if (ret != 1) | ||
225 | return ret; | ||
226 | printk(KERN_INFO "Injecting memory failure for page %lx at %lx\n", | ||
227 | page_to_pfn(p), start); | ||
228 | /* Ignore return value for now */ | ||
229 | __memory_failure(page_to_pfn(p), 0, 1); | ||
230 | put_page(p); | ||
231 | } | ||
232 | return ret; | ||
233 | } | ||
234 | #endif | ||
235 | |||
210 | static long | 236 | static long |
211 | madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev, | 237 | madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev, |
212 | unsigned long start, unsigned long end, int behavior) | 238 | unsigned long start, unsigned long end, int behavior) |
@@ -307,6 +333,10 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) | |||
307 | int write; | 333 | int write; |
308 | size_t len; | 334 | size_t len; |
309 | 335 | ||
336 | #ifdef CONFIG_MEMORY_FAILURE | ||
337 | if (behavior == MADV_HWPOISON) | ||
338 | return madvise_hwpoison(start, start+len_in); | ||
339 | #endif | ||
310 | if (!madvise_behavior_valid(behavior)) | 340 | if (!madvise_behavior_valid(behavior)) |
311 | return error; | 341 | return error; |
312 | 342 | ||