Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp815518imp; Thu, 21 Feb 2019 11:47:54 -0800 (PST) X-Google-Smtp-Source: AHgI3IZiEc5cHCehldTTJuX/yvbpciSFvFRtg+fBWP1pmbOYBOKGrYUTC+1cJ4Q04godg/7lJGEk X-Received: by 2002:a17:902:5066:: with SMTP id f35mr255837plh.78.1550778474086; Thu, 21 Feb 2019 11:47:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550778474; cv=none; d=google.com; s=arc-20160816; b=XpG7JPadwqC9tgPqOcTsInEQrnCjbYYLlupSx1o0Ffw8F29bnVJBEt28kx8npMcAwR 6u0ItcxXzGeCBpL8tF3MqsX440zbXL2gusQyYC9O+EnFMO2zXMDm8bdloKx/C+rivdeS 81vDw7uRyoeclel+v2I6VxDWGPxjBfM9TpaXu1YG8aynJP4yWzZqOk/45lEcgw63jlV/ F9wHK3N2vK6+zqd/tFCZlA+FaXRP8OhO8BhDvDLCJ+P9nUFK0oJo1upJmjuWEij72tYX Mf5+3vFEqUU7RtyU4lcPewXJ0EpdjEgodm4vPXnhN9KJTtju15WC0L6FLRHFuNNKgjKo +xgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=2Bd3yzDftsxFwBxfrvgbnKXass4MT1o7R2tEYBN9pRo=; b=taS6f8FQT203FrdyEAlcjMDC3fG0Spwo38vV7Moj/bjWGcO/GyIinFrvh6+fNo1z4p tpzGysP2xJIiDP0VzFSSrncbEe3RyY0DYHhILW00xzPTif/bW/KUhj/+h4NuUcTlhCPb +hwdU1N9SthzzWeLEjD8vjCMmXO4XQg7sEh2H9TGcWSTr0sDn/TyesQuKR9LCn140leV x4Jj278r8kw0kDYmTYOKRIEjFv+KdE/jSgjtDuQXKznHnvUX0o9b07lo82kFugE0/7Kc Uv9bx/ymf8Noer+pqHl+q3FjcRV7Vo8s95GG5RANM4W3WzWpFU7+qY71gJiskNHe5zGn vkgA== 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 64si23208235pld.436.2019.02.21.11.47.37; Thu, 21 Feb 2019 11:47:54 -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; 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 S1726273AbfBUTrQ (ORCPT + 99 others); Thu, 21 Feb 2019 14:47:16 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:48046 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbfBUTrQ (ORCPT ); Thu, 21 Feb 2019 14:47:16 -0500 Received: from localhost.localdomain (c-73-223-200-170.hsd1.ca.comcast.net [73.223.200.170]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0E0D93BD2; Thu, 21 Feb 2019 19:47:15 +0000 (UTC) Date: Thu, 21 Feb 2019 11:47:13 -0800 From: Andrew Morton To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko , Naoya Horiguchi , Andrea Arcangeli , "Kirill A . Shutemov" , Mel Gorman , Davidlohr Bueso , stable@vger.kernel.org Subject: Re: [PATCH] huegtlbfs: fix races and page leaks during migration Message-Id: <20190221114713.ee2a38267f75ef1a2fd6de44@linux-foundation.org> In-Reply-To: <7534d322-d782-8ac6-1c8d-a8dc380eb3ab@oracle.com> References: <803d2349-8911-0b47-bc5b-4f2c6cc3f928@oracle.com> <20190212221400.3512-1-mike.kravetz@oracle.com> <20190220220910.265bff9a7695540ee4121b80@linux-foundation.org> <7534d322-d782-8ac6-1c8d-a8dc380eb3ab@oracle.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 21 Feb 2019 11:11:06 -0800 Mike Kravetz wrote: > > Sorry for the churn. As I find and fix one issue I seem to discover another. > There is still at least one more issue with private pages when COW comes into > play. I continue to work that. I wanted to send this patch earlier as it > is pretty easy to hit the bugs if you try. If you would prefer another > approach, let me know. > No probs, the bug doesn't seem to be causing a lot of bother out there and it's cc:stable; there's time to get this right ;) Here's the delta I queued: --- a/mm/hugetlb.c~huegtlbfs-fix-races-and-page-leaks-during-migration-update +++ a/mm/hugetlb.c @@ -3729,6 +3729,7 @@ static vm_fault_t hugetlb_no_page(struct pte_t new_pte; spinlock_t *ptl; unsigned long haddr = address & huge_page_mask(h); + bool new_page = false; /* * Currently, we are forced to kill the process in the event the @@ -3790,6 +3791,7 @@ retry: } clear_huge_page(page, address, pages_per_huge_page(h)); __SetPageUptodate(page); + new_page = true; if (vma->vm_flags & VM_MAYSHARE) { int err = huge_add_to_page_cache(page, mapping, idx); @@ -3861,8 +3863,9 @@ retry: spin_unlock(ptl); - /* May already be set if not newly allocated page */ - set_page_huge_active(page); + /* Make newly allocated pages active */ + if (new_page) + set_page_huge_active(page); unlock_page(page); out: --- a/mm/migrate.c~huegtlbfs-fix-races-and-page-leaks-during-migration-update +++ a/mm/migrate.c @@ -1315,6 +1315,16 @@ static int unmap_and_move_huge_page(new_ lock_page(hpage); } + /* + * Check for pages which are in the process of being freed. Without + * page_mapping() set, hugetlbfs specific move page routine will not + * be called and we could leak usage counts for subpools. + */ + if (page_private(hpage) && !page_mapping(hpage)) { + rc = -EBUSY; + goto out_unlock; + } + if (PageAnon(hpage)) anon_vma = page_get_anon_vma(hpage); @@ -1345,6 +1355,7 @@ put_anon: put_new_page = NULL; } +out_unlock: unlock_page(hpage); out: if (rc != -EAGAIN) _