From patchwork Mon Dec 2 17:33:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DCB87D7831C for ; Mon, 2 Dec 2024 17:42:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yTDbXQrXeL1QtkcRT6P5tuG++7/ooNKDiK5MNH+dj+8=; b=pGxqA7BpI6SjKp7bKCWnFr7kgW vMi6XPaag6ar0nPwZ1j1UM2WJbZKv0zyYnFybVwIhqV7YGfK6+QPch3Lt9UFCW+1LieCvd1diL+CJ BAKO09XoOPZkItr/PMvq7qT8s7R/U6oNYMGuTd/iSjUM89t3Vhp+TbD5XR5/fdC1cWzT08Y7cml7K jtHlfwZIybFm+Zq6G4yVNuUhhEEnYzMhnEA2xU0ifj4yV1+HoEYM0fb5z2fpwhGWf5ngrCTp0/qFc eZ0J0OSTpkkqJB8DXYrlLO7xQn9KoVhvvPoyKDwe7Q6xkXSSTiE4K8qCgzy5XgIXTVEmRc1LC/QyF ah1R1bng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIAR6-000000073g7-2lya; Mon, 02 Dec 2024 17:42:16 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAK9-000000071zi-2bTM for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:06 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 448955C5D5B; Mon, 2 Dec 2024 17:34:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id EB054C4CED6; Mon, 2 Dec 2024 17:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=5SkdVpyxMkwcefHUvrmeRmooVspzWLLjyCNkLAyYF/4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=krYcOchpdZfTOGmmZmYXGkkzng0VBYzBaTIPS/JdWNiJdmt/4S7+V2deZeuJtDiHJ 5bOfjWx9PMCJkw4vWMJA+j7RGJgyQT3MCvZz+ywWGgXkUPQ1I8zhp2RRNDd7wmPgUC KVr3TdRx7r3vS7sNZQQ4VuZSeMJ1Co4MyFc7SbZRWDfa4cIk4lQ19T0FRsrpwOa17T JopKvCO/OnNKT3V7n07PfE9Ll3My7kWEoWbthp4JMgarfO7M35ovTZ+SUQIDeAkdh8 VxQs0KDQFLoqYMNE9XZ9vIlYg+Eia5POewyoXqK+ltXanlAIbCfNk8+zvx51tcJKic OeLS9BafEnm7Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2CC9D7833C; Mon, 2 Dec 2024 17:35:03 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:23 +0900 Subject: [PATCH 01/10] compiler.h: add statically_false() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-1-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1089; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=MUJOQQOOJL9dYDVaPT65KhZRSmD+ZVJ1pjvxSAixArY=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+74/KH7/U7qegXjXTofXb3TYljXrmuVYbMjW/tLXe4 w0P49vQUcrCIMbFICumyLKsnJNboaPQO+zQX0uYOaxMIEMYuDgFYCKiExj+h59n32w4XUS9Q6Hd rUTL9LrKv/cufhltT6M9vi38WfriOSPDth1s9Y4XTgudV69oFplrmhzR2RRm0jljjlHtl08TxWX ZAQ== X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_093505_756979_F0B06A45 X-CRM114-Status: GOOD ( 12.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol For completion, add statically_false() which is the equivalent of statically_true() except that it will return true only if the input is known to be false at compile time. The == operator is used instead of the ! negation to prevent a -Wint-in-bool-context compiler warning when the argument is not a boolean. For example: statically_false(var * 0) Signed-off-by: Vincent Mailhol --- include/linux/compiler.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 469a64dd6495fefab2c85ffc279568a657b72660..a2a56a50dd85227a4fdc62236a2710ca37c5ba52 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -314,6 +314,7 @@ static inline void *offset_to_ptr(const int *off) * values to determine that the condition is statically true. */ #define statically_true(x) (__builtin_constant_p(x) && (x)) +#define statically_false(x) (__builtin_constant_p(x) && (x) == 0) /* * This is needed in functions which generate the stack canary, see From patchwork Mon Dec 2 17:33:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7EB6ED7833D for ; Mon, 2 Dec 2024 17:46:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=joZYj5b0s15HYUbIVYcG1b7ouBChg5WQYHZmgetOqSY=; b=HrySieCtMZTygAax0SGpJOlytJ JRV6sj54/+/O2xom0mgxWMTy//t61OvJFwatl/t5yL+v110ZZLPh+sXC+XVPeejuuF0D69LQ7livK JJuEsnsS2Ps2VgZK94aj0QUn4hOSzDJxl/mcawYdwqTgkHyBaBJtRnIHmWB2P8tXFOUUATxVYfsSq qBKniieeSCW6NMXxUXWRzQE1Qqwl6CskDSDvyrN92XH4PNwKcUr6bkfh4zACUpMGGjpUoN+1AEa6T JtExSlXy6QtaU8xFz79omUQHI9xzX8vU4gLJcPd4Naaro3eQtLEyat/21O8giRP9XX4zYoH546qGM eshuWevg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIAUw-0000000746l-3SmF; Mon, 02 Dec 2024 17:46:14 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKF-00000007237-2aFM for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Dec 2024 17:35:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Reply-To:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Content-ID:Content-Description; bh=joZYj5b0s15HYUbIVYcG1b7ouBChg5WQYHZmgetOqSY=; b=E2OAsokemteQNzRLWCI+XhbGV2 Zy18fATNC8mvAOLl/BfBB2SzYlM8tDOjURCgQXQknoMX6F+vzFYtOmr/KTnQjJB3LVy+kYNRMlEqH Tf1pgAL5kFW73oq+iVyD6g2wWrirNUkWcnMP2DWmu8uoXBWwBT7ZffZRrVvcHajXtBQX8eD8HUU+h BkNBIRalApad/vZY8CypWxF9wD6caVQLDGOQmdsAORIiOKazUKUDwFbJhGJbR5QZOprMR/qRSA+7m 5Y+SokQm8bVWs4W6JUv4z3X875WmZyVoMfX9a3hTYxn2GfaShLuoY3A1si53F1LWNX7etq+L+6tOP ccbCRrSg==; Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKC-00000002Dic-1I9J for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A487F5C5D80; Mon, 2 Dec 2024 17:34:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 0E788C4CED9; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=9iW7A+YjBOO9RVnkPZTBuwbq0imIzWIqQzS9oUoJV80=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=roR0wmNDodAzyFfPTgFBBp/KqBd/M1Zco1d6OqO8B8sJlOTrYchslvtT08b9PEPAD spi3Zv5Lq4VW/Jihv7VnCNPNtkCFI4MsIeV4lzHFYmMaP7dYZGXCQ8d5TXlEApUNZq 8xoSLxg+uBDYJRHUQDRQQNT2XbDMV9G+MwlYNwxH7cmYQ06PHmtyFfEE6xh1DLG/UW fBq0X8GswKgLTC9l8wZKXKu8xTD6Nt4EJlv1q0krvN4+bcuQhKCJFdz8WlioK9jwoK 9VKeyHkx1LzW8cff48edd8HPqMCYIPhMmgODxWxXnUj/PlHgA8fMAPfb7UemLpzrLf oQq2wYAjdEIDw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2538D7833D; Mon, 2 Dec 2024 17:35:03 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:24 +0900 Subject: [PATCH 02/10] compiler.h: add is_const() as a replacement of __is_constexpr() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-2-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3781; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=ut5SHXlG8TFqM4dSL1voozHgmPfm9PCB5ssUWoNnPGc=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+748Gv37O5/hx2ynzqG0iN+cezF1/Uri8ynPxlkd99 448enNwUUcpC4MYF4OsmCLLsnJOboWOQu+wQ38tYeawMoEMYeDiFICJTCliZNgwxSRxxgaPNqN9 SvblgqYXk6R6q/p2hk3PmPP5/5TfZXaMDPsvHppbuS+xzuf2BZ0oL/Hl4l8WKni3vHLVk9a2ddC S5AQA X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_173508_712931_BF57DE09 X-CRM114-Status: GOOD ( 18.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol __is_constexpr(), while being one of the most glorious one liner hack ever witnessed by mankind, is overly complex. Following the adoption of C11 in the kernel, this macro can be simplified through the use of a _Generic() selection. First, split the macro in two: - __is_const_zero(x): an helper macro; tells whether x is the integer constant expression 0 or something else. - is_const(x): replacement of __is_constexpr(); tells whether x is a integer constant expression. The split serves two purposes: first make it easier to understand; second, __is_const_zero() will be reused as a building block for other is_const_*() macros that will be introduced later on. The core principle of __is_constexpr() to abuse the return type of the ternary operator remains, but all the surrounding sizeof() hack disappear. On a side note, while not relevant to the kernel, __is_constexpr() relied on the GNU extension that sizeof(void) is 1. const_expr() does not use any GNU extensions, making it ISO C compliant. __is_constexpr() is temporarily kept and will be removed once all its users get migrated to is_const() (or one of its friend). Signed-off-by: Vincent Mailhol --- include/linux/compiler.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index a2a56a50dd85227a4fdc62236a2710ca37c5ba52..30ce06df4153cfdc0fad9bc7bffab9097f8b0450 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -316,6 +316,47 @@ static inline void *offset_to_ptr(const int *off) #define statically_true(x) (__builtin_constant_p(x) && (x)) #define statically_false(x) (__builtin_constant_p(x) && (x) == 0) +/* + * Whether x is the integer constant expression 0 or something else. + * + * Details: + * - The C11 standard defines in §6.3.2.3.3 + * (void *) + * as a null pointer constant (c.f. the NULL macro). + * - If x evaluates to the integer constant expression 0, + * (void *)(x) + * is a null pointer constant. Else, it is a void * expression. + * - In a ternary expression: + * condition ? operand1 : operand2 + * if one of the two operands is of type void * and the other one + * some other pointer type, the C11 standard defines in §6.5.15.6 + * the resulting type as below: + * if one operand is a null pointer constant, the result has the + * type of the other operand; otherwise [...] the result type is + * a pointer to an appropriately qualified version of void. + * - As such, in + * 0 ? (void *)(x) : (char *)0 + * if x is the integer constant expression 0, operand1 is a null + * pointer constant and the resulting type is that of operand2: + * char *. If x is anything else, the type is void *. + * - The (long) cast silences a compiler warning for when x is not 0. + * - Finally, the _Generic() dispatches the resulting type into a + * Boolean. + * + * Glory to Martin Uecker + */ +#define __is_const_zero(x) \ + _Generic(0 ? (void *)(long)(x) : (char *)0, char *: 1, void *: 0) + +/* + * Returns a constant expression while determining if its argument is a + * constant expression, most importantly without evaluating the argument. + * + * If getting a constant expression is not relevant to you, use the more + * powerful __builtin_constant_p() instead. + */ +#define is_const(x) __is_const_zero(0 * (x)) + /* * This is needed in functions which generate the stack canary, see * arch/x86/kernel/smpboot.c::start_secondary() for an example. From patchwork Mon Dec 2 17:33:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891154 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F11D4D7831C for ; Mon, 2 Dec 2024 17:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EP19nJWwfwk7upkaQGi+3oo+ZZiPt49Q9aj41iXAAAM=; b=3aJlSFCzyQmRU3Y0iqhuqcgOeG N5syQCRE6ED6ZhC3CvBiX+LCDkgGXQLxqsAoPWS38kaX82SxtSv4rl7weZ1YHQd8Q9GikT/g7InzM y1uMaaZNkWUQi469XJPkEH+AMBPl5V7TVGBKZcimz/4lJq7fqKI1lqghPn/cy/GxeLcr7B8ZxsMnu j4qdtw/GPKGQIW7J/9w0Wzha66nH3C1gO7mrx7gBhRtJlxIt/ikgwRvUzfdjZh3CEaWT9AdML/5oZ MXrwxl0Ty9+d6dBaEDr5EVDjbFMPhrc+jI4t79xWyuj6MQyn8UM+JhJqge/ufUtTBQPb8zdEhdEEh 4KO9T3Gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIAWt-000000074Zo-0Hs1; Mon, 02 Dec 2024 17:48:15 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKF-0000000723D-3Q2z for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Dec 2024 17:35:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Reply-To:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Content-ID:Content-Description; bh=EP19nJWwfwk7upkaQGi+3oo+ZZiPt49Q9aj41iXAAAM=; b=dwkauChvRGlhbIvLDrFBS9IAaR gdN4XUgE/ida0EKQA7eUKr8khqbuBjGnhxpc13oYK8YnZhGaEuqAPDV4nhb5BlGJuVRLmNMaTNW6q XfOPMBKCIq/1/Daxbtd0A04gG24I1jJxhWtEoW6YEP7wR7KuyOoFBHyQwLUbVM1LbB+uGmKwDfUh0 JainO0ea5Q4PIG1B5bhY6+B03OQj4tKTLnHTa9CZXwGTug4kVelXHHXNOck78u4XA3jzpjPRHygAX o/sB4iILg4iDuR9vHECHNnC32v16BLCyqMMCsZ29+EYRkPRoeItT1G13+BVCuApUAhfnN+MRnMhQ8 6GiydjbA==; Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKC-00000002Dif-1PHK for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AC5B95C5DD3; Mon, 2 Dec 2024 17:34:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 2CE44C4CEE0; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=d4JkfBIFjtnH3QVmKyHAXV1Y+cJkoB706DolhEJtz9Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=IKBHMJsHqq1hMtszvFOcfe9UEP/UCGLNKk9ANnIcCBKQJxvDxJt38mPS8tAgR5c6t j5RlM4BNUTDfxDfI3Avtg0nX8yBTmlggQ5jrzzTBlPG91LszQP7ro4DvKTHMsIFx03 Ax8eQJYEbtpeAxORywU3rX4HP+TuVI/B+I0aVoNVWIPai14lbzwm47hWur1xDIshjw +pk1MzpiSmz0v305U/OGH5TFpUNcCVbn7jPy70aIyrijNwRQAXx8tmMsWl5bYKeSLc HHa0DpnGMURhpv8L6OAhVUs2I0ho4wfjaUlxpY9IPbtnDv+aCGGSr+wGWsqEqAq43Y kFSTBtw2Xu9wg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FFDCD7833E; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:25 +0900 Subject: [PATCH 03/10] compiler.h: add is_const_true() and is_const_false() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-3-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3669; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=vXXScdJ5PminDGoxDgA6Iag0c2X2hzS5qLrxjoqdg1k=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+74+abz5c0vD2uK1kR42Xpca9XMcb2cKG/u3MBSvKH /Ku00juKGVhEONikBVTZFlWzsmt0FHoHXboryXMHFYmkCEMXJwCMBG/KIY/HLZ2z5iFOme/c1oW fOXLsXk2BbHp55dO/BLheFbvzrrtzYwMF/986Qm84Gxx5Kl200c5i3rbi3snbcsKbZlrqLn/5is dBgA= X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_173508_747923_0FB9CFFD X-CRM114-Status: GOOD ( 18.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol __builtin_constant_p() is known for not always being able to produce constant expression [1] which led to the introduction of __is_constexpr() [2]. Because of its dependency on __builtin_constant_p(), statically_true() suffers from the same issues. For example: void foo(int a) { /* fail on GCC */ BUILD_BUG_ON_ZERO(statically_true(a)); /* fail on both clang and GCC */ static char arr[statically_true(a) ? 1 : 2]; } Define a new is_const_true() and is_const_false() pair of macros which, by making use of __is_const_zero(), always produces a constant expression. Note that is_const_false() can not be directly defined as an alias to __is_const_zero(). Otherwise, it could yield some false positives on huge numbers because of a lost of precision when doing the (long) cast in __is_const_zero(). Example: is_const_false((u128)ULONG_MAX << BITS_PER_LONG) Furthermore, using the ! operator like this: #define is_const_true(x) __is_const_zero(!(x)) #define is_const_false(x) __is_const_zero(!!(x)) would yield a -Wint-in-bool-context compiler warning if the argument is not a boolean. Use the == and != operators instead. It should be noted that statically_true/false() are the only ones capable of folding tautologic expressions in which at least one on the operands is not a constant expression. For example: statically_true(true || var) statically_true(var == var) statically_false(var * 0) statically_false(var * 8 % 4) always evaluate to true, whereas all of these would be false under is_const_true/false() if var is not a constant expression [3]. For this reason, usage of const_true/false() should be the exception. Reflect in the documentation that const_true() is less powerful and that statically_true() is the overall preferred solution. [1] __builtin_constant_p cannot resolve to const when optimizing Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19449 [2] commit 3c8ba0d61d04 ("kernel.h: Retain constant expression output for max()/min()") Link: https://git.kernel.org/torvalds/c/3c8ba0d61d04 [3] https://godbolt.org/z/E4r7EaxW9 Signed-off-by: Vincent Mailhol --- include/linux/compiler.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 30ce06df4153cfdc0fad9bc7bffab9097f8b0450..165aa5b9bc484376087a130a1ac1f3edb50c983d 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -357,6 +357,29 @@ static inline void *offset_to_ptr(const int *off) */ #define is_const(x) __is_const_zero(0 * (x)) +/* + * Similar to statically_true() but produces a constant expression + * + * To be used in conjunction with macros, such as BUILD_BUG_ON_ZERO(), + * which require their input to be a constant expression and for which + * statically_true() would otherwise fail. + * + * This is a trade-off: is_const_true() requires all its operands to + * be compile time constants. Else, it would always returns false even + * on the most trivial cases like: + * + * true || non_const_expr + * + * On the opposite, statically_true() is able to fold more complex + * tautologies and will return true on expressions such as: + * + * !(non_const_expr * 8 % 4) + * + * For the general case, statically_true() is better. + */ +#define is_const_true(x) __is_const_zero((x) == 0) +#define is_const_false(x) __is_const_zero((x) != 0) + /* * This is needed in functions which generate the stack canary, see * arch/x86/kernel/smpboot.c::start_secondary() for an example. From patchwork Mon Dec 2 17:33:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78A16D7831C for ; Mon, 2 Dec 2024 17:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MyBKNImG3543zkiJ+eMXPxx3YNczz2Mf1C6U2FxVidE=; b=ENnCzrg1VUeRnni9nQacR+jx9V rPrPZ4FcOq6/BIpfIwAPu8fhhYWIjqIZ4HuA1q29MvS9wvDSXgeXViLHHIunVSvzM3cSlcValYFSI lYtd+Y/NoQL96wIoIcVmtCq+t6L5ZFJnEu/yVCVWQBn4XRYASocZXzxWVY4JQNDg1qHiKR3KJCNlc hQWNr5TjK8EQYgMj75ymFj4D7an1Iz/2CbjoIc4HGY5LQkoPbHlaFTRgEdNGI6Ud2I6jw2Li/esu2 gB1SXOMS3PXYySfn00D4OiHjbKvHPk8toGPrUhPoZkuApu3bY6pDQzv90qD5egEULMr0wSYSPPh0U 3QnuGr2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIAVu-000000074MH-1gTa; Mon, 02 Dec 2024 17:47:14 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKF-0000000723B-3PXQ for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Dec 2024 17:35:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Reply-To:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Content-ID:Content-Description; bh=MyBKNImG3543zkiJ+eMXPxx3YNczz2Mf1C6U2FxVidE=; b=VP2E+Fj7+kfaJtxoPJ+ttYxg+c 7ekNQnjeQLTP2YJKC+BHB08GMsL18jVHwLMvtRQgDmM1pbqaNlbO0UgbwzAoO6IW1C127HtA3ENH2 gzIJgXvS/OuL5gy4DKKrZbOBdwetlO32ZuuxzAlJGNLjLzxEjfnnBHq4ShYbpZyhQuEIB1SPpnERw HvbpNJN1s9dYOOTy53CtVuYZyD5t3WfMdIWAHwJrPHc/es5W3Cdf06+VNfd6tHVh9jsPeBE7dc0NQ llIDdmRooq7jkt3rXzWoOT56DK6f5n6Y/RD44e3AT2EsfjH5OwXa7pQ/5Cbdu/6spICvsd6kg1iNq 6alZE02A==; Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKC-00000002Dig-2hbe for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 01F775C5E9D; Mon, 2 Dec 2024 17:34:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 451ECC4CEE2; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=xwTNFn3pAcjVSWQWx0fHAn53Pqy1YgPTXPD7CvZlCBE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Ungmd37L4dkWQvhcuFclEv+4CcvM6Wg2DepR4tJAgCJBakZJ4OmYWS9Csu9MKZr41 XOv24ODLjWwD+67sbFUifpRNCmPEQhS8JwS9csGxIlgYR/YLsHOkJVI+rsTOnZRPEy yH2cFtTBr9uKzmixHN0oJOTceYmKMqTwlwwO5KPm5TZsGgwOtl4ORdHEwBnZoivBBH bSGeNjS+e1SaQ5F6GGhF5sehAhHeG+tGesILeTagGwibgp+e6zEqRMEwmeSetfdcXn lSorEV45P7zurGKv9mS3+xrhz3uFMSJ+2PzbCz77WDhjVgbfudPNRgeib2oB/A/4F2 ITeXGxWMkkBeQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 394CFD7833C; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:26 +0900 Subject: [PATCH 04/10] linux/bits.h: simplify GENMASK_INPUT_CHECK() by using is_const_true() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-4-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1272; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=7pxUmK/6W4pXlFZB1NGxttLkuRalLbmF/D69OP2jG1o=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+749GXp33N/vXlsdiTw9lODzSEugV7vlifP1CSKJpp EL7cw+XjlIWBjEuBlkxRZZl5ZzcCh2F3mGH/lrCzGFlAhnCwMUpABNR2Mnw35utNVRP1Thc1XO/ kFrZj4LtpwX/s53aHOaffebyus1pTgz/82/rzvn0wGB67rdoO1XPe0Viq2NqdiXV19t3Vhuemj6 RGwA= X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_173509_043138_7453655E X-CRM114-Status: GOOD ( 11.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol In GENMASK_INPUT_CHECK(), __builtin_choose_expr(__is_constexpr((l) > (h)), (l) > (h), 0) is equivalent to: is_const_true((l) > (h)) Apply is_const_true() to simplify GENMASK_INPUT_CHECK(). Signed-off-by: Vincent Mailhol --- This change passes the unit tests from CONFIG_BITS_TEST, including the extra negative tests provided under #ifdef TEST_GENMASK_FAILURES [1]. [1] commit 6d511020e13d ("lib/test_bits.c: add tests of GENMASK") Link: https://git.kernel.org/torvalds/c/6d511020e13d --- include/linux/bits.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 60044b6088172b3f26aa3f17cdaede9786863dae..ef0119e6179e1ca95345a3d4d3327ba19633028e 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -20,9 +20,8 @@ */ #if !defined(__ASSEMBLY__) #include -#define GENMASK_INPUT_CHECK(h, l) \ - (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ - __is_constexpr((l) > (h)), (l) > (h), 0))) +#include +#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(is_const_true((l) > (h))) #else /* * BUILD_BUG_ON_ZERO is not available in h files included from asm files, From patchwork Mon Dec 2 17:33:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3846D7833E for ; Mon, 2 Dec 2024 17:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AZ+co9f4XoPsEknVzVXj3noJ8mlDHInL4O20KcNjoiM=; b=kdKtnv9CSAdJPweYHoPTzOjP6r D5uhpHQIatgLQDDjEdIx6XsSN3MZ9q7lwPei/miC+Iv46Bb/ZrGPuEMCj3KdW49j5jgUG57UO+2iw MKY7+V3V1do3igYR/wvl8sHAoF1hsnCA2VPKjKkiXvbeTs6fPe8bQgPu3kDoiKqzAv6OZYXNr3KMN lXgIevlmJhmTJoHyksokhiRll96tu65OWMYs1UTMF17Xo/k4VnClzhaAOR+n5oZRxsgGY8ybKX7mt O7gFeZiVClceoUSx/EYH/JdY8lEYYrhGqAo0Ok1wDHE24ve7MLJed03vd3iTqo/wCC1wzG+yz8U/w iISjjsmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIAXq-000000074mF-2otr; Mon, 02 Dec 2024 17:49:14 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKG-0000000723l-2d5W for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Dec 2024 17:35:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Reply-To:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Content-ID:Content-Description; bh=AZ+co9f4XoPsEknVzVXj3noJ8mlDHInL4O20KcNjoiM=; b=pdTGzuxjPU3JQrP2RM0CdcNsTl 8YiRNKpvs3MQKlmJ//yY5vK2OOpsl6O5eEf1VnQ38AIQNfZTxv96VkOIlsZx0mwRi4blToYittE7m XNy46LuQ5yBpzJsxSgsRCNyczLkXxTUgGLBMbocyDq+59+kS1obJomfpS5XCGKKLSQDGueS64Ywzg nluZswR8rkkveUbNn64b/FSE21e4D927SVaiU3tmPbRO0FIiiCP0oqBnbiy1UuV6+flbOTSElyBie On8AbhR+rRkjwWNGTEdDSupxN9nMycoQbxMd+ldC4r16wpw7cKhOu/UEgRauof+oTuzg83Ok5XFVE 9p+z90ew==; Received: from dfw.source.kernel.org ([139.178.84.217]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKC-00000002Dik-3zFZ for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:11 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0851A5C5EFC; Mon, 2 Dec 2024 17:34:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 637F2C4CEE3; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=FZmPlNwEP0dLH9uzEAPVjoA2IENASDBcbOxyxt6OpgQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Np6Vb9OHybQfNzDBImwNMJVhDJu/8UXyGodvRv29g6p6oSEeNdnBODBy7/6sK8Mt+ zlRyO0cedmOcRUNaIFPlX4cc9ErbeCj7+h5RT4pjxrGC77hKjrDMpHgNvCTqz/nTsN w2i9wWcIiPMIwKxE9P4tpnswci6LoL102L0oXYpKajA8DGNgirvUJuwLmrOme0joUv au2yD/+s5HolY3ATZHEuyWQNYlk57qFV5d0V2FGBKiMgUjnTAD8aFWym1eWRfJlkBL pu0rc2snu+Ik9dYybACLnKehUFwBD96canGBtO+Btp8w/PUQyUWT4dLC5UwFytqCqY 7y0i7z89Sln0A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51D2FD7833D; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:27 +0900 Subject: [PATCH 05/10] minmax: simplify __clamp_once() by using is_const_false() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-5-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1058; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=ktV9jrZU0giaHV9vBo3GiXQr/Qxl6VWxrueXUQe+OfY=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+74+eev1x37SU7/s4fOZsfexXwSuwUZXlqNClRp+XD 71fb+e91lHKwiDGxSArpsiyrJyTW6Gj0Dvs0F9LmDmsTCBDGLg4BWAit84y/BX7aL9/YU3XnR7j ixp8Oy/Oeb/9EFPOXNM1rhuKog5yzH/PyPD2dPyivxyLOtx7gqSDZL8HtSqF7j576ccC5tVXdN5 +EmADAA== X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_173509_413640_1A376A50 X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol In __clamp_once(), __builtin_choose_expr(__is_constexpr((lo) > (hi)), (lo) <= (hi), true) is equivalent to: !is_const_false((lo) <= (hi)) Apply is_const_false() to simplify __clamp_once(). Signed-off-by: Vincent Mailhol --- include/linux/minmax.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 98008dd92153db10c672155bca93201ffabee994..431bf76ac460a11a2e4af23acd90c0d26e99c862 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -111,8 +111,7 @@ __auto_type uval = (val); \ __auto_type ulo = (lo); \ __auto_type uhi = (hi); \ - static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ - (lo) <= (hi), true), \ + static_assert(!is_const_false((lo) <= (hi)), \ "clamp() low limit " #lo " greater than high limit " #hi); \ BUILD_BUG_ON_MSG(!__types_ok3(val,lo,hi,uval,ulo,uhi), \ "clamp("#val", "#lo", "#hi") signedness error"); \ From patchwork Mon Dec 2 17:33:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 230E0D7833D for ; Mon, 2 Dec 2024 17:43:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nvZ5Ea7O2CMMS8JxLyAlrOZJQuKNKPriSx2UOmU4MyA=; b=ARMmqrSWsFawZcOZ+qk8wh1N6T obwT/SxemS10mcG9obFxHrPbvdanMJP7X5+sTwHfAatih5349RIfBWSeS6GyizBKml7mbB+EWM157 aadeQmJgQXEFH5joUFRaEXmPawsAEtP4mRZ00Us6yUvBQvkKpv5xzMcRK2cTH1l1NXOh03h+cQrMK pDW7uORmnZ2DnrR7R871+c/FLbN7PTvlguy3g7jallUMv5Ti38MZJ5ZWdt2cp8H5mrosH8Kp/YVt1 FPp2DAojtNQXjSTfccS7MvQJH049KY7s0yRw7aedKr648REoN8qju443xM+r4mFYtwOc2bktpq7mi X6TArYGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIAS4-000000073nv-11vj; Mon, 02 Dec 2024 17:43:16 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKA-0000000720g-2s30 for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id B8F6BA41081; Mon, 2 Dec 2024 17:33:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 7D9C2C4CED1; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=otRfIIpR9ke8jKx0T5rYqZgdrJ75ZS57/Fik5wYJ77g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mbv/N+QLcgtpQR8QD3+Ebo0ZkA7L0mv7KOGi59I1rnrkhoHvWWt1ejgoGG0hn3cQH 7vY0bEpghsh4bdGKfDPWkJgjgE9H1kbPj3okgFTgy7GsQ5nHdE7+BlS4CfYCtp+olK IxHhytNs+RjNxOecYykd2M4jLLUkudPct9tMAWZ31vqh51ucXMeaL2xLFjw4duIFDw maNwAvLXVHp5++7gPZAAkp9asgFSy/lVIQgrV/RYVoGKbVqtKt/DGnAwPQJVU+dLvv OQNeCRsZUu9f3KQ7My3boRoQ7P4tB3aYMYuiHyP2HChG+NdQkCk0tLHRZQHijwMmM6 fzSDVM2CqMrSQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DAD4D7833C; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:28 +0900 Subject: [PATCH 06/10] fortify: replace __is_constexpr() by is_const() in strlen() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-6-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1072; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=jMI6GLWGOq2qwprnzsUGV4xG+9C9iHAQ1IPi4ZG8B0k=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+749+/rqPW6pvpu+W2UzTPlgk/hDbmVItMcnU/8kTl hNartOudJSyMIhxMciKKbIsK+fkVugo9A479NcSZg4rE8gQBi5OAZiIaBsjw/wOdQfrmY9Kw6X+ neVT9cwNVGdRL0772611cXrWBz25mQx/RT0nvEo4NlP8lov1Q74UufJwLg3WJUzZSUkaeZNe+69 lBQA= X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_093506_865047_6154656C X-CRM114-Status: GOOD ( 11.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol is_const() is a one to one replacement of __is_constexpr(). Do the replacement so that __is_constexpr() can be removed. Signed-off-by: Vincent Mailhol --- include/linux/fortify-string.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h index 0d99bf11d260a3482bbe46e35c7553c0ccfb8b94..e3f2f772c5439ef71eb4a904b4ce27956bc69743 100644 --- a/include/linux/fortify-string.h +++ b/include/linux/fortify-string.h @@ -254,8 +254,8 @@ __FORTIFY_INLINE __kernel_size_t strnlen(const char * const POS p, __kernel_size * Returns number of characters in @p (NOT including the final NUL). * */ -#define strlen(p) \ - __builtin_choose_expr(__is_constexpr(__builtin_strlen(p)), \ +#define strlen(p) \ + __builtin_choose_expr(is_const(__builtin_strlen(p)), \ __builtin_strlen(p), __fortify_strlen(p)) __FORTIFY_INLINE __diagnose_as(__builtin_strlen, 1) __kernel_size_t __fortify_strlen(const char * const POS p) From patchwork Mon Dec 2 17:33:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2CDABE69E85 for ; Mon, 2 Dec 2024 18:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qSecgOFCcnddgSXhEf8ACXGiWtLdAEY7PHrRXowILx0=; b=Sgr+iclMqfe0oPX3U9//m/UAsQ LcDgcQAt7N/61ioL4ygrAtac634ojxuDGrKOqSM2r8NXdU7Lym9+9w8naIi3MOvTXAuygtGqBcKPO z5GHWsqAr0uaj3cE5gncnt46BrRj09p9jk9gA7GaMYxul88wvLxECb22cUkNXkE0wu5G0mFV3slW6 P4xxsYU4VKdPn8416Bau33xQmv/bnFu+i5MsM33atVCCbKVOxLarQEIRzw5x15sjg/Zm4v9ttiTY+ DjwpVQNRqpjc0F28w6ClZcylYEd/ecbKdSM5UtsXHetqzCD+REgNJ+ZUPs/TK+dOEWsnNHuT2qCRm 1gBgAl6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIBd9-00000007Dj9-0mB5; Mon, 02 Dec 2024 18:58:47 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKF-0000000722j-13uz for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Dec 2024 17:35:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Reply-To:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Content-ID:Content-Description; bh=qSecgOFCcnddgSXhEf8ACXGiWtLdAEY7PHrRXowILx0=; b=hNA0j6Vvnbxv5P5j8cl8FnRzk7 7LLrJkiZ+ODRIzF5GGLMHUJK+NZM4NW6RlJ9bz/hokwAWmgnPw/S7CnTy1Xgh2k+DIEqXbSPrEI17 /6pgZqqZ7TeHnqw3G1AUTkiwLSBt9W7FbfbkzwCKXLTnDLJ2zZ/AMvRV3K0/xfWsmrL8J0uAtRxlZ TmsIoSFf3Naw73dCEwzEhMoK+aQJbF7vP2VfZFj/Wml/EzO2XzgP43B9s4r5PXSYl71elI33UkIAx nEHbDCAnqgnqs1+XhC0njP22JFnXdBTYZg388VirflnwryK985pTfjvRTUGIsHw1n+cccV9bi2SHz 1icVxNHA==; Received: from nyc.source.kernel.org ([147.75.193.91]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKC-00000002Die-1ERx for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id B4E26A4105D; Mon, 2 Dec 2024 17:33:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 9AEC8C4CEE9; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=0n7K8123aVRmHZxGT60ksDzEW/cULJYrbFl/Q86l37M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=j/90kkzHJYpxgw9fCykFpmgCYrZb/HPUY4Fn5AfokJhP84zgU7WPjnPRfcVDKNTZ6 wg+fmlmBVyCt//Ey3/M6ExHqZHnZfnNtjNwYpa7cjYFMZUUr9k/jEbhhMlkpXAEPu8 tyBddS+OV2r4MV7GOACqXDiV2MFmPliFoCKNi3gXMxhlm3mvVMqJV7rk2kHU1Nf1iF Rmspw7y6S/BTMrAVwZfQYYIvu3wu1tA0CWgmUb/hRT/5vecMQRWoCUH10RiN4SK+ik KNISAN2qv9Bv/qfkjhjCxYcPlt6QwRjzMjF4MkKIAmeuKGAEzSHUCnhg3q3mCxkg59 zwzNKjWmBqpZg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88EEED7831C; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:29 +0900 Subject: [PATCH 07/10] overflow: replace __is_constexpr() by is_const() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-7-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2119; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=3zhdAHGJKxe/cfP6gSQHSq0jEALX5ywlxJaLknSE8PU=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+74/q876MC9CKYjyo9Ky9cdPpsilBc38vnbBxvs6ZW UF5mtXRHaUsDGJcDLJiiizLyjm5FToKvcMO/bWEmcPKBDKEgYtTACbyQ5fhr7xK1ZyIKSviHgrp 8+d4/NxvmD6DX/jspxv39qf9Nnzx8QYjw5+v16eWdS2+XNXV/TjVMnulR8GKU3Mazly4pdn98Ng OKx4A X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_173508_635752_8195686F X-CRM114-Status: UNSURE ( 9.65 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol is_const() is a one to one replacement of __is_constexpr(). Do the replacement so that __is_constexpr() can be removed. Signed-off-by: Vincent Mailhol --- include/linux/overflow.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/overflow.h b/include/linux/overflow.h index 0c7e3dcfe8670cb95f371a6f7d41bb8b63b1786c..d69361a3128897d493b5e2ec471f077ca2b9861d 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h @@ -234,7 +234,7 @@ static inline bool __must_check __must_check_overflow(bool overflow) * Returns: true if overflow can occur, false otherwise. */ #define overflows_type(n, T) \ - __builtin_choose_expr(__is_constexpr(n), \ + __builtin_choose_expr(is_const(n), \ __overflows_type_constexpr(n, T), \ __overflows_type(n, T)) @@ -250,7 +250,7 @@ static inline bool __must_check __must_check_overflow(bool overflow) * back to __same_type(). */ #define castable_to_type(n, T) \ - __builtin_choose_expr(__is_constexpr(n), \ + __builtin_choose_expr(is_const(n), \ !__overflows_type_constexpr(n, T), \ __same_type(n, T)) @@ -352,7 +352,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend) * Return: number of bytes needed or SIZE_MAX on overflow. */ #define flex_array_size(p, member, count) \ - __builtin_choose_expr(__is_constexpr(count), \ + __builtin_choose_expr(is_const(count), \ (count) * sizeof(*(p)->member) + __must_be_array((p)->member), \ size_mul(count, sizeof(*(p)->member) + __must_be_array((p)->member))) @@ -368,7 +368,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend) * Return: number of bytes needed or SIZE_MAX on overflow. */ #define struct_size(p, member, count) \ - __builtin_choose_expr(__is_constexpr(count), \ + __builtin_choose_expr(is_const(count), \ sizeof(*(p)) + flex_array_size(p, member, count), \ size_add(sizeof(*(p)), flex_array_size(p, member, count))) From patchwork Mon Dec 2 17:33:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C230BE69E85 for ; Mon, 2 Dec 2024 18:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qQgA+V/LbkZ7WusSfir2wS+OQoEd5i7j/YDx1EP4l5I=; b=gI+eAzT4YRZ16wgLZqlluE6w7h qmjO2OhBEJBOSRVTLgrSIWmo309ws53r2aOtekgvu7tVYpoozoOJ/UkB7ZOv7JgWLMD7BQEziEXdE LxdfXsd6A/VJwC5yeGm3PENLuWRLWchgt7K3eC0GcvjpnlAEQ+kTieBwIiTA1iHNIuyCuAckFrheL ikovnC2vGaTh+TxGEs8JwFrhZLFGUU2GOp3W8lfmScbTjrM1ovfrpRYVPibzNHmY0ZKwrPX+Nxs62 UXsUtW0dyYrWusnaIhitKTzk8LrwETMXEj1z2nlGB50xBkwLPaeUBshTYJHnM/oRzuyMmOupuxESB U8RGIAcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIBd9-00000007DjZ-2vNN; Mon, 02 Dec 2024 18:58:47 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKG-0000000723o-2dqw for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Dec 2024 17:35:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Reply-To:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Content-ID:Content-Description; bh=qQgA+V/LbkZ7WusSfir2wS+OQoEd5i7j/YDx1EP4l5I=; b=LGz4uagIxBGVgfR1zvwetzaTW8 uLnRdsn85YLdPCU8wc9GFWQgt8qZHZu1j3PYa6/OoiNZkGOfjppFT+sX7bG2gaxWZhvriY6rsgoVe kTzB1XEUzbcM/NLIbHlT69j2VUD1VxI2TlI/nSaeT1sHOdPuj9DEgYam730fElziSfLXEwo6FvPcd zhhpNwQJ/N4rpLtFXaYo+tZbgA3WhTTFr+oT0ybLOqAjj9rI2+ZzROEGs4T179XG2CJifc04227Ux CQjiaq8CDLJjFciqeYSDSIXa4HLLhHP2yVE3hn2p5gG8CvysVrTanzx9A4VdkcKwIYek5BHxf56ei F1LeThNA==; Received: from dfw.source.kernel.org ([139.178.84.217]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKC-00000002Dil-3z9e for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:11 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4ABB25C5FC0; Mon, 2 Dec 2024 17:34:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id B6AFFC4CEDF; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=XFZ/ReIcnrUD50vCJZHFqXxOz1HrqXseDp2bfbIhVEs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rJoAowSx1LVP7Btyr5lB+8xAdHd7iP7/JAEPrrfN3Xk7muPKGT0/iepah+m+/jhba Ar74BLMFdFjoY6XfhjnKewDWfDbbNWm8KYhpPdmtR2c2uI1UoMu+gcUuSlNiVE2y5C cLzPppN5gmQTXbxsUODrezXWUbzKIUKreCWfcnGpNv2fMKpniPb2PWEjRBFVycjnqw +Px5hGZDoxjmwuxyNrSYJlgdwGWpKd7HSDVJ0o3CXNlMYqxpUOmzvzH4PZ+3tlPI/n qt8BcDigGGcCkkUpKS8OkwRHfN7edpW8csZ9LebomUgjbSxuaK0Xl8HZmJN/u+6al8 HnaEvpg18+ZYQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7656D7833E; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:30 +0900 Subject: [PATCH 08/10] drm/i915/reg: replace __is_const_expr() by is_const_true() or is_const() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-8-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6558; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=IT41eIS+OIIsRMdNS4yKlf8V72ofU+yIl1OolUa3zxc=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+748G+l5SvWBYeEcwf3ZH9lTPGKdm67Bt3/tZLGav/ 10qOqOto5SFQYyLQVZMkWVZOSe3Qkehd9ihv5Ywc1iZQIYwcHEKwESexjIyLH55gHdrk2cszxbF xhXdX74eKihrm/W6N9dCbd7DwkLng4wM65yVF6n33pSYytozo6h2wxde748zo9jPf1NZx+O44VI lOwA= X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_173509_403952_847689B6 X-CRM114-Status: GOOD ( 10.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol Most of the use of __is_const_expr() in i915_reg_defs.h are just to test whether an expression is known to be true. Because those checks are all done in a BUILD_BUG_ON_ZERO(), replace those with is_const_true(). Replace the few other occurrences of __is_const_expr() with is_const(). Signed-off-by: Vincent Mailhol --- drivers/gpu/drm/i915/i915_reg_defs.h | 47 +++++++++++++++++------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_reg_defs.h b/drivers/gpu/drm/i915/i915_reg_defs.h index e251bcc0c89f5710125bc70f07851b2cb978c89c..6ed2fb9cf506a3bd6467ba30f9d0e863d62762f3 100644 --- a/drivers/gpu/drm/i915/i915_reg_defs.h +++ b/drivers/gpu/drm/i915/i915_reg_defs.h @@ -19,8 +19,7 @@ */ #define REG_BIT(__n) \ ((u32)(BIT(__n) + \ - BUILD_BUG_ON_ZERO(__is_constexpr(__n) && \ - ((__n) < 0 || (__n) > 31)))) + BUILD_BUG_ON_ZERO(is_const_true((__n) < 0 || (__n) > 31)))) /** * REG_BIT8() - Prepare a u8 bit value @@ -32,8 +31,7 @@ */ #define REG_BIT8(__n) \ ((u8)(BIT(__n) + \ - BUILD_BUG_ON_ZERO(__is_constexpr(__n) && \ - ((__n) < 0 || (__n) > 7)))) + BUILD_BUG_ON_ZERO(is_const_true((__n) < 0 || (__n) > 7)))) /** * REG_GENMASK() - Prepare a continuous u32 bitmask @@ -46,9 +44,9 @@ */ #define REG_GENMASK(__high, __low) \ ((u32)(GENMASK(__high, __low) + \ - BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \ - __is_constexpr(__low) && \ - ((__low) < 0 || (__high) > 31 || (__low) > (__high))))) + BUILD_BUG_ON_ZERO(is_const_true((__low) < 0 || \ + (__high) > 31 || \ + (__low) > (__high))))) /** * REG_GENMASK64() - Prepare a continuous u64 bitmask @@ -61,9 +59,9 @@ */ #define REG_GENMASK64(__high, __low) \ ((u64)(GENMASK_ULL(__high, __low) + \ - BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \ - __is_constexpr(__low) && \ - ((__low) < 0 || (__high) > 63 || (__low) > (__high))))) + BUILD_BUG_ON_ZERO(is_const_true((__low) < 0 || \ + (__high) > 63 || \ + (__low) > (__high))))) /** * REG_GENMASK8() - Prepare a continuous u8 bitmask @@ -76,9 +74,9 @@ */ #define REG_GENMASK8(__high, __low) \ ((u8)(GENMASK(__high, __low) + \ - BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \ - __is_constexpr(__low) && \ - ((__low) < 0 || (__high) > 7 || (__low) > (__high))))) + BUILD_BUG_ON_ZERO(is_const_true((__low) < 0 || \ + (__high) > 7 || \ + (__low) > (__high))))) /* * Local integer constant expression version of is_power_of_2(). @@ -97,10 +95,10 @@ */ #define REG_FIELD_PREP(__mask, __val) \ ((u32)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) + \ - BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) + \ + BUILD_BUG_ON_ZERO(!is_const(__mask)) + \ BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) + \ BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \ - BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))) + BUILD_BUG_ON_ZERO(is_const_true(~((__mask) >> __bf_shf(__mask)) & (__val))))) /** * REG_FIELD_PREP8() - Prepare a u8 bitfield value @@ -114,10 +112,10 @@ */ #define REG_FIELD_PREP8(__mask, __val) \ ((u8)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) + \ - BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) + \ + BUILD_BUG_ON_ZERO(!is_const(__mask)) + \ BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U8_MAX) + \ BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \ - BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))) + BUILD_BUG_ON_ZERO(is_const_true(~((__mask) >> __bf_shf(__mask)) & (__val))))) /** * REG_FIELD_GET() - Extract a u32 bitfield value @@ -154,8 +152,7 @@ */ #define REG_BIT16(__n) \ ((u16)(BIT(__n) + \ - BUILD_BUG_ON_ZERO(__is_constexpr(__n) && \ - ((__n) < 0 || (__n) > 15)))) + BUILD_BUG_ON_ZERO(is_const_true((__n) < 0 || (__n) > 15)))) /** * REG_GENMASK16() - Prepare a continuous u8 bitmask @@ -169,9 +166,9 @@ */ #define REG_GENMASK16(__high, __low) \ ((u16)(GENMASK(__high, __low) + \ - BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \ - __is_constexpr(__low) && \ - ((__low) < 0 || (__high) > 15 || (__low) > (__high))))) + BUILD_BUG_ON_ZERO(is_const_true((__low) < 0 || \ + (__high) > 15 || \ + (__low) > (__high))))) /** * REG_FIELD_PREP16() - Prepare a u16 bitfield value @@ -186,10 +183,10 @@ */ #define REG_FIELD_PREP16(__mask, __val) \ ((u16)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) + \ - BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) + \ + BUILD_BUG_ON_ZERO(!is_const(__mask)) + \ BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U16_MAX) + \ BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \ - BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))) + BUILD_BUG_ON_ZERO(is_const_true(~((__mask) >> __bf_shf(__mask)) & (__val))))) #define __MASKED_FIELD(mask, value) ((mask) << 16 | (value)) #define _MASKED_FIELD(mask, value) ({ \ @@ -237,7 +234,7 @@ * ... */ #define _PICK_EVEN_2RANGES(__index, __c_index, __a, __b, __c, __d) \ - (BUILD_BUG_ON_ZERO(!__is_constexpr(__c_index)) + \ + (BUILD_BUG_ON_ZERO(!is_const(__c_index)) + \ ((__index) < (__c_index) ? _PICK_EVEN(__index, __a, __b) : \ _PICK_EVEN((__index) - (__c_index), __c, __d))) From patchwork Mon Dec 2 17:33:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE818D7831C for ; Mon, 2 Dec 2024 17:51:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lyryQPDkgnSwDrJqaTMsZ0c4G7WbCQxXZVk/3mnOxLg=; b=VmwWy9bZv709j4KviKyhcPA3J1 nTFWVA4R9CR5XzxwfCzY8lNT/8fpHip7Uz0VG7kcNP2WHTTmGXgdkpu5fZugc2+8HkVU4MM+RlNlD aWeJ+Pxlvq3I4tQBbY31nYi/uEpi5Pledw8Vfv3ZOfos7IO/RPg7/zc0DpgFAcIoQTQCc78MbXw0b nE8Fsq5wqr2lK5jKidxzhmYY8qHEPNsw1LRHFCCpS7Zw23ZTncm8uWwWlPwFfRdMdMXePrr3Q/l/+ XW/039zl8Dc23pwctgNlnLokh7AEvHcHlNypjPgtIo6EKucXcO2UFlfgKdnek4gYHHZ6wH28aCLco V58z0o3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIAZm-000000074yP-1ffT; Mon, 02 Dec 2024 17:51:14 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKH-0000000724G-1AL9 for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Dec 2024 17:35:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Reply-To:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Content-ID:Content-Description; bh=lyryQPDkgnSwDrJqaTMsZ0c4G7WbCQxXZVk/3mnOxLg=; b=IBNu3NqKLIHlDh2i8Xvf4EJblr O00E0bZIi3+f1WzxhDSD4zoQ4oQthXLlZCVSH1RXC8S6yHjsZpjaoGzdTGlnC9jl7SSi1h+pWDoO1 bztjWuIZeGsh7jlPeBg9k8c9bZrw1kC79oMp9t1I3+++/herG2NzQ+8O5h77y9IwxKLtW3HvZmy1i iK/1cU9Ce7uUaF8eZiyf6ItmpJeJnw/DWNYPD+F9M51qr+7LOdIdSdFsPav59SgmcO3Jjy25CSUHx AMT73+UHbayXbG398ocvt91MMrgmTnO34zZYwSkVdosi2nIxO3FCz0oUIMNu0T58FHTSklDlbK8nR mLeyDOvQ==; Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKD-00000002Dij-1MAk for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:12 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 0EBD3A410DD; Mon, 2 Dec 2024 17:33:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id D6DCAC4CEE1; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160904; bh=yr8nPgorqsKZslW18S7DrfbJzdSBjOy5Dm3FgmZaCBU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=FXO4sW7K+gc2vwM1se4GLS2jISLC4Hv85218fTBlxgqHaepVn0KVqtw5xphianfNI h+wVBnQYK0tMREorbt8f9+hmHMOkOSVx+q+E2s5zbRrnGuoCllEFGiWbUwo6Fjllmy fCUyb8OgeS7twO7222857W4QWof1k1Sa8HgeTQwrLcD1Ei793+c8JCrdZ5RXLygiws ZTk+5w6Tx5013RuYIOLIHRFEV6bNFL/FTUUdlecC4pe15aPkt4CYE2ksT3Nnc0r5qj N5aHHomI55Mhxi7/41e44zKJc3dncVCnCU4vbjgHyJ8SVCvF77uaHJSsGp7/RVdgkQ d6o3sa2MQfa2Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3BE6D7833C; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:31 +0900 Subject: [PATCH 09/10] coresight: etm4x: replace __is_const_expr() by is_const() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-9-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1152; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=2a9e0Sg1+HnRtDgEsb84OXVQoFxUHpuXTO0qI7avR5g=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+749O6FPas2ybatTeWc7prF16x3VX6XbM9TgktOrU7 v8zpTx3dZSyMIhxMciKKbIsK+fkVugo9A479NcSZg4rE8gQBi5OAZjIEUmGf4rH5jmVbpEP/Ddj A+/Sm/sTG/nmCVoanpxpWRL3vYGNfyIjQ/eqI0k+TNe37ZmStZpB6ZREi/BkBbfsadXL0zZxGHr +5wYA X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_173509_910036_A8807AB4 X-CRM114-Status: GOOD ( 11.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol is_const() is a one to one replacement of __is_constexpr(). Do the replacement so that __is_constexpr() can be removed. Refer to [1] for an explaination of why __builtin_constant_p() can not be used as a replacement here. [1] commit 4d45bc82df66 ("coresight: etm4x: avoid build failure with unrolled loops") Link: https://git.kernel.org/torvalds/c/4d45bc82df66 Signed-off-by: Vincent Mailhol --- drivers/hwtracing/coresight/coresight-etm4x.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x.h b/drivers/hwtracing/coresight/coresight-etm4x.h index 9e9165f62e81fe5a87d35b4e30bc23f93cb211ec..91cf81ac46f44418f76783c102477d08f9abc70f 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.h +++ b/drivers/hwtracing/coresight/coresight-etm4x.h @@ -492,7 +492,7 @@ ({ \ u64 __val; \ \ - if (__is_constexpr((offset))) \ + if (is_const(offset)) \ __val = read_etm4x_sysreg_const_offset((offset)); \ else \ __val = etm4x_sysreg_read((offset), true, (_64bit)); \ From patchwork Mon Dec 2 17:33:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 13891211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14F4EE69E81 for ; Mon, 2 Dec 2024 18:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KOr1wAKeSH3r8Wezvgm9CpgwVzLFLCpj5YY4q4Vs6WM=; b=4iVtBPpnI2frGFhDwTeqA4iFmy r5CJhmco7uNGKf7+SECsDUYUAIE9nA2hFViDfaCtHvRgeDVgs8d8onmwlfL78vGU0/2t0/AtpLxn/ hGIB0PP5n/HYizXgwEip91OFXqJv6enHX/+UVU4oN6AVHdDXedAvbOy8D+FqAzRR/1Hu94eS5qewt Csnmb+cuHCWzeJFCSGsLrykDk+EMj4rxO3e8Kd9VbqMxTS1QB3UXE5XCBStSMCpSp3k1S7zsyZSTi EV/p2Lv4aoQTv3GioGkvP+p1ootULq2KtaGGMxOx6ao+a7cWEc/XvtqupVvwDlC1BlVqtO2Vff3OP C2DCxxCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIBd8-00000007Dj5-2tbv; Mon, 02 Dec 2024 18:58:46 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIAKB-00000007213-13nx for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 17:35:08 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 5B024A410F2; Mon, 2 Dec 2024 17:33:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id EE828C4AF0C; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733160905; bh=uAZMv8YsD+O3wlShIE66KqQtYXWRRt5F/8DqFrLry7o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bnpeLmKTZ0P/1nIlgfq6P/89fGBp79XUw1RuAsTRlXRHCp2izeFvyG+TI1GSO6Kkj +vSOTNpWal9tOo9dbUTbh9ga3NCi42/NymrTLb22Q4h+u/cokTPsWtrlid/tRFM1T1 6dV8OjkixQG4eXBo6SkrUV3AeE/R4D8dTZFDlu9F64ELfy0Kyibo9a/OngDbjQ2PZS fRCmDaWTk6tZnYjK8xTrQZoanmydKBBAOMVkExgd7RD1+VOe0fYp5Yw3cTebcM93v7 5dsvx+CeiiRXTK43GkDDCdvLdYPnost8GIN8ypR562MwwNxO1YQn1QxI+326LAvREB 1xToeg5fGWCxA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E082BD7833D; Mon, 2 Dec 2024 17:35:04 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Tue, 03 Dec 2024 02:33:32 +0900 Subject: [PATCH 10/10] compiler.h: remove __is_constexpr() MIME-Version: 1.0 Message-Id: <20241203-is_constexpr-refactor-v1-10-4e4cbaecc216@wanadoo.fr> References: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> In-Reply-To: <20241203-is_constexpr-refactor-v1-0-4e4cbaecc216@wanadoo.fr> To: Linus Torvalds , David Laight , Luc Van Oostenryck , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Yury Norov , Rasmus Villemoes , Kees Cook , "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rikard Falkeborn , Martin Uecker Cc: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3686; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=KhSEJ/z9NSPJazKznaA4eGwJC3/rNJqN3dS4dHFF/N0=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOm+7485PP/cFjpv4ddvR2VLOPkvvJfXCD3qLZ3Eld3nt LjUeklRRykLgxgXg6yYIsuyck5uhY5C77BDfy1h5rAygQxh4OIUgImY+zH8T7uwUoiP88gRLpWl X/NO/Lygvi6i7yFjyKWdpdGpMdvv/2P4H5bWr3/0ydJ1OX+dF13m2GEVIfQr88mHOomEbc+bzFv kGAE= X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_093507_425267_FFAAB738 X-CRM114-Status: GOOD ( 16.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincent Mailhol Now that all the users of __is_constexpr() have been migrated to is_const() or one of its friends, remove it. The homage to Martin Uecker's genius hack remains in the documentation of __is_const_zero(). Signed-off-by: Vincent Mailhol --- include/linux/compiler.h | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 165aa5b9bc484376087a130a1ac1f3edb50c983d..7ba75044828129cf1f81f458ade695786dbf132a 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -252,53 +252,6 @@ static inline void *offset_to_ptr(const int *off) #define __must_be_cstr(p) \ __BUILD_BUG_ON_ZERO_MSG(__annotated(p, nonstring), "must be cstr (NUL-terminated)") -/* - * This returns a constant expression while determining if an argument is - * a constant expression, most importantly without evaluating the argument. - * Glory to Martin Uecker - * - * Details: - * - sizeof() return an integer constant expression, and does not evaluate - * the value of its operand; it only examines the type of its operand. - * - The results of comparing two integer constant expressions is also - * an integer constant expression. - * - The first literal "8" isn't important. It could be any literal value. - * - The second literal "8" is to avoid warnings about unaligned pointers; - * this could otherwise just be "1". - * - (long)(x) is used to avoid warnings about 64-bit types on 32-bit - * architectures. - * - The C Standard defines "null pointer constant", "(void *)0", as - * distinct from other void pointers. - * - If (x) is an integer constant expression, then the "* 0l" resolves - * it into an integer constant expression of value 0. Since it is cast to - * "void *", this makes the second operand a null pointer constant. - * - If (x) is not an integer constant expression, then the second operand - * resolves to a void pointer (but not a null pointer constant: the value - * is not an integer constant 0). - * - The conditional operator's third operand, "(int *)8", is an object - * pointer (to type "int"). - * - The behavior (including the return type) of the conditional operator - * ("operand1 ? operand2 : operand3") depends on the kind of expressions - * given for the second and third operands. This is the central mechanism - * of the macro: - * - When one operand is a null pointer constant (i.e. when x is an integer - * constant expression) and the other is an object pointer (i.e. our - * third operand), the conditional operator returns the type of the - * object pointer operand (i.e. "int *"). Here, within the sizeof(), we - * would then get: - * sizeof(*((int *)(...)) == sizeof(int) == 4 - * - When one operand is a void pointer (i.e. when x is not an integer - * constant expression) and the other is an object pointer (i.e. our - * third operand), the conditional operator returns a "void *" type. - * Here, within the sizeof(), we would then get: - * sizeof(*((void *)(...)) == sizeof(void) == 1 - * - The equality comparison to "sizeof(int)" therefore depends on (x): - * sizeof(int) == sizeof(int) (x) was a constant expression - * sizeof(int) != sizeof(void) (x) was not a constant expression - */ -#define __is_constexpr(x) \ - (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) - /* * Whether 'type' is a signed type or an unsigned type. Supports scalar types, * bool and also pointer types.