Skip to contentSkip to conversation

lib: sbi_illegal_insn: Fix FENCE.TSO emulation infinite trap loop

PATCH New Rahul Pathak 4 participants 4 messages Aug 12, 2022 – Aug 22, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi_illegal_insn: Fix FENCE.TSO emulation infinite trap loop

In case of missing "FENCE.TSO" instruction implementation, opensbi can emulate the "FENCE.TSO" with "FENCE RW,RW", but mepc was not incremented to continue from the next instruction causing infinite trap.

Fixes cb8271c8 ("lib: sbi_illegal_insn: Add emulation for fence.tso")
---
 lib/sbi/sbi_illegal_insn.c | 1 +
 1 file changed, 1 insertion(+)
lib/sbi/sbi_illegal_insn.c +1 -0
index 84c04f8..53e9320 100644
@@ -39,6 +39,7 @@ static int misc_mem_opcode_insn(ulong insn, struct sbi_trap_regs *regs)
 	/* Errata workaround: emulate `fence.tso` as `fence rw, rw`. */
 	if ((insn & INSN_MASK_FENCE_TSO) == INSN_MATCH_FENCE_TSO) {
 		smp_mb();
+		regs->mepc += 4;
 		return 0;
 	}
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 lib: sbi_illegal_insn: Fix FENCE.TSO emulation infinite trap loop

? 2022-08-12???? 19:24 +0530?Rahul Pathak???

Quoted 8 lines

In case of missing "FENCE.TSO" instruction implementation, opensbi can emulate the "FENCE.TSO" with "FENCE RW,RW", but mepc was not incremented to continue from the next instruction causing infinite trap.

Fixes cb8271c8 ("lib: sbi_illegal_insn: Add emulation for fence.tso")

Look good to me.

Quoted 20 lines

---
?lib/sbi/sbi_illegal_insn.c | 1 +
?1 file changed, 1 insertion(+)

lib/sbi/sbi_illegal_insn.c +0 -0
index 84c04f8..53e9320 100644
@@ -39,6 +39,7 @@ static int misc_mem_opcode_insn(ulong insn, struct sbi_trap_regs *regs)

????????/* Errata workaround: emulate fence.tso as fence rw, rw. */ ????????if ((insn & INSN_MASK_FENCE_TSO) == INSN_MATCH_FENCE_TSO) { ????????????????smp_mb();
+???????????????regs->mepc += 4;
????????????????return 0;
????????}
?

Signature · 1 line
2.34.1
#2 lore raw

PATCH 1/1 lib: sbi_illegal_insn: Fix FENCE.TSO emulation infinite trap loop

In reply to Rahul Pathak
Quoted 8 lines · Rahul Pathak

In case of missing "FENCE.TSO" instruction implementation, opensbi can emulate the "FENCE.TSO" with "FENCE RW,RW", but mepc was not incremented to continue from the next instruction causing infinite trap.

Fixes cb8271c8 ("lib: sbi_illegal_insn: Add emulation for fence.tso")

Thanks for catching this!

Applied
#3 lore raw

PATCH 1/1 lib: sbi_illegal_insn: Fix FENCE.TSO emulation infinite trap loop

In reply to Rahul Pathak
Quoted 9 lines · Rahul Pathak

In case of missing "FENCE.TSO" instruction implementation, opensbi can emulate the "FENCE.TSO" with "FENCE RW,RW", but mepc was not incremented to continue from the next instruction causing infinite trap.

Fixes cb8271c8 ("lib: sbi_illegal_insn: Add emulation for fence.tso")

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 19 lines
---
 lib/sbi/sbi_illegal_insn.c | 1 +
 1 file changed, 1 insertion(+)
lib/sbi/sbi_illegal_insn.c +1 -1
index 84c04f8..53e9320 100644
@@ -39,6 +39,7 @@ static int misc_mem_opcode_insn(ulong insn, struct sbi_trap_regs *regs)
        /* Errata workaround: emulate `fence.tso` as `fence rw, rw`. */
        if ((insn & INSN_MASK_FENCE_TSO) == INSN_MATCH_FENCE_TSO) {
                smp_mb();
+               regs->mepc += 4;
                return 0;
        }
 
--

2.34.1