Skip to contentSkip to conversation

target/hexagon: fix packet execution and fault handling

PATCH Superseded Marco Liebel 3 participants 28 messages Nov 17 Arm/Amlogic Meson SoC support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover target/hexagon: fix packet execution and fault handling

Marco Liebel (14):
target/hexagon: read the old predicate value through C4 target/hexagon: allow writes to V85 USR coprocessor fields target/hexagon: suppress LR writes from a losing call target/hexagon: reject HMX operands outside VTCM target/hexagon: commit coprocessor results before context changes target/hexagon: distinguish packet-page instruction TLB misses target/hexagon: bound packet lookahead to the current page target/hexagon: report the faulting memory slot target/hexagon: retain both scalar packet fault addresses target/hexagon: preserve inactive BADVA registers target/hexagon: probe scalar packet memory in slot priority order target/hexagon: check packet alignment before TLB probes target/hexagon: validate both stores before packet commit target/hexagon: probe VMEMU upper transactions before lower ones

 target/hexagon/cpu.c                 |  39 +++++++--
 target/hexagon/cpu.h                 |  12 +++
 target/hexagon/gen_tcg_func_table.py |   6 ++
 target/hexagon/gen_tcg_funcs.py      |  41 +++++++++
 target/hexagon/genptr.c              |  30 ++++++-
 target/hexagon/genptr.h              |   3 +
 target/hexagon/helper.h              |   8 +-
 target/hexagon/hex_common.py         |  22 +++++
 target/hexagon/op_helper.c           | 119 +++++++++++++++++++++++++--
 target/hexagon/reg_fields_def.h.inc  |   2 +
 target/hexagon/translate.c           |  75 +++++++++++++++--
 target/hexagon/translate.h           |  12 ++-
 tests/tcg/hexagon/meson.build        |   2 +
 tests/tcg/hexagon/packet_user.c      |  82 ++++++++++++++++++
 14 files changed, 426 insertions(+), 27 deletions(-)
 create mode 100644 tests/tcg/hexagon/packet_user.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/14 target/hexagon: read the old predicate value through C4

Track C4 reads as reads of all four predicates. This prevents the packet short circuit from exposing a predicate result to an old-value control register read.

---
 target/hexagon/translate.h      |  6 +++++-
 tests/tcg/hexagon/meson.build   |  1 +
 tests/tcg/hexagon/packet_user.c | 38 +++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/hexagon/packet_user.c
