Skip to contentSkip to conversation

Fixes for unaligned scalar accesses

PATCH Superseded Brian Cain 4 participants 10 messages Jul 9 – Jul 14

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

cover Fixes for unaligned scalar accesses

I took some "working" programs under userspace emulation into a linux instance running on a fork with comprehensive system mode support and discovered a compiler bug causing unaligned accesses. This bug had gone undetected in userspace tests because they were not handled correctly by QEMU.

With these patches, unaligned accesses cause an exception that generates SIGBUS.

Brian Cain (4):
target/hexagon: raise SIGBUS on unaligned scalar loads target/hexagon: raise SIGBUS on unaligned scalar stores target/hexagon: raise SIGBUS on unaligned data access in sysemu tests/tcg/hexagon: add unaligned scalar test

 linux-user/hexagon/cpu_loop.c               |   5 +
 target/hexagon/cpu.c                        |  25 +++++
 target/hexagon/genptr.c                     |  10 +-
 target/hexagon/idef-parser/parser-helpers.c |   2 +-
 target/hexagon/macros.h                     |  26 +++--
 target/hexagon/op_helper.c                  |  13 ++-
 target/hexagon/translate.c                  |   6 +-
 tests/tcg/hexagon/Makefile.target           |   2 +
 tests/tcg/hexagon/unaligned_data.c          | 118 ++++++++++++++++++++
 9 files changed, 185 insertions(+), 22 deletions(-)
 create mode 100644 tests/tcg/hexagon/unaligned_data.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/4 target/hexagon: raise SIGBUS on unaligned scalar loads

hexagon-linux-user had no enforcement of alignment for scalar load exceptions, and unaligned loads silently succeeded instead of raising SIGBUS.

Add MO_ALIGN to the MEM_LOAD* macros, the locked-load and load-frame helpers in genptr.c, and the idef-parser's fLOAD.

---
 target/hexagon/genptr.c                     |  6 ++---
 target/hexagon/idef-parser/parser-helpers.c |  2 +-
 target/hexagon/macros.h                     | 26 +++++++++++++--------
 3 files changed, 20 insertions(+), 14 deletions(-)
target/hexagon/genptr.c +3 -3
index 1ebc7471409..05c9aa04467 100644
@@ -470,14 +470,14 @@ void gen_set_byte_i64(int N, TCGv_i64 result, TCGv src)
 
 static inline void gen_load_locked4u(TCGv dest, TCGv vaddr, int mem_index)
 {
-    tcg_gen_qemu_ld_tl(dest, vaddr, mem_index, MO_LE | MO_UL);
+    tcg_gen_qemu_ld_tl(dest, vaddr, mem_index, MO_LE | MO_UL | MO_ALIGN);
     tcg_gen_mov_tl(hex_llsc_addr, vaddr);
     tcg_gen_mov_tl(hex_llsc_val, dest);
 }
 
 static inline void gen_load_locked8u(TCGv_i64 dest, TCGv vaddr, int mem_index)
 {
-    tcg_gen_qemu_ld_i64(dest, vaddr, mem_index, MO_LE | MO_UQ);
+    tcg_gen_qemu_ld_i64(dest, vaddr, mem_index, MO_LE | MO_UQ | MO_ALIGN);
     tcg_gen_mov_tl(hex_llsc_addr, vaddr);
     tcg_gen_mov_i64(hex_llsc_val_i64, dest);
 }
@@ -890,7 +890,7 @@ static void gen_load_frame(DisasContext *ctx, TCGv_i64 frame, TCGv EA)
 {
     Insn *insn = ctx->insn;  /* Needed for CHECK_NOSHUF */
     CHECK_NOSHUF(EA, 8);
-    tcg_gen_qemu_ld_i64(frame, EA, ctx->mem_idx, MO_LE | MO_UQ);
+    tcg_gen_qemu_ld_i64(frame, EA, ctx->mem_idx, MO_LE | MO_UQ | MO_ALIGN);
 }
 
 /* Stack overflow check */
