Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3115759pxj; Mon, 17 May 2021 18:10:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdaWN2Iige7SB+CU89biUvB0+V5hx5y5MzvwDwWckwAE89bOSJiWk2efh56I5E92THDmgS X-Received: by 2002:a50:fd13:: with SMTP id i19mr3691196eds.386.1621300232796; Mon, 17 May 2021 18:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621300232; cv=none; d=google.com; s=arc-20160816; b=ChOk2Ok47dLdTMmI0MCQguDF56uDuvaGRz7TnwX/VZDFi9fehQCwysLz6vdnISk7ce Pj1ZDFrxnMhnQJ9Z1/za7BH9D9T7SCpGTO7w5HioQZCOJRcdbtDWBl9VTZpSRF5sKkPO xwjUmDyV/iM0HdelWDSX2GS0ZlKZML6DafRLwcv/nWu0E8qVtTKC6sg6lOhO4rROgUUz aZn+dBVL3IBn/jcd8z0PPY9n5dhGhTm+OEFadgQRhEfDOPnyiXopRaDGjG6nl8K4tmIU h9o3pOZ0EDhfutcJ5W7NZ9Kam/0V2daaJuAqm7h6DcJ0Il2UJQNhgy/XpbIlMkFGNO/I H71Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0iUIi0E+k272z8Ws87ey2/gJMdDimB9eZKK/1HBxe/Y=; b=cAZx05DmsDdVFaWjZPZAIvh0umP9kDz4BsjD+bF8H3Y0t0isgT1cx29+Xd4NPoAyv1 6uW0TKMkqM1nrXBbRk+5ZaN4xrfvuE1qzyIBwDy/R1Sk8ybkOIXYERFZW28uNo/d5iJ/ mJwM4hfUk8BYMN3sL9lwZsStPC0hkIJHeDtRFc9DuvLV332fWsLiTWlECGaxQdjUddqf f0JISfGha84NkfSa+lRYUWaWUwmoKzDZU8IENWA0/ESg+SC/jiMmKiiWdlpNzKkQCCnx obxrK9tFf0Z2styrVU8JLIpvIrj4tZC+XwXWsk49fLS6thYBsX27AsBpviQekqBkK77Z 2SSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yfJlPF0r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n24si15534377eds.571.2021.05.17.18.10.10; Mon, 17 May 2021 18:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yfJlPF0r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239882AbhEQOdO (ORCPT + 99 others); Mon, 17 May 2021 10:33:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:53296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239217AbhEQO2N (ORCPT ); Mon, 17 May 2021 10:28:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 96BC861606; Mon, 17 May 2021 14:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260852; bh=AgBW2YH8kpy/3JGlqr074zJiO1SvvpeXPngdoHsqbSo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yfJlPF0rdLvOwq1ii/pc//cw4ih9ZsPDHHDPsDdT/77/XSl1obRP05SDvU+PsRHw7 l+j8jYJ6HxJlFX6RP5Q7me5FWuM1HK3AdH3Zid1/g1drhKtjMgRpp6xzXCtfoPd8tK ijLql+WFKJNrJTyX7RwKWLQ16ITVt/4kfTb2Jjek= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Tatashin , Jason Gunthorpe , Dan Williams , David Hildenbrand , David Rientjes , Ingo Molnar , Ira Weiny , James Morris , Jason Gunthorpe , John Hubbard , Joonsoo Kim , Matthew Wilcox , Mel Gorman , Michal Hocko , Michal Hocko , Mike Kravetz , Oscar Salvador , Peter Zijlstra , Sasha Levin , "Steven Rostedt (VMware)" , Tyler Hicks , Vlastimil Babka , Andrew Morton , Linus Torvalds Subject: [PATCH 5.12 223/363] mm/gup: check for isolation errors Date: Mon, 17 May 2021 16:01:29 +0200 Message-Id: <20210517140310.133885570@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Tatashin [ Upstream commit 6e7f34ebb8d25d71ce7f4580ba3cbfc10b895580 ] It is still possible that we pin movable CMA pages if there are isolation errors and cma_page_list stays empty when we check again. Check for isolation errors, and return success only when there are no isolation errors, and cma_page_list is empty after checking. Because isolation errors are transient, we retry indefinitely. Link: https://lkml.kernel.org/r/20210215161349.246722-5-pasha.tatashin@soleen.com Fixes: 9a4e9f3b2d73 ("mm: update get_user_pages_longterm to migrate pages allocated from CMA region") Signed-off-by: Pavel Tatashin Reviewed-by: Jason Gunthorpe Cc: Dan Williams Cc: David Hildenbrand Cc: David Rientjes Cc: Ingo Molnar Cc: Ira Weiny Cc: James Morris Cc: Jason Gunthorpe Cc: John Hubbard Cc: Joonsoo Kim Cc: Matthew Wilcox Cc: Mel Gorman Cc: Michal Hocko Cc: Michal Hocko Cc: Mike Kravetz Cc: Oscar Salvador Cc: Peter Zijlstra Cc: Sasha Levin Cc: Steven Rostedt (VMware) Cc: Tyler Hicks Cc: Vlastimil Babka Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/gup.c | 60 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 2b48c65e27cc..333f5dfd8942 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1551,8 +1551,8 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, struct vm_area_struct **vmas, unsigned int gup_flags) { - unsigned long i; - bool drain_allow = true; + unsigned long i, isolation_error_count; + bool drain_allow; LIST_HEAD(cma_page_list); long ret = nr_pages; struct page *prev_head, *head; @@ -1563,6 +1563,8 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, check_again: prev_head = NULL; + isolation_error_count = 0; + drain_allow = true; for (i = 0; i < nr_pages; i++) { head = compound_head(pages[i]); if (head == prev_head) @@ -1574,25 +1576,35 @@ check_again: * of the CMA zone if possible. */ if (is_migrate_cma_page(head)) { - if (PageHuge(head)) - isolate_huge_page(head, &cma_page_list); - else { + if (PageHuge(head)) { + if (!isolate_huge_page(head, &cma_page_list)) + isolation_error_count++; + } else { if (!PageLRU(head) && drain_allow) { lru_add_drain_all(); drain_allow = false; } - if (!isolate_lru_page(head)) { - list_add_tail(&head->lru, &cma_page_list); - mod_node_page_state(page_pgdat(head), - NR_ISOLATED_ANON + - page_is_file_lru(head), - thp_nr_pages(head)); + if (isolate_lru_page(head)) { + isolation_error_count++; + continue; } + list_add_tail(&head->lru, &cma_page_list); + mod_node_page_state(page_pgdat(head), + NR_ISOLATED_ANON + + page_is_file_lru(head), + thp_nr_pages(head)); } } } + /* + * If list is empty, and no isolation errors, means that all pages are + * in the correct zone. + */ + if (list_empty(&cma_page_list) && !isolation_error_count) + return ret; + if (!list_empty(&cma_page_list)) { /* * drop the above get_user_pages reference. @@ -1612,23 +1624,19 @@ check_again: return ret > 0 ? -ENOMEM : ret; } - /* - * We did migrate all the pages, Try to get the page references - * again migrating any new CMA pages which we failed to isolate - * earlier. - */ - ret = __get_user_pages_locked(mm, start, nr_pages, - pages, vmas, NULL, - gup_flags); - - if (ret > 0) { - nr_pages = ret; - drain_allow = true; - goto check_again; - } + /* We unpinned pages before migration, pin them again */ + ret = __get_user_pages_locked(mm, start, nr_pages, pages, vmas, + NULL, gup_flags); + if (ret <= 0) + return ret; + nr_pages = ret; } - return ret; + /* + * check again because pages were unpinned, and we also might have + * had isolation errors and need more pages to migrate. + */ + goto check_again; } #else static long check_and_migrate_cma_pages(struct mm_struct *mm, -- 2.30.2