target/hexagon/translate.h +5 -1
index bc3b49ab06..c988c85f33 100644
@@ -248,7 +248,11 @@ static inline void ctx_log_reg_write_pair(DisasContext *ctx, int rnum,
 
 static inline void ctx_log_reg_read(DisasContext *ctx, int rnum)
 {
-    if (test_bit(rnum, ctx->regs_written)) {
+    if (rnum == HEX_REG_P3_0_ALIASED) {
+        for (int i = 0; i < NUM_PREGS; i++) {
+            ctx_log_pred_read(ctx, i);
+        }
+    } else if (test_bit(rnum, ctx->regs_written)) {
         ctx->read_after_write = true;
     }
 }
tests/tcg/hexagon/meson.build +1 -0
index 70f6475656..b3635be3fc 100644
@@ -96,6 +96,7 @@ tests += {
   'misc.c': {'cflags': [cflags, '-mv71', '-O2']},
   'multiple-writes.c': {'cflags': [cflags, '-mhvx']},
   'overflow.c': {'cflags': cflags, 'exe_name': 'hex-overflow'},
+  'packet_user.c': {'cflags': [cflags, '-O2']},
   'preg_alias.c': {'cflags': cflags},
   'dual_stores.c': {'cflags': cflags},
   'framekey.c': {'cflags': cflags},
tests/tcg/hexagon/packet_user.c new file +38 -0
new file mode 100644
index 0000000000..acc77202ef
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+
+static int err;
+
+#include "hex_test.h"
+
+static void test_predicate_read(void)
+{
+    unsigned old, new;
+
+    asm volatile(
+        "r0 = #0x12\n"
+        "p3:0 = r0\n"
+        "{\n"
+        "    p0 = cmp.eq(r0,r0)\n"
+        "    %[old] = p3:0\n"
+        "}\n"
+        "%[new] = p3:0\n"
+        : [old] "=r"(old), [new] "=r"(new)
+        : : "r0", "p0", "p1", "p2", "p3"
+    );
+    /* Packet reads old C4, then commits P0. */
+    check32(old, 0x12);
+    check32(new, 0xff);
+}
+
+int main(void)
+{
+    test_predicate_read();
+    puts(err ? "FAIL" : "PASS");
+    return err != 0;
+}
Signature · 1 line
2.43.0
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] target/hexagon: read the old predicate value through C4

Quoted 4 lines · Marco Liebel

Track C4 reads as reads of all four predicates. This prevents the packet short circuit from exposing a predicate result to an old-value control register read.

Quoted 8 lines
---
 target/hexagon/translate.h      |  6 +++++-
 tests/tcg/hexagon/meson.build   |  1 +
 tests/tcg/hexagon/packet_user.c | 38 +++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/hexagon/packet_user.c
Reviewed-by on v1 1/14
#3 lore raw

Re: [PATCH 01/14] target/hexagon: read the old predicate value through C4

In reply to Marco Liebel
Quoted 11 lines · Marco Liebel

Track C4 reads as reads of all four predicates. This prevents the packet short circuit from exposing a predicate result to an old-value control register read.

---
  target/hexagon/translate.h      |  6 +++++-
  tests/tcg/hexagon/meson.build   |  1 +
  tests/tcg/hexagon/packet_user.c | 38 +++++++++++++++++++++++++++++++++
  3 files changed, 44 insertions(+), 1 deletion(-)

create mode 100644 tests/tcg/hexagon/packet_user.c

#4 lore raw

PATCH 2/14 target/hexagon: allow writes to V85 USR coprocessor fields

In reply to Marco Liebel

NPC and FPCOPROC are writable on V85. Remove them from the immutable mask for that revision, without changing older CPU models.

---
 target/hexagon/genptr.c             |  6 ++++++
 target/hexagon/reg_fields_def.h.inc |  2 ++
 tests/tcg/hexagon/meson.build       |  3 ++-
 tests/tcg/hexagon/packet_user.c     | 18 ++++++++++++++++++
 4 files changed, 28 insertions(+), 1 deletion(-)
target/hexagon/genptr.c +6 -0
index 52615628e3..d226cc4ebb 100644
@@ -562,6 +562,12 @@ static inline void gen_write_ctrl_reg(DisasContext *ctx, int reg_num,
             /* USR.FPSAT is reserved before v79 */
             reg_mask &= ~fGET_REG_FIELD_MASK(USR_FPSAT);
         }
+        if (reg_num == HEX_REG_USR &&
+            ctx->hex_def->hex_version >= HEX_VER_V85) {
+            /* V85 permits writes to NPC and FPCOPROC. */
+            reg_mask &= ~(fGET_REG_FIELD_MASK(USR_NPC) |
+                          fGET_REG_FIELD_MASK(USR_FPCOPROC));
+        }
         gen_masked_reg_write(val, hex_gpr[reg_num], reg_mask);
         tcg_gen_mov_tl(get_result_gpr(ctx, reg_num), val);
         if (reg_num == HEX_REG_QEMU_PKT_CNT) {
target/hexagon/reg_fields_def.h.inc +2 -0
index 32dbb2da30..4c0bd4674a 100644
@@ -29,10 +29,12 @@ DEF_REG_FIELD(USR_FPDBZF,         2, 1)
 DEF_REG_FIELD(USR_FPOVFF,         3, 1)
 DEF_REG_FIELD(USR_FPUNFF,         4, 1)
 DEF_REG_FIELD(USR_FPINPF,         5, 1)
+DEF_REG_FIELD(USR_NPC,            6, 1)
 
 DEF_REG_FIELD(USR_LPCFG,          8, 2)
 
 DEF_REG_FIELD(USR_FPDAZ,         17, 1)
+DEF_REG_FIELD(USR_FPCOPROC,      20, 2)
 
 DEF_REG_FIELD(USR_FPRND,         22, 2)
 DEF_REG_FIELD(USR_FPSAT,         24, 1)
tests/tcg/hexagon/meson.build +2 -1
index b3635be3fc..cb2e7e68b2 100644
@@ -96,7 +96,8 @@ tests += {
   'misc.c': {'cflags': [cflags, '-mv71', '-O2']},
   'multiple-writes.c': {'cflags': [cflags, '-mhvx']},
   'overflow.c': {'cflags': cflags, 'exe_name': 'hex-overflow'},
-  'packet_user.c': {'cflags': [cflags, '-O2']},
+  'packet_user.c': {'cflags': [cflags, '-O2'],
+                    'qemu_args': ['-cpu', 'v85']},
   'preg_alias.c': {'cflags': cflags},
   'dual_stores.c': {'cflags': cflags},
   'framekey.c': {'cflags': cflags},
tests/tcg/hexagon/packet_user.c +18 -0
index acc77202ef..1343a0287a 100644
@@ -30,9 +30,27 @@ static void test_predicate_read(void)
     check32(new, 0xff);
 }
 
+static void test_usr_mask(void)
+{
+    unsigned old, value;
+
+    asm volatile(
+        "%[old] = usr\n"
+        "r0 = #-1\n"
+        "usr = r0\n"
+        "%[value] = usr\n"
+        "usr = %[old]\n"
+        : [old] "=&r"(old), [value] "=&r"(value)
+        : : "r0"
+    );
+    /* V85 USR writable bits. */
+    check32(value, 0x3fffff7f);
+}
+
 int main(void)
 {
     test_predicate_read();
+    test_usr_mask();
     puts(err ? "FAIL" : "PASS");
     return err != 0;
 }
Signature · 1 line
2.43.0
Reviewed-by on v1 2/14
#5 lore raw

Re: [PATCH 02/14] target/hexagon: allow writes to V85 USR coprocessor fields

Quoted 11 lines · Marco Liebel

NPC and FPCOPROC are writable on V85. Remove them from the immutable mask for that revision, without changing older CPU models.

---
 target/hexagon/genptr.c             |  6 ++++++
 target/hexagon/reg_fields_def.h.inc |  2 ++
 tests/tcg/hexagon/meson.build       |  3 ++-
 tests/tcg/hexagon/packet_user.c     | 18 ++++++++++++++++++
 4 files changed, 28 insertions(+), 1 deletion(-)
Reviewed-by on v1 2/14
#6 lore raw

Re: [PATCH 02/14] target/hexagon: allow writes to V85 USR coprocessor fields

In reply to Marco Liebel
Quoted 10 lines · Marco Liebel

NPC and FPCOPROC are writable on V85. Remove them from the immutable mask for that revision, without changing older CPU models.

---
  target/hexagon/genptr.c             |  6 ++++++
  target/hexagon/reg_fields_def.h.inc |  2 ++
  tests/tcg/hexagon/meson.build       |  3 ++-
  tests/tcg/hexagon/packet_user.c     | 18 ++++++++++++++++++
  4 files changed, 28 insertions(+), 1 deletion(-)
#7 lore raw

PATCH 3/14 target/hexagon: suppress LR writes from a losing call

In reply to Marco Liebel

A call after a taken branch must not update LR. Guard direct and indirect calls with the packet branch state, and preserve LR when a multi-branch packet uses deferred register commit.

---
 target/hexagon/genptr.c         | 14 +++++++++++---
 target/hexagon/translate.c      |  4 ++++
 tests/tcg/hexagon/packet_user.c | 26 ++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)
target/hexagon/genptr.c +11 -3
index d226cc4ebb..954dea6622 100644
@@ -1058,27 +1058,35 @@ static void gen_jumpr(DisasContext *ctx, TCGv new_pc)
 static void gen_call(DisasContext *ctx, int pc_off)
 {
     TCGv lr = get_result_gpr(ctx, HEX_REG_LR);
+    TCGLabel *skip = gen_new_label();
+    if (ctx->pkt.pkt_has_multi_cof) {
+        tcg_gen_brcondi_tl(TCG_COND_NE, ctx->branch_taken, 0, skip);
+    }
     tcg_gen_movi_tl(lr, ctx->next_PC);
     gen_write_new_pc_pcrel(ctx, pc_off, TCG_COND_ALWAYS, NULL);
+    gen_set_label(skip);
 }
 
 static void gen_callr(DisasContext *ctx, TCGv new_pc)
 {
     TCGv lr = get_result_gpr(ctx, HEX_REG_LR);
+    TCGLabel *skip = gen_new_label();
 
     new_pc = gen_unalias_gpr_src(new_pc, lr);
+    if (ctx->pkt.pkt_has_multi_cof) {
+        tcg_gen_brcondi_tl(TCG_COND_NE, ctx->branch_taken, 0, skip);
+    }
     tcg_gen_movi_tl(lr, ctx->next_PC);
     gen_write_new_pc_addr(ctx, new_pc, TCG_COND_ALWAYS, NULL);
+    gen_set_label(skip);
 }
 
 static void gen_cond_call(DisasContext *ctx, TCGv pred,
                           TCGCond cond, int pc_off)
 {
-    TCGv lr = get_result_gpr(ctx, HEX_REG_LR);
     TCGLabel *skip = gen_new_label();
-    gen_write_new_pc_pcrel(ctx, pc_off, cond, pred);
     tcg_gen_brcondi_tl(cond, pred, 1, skip);
-    tcg_gen_movi_tl(lr, ctx->next_PC);
+    gen_call(ctx, pc_off);
     gen_set_label(skip);
 }
 
target/hexagon/translate.c +4 -0
index ec1d79e31f..10ed73590c 100644
@@ -495,6 +495,10 @@ static void mark_implicit_reg_write(DisasContext *ctx, int attrib, int rnum)
     if (GET_ATTRIB(opcode, attrib)) {
         bool is_predicated = GET_ATTRIB(opcode, A_CONDEXEC);
 
+        if (rnum == HEX_REG_LR && ctx->pkt.pkt_has_multi_cof) {
+            is_predicated = true;
+        }
+
         /* LC0/LC1 is conditionally written by endloop instructions */
         if ((rnum == HEX_REG_LC0 || rnum == HEX_REG_LC1) &&
             (opcode == J2_endloop0 ||
tests/tcg/hexagon/packet_user.c +26 -0
index 1343a0287a..4b23a02a79 100644
@@ -47,10 +47,36 @@ static void test_usr_mask(void)
     check32(value, 0x3fffff7f);
 }
 
+static void test_call_priority(void)
+{
+    unsigned lr;
+
+    asm volatile(
+        "r12 = r31\n"
+        "r31 = ##0x12345678\n"
+        "r0 = #0\n"
+        "p0 = cmp.eq(r0,r0)\n"
+        "{\n"
+        "    if (p0) jump 1f\n"
+        "    call 2f\n"
+        "}\n"
+        "2:\n"
+        "r31 = #0\n"
+        "1:\n"
+        "%[lr] = r31\n"
+        "r31 = r12\n"
+        : [lr] "=&r"(lr)
+        : : "r0", "r12", "r31", "p0"
+    );
+    /* Losing call preserves LR. */
+    check32(lr, 0x12345678);
+}
+
 int main(void)
 {
     test_predicate_read();
     test_usr_mask();
+    test_call_priority();
     puts(err ? "FAIL" : "PASS");
     return err != 0;
 }
Signature · 1 line
2.43.0
Reviewed-by on v1 3/14
#8 lore raw

Re: [PATCH 03/14] target/hexagon: suppress LR writes from a losing call

Quoted 10 lines · Marco Liebel

A call after a taken branch must not update LR. Guard direct and indirect calls with the packet branch state, and preserve LR when a multi-branch packet uses deferred register commit.

---
  target/hexagon/genptr.c         | 14 +++++++++++---
  target/hexagon/translate.c      |  4 ++++
  tests/tcg/hexagon/packet_user.c | 26 ++++++++++++++++++++++++++
  3 files changed, 41 insertions(+), 3 deletions(-)
Quoted 100 lines
target/hexagon/genptr.c +11 -3
index d226cc4ebb..954dea6622 100644
@@ -1058,27 +1058,35 @@ static void gen_jumpr(DisasContext *ctx, TCGv new_pc)
  static void gen_call(DisasContext *ctx, int pc_off)
  {
      TCGv lr = get_result_gpr(ctx, HEX_REG_LR);
+    TCGLabel *skip = gen_new_label();
+    if (ctx->pkt.pkt_has_multi_cof) {
+        tcg_gen_brcondi_tl(TCG_COND_NE, ctx->branch_taken, 0, skip);
+    }
      tcg_gen_movi_tl(lr, ctx->next_PC);
      gen_write_new_pc_pcrel(ctx, pc_off, TCG_COND_ALWAYS, NULL);
+    gen_set_label(skip);
  }
 
  static void gen_callr(DisasContext *ctx, TCGv new_pc)
  {
      TCGv lr = get_result_gpr(ctx, HEX_REG_LR);
+    TCGLabel *skip = gen_new_label();
 
      new_pc = gen_unalias_gpr_src(new_pc, lr);
+    if (ctx->pkt.pkt_has_multi_cof) {
+        tcg_gen_brcondi_tl(TCG_COND_NE, ctx->branch_taken, 0, skip);
+    }
      tcg_gen_movi_tl(lr, ctx->next_PC);
      gen_write_new_pc_addr(ctx, new_pc, TCG_COND_ALWAYS, NULL);
+    gen_set_label(skip);
  }
 
  static void gen_cond_call(DisasContext *ctx, TCGv pred,
                            TCGCond cond, int pc_off)
  {
-    TCGv lr = get_result_gpr(ctx, HEX_REG_LR);
      TCGLabel *skip = gen_new_label();
-    gen_write_new_pc_pcrel(ctx, pc_off, cond, pred);
      tcg_gen_brcondi_tl(cond, pred, 1, skip);
-    tcg_gen_movi_tl(lr, ctx->next_PC);
+    gen_call(ctx, pc_off);
      gen_set_label(skip);
  }
 
target/hexagon/translate.c +4 -0
index ec1d79e31f..10ed73590c 100644
@@ -495,6 +495,10 @@ static void mark_implicit_reg_write(DisasContext *ctx, int attrib, int rnum)
      if (GET_ATTRIB(opcode, attrib)) {
          bool is_predicated = GET_ATTRIB(opcode, A_CONDEXEC);
 
+        if (rnum == HEX_REG_LR && ctx->pkt.pkt_has_multi_cof) {
+            is_predicated = true;
+        }
+
          /* LC0/LC1 is conditionally written by endloop instructions */
          if ((rnum == HEX_REG_LC0 || rnum == HEX_REG_LC1) &&
              (opcode == J2_endloop0 ||
tests/tcg/hexagon/packet_user.c +26 -0
index 1343a0287a..4b23a02a79 100644
@@ -47,10 +47,36 @@ static void test_usr_mask(void)
      check32(value, 0x3fffff7f);
  }
 
+static void test_call_priority(void)
+{
+    unsigned lr;
+
+    asm volatile(
+        "r12 = r31\n"
+        "r31 = ##0x12345678\n"
+        "r0 = #0\n"
+        "p0 = cmp.eq(r0,r0)\n"
+        "{\n"
+        "    if (p0) jump 1f\n"
+        "    call 2f\n"
+        "}\n"
+        "2:\n"
+        "r31 = #0\n"
+        "1:\n"
+        "%[lr] = r31\n"
+        "r31 = r12\n"
+        : [lr] "=&r"(lr)
+        : : "r0", "r12", "r31", "p0"
+    );
+    /* Losing call preserves LR. */
+    check32(lr, 0x12345678);
+}
+
  int main(void)
  {
      test_predicate_read();
      test_usr_mask();
+    test_call_priority();
      puts(err ? "FAIL" : "PASS");
      return err != 0;
  }
#9 lore raw

PATCH 4/14 target/hexagon: reject HMX operands outside VTCM

In reply to Marco Liebel

Check activation and weight addresses against the machine VTCM range before executing packet instructions. An invalid operand raises the precise coprocessor VMEM address error and prevents packet commit. HMX arithmetic remains unimplemented.

---
 target/hexagon/helper.h    |  3 +++
 target/hexagon/op_helper.c | 19 +++++++++++++++++++
 target/hexagon/translate.c | 11 +++++++++++
 3 files changed, 33 insertions(+)
target/hexagon/helper.h +3 -0
index 292ca8eb7c..eddde9ab34 100644
@@ -22,6 +22,9 @@ DEF_HELPER_FLAGS_3(raise_exception, TCG_CALL_NO_RETURN, noreturn, env, i32, i32)
 DEF_HELPER_2(commit_store, void, env, int)
 DEF_HELPER_3(gather_store, void, env, i32, int)
 DEF_HELPER_1(commit_hvx_stores, void, env)
+#ifndef CONFIG_USER_ONLY
+DEF_HELPER_3(hmx_check_address, void, env, i32, i32)
+#endif
 DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32)
 DEF_HELPER_FLAGS_1(fbrev, TCG_CALL_NO_RWG_SE, i32, i32)
 DEF_HELPER_4(sfrecipa, i64, env, f32, f32, i32)
target/hexagon/op_helper.c +19 -0
index 71b27ef07f..8ed9aff7ee 100644
@@ -52,6 +52,25 @@
 #include "hw/intc/hex-l2vic.h"
 #include "hex_interrupts.h"
 #include "hexswi.h"
+#include "system/physmem.h"
+#endif
+
+#ifndef CONFIG_USER_ONLY
+void HELPER(hmx_check_address)(CPUHexagonState *env, uint32_t va, uint32_t pc)
+{
+    HexagonCPU *cpu = env_archcpu(env);
+    uint32_t config[2];
+    uint64_t base, size;
+
+    physical_memory_read(cpu->globalregs->config_table_addr + 0x38,
+                         config, sizeof(config));
+    base = (uint64_t)le32_to_cpu(config[0]) << 16;
+    size = (uint64_t)le32_to_cpu(config[1]) << 10;
+    if (va < base || va - base >= size) {
+        env->cause_code = 0x26; /* Coprocessor VMEM address error */
+        do_raise_exception(env, HEX_EVENT_PRECISE, pc, GETPC());
+    }
+}
 #endif
 
 #ifdef CONFIG_USER_ONLY
target/hexagon/translate.c +11 -0
index 10ed73590c..de5baf9f6e 100644
@@ -946,6 +946,17 @@ static void gen_start_packet(DisasContext *ctx)
         gen_precise_exception(HEX_CAUSE_NO_COPROC2_ENABLE, ctx->pkt.pc);
         ctx->hmx_check_emitted = true;
     }
+    if (ctx->pkt.pkt_has_hmx) {
+        for (i = 0; i < ctx->pkt.num_insns; i++) {
+            Insn *insn = &ctx->pkt.insn[i];
+            if (GET_ATTRIB(insn->opcode, A_HMX) &&
+                (GET_ATTRIB(insn->opcode, A_PAIR_1OF2) ||
+                 GET_ATTRIB(insn->opcode, A_PAIR_2OF2))) {
+                gen_helper_hmx_check_address(tcg_env,
+                    hex_gpr[insn->regno[0]], tcg_constant_i32(ctx->pkt.pc));
+            }
+        }
+    }
 #endif
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 4/14
#10 lore raw

Re: [PATCH 04/14] target/hexagon: reject HMX operands outside VTCM

Quoted 5 lines · Marco Liebel

Check activation and weight addresses against the machine VTCM range before executing packet instructions. An invalid operand raises the precise coprocessor VMEM address error and prevents packet commit. HMX arithmetic remains unimplemented.

Quoted 7 lines
---
 target/hexagon/helper.h    |  3 +++
 target/hexagon/op_helper.c | 19 +++++++++++++++++++
 target/hexagon/translate.c | 11 +++++++++++
 3 files changed, 33 insertions(+)
#11 lore raw

Re: [PATCH 04/14] target/hexagon: reject HMX operands outside VTCM

In reply to Marco Liebel
Quoted 38 lines · Marco Liebel

Check activation and weight addresses against the machine VTCM range before executing packet instructions. An invalid operand raises the precise coprocessor VMEM address error and prevents packet commit. HMX arithmetic remains unimplemented.

---
  target/hexagon/helper.h    |  3 +++
  target/hexagon/op_helper.c | 19 +++++++++++++++++++
  target/hexagon/translate.c | 11 +++++++++++
  3 files changed, 33 insertions(+)
target/hexagon/helper.h +3 -0
index 292ca8eb7c..eddde9ab34 100644
@@ -22,6 +22,9 @@ DEF_HELPER_FLAGS_3(raise_exception, TCG_CALL_NO_RETURN, noreturn, env, i32, i32)
  DEF_HELPER_2(commit_store, void, env, int)
  DEF_HELPER_3(gather_store, void, env, i32, int)
  DEF_HELPER_1(commit_hvx_stores, void, env)
+#ifndef CONFIG_USER_ONLY
+DEF_HELPER_3(hmx_check_address, void, env, i32, i32)
+#endif
  DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32)
  DEF_HELPER_FLAGS_1(fbrev, TCG_CALL_NO_RWG_SE, i32, i32)
  DEF_HELPER_4(sfrecipa, i64, env, f32, f32, i32)
target/hexagon/op_helper.c +4 -0
index 71b27ef07f..8ed9aff7ee 100644
@@ -52,6 +52,25 @@
  #include "hw/intc/hex-l2vic.h"
  #include "hex_interrupts.h"
  #include "hexswi.h"
+#include "system/physmem.h"
+#endif
+
+#ifndef CONFIG_USER_ONLY

target/hexagon/op_helper.c line 68

Quoted 10 lines
target/hexagon/op_helper.c +10 -0
+void HELPER(hmx_check_address)(CPUHexagonState *env, uint32_t va, uint32_t pc)
+{
+    HexagonCPU *cpu = env_archcpu(env);
+    uint32_t config[2];
+    uint64_t base, size;
+
+    physical_memory_read(cpu->globalregs->config_table_addr + 0x38,
+                         config, sizeof(config));
+    base = (uint64_t)le32_to_cpu(config[0]) << 16;
+    size = (uint64_t)le32_to_cpu(config[1]) << 10;

If you give these cfgtable values as properties to the vCPUs, then maybe this whole thing can be in TCG instead of a helper?

target/hexagon/op_helper.c line 70

Quoted 2 lines
target/hexagon/op_helper.c +2 -0
+    if (va < base || va - base >= size) {
+        env->cause_code = 0x26; /* Coprocessor VMEM address error */

I think this is HEX_CAUSE_COPROC_LDST.

If not, please add this as a new HEX_CAUSE to target/hexagon/cpu_bits.h.

Quoted 28 lines
target/hexagon/op_helper.c +3 -0
+        do_raise_exception(env, HEX_EVENT_PRECISE, pc, GETPC());
+    }
+}
  #endif
 
  #ifdef CONFIG_USER_ONLY
target/hexagon/translate.c +11 -0
index 10ed73590c..de5baf9f6e 100644
@@ -946,6 +946,17 @@ static void gen_start_packet(DisasContext *ctx)
          gen_precise_exception(HEX_CAUSE_NO_COPROC2_ENABLE, ctx->pkt.pc);
          ctx->hmx_check_emitted = true;
      }
+    if (ctx->pkt.pkt_has_hmx) {
+        for (i = 0; i < ctx->pkt.num_insns; i++) {
+            Insn *insn = &ctx->pkt.insn[i];
+            if (GET_ATTRIB(insn->opcode, A_HMX) &&
+                (GET_ATTRIB(insn->opcode, A_PAIR_1OF2) ||
+                 GET_ATTRIB(insn->opcode, A_PAIR_2OF2))) {
+                gen_helper_hmx_check_address(tcg_env,
+                    hex_gpr[insn->regno[0]], tcg_constant_i32(ctx->pkt.pc));
+            }
+        }
+    }
  #endif
  }
 
#12 lore raw

PATCH 5/14 target/hexagon: commit coprocessor results before context changes

In reply to Marco Liebel

A CCR write can detach the HLX context. Commit packet results to the old context before applying system register writes, so clearing XE3 does not abort the emulator.

---
 target/hexagon/translate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target/hexagon/translate.c +4 -1
index de5baf9f6e..590d50fc16 100644
@@ -1469,7 +1469,6 @@ static void gen_commit_packet(DisasContext *ctx)
     gen_reg_writes(ctx);
 #ifndef CONFIG_USER_ONLY
     gen_greg_writes(ctx);
-    gen_sreg_writes(ctx);
 #endif
     gen_pred_writes(ctx);
     if (ctx->pkt.pkt_has_hvx) {
@@ -1481,6 +1480,10 @@ static void gen_commit_packet(DisasContext *ctx)
     if (ctx->pkt.pkt_has_hmx) {
         gen_commit_hmx(ctx);
     }
+#ifndef CONFIG_USER_ONLY
+    /* Context changes must follow writes to the packet's old context. */
+    gen_sreg_writes(ctx);
+#endif
     update_exec_counters(ctx);
 
     if (ctx->pkt.vhist_insn != NULL) {
Signature · 1 line
2.43.0
Reviewed-by on v1 5/14
#13 lore raw

Re: [PATCH 05/14] target/hexagon: commit coprocessor results before context changes

Quoted 9 lines · Marco Liebel

A CCR write can detach the HLX context. Commit packet results to the old context before applying system register writes, so clearing XE3 does not abort the emulator.

---
 target/hexagon/translate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
#14 lore raw

PATCH 6/14 target/hexagon: distinguish packet-page instruction TLB misses

In reply to Marco Liebel

A page-aligned fault address does not imply a straddling packet. Compare its page with the packet PC page to select cause 0x60 or 0x61.

---
 target/hexagon/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/hexagon/cpu.c +2 -1
index 3575b31d19..2f3545e0a9 100644
@@ -784,7 +784,8 @@ static void raise_tlbmiss_exception(CPUState *cs, uint32_t VA, int slot,
     switch (access_type) {
     case MMU_INST_FETCH:
         cs->exception_index = HEX_EVENT_TLB_MISS_X;
-        if ((VA & ~TARGET_PAGE_MASK) == 0) {
+        if ((VA & TARGET_PAGE_MASK) !=
+            (env->gpr[HEX_REG_PC] & TARGET_PAGE_MASK)) {
             env->cause_code = HEX_CAUSE_TLBMISSX_CAUSE_NEXTPAGE;
         } else {
             env->cause_code = HEX_CAUSE_TLBMISSX_CAUSE_NORMAL;
Signature · 1 line
2.43.0
Reviewed-by on v1 6/14
#15 lore raw

Re: [PATCH 06/14] target/hexagon: distinguish packet-page instruction TLB misses

Quoted 8 lines · Marco Liebel

A page-aligned fault address does not imply a straddling packet. Compare its page with the packet PC page to select cause 0x60 or 0x61.

---
 target/hexagon/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by on v1 6/14
#16 lore raw

Re: [PATCH 06/14] target/hexagon: distinguish packet-page instruction TLB misses

In reply to Marco Liebel
Quoted 7 lines · Marco Liebel

A page-aligned fault address does not imply a straddling packet. Compare its page with the packet PC page to select cause 0x60 or 0x61.

---
  target/hexagon/cpu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
#17 lore raw

PATCH 7/14 target/hexagon: bound packet lookahead to the current page

In reply to Marco Liebel

Do not fetch an unmapped page while deciding where to end a TB. This lets complete packets retire before a straddling packet faults, and preserves the correct packet restart address.

---
 target/hexagon/translate.c | 5 +++++
 1 file changed, 5 insertions(+)
target/hexagon/translate.c +5 -0
index 590d50fc16..a1cb9da134 100644
@@ -1638,6 +1638,11 @@ static bool pkt_crosses_page(CPUHexagonState *env, DisasContext *ctx)
     int nwords;
 
     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
+        /* Look ahead only on this page; a fault must not discard this TB. */
+        if (ctx->base.pc_next + nwords * sizeof(uint32_t) - page_start >=
+            TARGET_PAGE_SIZE) {
+            return true;
+        }
         uint32_t word = translator_ldl_end(env, &ctx->base,
                                            ctx->base.pc_next
                                            + nwords * sizeof(uint32_t),
Signature · 1 line
2.43.0
Reviewed-by on v1 7/14
#18 lore raw

Re: [PATCH 07/14] target/hexagon: bound packet lookahead to the current page

Quoted 9 lines · Marco Liebel

Do not fetch an unmapped page while deciding where to end a TB. This lets complete packets retire before a straddling packet faults, and preserves the correct packet restart address.

---
 target/hexagon/translate.c | 5 +++++
 1 file changed, 5 insertions(+)
#19 lore raw

PATCH 8/14 target/hexagon: report the faulting memory slot

In reply to Marco Liebel

Track the slot during memory execution and store probes. Use it for TLB and alignment faults so a slot 1 fault selects BADVA1 and BVS.

---
 target/hexagon/cpu.c       |  4 ++--
 target/hexagon/cpu.h       |  2 ++
 target/hexagon/op_helper.c |  6 ++++++
 target/hexagon/translate.c | 18 ++++++++++++++++++
 4 files changed, 28 insertions(+), 2 deletions(-)
target/hexagon/cpu.c +2 -2
index 2f3545e0a9..f8a37c82b2 100644
@@ -834,7 +834,7 @@ static bool hexagon_tlb_fill(CPUState *cs, vaddr address, int size,
                              uintptr_t retaddr)
 {
     CPUHexagonState *env = cpu_env(cs);
-    int slot = 0;
+    int slot = access_type == MMU_INST_FETCH ? 0 : env->mem_slot;
     hwaddr phys;
     int prot = 0;
     uint64_t page_size = 0;
@@ -916,7 +916,7 @@ void hexagon_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
 {
     CPUHexagonState *env = cpu_env(cs);
 
-    raise_misaligned_exception(cs, addr, 0, access_type);
+    raise_misaligned_exception(cs, addr, env->mem_slot, access_type);
     do_raise_exception(env, cs->exception_index, env->gpr[HEX_REG_PC],
                        retaddr);
 }
target/hexagon/cpu.h +2 -0
index 5739254f1f..6f63b69c74 100644
@@ -165,6 +165,8 @@ typedef struct CPUArchState {
 #ifndef CONFIG_USER_ONLY
     /* Some system registers are per thread and some are global. */
     uint32_t t_sreg[NUM_SREGS];
+    /* Slot of the memory operation currently being executed or probed. */
+    uint32_t mem_slot;
 
     uint32_t greg[NUM_GREGS];
 
target/hexagon/op_helper.c +6 -0
index 8ed9aff7ee..22f05e7de4 100644
@@ -460,6 +460,9 @@ static void probe_store(CPUHexagonState *env, int slot, int mmu_idx,
                         bool is_predicated, uintptr_t retaddr)
 {
     if (!is_predicated || !(env->slot_cancelled & (1 << slot))) {
+#ifndef CONFIG_USER_ONLY
+        env->mem_slot = slot;
+#endif
         uint32_t width = env->mem_log_stores[slot].width;
         target_ulong va = env->mem_log_stores[slot].va;
         probe_write(env, va, width, mmu_idx, retaddr);
@@ -474,6 +477,9 @@ void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va,
                                int size, int mmu_idx)
 {
     uintptr_t retaddr = GETPC();
+#ifndef CONFIG_USER_ONLY
+    env->mem_slot = 0;
+#endif
     probe_read(env, va, size, mmu_idx, retaddr);
 }
 
target/hexagon/translate.c +18 -0
index a1cb9da134..60de40b528 100644
@@ -1006,6 +1006,13 @@ static void gen_insn(DisasContext *ctx)
 {
     uint16_t opcode = ctx->insn->opcode;
 
+#ifndef CONFIG_USER_ONLY
+    if (GET_ATTRIB(opcode, A_LOAD) || GET_ATTRIB(opcode, A_STORE)) {
+        tcg_gen_st_i32(tcg_constant_i32(ctx->insn->slot), tcg_env,
+                       offsetof(CPUHexagonState, mem_slot));
+    }
+#endif
+
     if (GET_ATTRIB(opcode, A_RELEASE) ||
         GET_ATTRIB(opcode, A_CVI_SCATTER_RELEASE)) {
         tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
@@ -1162,6 +1169,10 @@ void process_store(DisasContext *ctx, int slot_num)
     }
     {
         TCGv address = tcg_temp_new();
+#ifndef CONFIG_USER_ONLY
+        tcg_gen_st_i32(tcg_constant_i32(slot_num), tcg_env,
+                       offsetof(CPUHexagonState, mem_slot));
+#endif
         tcg_gen_mov_tl(address, hex_store_addr[slot_num]);
 
         /*
@@ -1208,6 +1219,13 @@ void process_store(DisasContext *ctx, int slot_num)
     if (is_predicated) {
         gen_set_label(label_end);
     }
+#ifndef CONFIG_USER_ONLY
+    /* An early mem_noshuf store is followed by the slot 0 load. */
+    if (ctx->pre_commit) {
+        tcg_gen_st_i32(tcg_constant_i32(ctx->insn->slot), tcg_env,
+                       offsetof(CPUHexagonState, mem_slot));
+    }
+#endif
 }
 
 static void process_store_log(DisasContext *ctx)
Signature · 1 line
2.43.0
#20 lore raw

PATCH 9/14 target/hexagon: retain both scalar packet fault addresses

In reply to Marco Liebel

Generate address-only code from scalar memory semantics. Record both active slots before memory execution, without loads, stores, or pointer updates. Use the recorded addresses and validity bits on a data fault.

---
 target/hexagon/cpu.c                 | 16 +++++++++++
 target/hexagon/cpu.h                 |  4 +++
 target/hexagon/gen_tcg_func_table.py |  6 ++++
 target/hexagon/gen_tcg_funcs.py      | 41 ++++++++++++++++++++++++++++
 target/hexagon/genptr.h              |  3 ++
 target/hexagon/helper.h              |  1 +
 target/hexagon/hex_common.py         | 22 +++++++++++++++
 target/hexagon/op_helper.c           | 10 +++++++
 target/hexagon/translate.c           | 15 ++++++++++
 target/hexagon/translate.h           |  1 +
 10 files changed, 119 insertions(+)
target/hexagon/cpu.c +16 -0
index f8a37c82b2..af86dec7dd 100644
@@ -757,6 +757,22 @@ static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot,
 {
     env->t_sreg[HEX_SREG_BADVA] = VA;
 
+    if (access_type != MMU_INST_FETCH && env->mem_access_valid) {
+        uint32_t valid = env->mem_access_valid | (1U << slot);
+        for (int i = 0; i < 2; i++) {
+            if (valid & (1U << i)) {
+                env->t_sreg[HEX_SREG_BADVA0 + i] =
+                    i == slot ? VA : env->mem_access_va[i];
+            } else {
+                env->t_sreg[HEX_SREG_BADVA0 + i] = INVALID_BADVA;
+            }
+        }
+        SET_SSR_FIELD(env, SSR_V0, valid & 1);
+        SET_SSR_FIELD(env, SSR_V1, (valid >> 1) & 1);
+        SET_SSR_FIELD(env, SSR_BVS, slot);
+        return;
+    }
+
     if (access_type == MMU_INST_FETCH || slot == 0) {
         env->t_sreg[HEX_SREG_BADVA0] = VA;
         env->t_sreg[HEX_SREG_BADVA1] = INVALID_BADVA;
target/hexagon/cpu.h +4 -0
index 6f63b69c74..092462cb6c 100644
@@ -167,6 +167,10 @@ typedef struct CPUArchState {
     uint32_t t_sreg[NUM_SREGS];
     /* Slot of the memory operation currently being executed or probed. */
     uint32_t mem_slot;
+    uint32_t mem_access_valid;
+    uint32_t mem_access_va[2];
+    uint32_t mem_access_size[2];
+    uint32_t mem_access_store[2];
 
     uint32_t greg[NUM_GREGS];
 
target/hexagon/gen_tcg_func_table.py +6 -0
index ba56ede568..3ec136d6f1 100755
@@ -22,6 +22,12 @@ def main():
             f.write(f"    [{tag}] = generate_{tag},\n")
 
         f.write("};\n\n")
+        f.write("#ifndef CONFIG_USER_ONLY\n")
+        f.write("const SemanticInsn opcode_address[XX_LAST_OPCODE] = {\n")
+        for tag in hex_common.tags:
+            if not hex_common.tag_ignore(tag) and hex_common.packet_memory_info(tag):
+                f.write(f"    [{tag}] = address_{tag},\n")
+        f.write("};\n#endif\n\n")
         f.write("#endif    /* HEXAGON_FUNC_TABLE_H */\n")
 
 
target/hexagon/gen_tcg_funcs.py +41 -0

52 lines not on this page · raw message

target/hexagon/genptr.h +3 -0
index 270375251f..d203fed587 100644
@@ -23,6 +23,9 @@
 #include "translate.h"
 
 extern const SemanticInsn opcode_genptr[];
+#ifndef CONFIG_USER_ONLY
+extern const SemanticInsn opcode_address[];
+#endif
 
 void gen_store32(TCGv vaddr, TCGv src, uint32_t width, uint32_t slot);
 void gen_store1(TCGv_env cpu_env, TCGv vaddr, TCGv src, uint32_t slot);
target/hexagon/helper.h +1 -0
index eddde9ab34..ccd55e385d 100644
@@ -24,6 +24,7 @@ DEF_HELPER_3(gather_store, void, env, i32, int)
 DEF_HELPER_1(commit_hvx_stores, void, env)
 #ifndef CONFIG_USER_ONLY
 DEF_HELPER_3(hmx_check_address, void, env, i32, i32)
+DEF_HELPER_5(log_mem_address, void, env, i32, i32, i32, i32)
 #endif
 DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32)
 DEF_HELPER_FLAGS_1(fbrev, TCG_CALL_NO_RWG_SE, i32, i32)
target/hexagon/hex_common.py +22 -0
index f85f063f52..6d335e9423 100755
@@ -299,6 +299,28 @@ def need_pkt_has_multi_cof(tag):
     return False
 
 
+def packet_memory_info(tag):
+    """Return a side-effect-free scalar address expression, if available."""
+    attrs = attribdict[tag]
+    if not ("A_LOAD" in attrs or "A_STORE" in attrs):
+        return None
+    if any(a in attrs for a in ("A_CVI", "A_HVX", "A_HLX", "A_HMX")):
+        return None
+    sem = semdict[tag]
+    ea = re.search(r"fEA_(?:RI|RRs|IRs|IMM|REG|BREVR)\([^;]+\)", sem)
+    if not ea:
+        return None
+    # A locked store is conditional on the reservation, not a predicate.
+    if "fSTORE_LOCKED" in sem:
+        return None
+    width = next((n for n in (1, 2, 4, 8)
+                  if f"A_MEMSIZE_{n}B" in attrs), None)
+    if width is None:
+        return None
+    pred = re.search(r"fLSB(OLD|NEW)(NOT)?\((P\w+)\)", sem)
+    return ea.group(0), pred, width
+
+
 def need_pkt_need_commit(tag):
     return 'A_IMPLICIT_WRITES_USR' in attribdict[tag]
 
target/hexagon/op_helper.c +10 -0
index 22f05e7de4..af7e9c3de4 100644
@@ -56,6 +56,16 @@
 #endif
 
 #ifndef CONFIG_USER_ONLY
+void HELPER(log_mem_address)(CPUHexagonState *env, uint32_t va,
+                             uint32_t slot, uint32_t size, uint32_t store)
+{
+    assert(slot < 2);
+    env->mem_access_valid |= 1U << slot;
+    env->mem_access_va[slot] = va;
+    env->mem_access_size[slot] = size;
+    env->mem_access_store[slot] = store;
+}
+
 void HELPER(hmx_check_address)(CPUHexagonState *env, uint32_t va, uint32_t pc)
 {
     HexagonCPU *cpu = env_archcpu(env);
target/hexagon/translate.c +15 -0
index 60de40b528..137fe60ca8 100644
@@ -800,7 +800,10 @@ static void gen_start_packet(DisasContext *ctx)
      * gen phase, so clear it again.
      */
     bitmap_zero(ctx->pregs_written, NUM_PREGS);
+    ctx->mem_addresses_generated = false;
 #ifndef CONFIG_USER_ONLY
+    tcg_gen_st_i32(tcg_constant_i32(0), tcg_env,
+                   offsetof(CPUHexagonState, mem_access_valid));
     for (i = 0; i < HEX_SREG_GLB_START; i++) {
         ctx->t_sreg_new_value[i] = NULL;
     }
@@ -1008,6 +1011,18 @@ static void gen_insn(DisasContext *ctx)
 
 #ifndef CONFIG_USER_ONLY
     if (GET_ATTRIB(opcode, A_LOAD) || GET_ATTRIB(opcode, A_STORE)) {
+        if (!ctx->mem_addresses_generated) {
+            Insn *saved = ctx->insn;
+            for (int i = 0; i < ctx->pkt.num_insns; i++) {
+                Insn *in = &ctx->pkt.insn[i];
+                if (opcode_address[in->opcode]) {
+                    ctx->insn = in;
+                    opcode_address[in->opcode](ctx);
+                }
+            }
+            ctx->insn = saved;
+            ctx->mem_addresses_generated = true;
+        }
         tcg_gen_st_i32(tcg_constant_i32(ctx->insn->slot), tcg_env,
                        offsetof(CPUHexagonState, mem_slot));
     }
target/hexagon/translate.h +1 -0
index c988c85f33..b4df21b70a 100644
@@ -88,6 +88,7 @@ typedef struct DisasContext {
     DECLARE_BITMAP(insn_qregs_read, NUM_QREGS);
     bool pre_commit;
     bool need_commit;
+    bool mem_addresses_generated;
     TCGCond branch_cond;
     target_ulong branch_dest;
     bool is_tight_loop;
Signature · 1 line
2.43.0
#21 lore raw

PATCH 10/14 target/hexagon: preserve inactive BADVA registers

In reply to Marco Liebel

Clear the validity bit without overwriting the inactive slot address. Fault handlers can retain BADVA values across exceptions.

---
 target/hexagon/cpu.c | 6 ------
 1 file changed, 6 deletions(-)
target/hexagon/cpu.c +0 -6
index af86dec7dd..77fd8156ed 100644
@@ -750,8 +750,6 @@ static bool hexagon_cpu_translate_for_debug(CPUState *cs, vaddr addr,
 }
 
 
-#define INVALID_BADVA 0xbadabada
-
 static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot,
                            MMUAccessType access_type)
 {
@@ -763,8 +761,6 @@ static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot,
             if (valid & (1U << i)) {
                 env->t_sreg[HEX_SREG_BADVA0 + i] =
                     i == slot ? VA : env->mem_access_va[i];
-            } else {
-                env->t_sreg[HEX_SREG_BADVA0 + i] = INVALID_BADVA;
             }
         }
         SET_SSR_FIELD(env, SSR_V0, valid & 1);
@@ -775,12 +771,10 @@ static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot,
 
     if (access_type == MMU_INST_FETCH || slot == 0) {
         env->t_sreg[HEX_SREG_BADVA0] = VA;
-        env->t_sreg[HEX_SREG_BADVA1] = INVALID_BADVA;
         SET_SSR_FIELD(env, SSR_V0, 1);
         SET_SSR_FIELD(env, SSR_V1, 0);
         SET_SSR_FIELD(env, SSR_BVS, 0);
     } else if (slot == 1) {
-        env->t_sreg[HEX_SREG_BADVA0] = INVALID_BADVA;
         env->t_sreg[HEX_SREG_BADVA1] = VA;
         SET_SSR_FIELD(env, SSR_V0, 0);
         SET_SSR_FIELD(env, SSR_V1, 1);
Signature · 1 line
2.43.0
#22 lore raw

PATCH 11/14 target/hexagon: probe scalar packet memory in slot priority order

In reply to Marco Liebel

Probe slot 1 before slot 0 without committing either access. A slot 1 store miss must win over a slot 0 load miss in a mem_noshuf packet.

---
 target/hexagon/helper.h    |  1 +
 target/hexagon/op_helper.c | 18 ++++++++++++++++++
 target/hexagon/translate.c |  2 ++
 3 files changed, 21 insertions(+)
target/hexagon/helper.h +1 -0
index ccd55e385d..32d71d84b5 100644
@@ -25,6 +25,7 @@ DEF_HELPER_1(commit_hvx_stores, void, env)
 #ifndef CONFIG_USER_ONLY
 DEF_HELPER_3(hmx_check_address, void, env, i32, i32)
 DEF_HELPER_5(log_mem_address, void, env, i32, i32, i32, i32)
+DEF_HELPER_2(probe_packet_mem, void, env, i32)
 #endif
 DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32)
 DEF_HELPER_FLAGS_1(fbrev, TCG_CALL_NO_RWG_SE, i32, i32)
target/hexagon/op_helper.c +18 -0
index af7e9c3de4..0814a32fa3 100644
@@ -66,6 +66,24 @@ void HELPER(log_mem_address)(CPUHexagonState *env, uint32_t va,
     env->mem_access_store[slot] = store;
 }
 
+void HELPER(probe_packet_mem)(CPUHexagonState *env, uint32_t mmu_idx)
+{
+    uintptr_t ra = GETPC();
+
+    for (int slot = 1; slot >= 0; slot--) {
+        if (env->mem_access_valid & (1U << slot)) {
+            env->mem_slot = slot;
+            if (env->mem_access_store[slot]) {
+                probe_write(env, env->mem_access_va[slot],
+                            env->mem_access_size[slot], mmu_idx, ra);
+            } else {
+                probe_read(env, env->mem_access_va[slot],
+                           env->mem_access_size[slot], mmu_idx, ra);
+            }
+        }
+    }
+}
+
 void HELPER(hmx_check_address)(CPUHexagonState *env, uint32_t va, uint32_t pc)
 {
     HexagonCPU *cpu = env_archcpu(env);
target/hexagon/translate.c +2 -0
index 137fe60ca8..130e1be8ed 100644
@@ -1021,6 +1021,8 @@ static void gen_insn(DisasContext *ctx)
                 }
             }
             ctx->insn = saved;
+            gen_helper_probe_packet_mem(tcg_env,
+                                        tcg_constant_i32(ctx->mem_idx));
             ctx->mem_addresses_generated = true;
         }
         tcg_gen_st_i32(tcg_constant_i32(ctx->insn->slot), tcg_env,
Signature · 1 line
2.43.0
#23 lore raw

Re: [PATCH 11/14] target/hexagon: probe scalar packet memory in slot priority order

Quoted 56 lines · Marco Liebel

Probe slot 1 before slot 0 without committing either access. A slot 1 store miss must win over a slot 0 load miss in a mem_noshuf packet.

---
  target/hexagon/helper.h    |  1 +
  target/hexagon/op_helper.c | 18 ++++++++++++++++++
  target/hexagon/translate.c |  2 ++
  3 files changed, 21 insertions(+)
target/hexagon/helper.h +1 -0
index ccd55e385d..32d71d84b5 100644
@@ -25,6 +25,7 @@ DEF_HELPER_1(commit_hvx_stores, void, env)
  #ifndef CONFIG_USER_ONLY
  DEF_HELPER_3(hmx_check_address, void, env, i32, i32)
  DEF_HELPER_5(log_mem_address, void, env, i32, i32, i32, i32)
+DEF_HELPER_2(probe_packet_mem, void, env, i32)
  #endif
  DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32)
  DEF_HELPER_FLAGS_1(fbrev, TCG_CALL_NO_RWG_SE, i32, i32)
target/hexagon/op_helper.c +18 -0
index af7e9c3de4..0814a32fa3 100644
@@ -66,6 +66,24 @@ void HELPER(log_mem_address)(CPUHexagonState *env, uint32_t va,
      env->mem_access_store[slot] = store;
  }
 
+void HELPER(probe_packet_mem)(CPUHexagonState *env, uint32_t mmu_idx)
+{
+    uintptr_t ra = GETPC();
+
+    for (int slot = 1; slot >= 0; slot--) {
+        if (env->mem_access_valid & (1U << slot)) {
+            env->mem_slot = slot;
+            if (env->mem_access_store[slot]) {
+                probe_write(env, env->mem_access_va[slot],
+                            env->mem_access_size[slot], mmu_idx, ra);
+            } else {
+                probe_read(env, env->mem_access_va[slot],
+                           env->mem_access_size[slot], mmu_idx, ra);
+            }
+        }
+    }
+}
+
  void HELPER(hmx_check_address)(CPUHexagonState *env, uint32_t va, uint32_t pc)
  {
      HexagonCPU *cpu = env_archcpu(env);
target/hexagon/translate.c +0 -0
index 137fe60ca8..130e1be8ed 100644

target/hexagon/translate.c static void gen_insn(DisasContext *ctx) · line 1027

Quoted 7 lines
target/hexagon/translate.c +2 -0
@@ -1021,6 +1021,8 @@ static void gen_insn(DisasContext *ctx)
                  }
              }
              ctx->insn = saved;
+            gen_helper_probe_packet_mem(tcg_env,
+                                        tcg_constant_i32(ctx->mem_idx));
              ctx->mem_addresses_generated = true;
          }

IIUC this is an unconditional helper call for all instructions? Hopefully we can find a way to leverage what we know at translation time to mitigate the need for this call.

Quoted 1 line
target/hexagon/translate.c +0 -0
          tcg_gen_st_i32(tcg_constant_i32(ctx->insn->slot), tcg_env,
#24 lore raw

PATCH 12/14 target/hexagon: check packet alignment before TLB probes

In reply to Marco Liebel

Check active scalar addresses for alignment before translating either slot. An alignment error must not trigger a recoverable TLB miss first.

---
 target/hexagon/cpu.c       | 12 ++++++++++++
 target/hexagon/cpu.h       |  6 ++++++
 target/hexagon/op_helper.c | 10 ++++++++++
 3 files changed, 28 insertions(+)
target/hexagon/cpu.c +12 -0
index 77fd8156ed..bc8e51ee61 100644
@@ -833,6 +833,18 @@ static void raise_misaligned_exception(CPUState *cs, uint32_t VA, int slot,
     env->cause_code = excp;
 }
 
+void hexagon_check_alignment(CPUHexagonState *env, uint32_t va,
+                             unsigned size, int slot,
+                             MMUAccessType access_type, uintptr_t retaddr)
+{
+    if (va & (size - 1)) {
+        CPUState *cs = env_cpu(env);
+        raise_misaligned_exception(cs, va, slot, access_type);
+        do_raise_exception(env, cs->exception_index, env->gpr[HEX_REG_PC],
+                           retaddr);
+    }
+}
+
 static const char *access_type_names[] = { "MMU_DATA_LOAD ", "MMU_DATA_STORE",
                                            "MMU_INST_FETCH" };
 
target/hexagon/cpu.h +6 -0
index 092462cb6c..e7ecbb1d59 100644
@@ -233,6 +233,12 @@ typedef struct CPUArchState {
     HmxState *hmx_state;
 } CPUHexagonState;
 
+#ifndef CONFIG_USER_ONLY
+void hexagon_check_alignment(CPUHexagonState *env, uint32_t va,
+                             unsigned size, int slot,
+                             MMUAccessType access_type, uintptr_t retaddr);
+#endif
+
 typedef struct HexagonCPUClass {
     CPUClass parent_class;
 
target/hexagon/op_helper.c +10 -0
index 0814a32fa3..7afd13c996 100644
@@ -70,6 +70,15 @@ void HELPER(probe_packet_mem)(CPUHexagonState *env, uint32_t mmu_idx)
 {
     uintptr_t ra = GETPC();
 
+    /* Alignment errors have priority over address translation faults. */
+    for (int slot = 1; slot >= 0; slot--) {
+        if (env->mem_access_valid & (1U << slot)) {
+            hexagon_check_alignment(env, env->mem_access_va[slot],
+                                    env->mem_access_size[slot], slot,
+                                    env->mem_access_store[slot] ?
+                                    MMU_DATA_STORE : MMU_DATA_LOAD, ra);
+        }
+    }
     for (int slot = 1; slot >= 0; slot--) {
         if (env->mem_access_valid & (1U << slot)) {
             env->mem_slot = slot;
@@ -507,6 +516,7 @@ void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va,
     uintptr_t retaddr = GETPC();
 #ifndef CONFIG_USER_ONLY
     env->mem_slot = 0;
+    hexagon_check_alignment(env, va, size, 0, MMU_DATA_LOAD, retaddr);
 #endif
     probe_read(env, va, size, mmu_idx, retaddr);
 }
Signature · 1 line
2.43.0
#25 lore raw

Re: [PATCH 12/14] target/hexagon: check packet alignment before TLB probes

Quoted 57 lines · Marco Liebel

Check active scalar addresses for alignment before translating either slot. An alignment error must not trigger a recoverable TLB miss first.

---
  target/hexagon/cpu.c       | 12 ++++++++++++
  target/hexagon/cpu.h       |  6 ++++++
  target/hexagon/op_helper.c | 10 ++++++++++
  3 files changed, 28 insertions(+)
target/hexagon/cpu.c +12 -0
index 77fd8156ed..bc8e51ee61 100644
@@ -833,6 +833,18 @@ static void raise_misaligned_exception(CPUState *cs, uint32_t VA, int slot,
      env->cause_code = excp;
  }
 
+void hexagon_check_alignment(CPUHexagonState *env, uint32_t va,
+                             unsigned size, int slot,
+                             MMUAccessType access_type, uintptr_t retaddr)
+{
+    if (va & (size - 1)) {
+        CPUState *cs = env_cpu(env);
+        raise_misaligned_exception(cs, va, slot, access_type);
+        do_raise_exception(env, cs->exception_index, env->gpr[HEX_REG_PC],
+                           retaddr);
+    }
+}
+
  static const char *access_type_names[] = { "MMU_DATA_LOAD ", "MMU_DATA_STORE",
                                             "MMU_INST_FETCH" };
 
target/hexagon/cpu.h +6 -0
index 092462cb6c..e7ecbb1d59 100644
@@ -233,6 +233,12 @@ typedef struct CPUArchState {
      HmxState *hmx_state;
  } CPUHexagonState;
 
+#ifndef CONFIG_USER_ONLY
+void hexagon_check_alignment(CPUHexagonState *env, uint32_t va,
+                             unsigned size, int slot,
+                             MMUAccessType access_type, uintptr_t retaddr);
+#endif
+
  typedef struct HexagonCPUClass {
      CPUClass parent_class;
 
target/hexagon/op_helper.c +0 -0
index 0814a32fa3..7afd13c996 100644
@@ -70,6 +70,15 @@ void HELPER(probe_packet_mem)(CPUHexagonState *env, uint32_t mmu_idx)
  {
      uintptr_t ra = GETPC();

target/hexagon/op_helper.c void HELPER(probe_packet_mem)(CPUHexagonState *env, uint32_t mmu_idx) · line 81

Quoted 10 lines
target/hexagon/op_helper.c +9 -0
 
+    /* Alignment errors have priority over address translation faults. */
+    for (int slot = 1; slot >= 0; slot--) {
+        if (env->mem_access_valid & (1U << slot)) {
+            hexagon_check_alignment(env, env->mem_access_va[slot],
+                                    env->mem_access_size[slot], slot,
+                                    env->mem_access_store[slot] ?
+                                    MMU_DATA_STORE : MMU_DATA_LOAD, ra);
+        }
+    }

... and related to the prior patch -- there's already MO_ALIGN which should be able to do the heavy lifting here.

If exception precedence is the problem maybe we can move the cost of solving this correctness problem to the backend where exceptions get raised?  That would mean that we could save ourselves the significant expense here with all loads/stores to just the cases where they're unaligned.

Quoted 11 lines
target/hexagon/op_helper.c +1 -0
      for (int slot = 1; slot >= 0; slot--) {
          if (env->mem_access_valid & (1U << slot)) {
              env->mem_slot = slot;
@@ -507,6 +516,7 @@ void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va,
      uintptr_t retaddr = GETPC();
  #ifndef CONFIG_USER_ONLY
      env->mem_slot = 0;
+    hexagon_check_alignment(env, va, size, 0, MMU_DATA_LOAD, retaddr);
  #endif
      probe_read(env, va, size, mmu_idx, retaddr);
  }
#26 lore raw

PATCH 13/14 target/hexagon: validate both stores before packet commit

In reply to Marco Liebel

Check alignment in store probes and validate both logged stores before committing either one. This also covers stores without generated address preflight code.

---
 target/hexagon/helper.h    |  2 +-
 target/hexagon/op_helper.c | 26 +++++++++++++++++++++-----
 target/hexagon/translate.c | 15 ++++++++-------
 target/hexagon/translate.h |  5 +++--
 4 files changed, 33 insertions(+), 15 deletions(-)
target/hexagon/helper.h +1 -1
index 32d71d84b5..754f341faf 100644
@@ -148,7 +148,7 @@ DEF_HELPER_2(vwhist128m, void, env, s32)
 DEF_HELPER_2(vwhist128qm, void, env, s32)
 
 DEF_HELPER_4(probe_noshuf_load, void, env, i32, int, int)
-DEF_HELPER_2(probe_pkt_scalar_store_s0, void, env, int)
+DEF_HELPER_2(probe_pkt_scalar_stores, void, env, int)
 DEF_HELPER_2(probe_hvx_stores, void, env, int)
 DEF_HELPER_2(probe_pkt_scalar_hvx_stores, void, env, int)
 
target/hexagon/op_helper.c +21 -5
index 7afd13c996..95e9f8b912 100644
@@ -502,6 +502,9 @@ static void probe_store(CPUHexagonState *env, int slot, int mmu_idx,
 #endif
         uint32_t width = env->mem_log_stores[slot].width;
         target_ulong va = env->mem_log_stores[slot].va;
+#ifndef CONFIG_USER_ONLY
+        hexagon_check_alignment(env, va, width, slot, MMU_DATA_STORE, retaddr);
+#endif
         probe_write(env, va, width, mmu_idx, retaddr);
     }
 }
@@ -522,13 +525,26 @@ void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va,
 }
 
 /* Called during packet commit when there are two scalar stores */
-void HELPER(probe_pkt_scalar_store_s0)(CPUHexagonState *env, int args)
+void HELPER(probe_pkt_scalar_stores)(CPUHexagonState *env, int args)
 {
-    int mmu_idx = FIELD_EX32(args, PROBE_PKT_SCALAR_STORE_S0, MMU_IDX);
-    bool is_predicated =
-        FIELD_EX32(args, PROBE_PKT_SCALAR_STORE_S0, IS_PREDICATED);
+    int mmu_idx = FIELD_EX32(args, PROBE_PKT_SCALAR_STORES, MMU_IDX);
+    bool pred[2] = {
+        FIELD_EX32(args, PROBE_PKT_SCALAR_STORES, S0_IS_PREDICATED),
+        FIELD_EX32(args, PROBE_PKT_SCALAR_STORES, S1_IS_PREDICATED),
+    };
     uintptr_t ra = GETPC();
-    probe_store(env, 0, mmu_idx, is_predicated, ra);
+#ifndef CONFIG_USER_ONLY
+    /* Do not let an alignment fault occur after either store commits. */
+    for (int slot = 1; slot >= 0; slot--) {
+        if (!pred[slot] || !(env->slot_cancelled & (1U << slot))) {
+            hexagon_check_alignment(env, env->mem_log_stores[slot].va,
+                                    env->mem_log_stores[slot].width, slot,
+                                    MMU_DATA_STORE, ra);
+        }
+    }
+#endif
+    probe_store(env, 1, mmu_idx, pred[1], ra);
+    probe_store(env, 0, mmu_idx, pred[0], ra);
 }
 
 static void probe_hvx_stores(CPUHexagonState *env, int mmu_idx,
target/hexagon/translate.c +8 -7
index 130e1be8ed..15c4be401d 100644
@@ -1473,19 +1473,20 @@ static void gen_commit_packet(DisasContext *ctx)
                                                    tcg_constant_tl(mask));
         }
     } else if (has_store_s0 && has_store_s1) {
-        /*
-         * process_store_log will execute the slot 1 store first,
-         * so we only have to probe the store in slot 0
-         */
+        /* Validate both stores, including alignment, before commit. */
         int args = 0;
         args =
-            FIELD_DP32(args, PROBE_PKT_SCALAR_STORE_S0, MMU_IDX, ctx->mem_idx);
+            FIELD_DP32(args, PROBE_PKT_SCALAR_STORES, MMU_IDX, ctx->mem_idx);
         if (slot_is_predicated(&ctx->pkt, 0)) {
             args =
-                FIELD_DP32(args, PROBE_PKT_SCALAR_STORE_S0, IS_PREDICATED, 1);
+                FIELD_DP32(args, PROBE_PKT_SCALAR_STORES, S0_IS_PREDICATED, 1);
+        }
+        if (slot_is_predicated(&ctx->pkt, 1)) {
+            args = FIELD_DP32(args, PROBE_PKT_SCALAR_STORES,
+                              S1_IS_PREDICATED, 1);
         }
         TCGv args_tcgv = tcg_constant_tl(args);
-        gen_helper_probe_pkt_scalar_store_s0(tcg_env, args_tcgv);
+        gen_helper_probe_pkt_scalar_stores(tcg_env, args_tcgv);
     }
 
     if (ctx->hex_def->hex_version >= HEX_VER_V83) {
target/hexagon/translate.h +3 -2
index b4df21b70a..849264e83b 100644
@@ -441,8 +441,9 @@ void hex_gen_exception_end_tb(DisasContext *ctx, int cause);
 
 void process_store(DisasContext *ctx, int slot_num);
 
-FIELD(PROBE_PKT_SCALAR_STORE_S0, MMU_IDX,       0, 2)
-FIELD(PROBE_PKT_SCALAR_STORE_S0, IS_PREDICATED, 2, 1)
+FIELD(PROBE_PKT_SCALAR_STORES, MMU_IDX,           0, 2)
+FIELD(PROBE_PKT_SCALAR_STORES, S0_IS_PREDICATED,  2, 1)
+FIELD(PROBE_PKT_SCALAR_STORES, S1_IS_PREDICATED,  3, 1)
 
 FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST0,        0, 1)
 FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST1,        1, 1)
Signature · 1 line
2.43.0
#27 lore raw

PATCH 14/14 target/hexagon: probe VMEMU upper transactions before lower ones

In reply to Marco Liebel

Record both unaligned VMEMU addresses and probe the upper transaction first. Report the architectural address, not the page boundary found by a split TLB access. Preserve both validity bits on load and store faults.

---
 target/hexagon/cpu.c       |  4 +++-
 target/hexagon/genptr.c    | 10 ++++++++++
 target/hexagon/helper.h    |  1 +
 target/hexagon/op_helper.c | 30 ++++++++++++++++++++++++++++++
 4 files changed, 44 insertions(+), 1 deletion(-)
target/hexagon/cpu.c +3 -1
index bc8e51ee61..2965c92a77 100644
@@ -760,9 +760,11 @@ static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot,
         for (int i = 0; i < 2; i++) {
             if (valid & (1U << i)) {
                 env->t_sreg[HEX_SREG_BADVA0 + i] =
-                    i == slot ? VA : env->mem_access_va[i];
+                    (env->mem_access_valid & (1U << i)) ?
+                    env->mem_access_va[i] : VA;
             }
         }
+        env->t_sreg[HEX_SREG_BADVA] = env->t_sreg[HEX_SREG_BADVA0 + slot];
         SET_SSR_FIELD(env, SSR_V0, valid & 1);
         SET_SSR_FIELD(env, SSR_V1, (valid >> 1) & 1);
         SET_SSR_FIELD(env, SSR_BVS, slot);
target/hexagon/genptr.c +10 -0
index 954dea6622..d9830b230d 100644
@@ -1634,6 +1634,11 @@ static void gen_vreg_load(DisasContext *ctx, TCGv_ptr dstbase,
                           intptr_t dstoff, TCGv src, bool aligned)
 {
     TCGv_i64 tmp = tcg_temp_new_i64();
+#ifndef CONFIG_USER_ONLY
+    gen_helper_probe_hvx_mem(tcg_env, src, tcg_constant_i32(ctx->insn->slot),
+                             tcg_constant_i32(aligned), tcg_constant_i32(0),
+                             tcg_constant_i32(ctx->mem_idx));
+#endif
     if (aligned) {
         tcg_gen_andi_tl(src, src, ~((int32_t)VECTOR_SIZE_BYTE - 1));
     }
@@ -1656,6 +1661,11 @@ static void gen_vreg_store(DisasContext *ctx, TCGv EA, TCGv_ptr srcbase,
         return;
     }
 
+#ifndef CONFIG_USER_ONLY
+    gen_helper_probe_hvx_mem(tcg_env, EA, tcg_constant_i32(slot),
+                             tcg_constant_i32(aligned), tcg_constant_i32(1),
+                             tcg_constant_i32(ctx->mem_idx));
+#endif
     tcg_gen_movi_tl(hex_vstore_pending[slot], 1);
     if (aligned) {
         tcg_gen_andi_tl(hex_vstore_addr[slot], EA,
target/hexagon/helper.h +1 -0
index 754f341faf..160ab81ebc 100644
@@ -26,6 +26,7 @@ DEF_HELPER_1(commit_hvx_stores, void, env)
 DEF_HELPER_3(hmx_check_address, void, env, i32, i32)
 DEF_HELPER_5(log_mem_address, void, env, i32, i32, i32, i32)
 DEF_HELPER_2(probe_packet_mem, void, env, i32)
+DEF_HELPER_6(probe_hvx_mem, void, env, i32, i32, i32, i32, i32)
 #endif
 DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32)
 DEF_HELPER_FLAGS_1(fbrev, TCG_CALL_NO_RWG_SE, i32, i32)
target/hexagon/op_helper.c +30 -0
index 95e9f8b912..231855fdd6 100644
@@ -108,6 +108,33 @@ void HELPER(hmx_check_address)(CPUHexagonState *env, uint32_t va, uint32_t pc)
         do_raise_exception(env, HEX_EVENT_PRECISE, pc, GETPC());
     }
 }
+
+void HELPER(probe_hvx_mem)(CPUHexagonState *env, uint32_t va, uint32_t slot,
+                           uint32_t aligned, uint32_t store, uint32_t mmu_idx)
+{
+    uintptr_t ra = GETPC();
+    uint32_t base = va & ~(VECTOR_SIZE_BYTE - 1);
+
+    if (aligned) {
+        HELPER(log_mem_address)(env, base, slot, VECTOR_SIZE_BYTE, store);
+    } else {
+        /* VMEMU uses both slots; BADVA records the unaligned addresses. */
+        HELPER(log_mem_address)(env, va, 0, VECTOR_SIZE_BYTE, store);
+        HELPER(log_mem_address)(env, va + VECTOR_SIZE_BYTE, 1,
+                                VECTOR_SIZE_BYTE, store);
+    }
+    int first = aligned ? slot : 1;
+    int last = aligned ? slot : 0;
+    for (int s = first; s >= last; s--) {
+        uint32_t address = base + (aligned ? 0 : s * VECTOR_SIZE_BYTE);
+        env->mem_slot = s;
+        if (store) {
+            probe_write(env, address, VECTOR_SIZE_BYTE, mmu_idx, ra);
+        } else {
+            probe_read(env, address, VECTOR_SIZE_BYTE, mmu_idx, ra);
+        }
+    }
+}
 #endif
 
 #ifdef CONFIG_USER_ONLY
@@ -553,6 +580,9 @@ static void probe_hvx_stores(CPUHexagonState *env, int mmu_idx,
     /* Normal (possibly masked) vector store */
     for (int i = 0; i < VSTORES_MAX; i++) {
         if (env->vstore_pending[i]) {
+#ifndef CONFIG_USER_ONLY
+            env->mem_slot = i;
+#endif
             target_ulong va = env->vstore[i].va;
             int size = env->vstore[i].size;
             for (int j = 0; j < size; j++) {
Signature · 1 line
2.43.0