From patchwork Tue Jun 13 10:28:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 104377 Delivered-To: patch@linaro.org Received: by 10.182.29.35 with SMTP id g3csp392800obh; Tue, 13 Jun 2017 03:28:41 -0700 (PDT) X-Received: by 10.98.64.6 with SMTP id n6mr4514529pfa.196.1497349721448; Tue, 13 Jun 2017 03:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497349721; cv=none; d=google.com; s=arc-20160816; b=p0mz22RdZowsDbaLWl29INOc2xIrTtmdUGtAT5J2fTFXTF8/LXvQzQdydj2X27A67Q dg8uWbP7m1uBiTJpBNH23zEZJ+A1etNe8cxCMqjT6lrNLs5KJRj3C8hbaElWitoUu2+S PhefxrpPGWl48zOwuSyNwxdFlgGdiuvKA/9gBVt/ksCdsUouFqlOo9fPD171tx5O4IX7 CFM0cA7nczir+/UoPIj6CApaJB5GpVaoi5yhQFK/AVX/I4IpENLrn/oH/e5UlJYLB88R kjCjtST8pws/2YgK2itURMgmhcMTrWKEvSONiNbzepoHercIBYjDgbBK0zxSnvgHdOZn 5UUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=6esyNXK6Vh379w8NdkZkaHx8FmXEQzt/EOLWrX9LfFo=; b=gPjpg9PkvLEWfETWVx6wx93eMIFSD16g44nmhMUhHphbrm6vMIjvB4B3tzpldbjfOw QIAfrInucIyasBjTvdEzCyBSxQzAiGGO0DcrPR3WhkjNURZjw0cIlenNZKRzp5ZUBMtU vl4TMHTnLZuHs+Jw/FzBODblolgZOCC3jDOv7CzGIuVyxLesfnWQCGs3ybDXbYGyf5Wa 9IhjxFhfZb5rzrBBVkNmYIxixXqkw1+vE8fzqtx+jClpcmSXxeYiFI/yoYxIBkwx9GJR kqEF+FOlc2KsEUtou06zUeKK3HJzw/w1IccMNmdcR3lpuevpO6nl3EcRl28Khno7PU8F LqkQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k62si8991107pfj.411.2017.06.13.03.28.41; Tue, 13 Jun 2017 03:28:41 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752674AbdFMK2h (ORCPT + 25 others); Tue, 13 Jun 2017 06:28:37 -0400 Received: from foss.arm.com ([217.140.101.70]:46144 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752102AbdFMK2f (ORCPT ); Tue, 13 Jun 2017 06:28:35 -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 E3FFF15A2; Tue, 13 Jun 2017 03:28:34 -0700 (PDT) Received: from edgewater-inn.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 B69063F59C; Tue, 13 Jun 2017 03:28:34 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id C474F1AE01AE; Tue, 13 Jun 2017 11:28:44 +0100 (BST) From: Will Deacon To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: mark.rutland@arm.com, akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, Punit.Agrawal@arm.com, mgorman@suse.de, steve.capper@arm.com, vbabka@suse.cz, Will Deacon Subject: [PATCH v2 1/3] mm: numa: avoid waiting on freed migrated pages Date: Tue, 13 Jun 2017 11:28:40 +0100 Message-Id: <1497349722-6731-2-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1497349722-6731-1-git-send-email-will.deacon@arm.com> References: <1497349722-6731-1-git-send-email-will.deacon@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland 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. Acked-by: Steve Capper Acked-by: Kirill A. Shutemov Acked-by: Vlastimil Babka Fixes: b8916634b77bffb2 ("mm: Prevent parallel splits during THP migration") Signed-off-by: Mark Rutland Signed-off-by: Will Deacon --- mm/huge_memory.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) -- 2.1.4 diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a84909cf20d3..88c6167f194d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1426,8 +1426,11 @@ int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t pmd) */ if (unlikely(pmd_trans_migrating(*vmf->pmd))) { page = pmd_page(*vmf->pmd); + if (!get_page_unless_zero(page)) + goto out_unlock; spin_unlock(vmf->ptl); wait_on_page_locked(page); + put_page(page); goto out; } @@ -1459,9 +1462,12 @@ int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t pmd) /* Migration could have started since the pmd_trans_migrating check */ if (!page_locked) { + page_nid = -1; + if (!get_page_unless_zero(page)) + goto out_unlock; spin_unlock(vmf->ptl); wait_on_page_locked(page); - page_nid = -1; + put_page(page); goto out; }