[PATCH v4 0/4] target/riscv: Correct undefined behaviors in x-rv128

frederic.petrot@univ-grenoble-alpes.fr posted 4 patches 3 days, 11 hours ago
There is a newer version of this series
target/riscv/cpu.c                    |   1 +
target/riscv/cpu.h                    |   4 +
target/riscv/machine.c                |  12 ++-
target/riscv/tcg/cpu_helper.c         |  20 ++++-
target/riscv/tcg/csr.c                |  95 ++++++++++++++++++++----
target/riscv/tcg/csr.h                |   3 +
target/riscv/tcg/pmp.c                |  38 ++++++++++
tests/tcg/riscv64/system/meson.build  |  14 ++++
tests/tcg/riscv64/test-rv128-mcause.S | 101 ++++++++++++++++++++++++++
tests/tcg/riscv64/test-rv128-scause.S |  94 ++++++++++++++++++++++++
10 files changed, 362 insertions(+), 20 deletions(-)
create mode 100644 tests/tcg/riscv64/test-rv128-mcause.S
create mode 100644 tests/tcg/riscv64/test-rv128-scause.S
[PATCH v4 0/4] target/riscv: Correct undefined behaviors in x-rv128
Posted by frederic.petrot@univ-grenoble-alpes.fr 3 days, 11 hours ago
From: Frédéric Pétrot <frederic.petrot@univ-grenoble-alpes.fr>

Peter reported undefined behaviors in x-rv128 pmp configuration
registers accesses detected by the clang sanitizer.
This series introduces a 128-bit version of these accesses, and
corrects other out-of-bound shifts within the handling of interrupts
that were triggered afterwards.

Changes in v4:
- Change version_id in machine states as we are adding new fields,
- Add Fixes: trailers in commits
Note that Sashiko AI reports a misuse of riscv_cpu_sxl in patch 2, 
while all calls are related to the use of scause (or vscause). 

Changes in v3:
- Extract the "interrupt" bitfield in the different versions of the
  cause register in a separate field of cpu.h and build the cause
  registers value on demand,
- Add these new fields into the machine migration state,
- Check that the pmp registers used in rv128 are only those allowed,
- Add tcg tests for mcause and scause accesses.

Changes in v2:
- I messed up and directly assigned a 0 to an Int128, so v2 corrects
  that.

Frédéric Pétrot (4):
  target/riscv: fix pmp sanitize error for x-rv128
  target/riscv: fix riscv_cpu_do_interrupt sanitize error for x-rv128
  target/riscv: Update machine state
  target/riscv: [ms]cause tcg tests for x-rv128

 target/riscv/cpu.c                    |   1 +
 target/riscv/cpu.h                    |   4 +
 target/riscv/machine.c                |  12 ++-
 target/riscv/tcg/cpu_helper.c         |  20 ++++-
 target/riscv/tcg/csr.c                |  95 ++++++++++++++++++++----
 target/riscv/tcg/csr.h                |   3 +
 target/riscv/tcg/pmp.c                |  38 ++++++++++
 tests/tcg/riscv64/system/meson.build  |  14 ++++
 tests/tcg/riscv64/test-rv128-mcause.S | 101 ++++++++++++++++++++++++++
 tests/tcg/riscv64/test-rv128-scause.S |  94 ++++++++++++++++++++++++
 10 files changed, 362 insertions(+), 20 deletions(-)
 create mode 100644 tests/tcg/riscv64/test-rv128-mcause.S
 create mode 100644 tests/tcg/riscv64/test-rv128-scause.S

-- 
2.43.0


Re: [PATCH v4 0/4] target/riscv: Correct undefined behaviors in x-rv128
Posted by Peter Maydell 3 days, 11 hours ago
On Thu, 19 Nov 2026 at 16:57, <frederic.petrot@univ-grenoble-alpes.fr> wrote:
>
> From: Frédéric Pétrot <frederic.petrot@univ-grenoble-alpes.fr>
>
> Peter reported undefined behaviors in x-rv128 pmp configuration
> registers accesses detected by the clang sanitizer.
> This series introduces a 128-bit version of these accesses, and
> corrects other out-of-bound shifts within the handling of interrupts
> that were triggered afterwards.

I would really like some fix in this area for 11.2, please,
because this is I think the only place where a sanitizer
build falls over in "make check" / "make check-functional".
I don't particularly care if it's the full fix or just a
hack to avoid the immediate out of bound shift.

thanks
-- PMM