linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thp: fix copy_page_rep GPF by testing is_huge_zero_pmd once only
@ 2014-01-12  9:25 Hugh Dickins
  2014-01-12 11:33 ` Kirill A. Shutemov
  0 siblings, 1 reply; 2+ messages in thread
From: Hugh Dickins @ 2014-01-12  9:25 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Andrew Morton, Kirill A. Shutemov, Sasha Levin, Mel Gorman,
	linux-kernel, linux-mm

We see General Protection Fault on RSI in copy_page_rep:
that RSI is what you get from a NULL struct page pointer.

RIP: 0010:[<ffffffff81154955>]  [<ffffffff81154955>] copy_page_rep+0x5/0x10
RSP: 0000:ffff880136e15c00  EFLAGS: 00010286
RAX: ffff880000000000 RBX: ffff880136e14000 RCX: 0000000000000200
RDX: 6db6db6db6db6db7 RSI: db73880000000000 RDI: ffff880dd0c00000
RBP: ffff880136e15c18 R08: 0000000000000200 R09: 000000000005987c
R10: 000000000005987c R11: 0000000000000200 R12: 0000000000000001
R13: ffffea00305aa000 R14: 0000000000000000 R15: 0000000000000000
FS:  00007f195752f700(0000) GS:ffff880c7fc20000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000093010000 CR3: 00000001458e1000 CR4: 00000000000027e0
Call Trace:
 [<ffffffff810f2835>] ? copy_user_highpage.isra.43+0x65/0x80
 [<ffffffff812654b2>] copy_user_huge_page+0x93/0xab
 [<ffffffff8127cc76>] do_huge_pmd_wp_page+0x710/0x815
 [<ffffffff81055ab8>] handle_mm_fault+0x15d8/0x1d70
 [<ffffffff814f909d>] __do_page_fault+0x14d/0x840
 [<ffffffff810a13ad>] ? SYSC_recvfrom+0x10d/0x210
 [<ffffffff814f97bf>] do_page_fault+0x2f/0x90
 [<ffffffff814f6032>] page_fault+0x22/0x30

do_huge_pmd_wp_page() tests is_huge_zero_pmd(orig_pmd) four times:
but since shrink_huge_zero_page() can free the huge_zero_page, and
we have no hold of our own on it here (except where the fourth test
holds page_table_lock and has checked pmd_same), it's possible for
it to answer yes the first time, but no to the second or third test.
Change all those last three to tests for NULL page.

(Note: this is not the same issue as trinity's DEBUG_PAGEALLOC BUG
in copy_page_rep with RSI: ffff88009c422000, reported by Sasha Levin
in https://lkml.org/lkml/2013/3/29/103.  I believe that one is due
to the source page being split, and a tail page freed, while copy
is in progress; and not a problem without DEBUG_PAGEALLOC, since
the pmd_same check will prevent a miscopy from being made visible.)

Fixes: 97ae17497e99 ("thp: implement refcounting for huge zero page")
Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: stable@vger.kernel.org # v3.10 v3.11 v3.12
---

 mm/huge_memory.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- 3.13-rc7/mm/huge_memory.c	2014-01-04 22:30:56.388815704 -0800
+++ linux/mm/huge_memory.c	2014-01-12 00:54:09.292491631 -0800
@@ -1154,7 +1154,7 @@ alloc:
 		new_page = NULL;
 
 	if (unlikely(!new_page)) {
-		if (is_huge_zero_pmd(orig_pmd)) {
+		if (!page) {
 			ret = do_huge_pmd_wp_zero_page_fallback(mm, vma,
 					address, pmd, orig_pmd, haddr);
 		} else {
@@ -1181,7 +1181,7 @@ alloc:
 
 	count_vm_event(THP_FAULT_ALLOC);
 
-	if (is_huge_zero_pmd(orig_pmd))
+	if (!page)
 		clear_huge_page(new_page, haddr, HPAGE_PMD_NR);
 	else
 		copy_user_huge_page(new_page, page, haddr, vma, HPAGE_PMD_NR);
@@ -1207,7 +1207,7 @@ alloc:
 		page_add_new_anon_rmap(new_page, vma, haddr);
 		set_pmd_at(mm, haddr, pmd, entry);
 		update_mmu_cache_pmd(vma, address, pmd);
-		if (is_huge_zero_pmd(orig_pmd)) {
+		if (!page) {
 			add_mm_counter(mm, MM_ANONPAGES, HPAGE_PMD_NR);
 			put_huge_zero_page();
 		} else {

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] thp: fix copy_page_rep GPF by testing is_huge_zero_pmd once only
  2014-01-12  9:25 [PATCH] thp: fix copy_page_rep GPF by testing is_huge_zero_pmd once only Hugh Dickins
@ 2014-01-12 11:33 ` Kirill A. Shutemov
  0 siblings, 0 replies; 2+ messages in thread
From: Kirill A. Shutemov @ 2014-01-12 11:33 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Linus Torvalds, Andrew Morton, Kirill A. Shutemov, Sasha Levin,
	Mel Gorman, linux-kernel, linux-mm

On Sun, Jan 12, 2014 at 01:25:21AM -0800, Hugh Dickins wrote:
> We see General Protection Fault on RSI in copy_page_rep:
> that RSI is what you get from a NULL struct page pointer.
> 
> RIP: 0010:[<ffffffff81154955>]  [<ffffffff81154955>] copy_page_rep+0x5/0x10
> RSP: 0000:ffff880136e15c00  EFLAGS: 00010286
> RAX: ffff880000000000 RBX: ffff880136e14000 RCX: 0000000000000200
> RDX: 6db6db6db6db6db7 RSI: db73880000000000 RDI: ffff880dd0c00000
> RBP: ffff880136e15c18 R08: 0000000000000200 R09: 000000000005987c
> R10: 000000000005987c R11: 0000000000000200 R12: 0000000000000001
> R13: ffffea00305aa000 R14: 0000000000000000 R15: 0000000000000000
> FS:  00007f195752f700(0000) GS:ffff880c7fc20000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000093010000 CR3: 00000001458e1000 CR4: 00000000000027e0
> Call Trace:
>  [<ffffffff810f2835>] ? copy_user_highpage.isra.43+0x65/0x80
>  [<ffffffff812654b2>] copy_user_huge_page+0x93/0xab
>  [<ffffffff8127cc76>] do_huge_pmd_wp_page+0x710/0x815
>  [<ffffffff81055ab8>] handle_mm_fault+0x15d8/0x1d70
>  [<ffffffff814f909d>] __do_page_fault+0x14d/0x840
>  [<ffffffff810a13ad>] ? SYSC_recvfrom+0x10d/0x210
>  [<ffffffff814f97bf>] do_page_fault+0x2f/0x90
>  [<ffffffff814f6032>] page_fault+0x22/0x30
> 
> do_huge_pmd_wp_page() tests is_huge_zero_pmd(orig_pmd) four times:
> but since shrink_huge_zero_page() can free the huge_zero_page, and
> we have no hold of our own on it here (except where the fourth test
> holds page_table_lock and has checked pmd_same), it's possible for
> it to answer yes the first time, but no to the second or third test.
> Change all those last three to tests for NULL page.
> 
> (Note: this is not the same issue as trinity's DEBUG_PAGEALLOC BUG
> in copy_page_rep with RSI: ffff88009c422000, reported by Sasha Levin
> in https://lkml.org/lkml/2013/3/29/103.  I believe that one is due
> to the source page being split, and a tail page freed, while copy
> is in progress; and not a problem without DEBUG_PAGEALLOC, since
> the pmd_same check will prevent a miscopy from being made visible.)
> 
> Fixes: 97ae17497e99 ("thp: implement refcounting for huge zero page")
> Signed-off-by: Hugh Dickins <hughd@google.com>
> Cc: stable@vger.kernel.org # v3.10 v3.11 v3.12

Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-12 11:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-12  9:25 [PATCH] thp: fix copy_page_rep GPF by testing is_huge_zero_pmd once only Hugh Dickins
2014-01-12 11:33 ` Kirill A. Shutemov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox