Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3115775pxj; Mon, 17 May 2021 18:10:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznnFq/i0Eb1o+DMSV0qPyLmymT18S65UIJDxoyqi2sFtCshuAnV+8hQkGFvGs4tWnfOieN X-Received: by 2002:a17:906:7d7:: with SMTP id m23mr3001984ejc.331.1621300235056; Mon, 17 May 2021 18:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621300235; cv=none; d=google.com; s=arc-20160816; b=n6WQP2kTJqoaHkISPheAxwqb8JMINr8ZDfn0qSzvHtKC5BzxIV6phFO+Dv0jQ/qNXe WfQzK+o26arEnjHJD4bYpx1W0NKKTxE0UpJVe5fyUuYzBl332EUqCCbQX1zFSMTxQXmA mbWslLYZchKeAaJ8fKlz6FYfBS+nAjc/U26i1JF3DF3hXkuiBHac5i5xqd8qabP6PxbA rhXCgc+Sj3iMjWVKWzLwzTzxj2B16/cId/J7zL7VZwR9NpDv6XqwLIEilnJEMVWIqh3S V54SXxwThssHEHWzIEgR+QlY84GeHqUTkuSZ2j8MsCHk2lT276BqJtPA/s0cVAtUe99R X+9A== 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=4opNRla9/AS0+i75ksSQrnx/v5+0n3CIDL5axWhXyQc=; b=PuGyaNHSNGCq7ictvLI3A/GBpQ2PLdL0tqX/ThVGoLPqYAFGrP1o0bhwBcfUSs9aoy UDlbWZYya4PQ2uVV/TnsMLs4BNCBfuqwODn9sR7y9GoU4BWH0rkbABrzQH6NMehvq4IZ ok3gc/wdIi/vv/rGbJQuRRHj3fiI9M6/38ABvK73OBapKB6NWIERsOO1Stpz2M+84Cfn tLvgn9LkfMTdqspyN+i+BG20+W0Zd/xLOfIPyU0t0dD8jzVK34Zah5/HWBNh4kgwlKEt OqjL1ylWkL/d03BZH41keouiILJ1yonRppAosHBdNSjVlIEwKN7xyYT/g9w+KqLAnTe8 V//A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1cVimAyd; 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 t21si15955166edw.597.2021.05.17.18.10.11; Mon, 17 May 2021 18:10:35 -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=1cVimAyd; 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 S239937AbhEQOdU (ORCPT + 99 others); Mon, 17 May 2021 10:33:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:53290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235329AbhEQO2L (ORCPT ); Mon, 17 May 2021 10:28:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8DEF761627; Mon, 17 May 2021 14:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260850; bh=K1jWZImZhN+LCmTN8JjNk7t0AysYUeLwb62XkbKZ95c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1cVimAydWW9NbRh5tcmiwNtoq/3LV94s86Cgdmd+szz+Q6gO/Gj0ULWWLcPgWRVRi c5Tzjl5UqghoMUmzJH0b/jWu39j8MJnqF7KdRH2YorsxyyCtLxtLvIlCoYOGphnPYy UIRfog/G8qhdBnbg6XADdwwtNSr/YwWcXqJTTHac= 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 222/363] mm/gup: return an error on migration failure Date: Mon, 17 May 2021 16:01:28 +0200 Message-Id: <20210517140310.100904587@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 f0f4463837da17a89d965dcbe4e411629dbcf308 ] When migration failure occurs, we still pin pages, which means that we may pin CMA movable pages which should never be the case. Instead return an error without pinning pages when migration failure happens. No need to retry migrating, because migrate_pages() already retries 10 times. Link: https://lkml.kernel.org/r/20210215161349.246722-4-pasha.tatashin@soleen.com 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 | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 6530672131db..2b48c65e27cc 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1553,7 +1553,6 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, { unsigned long i; bool drain_allow = true; - bool migrate_allow = true; LIST_HEAD(cma_page_list); long ret = nr_pages; struct page *prev_head, *head; @@ -1604,17 +1603,15 @@ check_again: for (i = 0; i < nr_pages; i++) put_page(pages[i]); - if (migrate_pages(&cma_page_list, alloc_migration_target, NULL, - (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) { - /* - * some of the pages failed migration. Do get_user_pages - * without migration. - */ - migrate_allow = false; - + ret = migrate_pages(&cma_page_list, alloc_migration_target, + NULL, (unsigned long)&mtc, MIGRATE_SYNC, + MR_CONTIG_RANGE); + if (ret) { if (!list_empty(&cma_page_list)) putback_movable_pages(&cma_page_list); + 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 @@ -1624,7 +1621,7 @@ check_again: pages, vmas, NULL, gup_flags); - if ((ret > 0) && migrate_allow) { + if (ret > 0) { nr_pages = ret; drain_allow = true; goto check_again; -- 2.30.2