[RFC,0/2] RISC-V: Add dynamic TSO support

Message ID 20231127145603.2339644-1-christoph.muellner@vrull.eu
Headers
Series RISC-V: Add dynamic TSO support |

Message

Christoph Müllner Nov. 27, 2023, 2:56 p.m. UTC
  From: Christoph Müllner <christoph.muellner@vrull.eu>

The upcoming RISC-V Ssdtso specification introduces a bit in the senvcfg
CSR to switch the memory consistency model at run-time from RVWMO to TSO
(and back). The active consistency model can therefore be switched on a
per-hart base and managed by the kernel on a per-process/thread base.

A kernel patchset that exposes a prctl API to let user-space processes
switch their memory consistency model has been posted recently:
  https://lore.kernel.org/all/20231124072142.2786653-1-christoph.muellner@vrull.eu/T/#t
A remote branch that includes a couple of fixes for that first patchset
can be found here (note, that new fixes will be force-pushed into this branch):
  https://github.com/cmuellner/linux/tree/ssdtso

A Ssdtso patchset for QEMU has been posted:
  https://lists.nongnu.org/archive/html/qemu-devel/2023-11/msg02962.html
Additional patches to implement the prctl API for user-mode emulation
have been developed as well and can be found here (same note as before):
  https://github.com/cmuellner/qemu/tree/ssdtso

This patchset builds upon this prctl API and extends
elf_machine_matches_host() such, that it attempts to switch to TSO mode
if the ELF header has EF_RISCV_TSO set, but the machine reports
RVWMO as current consistency model.
Of course, this is an optional feature, which will fall-back to the
current behaviour (rejecting the ELF) if there is any error.

The implementation is somewhat inspired by a similar mechanism
in the MIPS code (sysdeps/mips/dl-machine-reject-phdr.h) that
switches the FP mode if necessary.

Following the same pattern, there is also branch for this patchset:
  https://github.com/cmuellner/glibc/tree/ssdtso

Christoph Müllner (2):
  RISC-V: Move TSO check to elf_machine_matches_host()
  RISC-V: Attempt to enable TSO mode for TSO binaries

 sysdeps/riscv/dl-machine.h                 | 15 +++++++++++++++
 sysdeps/unix/sysv/linux/riscv/readelflib.c |  5 ++---
 2 files changed, 17 insertions(+), 3 deletions(-)