linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Brendan Jackman <jackmanb@google.com>
To: Brendan Higgins <brendan.higgins@linux.dev>,
	David Gow <davidgow@google.com>,  Rae Moar <rmoar@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 David Hildenbrand <david@redhat.com>,
	Oscar Salvador <osalvador@suse.de>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	 Michal Hocko <mhocko@kernel.org>,
	linux-kselftest@vger.kernel.org,  kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	 Brendan Jackman <jackmanb@google.com>,
	Yosry Ahmed <yosry.ahmed@linux.dev>
Subject: [PATCH RFC 1/4] kunit: Allocate assertion data with GFP_ATOMIC
Date: Mon, 24 Feb 2025 14:47:11 +0000	[thread overview]
Message-ID: <20250224-page-alloc-kunit-v1-1-d337bb440889@google.com> (raw)
In-Reply-To: <20250224-page-alloc-kunit-v1-0-d337bb440889@google.com>

At present KUnit doesn't handle assertions happening in atomic contexts.
A later commit will add tests that make assertions with spinlocks held.

In preparation, switch to GFP_ATOMIC.

"Just use GFP_ATOMIC" is not generally a solution to this kind of
problem: since it uses up memory reserves, instead it should be only
used when truly needed.

However, for test code that should not be expected to run in production
systems it seems tolerable, given that it avoids creating more complex
APIs.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
 lib/kunit/assert.c   | 2 +-
 lib/kunit/resource.c | 2 +-
 lib/kunit/test.c     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
index 867aa5c4bccf764757e190948b8e3a2439116786..f08656c5fb247b510c4215445cc307ed1205a96c 100644
--- a/lib/kunit/assert.c
+++ b/lib/kunit/assert.c
@@ -101,7 +101,7 @@ VISIBLE_IF_KUNIT bool is_literal(const char *text, long long value)
 	if (strlen(text) != len)
 		return false;
 
-	buffer = kmalloc(len+1, GFP_KERNEL);
+	buffer = kmalloc(len+1, GFP_ATOMIC);
 	if (!buffer)
 		return false;
 
diff --git a/lib/kunit/resource.c b/lib/kunit/resource.c
index f0209252b179f8b48d47ecc244c468ed80e23bdc..eac511af4f8d7843d58c4e3976c77a9c4def86a7 100644
--- a/lib/kunit/resource.c
+++ b/lib/kunit/resource.c
@@ -98,7 +98,7 @@ int kunit_add_action(struct kunit *test, void (*action)(void *), void *ctx)
 
 	KUNIT_ASSERT_NOT_NULL_MSG(test, action, "Tried to action a NULL function!");
 
-	action_ctx = kzalloc(sizeof(*action_ctx), GFP_KERNEL);
+	action_ctx = kzalloc(sizeof(*action_ctx), GFP_ATOMIC);
 	if (!action_ctx)
 		return -ENOMEM;
 
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 146d1b48a0965e8aaddb6162928f408bbb542645..08d0ff51bd85845a08b40cd3933dd588bd10bddf 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -279,7 +279,7 @@ static void kunit_fail(struct kunit *test, const struct kunit_loc *loc,
 
 	kunit_set_failure(test);
 
-	stream = kunit_alloc_string_stream(test, GFP_KERNEL);
+	stream = kunit_alloc_string_stream(test, GFP_ATOMIC);
 	if (IS_ERR(stream)) {
 		WARN(true,
 		     "Could not allocate stream to print failed assertion in %s:%d\n",

-- 
2.48.1.601.g30ceb7b040-goog



  reply	other threads:[~2025-02-24 14:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24 14:47 [PATCH RFC 0/4] mm: KUnit tests for the page allocator Brendan Jackman
2025-02-24 14:47 ` Brendan Jackman [this message]
2025-02-24 14:47 ` [PATCH RFC 2/4] mm/page_alloc_test: Add empty KUnit boilerplate Brendan Jackman
2025-02-24 14:47 ` [PATCH RFC 3/4] mm/page_alloc_test: Add logic to isolate a node for testing Brendan Jackman
2025-02-24 18:33   ` Yosry Ahmed
2025-02-25 11:20     ` Brendan Jackman
2025-02-26 10:33       ` Brendan Jackman
2025-02-24 14:47 ` [PATCH RFC 4/4] mm/page_alloc_test: Add smoke-test for page allocation Brendan Jackman
2025-02-24 18:26   ` Yosry Ahmed
2025-02-25 11:14     ` Brendan Jackman
2025-02-26 10:47   ` Brendan Jackman
2025-02-25 10:01 ` [PATCH RFC 0/4] mm: KUnit tests for the page allocator David Hildenbrand
2025-02-25 12:56   ` Brendan Jackman
2025-02-26 11:52     ` David Hildenbrand
2025-02-26 12:21       ` Brendan Jackman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250224-page-alloc-kunit-v1-1-d337bb440889@google.com \
    --to=jackmanb@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.higgins@linux.dev \
    --cc=david@redhat.com \
    --cc=davidgow@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@kernel.org \
    --cc=osalvador@suse.de \
    --cc=rmoar@google.com \
    --cc=vbabka@suse.cz \
    --cc=yosry.ahmed@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox