Skip to contentSkip to conversation

hex queue

GIT PULL Applied Brian Cain 2 participants 9 messages Nov 30 – Dec 1 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

The following changes since commit 9cda597a1a3903d090e8e55e23f5b8a859da88ab:

Merge tag 'pbouvier/pr/fixes_11.2-20261127' of https://gitlab.com/p-b-o/qemu into staging (2026-11-29 13:42:36 -0800)

are available in the Git repository at:

https://github.com/qualcomm/qemu tags/pull-hex-20261130

for you to fetch changes up to 23f93333cd0a9c82f9d1e0d920a9b194426fd8d8:

hw/hexagon: honor configured RAM backends (2026-11-29 20:59:24 -0800)

----------------------------------------------------------------
hexagon: fix page-cross ELR, p0-3/c4, fp excp

----------------------------------------------------------------
Brian Cain (5):
target/hexagon: fix get_exe_mode assertion in hexagon_stop_thread target/hexagon: deliver floating point exceptions after the packet target/hexagon: report the faulting packet for stack limit exceptions target/hexagon: raise decode failures at the faulting packet hw/hexagon: honor configured RAM backends

Marco Liebel (2):
target/hexagon: read the old predicate value through C4 target/hexagon: bound packet lookahead to the current page

 target/hexagon/helper.h                   |  2 +-
 target/hexagon/translate.h                |  6 ++++-
 hw/hexagon/hex-subsys.c                   | 10 +++++---
 target/hexagon/arch.c                     |  9 ++++----
 target/hexagon/cpu_helper.c               |  1 +
 target/hexagon/genptr.c                   |  3 ++-
 target/hexagon/hexswi.c                   |  1 +
 target/hexagon/op_helper.c                |  4 +++-
 target/hexagon/translate.c                | 28 +++++++++++++++++++----
 tests/qtest/hexagon-config-test.c         | 26 +++++++++++++++++++++
 tests/tcg/hexagon/packet_user.c           | 38 +++++++++++++++++++++++++++++++
 tests/functional/hexagon/test_systests.py | 15 ++++++++++++
 tests/tcg/hexagon/meson.build             |  1 +
 13 files changed, 129 insertions(+), 15 deletions(-)
 create mode 100644 tests/tcg/hexagon/packet_user.c
author
#1 lore raw

[PULL 3/7] target/hexagon: fix get_exe_mode assertion in hexagon_stop_thread

When a thread in WAIT mode (W=1, E=1) executes a STOP instruction, hexagon_stop_thread must clear the wait-mode bit before clearing the enable bit. Without this, clear_enable_mask creates a transient (W=1, E=0) state in MODECTL that triggers g_assert_not_reached() in get_exe_mode() when another thread iterates all CPUs via hex_interrupt_update.

---
 target/hexagon/cpu_helper.c | 1 +
 1 file changed, 1 insertion(+)
target/hexagon/cpu_helper.c +1 -0
index f53d377ab14..680dcf56803 100644
@@ -441,6 +441,7 @@ void hexagon_stop_thread(CPUHexagonState *env)
 
     BQL_LOCK_GUARD();
 
+    clear_wait_mode(env);
     thread_enabled_mask = clear_enable_mask(env);
     cs = env_cpu(env);
     cpu_interrupt(cs, CPU_INTERRUPT_HALT);
Signature · 1 line
2.34.1
author
#2 lore raw

[PULL 1/7] target/hexagon: read the old predicate value through C4

In reply to Brian Cain

From: Marco Liebel <[email protected]>

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/packet_user.c | 38 +++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/meson.build   |  1 +
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/hexagon/packet_user.c
target/hexagon/translate.h +5 -1
index bc3b49ab06d..c988c85f33b 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/packet_user.c new file +38 -0
new file mode 100644
index 00000000000..27ac17de745
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#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;
+}
tests/tcg/hexagon/meson.build +1 -0
index 70f6475656c..b3635be3fcb 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},
Signature · 1 line
2.34.1
author
#3 lore raw

[PULL 4/7] target/hexagon: deliver floating point exceptions after the packet

In reply to Brian Cain

An unmasked floating point exception used to take the exception in the middle of the packet, with whatever PC was last written. The architecture takes it after the packet commits, like trap0, so pend it the way the TLB pends an imprecise exception and raise it at the end of the packet. Report ELR as the last word of the packet so that a handler resumes at the next packet by advancing ELR by one word.

This enables the float_excp systest.

---
 target/hexagon/arch.c                     |  9 +++++----
 target/hexagon/hexswi.c                   |  1 +
 target/hexagon/translate.c                | 10 ++++++++--
 tests/functional/hexagon/test_systests.py |  5 +++++
 4 files changed, 19 insertions(+), 6 deletions(-)