target/hexagon/idef-parser/parser-helpers.c +1 -1
index b942d9ea16b..49cc11fddd8 100644
@@ -1770,7 +1770,7 @@ void gen_load(Context *c, YYLTYPE *locp, HexValue *width,
     if (signedness == SIGNED) {
         OUT(c, locp, " | MO_SIGN");
     }
-    OUT(c, locp, " | MO_LE);\n");
+    OUT(c, locp, " | MO_LE | MO_ALIGN);\n");
 }
 
 void gen_store(Context *c, YYLTYPE *locp, HexValue *width, HexValue *ea,
target/hexagon/macros.h +16 -10
index 21ab8ae5bbf..b439e31974c 100644
@@ -106,37 +106,37 @@
 #define MEM_LOAD1s(DST, VA) \
     do { \
         CHECK_NOSHUF(VA, 1); \
-        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_SB); \
+        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_SB | MO_ALIGN); \
     } while (0)
 #define MEM_LOAD1u(DST, VA) \
     do { \
         CHECK_NOSHUF(VA, 1); \
-        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_UB); \
+        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_UB | MO_ALIGN); \
     } while (0)
 #define MEM_LOAD2s(DST, VA) \
     do { \
         CHECK_NOSHUF(VA, 2); \
-        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_LE | MO_SW); \
+        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_LE | MO_SW | MO_ALIGN); \
     } while (0)
 #define MEM_LOAD2u(DST, VA) \
     do { \
         CHECK_NOSHUF(VA, 2); \
-        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_LE | MO_UW); \
+        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_LE | MO_UW | MO_ALIGN); \
     } while (0)
 #define MEM_LOAD4s(DST, VA) \
     do { \
         CHECK_NOSHUF(VA, 4); \
-        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_LE | MO_SL); \
+        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_LE | MO_SL | MO_ALIGN); \
     } while (0)
 #define MEM_LOAD4u(DST, VA) \
     do { \
         CHECK_NOSHUF(VA, 4); \
-        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_LE | MO_UL); \
+        tcg_gen_qemu_ld_tl(DST, VA, ctx->mem_idx, MO_LE | MO_UL | MO_ALIGN); \
     } while (0)
 #define MEM_LOAD8u(DST, VA) \
     do { \
         CHECK_NOSHUF(VA, 8); \
-        tcg_gen_qemu_ld_i64(DST, VA, ctx->mem_idx, MO_LE | MO_UQ); \
+        tcg_gen_qemu_ld_i64(DST, VA, ctx->mem_idx, MO_LE | MO_UQ | MO_ALIGN); \
     } while (0)
 
 #define MEM_STORE1_FUNC(X) \
@@ -519,9 +519,15 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)
 #define fLOAD(NUM, SIZE, SIGN, EA, DST) MEM_LOAD##SIZE##SIGN(DST, EA)
 #else
 #define MEM_LOAD1 cpu_ldub_data_ra
