target/riscv: flh/fsh and cm.push/cm.pop/cm.popret/cm.popretz do not apply pointer masking

Host environment

  • Operating system: AlmaLinux 9.7, Linux 5.14.0-611.45.1.el9_7.x86_64
  • Architecture: x86_64
  • QEMU flavor: qemu-system-riscv64
  • QEMU version: 11.1.3, and master 6bf90d4f (v11.2.0-rc1) built from source
  • QEMU command line:
    qemu-system-riscv64 -nographic -semihosting -icount shift=1 -machine virt,aia=aplic-imsic,aia-guests=7 -cpu max,smpmpmt=false,pmu-mask=0xfffffff8,smdbltrp=true,ssdbltrp=true -bios pm_flh_fsh-rv64.elf

Emulated/Virtualized environment

  • Bare metal: a self-checking M-mode test program (attached).

Description of problem

With pointer masking enabled, flh and fsh use the untransformed address: through a pointer with a tag in bits 63:57 they raise a load/store access fault, while lw, flw/fsw and fld/fsd through the same pointer work. The Zcmp stack instructions cm.push, cm.pop and cm.popret do the same with a tagged sp (cm.popretz shares their code and was not run). Spec, zpm.adoc:67, norm:pm_apply_explicit: "When pointer masking is enabled, the ignore transformation will be applied to every explicit memory access (e.g., loads/stores, atomics operations, and floating point loads/stores)".

pm_flh_fsh: S-mode, satp Bare, menvcfg.PMM = 10 (PMLEN 7), pointer = buf | (0x2A << 57)
                                            expected   observed
lw, flw/fsw, fld/fsd through the pointer    no trap    no trap
flh through the pointer                     no trap    cause 5, xtval 0x5400000080008e90
fsh through the pointer                     no trap    cause 7

pm_zcmp_push_pop: M-mode, mseccfg.PMM = 10, sp = stack | (0x55 << 57)
sd/ld through the pointer                   no trap    no trap
cm.push {ra}, -16                           no trap    cause 7, nothing stored, sp unchanged
cm.pop {ra}, 16                             no trap    cause 5
cm.popret {ra}, 16                          no trap    cause 5

Likely cause: trans_flh()/trans_fsh() in target/riscv/tcg/insn_trans/trans_rvzfh.c.inc and gen_pop()/trans_cm_push() in trans_rvzce.c.inc form the address without get_address(), which applies the mask.

Related: #4758 (the same defect for sspush/sspopchk)

Sail, Spike and Whisper give the expected result for flh/fsh; the Zcmp test was run on QEMU only.

Steps to reproduce

  1. Unpack the attached tarball: tar xzf 2026-11-24-qemu-pointer-masking-flh-fsh-zcmp.tar.gz && cd 2026-11-24-qemu-pointer-masking-flh-fsh-zcmp
  2. ./run.sh /path/to/qemu/bin (prebuilt ELFs; source and build notes included). The Zcmp ELF needs a CPU with Zcmp, which -cpu max does not enable; run.sh passes the options.
  3. It prints one PASS or FAIL line per ELF, with the failing checks. Expected: PASS for each of the 2 ELFs. Observed on 11.1.3 and master 6bf90d4f: all fail, for example:
    FAIL pm_flh_fsh-rv64.elf
        SA-MISMATCH: (1) flh through the tagged pointer: no trap: xcause (-1 none) expect=0xffffffffffffffff got=0x0000000000000005
        SA-MISMATCH: (1) flh trapped: xtval (record; the unmasked pointer shows no masking was applied) expect=0x0000000000000000 got=0x5400000080008e90
        SA-MISMATCH: (1) flh value expect=0x0000000000003344 got=0x0000000000000000

Additional information

2026-11-24-qemu-pointer-masking-flh-fsh-zcmp.tar.gz

Found by an AI-assisted review of QEMU against the RISC-V specifications; reproduced on both versions above.