lib: sbi: Fix sign-extension in sbi_misaligned_load_handler()
PATCH v2 1/1 lib: sbi: Fix sign-extension in sbi_misaligned_load_handler()
The misaligned load emulation does not sign-extend values correctly due to missing sign typecast in value passed to the SET_RD() macro.
A very easy way to reproduce this issue is to load 16-bit value 0xff1e from a byte aligned address using LH instruction on hardware lacking misaligned load/store.
This patch fixes sbi_misaligned_load_handler() for above issue.
---
Changes since v1:
- Cast after left-shift and use braces.
--- lib/sbi/sbi_misaligned_ldst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_misaligned_ldst.c +1 -1
@@ -128,7 +128,7 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, }if (!fp) -SET_RD (insn, regs, val.data_ulong << shift >> shift); +SET_RD (insn, regs, ((long )(val.data_ulong << shift)) >> shift);#ifdef __riscv_flen else if (len == 8) SET_F64_RD(insn, regs, val.data_u64);
Signature · 1 line
2.25.1
PATCH v2 1/1 lib: sbi: Fix sign-extension in sbi_misaligned_load_handler()
Quoted 35 lines · Anup Patel
The misaligned load emulation does not sign-extend values correctly due to missing sign typecast in value passed to the
SET_RD()macro.A very easy way to reproduce this issue is to load 16-bit value
0xff1efrom a byte aligned address using LH instruction on hardware lacking misaligned load/store.This patch fixes
sbi_misaligned_load_handler()for above issue.Signed-off-by Anup Patel <[email protected]>---
Changes since v1:
- Cast after left-shift and use braces.--- lib/sbi/sbi_misaligned_ldst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/sbi/sbi_misaligned_ldst.c +1
-2@@ -128,7 +128,7 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, }if (!fp) -SET_RD (insn, regs, val.data_ulong << shift >> shift); +SET_RD (insn, regs, ((long )(val.data_ulong << shift)) >> shift);#ifdef __riscv_flen else if (len == 8) SET_F64_RD(insn, regs, val.data_u64); --2.25.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 2 lines
Regards, Atish
PATCH v2 1/1 lib: sbi: Fix sign-extension in sbi_misaligned_load_handler()
Quoted 50 lines
-----Original Message-----
From: Atish Patra <[email protected]>
Sent: 22 December 2020 05:28
To: Anup Patel <[email protected]>
Cc: Atish Patra <[email protected]>; Alistair Francis <[email protected]>; Anup Patel <[email protected]>; OpenSBI <[email protected]>
Subject: Re: [PATCH v2] lib: sbi: Fix sign-extension insbi_misaligned_load_handler()lib/sbi/sbi_misaligned_ldst.c int sbi_misaligned_load_handler(ulong addr, ulong
Quoted 23 lines · Anup Patel
The misaligned load emulation does not sign-extend values correctly due to missing sign typecast in value passed to the
SET_RD()macro.A very easy way to reproduce this issue is to load 16-bit value
0xff1efrom a byte aligned address using LH instruction on hardware lacking misaligned load/store.This patch fixes
sbi_misaligned_load_handler()for above issue.Signed-off-by Anup Patel <[email protected]>---
Changes since v1:
- Cast after left-shift and use braces.--- lib/sbi/sbi_misaligned_ldst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)(quoted diff) +0
-0
b/lib/sbi/sbi_misaligned_ldst.cindex 964a372..5057cb5 100644lib/sbi/sbi_misaligned_ldst.c +0
-0@@ -128,7 +128,7 @@ int sbi_misaligned_load_handler(ulong addr, ulongtval2, ulong tinst,
Quoted 13 lines
lib/sbi/sbi_misaligned_ldst.c +2
-2}if (!fp) -SET_RD (insn, regs, val.data_ulong << shift >> shift); +SET_RD (insn, regs, ((long )(val.data_ulong << shift)) + >> shift);#ifdef __riscv_flen else if (len == 8) SET_F64_RD(insn, regs, val.data_u64); --2.25.1
Quoted 7 lines
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbiReviewed-by Atish Patra <[email protected]>
Applied this patch on riscv/opensbi repo
Regards,
Anup