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

arm64: cpufeature: make cpus_have_cap() noinstr-safe

Currently it isn't safe to use cpus_have_cap() from noinstr code as
test_bit() is explicitly instrumented, and were cpus_have_cap() placed
out-of-line, cpus_have_cap() itself could be instrumented.

Make cpus_have_cap() noinstr safe by marking it __always_inline and
using arch_test_bit().

Aside from the prevention of instrumentation, there should be no
functional change as a result of this patch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: James Morse <james.morse@arm.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20220912162210.3626215-2-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Mark Rutland and committed by
Catalin Marinas
92b4b561 b90cb105

+2 -2
+2 -2
arch/arm64/include/asm/cpufeature.h
··· 448 448 * 449 449 * Before the capability is detected, this returns false. 450 450 */ 451 - static inline bool cpus_have_cap(unsigned int num) 451 + static __always_inline bool cpus_have_cap(unsigned int num) 452 452 { 453 453 if (num >= ARM64_NCAPS) 454 454 return false; 455 - return test_bit(num, cpu_hwcaps); 455 + return arch_test_bit(num, cpu_hwcaps); 456 456 } 457 457 458 458 /*