-#define MEM_LOAD2 cpu_lduw_le_data_ra
-#define MEM_LOAD4 cpu_ldl_le_data_ra
-#define MEM_LOAD8 cpu_ldq_le_data_ra
+#define MEM_LOAD2(ENV, EA, RA) \
+    cpu_ldw_mmu(ENV, EA, make_memop_idx(MO_LEUW | MO_ALIGN, \
+                                        cpu_mmu_index(env_cpu(ENV), false)), RA)
+#define MEM_LOAD4(ENV, EA, RA) \
+    cpu_ldl_mmu(ENV, EA, make_memop_idx(MO_LEUL | MO_ALIGN, \
+                                        cpu_mmu_index(env_cpu(ENV), false)), RA)
+#define MEM_LOAD8(ENV, EA, RA) \
+    cpu_ldq_mmu(ENV, EA, make_memop_idx(MO_LEUQ | MO_ALIGN, \
+                                        cpu_mmu_index(env_cpu(ENV), false)), RA)
 
 #define fLOAD(NUM, SIZE, SIGN, EA, DST) \
     do { \
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/4 target/hexagon: raise SIGBUS on unaligned scalar stores

In reply to Brian Cain

hexagon-linux-user had no enforcement of alignment for scalar store exceptions, and unaligned stores silently succeeded instead of raising SIGBUS.

Stores are logged rather than committed immediately, so both commit paths need the fix.

---
 target/hexagon/genptr.c    |  4 ++--
 target/hexagon/op_helper.c | 13 ++++++++++---
 target/hexagon/translate.c |  6 +++---
 3 files changed, 15 insertions(+), 8 deletions(-)
target/hexagon/genptr.c +2 -2
index 05c9aa04467..f48a27bc09b 100644
@@ -495,7 +495,7 @@ static inline void gen_store_conditional4(DisasContext *ctx,
     zero = tcg_constant_tl(0);
     tmp = tcg_temp_new();
     tcg_gen_atomic_cmpxchg_tl(tmp, hex_llsc_addr, hex_llsc_val, src,
-                              ctx->mem_idx, MO_32);
+                              ctx->mem_idx, MO_32 | MO_ALIGN);
     tcg_gen_movcond_tl(TCG_COND_EQ, pred, tmp, hex_llsc_val,
                        one, zero);
     tcg_gen_br(done);
@@ -520,7 +520,7 @@ static inline void gen_store_conditional8(DisasContext *ctx,
     zero = tcg_constant_i64(0);
     tmp = tcg_temp_new_i64();
     tcg_gen_atomic_cmpxchg_i64(tmp, hex_llsc_addr, hex_llsc_val_i64, src,
-                               ctx->mem_idx, MO_64);
+                               ctx->mem_idx, MO_64 | MO_ALIGN);
     tcg_gen_movcond_i64(TCG_COND_EQ, tmp, tmp, hex_llsc_val_i64,
                         one, zero);
     tcg_gen_extrl_i64_i32(pred, tmp);
target/hexagon/op_helper.c +10 -3
index 125952aee59..3ce223caba3 100644
@@ -95,19 +95,26 @@ static void commit_store(CPUHexagonState *env, int slot_num, uintptr_t ra)
 {
     uint32_t width = env->mem_log_stores[slot_num].width;
     target_ulong va = env->mem_log_stores[slot_num].va;
+    MemOpIdx oi;
 
     switch (width) {
     case 1:
         cpu_stb_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
         break;
     case 2:
-        cpu_stw_le_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
+        oi = make_memop_idx(MO_LEUW | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false));
+        cpu_stw_mmu(env, va, env->mem_log_stores[slot_num].data32, oi, ra);
         break;
     case 4:
-        cpu_stl_le_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
+        oi = make_memop_idx(MO_LEUL | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false));
+        cpu_stl_mmu(env, va, env->mem_log_stores[slot_num].data32, oi, ra);
         break;
     case 8:
-        cpu_stq_le_data_ra(env, va, env->mem_log_stores[slot_num].data64, ra);
+        oi = make_memop_idx(MO_LEUQ | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false));
+        cpu_stq_mmu(env, va, env->mem_log_stores[slot_num].data64, oi, ra);
         break;
     default:
         g_assert_not_reached();
target/hexagon/translate.c +3 -3
index 77235916f4b..5d54ce8caa4 100644
@@ -896,17 +896,17 @@ void process_store(DisasContext *ctx, int slot_num)
         case 2:
             tcg_gen_qemu_st_tl(hex_store_val32[slot_num],
                                hex_store_addr[slot_num],
-                               ctx->mem_idx, MO_LE | MO_UW);
+                               ctx->mem_idx, MO_LE | MO_UW | MO_ALIGN);
             break;
         case 4:
             tcg_gen_qemu_st_tl(hex_store_val32[slot_num],
                                hex_store_addr[slot_num],
-                               ctx->mem_idx, MO_LE | MO_UL);
+                               ctx->mem_idx, MO_LE | MO_UL | MO_ALIGN);
             break;
         case 8:
             tcg_gen_qemu_st_i64(hex_store_val64[slot_num],
                                 hex_store_addr[slot_num],
-                                ctx->mem_idx, MO_LE | MO_UQ);
+                                ctx->mem_idx, MO_LE | MO_UQ | MO_ALIGN);
             break;
         default:
             {
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/4] target/hexagon: raise SIGBUS on unaligned scalar stores

Hi Brian,

Quoted 37 lines · Brian Cain

hexagon-linux-user had no enforcement of alignment for scalar store exceptions, and unaligned stores silently succeeded instead of raising SIGBUS.

Stores are logged rather than committed immediately, so both commit paths need the fix.

---
  target/hexagon/genptr.c    |  4 ++--
  target/hexagon/op_helper.c | 13 ++++++++++---
  target/hexagon/translate.c |  6 +++---
  3 files changed, 15 insertions(+), 8 deletions(-)
