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

arm64: cpufeatures: Add capability for LDAPR instruction

Armv8.3 introduced the LDAPR instruction, which provides weaker memory
ordering semantics than LDARi (RCpc vs RCsc). Generally, we provide an
RCsc implementation when implementing the Linux memory model, but LDAPR
can be used as a useful alternative to dependency ordering, particularly
when the compiler is capable of breaking the dependencies.

Since LDAPR is not available on all CPUs, add a cpufeature to detect it at
runtime and allow the instruction to be used with alternative code
patching.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>

+15 -1
+3
arch/arm64/Kconfig
··· 1388 1388 The feature is detected at runtime, and will remain as a 'nop' 1389 1389 instruction if the cpu does not implement the feature. 1390 1390 1391 + config AS_HAS_LDAPR 1392 + def_bool $(as-instr,.arch_extension rcpc) 1393 + 1391 1394 config ARM64_LSE_ATOMICS 1392 1395 bool 1393 1396 default ARM64_USE_LSE_ATOMICS
+2 -1
arch/arm64/include/asm/cpucaps.h
··· 66 66 #define ARM64_HAS_TLB_RANGE 56 67 67 #define ARM64_MTE 57 68 68 #define ARM64_WORKAROUND_1508412 58 69 + #define ARM64_HAS_LDAPR 59 69 70 70 - #define ARM64_NCAPS 59 71 + #define ARM64_NCAPS 60 71 72 72 73 #endif /* __ASM_CPUCAPS_H */
+10
arch/arm64/kernel/cpufeature.c
··· 2136 2136 .cpu_enable = cpu_enable_mte, 2137 2137 }, 2138 2138 #endif /* CONFIG_ARM64_MTE */ 2139 + { 2140 + .desc = "RCpc load-acquire (LDAPR)", 2141 + .capability = ARM64_HAS_LDAPR, 2142 + .type = ARM64_CPUCAP_SYSTEM_FEATURE, 2143 + .sys_reg = SYS_ID_AA64ISAR1_EL1, 2144 + .sign = FTR_UNSIGNED, 2145 + .field_pos = ID_AA64ISAR1_LRCPC_SHIFT, 2146 + .matches = has_cpuid_feature, 2147 + .min_field_value = 1, 2148 + }, 2139 2149 {}, 2140 2150 }; 2141 2151