From patchwork Mon Jun 19 09:18:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 105808 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp781826qgd; Mon, 19 Jun 2017 02:19:50 -0700 (PDT) X-Received: by 10.98.112.137 with SMTP id l131mr24261508pfc.186.1497863990670; Mon, 19 Jun 2017 02:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497863990; cv=none; d=google.com; s=arc-20160816; b=g9eey5aXRXxZwaEbBAp8YJevXJZQ8Ust5KcUYQWId/qBzz6v12LIUegDAVlzfcPJ3i hBJdobX4BzqTHqJmKfXHUhx/DbE13c4xQFNH3/jcSqlfT+yeGCCn/gUkOJwBC6QkdTls 9rLLGIQlo3LE/88NxFqMfV8Q3uY+ixkT2X/JwPEGeR1YqTxi3GYAEtmtmLQvuY09gdKt e8tPykQ8pBzcZIl/yPTSGpQsgL4cMVzWSlWvZ5ZyipZhepL2E1Z81eEh5Y34KyFh+NC3 4WmtTy8amnD9ajlBSkUEc/RX2vYfRRoV3onIeLQiCpoSsOpugEXYOOqX1qSiFUgXP8+w 1n4A== 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=Ep3JSQ/vX45LnjLwMRiN0Qq5A3Av/0F8b+9oGGZW1wo=; b=DQrA+jfRCsQ7wRSe1y/ZGmHeZQft0BwSJlgXwyZYiVJW4U49BkmUDxsT9l6o00sfU8 B0Askg/twhWq7ELJxIiiRb0yhxFHBEgBD3V7BrlAfurq0XQt4Xyc17iXrHfOeDOKCjIX hd9o8j7CcBUdcHEX5RR1IaXX4/6hPKtI8HQObFf8rYfCTU7AM8dmKtFR+XzlYRLo9EDe P+4qjYj1uP+6vhdTtjAHJk/OK7fjUswiqroc9wWGIYR+7IMINdpRrj1uMxkbl1EFCv+v aJ+GbwuieNqR4eSWgqWjBniU/2up5emYQcUC5bgY0+/AtMDy+CaCm1YJ7W0Ha5u58FmT FNnQ== 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 z82si7473710pff.392.2017.06.19.02.19.50; Mon, 19 Jun 2017 02:19:50 -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 S1753769AbdFSJTk (ORCPT + 6 others); Mon, 19 Jun 2017 05:19:40 -0400 Received: from foss.arm.com ([217.140.101.70]:47376 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753707AbdFSJTk (ORCPT ); Mon, 19 Jun 2017 05:19:40 -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 B9A97344; Mon, 19 Jun 2017 02:19:29 -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 3C70B3F587; Mon, 19 Jun 2017 02:19:29 -0700 (PDT) From: Mark Rutland To: stable@vger.kernel.org Cc: mark.rutland@arm.com Subject: [PATCH v4.4.y] mm: numa: avoid waiting on freed migrated pages Date: Mon, 19 Jun 2017 10:18:39 +0100 Message-Id: <1497863919-21352-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 47b4696..6c6f5cc 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1363,8 +1363,11 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, */ if (unlikely(pmd_trans_migrating(*pmdp))) { page = pmd_page(*pmdp); + if (!get_page_unless_zero(page)) + goto out_unlock; spin_unlock(ptl); wait_on_page_locked(page); + put_page(page); goto out; } @@ -1396,8 +1399,11 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, /* Migration could have started since the pmd_trans_migrating check */ if (!page_locked) { + if (!get_page_unless_zero(page)) + goto out_unlock; spin_unlock(ptl); wait_on_page_locked(page); + put_page(page); page_nid = -1; goto out; }