target/hexagon/op_helper.c +4 -2
index 125952aee59..3ce223caba3 100644
@@ -95,19 +95,26 @@ static void commit_store(CPUHexagonState *env, int slot_num, uintptr_t ra)
  {
      uint32_t width = env->mem_log_stores[slot_num].width;
      target_ulong va = env->mem_log_stores[slot_num].va;
+    MemOpIdx oi;
 
      switch (width) {
      case 1:
          cpu_stb_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
          break;
      case 2:
-        cpu_stw_le_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
+        oi = make_memop_idx(MO_LEUW | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false));
+        cpu_stw_mmu(env, va, env->mem_log_stores[slot_num].data32, oi, ra);
          break;
      case 4:
-        cpu_stl_le_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);

target/hexagon/op_helper.c static void commit_store(CPUHexagonState *env, int slot_num, uintptr_t ra) · line 118

Quoted 10 lines
target/hexagon/op_helper.c +6 -1
+        oi = make_memop_idx(MO_LEUL | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false));
+        cpu_stl_mmu(env, va, env->mem_log_stores[slot_num].data32, oi, ra);
          break;
      case 8:
-        cpu_stq_le_data_ra(env, va, env->mem_log_stores[slot_num].data64, ra);
+        oi = make_memop_idx(MO_LEUQ | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false));
+        cpu_stq_mmu(env, va, env->mem_log_stores[slot_num].data64, oi, ra);
          break;

Thanks for the API conversion :)

Consider enabling TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API in configs/targets/ (I missed that when you merged the system emulation part).

author
#4 lore raw

Re: [PATCH 2/4] target/hexagon: raise SIGBUS on unaligned scalar stores

Quoted 58 lines · Philippe Mathieu-Daudé

Hi Brian,

Quoted 45 lines · Brian Cain

hexagon-linux-user had no enforcement of alignment for scalar store exceptions, and unaligned stores silently succeeded instead of raising SIGBUS.

Stores are logged rather than committed immediately, so both commit paths need the fix.

---
  target/hexagon/genptr.c    |  4 ++--
  target/hexagon/op_helper.c | 13 ++++++++++---
  target/hexagon/translate.c |  6 +++---

  3 files changed, 15 insertions(+), 8 deletions(-)
target/hexagon/op_helper.c +1 -0
index 125952aee59..3ce223caba3 100644
@@ -95,19 +95,26 @@ static void commit_store(CPUHexagonState *env, 
 int slot_num, uintptr_t ra)
   {
       uint32_t width = env->mem_log_stores[slot_num].width;
       target_ulong va = env->mem_log_stores[slot_num].va;
+    MemOpIdx oi;
         switch (width) {

      case 1:
          cpu_stb_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra); break;
      case 2:
-        cpu_stw_le_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
+        oi = make_memop_idx(MO_LEUW | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false)); +        cpu_stw_mmu(env, va, env->mem_log_stores[slot_num].data32, oi, ra);
          break;
      case 4:
-        cpu_stl_le_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
+        oi = make_memop_idx(MO_LEUL | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false)); +        cpu_stl_mmu(env, va, env->mem_log_stores[slot_num].data32, oi, ra);
          break;

Quoted 8 lines

      case 8:
-        cpu_stq_le_data_ra(env, va, env->mem_log_stores[slot_num].data64, ra);
+        oi = make_memop_idx(MO_LEUQ | MO_ALIGN,
+                            cpu_mmu_index(env_cpu(env), false)); +        cpu_stq_mmu(env, va, env->mem_log_stores[slot_num].data64, oi, ra);
          break;

Thanks for the API conversion :)

Quoted 3 lines

Consider enabling TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API in configs/targets/ (I missed that when you merged the system emulation part).

TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API was in "target/hexagon: add build config for softmmu" (you indeed caught it ;).

-Brian

author
#5 lore raw

PATCH 3/4 target/hexagon: raise SIGBUS on unaligned data access in sysemu

In reply to Brian Cain

hexagon-softmmu had no enforcement of alignment for scalar loads and
stores: the MO_ALIGN flag added by the previous two commits triggers TLB_INVALID_MASK/alignment faults in cputlb.c, but Hexagon's TCGCPUOps did not implement do_unaligned_access, so the fault was never delivered to the guest.

Add hexagon_cpu_do_unaligned_access(), which raises HEX_CAUSE_MISALIGNED_LOAD/_STORE via the existing HEX_EVENT_PRECISE path, mirroring raise_tlbmiss_exception()/raise_perm_exception().

