Commit 16fd0fe4 authored by yalin wang's avatar yalin wang Committed by Linus Torvalds

mm: fix kernel crash in khugepaged thread

This crash is caused by NULL pointer deference, in page_to_pfn() marco,
when page == NULL :

  Unable to handle kernel NULL pointer dereference at virtual address 00000000
  Internal error: Oops: 94000006 [#1] SMP
  Modules linked in:
  CPU: 1 PID: 26 Comm: khugepaged Tainted: G        W       4.3.0-rc6-next-20151022ajb-00001-g32f3386-dirty #3
  PC is at khugepaged+0x378/0x1af8
  LR is at khugepaged+0x418/0x1af8
  Process khugepaged (pid: 26, stack limit = 0xffffffc079638020)
  Call trace:
    khugepaged+0x378/0x1af8
    kthread+0xdc/0xf4
    ret_from_fork+0xc/0x40
  Code: 35001700 f0002c60 aa0703e3 f9009fa0 (f94000e0)
  ---[ end trace 637503d8e28ae69e  ]---
  Kernel panic - not syncing: Fatal exception
  CPU2: stopping
  CPU: 2 PID: 0 Comm: swapper/2 Tainted: G      D W       4.3.0-rc6-next-20151022ajb-00001-g32f3386-dirty #3
  Hardware name: linux,dummy-virt (DT)

[akpm@linux-foundation.org: fix fat-fingered merge resolution]
Signed-off-by: default avataryalin wang <yalin.wang2010@gmail.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Acked-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7162a1e8
...@@ -46,10 +46,10 @@ SCAN_STATUS ...@@ -46,10 +46,10 @@ SCAN_STATUS
TRACE_EVENT(mm_khugepaged_scan_pmd, TRACE_EVENT(mm_khugepaged_scan_pmd,
TP_PROTO(struct mm_struct *mm, unsigned long pfn, bool writable, TP_PROTO(struct mm_struct *mm, struct page *page, bool writable,
bool referenced, int none_or_zero, int status), bool referenced, int none_or_zero, int status),
TP_ARGS(mm, pfn, writable, referenced, none_or_zero, status), TP_ARGS(mm, page, writable, referenced, none_or_zero, status),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(struct mm_struct *, mm) __field(struct mm_struct *, mm)
...@@ -62,7 +62,7 @@ TRACE_EVENT(mm_khugepaged_scan_pmd, ...@@ -62,7 +62,7 @@ TRACE_EVENT(mm_khugepaged_scan_pmd,
TP_fast_assign( TP_fast_assign(
__entry->mm = mm; __entry->mm = mm;
__entry->pfn = pfn; __entry->pfn = page ? page_to_pfn(page) : -1;
__entry->writable = writable; __entry->writable = writable;
__entry->referenced = referenced; __entry->referenced = referenced;
__entry->none_or_zero = none_or_zero; __entry->none_or_zero = none_or_zero;
...@@ -104,10 +104,10 @@ TRACE_EVENT(mm_collapse_huge_page, ...@@ -104,10 +104,10 @@ TRACE_EVENT(mm_collapse_huge_page,
TRACE_EVENT(mm_collapse_huge_page_isolate, TRACE_EVENT(mm_collapse_huge_page_isolate,
TP_PROTO(unsigned long pfn, int none_or_zero, TP_PROTO(struct page *page, int none_or_zero,
bool referenced, bool writable, int status), bool referenced, bool writable, int status),
TP_ARGS(pfn, none_or_zero, referenced, writable, status), TP_ARGS(page, none_or_zero, referenced, writable, status),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(unsigned long, pfn) __field(unsigned long, pfn)
...@@ -118,7 +118,7 @@ TRACE_EVENT(mm_collapse_huge_page_isolate, ...@@ -118,7 +118,7 @@ TRACE_EVENT(mm_collapse_huge_page_isolate,
), ),
TP_fast_assign( TP_fast_assign(
__entry->pfn = pfn; __entry->pfn = page ? page_to_pfn(page) : -1;
__entry->none_or_zero = none_or_zero; __entry->none_or_zero = none_or_zero;
__entry->referenced = referenced; __entry->referenced = referenced;
__entry->writable = writable; __entry->writable = writable;
......
...@@ -2072,7 +2072,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -2072,7 +2072,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
if (likely(writable)) { if (likely(writable)) {
if (likely(referenced)) { if (likely(referenced)) {
result = SCAN_SUCCEED; result = SCAN_SUCCEED;
trace_mm_collapse_huge_page_isolate(page_to_pfn(page), none_or_zero, trace_mm_collapse_huge_page_isolate(page, none_or_zero,
referenced, writable, result); referenced, writable, result);
return 1; return 1;
} }
...@@ -2082,7 +2082,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -2082,7 +2082,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
out: out:
release_pte_pages(pte, _pte); release_pte_pages(pte, _pte);
trace_mm_collapse_huge_page_isolate(page_to_pfn(page), none_or_zero, trace_mm_collapse_huge_page_isolate(page, none_or_zero,
referenced, writable, result); referenced, writable, result);
return 0; return 0;
} }
...@@ -2580,7 +2580,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, ...@@ -2580,7 +2580,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
collapse_huge_page(mm, address, hpage, vma, node); collapse_huge_page(mm, address, hpage, vma, node);
} }
out: out:
trace_mm_khugepaged_scan_pmd(mm, page_to_pfn(page), writable, referenced, trace_mm_khugepaged_scan_pmd(mm, page, writable, referenced,
none_or_zero, result); none_or_zero, result);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment