lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251119224140.8616-2-david.laight.linux@gmail.com>
Date: Wed, 19 Nov 2025 22:40:57 +0000
From: david.laight.linux@...il.com
To: linux-kernel@...r.kernel.org
Cc: Borislav Petkov <bp@...en8.de>,
	Dave Hansen <dave.hansen@...ux.intel.com>,
	Ingo Molnar <mingo@...hat.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	x86@...nel.org,
	Yury Norov <yury.norov@...il.com>,
	David Laight <david.laight.linux@...il.com>
Subject: [PATCH 01/44] x86/asm/bitops: Change the return type of variable__ffs() to unsigned int

From: David Laight <david.laight.linux@...il.com>

The return type of variable__ffs() is currently 'unsigned long'.
This makes the x86 __ffs() be 'unsigned long' whereas the generic
version is 'unsigned int'.

Similarly change variable_ffz() and ffz().

This may save some REX prefix on 64bit.

Detected by some extra checks added to min_t() to detect possible
truncation of large values.

Signed-off-by: David Laight <david.laight.linux@...il.com>
---
 arch/x86/include/asm/bitops.h | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index c2ce213f2b9b..2e8a954d2e2d 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -240,7 +240,7 @@ arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
 					  variable_test_bit(nr, addr);
 }
 
-static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned long word)
+static __always_inline __attribute_const__ unsigned int variable__ffs(unsigned long word)
 {
 	asm("tzcnt %1,%0"
 		: "=r" (word)
@@ -254,12 +254,10 @@ static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned
  *
  * Undefined if no bit exists, so code should check against 0 first.
  */
-#define __ffs(word)				\
-	(__builtin_constant_p(word) ?		\
-	 (unsigned long)__builtin_ctzl(word) :	\
-	 variable__ffs(word))
+#define __ffs(word)	\
+	(__builtin_constant_p(word) ? __builtin_ctzl(word) : variable__ffs(word))
 
-static __always_inline __attribute_const__ unsigned long variable_ffz(unsigned long word)
+static __always_inline __attribute_const__ unsigned int variable_ffz(unsigned long word)
 {
 	return variable__ffs(~word);
 }
@@ -270,10 +268,8 @@ static __always_inline __attribute_const__ unsigned long variable_ffz(unsigned l
  *
  * Undefined if no zero exists, so code should check against ~0UL first.
  */
-#define ffz(word)				\
-	(__builtin_constant_p(word) ?		\
-	 (unsigned long)__builtin_ctzl(~word) :	\
-	 variable_ffz(word))
+#define ffz(word)	\
+	(__builtin_constant_p(word) ? __builtin_ctzl(~word) : variable_ffz(word))
 
 /*
  * __fls: find last set bit in word
@@ -281,7 +277,7 @@ static __always_inline __attribute_const__ unsigned long variable_ffz(unsigned l
  *
  * Undefined if no set bit exists, so code should check against 0 first.
  */
-static __always_inline __attribute_const__ unsigned long __fls(unsigned long word)
+static __always_inline __attribute_const__ unsigned int __fls(unsigned long word)
 {
 	if (__builtin_constant_p(word))
 		return BITS_PER_LONG - 1 - __builtin_clzl(word);
-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