Skip to content

Commit 5a83e73

Browse files
charlie-rivospalmer-dabbelt
authored andcommitted
riscv: lib: Introduce has_fast_unaligned_access()
Create has_fast_unaligned_access to avoid needing to explicitly check the fast_misaligned_access_speed_key static key. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Reviewed-by: Evan Green <evan@rivosinc.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Link: https://lore.kernel.org/r/20240308-disable_misaligned_probe_config-v9-1-a388770ba0ce@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 6613476 commit 5a83e73

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

arch/riscv/include/asm/cpufeature.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22
/*
3-
* Copyright 2022-2023 Rivos, Inc
3+
* Copyright 2022-2024 Rivos, Inc
44
*/
55

66
#ifndef _ASM_CPUFEATURE_H
@@ -53,6 +53,13 @@ static inline bool check_unaligned_access_emulated(int cpu)
5353
static inline void unaligned_emulation_finish(void) {}
5454
#endif
5555

56+
DECLARE_STATIC_KEY_FALSE(fast_unaligned_access_speed_key);
57+
58+
static __always_inline bool has_fast_unaligned_accesses(void)
59+
{
60+
return static_branch_likely(&fast_unaligned_access_speed_key);
61+
}
62+
5663
unsigned long riscv_get_elf_hwcap(void);
5764

5865
struct riscv_isa_ext_data {
@@ -135,6 +142,4 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi
135142
return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
136143
}
137144

138-
DECLARE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key);
139-
140145
#endif

arch/riscv/kernel/cpufeature.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,14 @@ static void check_unaligned_access_nonboot_cpu(void *param)
810810
check_unaligned_access(pages[cpu]);
811811
}
812812

813-
DEFINE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key);
813+
DEFINE_STATIC_KEY_FALSE(fast_unaligned_access_speed_key);
814814

815815
static void modify_unaligned_access_branches(cpumask_t *mask, int weight)
816816
{
817817
if (cpumask_weight(mask) == weight)
818-
static_branch_enable_cpuslocked(&fast_misaligned_access_speed_key);
818+
static_branch_enable_cpuslocked(&fast_unaligned_access_speed_key);
819819
else
820-
static_branch_disable_cpuslocked(&fast_misaligned_access_speed_key);
820+
static_branch_disable_cpuslocked(&fast_unaligned_access_speed_key);
821821
}
822822

823823
static void set_unaligned_access_static_branches_except_cpu(int cpu)

arch/riscv/lib/csum.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Checksum library
44
*
55
* Influenced by arch/arm64/lib/csum.c
6-
* Copyright (C) 2023 Rivos Inc.
6+
* Copyright (C) 2023-2024 Rivos Inc.
77
*/
88
#include <linux/bitops.h>
99
#include <linux/compiler.h>
@@ -318,10 +318,7 @@ unsigned int do_csum(const unsigned char *buff, int len)
318318
* branches. The largest chunk of overlap was delegated into the
319319
* do_csum_common function.
320320
*/
321-
if (static_branch_likely(&fast_misaligned_access_speed_key))
322-
return do_csum_no_alignment(buff, len);
323-
324-
if (((unsigned long)buff & OFFSET_MASK) == 0)
321+
if (has_fast_unaligned_accesses() || (((unsigned long)buff & OFFSET_MASK) == 0))
325322
return do_csum_no_alignment(buff, len);
326323

327324
return do_csum_with_alignment(buff, len);

0 commit comments

Comments
 (0)