Skip to contentSkip to conversation

target/riscv: prevent abrupt abortion on unassigned value write to tdata

PATCH Applied Abhigyan Kumar 2 participants 4 messages Jul 29 – Sep 3 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: prevent abrupt abortion on unassigned value write to tdata

tdata_csr_write is approachable by guest programs. In case of unassigned values written to a tdata CSR in debug mode, the switch-case falls through straight to default causing an immediate abort. The risc-v spec says:

All tdata registers follow write-any-read-legal semantics. If a debugger writes an unsupported configuration, the register will read back a value that is supported (which may simply be a disabled trigger). This means that a debugger must always read back values it writes to tdata registers, unless it already knows what is supported.

This fix correctly ensures that the WARL behaviour of tdata CSRs.

Fixes a42bd001 ("target/riscv: debug: Determine the trigger type from

tdata1.type")

---
 target/riscv/tcg/debug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/tcg/debug.c +2 -1
index 3c0fe7010..ae493235d 100644
@@ -913,7 +913,8 @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val)
                       trigger_type);
         break;
     default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_GUEST_ERROR, "trigger type: %d is unassigned\n",
+                trigger_type);
     }
 }
 
Signature · 1 line
2.55.0
author
#1 lore raw
Quoted 25 lines · Abhigyan Kumar

tdata_csr_write is approachable by guest programs. In case of unassigned values written to a tdata CSR in debug mode, the switch-case falls through straight to default causing an immediate abort. The risc-v spec says:

All tdata registers follow write-any-read-legal semantics. If a debugger writes an unsupported configuration, the register will read back a value that is supported (which may simply be a disabled trigger). This means that a debugger must always read back values it writes to tdata registers, unless it already knows what is supported.

This fix correctly ensures that the WARL behaviour of tdata CSRs.

Fixes a42bd001 ("target/riscv: debug: Determine the trigger type from

tdata1.type")

---
  target/riscv/tcg/debug.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/tcg/debug.c +0 -0
index 3c0fe7010..ae493235d 100644

target/riscv/tcg/debug.c void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val) · line 920

Quoted 9 lines
target/riscv/tcg/debug.c +2 -1
@@ -913,7 +913,8 @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val)
                        trigger_type);
          break;
      default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_GUEST_ERROR, "trigger type: %d is unassigned\n",
+                trigger_type);
      }
  }
 

Greetings. It has been over two weeks since I submitted this patch. It's my humble request to know the status of the review/acceptance for my patch. Please inform me about any required amends.

Thank you for your patience and attention.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Abhigyan Kumar
Quoted 16 lines · Abhigyan Kumar

tdata_csr_write is approachable by guest programs. In case of unassigned
values written to a tdata CSR in debug mode, the switch-case falls through straight to default causing an immediate abort. The risc-v spec
says:

    All tdata registers follow write-any-read-legal semantics. If a debugger
    writes an unsupported configuration, the register will read back a value
    that is supported (which may simply be a disabled trigger). This means
    that a debugger must always read back values it writes to tdata registers, unless it already knows what is supported.

Quoted 6 lines

This fix correctly ensures that the WARL behaviour of tdata CSRs.

Fixes a42bd001 ("target/riscv: debug: Determine the trigger type

from
tdata1.type")

Alistair

Quoted 20 lines

---
 target/riscv/tcg/debug.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/tcg/debug.c +0 -0
index 3c0fe7010..ae493235d 100644
@@ -913,7 +913,8 @@ void tdata_csr_write(CPURISCVState *env, int
 tdata_index, target_ulong val)
                        trigger_type);
          break;

     default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_GUEST_ERROR, "trigger type: %d is unassigned\n",
+                trigger_type);
     }
 }

#3 lore raw
In reply to Abhigyan Kumar
Quoted 16 lines · Abhigyan Kumar

tdata_csr_write is approachable by guest programs. In case of unassigned
values written to a tdata CSR in debug mode, the switch-case falls through straight to default causing an immediate abort. The risc-v spec
says:

    All tdata registers follow write-any-read-legal semantics. If a debugger
    writes an unsupported configuration, the register will read back a value
    that is supported (which may simply be a disabled trigger). This means
    that a debugger must always read back values it writes to tdata registers, unless it already knows what is supported.

Quoted 6 lines

This fix correctly ensures that the WARL behaviour of tdata CSRs.

Fixes a42bd001 ("target/riscv: debug: Determine the trigger type

from
tdata1.type")

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 20 lines

---
 target/riscv/tcg/debug.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/tcg/debug.c +0 -0
index 3c0fe7010..ae493235d 100644
@@ -913,7 +913,8 @@ void tdata_csr_write(CPURISCVState *env, int
 tdata_index, target_ulong val)
                        trigger_type);
          break;

     default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_GUEST_ERROR, "trigger type: %d is unassigned\n",
+                trigger_type);
     }
 }