Skip to content

Commit 7977448

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
riscv: misaligned: add a function to check misalign trap delegability
Checking for the delegability of the misaligned access trap is needed for the KVM FWFT extension implementation. Add a function to get the delegability of the misaligned trap exception. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Charlie Jenkins <[email protected]> Tested-by: Charlie Jenkins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 4eaaa65 commit 7977448

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

arch/riscv/include/asm/cpufeature.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ static inline bool unaligned_ctl_available(void)
8181

8282
#if defined(CONFIG_RISCV_MISALIGNED)
8383
DECLARE_PER_CPU(long, misaligned_access_speed);
84+
bool misaligned_traps_can_delegate(void);
85+
#else
86+
static inline bool misaligned_traps_can_delegate(void)
87+
{
88+
return false;
89+
}
8490
#endif
8591

8692
bool __init check_vector_unaligned_access_emulated_all_cpus(void);

arch/riscv/kernel/traps_misaligned.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,10 @@ static int cpu_online_check_unaligned_access_emulated(unsigned int cpu)
724724
}
725725
#endif
726726

727-
#ifdef CONFIG_RISCV_SBI
728-
729727
static bool misaligned_traps_delegated;
730728

729+
#ifdef CONFIG_RISCV_SBI
730+
731731
static int cpu_online_sbi_unaligned_setup(unsigned int cpu)
732732
{
733733
if (sbi_fwft_set(SBI_FWFT_MISALIGNED_EXC_DELEG, 1, 0) &&
@@ -763,6 +763,7 @@ static int cpu_online_sbi_unaligned_setup(unsigned int cpu __always_unused)
763763
{
764764
return 0;
765765
}
766+
766767
#endif
767768

768769
int cpu_online_unaligned_access_init(unsigned int cpu)
@@ -775,3 +776,15 @@ int cpu_online_unaligned_access_init(unsigned int cpu)
775776

776777
return cpu_online_check_unaligned_access_emulated(cpu);
777778
}
779+
780+
bool misaligned_traps_can_delegate(void)
781+
{
782+
/*
783+
* Either we successfully requested misaligned traps delegation for all
784+
* CPUs, or the SBI does not implement the FWFT extension but delegated
785+
* the exception by default.
786+
*/
787+
return misaligned_traps_delegated ||
788+
all_cpus_unaligned_scalar_access_emulated();
789+
}
790+
EXPORT_SYMBOL_GPL(misaligned_traps_can_delegate);

0 commit comments

Comments
 (0)