Commit bec85cbf89 for qemu.org

commit bec85cbf897b5f97babd3dc26c3010798ba1dc7e
Author: Brian Cain <brian.cain@oss.qualcomm.com>
Date:   Tue Nov 24 11:03:13 2026 -0800

    target/hexagon: raise decode failures at the faulting packet

    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.

    Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
    Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>

diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c
index 2461b0064a..f10fc2c839 100644
--- a/target/hexagon/translate.c
+++ b/target/hexagon/translate.c
@@ -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,
diff --git a/tests/functional/hexagon/test_systests.py b/tests/functional/hexagon/test_systests.py
index f997563bac..4130c1b4ee 100755
--- a/tests/functional/hexagon/test_systests.py
+++ b/tests/functional/hexagon/test_systests.py
@@ -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")