From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 D81A22C15A5 for ; Mon, 16 Mar 2026 14:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773671892; cv=none; b=g1riPACPEm+Y7KeIxC7+u2lVyoOvWej5IY3f7PJC6GGNPfQHPVOiucMa/aLmI7hbXxAjA872AajIrS9SpHawnl3ncpfr31cmJrcMwcU+MF/I/NAdJ93A9qRuxr8LlD7R6pwKaKjWX+48PzrSfkB09cBOMWdc7dLHE58SzSFQUTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773671892; c=relaxed/simple; bh=OG3mngXWd0Rs11/xwTUn9M9+Afd8qBr1fPXEAfqlJLk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WjXJIrxq7Howo61x3XlRL0bp2POM9X5NMa/lCxDY4MRI+O6Q92otSQpjhOMxF/IkCoAb7R/o0bzlrDhGm7+FV9i5s5LikCh0rN2cfA5Ucxnf+Zti8JXmfmPbjE6jNWmNL4Gw7N0ZFMvF8T/bDJfq6YWOscEXVoDI0Byuhfm30FQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XX+z8QJT; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XX+z8QJT" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-48540d21f7dso55086155e9.0 for ; Mon, 16 Mar 2026 07:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773671889; x=1774276689; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qbAba3ykAuvBj2oUAd/OGQP3DrNnRZycn1qYo4T6O64=; b=XX+z8QJTtl7RzJPfgMWN5vGjj1LracCmOjvwYl/Q5Sak8xVjMuMbfHPjewCX7Y2dM4 D+YKIgAl07AfNPSgHdboQlC4GxD9eKGFHJr5iVe1p08ZYwnuM4tmYF8p98zV5OFImpJ1 vn2svIpZK8n2lzWcBWn/pDo1kzKJV5Xm9TfFkKAfJX7DMyHok2r+4P8fJ+ka2MGryRig Y2Ez4VbnjKFIcskPK38ZOOVYW9saJqQhLpt2y207mERjk35DkKyTgauFsu3jNglWvEpC bxPWyG8EyBBORXAzDZY1HcLUc2KI9zE0h4HoiTAd4C1LGHGM0vjxf+Af+83o0vGFePqB Fdzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773671889; x=1774276689; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qbAba3ykAuvBj2oUAd/OGQP3DrNnRZycn1qYo4T6O64=; b=TLe0dbhIYRYIwozCuZ5q35NXKBqgFIJl1/89TEXD04GVSiebMU2us/ti+m6Sa/OL5d ObZWxAtGW/KrB3bZtDBw3EL90BT6IDKv4SOfMkx9E8PkUlSEEuUFo0R//PzJq8e6XHEw tIDMx2kUzZTf30MA3N8uOcGGunEm3GjMX/6hlxE+LmxZS9br0ACI+ZvX0PcXinLBFyS3 NCdypduX/XchZqCO9vWtnQufeZvJaK++xkyLxLXQ7LndzJP5Mf97wUVHp8/qlqQJmOFq 8CXHYSC9lr8NZCrE/rvH1kFMslcekkBw/pHqAieOQCrIK6fxg0winpCVhtJ0D3cfbsgQ umWA== X-Forwarded-Encrypted: i=1; AJvYcCWjz1uUcQpdjFQql7bqu9qokpp8VGqQhvYDQQddMP97fivBnW13IgTJUFPJZeR4Jfffvn74xDXSguNrrrs=@vger.kernel.org X-Gm-Message-State: AOJu0YwYehoxcRa9ADVpuqSXSH1B5u5M/B8PPTkJECre4vzHKxdPi1ay h5sfoaDmKphBkoLQgr8tOLNngzyquIRz2zb9Q7jFE5dxqNMx3KV33rN+zISCD5Uj X-Gm-Gg: ATEYQzwAReFAgXB6SVj5vRq+zxj89bd28D4q9qL8Mt52+Q73o1YyhvZLr59rnuAFcAn NJ5JIIB17BxdsRPdQKV9WzbogrztyvV9iEdziW3OT1GBnwMhzYzfaAcVGAA17OtkoZ33+48nox/ MzJgQAXe9GoEaF6nN5hwadiBIG79qAamyeF6usWtlDxca3b1/UQQ31qAlv7ntkhYvq1sUBXv9n7 mi9FwWu8sKjLA75cOxqrveUIiL8uY+SyqCrJt50grfyomCgCmyzwLynA3LRxukJTguta4/5wiwN I7Tb/sADpWgg9iLge4sBDnphrsxaj+mRbrULgWpTjJAw6+0mR2bwGZbyOCroWlwr0ajin/OrGZN H/vEWx8gHbUCIceZ1BuNmruOfJY6+fFCkQsSXOJZ+Vdy49Hp5xey14yJSwH9oqoMIFPFYRkTfy2 WS1aQwmh65vvQJIsy0c86/KIhiX1ttztxxM32JXjBsGJ6jHlmfFK3p7n8agbT32UWQqkZFlLsMx rfPF0b2F39tdIommRPE X-Received: by 2002:a05:600c:1c05:b0:47e:e48b:506d with SMTP id 5b1f17b1804b1-48556702848mr230552705e9.16.1773671888966; Mon, 16 Mar 2026 07:38:08 -0700 (PDT) Received: from rozandragon.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4854e2537c3sm458521895e9.15.2026.03.16.07.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2026 07:38:08 -0700 (PDT) From: David Carlier To: Josh Law , Dennis Zhou Cc: Mathieu Desnoyers , Andrew Morton , linux-kernel@vger.kernel.org, David Carlier Subject: [PATCH 1/2] lib: fix compare_delta parameter order in percpu_counter_tree Date: Mon, 16 Mar 2026 14:38:04 +0000 Message-ID: <20260316143805.36805-1-devnexen@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Signed-off-by: David Carlier --- lib/percpu_counter_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/percpu_counter_tree.c b/lib/percpu_counter_tree.c index 5c8fc2dcdc16..beb1144e6450 100644 --- a/lib/percpu_counter_tree.c +++ b/lib/percpu_counter_tree.c @@ -458,7 +458,7 @@ long percpu_counter_tree_precise_sum(struct percpu_counter_tree *counter) 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) -- 2.51.0