Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp547408pxj; Tue, 18 May 2021 09:01:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfaHzsqrZDOrnWn8FHVurZyW7ErobUKTgZ53BZ4wMUKBMsbgxx4g2vc0WLJYC5B1LIfBku X-Received: by 2002:a17:906:b048:: with SMTP id bj8mr6742175ejb.236.1621353703831; Tue, 18 May 2021 09:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621353703; cv=none; d=google.com; s=arc-20160816; b=D4a0eZE5HNQeAZyZP9Wn26JcehQ9p/9uARhuxHpJHbDGSbs2nUWAc94OHOfmuG593Q T+bf6yDSIGk5S8E3vbrQj7Awu+LVNU/T69KmpANXzIFnVJt/miSNadg5rj1UXX8CVgLc YwYgkeswp1vpLo5F4EzbteP5RGHgXR9UYCMWrU0AgdVEzZf8Xnzp543eqWyA9dCM3WLF rabSes4wmizzwKbgKkRbhCSPN+H0pN7FyqJxy+3gWiTYQDkGfYW5necM5q7uo+yL2r4x lJ7OVMBJK24xnA6uK3C9x4oK7DcxItRB937qUE/UUfpaBVwXX1y/ClaSt/J5VaZUrFYp IcvQ== 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=ocPy2Rjn/03ectVLyC/rMkRPq++AkdksJ+zlj2JY4IY=; b=V533ozaJX7SeUv7INNmnOFoq5E2TYmWbScPw5z4Vf0iu7lRTUU3UyPZWetQmpuAaEn RuSsH7ybJGNMJgmVJHj6iIHi1Elgjws+AwfaEQxoNbP8V0NOP5n/1r65jexw7GUoBu7D 38DXeosvYHvHPtNfGNzqKNRyQYy0gAvS7zI1QDDXPLNCTKOF5NsVsmhrFO85Mu4PJxii jbZpDIuCCXg8MGRJh7fda5VkX51dZsfXPQXDA6WLFGzGsYlFk7FuxnqzzxM8QLQZYAK7 8J/j8GmH3VPhox0/1f5MCNQ8Sjx7e/MblsFM4HI8gWnzyUnq/lSKRQvj4t/Q+Aj6QYDz H19w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y43TAqJN; 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 w7si11624215edq.358.2021.05.18.09.00.56; Tue, 18 May 2021 09:01:43 -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=Y43TAqJN; 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 S1344416AbhEQP7S (ORCPT + 99 others); Mon, 17 May 2021 11:59:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:51390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343505AbhEQPjh (ORCPT ); Mon, 17 May 2021 11:39:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7769F61D08; Mon, 17 May 2021 14:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262486; bh=gxL1L//z6b9d6GjSM5DnSz+KVH2AMz/1RnwTpGD62qI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y43TAqJNesD1gYphODm+aOZG4gd9ON7RY5q1VRlYyDIxpQU2JBtomxMhBlxu+wX6f TZCtsAFSgyY90U9+s69psDmxdSiX0KjXRnAt+QPFZy9PNCkUvWuwrwS9neqigaX9tR NIT3TVY9JcHoCwNrZjJsDTGz7HccbS3C8PTRDkgo= 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 172/289] mm/gup: check for isolation errors Date: Mon, 17 May 2021 16:01:37 +0200 Message-Id: <20210517140310.911473206@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 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 0fa8d88eb7ba..c2826f3afe72 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1561,8 +1561,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; @@ -1573,6 +1573,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) @@ -1584,25 +1586,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. @@ -1622,23 +1634,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