Skip to content

Commit 22e0eb0

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
riscv: fix misaligned access handling of C.SWSP and C.SDSP
This is a backport of a fix that was done in OpenSBI: ec0559eb315b ("lib: sbi_misaligned_ldst: Fix handling of C.SWSP and C.SDSP"). Unlike C.LWSP/C.LDSP, these encodings can be used with the zero register, so checking that the rs2 field is non-zero is unnecessary. Additionally, the previous check was incorrect since it was checking the immediate field of the instruction instead of the rs2 field. Fixes: 956d705 ("riscv: Unaligned load/store handling for M_MODE") Signed-off-by: Clément Léger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 777c0d7 commit 22e0eb0

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

arch/riscv/kernel/traps_misaligned.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,16 +550,14 @@ int handle_misaligned_store(struct pt_regs *regs)
550550
} else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) {
551551
len = 8;
552552
val.data_ulong = GET_RS2S(insn, regs);
553-
} else if ((insn & INSN_MASK_C_SDSP) == INSN_MATCH_C_SDSP &&
554-
((insn >> SH_RD) & 0x1f)) {
553+
} else if ((insn & INSN_MASK_C_SDSP) == INSN_MATCH_C_SDSP) {
555554
len = 8;
556555
val.data_ulong = GET_RS2C(insn, regs);
557556
#endif
558557
} else if ((insn & INSN_MASK_C_SW) == INSN_MATCH_C_SW) {
559558
len = 4;
560559
val.data_ulong = GET_RS2S(insn, regs);
561-
} else if ((insn & INSN_MASK_C_SWSP) == INSN_MATCH_C_SWSP &&
562-
((insn >> SH_RD) & 0x1f)) {
560+
} else if ((insn & INSN_MASK_C_SWSP) == INSN_MATCH_C_SWSP) {
563561
len = 4;
564562
val.data_ulong = GET_RS2C(insn, regs);
565563
} else if ((insn & INSN_MASK_C_FSD) == INSN_MATCH_C_FSD) {

0 commit comments

Comments
 (0)