Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

percpu: add a test case for the specific 64-bit value addition

It might be a corner case when we add UINT_MAX as 64-bit unsigned value to
the percpu variable as it's not the same as -1 (ULONG_LONG_MAX). Add a
test case for that.

Link: https://lkml.kernel.org/r/20241016182635.1156168-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Christoph Lameter <cl@linux.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Andy Shevchenko and committed by
Andrew Morton
4a7bba1d 6c2625e9

+10 -1
+10 -1
lib/percpu_test.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 + #include <linux/limits.h> 2 3 #include <linux/module.h> 3 4 4 5 /* validate @native and @pcp counter values match @expected */ ··· 25 24 * +ul_one/-ul_one below would replace with inc/dec instructions. 26 25 */ 27 26 volatile unsigned int ui_one = 1; 28 - long l = 0; 27 + unsigned long long ull = 0; 29 28 unsigned long ul = 0; 29 + long l = 0; 30 30 31 31 pr_info("percpu test start\n"); 32 32 ··· 113 111 __this_cpu_sub(ulong_counter, ui_one); 114 112 CHECK(ul, ulong_counter, -1); 115 113 CHECK(ul, ulong_counter, ULONG_MAX); 114 + 115 + ul = ull = 0; 116 + __this_cpu_write(ulong_counter, 0); 117 + 118 + ul = ull += UINT_MAX; 119 + __this_cpu_add(ulong_counter, ull); 120 + CHECK(ul, ulong_counter, UINT_MAX); 116 121 117 122 ul = 3; 118 123 __this_cpu_write(ulong_counter, 3);