Also add a linux-user cpu_loop handler for these two cause codes for consistency with hexswi.c's sysemu handling, even though linux-user's own alignment check in accel/tcg/user-exec.c currently raises SIGBUS before Hexagon's cause-code machinery is reached.

---
 linux-user/hexagon/cpu_loop.c |  5 +++++
 target/hexagon/cpu.c          | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
linux-user/hexagon/cpu_loop.c +5 -0
index 0958c51fbb3..d7f73439dbc 100644
@@ -76,6 +76,11 @@ void cpu_loop(CPUHexagonState *env)
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,
                     env->gpr[HEX_REG_PC]);
             break;
+            case HEX_CAUSE_MISALIGNED_LOAD:
+            case HEX_CAUSE_MISALIGNED_STORE:
+            force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN,
+                    env->gpr[HEX_REG_PC]);
+            break;
             default:
                 EXCP_DUMP(env, "\nqemu: unhandled CPU precise exception "
                     "cause code 0x%x - aborting\n",
target/hexagon/cpu.c +25 -0
index 42d93e5da47..e2af736a99d 100644
@@ -637,6 +637,18 @@ static void raise_perm_exception(CPUState *cs, uint32_t VA, int slot,
     cs->exception_index = excp;
 }
 
+static void raise_misaligned_exception(CPUState *cs, uint32_t VA, int slot,
+                                       MMUAccessType access_type)
+{
+    CPUHexagonState *env = cpu_env(cs);
+    int32_t excp = (access_type == MMU_DATA_STORE) ?
+                   HEX_CAUSE_MISALIGNED_STORE : HEX_CAUSE_MISALIGNED_LOAD;
+
+    set_badva_regs(env, VA, slot, access_type);
+    cs->exception_index = HEX_EVENT_PRECISE;
+    env->cause_code = excp;
+}
+
 static const char *access_type_names[] = { "MMU_DATA_LOAD ", "MMU_DATA_STORE",
                                            "MMU_INST_FETCH" };
 
@@ -715,6 +727,18 @@ static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx,
     return result;
 }
 
+static G_NORETURN
+void hexagon_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
+                                     MMUAccessType access_type, int mmu_idx,
+                                     uintptr_t retaddr)
+{
+    CPUHexagonState *env = cpu_env(cs);
+
+    raise_misaligned_exception(cs, addr, 0, access_type);
+    do_raise_exception(env, cs->exception_index, env->gpr[HEX_REG_PC],
+                       retaddr);
+}
+
 #endif
 
 static const TCGCPUOps hexagon_tcg_ops = {
@@ -732,6 +756,7 @@ static const TCGCPUOps hexagon_tcg_ops = {
     .pointer_wrap = hexagon_pointer_wrap,
     .cpu_exec_reset = cpu_reset,
     .tlb_fill = hexagon_tlb_fill,
+    .do_unaligned_access = hexagon_cpu_do_unaligned_access,
     .cpu_exec_halt = hexagon_cpu_has_work,
     .do_interrupt = hexagon_cpu_do_interrupt,
 #endif /* !CONFIG_USER_ONLY */
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 3/4] target/hexagon: raise SIGBUS on unaligned data access in sysemu

Quoted 27 lines · Brian Cain

hexagon-softmmu had no enforcement of alignment for scalar loads and
stores: the MO_ALIGN flag added by the previous two commits triggers TLB_INVALID_MASK/alignment faults in cputlb.c, but Hexagon's TCGCPUOps did not implement do_unaligned_access, so the fault was never delivered to the guest.

Add hexagon_cpu_do_unaligned_access(), which raises HEX_CAUSE_MISALIGNED_LOAD/_STORE via the existing HEX_EVENT_PRECISE path, mirroring raise_tlbmiss_exception()/raise_perm_exception().

Also add a linux-user cpu_loop handler for these two cause codes for consistency with hexswi.c's sysemu handling, even though linux-user's own alignment check in accel/tcg/user-exec.c currently raises SIGBUS before Hexagon's cause-code machinery is reached.

---
  linux-user/hexagon/cpu_loop.c |  5 +++++
  target/hexagon/cpu.c          | 25 +++++++++++++++++++++++++
  2 files changed, 30 insertions(+)
linux-user/hexagon/cpu_loop.c +0 -0
index 0958c51fbb3..d7f73439dbc 100644
@@ -76,6 +76,11 @@ void cpu_loop(CPUHexagonState *env)
              force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,

linux-user/hexagon/cpu_loop.c void cpu_loop(CPUHexagonState *env) · line 86

Quoted 10 lines
linux-user/hexagon/cpu_loop.c +5 -0
                      env->gpr[HEX_REG_PC]);
              break;
+            case HEX_CAUSE_MISALIGNED_LOAD:
+            case HEX_CAUSE_MISALIGNED_STORE:
+            force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN,
+                    env->gpr[HEX_REG_PC]);
+            break;
              default:
                  EXCP_DUMP(env, "\nqemu: unhandled CPU precise exception "
                      "cause code 0x%x - aborting\n",

It would be clearer to have this hunk in a preliminary patch (more even since the $subject is about sysemu).

author
#7 lore raw

PATCH 4/4 tests/tcg/hexagon: add unaligned scalar test

In reply to Brian Cain

Add unaligned_data.c to exercise unaligned memh/memw/memd accesses and verify SIGBUS is raised and caught.

---
 tests/tcg/hexagon/Makefile.target  |   2 +
 tests/tcg/hexagon/unaligned_data.c | 118 +++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 tests/tcg/hexagon/unaligned_data.c
tests/tcg/hexagon/Makefile.target +2 -0
index 70a8ec2e7fb..a2a0ffc69b2 100644
@@ -54,6 +54,7 @@ HEX_TESTS += invalid-slots
 HEX_TESTS += invalid-encoding
 HEX_TESTS += multiple-writes
 HEX_TESTS += unaligned_pc
+HEX_TESTS += unaligned_data
 
 HEX_TESTS += test_abs
 HEX_TESTS += test_bitcnt
@@ -108,6 +109,7 @@ preg_alias: preg_alias.c hex_test.h
 read_write_overlap: read_write_overlap.c hex_test.h
 reg_mut: reg_mut.c hex_test.h
 test_pnew_jump_loads: test_pnew_jump_loads.c hex_test.h
+unaligned_data: unaligned_data.c hex_test.h
 unaligned_pc: unaligned_pc.c
 
 # Compile for v66 so that the ELF selects a v66 CPU; the test then
tests/tcg/hexagon/unaligned_data.c new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on the v1 series
#8 lore raw
In reply to Brian Cain
Quoted 7 lines · On Thu, 9 Jul 2026 16:34:32 -0700 Brian Cain <[email protected]>…

I took some "working" programs under userspace emulation into a linux instance running on a fork with comprehensive system mode support and discovered a compiler bug causing unaligned accesses. This bug had gone undetected in userspace tests because they were not handled correctly by QEMU.

Quoted 8 lines

With these patches, unaligned accesses cause an exception that generates SIGBUS.

Brian Cain (4):
target/hexagon: raise SIGBUS on unaligned scalar loads target/hexagon: raise SIGBUS on unaligned scalar stores target/hexagon: raise SIGBUS on unaligned data access in sysemu tests/tcg/hexagon: add unaligned scalar test

Reviewed-by on the v1 series
#9 lore raw
In reply to Brian Cain
Quoted 15 lines · Brian Cain

I took some "working" programs under userspace emulation into a linux instance running on a fork with comprehensive system mode support and discovered a compiler bug causing unaligned accesses. This bug had gone undetected in userspace tests because they were not handled correctly by QEMU.

With these patches, unaligned accesses cause an exception that generates SIGBUS.

Brian Cain (4):
target/hexagon: raise SIGBUS on unaligned scalar loads target/hexagon: raise SIGBUS on unaligned scalar stores target/hexagon: raise SIGBUS on unaligned data access in sysemu tests/tcg/hexagon: add unaligned scalar test

Quoted 12 lines
 linux-user/hexagon/cpu_loop.c               |   5 +
 target/hexagon/cpu.c                        |  25 +++++
 target/hexagon/genptr.c                     |  10 +-
 target/hexagon/idef-parser/parser-helpers.c |   2 +-
 target/hexagon/macros.h                     |  26 +++--
 target/hexagon/op_helper.c                  |  13 ++-
 target/hexagon/translate.c                  |   6 +-
 tests/tcg/hexagon/Makefile.target           |   2 +
 tests/tcg/hexagon/unaligned_data.c          | 118 ++++++++++++++++++++
 9 files changed, 185 insertions(+), 22 deletions(-)
 create mode 100644 tests/tcg/hexagon/unaligned_data.c