mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lib: kunit_iov_iter: repeatedly call alloc_pages_bulk()
@ 2026-05-24 13:02 Thomas Weißschuh
  2026-05-25 15:58 ` Christian A. Ehrhardt
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Weißschuh @ 2026-05-24 13:02 UTC (permalink / raw)
  To: Christian A. Ehrhardt, Andrew Morton; +Cc: linux-kernel, Thomas Weißschuh

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>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib: kunit_iov_iter: repeatedly call alloc_pages_bulk()
  2026-05-24 13:02 [PATCH] lib: kunit_iov_iter: repeatedly call alloc_pages_bulk() Thomas Weißschuh
@ 2026-05-25 15:58 ` Christian A. Ehrhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Christian A. Ehrhardt @ 2026-05-25 15:58 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Andrew Morton, linux-kernel


Hi Thomas,

On Sun, May 24, 2026 at 03:02:45PM +0200, Thomas Weißschuh wrote:
> 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")

Diff LGTM but the "Fixes:" tag should probably point to this commit instead:
2d71340ff1d4 iov_iter: Kunit tests for copying to/from an iterator


> 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);
> 

Best regards,
Christian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-25 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-24 13:02 [PATCH] lib: kunit_iov_iter: repeatedly call alloc_pages_bulk() Thomas Weißschuh
2026-05-25 15:58 ` Christian A. Ehrhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®