Skip to content

Commit adf8dfb

Browse files
author
CKI KWF Bot
committed
Merge: Revert GUP commit that introduces potential bug
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/1156 JIRA: https://issues.redhat.com/browse/RHEL-101826 ``` commit 517f496 Author: David Hildenbrand <david@redhat.com> Date: Wed Jun 11 15:13:14 2025 +0200 mm/gup: revert "mm: gup: fix infinite loop within __get_longterm_locked" After commit 1aaf8c1 ("mm: gup: fix infinite loop within __get_longterm_locked") we are able to longterm pin folios that are not supposed to get longterm pinned, simply because they temporarily have the LRU flag cleared (esp. temporarily isolated). For example, two __get_longterm_locked() callers can race, or __get_longterm_locked() can race with anything else that temporarily isolates folios. The introducing commit mentions the use case of a driver that uses vm_ops->fault to insert pages allocated through cma_alloc() into the page tables, assuming they can later get longterm pinned. These pages/ folios would never have the LRU flag set and consequently cannot get isolated. There is no known in-tree user making use of that so far, fortunately. To handle that in the future -- and avoid retrying forever to isolate/migrate them -- we will need a different mechanism for the CMA area *owner* to indicate that it actually already allocated the page and is fine with longterm pinning it. The LRU flag is not suitable for that. Probably we can lookup the relevant CMA area and query the bitmap; we only have have to care about some races, probably. If already allocated, we could just allow longterm pinning) Anyhow, let's fix the "must not be longterm pinned" problem first by reverting the original commit. Link: https://lkml.kernel.org/r/20250611131314.594529-1-david@redhat.com Fixes: 1aaf8c1 ("mm: gup: fix infinite loop within __get_longterm_locked") Signed-off-by: David Hildenbrand <david@redhat.com> Closes: https://lore.kernel.org/all/20250522092755.GA3277597@tiffany/ Reported-by: Hyesoo Yu <hyesoo.yu@samsung.com> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Peter Xu <peterx@redhat.com> Cc: Zhaoyang Huang <zhaoyang.huang@unisoc.com> Cc: Aijun Sun <aijun.sun@unisoc.com> Cc: Alistair Popple <apopple@nvidia.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> ``` Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com> --- <small>Created 2025-07-03 23:14 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://issues.redhat.com/secure/CreateIssueDetails!init.jspa?pid=12334433&issuetype=1&priority=4&summary=backporter+webhook+issue&components=kernel-workflow+/+backporter)</small> Approved-by: Jarod Wilson <jarod@redhat.com> Approved-by: Waiman Long <longman@redhat.com> Approved-by: Donald Dutile <ddutile@redhat.com> Approved-by: Rafael Aquini <raquini@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents b1afb79 + 61188ec commit adf8dfb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

mm/gup.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,13 +2323,13 @@ static void pofs_unpin(struct pages_or_folios *pofs)
23232323
/*
23242324
* Returns the number of collected folios. Return value is always >= 0.
23252325
*/
2326-
static void collect_longterm_unpinnable_folios(
2326+
static unsigned long collect_longterm_unpinnable_folios(
23272327
struct list_head *movable_folio_list,
23282328
struct pages_or_folios *pofs)
23292329
{
2330+
unsigned long i, collected = 0;
23302331
struct folio *prev_folio = NULL;
23312332
bool drain_allow = true;
2332-
unsigned long i;
23332333

23342334
for (i = 0; i < pofs->nr_entries; i++) {
23352335
struct folio *folio = pofs_get_folio(pofs, i);
@@ -2341,6 +2341,8 @@ static void collect_longterm_unpinnable_folios(
23412341
if (folio_is_longterm_pinnable(folio))
23422342
continue;
23432343

2344+
collected++;
2345+
23442346
if (folio_is_device_coherent(folio))
23452347
continue;
23462348

@@ -2362,6 +2364,8 @@ static void collect_longterm_unpinnable_folios(
23622364
NR_ISOLATED_ANON + folio_is_file_lru(folio),
23632365
folio_nr_pages(folio));
23642366
}
2367+
2368+
return collected;
23652369
}
23662370

23672371
/*
@@ -2438,9 +2442,11 @@ static long
24382442
check_and_migrate_movable_pages_or_folios(struct pages_or_folios *pofs)
24392443
{
24402444
LIST_HEAD(movable_folio_list);
2445+
unsigned long collected;
24412446

2442-
collect_longterm_unpinnable_folios(&movable_folio_list, pofs);
2443-
if (list_empty(&movable_folio_list))
2447+
collected = collect_longterm_unpinnable_folios(&movable_folio_list,
2448+
pofs);
2449+
if (!collected)
24442450
return 0;
24452451

24462452
return migrate_longterm_unpinnable_folios(&movable_folio_list, pofs);

0 commit comments

Comments
 (0)