diff options
author | Andi Kleen <ak@linux.intel.com> | 2010-10-06 15:45:00 -0400 |
---|---|---|
committer | Andi Kleen <ak@linux.intel.com> | 2010-10-08 03:32:46 -0400 |
commit | aa50d3a7aa8147b9e14dc9d5972a5d2359db4ef8 (patch) | |
tree | 68fae5060333dcc24c17e9dd00a87bd760d883e9 | |
parent | 6f39ce056ab2ab2d29b2fae4aed61ed0b485972f (diff) |
Encode huge page size for VM_FAULT_HWPOISON errors
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.
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: fengguang.wu@intel.com
Signed-off-by: Andi Kleen <ak@linux.intel.com>
-rw-r--r-- | include/linux/hugetlb.h | 6 | ||||
-rw-r--r-- | include/linux/mm.h | 12 | ||||
-rw-r--r-- | mm/hugetlb.c | 6 | ||||
-rw-r--r-- | mm/memory.c | 3 |
4 files changed, 22 insertions, 5 deletions
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 796f30e00806..943c76b3d4bb 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h | |||
@@ -307,6 +307,11 @@ static inline struct hstate *page_hstate(struct page *page) | |||
307 | return size_to_hstate(PAGE_SIZE << compound_order(page)); | 307 | return size_to_hstate(PAGE_SIZE << compound_order(page)); |
308 | } | 308 | } |
309 | 309 | ||
310 | static inline unsigned hstate_index_to_shift(unsigned index) | ||
311 | { | ||
312 | return hstates[index].order + PAGE_SHIFT; | ||
313 | } | ||
314 | |||
310 | #else | 315 | #else |
311 | struct hstate {}; | 316 | struct hstate {}; |
312 | #define alloc_huge_page_node(h, nid) NULL | 317 | #define alloc_huge_page_node(h, nid) NULL |
@@ -324,6 +329,7 @@ static inline unsigned int pages_per_huge_page(struct hstate *h) | |||
324 | { | 329 | { |
325 | return 1; | 330 | return 1; |
326 | } | 331 | } |
332 | #define hstate_index_to_shift(index) 0 | ||
327 | #endif | 333 | #endif |
328 | 334 | ||
329 | #endif /* _LINUX_HUGETLB_H */ | 335 | #endif /* _LINUX_HUGETLB_H */ |
diff --git a/include/linux/mm.h b/include/linux/mm.h index 74949fbef8c6..f7e9efc6720b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -718,12 +718,20 @@ static inline int page_mapped(struct page *page) | |||
718 | #define VM_FAULT_SIGBUS 0x0002 | 718 | #define VM_FAULT_SIGBUS 0x0002 |
719 | #define VM_FAULT_MAJOR 0x0004 | 719 | #define VM_FAULT_MAJOR 0x0004 |
720 | #define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */ | 720 | #define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */ |
721 | #define VM_FAULT_HWPOISON 0x0010 /* Hit poisoned page */ | 721 | #define VM_FAULT_HWPOISON 0x0010 /* Hit poisoned small page */ |
722 | #define VM_FAULT_HWPOISON_LARGE 0x0020 /* Hit poisoned large page. Index encoded in upper bits */ | ||
722 | 723 | ||
723 | #define VM_FAULT_NOPAGE 0x0100 /* ->fault installed the pte, not return page */ | 724 | #define VM_FAULT_NOPAGE 0x0100 /* ->fault installed the pte, not return page */ |
724 | #define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */ | 725 | #define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */ |
725 | 726 | ||
726 | #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_HWPOISON) | 727 | #define VM_FAULT_HWPOISON_LARGE_MASK 0xf000 /* encodes hpage index for large hwpoison */ |
728 | |||
729 | #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_HWPOISON | \ | ||
730 | VM_FAULT_HWPOISON_LARGE) | ||
731 | |||
732 | /* Encode hstate index for a hwpoisoned large page */ | ||
733 | #define VM_FAULT_SET_HINDEX(x) ((x) << 12) | ||
734 | #define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf) | ||
727 | 735 | ||
728 | /* | 736 | /* |
729 | * Can be called by the pagefault handler when it gets a VM_FAULT_OOM. | 737 | * Can be called by the pagefault handler when it gets a VM_FAULT_OOM. |
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 67cd03239b75..96991ded82fe 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c | |||
@@ -2589,7 +2589,8 @@ retry: | |||
2589 | * So we need to block hugepage fault by PG_hwpoison bit check. | 2589 | * So we need to block hugepage fault by PG_hwpoison bit check. |
2590 | */ | 2590 | */ |
2591 | if (unlikely(PageHWPoison(page))) { | 2591 | if (unlikely(PageHWPoison(page))) { |
2592 | ret = VM_FAULT_HWPOISON; | 2592 | ret = VM_FAULT_HWPOISON | |
2593 | VM_FAULT_SET_HINDEX(h - hstates); | ||
2593 | goto backout_unlocked; | 2594 | goto backout_unlocked; |
2594 | } | 2595 | } |
2595 | page_dup_rmap(page); | 2596 | page_dup_rmap(page); |
@@ -2656,7 +2657,8 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, | |||
2656 | migration_entry_wait(mm, (pmd_t *)ptep, address); | 2657 | migration_entry_wait(mm, (pmd_t *)ptep, address); |
2657 | return 0; | 2658 | return 0; |
2658 | } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) | 2659 | } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) |
2659 | return VM_FAULT_HWPOISON; | 2660 | return VM_FAULT_HWPOISON_LARGE | |
2661 | VM_FAULT_SET_HINDEX(h - hstates); | ||
2660 | } | 2662 | } |
2661 | 2663 | ||
2662 | ptep = huge_pte_alloc(mm, address, huge_page_size(h)); | 2664 | ptep = huge_pte_alloc(mm, address, huge_page_size(h)); |
diff --git a/mm/memory.c b/mm/memory.c index 0e18b4d649ec..c2d6dd315659 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
@@ -1450,7 +1450,8 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, | |||
1450 | if (ret & VM_FAULT_OOM) | 1450 | if (ret & VM_FAULT_OOM) |
1451 | return i ? i : -ENOMEM; | 1451 | return i ? i : -ENOMEM; |
1452 | if (ret & | 1452 | if (ret & |
1453 | (VM_FAULT_HWPOISON|VM_FAULT_SIGBUS)) | 1453 | (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE| |
1454 | VM_FAULT_SIGBUS)) | ||
1454 | return i ? i : -EFAULT; | 1455 | return i ? i : -EFAULT; |
1455 | BUG(); | 1456 | BUG(); |
1456 | } | 1457 | } |