linux/arch/hexagon/include/asm
Kees Cook 799776f336 hexagon: Add __attribute_const__ to ffs()-family implementations
While tracking down a problem where constant expressions used by
BUILD_BUG_ON() suddenly stopped working[1], we found that an added static
initializer was convincing the compiler that it couldn't track the state
of the prior statically initialized value. Tracing this down found that
ffs() was used in the initializer macro, but since it wasn't marked with
__attribute__const__, the compiler had to assume the function might
change variable states as a side-effect (which is not true for ffs(),
which provides deterministic math results).

Add missing __attribute_const__ annotations to Hexagon's implementations
of fls(), ffs(), __ffs(), __fls(), and ffz() functions. These are
pure mathematical functions that always return the same result for
the same input with no side effects, making them eligible for compiler
optimization.

Build tested ARCH=hexagon defconfig with Clang 21.0.0git (LLVM=1).

Link: https://github.com/KSPP/linux/issues/364 [1]
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250804164417.1612371-8-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
2025-09-08 14:58:51 -07:00
..
Kbuild asm-generic: introduce text-patching.h 2024-11-07 14:25:15 -08:00
asm-offsets.h Hexagon: Add processor and system headers 2011-11-01 07:34:18 -07:00
atomic.h locking/atomic: treewide: delete arch_atomic_*() kerneldoc 2023-06-05 09:57:24 +02:00
bitops.h hexagon: Add __attribute_const__ to ffs()-family implementations 2025-09-08 14:58:51 -07:00
cache.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
cacheflush.h mm: rationalise flush_icache_pages() and flush_icache_page() 2023-08-24 16:20:25 -07:00
checksum.h unify generic instances of csum_partial_copy_nocheck() 2020-08-20 15:45:14 -04:00
cmpxchg.h hexagon: fix using plain integer as NULL pointer warning in cmpxchg 2025-01-30 18:44:54 -08:00
delay.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
dma.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
elf.h whack-a-mole: USE_ELF_CORE_DUMP 2020-10-25 20:03:05 -04:00
exec.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
fixmap.h mm: pgtable: add shortcuts for accessing kernel PMD and PTE 2020-06-09 09:39:13 -07:00
fpu.h Hexagon: Core arch-specific header files 2011-11-01 07:34:18 -07:00
futex.h Hexagon: change jumps to must-extend in futex_atomic_* 2021-05-03 11:04:19 -05:00
hexagon_vm.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
intrinsics.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
io.h hexagon: simplify asm/io.h for !HAS_IOPORT 2024-10-28 21:44:29 +00:00
irq.h hexagon: irq: add prototype for arch_do_IRQ() 2023-12-10 17:21:37 -08:00
irqflags.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
kgdb.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
linkage.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
mem-layout.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
mmu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
mmu_context.h hexagon: use asm-generic/mmu_context.h for no-op implementations 2020-10-27 16:02:35 +01:00
page.h asm-generic updates for 6.13 2024-11-20 15:13:02 -08:00
perf_event.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
pgalloc.h mm: pgtable: convert some architectures to use tlb_remove_ptdesc() 2025-04-01 15:17:13 -07:00
pgtable.h mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
processor.h kernel: exit: cleanup release_thread() 2022-09-11 21:55:07 -07:00
ptrace.h hexagon: Remove unusable symbols from the ptrace.h uapi 2023-10-25 15:54:24 +02:00
setup.h hexagon: Move kernel prototypes out of uapi/asm/setup.h header 2025-01-30 18:45:45 -08:00
smp.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
spinlock.h hexagon: parenthesize registers in asm predicates 2020-01-04 13:55:09 -08:00
spinlock_types.h Improve consistency of '#error' directive messages 2024-11-11 17:17:04 -08:00
string.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
suspend.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
switch_to.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
syscall.h syscall.h: introduce syscall_set_nr() 2025-05-11 17:48:15 -07:00
syscalls.h hexagon: fix fadvise64_64 calling conventions 2024-06-25 15:57:37 +02:00
thread_info.h uaccess: remove CONFIG_SET_FS 2022-02-25 09:36:06 +01:00
time.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
timex.h hexagon: clean up timer-regs.h 2021-11-20 10:35:54 -08:00
tlb.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
tlbflush.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
traps.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
uaccess.h uaccess: generalize access_ok() 2022-02-25 09:36:05 +01:00
unistd.h hexagon: use new system call table 2024-07-10 14:23:38 +02:00
vdso.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
vermagic.h arch: split MODULE_ARCH_VERMAGIC definitions out to <asm/vermagic.h> 2020-04-23 10:50:26 +09:00
vm_fault.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
vm_mmu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
vmalloc.h mm/vmalloc: Add empty <asm/vmalloc.h> headers and use them from <linux/vmalloc.h> 2019-12-10 10:12:55 +01:00