* [PATCH] hwpoison: fix oops on ksm pages @ 2009-10-13 14:02 Hugh Dickins 2009-10-13 15:43 ` Andi Kleen 0 siblings, 1 reply; 4+ messages in thread From: Hugh Dickins @ 2009-10-13 14:02 UTC (permalink / raw) To: Andi Kleen; +Cc: Wu Fengguang, Izik Eidus, Andrew Morton, linux-kernel Memory failure on a KSM page currently oopses on its NULL anon_vma in page_lock_anon_vma(): that may not be much worse than the consequence of ignoring it, but it is better to be consistent with how ZERO_PAGE and hugetlb pages and other awkward cases are treated. Just skip it. Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk> --- We could fix it for 2.6.32 at the KSM end, by putting a dummy anon_vma pointer in there; but that would get harder next time, when KSM will put a pointer to something else there (and I'm not currently planning to do any work to open that up to memory_failure). So I would prefer this simple PageKsm test, until the other exceptions are handled. mm/memory-failure.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- 2.6.32-rc4/mm/memory-failure.c 2009-09-28 00:28:41.000000000 +0100 +++ linux/mm/memory-failure.c 2009-10-13 14:09:12.000000000 +0100 @@ -35,6 +35,7 @@ #include <linux/mm.h> #include <linux/page-flags.h> #include <linux/sched.h> +#include <linux/ksm.h> #include <linux/rmap.h> #include <linux/pagemap.h> #include <linux/swap.h> @@ -661,7 +662,7 @@ static void hwpoison_user_mappings(struc int i; int kill = 1; - if (PageReserved(p) || PageCompound(p) || PageSlab(p)) + if (PageReserved(p) || PageCompound(p) || PageSlab(p) || PageKsm(p)) return; if (!PageLRU(p)) ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hwpoison: fix oops on ksm pages 2009-10-13 14:02 [PATCH] hwpoison: fix oops on ksm pages Hugh Dickins @ 2009-10-13 15:43 ` Andi Kleen 2009-10-13 18:03 ` Hugh Dickins 0 siblings, 1 reply; 4+ messages in thread From: Andi Kleen @ 2009-10-13 15:43 UTC (permalink / raw) To: Hugh Dickins Cc: Andi Kleen, Wu Fengguang, Izik Eidus, Andrew Morton, linux-kernel On Tue, Oct 13, 2009 at 03:02:11PM +0100, Hugh Dickins wrote: > Memory failure on a KSM page currently oopses on its NULL anon_vma in > page_lock_anon_vma(): that may not be much worse than the consequence > of ignoring it, but it is better to be consistent with how ZERO_PAGE > and hugetlb pages and other awkward cases are treated. Just skip it. Thanks, Hugh. I'm curious: did this come out of code review or did you actually run into that? -Andi -- ak@linux.intel.com -- Speaking for myself only. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hwpoison: fix oops on ksm pages 2009-10-13 15:43 ` Andi Kleen @ 2009-10-13 18:03 ` Hugh Dickins 0 siblings, 0 replies; 4+ messages in thread From: Hugh Dickins @ 2009-10-13 18:03 UTC (permalink / raw) To: Andi Kleen; +Cc: Wu Fengguang, Izik Eidus, Andrew Morton, linux-kernel On Tue, 13 Oct 2009, Andi Kleen wrote: > On Tue, Oct 13, 2009 at 03:02:11PM +0100, Hugh Dickins wrote: > > Memory failure on a KSM page currently oopses on its NULL anon_vma in > > page_lock_anon_vma(): that may not be much worse than the consequence > > of ignoring it, but it is better to be consistent with how ZERO_PAGE > > and hugetlb pages and other awkward cases are treated. Just skip it. > > Thanks, Hugh. I'm curious: did this come out of code review or > did you actually run into that? Just out of code review: well, that's too fancy a name for it, I merely remembered that I hadn't looked at ksm/hwpoison interoperabilty, so did so just now. After looking at the code, I did then try MADV_HWPOISON on a MADV_MERGEABLE area, to check that the problem and the fix were real. Hugh ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <i>]
* HWPOISON updates for 2.6.32-rc5 for review [not found] <i> @ 2009-10-22 6:02 ` Andi Kleen 2009-10-22 6:02 ` [PATCH] HWPOISON: Clean up PR_MCE_KILL interface Andi Kleen 0 siblings, 1 reply; 4+ messages in thread From: Andi Kleen @ 2009-10-22 6:02 UTC (permalink / raw) To: linux-kernel; +Cc: fengguang.wu Here are the hwpoison bug fixes queued up for 2.6.32-rc5. In particularly they fix the page flags races that were discussed earlier and a couple of random bug fixes. Please review. -Andi ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] HWPOISON: Clean up PR_MCE_KILL interface 2009-10-22 6:02 ` HWPOISON updates for 2.6.32-rc5 for review Andi Kleen @ 2009-10-22 6:02 ` Andi Kleen 2009-10-22 6:02 ` [PATCH] HWPOISON: Add brief hwpoison description to Documentation Andi Kleen 0 siblings, 1 reply; 4+ messages in thread From: Andi Kleen @ 2009-10-22 6:02 UTC (permalink / raw) To: linux-kernel; +Cc: fengguang.wu, Andi Kleen From: Andi Kleen <ak@linux.intel.com> While writing the manpage I noticed some shortcomings in the current interface. - Define symbolic names for all the different values - Boundary check the kill mode values - For symmetry add a get interface too. This allows library code to get/set the current state. - For consistency define a PR_MCE_KILL_DEFAULT value Signed-off-by: Andi Kleen <ak@linux.intel.com> --- include/linux/prctl.h | 12 ++++++++++++ kernel/sys.c | 23 ++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/linux/prctl.h b/include/linux/prctl.h index 9311505..a3baeb2 100644 --- a/include/linux/prctl.h +++ b/include/linux/prctl.h @@ -88,6 +88,18 @@ #define PR_TASK_PERF_EVENTS_DISABLE 31 #define PR_TASK_PERF_EVENTS_ENABLE 32 +/* + * Set early/late kill mode for hwpoison memory corruption. + * This influences when the process gets killed on a memory corruption. + */ #define PR_MCE_KILL 33 +# define PR_MCE_KILL_CLEAR 0 +# define PR_MCE_KILL_SET 1 + +# define PR_MCE_KILL_LATE 0 +# define PR_MCE_KILL_EARLY 1 +# define PR_MCE_KILL_DEFAULT 2 + +#define PR_MCE_KILL_GET 34 #endif /* _LINUX_PRCTL_H */ diff --git a/kernel/sys.c b/kernel/sys.c index 255475d..f6afe07 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1546,24 +1546,37 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, if (arg4 | arg5) return -EINVAL; switch (arg2) { - case 0: + case PR_MCE_KILL_CLEAR: if (arg3 != 0) return -EINVAL; current->flags &= ~PF_MCE_PROCESS; break; - case 1: + case PR_MCE_KILL_SET: current->flags |= PF_MCE_PROCESS; - if (arg3 != 0) + if (arg3 == PR_MCE_KILL_EARLY) current->flags |= PF_MCE_EARLY; - else + else if (arg3 == PR_MCE_KILL_LATE) current->flags &= ~PF_MCE_EARLY; + else if (arg3 == PR_MCE_KILL_DEFAULT) + current->flags &= + ~(PF_MCE_EARLY|PF_MCE_PROCESS); + else + return -EINVAL; break; default: return -EINVAL; } error = 0; break; - + case PR_MCE_KILL_GET: + if (arg2 | arg3 | arg4 | arg5) + return -EINVAL; + if (current->flags & PF_MCE_PROCESS) + error = (current->flags & PF_MCE_EARLY) ? + PR_MCE_KILL_EARLY : PR_MCE_KILL_LATE; + else + error = PR_MCE_KILL_DEFAULT; + break; default: error = -EINVAL; break; -- 1.6.0.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] HWPOISON: Add brief hwpoison description to Documentation 2009-10-22 6:02 ` [PATCH] HWPOISON: Clean up PR_MCE_KILL interface Andi Kleen @ 2009-10-22 6:02 ` Andi Kleen 2009-10-22 6:02 ` [PATCH] HWPOISON: return early on non-LRU pages Andi Kleen 0 siblings, 1 reply; 4+ messages in thread From: Andi Kleen @ 2009-10-22 6:02 UTC (permalink / raw) To: linux-kernel; +Cc: fengguang.wu, Andi Kleen From: Andi Kleen <ak@linux.intel.com> Signed-off-by: Andi Kleen <ak@linux.intel.com> --- Documentation/vm/hwpoison.txt | 136 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 136 insertions(+), 0 deletions(-) create mode 100644 Documentation/vm/hwpoison.txt diff --git a/Documentation/vm/hwpoison.txt b/Documentation/vm/hwpoison.txt new file mode 100644 index 0000000..3ffadf8 --- /dev/null +++ b/Documentation/vm/hwpoison.txt @@ -0,0 +1,136 @@ +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: + +madvise(MADV_POISON, ....) + (as root) + Poison a page in the process for testing + + +hwpoison-inject module through debugfs + /sys/debug/hwpoison/corrupt-pfn + +Inject hwpoison fault at PFN echoed into this file + + +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 + -- 1.6.0.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] HWPOISON: return early on non-LRU pages 2009-10-22 6:02 ` [PATCH] HWPOISON: Add brief hwpoison description to Documentation Andi Kleen @ 2009-10-22 6:02 ` Andi Kleen 2009-10-22 6:02 ` [PATCH] HWPOISON: Fix page count leak in hwpoison late kill in do_swap_page Andi Kleen 0 siblings, 1 reply; 4+ messages in thread From: Andi Kleen @ 2009-10-22 6:02 UTC (permalink / raw) To: linux-kernel; +Cc: fengguang.wu, Andi Kleen From: Wu Fengguang <fengguang.wu@intel.com> Right now we have some trouble with non atomic access to page flags when locking the page. To plug this hole for now, limit error recovery to LRU pages for now. This could be better fixed by defining a suitable protocol, but let's go this simple way for now This avoids unnecessary races with __set_page_locked() and __SetPageSlab*() and maybe more non-atomic page flag operations. This loses isolated pages which are currently in page reclaim, but these are relatively limited compared to the total memory. Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Andi Kleen <ak@linux.intel.com> [AK: new description, bug fixes, cleanups] --- mm/memory-failure.c | 49 ++++++++++++++++++++++++------------------------- 1 files changed, 24 insertions(+), 25 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 729d4b1..e17ec3f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -370,9 +370,6 @@ static int me_pagecache_clean(struct page *p, unsigned long pfn) int ret = FAILED; struct address_space *mapping; - if (!isolate_lru_page(p)) - page_cache_release(p); - /* * For anonymous pages we're done the only reference left * should be the one m_f() holds. @@ -498,30 +495,18 @@ static int me_pagecache_dirty(struct page *p, unsigned long pfn) */ static int me_swapcache_dirty(struct page *p, unsigned long pfn) { - int ret = FAILED; - ClearPageDirty(p); /* Trigger EIO in shmem: */ ClearPageUptodate(p); - if (!isolate_lru_page(p)) { - page_cache_release(p); - ret = DELAYED; - } - - return ret; + return DELAYED; } static int me_swapcache_clean(struct page *p, unsigned long pfn) { - int ret = FAILED; - - if (!isolate_lru_page(p)) { - page_cache_release(p); - ret = RECOVERED; - } delete_from_swap_cache(p); - return ret; + + return RECOVERED; } /* @@ -611,8 +596,6 @@ static struct page_state { { 0, 0, "unknown page state", me_unknown }, }; -#undef lru - static void action_result(unsigned long pfn, char *msg, int result) { struct page *page = NULL; @@ -664,9 +647,6 @@ static void hwpoison_user_mappings(struct page *p, unsigned long pfn, if (PageReserved(p) || PageCompound(p) || PageSlab(p)) return; - if (!PageLRU(p)) - lru_add_drain_all(); - /* * This check implies we don't kill processes if their pages * are in the swap cache early. Those are always late kills. @@ -738,6 +718,7 @@ static void hwpoison_user_mappings(struct page *p, unsigned long pfn, int __memory_failure(unsigned long pfn, int trapno, int ref) { + unsigned long lru_flag; struct page_state *ps; struct page *p; int res; @@ -775,6 +756,24 @@ int __memory_failure(unsigned long pfn, int trapno, int ref) } /* + * We ignore non-LRU pages for good reasons. + * - PG_locked is only well defined for LRU pages and a few others + * - to avoid races with __set_page_locked() + * - to avoid races with __SetPageSlab*() (and more non-atomic ops) + * The check (unnecessarily) ignores LRU pages being isolated and + * walked by the page reclaim code, however that's not a big loss. + */ + if (!PageLRU(p)) + lru_add_drain_all(); + lru_flag = p->flags & lru; + if (isolate_lru_page(p)) { + action_result(pfn, "non LRU", IGNORED); + put_page(p); + return -EBUSY; + } + page_cache_release(p); + + /* * Lock the page and wait for writeback to finish. * It's very difficult to mess with pages currently under IO * and in many cases impossible, so we just avoid it here. @@ -790,7 +789,7 @@ int __memory_failure(unsigned long pfn, int trapno, int ref) /* * Torn down by someone else? */ - if (PageLRU(p) && !PageSwapCache(p) && p->mapping == NULL) { + if ((lru_flag & lru) && !PageSwapCache(p) && p->mapping == NULL) { action_result(pfn, "already truncated LRU", IGNORED); res = 0; goto out; @@ -798,7 +797,7 @@ int __memory_failure(unsigned long pfn, int trapno, int ref) res = -EBUSY; for (ps = error_states;; ps++) { - if ((p->flags & ps->mask) == ps->res) { + if (((p->flags | lru_flag)& ps->mask) == ps->res) { res = page_action(ps, p, pfn, ref); break; } -- 1.6.0.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] HWPOISON: Fix page count leak in hwpoison late kill in do_swap_page 2009-10-22 6:02 ` [PATCH] HWPOISON: return early on non-LRU pages Andi Kleen @ 2009-10-22 6:02 ` Andi Kleen 2009-10-22 6:02 ` [PATCH] HWPOISON: fix oops on ksm pages Andi Kleen 0 siblings, 1 reply; 4+ messages in thread From: Andi Kleen @ 2009-10-22 6:02 UTC (permalink / raw) To: linux-kernel; +Cc: fengguang.wu, Andi Kleen From: Andi Kleen <ak@linux.intel.com> When returning due to a poisoned page drop the page count. It wasn't a fatal problem because noone cares about the page count on a poisoned page (except when it wraps), but it's cleaner to fix it. Pointed out by Linus. Signed-off-by: Andi Kleen <ak@linux.intel.com> --- mm/memory.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7e91b5f..7a3b0ad 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2539,7 +2539,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma, } else if (PageHWPoison(page)) { ret = VM_FAULT_HWPOISON; delayacct_clear_flag(DELAYACCT_PF_SWAPIN); - goto out; + goto out_release; } lock_page(page); @@ -2611,6 +2611,7 @@ out_nomap: pte_unmap_unlock(page_table, ptl); out_page: unlock_page(page); +out_release: page_cache_release(page); return ret; } -- 1.6.0.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] HWPOISON: fix oops on ksm pages 2009-10-22 6:02 ` [PATCH] HWPOISON: Fix page count leak in hwpoison late kill in do_swap_page Andi Kleen @ 2009-10-22 6:02 ` Andi Kleen 0 siblings, 0 replies; 4+ messages in thread From: Andi Kleen @ 2009-10-22 6:02 UTC (permalink / raw) To: linux-kernel; +Cc: fengguang.wu, Hugh Dickins, Andi Kleen From: Hugh Dickins <hugh.dickins@tiscali.co.uk> Memory failure on a KSM page currently oopses on its NULL anon_vma in page_lock_anon_vma(): that may not be much worse than the consequence of ignoring it, but it is better to be consistent with how ZERO_PAGE and hugetlb pages and other awkward cases are treated. Just skip it. Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk> Signed-off-by: Andi Kleen <ak@linux.intel.com> --- mm/memory-failure.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index e17ec3f..e354b9f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -35,6 +35,7 @@ #include <linux/mm.h> #include <linux/page-flags.h> #include <linux/sched.h> +#include <linux/ksm.h> #include <linux/rmap.h> #include <linux/pagemap.h> #include <linux/swap.h> @@ -644,7 +645,7 @@ static void hwpoison_user_mappings(struct page *p, unsigned long pfn, int i; int kill = 1; - if (PageReserved(p) || PageCompound(p) || PageSlab(p)) + if (PageReserved(p) || PageCompound(p) || PageSlab(p) || PageKsm(p)) return; /* -- 1.6.0.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-10-22 6:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-13 14:02 [PATCH] hwpoison: fix oops on ksm pages Hugh Dickins
2009-10-13 15:43 ` Andi Kleen
2009-10-13 18:03 ` Hugh Dickins
[not found] <i>
2009-10-22 6:02 ` HWPOISON updates for 2.6.32-rc5 for review Andi Kleen
2009-10-22 6:02 ` [PATCH] HWPOISON: Clean up PR_MCE_KILL interface Andi Kleen
2009-10-22 6:02 ` [PATCH] HWPOISON: Add brief hwpoison description to Documentation Andi Kleen
2009-10-22 6:02 ` [PATCH] HWPOISON: return early on non-LRU pages Andi Kleen
2009-10-22 6:02 ` [PATCH] HWPOISON: Fix page count leak in hwpoison late kill in do_swap_page Andi Kleen
2009-10-22 6:02 ` [PATCH] HWPOISON: fix oops on ksm pages Andi Kleen
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.