From nobody Tue Nov 26 17:41:37 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C017B212F19 for ; Wed, 16 Oct 2024 18:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729103208; cv=none; b=OJF2OfhQjUxmVxqPulJv/k7wVs2l4T8pS0xKOxZJ4FK4XtpCxi2ZiJFVO+1aumUAV7iZxwrA/k8SYISHo5Fzrjru4MkGfJCkxuzlkd8ufuP/H5ireaeETQz4b1HpOqcPHp6RwOV5mbMFYTc7KdFV2upmAkTYKFxzWsw5qrztb+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729103208; c=relaxed/simple; bh=Y1pvPzSz6TtO0NwNOIptufkDVrOTI5EKhsiPz7J6yYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NOBurDxQL3+aE1KHZExVs15uq8qYzCZlf8ZEBkEXi9fsfCmEJAAmRypSJmMEhAM7yFdwBIovJ3u78ndIoKUxoRnVxtz1l0bqtCUm/XAnTdMaCM66j37uayTHe3I2tVtBp9o1T8w7wQliNwsHBvabVBYjDl18esULLrrSKooMwIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=PxKECxz0; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PxKECxz0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729103207; x=1760639207; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y1pvPzSz6TtO0NwNOIptufkDVrOTI5EKhsiPz7J6yYM=; b=PxKECxz0GFG5PpDCa/nmVkhyFViFn5QIt8MJYwYGRP4Xu1UVWKy4i+ld Aof4HhiHVsJRW3UQ2JfRSq02i1ow30B+jTZHAfDkJAy2TMz8CrLwXcwG+ /MxHzMDZ6oDHvaoTAaXOFaKluqyvjfUKDb+k3zfJ4C/U2/TXYGCR+0iv6 U4q/BG8tccHGVEkxIlh+O0DEDQONKrS1N+uXfU6IsdW7E8JDFI3IW4/iS ye37t/lGfbip/o3jsttlEC7txE3i+fxGqhQ8XkfEbApL0ib0jXfLuO44j 5T3OiDH52N+0MdwkGpEUrwGrVoil/vZ5UYl1CI4OreaINnPj5G48EdcDm A==; X-CSE-ConnectionGUID: 2un4l6/NS063sYYi2k3vuA== X-CSE-MsgGUID: +nutd58cRP+fB31f3qD3ig== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="39686006" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="39686006" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 11:26:43 -0700 X-CSE-ConnectionGUID: MK97uBo5Tn+tcSA03kCSRw== X-CSE-MsgGUID: gIKrOOOwSb2pvAmcsBYolw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="78269523" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa010.jf.intel.com with ESMTP; 16 Oct 2024 11:26:40 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6A6CE159; Wed, 16 Oct 2024 21:26:38 +0300 (EEST) From: Andy Shevchenko To: Ingo Molnar , Uros Bizjak , Andy Shevchenko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Dennis Zhou , Tejun Heo , Christoph Lameter , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton Subject: [PATCH v2 1/2] x86/percpu: Fix clang warning when dealing with unsigned types Date: Wed, 16 Oct 2024 21:23:51 +0300 Message-ID: <20241016182635.1156168-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241016182635.1156168-1-andriy.shevchenko@linux.intel.com> References: <20241016182635.1156168-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When percpu_add_op() is used with an unsigned argument, it prevents kernel builds with clang, `make W=3D1` and CONFIG_WERROR=3Dy: net/ipv4/tcp_output.c:187:3: error: result of comparison of constant -1 wit= h expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-W= tautological-constant-out-of-range-compare] 187 | NET_ADD_STATS(sock_net(sk), LINUX_MIB_TCPACKCOMPRES= SED, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~ 188 | tp->compressed_ack); | ~~~~~~~~~~~~~~~~~~~ ... arch/x86/include/asm/percpu.h:238:31: note: expanded from macro 'percpu_add= _op' 238 | ((val) =3D=3D 1 || (val) =3D=3D -1)) = ? \ | ~~~~~ ^ ~~ Fix this by casting -1 to the type of the parameter and then compare. Signed-off-by: Andy Shevchenko --- arch/x86/include/asm/percpu.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index c55a79d5feae..e525cd85f999 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -234,9 +234,10 @@ do { \ */ #define percpu_add_op(size, qual, var, val) \ do { \ - const int pao_ID__ =3D (__builtin_constant_p(val) && \ - ((val) =3D=3D 1 || (val) =3D=3D -1)) ? \ - (int)(val) : 0; \ + const int pao_ID__ =3D \ + (__builtin_constant_p(val) && \ + ((val) =3D=3D 1 || \ + (val) =3D=3D (typeof(val))-1)) ? (int)(val) : 0; \ \ if (0) { \ typeof(var) pao_tmp__; \ --=20 2.43.0.rc1.1336.g36b5255a03ac From nobody Tue Nov 26 17:41:37 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3437F2139C4 for ; Wed, 16 Oct 2024 18:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729103208; cv=none; b=M2OzOHGWLWNXUzHXpV38tWi/qf1S5oR4cuMTxBYY3F1pZQ+BLJycmtDSw8u6gL9/oMaAba7hg7mLbWRj8dhvHJONTQPS9f95oVMj9qToIgeAgRYfQ1myxNp8neio5jUxoCQNz3xwiLaGL/4EdLCctpXg2M50dcbhSsFmY3GEnQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729103208; c=relaxed/simple; bh=i+jlu5IJcAwS1nR30IqBmViiQ/7hLgqTK8ynQICvJdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U8Djybzi6jvYqMquDHRW4mTfXbkFlktiQwRgKDqtT0kTMoqkBwetJbnq37rXHiLksiyfnbpbW5sye3+xv8/sv/Ltiwq4PgeE4hWsWRft8EcIWvyctlhe+TbzSHhAobPJWVh3c02xiBMipX6T0jgz0AfK+CBTVXVCa2zQPhzMhg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CTTTlqs2; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CTTTlqs2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729103207; x=1760639207; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i+jlu5IJcAwS1nR30IqBmViiQ/7hLgqTK8ynQICvJdY=; b=CTTTlqs2pDvyO6+LihlUSSDbXVRpkhwytwAstx0193MVwXASO4g6RbBU OIsO3Q7CgmYm+37DuwG3TvY+FTi0dcMEm/9UAekRAaVDM/jthnPpJeBF4 wgnaOVQa0aaJ0/YygHOWxU8DPt0WgDHrcB32MzNeTZn61uwiOVRZJwh2D TTor8mTrE4nvo/oC6Su8u9IAvPyjmcQ1YnE8SCc9q/Tz6gaAZrJ2d/gmN wJSHBJTfWPxEEo0rsaIYHTfHa7YYbJggmdJxuswAjbtYblvLy1K1+wqxU WeqCmOcJYFu4ZwpEj6Ow9WTuMVL+VM9LvCZhs6U0InRvE/cWGrpuV0427 w==; X-CSE-ConnectionGUID: dPDaXa4KQImKXk+S5QOi+Q== X-CSE-MsgGUID: R/YbT0y/QKi+6et1Scv1lQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="39686016" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="39686016" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 11:26:44 -0700 X-CSE-ConnectionGUID: qOkdTDljSWaCVjpBCK00fg== X-CSE-MsgGUID: Ogdlfdq1TzORnKxcVJdobw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="78269525" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa010.jf.intel.com with ESMTP; 16 Oct 2024 11:26:40 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7CE681C4; Wed, 16 Oct 2024 21:26:38 +0300 (EEST) From: Andy Shevchenko To: Ingo Molnar , Uros Bizjak , Andy Shevchenko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Dennis Zhou , Tejun Heo , Christoph Lameter , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton Subject: [PATCH v2 2/2] percpu: Add a test case for the specific 64-bit value addition Date: Wed, 16 Oct 2024 21:23:52 +0300 Message-ID: <20241016182635.1156168-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241016182635.1156168-1-andriy.shevchenko@linux.intel.com> References: <20241016182635.1156168-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Andy Shevchenko --- lib/percpu_test.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/percpu_test.c b/lib/percpu_test.c index 4a3d70bbc1a0..ce7124b16dab 100644 --- a/lib/percpu_test.c +++ b/lib/percpu_test.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only +#include #include =20 /* validate @native and @pcp counter values match @expected */ @@ -24,8 +25,9 @@ static int __init percpu_test_init(void) * +ul_one/-ul_one below would replace with inc/dec instructions. */ volatile unsigned int ui_one =3D 1; - long l =3D 0; + unsigned long long ull =3D 0; unsigned long ul =3D 0; + long l =3D 0; =20 pr_info("percpu test start\n"); =20 @@ -112,6 +114,13 @@ static int __init percpu_test_init(void) CHECK(ul, ulong_counter, -1); CHECK(ul, ulong_counter, ULONG_MAX); =20 + ul =3D ull =3D 0; + __this_cpu_write(ulong_counter, 0); + + ul =3D ull +=3D UINT_MAX; + __this_cpu_add(ulong_counter, ull); + CHECK(ul, ulong_counter, UINT_MAX); + ul =3D 3; __this_cpu_write(ulong_counter, 3); =20 --=20 2.43.0.rc1.1336.g36b5255a03ac