]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib: kunit_iov_iter: repeatedly call alloc_pages_bulk()
authorThomas Weißschuh <linux@weissschuh.net>
Tue, 26 May 2026 16:43:40 +0000 (18:43 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 4 Jun 2026 21:49:27 +0000 (14:49 -0700)
alloc_pages_bulk() is not guaranteed to return all requested pages in a
single call.

Call it repeatedly until all pages have been allocated or no more progress
is being made.

Link: https://lore.kernel.org/20260526-kunit_iov_iter-alloc_bulk-v2-1-24fbcd995c61@weissschuh.net
Fixes: 2d71340ff1d4 ("iov_iter: Kunit tests for copying to/from an iterator")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Cc: "Christian A. Ehrhardt" <lk@c--e.de>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/tests/kunit_iov_iter.c

index f02f7b7aa79605c918de8a22ad9ca5b359f61549..1e6fce9cb255ffd07ef0fdbaf5b08402f9ba333d 100644 (file)
@@ -53,7 +53,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test,
                                            size_t npages)
 {
        struct page **pages;
-       unsigned long got;
+       unsigned long got, last;
        void *buffer;
        unsigned int i;
 
@@ -61,7 +61,15 @@ static void *__init iov_kunit_create_buffer(struct kunit *test,
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages);
        *ppages = pages;
 
-       got = alloc_pages_bulk(GFP_KERNEL, npages, pages);
+       got = 0;
+       while (true) {
+               last = got;
+               got = alloc_pages_bulk(GFP_KERNEL, npages, pages);
+
+               if (last == got || got == npages)
+                       break;
+       }
+
        if (got != npages) {
                release_pages(pages, got);
                kvfree(pages);