On 11/5/26 20:22, James Hilliard wrote:
Linux/MIPS enables software fixups for user-mode unaligned scalar
accesses by default through MIPS_FIXADE/TIF_FIXADE.  QEMU linux-user did
not model that ABI, so MIPS guests took fatal AdEL/AdES exceptions unless
translation was forced to use unaligned host accesses.

Key MIPS translation blocks on the linux-user unaligned policy, implement
sysmips(MIPS_FIXADE) to toggle that policy, and raise SIGBUS/BUS_ADRALN
when fixups are disabled.

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: James Hilliard <[email protected]>
---
Changes v5 -> v6:
   - Rename the TB flag from TB_FLAG_UNALIGN to TB_FLAG_MIPS_FIXADE
     to match the MIPS_FIXADE ABI policy.

Changes v2 -> v3:
   - Split MIPS_FLUSH_CACHE and MIPS_ATOMIC_SET into preparatory sysmips
     patches.  (suggested by Richard Henderson)
---
  linux-user/mips/cpu_loop.c         | 5 +++++
  linux-user/mips/target_syscall.h   | 1 +
  linux-user/mips64/target_syscall.h | 1 +
  linux-user/syscall.c               | 8 ++++++++
  target/mips/cpu.c                  | 8 ++++++--
  target/mips/cpu.h                  | 4 ++++
  target/mips/tcg/translate.c        | 6 +++++-
  7 files changed, 30 insertions(+), 3 deletions(-)


diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index f803d47763..6e827c72de 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -565,11 +565,15 @@ static int mips_cpu_mmu_index(CPUState *cs, bool ifunc)
  static TCGTBCPUState mips_get_tb_cpu_state(CPUState *cs)
  {
      CPUMIPSState *env = cpu_env(cs);
+    uint32_t flags = env->hflags & MIPS_HFLAG_TB_MASK;
+
+#ifdef CONFIG_USER_ONLY
+    flags |= TB_FLAG_MIPS_FIXADE * !cs->prctl_unalign_sigbus;

I'm not a big fan of this optimized style where you need to think
twice about what is being done. The following uses 3 lines but is
a no-brainer:

  if (!cs->prctl_unalign_sigbus) {
      flags |= TB_FLAG_MIPS_FIXADE
  }

+#endif
return (TCGTBCPUState){
          .pc = env->active_tc.PC,
-        .flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK |
-                                MIPS_HFLAG_HWRENA_ULR),
+        .flags = flags,
      };
  }


Reply via email to