Received: by 10.223.176.5 with SMTP id f5csp3749555wra; Mon, 29 Jan 2018 19:00:55 -0800 (PST) X-Google-Smtp-Source: AH8x227sidCETcwPDR3X5TSh5jfQYwRpvqHUikbW85/c2wDVKPAeQa5E3TXuhwnfz1Eb4O0H461E X-Received: by 10.101.72.69 with SMTP id i5mr19362047pgs.9.1517281255292; Mon, 29 Jan 2018 19:00:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517281255; cv=none; d=google.com; s=arc-20160816; b=kRisjNXnU8n7O0cGLcmsSZzKflCyESdyFQVW9i+fY0WWGM6dT2SJcLYO5roB4kgJD7 rQeqX92EI5193maRaMcn/OPM3iGpYCj0wOuaSKGVgqTL8Sducd5yjhfmiZrNbz/cPD2S gDmoiCZ/i/ZJ0nP/YCaVjN/IV4p01O6h4oTNDmKrgdmlzckAoTPNddl4q5z23XJdGHcQ xqHgdIIMeARrpO9mnoi+Ed95CfI3MpFJchYAi6Ju08ClY4F/O1uZ/5deLIeA6T9n8eRV e+l3QLYMQO7ty0WZGQqm99kNkvWUgbKu5k4Ls6SOrTpgyL0IO3uZXkg4VIBDt7xmBZ47 OajQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature:arc-authentication-results; bh=e+NL6D6Q15W9uLFFv6inwoL0f7VwiYdePiFFMbi9Lx0=; b=FK5Mei8Lo2MV28T2Gct6U/hhniZNzqR4IAI2+gnWWz4zzUJCjSVfdlHtctLqYrB/C5 T1h6KSz3sjbD3jw3FWVkXcptxK3xX9YHx4X4K6OSlIumtIZHy/aoZe6nXwVl34VgW6b0 dJbYeJ0Np1wbakzY0LIoWcRsF7Fm5N7szRmM/Wusdn3uJTphmoR4exkUDNjeo6Sph+ax TpSULQ0quoQxER1HCw8MzZOHm1yg4jAXaonyjqTZv9ypwnOIkkIRDma4VEI5A8gkmgHx upKAuumtEBa3+uGkjMihAJpU07g2gTYFv0KJ4WuZnNQgZDk4il3rsmWn8B7n9lAY50+o 1BEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=qRNVEDm3; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=mtmgS6D+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n15si575027pfh.258.2018.01.29.19.00.40; Mon, 29 Jan 2018 19:00:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=qRNVEDm3; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=mtmgS6D+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752628AbeA3DAP (ORCPT + 99 others); Mon, 29 Jan 2018 22:00:15 -0500 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:59019 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752566AbeA3DAN (ORCPT ); Mon, 29 Jan 2018 22:00:13 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 1C6C420991; Mon, 29 Jan 2018 22:00:13 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute3.internal (MEProxy); Mon, 29 Jan 2018 22:00:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=e+NL6D6Q15W9uLFFv6inwoL0f7VwiYdePiFFMbi9L x0=; b=qRNVEDm3PMGeiPEts+aVj5Cts+ESiy50YHby4bkInx9BQquTBzTfqf9fw ErfBlyb6kNl+zhR142QTk6EwxOpSYbZ9/MDtmuGvK/+fRJR8VyiiP14q7vHoRkVI vlulAQIOOwHKIAH64DJzC8LrmVzYY4NY8goUPC8IBFvmKBq6ajBCqb/dMCT1gC7u RITo9cYGu220HBaUtsKsvdr76aQKkQCGZA4hxO1UBF6tIAwIL7V+WrB//mscNhUf nL8F4sJ88JS3NbfZjwBwaGUoFcvCW/4qP0Ue2Px7paykWBRBpx1Hs5ftUHYpI3yW fKpjAl4HUHQD8NHCEBvo9xi3IzBcg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=e+NL6D6Q15W9uLFFv 6inwoL0f7VwiYdePiFFMbi9Lx0=; b=mtmgS6D+WPDn+tpaHMp1bQfnjs4sRtIyb cvSk2rSSLBRI/XH4OSpeBlaPn64v3BeA13/N3nBBeqJIHQSHZL9rvnc8R2UeL5Wa PXKSr3ciRT3PfAdWT/vjnqrjwkXSCE0yvGmQktqof1hMIlIz7KMVTbbVodBYDqXH v5bbr07y9u9Fm2R7EAXLqyKrztaRmjYeldammEg1yA0SQmEaJODJJvhM+6XlbSD2 XrKrn2B6/3XwUsIUvLo0DB1uoNeIRN6gY45QrZ2gD5dJxKPacxy1cGsHKs3AfTdq Ktflr53BvzzbCjcB8PHJ0U82Ot060Hxnc+mgxAgrwC82JFJK6Q5gA== X-ME-Sender: Received: from tenansix.rutgers.edu (pool-165-230-225-59.nat.rutgers.edu [165.230.225.59]) by mail.messagingengine.com (Postfix) with ESMTPA id BC1EC240B6; Mon, 29 Jan 2018 22:00:12 -0500 (EST) From: Zi Yan To: Andrew Morton Cc: Michal Hocko , "Kirill A . Shutemov" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Zi Yan Subject: [PATCH] Lock mmap_sem when calling migrate_pages() in do_move_pages_to_node() Date: Mon, 29 Jan 2018 22:00:11 -0500 Message-Id: <20180130030011.4310-1-zi.yan@sent.com> X-Mailer: git-send-email 2.15.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zi Yan migrate_pages() requires at least down_read(mmap_sem) to protect related page tables and VMAs from changing. Let's do it in do_page_moves() for both do_move_pages_to_node() and add_page_for_migration(). Also add this lock requirement in the comment of migrate_pages(). Signed-off-by: Zi Yan --- mm/migrate.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 5d0dc7b85f90..52d029953c32 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1354,6 +1354,9 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, * or free list only if ret != 0. * * Returns the number of pages that were not migrated, or an error code. + * + * The caller must hold at least down_read(mmap_sem) for to-be-migrated pages + * to protect related page tables and VMAs from changing. */ int migrate_pages(struct list_head *from, new_page_t get_new_page, free_page_t put_new_page, unsigned long private, @@ -1457,6 +1460,12 @@ static int store_status(int __user *status, int start, int value, int nr) return 0; } +/* + * Migrates the pages from pagelist and put back those not migrated. + * + * The caller must at least hold down_read(mmap_sem), which is required + * for migrate_pages() + */ static int do_move_pages_to_node(struct mm_struct *mm, struct list_head *pagelist, int node) { @@ -1487,7 +1496,6 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, unsigned int follflags; int err; - down_read(&mm->mmap_sem); err = -EFAULT; vma = find_vma(mm, addr); if (!vma || addr < vma->vm_start || !vma_migratable(vma)) @@ -1540,7 +1548,6 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, */ put_page(page); out: - up_read(&mm->mmap_sem); return err; } @@ -1561,6 +1568,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, migrate_prep(); + down_read(&mm->mmap_sem); for (i = start = 0; i < nr_pages; i++) { const void __user *p; unsigned long addr; @@ -1628,6 +1636,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, if (!err) err = err1; out: + up_read(&mm->mmap_sem); return err; } -- 2.15.1