Skip to contentSkip to conversation

target/riscv: make mstatush.MPELP writable [GL4220]

PATCH Applied Daniel Henrique Barboza 2 participants 4 messages Nov 12 – Nov 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: make mstatush.MPELP writable [GL4220]

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

---
 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
target/riscv/tcg/csr.c +5 -0
index af444e3e6f..e73455d021 100644
@@ -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) {
tests/tcg/riscv32/system/meson.build +7 -0
index 117ae6fbce..415a1c212d 100644
@@ -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': {
tests/tcg/riscv32/test-mstatush-mpelp.S new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw

Ping review/Sashiko

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

Thanks,
Daniel

Quoted 94 lines · Daniel Henrique Barboza

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

---
  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

target/riscv/tcg/csr.c +5 -0
index af444e3e6f..e73455d021 100644
@@ -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) {
tests/tcg/riscv32/system/meson.build +7 -0
index 117ae6fbce..415a1c212d 100644
@@ -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': {
tests/tcg/riscv32/test-mstatush-mpelp.S new file +42 -0
new file mode 100644
index 0000000000..f70b4dfc32
@@ -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	.
Reviewed-by on v1 1/1
#2 lore raw
In reply to Daniel Henrique Barboza
Quoted 7 lines · Daniel Henrique Barboza

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]>

Alistair

Quoted 96 lines

---
 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

target/riscv/tcg/csr.c +0 -0
index af444e3e6f..e73455d021 100644
@@ -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) {

tests/tcg/riscv32/system/meson.build +0 -0
index 117ae6fbce..415a1c212d 100644
@@ -22,6 +22,13 @@ tests += {
    },
  }

tests/tcg/riscv32/system/meson.build +7 -0
+tests += {
+  'test-mstatush-mpelp.S': {
+    'cflags': cflags,
+    'qemu_args': ['-cpu', 'max', qemu_args],
+  },
+}
+

 if 'qemu-system-riscv32' in emulators
   tcg_tests += {
     'riscv32-softmmu': {

tests/tcg/riscv32/test-mstatush-mpelp.S new file +4 -0
new file mode 100644
index 0000000000..f70b4dfc32
@@ -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
+ */

tests/tcg/riscv32/test-mstatush-mpelp.S new file +34 -0
+
+#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

*/

tests/tcg/riscv32/test-mstatush-mpelp.S new file +2 -0
+	sw	t1, 0(t0)
+	j	.
#3 lore raw
In reply to Daniel Henrique Barboza
Quoted 7 lines · Daniel Henrique Barboza

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]>

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 96 lines

---
 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

target/riscv/tcg/csr.c +0 -0
index af444e3e6f..e73455d021 100644
@@ -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) {

tests/tcg/riscv32/system/meson.build +0 -0
index 117ae6fbce..415a1c212d 100644
@@ -22,6 +22,13 @@ tests += {
    },
  }

tests/tcg/riscv32/system/meson.build +7 -0
+tests += {
+  'test-mstatush-mpelp.S': {
+    'cflags': cflags,
+    'qemu_args': ['-cpu', 'max', qemu_args],
+  },
+}
+

 if 'qemu-system-riscv32' in emulators
   tcg_tests += {
     'riscv32-softmmu': {

tests/tcg/riscv32/test-mstatush-mpelp.S new file +4 -0
new file mode 100644
index 0000000000..f70b4dfc32
@@ -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
+ */

tests/tcg/riscv32/test-mstatush-mpelp.S new file +34 -0
+
+#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

*/

tests/tcg/riscv32/test-mstatush-mpelp.S new file +2 -0
+	sw	t1, 0(t0)
+	j	.