From: Waiman Long Date: Fri, 25 Aug 2023 16:49:47 +0000 (-0400) Subject: mm/kmemleak: move up cond_resched() call in page scanning loop X-Git-Tag: v6.6-rc1~53^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e68d343d2720779362cb7160cb7f4bd24979b2b4;p=thirdparty%2Flinux.git mm/kmemleak: move up cond_resched() call in page scanning loop Commit bde5f6bc68db ("kmemleak: add scheduling point to kmemleak_scan()") added a cond_resched() call to the struct page scanning loop to prevent soft lockup from happening. However, soft lockup can still happen in that loop in some corner cases when the pages that satisfy the "!(pfn & 63)" check are skipped for some reasons. Fix this corner case by moving up the cond_resched() check so that it will be called every 64 pages unconditionally. Link: https://lkml.kernel.org/r/20230825164947.1317981-1-longman@redhat.com Fixes: bde5f6bc68db ("kmemleak: add scheduling point to kmemleak_scan()") Signed-off-by: Waiman Long Cc: Catalin Marinas Cc: Yisheng Xie Signed-off-by: Andrew Morton --- diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 2918150e31bd9..54c2c90d3abc9 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1584,6 +1584,9 @@ static void kmemleak_scan(void) for (pfn = start_pfn; pfn < end_pfn; pfn++) { struct page *page = pfn_to_online_page(pfn); + if (!(pfn & 63)) + cond_resched(); + if (!page) continue; @@ -1594,8 +1597,6 @@ static void kmemleak_scan(void) if (page_count(page) == 0) continue; scan_block(page, page + 1, NULL); - if (!(pfn & 63)) - cond_resched(); } } put_online_mems();