From patchwork Mon Jun 19 09:17:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 105807 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp781581qgd; Mon, 19 Jun 2017 02:18:51 -0700 (PDT) X-Received: by 10.99.56.82 with SMTP id h18mr19075351pgn.52.1497863931842; Mon, 19 Jun 2017 02:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497863931; cv=none; d=google.com; s=arc-20160816; b=c0Ewgz50q0Rbvk/r+d0ZId6lhlYNadmwFoQGHC2C8tuy9QLEzyhG3xcrElE8d8wxl8 AlT6Ah2NUerN7lwwwRcPxFrFBHF/axQ43C2ezZ2FwRU7W9Y2r7K5/1TXivInfr5bHpYn Y6DMIoiaZFgiYMS+QMOdslR+h9dyPxp79uvHMrsBNQc4khqSrTbSJvI6no+l77Fjkb+p 83m1ZDhRlOflOWLZodOGqKHyz0NPHy6lJDumoGrecRp2EJM9nV+ojS6CcgvVwRwTC68I CtpfWqf/nARixijEXWnlFfCV6aUjyhXD+yIGgey6PaixckqTpYywx9WYIF6rOS/qkOsS CptQ== 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 :arc-authentication-results; bh=Y70dVvoEwJCvZd5NXSQTcIWeqoa0ZBo+m71Tp+LmrlM=; b=jjwYmpgAH0G62VdX1TU0cyHZ0hyzQxOwffOWp83UwAhe0ch4XvP1CC01L9oCC37PF9 DZYDYgIwXHGqLEPqrdbPd9cLJqTFOB7Qt+2QzFYmzJanGfZemC/Q3pYAbOyKOqCUMhBT PltSN5DeyZsaBo+03/tFJN96MWcM6ErqPyVZV/GiOfS9kaGVbSe4/1OO6iE0Chf03Iqg kWr0JrgQJbor5zl042E3xJldcD8Cpd8PERx9A8vfSbnsEb9A0o5JbnaQ4KEL46TnIsSN JYyn9fu4BZBFUoAnZT8vWlurGnPjM9G+ZbbV83tUjq98k5oRUC9ZyYCPkaHL/Pup0L0C Jcug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i128si7216420pfg.121.2017.06.19.02.18.51; Mon, 19 Jun 2017 02:18:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753837AbdFSJSn (ORCPT + 6 others); Mon, 19 Jun 2017 05:18:43 -0400 Received: from foss.arm.com ([217.140.101.70]:47344 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753845AbdFSJSm (ORCPT ); Mon, 19 Jun 2017 05:18:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B4B91344; Mon, 19 Jun 2017 02:18:36 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 356823F587; Mon, 19 Jun 2017 02:18:36 -0700 (PDT) From: Mark Rutland To: stable@vger.kernel.org Cc: mark.rutland@arm.com Subject: [PATCH v4.9.y] mm: numa: avoid waiting on freed migrated pages Date: Mon, 19 Jun 2017 10:17:29 +0100 Message-Id: <1497863849-21277-1-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org commit 3c226c637b69104f6b9f1c6ec5b08d7b741b3229 upstream. In do_huge_pmd_numa_page(), we attempt to handle a migrating thp pmd by waiting until the pmd is unlocked before we return and retry. However, we can race with migrate_misplaced_transhuge_page(): // do_huge_pmd_numa_page // migrate_misplaced_transhuge_page() // Holds 0 refs on page // Holds 2 refs on page vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); /* ... */ if (pmd_trans_migrating(*vmf->pmd)) { page = pmd_page(*vmf->pmd); spin_unlock(vmf->ptl); ptl = pmd_lock(mm, pmd); if (page_count(page) != 2)) { /* roll back */ } /* ... */ mlock_migrate_page(new_page, page); /* ... */ spin_unlock(ptl); put_page(page); put_page(page); // page freed here wait_on_page_locked(page); goto out; } This can result in the freed page having its waiters flag set unexpectedly, which trips the PAGE_FLAGS_CHECK_AT_PREP checks in the page alloc/free functions. This has been observed on arm64 KVM guests. We can avoid this by having do_huge_pmd_numa_page() take a reference on the page before dropping the pmd lock, mirroring what we do in __migration_entry_wait(). When we hit the race, migrate_misplaced_transhuge_page() will see the reference and abort the migration, as it may do today in other cases. Fixes: b8916634b77bffb2 ("mm: Prevent parallel splits during THP migration") Link: http://lkml.kernel.org/r/1497349722-6731-2-git-send-email-will.deacon@arm.com Signed-off-by: Mark Rutland Signed-off-by: Will Deacon Acked-by: Steve Capper Acked-by: Kirill A. Shutemov Acked-by: Vlastimil Babka Cc: Mel Gorman Cc: Signed-off-by: Andrew Morton --- mm/huge_memory.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 1.9.1 diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d5b2b75..e7d5db9 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1227,8 +1227,11 @@ int do_huge_pmd_numa_page(struct fault_env *fe, pmd_t pmd) */ if (unlikely(pmd_trans_migrating(*fe->pmd))) { page = pmd_page(*fe->pmd); + if (!get_page_unless_zero(page)) + goto out_unlock; spin_unlock(fe->ptl); wait_on_page_locked(page); + put_page(page); goto out; } @@ -1260,8 +1263,11 @@ int do_huge_pmd_numa_page(struct fault_env *fe, pmd_t pmd) /* Migration could have started since the pmd_trans_migrating check */ if (!page_locked) { + if (!get_page_unless_zero(page)) + goto out_unlock; spin_unlock(fe->ptl); wait_on_page_locked(page); + put_page(page); page_nid = -1; goto out; }