Skip to content

Commit

Permalink
riscv: Disable Vector Instructions for kernel itself
Browse files Browse the repository at this point in the history
Disable vector instructions execution for kernel mode at its entrances.
This helps find illegal uses of vector in the kernel space, which is
similar to the fpu.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Co-developed-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Co-developed-by: Han-Kuan Chen <hankuan.chen@sifive.com>
Signed-off-by: Han-Kuan Chen <hankuan.chen@sifive.com>
Co-developed-by: Greentime Hu <greentime.hu@sifive.com>
Signed-off-by: Greentime Hu <greentime.hu@sifive.com>
Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner@vrull.eu>
Tested-by: Heiko Stuebner <heiko.stuebner@vrull.eu>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Link: https://lore.kernel.org/r/20230605110724.21391-7-andy.chiu@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
  • Loading branch information
Guo Ren authored and Palmer Dabbelt committed Jun 8, 2023
1 parent 6b53382 commit 74abe5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions arch/riscv/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ _save_context:
* Disable user-mode memory access as it should only be set in the
* actual user copy routines.
*
* Disable the FPU to detect illegal usage of floating point in kernel
* space.
* Disable the FPU/Vector to detect illegal usage of floating point
* or vector in kernel space.
*/
li t0, SR_SUM | SR_FS
li t0, SR_SUM | SR_FS_VS

REG_L s0, TASK_TI_USER_SP(tp)
csrrc s1, CSR_STATUS, t0
Expand Down
12 changes: 6 additions & 6 deletions arch/riscv/kernel/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ secondary_start_sbi:
.option pop

/*
* Disable FPU to detect illegal usage of
* floating point in kernel space
* Disable FPU & VECTOR to detect illegal usage of
* floating point or vector in kernel space
*/
li t0, SR_FS
li t0, SR_FS_VS
csrc CSR_STATUS, t0

/* Set trap vector to spin forever to help debug */
Expand Down Expand Up @@ -234,10 +234,10 @@ pmp_done:
.option pop

/*
* Disable FPU to detect illegal usage of
* floating point in kernel space
* Disable FPU & VECTOR to detect illegal usage of
* floating point or vector in kernel space
*/
li t0, SR_FS
li t0, SR_FS_VS
csrc CSR_STATUS, t0

#ifdef CONFIG_RISCV_BOOT_SPINWAIT
Expand Down

0 comments on commit 74abe5a

Please sign in to comment.