HWPOISON huge page signal fixes
Subsystems (5)
These patches fix the address granuality reporting for hugepage hwpoison errors. This requires some straight forward changes in the MM (to return this information from handle_mm_fault) and in the x86 fault handler (to pass this information on)
Any reviews and acks appreciated.
I plan to carry this in my tree for now. Targetted for 2.6.37
Thanks,
-Andi
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/2 Encode huge page size for VM_FAULT_HWPOISON errors
From: Andi Kleen <[email protected]>
This fixes a problem introduced with the hugetlb hwpoison handling
The user space SIGBUS signalling wants to know the size of the hugepage that caused a HWPOISON fault.
Unfortunately the architecture page fault handlers do not have easy access to the struct page.
Pass the information out in the fault error code instead.
I added a separate VM_FAULT_HWPOISON_LARGE bit for this case and encode the hpage index in some free upper bits of the fault code. The small page hwpoison keeps stays with the VM_FAULT_HWPOISON name to minimize changes.
Also add code to hugetlb.h to convert that index into a page shift.
Will be used in a further patch.
--- include/linux/hugetlb.h | 6 ++++++ include/linux/mm.h | 12 ++++++++++-- mm/hugetlb.c | 6 ++++-- mm/memory.c | 3 ++- 4 files changed, 22 insertions(+), 5 deletions(-)
include/linux/hugetlb.h +6 -0
@@ -307,6 +307,11 @@ static inline struct hstate *page_hstate(struct page *page) return size_to_hstate(PAGE_SIZE << compound_order(page)); } +static inline unsigned hstate_index_to_shift (unsigned index) +{ +return hstates[index].order +PAGE_SHIFT ; +} +#else struct hstate {};#define alloc_huge_page_node (h, nid) NULL
@@ -324,6 +329,7 @@ static inline unsigned int pages_per_huge_page(struct hstate *h) {return 1 ; } +#define hstate_index_to_shift (index) 0#endif #endif /* _LINUX_HUGETLB_H */
include/linux/mm.h +10 -2
@@ -718,12 +718,20 @@ static inline int page_mapped(struct page *page)#define VM_FAULT_SIGBUS 0x0002#define VM_FAULT_MAJOR 0x0004#define VM_FAULT_WRITE 0x0008/* Special case for get_user_pages */ -#define VM_FAULT_HWPOISON 0x0010/* Hit poisoned page */ +#define VM_FAULT_HWPOISON 0x0010/* Hit poisoned small page */ +#define VM_FAULT_HWPOISON_LARGE 0x0020/* Hit poisoned large page. Index encoded in upper bits */ #define VM_FAULT_NOPAGE 0x0100/* ->fault installed the pte, not return page */ #define VM_FAULT_LOCKED 0x0200/* ->fault locked the returned page */ -#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_HWPOISON) +#define VM_FAULT_HWPOISON_LARGE_MASK 0xf000/* encodes hpage index for large hwpoison */ + +#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_HWPOISON | \ + VM_FAULT_HWPOISON_LARGE) + +/* Encode hstate index for a hwpoisoned large page */ +#define VM_FAULT_SET_HINDEX (x) ((x) << 12) +#define VM_FAULT_GET_HINDEX (x) (((x) >> 12) & 0xf)/* * Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
mm/hugetlb.c +4 -2
@@ -2589,7 +2589,8 @@ retry:* So we need to block hugepage fault by PG_hwpoison bit check. */ if (unlikely (PageHWPoison (page))) { - ret =VM_FAULT_HWPOISON ; + ret =VM_FAULT_HWPOISON | +VM_FAULT_SET_HINDEX (h - hstates); goto backout_unlocked; }page_dup_rmap (page);
@@ -2656,7 +2657,8 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,migration_entry_wait (mm, (pmd_t *)ptep, address);return 0 ; }else if (unlikely (is_hugetlb_entry_hwpoisoned (entry))) -return VM_FAULT_HWPOISON ; +return VM_FAULT_HWPOISON_LARGE | +VM_FAULT_SET_HINDEX (h - hstates); } ptep =huge_pte_alloc (mm, address,huge_page_size (h));
mm/memory.c +2 -1
@@ -1450,7 +1450,8 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,if (ret &VM_FAULT_OOM )return i ? i : -ENOMEM ;if (ret & - (VM_FAULT_HWPOISON |VM_FAULT_SIGBUS )) + (VM_FAULT_HWPOISON |VM_FAULT_HWPOISON_LARGE | +VM_FAULT_SIGBUS ))return i ? i : -EFAULT ;BUG (); }
Signature · 7 lines
1.7.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 1/2] Encode huge page size for VM_FAULT_HWPOISON errors
Quoted 10 lines · Andi Kleen
From: Andi Kleen <[email protected]>
This fixes a problem introduced with the hugetlb hwpoison handling
The user space SIGBUS signalling wants to know the size of the hugepage that caused a HWPOISON fault.
Unfortunately the architecture page fault handlers do not have easy access to the struct page.
Quoted 8 lines
Pass the information out in the fault error code instead.
I added a separate
VM_FAULT_HWPOISON_LARGEbit for this case and encode the hpage index in some free upper bits of the fault code. The small page hwpoison keeps stays with theVM_FAULT_HWPOISONname to minimize changes.Also add code to
hugetlb.hto convert that index into a page shift.
The use of hstate index is space efficient, however at the cost of more code and tight coupling with hugetlb. If directly encoding page_order-PAGE_SHIFT, a mask of 0x3f (6 bits) will be able to present max order 63+12=75 which is sufficient large. We still have plenty of free bits in the 32bit fault code :)
Thanks,
Fengguang
Quoted 103 lines
Will be used in a further patch.
Cc Naoya Horiguchi <[email protected]>Signed-off-by Andi Kleen <[email protected]>--- include/linux/hugetlb.h | 6 ++++++ include/linux/mm.h | 12 ++++++++++-- mm/hugetlb.c | 6 ++++-- mm/memory.c | 3 ++- 4 files changed, 22 insertions(+), 5 deletions(-)include/linux/hugetlb.h +6
-0@@ -307,6 +307,11 @@ static inline struct hstate *page_hstate(struct page *page) return size_to_hstate(PAGE_SIZE << compound_order(page)); } +static inline unsigned hstate_index_to_shift (unsigned index) +{ +return hstates[index].order +PAGE_SHIFT ; +} +#else struct hstate {};#define alloc_huge_page_node (h, nid) NULL@@ -324,6 +329,7 @@ static inline unsigned int pages_per_huge_page(struct hstate *h) {return 1 ; } +#define hstate_index_to_shift (index) 0#endif #endif /* _LINUX_HUGETLB_H */ include/linux/mm.h +10
-2@@ -718,12 +718,20 @@ static inline int page_mapped(struct page *page)#define VM_FAULT_SIGBUS 0x0002#define VM_FAULT_MAJOR 0x0004#define VM_FAULT_WRITE 0x0008/* Special case for get_user_pages */ -#define VM_FAULT_HWPOISON 0x0010/* Hit poisoned page */ +#define VM_FAULT_HWPOISON 0x0010/* Hit poisoned small page */ +#define VM_FAULT_HWPOISON_LARGE 0x0020/* Hit poisoned large page. Index encoded in upper bits */ #define VM_FAULT_NOPAGE 0x0100/* ->fault installed the pte, not return page */ #define VM_FAULT_LOCKED 0x0200/* ->fault locked the returned page */ -#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_HWPOISON) +#define VM_FAULT_HWPOISON_LARGE_MASK 0xf000/* encodes hpage index for large hwpoison */ + +#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_HWPOISON | \ + VM_FAULT_HWPOISON_LARGE) + +/* Encode hstate index for a hwpoisoned large page */ +#define VM_FAULT_SET_HINDEX (x) ((x) << 12) +#define VM_FAULT_GET_HINDEX (x) (((x) >> 12) & 0xf)/* * Can be called by the pagefault handler when it gets a VM_FAULT_OOM. mm/hugetlb.c +4
-2@@ -2589,7 +2589,8 @@ retry:* So we need to block hugepage fault by PG_hwpoison bit check. */ if (unlikely (PageHWPoison (page))) { - ret =VM_FAULT_HWPOISON ; + ret =VM_FAULT_HWPOISON | +VM_FAULT_SET_HINDEX (h - hstates); goto backout_unlocked; }page_dup_rmap (page);@@ -2656,7 +2657,8 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,migration_entry_wait (mm, (pmd_t *)ptep, address);return 0 ; }else if (unlikely (is_hugetlb_entry_hwpoisoned (entry))) -return VM_FAULT_HWPOISON ; +return VM_FAULT_HWPOISON_LARGE | +VM_FAULT_SET_HINDEX (h - hstates); } ptep =huge_pte_alloc (mm, address,huge_page_size (h));mm/memory.c +2
-1@@ -1450,7 +1450,8 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,if (ret &VM_FAULT_OOM )return i ? i : -ENOMEM ;if (ret & - (VM_FAULT_HWPOISON |VM_FAULT_SIGBUS )) + (VM_FAULT_HWPOISON |VM_FAULT_HWPOISON_LARGE | +VM_FAULT_SIGBUS ))return i ? i : -EFAULT ;BUG (); }Signature · 1 line
1.7.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/2 x86: HWPOISON: Report correct address granuality for huge hwpoison faults
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
An earlier patch fixed the hwpoison fault handling to encode the huge page size in the fault code of the page fault handler.
This is needed to report this information in SIGBUS to user space.
This is a straight forward patch to pass this information through to the signal handling in the x86 specific fault.c
--- arch/x86/mm/fault.c | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)
arch/x86/mm/fault.c +13 -6
@@ -11,6 +11,7 @@#include <linux/kprobes.h> /* __kprobes, ... */ #include <linux/mmiotrace.h> /* kmmio_handler, ... */ #include <linux/perf_event.h> /* perf_sw_event */ +#include <linux/hugetlb.h> /* hstate_index_to_shift */ #include <asm/traps.h> /* dotraplinkage, ... */ #include <asm/pgalloc.h> /* pgd_*(), ... */
@@ -160,15 +161,20 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)static void force_sig_info_fault (int si_signo,int si_code,unsigned long address, -struct task_struct *tsk) +struct task_struct *tsk,int fault) { +unsigned lsb =0 ;siginfo_t info; info.si_signo = si_signo; info.si_errno =0 ; info.si_code = si_code; info.si_addr = (void __user *)address; - info.si_addr_lsb = si_code ==BUS_MCEERR_AR ?PAGE_SHIFT :0 ; +if (fault &VM_FAULT_HWPOISON_LARGE ) + lsb =hstate_index_to_shift (VM_FAULT_GET_HINDEX (fault)); +if (fault &VM_FAULT_HWPOISON ) + lsb =PAGE_SHIFT ; + info.si_addr_lsb = lsb;force_sig_info (si_signo, &info, tsk); }
@@ -731,7 +737,7 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, tsk->thread.error_code = error_code | (address >=TASK_SIZE ); tsk->thread.trap_no =14 ; -force_sig_info_fault (SIGSEGV , si_code, address, tsk); +force_sig_info_fault (SIGSEGV , si_code, address, tsk,0 );return ; }
@@ -816,14 +822,14 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address, tsk->thread.trap_no =14 ;#ifdef CONFIG_MEMORY_FAILURE -if (fault &VM_FAULT_HWPOISON ) { +if (fault & (VM_FAULT_HWPOISON |VM_FAULT_HWPOISON_LARGE )) {printk (KERN_ERR "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n" , tsk->comm, tsk->pid, address); code =BUS_MCEERR_AR ; }#endif -force_sig_info_fault (SIGBUS , code, address, tsk); +force_sig_info_fault (SIGBUS , code, address, tsk, fault); }static noinline void
@@ -833,7 +839,8 @@ mm_fault_error(struct pt_regs *regs, unsigned long error_code,if (fault &VM_FAULT_OOM ) {out_of_memory (regs, error_code, address); }else { -if (fault & (VM_FAULT_SIGBUS |VM_FAULT_HWPOISON )) +if (fault & (VM_FAULT_SIGBUS |VM_FAULT_HWPOISON | +VM_FAULT_HWPOISON_LARGE ))do_sigbus (regs, error_code, address, fault);else BUG ();
Signature · 7 lines
1.7.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] x86: HWPOISON: Report correct address granuality for huge hwpoison faults
Quoted 35 lines · Andi Kleen
From: Andi Kleen <[email protected]>
An earlier patch fixed the hwpoison fault handling to encode the huge page size in the fault code of the page fault handler.
This is needed to report this information in SIGBUS to user space.
This is a straight forward patch to pass this information through to the signal handling in the x86 specific
fault.cCc Naoya Horiguchi <[email protected]>Signed-off-by Andi Kleen <[email protected]>--- arch/x86/mm/fault.c | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)arch/x86/mm/fault.c +1
-1@@ -11,6 +11,7 @@#include <linux/kprobes.h> /* __kprobes, ... */ #include <linux/mmiotrace.h> /* kmmio_handler, ... */ #include <linux/perf_event.h> /* perf_sw_event */ +#include <linux/hugetlb.h> /* hstate_index_to_shift */ #include <asm/traps.h> /* dotraplinkage, ... */ #include <asm/pgalloc.h> /* pgd_*(), ... */ @@ -160,15 +161,20 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr) static void force_sig_info_fault(int si_signo, int si_code, unsigned long address, -struct task_struct *tsk)
arch/x86/mm/fault.c is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr) · line 171
Quoted 10 lines
arch/x86/mm/fault.c +2
-1+ struct task_struct *tsk, int fault) { + unsigned lsb = 0;siginfo_t info; info.si_signo = si_signo; info.si_errno =0 ; info.si_code = si_code; info.si_addr = (void __user *)address; - info.si_addr_lsb = si_code ==BUS_MCEERR_AR ?PAGE_SHIFT :0 ;
Ah you changed the conditional 0..
Quoted 9 lines
arch/x86/mm/fault.c +5
-0+if (fault &VM_FAULT_HWPOISON_LARGE ) + lsb =hstate_index_to_shift (VM_FAULT_GET_HINDEX (fault)); +if (fault &VM_FAULT_HWPOISON ) + lsb =PAGE_SHIFT ; + info.si_addr_lsb = lsb;force_sig_info (si_signo, &info, tsk); }
arch/x86/mm/fault.c __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, · line 740
Quoted 5 lines
arch/x86/mm/fault.c +1
-1@@ -731,7 +737,7 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, tsk->thread.error_code = error_code | (address >=TASK_SIZE ); tsk->thread.trap_no =14 ; -force_sig_info_fault (SIGSEGV , si_code, address, tsk); +force_sig_info_fault (SIGSEGV , si_code, address, tsk,0 );
..and it's sure reasonable.
Thanks,
Fengguang
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>