From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: stable-review@vger.kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
Hugh Dickins <hughd@google.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Mel Gorman <mgorman@suse.de>
Subject: [23/27] mm: fix race between mremap and removing migration entry
Date: Sun, 23 Oct 2011 08:24:51 +0200 [thread overview]
Message-ID: <20111023062540.855550059@pistachio.kroah.org> (raw)
In-Reply-To: <20111023062833.GA8126@kroah.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2637 bytes --]
3.0-stable review patch. If anyone has any objections, please let us know.
------------------
From: Hugh Dickins <hughd@google.com>
commit 486cf46f3f9be5f2a966016c1a8fe01e32cde09e upstream.
I don't usually pay much attention to the stale "? " addresses in
stack backtraces, but this lucky report from Pawel Sikora hints that
mremap's move_ptes() has inadequate locking against page migration.
3.0 BUG_ON(!PageLocked(p)) in migration_entry_to_page():
kernel BUG at include/linux/swapops.h:105!
RIP: 0010:[<ffffffff81127b76>] [<ffffffff81127b76>]
migration_entry_wait+0x156/0x160
[<ffffffff811016a1>] handle_pte_fault+0xae1/0xaf0
[<ffffffff810feee2>] ? __pte_alloc+0x42/0x120
[<ffffffff8112c26b>] ? do_huge_pmd_anonymous_page+0xab/0x310
[<ffffffff81102a31>] handle_mm_fault+0x181/0x310
[<ffffffff81106097>] ? vma_adjust+0x537/0x570
[<ffffffff81424bed>] do_page_fault+0x11d/0x4e0
[<ffffffff81109a05>] ? do_mremap+0x2d5/0x570
[<ffffffff81421d5f>] page_fault+0x1f/0x30
mremap's down_write of mmap_sem, together with i_mmap_mutex or lock,
and pagetable locks, were good enough before page migration (with its
requirement that every migration entry be found) came in, and enough
while migration always held mmap_sem; but not enough nowadays, when
there's memory hotremove and compaction.
The danger is that move_ptes() lets a migration entry dodge around
behind remove_migration_pte()'s back, so it's in the old location when
looking at the new, then in the new location when looking at the old.
Either mremap's move_ptes() must additionally take anon_vma lock(), or
migration's remove_migration_pte() must stop peeking for is_swap_entry()
before it takes pagetable lock.
Consensus chooses the latter: we prefer to add overhead to migration
than to mremapping, which gets used by JVMs and by exec stack setup.
Reported-and-tested-by: Paweł Sikora <pluto@agmk.net>
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Andrea Arcangeli <aarcange@redhat.com>
Acked-by: Mel Gorman <mgorman@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
mm/migrate.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -120,10 +120,10 @@ static int remove_migration_pte(struct p
ptep = pte_offset_map(pmd, addr);
- if (!is_swap_pte(*ptep)) {
- pte_unmap(ptep);
- goto out;
- }
+ /*
+ * Peek to check is_swap_pte() before taking ptlock? No, we
+ * can race mremap's move_ptes(), which skips anon_vma lock.
+ */
ptl = pte_lockptr(mm, pmd);
}
next prev parent reply other threads:[~2011-10-23 6:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-23 6:28 [00/27] 3.0.8-stable review Greg KH
2011-10-23 6:24 ` [01/27] ARM: 7113/1: mm: Align bank start to MAX_ORDER_NR_PAGES Greg KH
2011-10-23 6:24 ` [02/27] ARM: 7117/1: perf: fix HW_CACHE_* events on Cortex-A9 Greg KH
2011-10-23 6:24 ` [03/27] HID: usbhid: Add support for SiGma Micro chip Greg KH
2011-10-23 6:24 ` [04/27] hwmon: (w83627ehf) Properly report thermal diode sensors Greg KH
2011-10-23 6:24 ` [05/27] Avoid using variable-length arrays in kernel/sys.c Greg KH
2011-10-23 6:24 ` [06/27] drm/radeon/kms/atom: fix handling of FB scratch indices Greg KH
2011-10-23 6:24 ` [07/27] cputimer: Cure lock inversion Greg KH
2011-10-23 6:24 ` [08/27] fuse: fix memory leak Greg KH
2011-10-23 6:24 ` [09/27] Platform: fix samsung-laptop DMI identification for N150/N210/220/N230 Greg KH
2011-10-23 6:24 ` [10/27] HID: magicmouse: ignore ivalid report id while switching modes, v2 Greg KH
2011-10-23 6:24 ` [11/27] [media] uvcvideo: Fix crash when linking entities Greg KH
2011-10-23 6:24 ` [12/27] hfsplus: ensure bio requests are not smaller than the hardware sectors Greg KH
2011-10-23 6:24 ` [13/27] drm/ttm: ensure ttm for new node is bound before calling move_notify() Greg KH
2011-10-23 6:24 ` [14/27] drm/ttm: unbind ttm before destroying node in accel move cleanup Greg KH
2011-10-23 6:24 ` [15/27] CIFS: Fix ERR_PTR dereference in cifs_get_root Greg KH
2011-10-23 6:24 ` [16/27] xfs: start periodic workers later Greg KH
2011-10-23 6:24 ` [17/27] xfs: use a cursor for bulk AIL insertion Greg KH
2011-10-23 6:24 ` [18/27] xfs: do not update xa_last_pushed_lsn for locked items Greg KH
2011-10-23 6:24 ` [19/27] xfs: force the log if we encounter pinned buffers in .iop_pushbuf Greg KH
2011-10-23 6:24 ` [20/27] xfs: revert to using a kthread for AIL pushing Greg KH
2011-10-23 6:24 ` [21/27] firewire: sbp2: fix panic after rmmod with slow targets Greg KH
2011-10-23 6:24 ` [22/27] VFS: Fix automount for negative autofs dentries Greg KH
2011-10-23 7:35 ` Linus Torvalds
2011-10-23 8:36 ` Greg KH
2011-10-23 21:09 ` Miklos Szeredi
2011-10-24 14:22 ` Greg KH
2011-10-23 11:59 ` Ian Kent
2011-11-01 15:51 ` David Howells
2011-10-23 11:41 ` Ian Kent
2011-10-23 11:48 ` Greg KH
2011-10-23 12:07 ` Ian Kent
2011-10-23 6:24 ` Greg KH [this message]
2011-10-23 6:24 ` [24/27] x25: Prevent skb overreads when checking call user data Greg KH
2011-10-23 6:24 ` [25/27] crypto: ghash - Avoid null pointer dereference if no key is set Greg KH
2011-10-23 6:24 ` [26/27] ALSA: HDA: conexant support for Lenovo T520/W520 Greg KH
2011-10-23 6:24 ` [27/27] ALSA: hda - Add position_fix quirk for Dell Inspiron 1010 Greg KH
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=20111023062540.855550059@pistachio.kroah.org \
--to=gregkh@suse.de \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=stable-review@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®