All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Sasha Levin <sasha.levin@oracle.com>, Hugh Dickins <hughd@google.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Rientjes <rientjes@google.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Mel Gorman <mgorman@suse.de>,
	Dave Jones <davej@redhat.com>, linux-mm <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: mm: BUG in do_huge_pmd_wp_page
Date: Mon, 7 Apr 2014 17:48:35 +0300	[thread overview]
Message-ID: <20140407144835.GA17774@node.dhcp.inet.fi> (raw)
In-Reply-To: <533F09F0.1050206@oracle.com>

On Fri, Apr 04, 2014 at 03:37:20PM -0400, Sasha Levin wrote:
> And another ping exactly a year later :)

I think we could "fix" this false positive with the patch below
(untested), but it's ugly and doesn't add much value.

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 6ac89e9f82ef..65ac113037e4 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1053,6 +1053,7 @@ int do_huge_pmd_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	unsigned long haddr;
 	unsigned long mmun_start;	/* For mmu_notifiers */
 	unsigned long mmun_end;		/* For mmu_notifiers */
+	pmd_t entry;
 
 	ptl = pmd_lockptr(mm, pmd);
 	VM_BUG_ON(!vma->anon_vma);
@@ -1115,42 +1116,45 @@ alloc:
 
 	count_vm_event(THP_FAULT_ALLOC);
 
+	mmun_start = haddr;
+	mmun_end   = haddr + HPAGE_PMD_SIZE;
+	mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
+
+	if (IS_ENABLED(CONFIG_DEBUG_PAGEALLOC)) {
+		spin_lock(ptl);
+		if (unlikely(!pmd_same(*pmd, orig_pmd)))
+			goto out_race;
+	}
+
 	if (!page)
 		clear_huge_page(new_page, haddr, HPAGE_PMD_NR);
 	else
 		copy_user_huge_page(new_page, page, haddr, vma, HPAGE_PMD_NR);
 	__SetPageUptodate(new_page);
 
-	mmun_start = haddr;
-	mmun_end   = haddr + HPAGE_PMD_SIZE;
-	mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
-
-	spin_lock(ptl);
+	if (!IS_ENABLED(CONFIG_DEBUG_PAGEALLOC)) {
+		spin_lock(ptl);
+		if (unlikely(!pmd_same(*pmd, orig_pmd)))
+			goto out_race;
+	}
 	if (page)
 		put_page(page);
-	if (unlikely(!pmd_same(*pmd, orig_pmd))) {
-		spin_unlock(ptl);
-		mem_cgroup_uncharge_page(new_page);
-		put_page(new_page);
-		goto out_mn;
+
+	entry = mk_huge_pmd(new_page, vma->vm_page_prot);
+	entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
+	pmdp_clear_flush(vma, haddr, pmd);
+	page_add_new_anon_rmap(new_page, vma, haddr);
+	set_pmd_at(mm, haddr, pmd, entry);
+	update_mmu_cache_pmd(vma, address, pmd);
+	if (!page) {
+		add_mm_counter(mm, MM_ANONPAGES, HPAGE_PMD_NR);
+		put_huge_zero_page();
 	} else {
-		pmd_t entry;
-		entry = mk_huge_pmd(new_page, vma->vm_page_prot);
-		entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
-		pmdp_clear_flush(vma, haddr, pmd);
-		page_add_new_anon_rmap(new_page, vma, haddr);
-		set_pmd_at(mm, haddr, pmd, entry);
-		update_mmu_cache_pmd(vma, address, pmd);
-		if (!page) {
-			add_mm_counter(mm, MM_ANONPAGES, HPAGE_PMD_NR);
-			put_huge_zero_page();
-		} else {
-			VM_BUG_ON_PAGE(!PageHead(page), page);
-			page_remove_rmap(page);
-			put_page(page);
-		}
-		ret |= VM_FAULT_WRITE;
+		VM_BUG_ON_PAGE(!PageHead(page), page);
+		page_remove_rmap(page);
+		put_page(page);
 	}
+	ret |= VM_FAULT_WRITE;
 	spin_unlock(ptl);
 out_mn:
 	mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
@@ -1159,6 +1163,13 @@ out:
 out_unlock:
 	spin_unlock(ptl);
 	return ret;
+out_race:
+	spin_unlock(ptl);
+	if (page)
+		put_page(page);
+	mem_cgroup_uncharge_page(new_page);
+	put_page(new_page);
+	goto out_mn;
 }
 
 struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
