]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
riscv: misaligned: add a function to check misalign trap delegability
authorClément Léger <cleger@rivosinc.com>
Fri, 23 May 2025 10:19:27 +0000 (12:19 +0200)
committerPalmer Dabbelt <palmer@dabbelt.com>
Wed, 4 Jun 2025 22:11:07 +0000 (15:11 -0700)
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 <cleger@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
Tested-by: Charlie Jenkins <charlie@rivosinc.com>
Link: https://lore.kernel.org/r/20250523101932.1594077-11-cleger@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>
arch/riscv/include/asm/cpufeature.h
arch/riscv/kernel/traps_misaligned.c

index 2bfa4ef383edaf5ffde3f255e563e1cf6381517c..fbd0e4306c93478470daf270dfeec8bd7a024437 100644 (file)
@@ -81,6 +81,12 @@ static inline bool unaligned_ctl_available(void)
 
 #if defined(CONFIG_RISCV_MISALIGNED)
 DECLARE_PER_CPU(long, misaligned_access_speed);
+bool misaligned_traps_can_delegate(void);
+#else
+static inline bool misaligned_traps_can_delegate(void)
+{
+       return false;
+}
 #endif
 
 bool __init check_vector_unaligned_access_emulated_all_cpus(void);
index 7ecaa8103fe7486d0531be2cf82340647087ec5c..93043924fe6c608c9fa8ee322096450a3963e614 100644 (file)
@@ -724,10 +724,10 @@ static int cpu_online_check_unaligned_access_emulated(unsigned int cpu)
 }
 #endif
 
-#ifdef CONFIG_RISCV_SBI
-
 static bool misaligned_traps_delegated;
 
+#ifdef CONFIG_RISCV_SBI
+
 static int cpu_online_sbi_unaligned_setup(unsigned int cpu)
 {
        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)
 {
        return 0;
 }
+
 #endif
 
 int cpu_online_unaligned_access_init(unsigned int cpu)
@@ -775,3 +776,15 @@ int cpu_online_unaligned_access_init(unsigned int cpu)
 
        return cpu_online_check_unaligned_access_emulated(cpu);
 }
+
+bool misaligned_traps_can_delegate(void)
+{
+       /*
+        * Either we successfully requested misaligned traps delegation for all
+        * CPUs, or the SBI does not implement the FWFT extension but delegated
+        * the exception by default.
+        */
+       return misaligned_traps_delegated ||
+              all_cpus_unaligned_scalar_access_emulated();
+}
+EXPORT_SYMBOL_GPL(misaligned_traps_can_delegate);