From patchwork Wed Jan 22 01:26:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13946741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26ECFC02182 for ; Wed, 22 Jan 2025 01:27:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AACFC280003; Tue, 21 Jan 2025 20:27:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A5CFD280001; Tue, 21 Jan 2025 20:27:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94C3C280003; Tue, 21 Jan 2025 20:27:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 734B8280001 for ; Tue, 21 Jan 2025 20:27:50 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DDFB31411F6 for ; Wed, 22 Jan 2025 01:27:49 +0000 (UTC) X-FDA: 83033351058.05.0D714F2 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf20.hostedemail.com (Postfix) with ESMTP id 19A151C0006 for ; Wed, 22 Jan 2025 01:27:46 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737509268; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=YbEL0xYVHVF7G8ELbGJOKakBWFzAHYl+XXaWmydIQvA=; b=8bmKQRyFe2AYhtn5c3nb5PR12qwFrZ6IG/Au3ayXQNARSEPnDUg5To1EYP15EEoS4e2y1g t5WmytfkNpN2t3JyXXeihlstgmJ3qCDdw8WBDPtHfJg/J8AbAWYQXK4C2rmuAGmd6oSZ6M 1lwmeNCaiy+IGcgYMJOmTN7SFsmBxBg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737509268; a=rsa-sha256; cv=none; b=OSbgD+0wQDYxk+I58IfmMwEKXA4Lf2429MA3EFQAMnWA9iIV2+HZCMNuDu9oH6P6zYm52p 9r3sEdUWps9zYD3KGOXZDZ6NYlrui2fDce49Cu79H6GAc9EbnQNib6Lw/8cBTfH+7AteOt 24TSMYQNWdCQ98Sh+ioEBkxLBDtxWI0= Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 50M1QGxK046972; Wed, 22 Jan 2025 09:26:16 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Yd5t2458bz2P2yJ5; Wed, 22 Jan 2025 09:22:50 +0800 (CST) Received: from bj03382pcu01.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 22 Jan 2025 09:26:12 +0800 From: "zhaoyang.huang" To: Andrew Morton , Alistair Popple , John Hubbard , , , Zhaoyang Huang , , Subject: [PATCH v3] mm: gup: fix infinite loop within __get_longterm_locked Date: Wed, 22 Jan 2025 09:26:04 +0800 Message-ID: <20250122012604.3654667-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.40] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 50M1QGxK046972 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 19A151C0006 X-Stat-Signature: afuu4qw7ath89yc5i1nriperghpefi6t X-Rspam-User: X-HE-Tag: 1737509266-104461 X-HE-Meta: U2FsdGVkX1/5Z10BGKGECpVvX0XoUkccFznMRB37gCsEjblYvPF1yXhsiT2Hk4tA0X0AT3In/Yft+Emt5ZVhfmaV1jh8YV1AVb0LRymQK8iX+FQXD+bUTY2mpmMZwdBnq3QaMFRTBVVlPc2xCM1yTkchgszhBQva43J9P6vXobeeKNqRXjQb9hklPJz8emosrpRewL+wCYP/ZnjkiQM8F8a/Qa8zBia7cfsgcV2XLN8pHi9J5fY/vdpZsw1NneIsvb6g5VfSmf5NHcdgEZd7IfK7UvIUZzkslJr/j58NZRxq0KcAxSDX9LkLC0XndrmbIarTh6r4DikyscW3+R91dG+huji1XtwWw+FtjlQcKfWgdyD8lot8FetPRMFGt7/atQNtR/cpASUWSGUF0Po/aax2RxWJNZgHUPb06XmDzVmPpE46iF2R0q85Pha/4+XpD1FtxPSVyfpx9FJ3AiQWA2Oy8MF9ScyM2lA397nbHMMkkYZLBkmHG4Cfu5152j/zool3l01KQ3EqXKbJniKbu7IkOYWWJKHlxap7yY7vbSokrdEfsqDpFX5jJtCNCq1nbfb4fU7eiVZQWYHbtB3LoqalD2akr6Xmzx+HUMh6lbV8CFHQef3KJDT8Z3DSAIlDuVcYt9qRzCmXF0qs0iYV79P2tO9FhdI0xZyjp2zO+Di0m2CnS85OK6WzEqXw/LsNbVT+rZ9pepqYEEx7GGlztP0S36B/ywYXegnY3EhcxO08OsLuDe9FM+7f8DhMlD9nUH50pGVuau5PmDoqzb56dkxD8r4XCC/EJCn0xw87RfhicLjuU0tPKCb1/lQMncnoSk7YAEsBwF9D84O0/Sv6c4GDxJxJSMWqgvpIvw/dcNkR0v8VyP4obeI/ePUvZrha6rXhFgXXa/T5NOoKkWYAxaTyUKNSYmw1Csa5KESG4gX2VLjepwswVYLIGl/hsZ+QwVWJGbAVQiPTZSQ2Vgu WDA7j1I5 QUu9jXLzP22biqlYeof0nkzzuzT79NvwUjWfygXmiuV/5HwFGnQS/hrcgBhMcJNlYZdTYEDmPv1R+18czaC9KPY6MkPIxQ2HI2Bt5qrHAE0gbBZdEHtMzmCVhBtdYoPoy2MY5Os1WrjvyzV8USo03T4PxESNrfCeqka7DbqmwVquXeWISkXgWut/+X15qlSlM7FT684rHDRPp4wt85XtBzBbj2rzZymHrMqKJ6YGkAkF6SG2ycA7UUDtKqjAdKjqpgrXgSUbtmkpVTg1tO4LG77cYUqCkqc6SgJb3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhaoyang Huang We can run into an infinite loop in __get_longterm_locked() when collect_longterm_unpinnable_folios() finds only folios that are isolated from the LRU or were never added to the LRU. This can happen when all folios to be pinned are never added to the LRU, for example when vm_ops->fault allocated pages using cma_alloc() and never added them to the LRU. Fix it by simply taking a look at the list in the single caller, to see if anything was added. Fixes: 67e139b02d99 ("mm/gup.c: refactor check_and_migrate_movable_pages()") Reviewed-by: John Hubbard Suggested-by: David Hildenbrand Signed-off-by: Zhaoyang Huang --- v2: judge if there are unpinnable pages via list_empty and update commit message v3: update commit message --- --- mm/gup.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 3b75e631f369..569a4d82012d 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2323,13 +2323,13 @@ static void pofs_unpin(struct pages_or_folios *pofs) /* * Returns the number of collected folios. Return value is always >= 0. */ -static unsigned long collect_longterm_unpinnable_folios( +static void collect_longterm_unpinnable_folios( struct list_head *movable_folio_list, struct pages_or_folios *pofs) { - unsigned long i, collected = 0; struct folio *prev_folio = NULL; bool drain_allow = true; + unsigned long i; for (i = 0; i < pofs->nr_entries; i++) { struct folio *folio = pofs_get_folio(pofs, i); @@ -2341,8 +2341,6 @@ static unsigned long collect_longterm_unpinnable_folios( if (folio_is_longterm_pinnable(folio)) continue; - collected++; - if (folio_is_device_coherent(folio)) continue; @@ -2364,8 +2362,6 @@ static unsigned long collect_longterm_unpinnable_folios( NR_ISOLATED_ANON + folio_is_file_lru(folio), folio_nr_pages(folio)); } - - return collected; } /* @@ -2442,11 +2438,9 @@ static long check_and_migrate_movable_pages_or_folios(struct pages_or_folios *pofs) { LIST_HEAD(movable_folio_list); - unsigned long collected; - collected = collect_longterm_unpinnable_folios(&movable_folio_list, - pofs); - if (!collected) + collect_longterm_unpinnable_folios(&movable_folio_list, pofs); + if (list_empty(&movable_folio_list)) return 0; return migrate_longterm_unpinnable_folios(&movable_folio_list, pofs);