[PATCH] lib: kunit_iov_iter: repeatedly call alloc_pages_bulk()

Thomas Weißschuh posted 1 patch 3 hours ago
lib/tests/kunit_iov_iter.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
[PATCH] lib: kunit_iov_iter: repeatedly call alloc_pages_bulk()
Posted by Thomas Weißschuh 3 hours ago
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.

Fixes: 0913b7554726 ("lib: kunit_iov_iter: add tests for extract_iter_to_sg")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 lib/tests/kunit_iov_iter.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/tests/kunit_iov_iter.c b/lib/tests/kunit_iov_iter.c
index f02f7b7aa796..1e6fce9cb255 100644
--- a/lib/tests/kunit_iov_iter.c
+++ b/lib/tests/kunit_iov_iter.c
@@ -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);

---
base-commit: 79bd2dded182b1d458b18e62684b7f82ffc682e5
change-id: 20260523-kunit_iov_iter-alloc_bulk-767126626ecc

Best regards,
--  
Thomas Weißschuh <linux@weissschuh.net>