* + lib-introduce-hierarchical-per-cpu-counters-fix.patch added to mm-unstable branch
@ 2026-03-14 21:45 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-03-14 21:45 UTC (permalink / raw)
To: mm-commits, objecting, mathieu.desnoyers, dennis, devnexen, akpm
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3473 bytes --]
The patch titled
Subject: lib: fix compare_delta parameter order in percpu_counter_tree
has been added to the -mm mm-unstable branch. Its filename is
lib-introduce-hierarchical-per-cpu-counters-fix.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/lib-introduce-hierarchical-per-cpu-counters-fix.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: David Carlier <devnexen@gmail.com>
Subject: lib: fix compare_delta parameter order in percpu_counter_tree
Date: Fri, 13 Mar 2026 17:54:24 +0000
The compare_delta() helper takes (delta, accuracy_neg, accuracy_pos), but
every call site passes (delta, accuracy_pos, accuracy_neg) — the last
two arguments are consistently swapped.
The documented invariant (include/linux/percpu_counter_tree.h) is:
(precise_sum - under) <= approx_sum <= (precise_sum + over)
Which means precise_sum is in [approx_sum - over, approx_sum + under].
For a positive delta (v - approx_sum >= 0), accuracy_pos must be
"under" (the maximum amount precise_sum can exceed approx_sum).
For a negative delta, accuracy_neg must be "over". Since under > over
always (batch_size * M vs (batch_size - 1) * M), swapping them causes
false definitive results: the functions return 1 ("v > counter") when
the correct answer is 0 (indeterminate).
This affects all comparison functions:
- percpu_counter_tree_approximate_compare_value()
- percpu_counter_tree_approximate_compare()
- percpu_counter_tree_precise_compare_value()
- percpu_counter_tree_precise_compare()
The precise variants are also affected because their approximate
fast-path can short-circuit with a wrong result, skipping the precise
sum computation.
Fix by swapping the parameter order in compare_delta() itself, since all
call sites are consistently swapped.
Link: https://lkml.kernel.org/r/20260313175424.132735-1-devnexen@gmail.com
Signed-off-by: David Carlier <devnexen@gmail.com>
Reviewed-by: Josh Law <objecting@objecting.org>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
lib/percpu_counter_tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/lib/percpu_counter_tree.c~lib-introduce-hierarchical-per-cpu-counters-fix
+++ a/lib/percpu_counter_tree.c
@@ -458,7 +458,7 @@ long percpu_counter_tree_precise_sum(str
EXPORT_SYMBOL_GPL(percpu_counter_tree_precise_sum);
static
-int compare_delta(long delta, unsigned long accuracy_neg, unsigned long accuracy_pos)
+int compare_delta(long delta, unsigned long accuracy_pos, unsigned long accuracy_neg)
{
if (delta >= 0) {
if (delta <= accuracy_pos)
_
Patches currently in -mm which might be from devnexen@gmail.com are
lib-introduce-hierarchical-per-cpu-counters-fix.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-03-14 21:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-14 21:45 + lib-introduce-hierarchical-per-cpu-counters-fix.patch added to mm-unstable branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.