From nobody Fri Dec 19 06:17:53 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C0FB24BC09 for ; Mon, 24 Feb 2025 14:47:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740408454; cv=none; b=URqh9g3Xk+o1Bf1h8K3+Uq2qO2CLBVKDnz5vVb2koZZ03wCsECbGP8n/0iX0SYX4MjjmR8e2H8+NDOQCQXZ18RBnA1t4MYYRFmVrPHK3PE5938Y0xzIobyscWNiTrPeItjCcMEI3cYYU+s0ftoyNTaLy48wfdY0/LwDvfROq3W0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740408454; c=relaxed/simple; bh=P68516FL20Q73MKJrvoy+KUUJ1cdsXSffNv5b3x6YAY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AV0Ir3vcX0A/M8KQ3d0MB1JiGsND4RpXY3I0UupTPjrfwVjjbx0yCfWJdQyfnuxsYm7oehiGvehl7FU/IJ01lamTEKVAeu/uWXKKQZqWPu4RL0N7WXphP7yYf1nbMZzTFfLSXK1v+bE7A26FJm+wFZM+tLZc1/7SMuF9h9A7sTA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UG2p7037; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UG2p7037" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43942e82719so33926735e9.2 for ; Mon, 24 Feb 2025 06:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740408449; x=1741013249; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Cx79yAQvvtOreEIgXQgmWnaukRcNTY0vcbEckVNMqhA=; b=UG2p7037ZKGP2jLzBbvtmbmH6p+4QeJjtUD4CwALbDjCWxx1i6TYevWluhCA7bI2p9 VnpJ4aeHW8v0s7cnmFB7ExgktkL4WxmiGuwwEZObJ/ONYiwofOA8xjFmokhmwxgEpu87 /56lF4wTnyJoF3meowETV4e1h9NcgB+xRaQI60F0rexuizMmKLkuy7NYK1bbNw4L20DB sZgRdc4K3CLaK0AbSeW6BBNr89sjI9FN7bhaWSMfln8kqp/mAnSDgg90gHmonG0lKME/ ShRxz90G9wMdjqLXXbZCkuyB9m0JBwgVaoX0DpPwwc2+4FKJbSM91jIKPCzGJwTfx5iR ZntA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740408449; x=1741013249; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Cx79yAQvvtOreEIgXQgmWnaukRcNTY0vcbEckVNMqhA=; b=vYqOTma6uoQVw2xsZLU/mUhuu4L51k/8oRxqMEnSzQOQ2fkzxTnNdH0izse5Os5Sze MGFoOXBrd5tlnuw0G4Rkoj5EkJYtSWA4wQkMFF3qmQpvUuB107TVm5kwa1i4h+aBBRmk 5htFpr4ZlCK++10l7FJj9dS36qtKIvCyB+PMpAAJMZdUF4SSDDqBimIX7bSnGd+Oc10x 3VamzNuL5NC4O9EMonEC93jD2uR+z1Kp9AvKhJ223FHDke956Y6HE4Goxd6JQsTg/8rX 2s/qN+WUrmqQ8VejuRooFjcpv6vI3cQp8ClEnO4bXKD7OUrFtE1G+b47zd/5e0UVXNMr kIrA== X-Forwarded-Encrypted: i=1; AJvYcCW7Ze11vlJEiL0KWKSS1+tvcSVJPMeV9GVVgOxneRMSgz0zJXBGJFrvJ9M8j8hm8DtnxhjZPiTOeAukbK8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxwwof/H7c4/qjif2Gfcm62d8q2OGATUUSzfVXv6lrKw8e/J2Qh QeKnR+guPjMKhBSb27UyuNoG34eOZ2+1JXp/mGNCnPx0urAuAdQ/aA1sGhY0umNTz+ku7KZItwT +Yth4YTUZ1A== X-Google-Smtp-Source: AGHT+IFgzCZS8e4eXhzZ0Xu7b9rwIWCAcRNX6T6m7WXpW/BUkn6CvzEZFi5nDx4xFkLSY1Sid/xnIUacfnELow== X-Received: from wmqd6.prod.google.com ([2002:a05:600c:34c6:b0:439:98eb:28cd]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:b9b:b0:439:8ef6:5782 with SMTP id 5b1f17b1804b1-439ae1e8be4mr121933775e9.10.1740408449496; Mon, 24 Feb 2025 06:47:29 -0800 (PST) Date: Mon, 24 Feb 2025 14:47:11 +0000 In-Reply-To: <20250224-page-alloc-kunit-v1-0-d337bb440889@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250224-page-alloc-kunit-v1-0-d337bb440889@google.com> X-Mailer: b4 0.15-dev Message-ID: <20250224-page-alloc-kunit-v1-1-d337bb440889@google.com> Subject: [PATCH RFC 1/4] kunit: Allocate assertion data with GFP_ATOMIC From: Brendan Jackman To: Brendan Higgins , David Gow , Rae Moar , Andrew Morton , David Hildenbrand , Oscar Salvador Cc: Lorenzo Stoakes , Vlastimil Babka , Michal Hocko , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Brendan Jackman , Yosry Ahmed Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 --- 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..f08656c5fb247b510c4215445cc= 307ed1205a96c 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) !=3D len) return false; =20 - buffer =3D kmalloc(len+1, GFP_KERNEL); + buffer =3D kmalloc(len+1, GFP_ATOMIC); if (!buffer) return false; =20 diff --git a/lib/kunit/resource.c b/lib/kunit/resource.c index f0209252b179f8b48d47ecc244c468ed80e23bdc..eac511af4f8d7843d58c4e3976c= 77a9c4def86a7 100644 --- a/lib/kunit/resource.c +++ b/lib/kunit/resource.c @@ -98,7 +98,7 @@ int kunit_add_action(struct kunit *test, void (*action)(v= oid *), void *ctx) =20 KUNIT_ASSERT_NOT_NULL_MSG(test, action, "Tried to action a NULL function!= "); =20 - action_ctx =3D kzalloc(sizeof(*action_ctx), GFP_KERNEL); + action_ctx =3D kzalloc(sizeof(*action_ctx), GFP_ATOMIC); if (!action_ctx) return -ENOMEM; =20 diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 146d1b48a0965e8aaddb6162928f408bbb542645..08d0ff51bd85845a08b40cd3933= dd588bd10bddf 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, =20 kunit_set_failure(test); =20 - stream =3D kunit_alloc_string_stream(test, GFP_KERNEL); + stream =3D 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", --=20 2.48.1.601.g30ceb7b040-goog