-- 
 Kirill A. Shutemov

  reply	other threads:[~2014-04-07 14:48 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-29 13:04 mm: BUG in do_huge_pmd_wp_page Sasha Levin
2013-03-29 13:04 ` Sasha Levin
2013-04-04 14:03 ` Sasha Levin
2013-04-04 14:03   ` Sasha Levin
2013-04-04 14:30   ` Kirill A. Shutemov
2013-04-04 14:30     ` Kirill A. Shutemov
2013-04-04 14:37     ` Sasha Levin
2013-04-04 14:37       ` Sasha Levin
2013-04-04 16:28       ` Kirill A. Shutemov
2013-04-04 16:28         ` Kirill A. Shutemov
2013-04-04 21:54         ` Sasha Levin
2013-04-04 21:54           ` Sasha Levin
2014-04-04 19:37   ` Sasha Levin
2014-04-04 19:37     ` Sasha Levin
2014-04-07 14:48     ` Kirill A. Shutemov [this message]
2014-04-07 14:56       ` Sasha Levin
2014-04-07 14:56         ` Sasha Levin
2014-04-07 19:40       ` Sasha Levin
2014-04-07 19:40         ` Sasha Levin
2014-04-07 20:11         ` Kirill A. Shutemov
2014-05-15 17:31           ` Sasha Levin
2014-05-15 17:31             ` Sasha Levin
2014-05-15 17:37             ` Hugh Dickins
2014-05-15 17:37               ` Hugh Dickins
2014-05-15 17:43               ` Sasha Levin
2014-05-15 17:43                 ` Sasha Levin
2014-05-15 17:58                 ` Hugh Dickins
2014-05-15 17:58                   ` Hugh Dickins
2013-04-10  8:02 ` Minchan Kim
2013-04-10  8:02   ` Minchan Kim
2013-04-11 13:18   ` Kirill A. Shutemov
2013-04-11 13:18     ` Kirill A. Shutemov
2013-04-14  7:13     ` Minchan Kim
2013-04-14  7:13       ` Minchan Kim
2013-04-11 14:55   ` Sasha Levin
2013-04-11 14:55     ` Sasha Levin
2013-04-11 15:13     ` Kirill A. Shutemov
2013-04-11 15:13       ` Kirill A. Shutemov
2013-04-11 15:14       ` Sasha Levin
2013-04-24 22:46         ` Andrew Morton
2013-04-24 22:46           ` Andrew Morton
2013-04-26  0:51           ` Sasha Levin
2013-04-26  0:51             ` Sasha Levin
2013-04-26  2:01             ` Dave Jones
2013-04-26  2:01               ` Dave Jones
2013-04-26  3:12               ` Sasha Levin
2013-04-26  3:12                 ` Sasha Levin
2014-02-04  3:01               ` Sasha Levin
2014-02-04  3:01                 ` Sasha Levin
2014-02-04  3:59                 ` Hugh Dickins
2014-02-04  3:59                   ` Hugh Dickins
2014-02-04 16:58                   ` Kirill A. Shutemov
2014-02-04 16:58                     ` Kirill A. Shutemov
2014-02-05 18:12                   ` Sasha Levin
2014-02-05 18:12                     ` Sasha Levin
2014-02-05 22:50                     ` Hugh Dickins
2014-02-05 22:50                       ` Hugh Dickins
2013-04-24 22:51   ` H. Peter Anvin
2013-04-24 22:51     ` H. Peter Anvin
2013-04-24 23:40     ` Simon Jeons
2013-04-26  2:28       ` H. Peter Anvin
2013-04-26  2:28         ` H. Peter Anvin
2013-04-26  1:30     ` Minchan Kim
2013-04-26  1:30       ` Minchan Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140407144835.GA17774@node.dhcp.inet.fi \
    --to=kirill@shutemov.name \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=davej@redhat.com \
    --cc=hpa@zytor.com \
    --cc=hughd@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=rientjes@google.com \
    --cc=sasha.levin@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.