Ping review/Sashiko

Let's not miss the great "Gitlab fixes" train coming up in the next PR :)


Thanks,
Daniel

On 11/12/2026 5:06 PM, Daniel Henrique Barboza wrote:
Add MSTATUS_MPELP in the write mask inside write_mstatush().

Fixes: 4923f672e3d7 ("target/riscv: Introduce elp state and enabling controls for 
zicfilp")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4220
Signed-off-by: Daniel Henrique Barboza <[email protected]>
---
  target/riscv/tcg/csr.c                  |  5 +++
  tests/tcg/riscv32/system/meson.build    |  7 +++++
  tests/tcg/riscv32/test-mstatush-mpelp.S | 42 +++++++++++++++++++++++++
  3 files changed, 54 insertions(+)
  create mode 100644 tests/tcg/riscv32/test-mstatush-mpelp.S

diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c
index af444e3e6f..e73455d021 100644
--- a/target/riscv/tcg/csr.c
+++ b/target/riscv/tcg/csr.c
@@ -2155,6 +2155,11 @@ static RISCVException write_mstatush(CPURISCVState *env, 
int csrno,
      uint64_t valh = (uint64_t)val << 32;
      uint64_t mask = riscv_has_ext(env, RVH) ? MSTATUS_MPV | MSTATUS_GVA : 0;
+ /* If cfi lp extension is available, then apply cfi lp mask */
+    if (env_archcpu(env)->cfg.ext_zicfilp) {
+        mask |= MSTATUS_MPELP;
+    }
+
      if (riscv_cpu_cfg(env)->ext_smdbltrp) {
          mask |= MSTATUS_MDT;
          if ((valh & MSTATUS_MDT) != 0) {
diff --git a/tests/tcg/riscv32/system/meson.build 
b/tests/tcg/riscv32/system/meson.build
index 117ae6fbce..415a1c212d 100644
--- a/tests/tcg/riscv32/system/meson.build
+++ b/tests/tcg/riscv32/system/meson.build
@@ -22,6 +22,13 @@ tests += {
    },
  }
+tests += {
+  'test-mstatush-mpelp.S': {
+    'cflags': cflags,
+    'qemu_args': ['-cpu', 'max', qemu_args],
+  },
+}
+
  if 'qemu-system-riscv32' in emulators
    tcg_tests += {
      'riscv32-softmmu': {
diff --git a/tests/tcg/riscv32/test-mstatush-mpelp.S 
b/tests/tcg/riscv32/test-mstatush-mpelp.S
new file mode 100644
index 0000000000..f70b4dfc32
--- /dev/null
+++ b/tests/tcg/riscv32/test-mstatush-mpelp.S
@@ -0,0 +1,42 @@
+/*
+ * Test that mstatush.MPELP is writable (Gitlab 4220).
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#define MSTATUSH_MPELP 0x200
+
+.option norvc
+       .text
+       .global _start
+
+_start:
+       lla     t0, trap
+       csrw    mtvec, t0
+
+       csrr    s0, mstatush
+       li      t0, MSTATUSH_MPELP
+       or      t1, s0, t0
+       csrw    mstatush, t1
+
+       csrr    s0, mstatush
+       and     t1, s0, t0
+       bne     t0, t1, _fail
+
+       j       _pass
+
+trap:
+       j       _fail
+
+_pass:
+       li      t0, 0x100000
+       li      t1, 0x5555      /* FINISHER_PASS */
+       sw      t1, 0(t0)
+       j       .
+
+_fail:
+       li      t0, 0x100000
+       li      t1, 0x13333     /* status = FINISHER_FAIL, code = 1 */
+       sw      t1, 0(t0)
+       j       .


Reply via email to