target/hexagon/arch.c +5 -4
index 5ee87b320b6..ddbcba9cdd0 100644
@@ -214,13 +214,14 @@ void arch_fpop_start(CPUHexagonState *env)
  */
 #define RAISE_FP_EXCEPTION   do {} while (0)
 #else
+/*
+ * Floating point exceptions are taken after the packet that caused them
+ * commits, so pend this one for check_imprecise_exception().
+ */
 #define RAISE_FP_EXCEPTION \
     do { \
-        CPUState *cs = env_cpu(env); \
-        cs->exception_index = HEX_EVENT_FPTRAP; \
+        env->imprecise_exception = HEX_EVENT_FPTRAP; \
         env->cause_code = HEX_CAUSE_FPTRAP_CAUSE_BADFLOAT; \
-        do_raise_exception(env, cs->exception_index, \
-                           env->gpr[HEX_REG_PC], 0); \
     } while (0)
 #endif
 
target/hexagon/hexswi.c +1 -0
index acc68aa6c23..96d4a783ed4 100644
@@ -972,6 +972,7 @@ void hexagon_cpu_do_interrupt(CPUState *cs)
         break;
 
     case HEX_EVENT_FPTRAP:
+        env->imprecise_exception = 0;
         if (event_to_guest(env, CCR_GEE)) {
             guest_event_entry(env, env->cause_code, env->gpr[HEX_REG_PC],
                               HEX_GEVB_HW_FPTRAP, false);
target/hexagon/translate.c +8 -2
index 796d32bff95..2461b0064a2 100644
@@ -1345,11 +1345,17 @@ static void update_exec_counters(DisasContext *ctx)
 #ifndef CONFIG_USER_ONLY
 /*
  * A tlbp instruction may detect multiple TLB matches and set a pending
- * imprecise exception.  Raise it after the packet that ran the tlbp.
+ * imprecise exception, and a floating point instruction may set a pending
+ * floating point exception.  Raise them after the packet that caused them.
+ *
+ * A floating point exception establishes the exception point after the
+ * packet, like trap0.  ELR is the last word of the packet, so a handler
+ * resumes at the next packet by advancing ELR by one word.
  */
 static void check_imprecise_exception(DisasContext *ctx)
 {
-    TCGv PC = tcg_constant_tl(ctx->pkt.pc);
+    TCGv PC = tcg_constant_tl(check_for_attrib(&ctx->pkt, A_FPOP) ?
+                              ctx->next_PC - 4 : ctx->pkt.pc);
     TCGLabel *label = gen_new_label();
 
     tcg_gen_brcondi_tl(TCG_COND_EQ, hex_imprecise_exception, 0, label);
tests/functional/hexagon/test_systests.py +5 -0
index 76e2480c1d3..606567230b9 100755
@@ -82,6 +82,11 @@ def test_ftrunc(self):
         self.assertEqual(os.path.getsize(ftrunc_path), 1,
                          "_testfile_ftrunc should be 1 byte after ftrunc")
 
+    def test_float_excp(self):
+        """Unmasked floating point exceptions are taken after the packet
+        that caused them commits."""
+        self.run_exit_zero("float_excp")
+
     def test_access(self):
         """access checks R_OK|W_OK on _testfile_access."""
         testfile = self.scratch_file("_testfile_access")
Signature · 1 line
2.34.1
author
#4 lore raw

[PULL 6/7] target/hexagon: raise decode failures at the faulting packet

In reply to Brian Cain

A guest handler for an invalid packet or opcode skips the packet by advancing ELR past it. gen_exception_decode_fail() raised the exception at the address after the packet words, so the handler stepped over the packet that followed as well. In system mode report the address of the faulting packet. linux-user keeps reporting the address after the words, which is where the invalid encoding tests resume.

This enables the llsc_on_excp systest.

---
 target/hexagon/translate.c                | 13 +++++++++++--
 tests/functional/hexagon/test_systests.py |  5 +++++
 2 files changed, 16 insertions(+), 2 deletions(-)
target/hexagon/translate.c +11 -2
index 2461b0064a2..f10fc2c8390 100644
@@ -271,13 +271,22 @@ void hex_gen_exception_end_tb(DisasContext *ctx, int cause)
  */
 static void gen_exception_decode_fail(DisasContext *ctx, int nwords, int cause)
 {
-    target_ulong fail_pc = ctx->base.pc_next + nwords * sizeof(uint32_t);
+    target_ulong next_pc = ctx->base.pc_next + nwords * sizeof(uint32_t);
+#ifdef CONFIG_USER_ONLY
+    target_ulong fail_pc = next_pc;
+#else
+    /*
+     * A guest handler skips the packet by advancing ELR, so it must be the
+     * address of the faulting packet and not the one after it.
+     */
+    target_ulong fail_pc = ctx->base.pc_next;
+#endif
 
     gen_exec_counters(ctx);
     tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], fail_pc);
     gen_precise_exception(cause, fail_pc);
     ctx->base.is_jmp = DISAS_NORETURN;
-    ctx->base.pc_next = fail_pc;
+    ctx->base.pc_next = next_pc;
 }
 
 static int read_packet_words(CPUHexagonState *env, DisasContext *ctx,
tests/functional/hexagon/test_systests.py +5 -0
index f997563baca..4130c1b4ee1 100755
@@ -92,6 +92,11 @@ def test_framelimit(self):
         exception at the allocframe packet."""
         self.run_exit_zero("framelimit")
 
+    def test_llsc_on_excp(self):
+        """An exception between a load-locked and the store-conditional
+        clears the reservation."""
+        self.run_exit_zero("llsc_on_excp")
+
     def test_access(self):
         """access checks R_OK|W_OK on _testfile_access."""
         testfile = self.scratch_file("_testfile_access")
Signature · 1 line
2.34.1
author
#5 lore raw

[PULL 2/7] target/hexagon: bound packet lookahead to the current page

In reply to Brian Cain

From: Marco Liebel <[email protected]>

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 11b3917b96c..796d32bff95 100644
@@ -1621,6 +1621,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.34.1
author
#6 lore raw

[PULL 7/7] hw/hexagon: honor configured RAM backends

In reply to Brian Cain

The Hexagon machines consumed the MachineState memory-backend configuration but always created and mapped a separate DDR region, so a memory backend given with -machine memory-backend= was never used as guest memory. Map the machine's configured RAM when present, so that file-backed and shared memory (as used by the migration tests) is actually guest memory. Keep the board-allocated RAM as the fallback.

Add a regression test that writes guest DDR and verifies the bytes through the backing file. It fails without this change.

---
 hw/hexagon/hex-subsys.c           | 10 +++++++---
 tests/qtest/hexagon-config-test.c | 26 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)
hw/hexagon/hex-subsys.c +7 -3
index 52ec0cadacc..1103d2b556c 100644
@@ -163,12 +163,16 @@ void hex_subsys_create(HexagonCommonMachineState *hms,
 {
     MachineState *machine = MACHINE(hms);
     MemoryRegion *sysmem = get_system_memory();
+    MemoryRegion *ram = machine->ram;
     size_t i;
 
     /* Main DDR. */
-    memory_region_init_ram(&hms->ram, NULL, "ddr.ram", machine->ram_size,
-                           &error_fatal);
-    memory_region_add_subregion(sysmem, m_cfg->ddr_base, &hms->ram);
+    if (!ram) {
+        memory_region_init_ram(&hms->ram, NULL, "ddr.ram", machine->ram_size,
+                               &error_fatal);
+        ram = &hms->ram;
+    }
+    memory_region_add_subregion(sysmem, m_cfg->ddr_base, ram);
 
     /* Config-table ROM and the blob that backs it. */
     memory_region_init_rom(&hms->cfgtable_rom, NULL, "config_table.rom",
tests/qtest/hexagon-config-test.c +26 -0
index 9554fce57ca..d4dc9a2d3f0 100644
@@ -60,6 +60,31 @@ static void test_config_table(gconstpointer data)
     qtest_end();
 }
 
+/* The virt machine maps DDR at guest physical address 0. */
+static void test_memory_backend(void)
+{
+    g_autofree char *path = NULL;
+    g_autofree char *args = NULL;
+    const uint8_t expected[] = { 0x12, 0x34, 0x56, 0x78 };
+    uint8_t actual[4];
+    int fd = g_file_open_tmp("hexagon-ram-XXXXXX", &path, NULL);
+
+    g_assert_cmpint(fd, >=, 0);
+    g_assert_cmpint(ftruncate(fd, 16 * 1024 * 1024), ==, 0);
+    args = g_strdup_printf("-machine virt,memory-backend=ram -m 16M "
+                           "-object memory-backend-file,id=ram,size=16M,"
+                           "share=on,mem-path=%s", path);
+    qtest_start(args);
+    /* QEMU has the file open now, so nothing is left behind on failure. */
+    unlink(path);
+    writel(0x1000, 0x78563412);
+    g_assert_cmpint(lseek(fd, 0x1000, SEEK_SET), ==, 0x1000);
+    g_assert_cmpint(read(fd, actual, sizeof(actual)), ==, sizeof(actual));
+    g_assert_cmpmem(actual, sizeof(actual), expected, sizeof(expected));
+    qtest_end();
+    close(fd);
+}
+
 int main(int argc, char **argv)
 {
     size_t i;
@@ -74,5 +99,6 @@ int main(int argc, char **argv)
         qtest_add_data_func(path, mc, test_config_table);
     }
 
+    qtest_add_func("/config/memory-backend", test_memory_backend);
     return g_test_run();
 }
Signature · 1 line
2.34.1
author
#7 lore raw

[PULL 5/7] target/hexagon: report the faulting packet for stack limit exceptions

In reply to Brian Cain

The stack limit check raised the exception from a helper without updating the PC register, which is not kept current while a packet runs. The exception's ELR was whatever PC was last written, so a handler that skipped the faulting allocframe resumed at an earlier packet and took the same exception forever. Pass the packet's PC to the helper.

This enables the framelimit systest.

---
 target/hexagon/helper.h                   | 2 +-
 target/hexagon/genptr.c                   | 3 ++-
 target/hexagon/op_helper.c                | 4 +++-
 tests/functional/hexagon/test_systests.py | 5 +++++
 4 files changed, 11 insertions(+), 3 deletions(-)
target/hexagon/helper.h +1 -1
index 292ca8eb7c5..e658f8068f4 100644
@@ -158,7 +158,7 @@ DEF_HELPER_5(insn_cache_op, void, env, i32, int, int, i32)
 #endif
 
 #if !defined(CONFIG_USER_ONLY)
-DEF_HELPER_3(raise_stack_overflow, void, env, i32, i32)
+DEF_HELPER_4(raise_stack_overflow, void, env, i32, i32, i32)
 DEF_HELPER_2(swi, void, env, i32)
 DEF_HELPER_2(cswi, void, env, i32)
 DEF_HELPER_2(ciad, void, env, i32)
target/hexagon/genptr.c +2 -1
index 52615628e3f..90b71ebc016 100644
@@ -1156,7 +1156,8 @@ void gen_framecheck(DisasContext *ctx, TCGv_i32 addr, TCGv_i32 ea)
     TCGLabel *ok = gen_new_label();
     tcg_gen_brcond_i32(TCG_COND_GEU, addr, hex_gpr[HEX_REG_FRAMELIMIT], ok);
     gen_helper_raise_stack_overflow(tcg_env,
-                                   tcg_constant_i32(ctx->insn->slot), ea);
+                                    tcg_constant_i32(ctx->insn->slot), ea,
+                                    tcg_constant_i32(ctx->pkt.pc));
     gen_set_label(ok);
 #endif
 }
target/hexagon/op_helper.c +3 -1
index 71b27ef07f1..cdb731160eb 100644
@@ -1660,7 +1660,7 @@ void HELPER(vwhist128qm)(CPUHexagonState *env, int32_t uiV)
 
 #ifndef CONFIG_USER_ONLY
 void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,
-                                  uint32_t badva)
+                                  uint32_t badva, uint32_t pc)
 {
     /*
      * Per section 7.3.1 of the V67 Programmer's Reference,
@@ -1677,6 +1677,8 @@ void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,
     cs = env_cpu(env);
     cs->exception_index = HEX_EVENT_PRECISE;
     env->cause_code = HEX_CAUSE_STACK_LIMIT;
+    /* The PC register is not kept current, ELR is the faulting packet */
+    env->gpr[HEX_REG_PC] = pc;
 
     if (slot == 0) {
         env->t_sreg[HEX_SREG_BADVA0] = badva;
tests/functional/hexagon/test_systests.py +5 -0
index 606567230b9..f997563baca 100755
@@ -87,6 +87,11 @@ def test_float_excp(self):
         that caused them commits."""
         self.run_exit_zero("float_excp")
 
+    def test_framelimit(self):
+        """allocframe past FRAMELIMIT in user mode raises the stack limit
+        exception at the allocframe packet."""
+        self.run_exit_zero("framelimit")
+
     def test_access(self):
         """access checks R_OK|W_OK on _testfile_access."""
         testfile = self.scratch_file("_testfile_access")
Signature · 1 line
2.34.1
#8 lore raw
In reply to Brian Cain
Quoted 6 lines · Brian Cain

The following changes since commit 9cda597a1a3903d090e8e55e23f5b8a859da88ab:

   Merge tag 'pbouvier/pr/fixes_11.2-20261127' ofhttps://gitlab.com/p-b-o/qemu into staging (2026-11-29 13:42:36 -0800)

are available in the Git repository at:

Quoted 8 lines
   https://github.com/qualcomm/qemu tags/pull-hex-20261130

for you to fetch changes up to 23f93333cd0a9c82f9d1e0d920a9b194426fd8d8:

   hw/hexagon: honor configured RAM backends (2026-11-29 20:59:24 -0800)

----------------------------------------------------------------
hexagon: fix page-cross ELR, p0-3/c4, fp excp

Applied, thanks.

r~