Add support to handle misaligned accesses in S-mode
cover Add support to handle misaligned accesses in S-mode
Since commit 61cadb9 ("Provide new description of misaligned load/store behavior compatible with privileged architecture.") in the RISC-V ISA manual, it is stated that misaligned load/store might not be supported. However, the RISC-V kernel uABI describes that misaligned accesses are supported. In order to support that, this series adds support for S-mode handling of misaligned accesses, SBI call for misaligned trap delegation as well prctl support for PR_SET_UNALIGN.
Handling misaligned access in kernel allows for a finer grain control of the misaligned accesses behavior, and thanks to the prctl call, can allow disabling misaligned access emulation to generate SIGBUS. User space software can then be optimized by removing such access based on SIGBUS generation.
This series relies on a SBI extension [1] allowing to request delegation of the misaligned load/store traps to the S-mode software. This extension has been submitted for review to the riscv tech-prs group.
This work was tested on spike since Qemu does transparently handles misaligned access.
[1] https://lists.riscv.org/g/tech-prs/message/472i
Clément Léger (6):
riscv: remove unused functions in traps_misaligned.c
riscv: add support for misaligned handling in S-mode
riscv: allow S-mode to handle misaligned traps
riscv: add support for SBI misalignment trap delegation
riscv: add support for PR_SET_UNALIGN and PR_GET_UNALIGN
riscv: add floating point insn support to misaligned access emulation
arch/riscv/include/asm/processor.h | 9 + arch/riscv/include/asm/sbi.h | 12 ++ arch/riscv/kernel/Makefile | 2 +- arch/riscv/kernel/fpu.S | 118 ++++++++++++ arch/riscv/kernel/process.c | 20 ++ arch/riscv/kernel/sbi.c | 28 +++ arch/riscv/kernel/traps.c | 7 - arch/riscv/kernel/traps_misaligned.c | 276 ++++++++++++++++++++++----- 8 files changed, 417 insertions(+), 55 deletions(-)
Signature · 1 line
2.40.1
RFC PATCH 1/6 riscv: remove unused functions in traps_misaligned.c
Replace macros by the only two function calls that are done from this file, store_u8() and load_u8().
--- arch/riscv/kernel/traps_misaligned.c | 46 +++++----------------------- 1 file changed, 7 insertions(+), 39 deletions(-)
arch/riscv/kernel/traps_misaligned.c +7 -39
@@ -151,51 +151,19 @@#define PRECISION_S 0#define PRECISION_D 1 -#define DECLARE_UNPRIVILEGED_LOAD_FUNCTION (type, insn) \ -static inline type load_##type(const type *addr) \ -{ \ - type val; \ - asm (#insn " %0, %1" \ - : "=&r" (val) : "m" (*addr)); \ - return val; \ -} +static inline u8 load_u8 (const u8 *addr) +{ +u8 val; -#define DECLARE_UNPRIVILEGED_STORE_FUNCTION (type, insn) \ -static inline void store_##type(type *addr, type val) \ -{ \ - asm volatile (#insn " %0, %1\n" \ - : : "r" (val), "m" (*addr)); \ -} + asmvolatile ("lbu %0, %1" :"=&r" (val) :"m" (*addr)); -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u8, lbu) -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u16, lhu) -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s8, lb) -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s16, lh) -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s32, lw) -DECLARE_UNPRIVILEGED_STORE_FUNCTION(u8, sb) -DECLARE_UNPRIVILEGED_STORE_FUNCTION(u16, sh) -DECLARE_UNPRIVILEGED_STORE_FUNCTION(u32, sw) -#if defined(CONFIG_64BIT ) -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u32, lwu) -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u64, ld) -DECLARE_UNPRIVILEGED_STORE_FUNCTION(u64, sd) -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(ulong, ld) -#else -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u32, lw) -DECLARE_UNPRIVILEGED_LOAD_FUNCTION(ulong, lw) - -static inline u64 load_u64 (const u64 *addr) -{ -return load_u32 ((u32 *)addr) - + ((u64 )load_u32 ((u32 *)addr +1 ) <<32 ); +return val; } -static inline void store_u64 (u64 *addr,u64 val) +static inline void store_u8 (u8 *addr,u8 val) { -store_u32 ((u32 *)addr, val); -store_u32 ((u32 *)addr +1 , val >>32 ); + asmvolatile ("sb %0, %1\n" : :"r" (val),"m" (*addr)); } -#endif static inline ulong get_insn (ulong mepc) {
Signature · 1 line
2.40.1
RFC PATCH 2/6 riscv: add support for misaligned handling in S-mode
In reply to Clément LégerMisalignment handling is only supported for M-mode and uses direct accesses to user memory. in S-mode, this requires to use the get_user()/put_user() accessors. Implement load_u8(), store_u8() and get_insn() using these accessors. Also, use CSR_TVAL instead of hardcoded mtval in csr_read() call which will work for both S-mode and M-mode. When used in S-mode, we do not handle misaligned accesses that are triggered from kernel mode.
--- arch/riscv/kernel/Makefile | 2 +- arch/riscv/kernel/traps_misaligned.c | 111 +++++++++++++++++++++++---- 2 files changed, 99 insertions(+), 14 deletions(-)
arch/riscv/kernel/Makefile +1 -1
@@ -56,9 +56,9 @@ obj-y += stacktrace.o obj-y += cacheinfo.o obj-y += patch.o obj-y += probes/ +obj-y += traps_misaligned.o obj-$(CONFIG_MMU) += vdso.o vdso/ -obj-$(CONFIG_RISCV_M_MODE) += traps_misaligned.o obj-$(CONFIG_FPU) += fpu.o obj-$(CONFIG_SMP) += smpboot.o obj-$(CONFIG_SMP) += smp.o
arch/riscv/kernel/traps_misaligned.c +98 -13
170 lines not on this page · raw message
Signature · 1 line
2.40.1
RFC PATCH 3/6 riscv: allow S-mode to handle misaligned traps
In reply to Clément LégerNow that we will be able to configure the SBI to let us handle the traps, let this misalignment handling be available for S-mode.
--- arch/riscv/kernel/traps.c | 7 ------- 1 file changed, 7 deletions(-)
arch/riscv/kernel/traps.c +0 -7
@@ -149,12 +149,6 @@ DO_ERROR_INFO(do_trap_insn_illegal, SIGILL, ILL_ILLOPC, "illegal instruction");DO_ERROR_INFO (do_trap_load_fault,SIGSEGV ,SEGV_ACCERR ,"load access fault" ); -#ifndef CONFIG_RISCV_M_MODE -DO_ERROR_INFO (do_trap_load_misaligned, -SIGBUS ,BUS_ADRALN ,"Oops - load address misaligned" ); -DO_ERROR_INFO (do_trap_store_misaligned, -SIGBUS ,BUS_ADRALN ,"Oops - store (or AMO) address misaligned" ); -#else int handle_misaligned_load (struct pt_regs *regs);int handle_misaligned_store (struct pt_regs *regs);
@@ -199,7 +193,6 @@ asmlinkage __visible __trap_section void do_trap_store_misaligned(struct pt_regsirqentry_nmi_exit (regs, state); } } -#endif DO_ERROR_INFO (do_trap_store_fault,SIGSEGV ,SEGV_ACCERR ,"store (or AMO) access fault" ); DO_ERROR_INFO(do_trap_ecall_s,
Signature · 7 lines
2.40.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 4/6 riscv: add support for SBI misalignment trap delegation
In reply to Clément LégerAdd support for misalignment trap delegation by setting it with SBI_EXT_FW_FEATURE SBI extension. This extension allows to control SBI behavior by requesting to set them to specific value. In order to implement prctl(PR_SET_UNALIGN, PR_UNALIGN_SIGBUS) behavior properly, we need to let the kernel handle the misalignment error by itself. This commit adds the sbi_delegate_misaligned() function to check if the SBI delegated us the misalignement handling. The value returned by this function is initialize at init time from sbi_init().
--- arch/riscv/include/asm/sbi.h | 12 ++++++++++++ arch/riscv/kernel/sbi.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
arch/riscv/include/asm/sbi.h +12 -0
@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , +SBI_EXT_FW_FEATURE =0x46574654 ,/* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000,
@@ -236,6 +237,16 @@ enum sbi_pmu_ctr_type {/* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0) +/* SBI function IDs for FW feature extension */ +#define SBI_EXT_FW_FEATURE_SET 0x0 +#define SBI_EXT_FW_FEATURE_GET 0x1 + +enum sbi_fw_features_t { +SBI_FW_FEATURE_MISALIGNED_DELEG =0 , + +SBI_FW_FEATURE_MAX , +}; +#define SBI_SPEC_VERSION_DEFAULT 0x1#define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
@@ -269,6 +280,7 @@ int sbi_console_getchar(void);long sbi_get_mvendorid (void );long sbi_get_marchid (void );long sbi_get_mimpid (void ); +bool sbi_delegate_misaligned (void );void sbi_set_timer (uint64_t stime_value);void sbi_shutdown (void );void sbi_send_ipi (unsigned int cpu);
arch/riscv/kernel/sbi.c +28 -0
@@ -22,6 +22,8 @@ static int (*__sbi_rfence)(int fid, const struct cpumask *cpu_mask, unsigned long start, unsigned long size, unsigned long arg4, unsigned long arg5) __ro_after_init; +static bool __sbi_misaligned_deleg__ro_after_init ; + struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4,
@@ -342,6 +344,11 @@ static int __sbi_rfence_v02(int fid, const struct cpumask *cpu_mask,return 0 ; } +bool sbi_delegate_misaligned (void ) +{ +return __sbi_misaligned_deleg; +} +/** * sbi_set_timer() - Program the timer for next timer event. * @stime_value: The value after which next timer event should fire.
@@ -494,6 +501,16 @@ int sbi_remote_hfence_vvma_asid(const struct cpumask *cpu_mask, }EXPORT_SYMBOL (sbi_remote_hfence_vvma_asid); +static int sbi_fw_feature_set (enum sbi_fw_features_t feature,bool set) +{ +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_FW_FEATURE ,SBI_EXT_FW_FEATURE_SET , feature, + set,0 ,0 ,0 ,0 ); + +return sbi_err_map_linux_errno (ret.error); +} +static void sbi_srst_reset (unsigned long type,unsigned long reason) { sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_RESET, type, reason,
@@ -624,6 +641,17 @@ void __init sbi_init(void) sbi_srst_reboot_nb.priority =192 ;register_restart_handler (&sbi_srst_reboot_nb); } +/* +* TODO: this will likely need to be updated when SBI extension +* is ratified +*/ +if ((sbi_spec_version >=sbi_mk_version (1 ,0 )) && + (sbi_probe_extension (SBI_EXT_FW_FEATURE ) >0 )) { +pr_info ("SBI FW_FEATURE extension detected\n" ); +if (!sbi_fw_feature_set (SBI_FW_FEATURE_MISALIGNED_DELEG , + true)) + __sbi_misaligned_deleg = true; + } }else { __sbi_set_timer = __sbi_set_timer_v01; __sbi_send_ipi = __sbi_send_ipi_v01;
Signature · 7 lines
2.40.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 5/6 riscv: add support for PR_SET_UNALIGN and PR_GET_UNALIGN
In reply to Clément LégerNow that trap support is ready to handle misalignment errors in S-mode, allow the user to control the behavior of misalignment accesses using prctl(). Add an align_ctl flag in thread_struct which will be used to determine if we should SIGBUS the process or not on such fault.
--- arch/riscv/include/asm/processor.h | 9 +++++++++ arch/riscv/kernel/process.c | 20 ++++++++++++++++++++ arch/riscv/kernel/traps_misaligned.c | 7 +++++++ 3 files changed, 36 insertions(+)
arch/riscv/include/asm/processor.h +9 -0
@@ -7,6 +7,7 @@#define _ASM_RISCV_PROCESSOR_H#include <linux/const.h> +#include <linux/prctl.h> #include <vdso/processor.h>
@@ -39,6 +40,7 @@ struct thread_struct {unsigned long s[12 ];/* s[0]: frame pointer */ struct __riscv_d_ext_state fstate;unsigned long bad_cause; +unsigned long align_ctl; };/* Whitelist the fstate from the task_struct for hardened usercopy */
@@ -51,6 +53,7 @@ static inline void arch_thread_struct_whitelist(unsigned long *offset,#define INIT_THREAD { \ .sp = sizeof(init_stack) + (long)&init_stack, \ + .align_ctl = PR_UNALIGN_NOPRINT, \ }#define task_pt_regs (tsk) \
@@ -80,6 +83,12 @@ int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid);extern void riscv_fill_hwcap (void );extern int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src); +extern int get_unalign_ctl (struct task_struct *,unsigned long addr); +extern int set_unalign_ctl (struct task_struct *,unsigned int val); + +#define GET_UNALIGN_CTL (tsk, addr) get_unalign_ctl((tsk), (addr)) +#define SET_UNALIGN_CTL (tsk, val) set_unalign_ctl((tsk), (val)) +#endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_PROCESSOR_H */
arch/riscv/kernel/process.c +20 -0
@@ -19,6 +19,7 @@#include <asm/unistd.h> #include <asm/processor.h> #include <asm/csr.h> +#include <asm/sbi.h> #include <asm/stacktrace.h> #include <asm/string.h> #include <asm/switch_to.h>
@@ -40,6 +41,25 @@ void arch_cpu_idle(void)cpu_do_idle (); } +int set_unalign_ctl (struct task_struct *tsk,unsigned int val) +{ +#if IS_ENABLED (CONFIG_RISCV_SBI ) +if (!sbi_delegate_misaligned ()) +return -EINVAL ; +#endif + tsk->thread.align_ctl = val; +return 0 ; +} + +int get_unalign_ctl (struct task_struct *tsk,unsigned long adr) +{ +#if IS_ENABLED (CONFIG_RISCV_SBI ) +if (!sbi_delegate_misaligned ()) +return -EINVAL ; +#endif +return put_user (tsk->thread.align_ctl, (unsigned long __user *)adr); +} +void __show_regs (struct pt_regs *regs) {show_regs_print_info (KERN_DEFAULT );
arch/riscv/kernel/traps_misaligned.c +7 -0
@@ -8,6 +8,7 @@#include <linux/module.h> #include <linux/irq.h> #include <linux/stringify.h> +#include <linux/prctl.h> #include <asm/processor.h> #include <asm/ptrace.h>
@@ -277,6 +278,9 @@ int handle_misaligned_load(struct pt_regs *regs)if (!IS_ENABLED (CONFIG_RISCV_M_MODE ) && !user_mode (regs))return -1 ; +if ((current->thread.align_ctl &PR_UNALIGN_SIGBUS )) +return -1 ; +if (get_insn (epc, &insn))return -1 ;
@@ -373,6 +377,9 @@ int handle_misaligned_store(struct pt_regs *regs)if (!IS_ENABLED (CONFIG_RISCV_M_MODE ) && !user_mode (regs))return -1 ; +if ((current->thread.align_ctl &PR_UNALIGN_SIGBUS )) +return -1 ; +if (get_insn (epc, &insn))return -1 ;
Signature · 7 lines
2.40.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 6/6 riscv: add floating point insn support to misaligned access emulation
In reply to Clément LégerThis support is partially based of openSBI misaligned emulation floating point instruction support. It provides support for the existing floating point instructions (both for 32/64 bits as well as compressed ones). Since floating point registers are not aprt of the pt_regs struct, we need to modify them directly using some assembly. We also dirty the pt_regs status in case we modify them to be sure context switch will save them. With this support, Linux is on par with openSBI support.
--- arch/riscv/kernel/fpu.S | 118 ++++++++++++++++++++++++ arch/riscv/kernel/traps_misaligned.c | 130 ++++++++++++++++++++++++++- 2 files changed, 244 insertions(+), 4 deletions(-)
arch/riscv/kernel/fpu.S +118 -0
@@ -104,3 +104,121 @@ ENTRY(__fstate_restore) csrc CSR_STATUS, t1 ret ENDPROC(__fstate_restore) + + +#define get_f32(which) fmv.x.s a0, which; j 2f +#define put_f32(which) fmv.s.x which, a1; j 2f +#if __riscv_xlen == 64 +# define get_f64(which) fmv.x.d a0, which; j 2f +# define put_f64(which) fmv.d.x which, a1; j 2f +#else +# define get_f64(which) fsd which, 0(a1); j 2f +# define put_f64(which) fld which, 0(a1); j 2f +#endif + +.macro fp_access_prologue + /* + * Compute jump offset to store the correct FP register since we don't + * have indirect FP register access + */ + sll t0, a0, 3 + la t2, 1f + add t0, t0, t2 + li t1, SR_FS + csrs CSR_STATUS, t1 + jr t0 +1: +.endm + +.macro fp_access_epilogue +2: + csrc CSR_STATUS, t1 + ret +.endm + +#define fp_access_body(__access_func) \ + __access_func(f0); \ + __access_func(f1); \ + __access_func(f2); \ + __access_func(f3); \ + __access_func(f4); \ + __access_func(f5); \ + __access_func(f6); \ + __access_func(f7); \ + __access_func(f8); \ + __access_func(f9); \ + __access_func(f10); \ + __access_func(f11); \ + __access_func(f12); \ + __access_func(f13); \ + __access_func(f14); \ + __access_func(f15); \ + __access_func(f16); \ + __access_func(f17); \ + __access_func(f18); \ + __access_func(f19); \ + __access_func(f20); \ + __access_func(f21); \ + __access_func(f22); \ + __access_func(f23); \ + __access_func(f24); \ + __access_func(f25); \ + __access_func(f26); \ + __access_func(f27); \ + __access_func(f28); \ + __access_func(f29); \ + __access_func(f30); \ + __access_func(f31) + + +/* + * Disable compressed instructions set to keep a constant offset between FP + * load/store/move instructions + */ +.option norvc +/* + * put_f32_reg - Set a FP register from a register containing the value + * a0 = FP register index to be set + * a1 = value to be loaded in the FP register + */ +SYM_FUNC_START(put_f32_reg) + fp_access_prologue + fp_access_body(put_f32) + fp_access_epilogue +SYM_FUNC_END(put_f32_reg) + +/* + * get_f32_reg - Get a FP register value and return it + * a0 = FP register index to be retrieved + */ +SYM_FUNC_START(get_f32_reg) + fp_access_prologue + fp_access_body(get_f32) + fp_access_epilogue +SYM_FUNC_END(put_f32_reg) + +/* + * put_f64_reg - Set a 64 bits FP register from a value or a pointer. + * a0 = FP register index to be set + * a1 = value/pointer to be loaded in the FP register (when xlen == 32 bits, we + * load the value to a pointer). + */ +SYM_FUNC_START(put_f64_reg) + fp_access_prologue + fp_access_body(put_f64) + fp_access_epilogue +SYM_FUNC_END(put_f64_reg) + +/* + * put_f64_reg - Get a 64 bits FP register value and returned it or store it to + * a pointer. + * a0 = FP register index to be retrieved + * a1 = If xlen == 32, pointer which should be loaded with the FP register value + * or unused if xlen == 64. In which case the FP register value is returned + * through a0 + */ +SYM_FUNC_START(get_f64_reg) + fp_access_prologue + fp_access_body(get_f64) + fp_access_epilogue +SYM_FUNC_END(get_f64_reg)
arch/riscv/kernel/traps_misaligned.c +126 -4
171 lines not on this page · raw message
Signature · 7 lines
2.40.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
kernel test robot
build botRe: [RFC PATCH 6/6] riscv: add floating point insn support to misaligned access emulation
kernel test robot noticed the following build errors:
Hi Clément,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.4-rc7]
[cannot apply to openrisc/for-next next-20230623]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Cl-ment-L-ger/riscv-remove-unused-functions-in-traps_misaligned-c/20230624-202152 base: linus/master patch link: https://lore.kernel.org/r/20230624122049.7886-7-cleger%40rivosinc.com patch subject: [RFC PATCH 6/6] riscv: add floating point insn support to misaligned access emulation config: riscv-randconfig-r013-20230624 (https://download.01.org/0day-ci/archive/20230624/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230624/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
arch/riscv/kernel/traps_misaligned.c:353:5: warning: no previous prototype for 'handle_misaligned_load' [-Wmissing-prototypes]
353 | int handle_misaligned_load(struct pt_regs *regs)
| ^~~~~~~~~~~~~~~~~~~~~~
arch/riscv/kernel/traps_misaligned.c: In function 'handle_misaligned_load':
>> arch/riscv/kernel/traps_misaligned.c:449:17: error: implicit declaration of function 'set_f64_rd'; did you mean 'set_p4d'? [-Werror=implicit-function-declaration]
449 | set_f64_rd(insn, regs, val.data_u64);
| ^~~~~~~~~~
| set_p4d
>> arch/riscv/kernel/traps_misaligned.c:451:17: error: implicit declaration of function 'set_f32_rd' [-Werror=implicit-function-declaration]
451 | set_f32_rd(insn, regs, val.data_ulong);
| ^~~~~~~~~~
arch/riscv/kernel/traps_misaligned.c: At top level:
arch/riscv/kernel/traps_misaligned.c:458:5: warning: no previous prototype for 'handle_misaligned_store' [-Wmissing-prototypes]
458 | int handle_misaligned_store(struct pt_regs *regs)
| ^~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/kernel/traps_misaligned.c: In function 'handle_misaligned_store':
>> arch/riscv/kernel/traps_misaligned.c:493:32: error: implicit declaration of function 'GET_F64_RS2'; did you mean 'GET_RS2'? [-Werror=implicit-function-declaration]
493 | val.data_u64 = GET_F64_RS2(insn, regs);
| ^~~~~~~~~~~
| GET_RS2
>> arch/riscv/kernel/traps_misaligned.c:497:34: error: implicit declaration of function 'GET_F32_RS2'; did you mean 'GET_RS2'? [-Werror=implicit-function-declaration]
497 | val.data_ulong = GET_F32_RS2(insn, regs);
| ^~~~~~~~~~~
| GET_RS2
>> arch/riscv/kernel/traps_misaligned.c:519:32: error: implicit declaration of function 'GET_F64_RS2S'; did you mean 'GET_RS2S'? [-Werror=implicit-function-declaration]
519 | val.data_u64 = GET_F64_RS2S(insn, regs);
| ^~~~~~~~~~~~
| GET_RS2S
>> arch/riscv/kernel/traps_misaligned.c:523:32: error: implicit declaration of function 'GET_F64_RS2C'; did you mean 'GET_RS2C'? [-Werror=implicit-function-declaration]
523 | val.data_u64 = GET_F64_RS2C(insn, regs);
| ^~~~~~~~~~~~
| GET_RS2Ccc1: some warnings being treated as errors
vim +449 arch/riscv/kernel/traps_misaligned.c
352
353 int handle_misaligned_load(struct pt_regs *regs)
354 {
355 union reg_data val;
356 unsigned long epc = regs->epc;
357 unsigned long insn;
358 unsigned long addr;
359 int i, fp = 0, shift = 0, len = 0;
360
361 /*
362 * When running in supervisor mode, we only handle misaligned accesses
363 * triggered from user mode.
364 */
365 if (!IS_ENABLED(CONFIG_RISCV_M_MODE) && !user_mode(regs))
366 return -1;
367
368 if ((current->thread.align_ctl & PR_UNALIGN_SIGBUS))
369 return -1;
370
371 if (get_insn(epc, &insn))
372 return -1;
373
374 addr = csr_read(CSR_TVAL);
375 regs->epc = 0;
376
377 if ((insn & INSN_MASK_LW) == INSN_MATCH_LW) {
378 len = 4;
379 shift = 8 * (sizeof(unsigned long) - len);
380 #if defined(CONFIG_64BIT)
381 } else if ((insn & INSN_MASK_LD) == INSN_MATCH_LD) {
382 len = 8;
383 shift = 8 * (sizeof(unsigned long) - len);
384 } else if ((insn & INSN_MASK_LWU) == INSN_MATCH_LWU) {
385 len = 4;
386 #endif
387 } else if ((insn & INSN_MASK_FLD) == INSN_MATCH_FLD) {
388 fp = 1;
389 len = 8;
390 } else if ((insn & INSN_MASK_FLW) == INSN_MATCH_FLW) {
391 fp = 1;
392 len = 4;
393 } else if ((insn & INSN_MASK_LH) == INSN_MATCH_LH) {
394 len = 2;
395 shift = 8 * (sizeof(unsigned long) - len);
396 } else if ((insn & INSN_MASK_LHU) == INSN_MATCH_LHU) {
397 len = 2;
398 #if defined(CONFIG_64BIT)
399 } else if ((insn & INSN_MASK_C_LD) == INSN_MATCH_C_LD) {
400 len = 8;
401 shift = 8 * (sizeof(unsigned long) - len);
402 insn = RVC_RS2S(insn) << SH_RD;
403 } else if ((insn & INSN_MASK_C_LDSP) == INSN_MATCH_C_LDSP &&
404 ((insn >> SH_RD) & 0x1f)) {
405 len = 8;
406 shift = 8 * (sizeof(unsigned long) - len);
407 #endif
408 } else if ((insn & INSN_MASK_C_LW) == INSN_MATCH_C_LW) {
409 len = 4;
410 shift = 8 * (sizeof(unsigned long) - len);
411 insn = RVC_RS2S(insn) << SH_RD;
412 } else if ((insn & INSN_MASK_C_LWSP) == INSN_MATCH_C_LWSP &&
413 ((insn >> SH_RD) & 0x1f)) {
414 len = 4;
415 shift = 8 * (sizeof(unsigned long) - len);
416 } else if ((insn & INSN_MASK_C_FLD) == INSN_MATCH_C_FLD) {
417 fp = 1;
418 len = 8;
419 insn = RVC_RS2S(insn) << SH_RD;
420 } else if ((insn & INSN_MASK_C_FLDSP) == INSN_MATCH_C_FLDSP) {
421 fp = 1;
422 len = 8;
423 #if defined(CONFIG_32BIT)
424 } else if ((insn & INSN_MASK_C_FLW) == INSN_MATCH_C_FLW) {
425 fp = 1;
426 len = 4;
427 insn = RVC_RS2S(insn) << SH_RD;
428 } else if ((insn & INSN_MASK_C_FLWSP) == INSN_MATCH_C_FLWSP) {
429 fp = 1;
430 len = 4;
431 #endif
432 } else {
433 regs->epc = epc;
434 return -1;
435 }
436
437 if (!IS_ENABLED(CONFIG_FPU) && fp)
438 return -1;
439
440 val.data_u64 = 0;
441 for (i = 0; i < len; i++) {
442 if (load_u8((void *)(addr + i), &val.data_bytes[i]))
443 return -1;
444 }
445
446 if (!fp)
447 SET_RD(insn, regs, val.data_ulong << shift >> shift);
448 else if (len == 8)
> 449 set_f64_rd(insn, regs, val.data_u64);
450 else
> 451 set_f32_rd(insn, regs, val.data_ulong);
452
453 regs->epc = epc + INSN_LEN(insn);
454
455 return 0;
456 }
457
458 int handle_misaligned_store(struct pt_regs *regs)
459 {
460 union reg_data val;
461 unsigned long epc = regs->epc;
462 unsigned long insn;
463 unsigned long addr;
464 int i, len = 0, fp = 0;
465
466 /*
467 * When running in supervisor mode, we only handle misaligned accesses
468 * triggered from user mode.
469 */
470 if (!IS_ENABLED(CONFIG_RISCV_M_MODE) && !user_mode(regs))
471 return -1;
472
473 if ((current->thread.align_ctl & PR_UNALIGN_SIGBUS))
474 return -1;
475
476 if (get_insn(epc, &insn))
477 return -1;
478
479 addr = csr_read(CSR_TVAL);
480 regs->epc = 0;
481
482 val.data_ulong = GET_RS2(insn, regs);
483
484 if ((insn & INSN_MASK_SW) == INSN_MATCH_SW) {
485 len = 4;
486 #if defined(CONFIG_64BIT)
487 } else if ((insn & INSN_MASK_SD) == INSN_MATCH_SD) {
488 len = 8;
489 #endif
490 } else if ((insn & INSN_MASK_FSD) == INSN_MATCH_FSD) {
491 fp = 1;
492 len = 8;
> 493 val.data_u64 = GET_F64_RS2(insn, regs);
494 } else if ((insn & INSN_MASK_FSW) == INSN_MATCH_FSW) {
495 fp = 1;
496 len = 4;
> 497 val.data_ulong = GET_F32_RS2(insn, regs);
498 } else if ((insn & INSN_MASK_SH) == INSN_MATCH_SH) {
499 len = 2;
500 #if defined(CONFIG_64BIT)
501 } else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) {
502 len = 8;
503 val.data_ulong = GET_RS2S(insn, regs);
504 } else if ((insn & INSN_MASK_C_SDSP) == INSN_MATCH_C_SDSP &&
505 ((insn >> SH_RD) & 0x1f)) {
506 len = 8;
507 val.data_ulong = GET_RS2C(insn, regs);
508 #endif
509 } else if ((insn & INSN_MASK_C_SW) == INSN_MATCH_C_SW) {
510 len = 4;
511 val.data_ulong = GET_RS2S(insn, regs);
512 } else if ((insn & INSN_MASK_C_SWSP) == INSN_MATCH_C_SWSP &&
513 ((insn >> SH_RD) & 0x1f)) {
514 len = 4;
515 val.data_ulong = GET_RS2C(insn, regs);
516 } else if ((insn & INSN_MASK_C_FSD) == INSN_MATCH_C_FSD) {
517 fp = 1;
518 len = 8;
> 519 val.data_u64 = GET_F64_RS2S(insn, regs);
520 } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP) {
521 fp = 1;
522 len = 8;
> 523 val.data_u64 = GET_F64_RS2C(insn, regs);Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki