Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp546677pxj; Tue, 18 May 2021 09:01:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlKfUEGLnMU58H6Ro2QEIG8pqG9ZL2F/UEinksGkLgWzWfENKQaDNa8tr5d25Ov0MREShB X-Received: by 2002:a05:6402:30a2:: with SMTP id df2mr7775001edb.176.1621353661571; Tue, 18 May 2021 09:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621353661; cv=none; d=google.com; s=arc-20160816; b=OVe5cOWWl9gVnm/hS4pEgkYdRdlmqLPFQcrpSXtgPhBLMSAvb0RHqGLJrzPY37KGf9 ibmUMb20cyRjgsQm9Urit1A8PVqziqcYAv/d8RyymHV8W8+TLtL9MxKLeSiJdhHtaIhu cHLlVaa7PfApiQ7BetnpQM6OtCcvSGNQ2AOGvm1Vn8YooEj5t3ydz4eXYByfq7kLW+d9 HFoKLGtMkp5CrE6HwP7UqreTOZiRkY/GRVtFfrP9vinDscwTxiHaSBHVVrOwEUZUPOkK bwDQzNbhkKKdCAaDGPij4lFwOU2/ic+rQl9rCnvUfqUsi6wmmY0tyDY1W64TM5Dd1SIE RXpw== 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=Ne71We7vWYU9tUCMyTYiM2gS0z5fBnpixMlWkJckRGE=; b=itRM30OY97YkkGGhgZYQ9SfGOW8jH3nAO0XA4zIvgBHCyh3VolcXkgkfY4cl6w7WkO r3P8R7tGaUjvnRfxTEW7PWXHW5nxT8b2XznRstw0r6CeYVVc0Nk6idFv0bSVzubrS2Z7 Y+ic7mYqvklETGvmUf7Ng+fnYHIc7qNu7rd9b7D+27tU7iZ2kIpu3UwbZF184FRJvpKh i5+gwcv1FfrcExVv2i/tjQBprwbN8XMj/HrXHUO+hwjqS8trZsikNz4r/bSqf9jtigMS TlFwrnMLm03+CrTB9ldBO1WQmj/tsLdVOsGdHVMa1Iou4Gn6skJwNu+NFjbjT/XKe/0d QbDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=e2vqvHuS; 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 m10si85214eds.259.2021.05.18.09.00.27; Tue, 18 May 2021 09:01:01 -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=e2vqvHuS; 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 S238720AbhEQP7B (ORCPT + 99 others); Mon, 17 May 2021 11:59:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:51344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245740AbhEQPjf (ORCPT ); Mon, 17 May 2021 11:39:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4DD8061D05; Mon, 17 May 2021 14:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262481; bh=9zsl9zDHEx/+/pebn0qQBMX6T086vh3OQ34q2z/vCks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e2vqvHuSM0cStQRupsy5tZVFOzdvuPgYYD4ZQrTQas5Nyxdub9LrT8YHK5rRVOe/V qgNTdZfo8M/p2XWaRd9XD/P2bYYRd8oPZVIsceiFM8gMhi0tDNrIZLBNlSpwc31epV NjZJRB7cZppjxUBbXqHwlvdtE+dVBFz4FlVAL/eY= 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.10 171/289] mm/gup: return an error on migration failure Date: Mon, 17 May 2021 16:01:36 +0200 Message-Id: <20210517140310.874758677@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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 e10807c4c46b..0fa8d88eb7ba 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1563,7 +1563,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; @@ -1614,17 +1613,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 @@ -1634,7 +1631,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