Skip to contentSkip to conversation

percpu-fix-race-on-alloc-failed-warning-limit.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Sep 9, 2025

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: percpu: fix race on alloc failed warning limit
has been removed from the -mm tree. Its filename was
percpu-fix-race-on-alloc-failed-warning-limit.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Vlad Dumitrescu <[email protected]>
Subject: percpu: fix race on alloc failed warning limit
Date: Fri, 22 Aug 2025 15:55:16 -0700

The 'allocation failed, ...' warning messages can cause unlimited log spam, contrary to the implementation's intent.

The warn_limit variable is accessed without synchronization. If more than <warn_limit> threads enter the warning path at the same time, the variable will get decremented past 0. Once it becomes negative, the non-zero check will always return true leading to unlimited log spam.

Use atomic operation to access warn_limit and change condition to test for non-negative (>= 0) - atomic_dec_if_positive will return -1 once warn_limit becomes 0. Continue to print disable message alongside the last warning.

While the change cited in Fixes is only adjacent, the warning limit implementation was correct before it. Only non-atomic allocations were considered for warnings, and those happened to hold pcpu_alloc_mutex while accessing warn_limit.

[[email protected]: prevent warn_limit from going negative, per Christoph Lameter]
Fixes f7d77dfc91f7 ("mm/percpu.c: print error message too if atomic alloc failed")
Cc Christoph Lameter (Ampere) <[email protected]>
Cc Dennis Zhou <[email protected]>
Cc Tejun Heo <[email protected]>

---

 mm/percpu.c |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
mm/percpu.c renamed from mm/percpu.c~percpu-fix-race-on-alloc-failed-warning-limit +12 -8
@@ -1734,7 +1734,7 @@ void __percpu *pcpu_alloc_noprof(size_t
 	bool is_atomic;
 	bool do_warn;
 	struct obj_cgroup *objcg = NULL;
-	static int warn_limit = 10;
+	static atomic_t warn_limit = ATOMIC_INIT(10);
 	struct pcpu_chunk *chunk, *next;
 	const char *err;
 	int slot, off, cpu, ret;
@@ -1904,13 +1904,17 @@ fail_unlock:
 fail:
 	trace_percpu_alloc_percpu_fail(reserved, is_atomic, size, align);
 
-	if (do_warn && warn_limit) {
-		pr_warn("allocation failed, size=%zu align=%zu atomic=%d, %s\n",
-			size, align, is_atomic, err);
-		if (!is_atomic)
-			dump_stack();
-		if (!--warn_limit)
-			pr_info("limit reached, disable warning\n");
+	if (do_warn) {
+		int remaining = atomic_dec_if_positive(&warn_limit);
+
+		if (remaining >= 0) {
+			pr_warn("allocation failed, size=%zu align=%zu atomic=%d, %s\n",
+				size, align, is_atomic, err);
+			if (!is_atomic)
+				dump_stack();
+			if (remaining == 0)
+				pr_info("limit reached, disable warning\n");
+		}
 	}
 
 	if (is_atomic) {

_

Patches currently in -mm which might be from [email protected] are