]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commit - mm/mlock.c
thp: fix another corner case of munlock() vs. THPs
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fri, 10 Mar 2017 00:17:23 +0000 (16:17 -0800)
committerTim Gardner <tim.gardner@canonical.com>
Wed, 15 Mar 2017 15:32:11 +0000 (10:32 -0500)
commitcd29742eefcbd8fe3ff3c797e6dfe9f5b6079120
treee4a0f40a170736c348f9ef9b898882af5d6583b6
parente221ab246cd12e6a70137e928304cfd342ad4f9a
thp: fix another corner case of munlock() vs. THPs

BugLink: http://bugs.launchpad.net/bugs/1673118
commit 6ebb4a1b848fe75323135f93e72c78f8780fd268 upstream.

The following test case triggers BUG() in munlock_vma_pages_range():

int main(int argc, char *argv[])
{
int fd;

system("mount -t tmpfs -o huge=always none /mnt");
fd = open("/mnt/test", O_CREAT | O_RDWR);
ftruncate(fd, 4UL << 20);
mmap(NULL, 4UL << 20, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_FIXED | MAP_LOCKED, fd, 0);
mmap(NULL, 4096, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_LOCKED, fd, 0);
munlockall();
return 0;
}

The second mmap() create PTE-mapping of the first huge page in file.  It
makes kernel munlock the page as we never keep PTE-mapped page mlocked.

On munlockall() when we handle vma created by the first mmap(),
munlock_vma_page() returns page_mask == 0, as the page is not mlocked
anymore.  On next iteration follow_page_mask() return tail page, but
page_mask is HPAGE_NR_PAGES - 1.  It makes us skip to the first tail
page of the next huge page and step on
VM_BUG_ON_PAGE(PageMlocked(page)).

The fix is not use the page_mask from follow_page_mask() at all.  It has
no use for us.

Link: http://lkml.kernel.org/r/20170302150252.34120-1-kirill.shutemov@linux.intel.com
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
mm/mlock.c