Commit 4c85bdde43 for qemu.org

commit 4c85bdde43ee66a6d55d6511bccdb32754028164
Author: Brian Cain <brian.cain@oss.qualcomm.com>
Date:   Tue Sep 1 10:33:47 2026 -0700

    target/hexagon: take BQL when reading the system pcycle count

    hexagon_get_sys_pcycle_count() iterates all CPUs, so take the BQL with
    BQL_LOCK_GUARD() instead of asserting the caller already holds it.
    Convert the matching setters the same way, which keeps the locking
    contract symmetric and makes the read-modify-write in the _low/_high
    setters atomic.  BQL_LOCK_GUARD() is a no-op when the lock is already
    held, so the nested guards on the guest-register read path cost nothing.

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

diff --git a/target/hexagon/cpu_helper.c b/target/hexagon/cpu_helper.c
index fab9a9d7b1..17d6b4eb2b 100644
--- a/target/hexagon/cpu_helper.c
+++ b/target/hexagon/cpu_helper.c
@@ -136,7 +136,7 @@ uint64_t hexagon_get_sys_pcycle_count(CPUHexagonState *env)
     uint64_t total = 0;
     CPUState *cs;

-    g_assert(bql_locked());
+    BQL_LOCK_GUARD();
     CPU_FOREACH(cs) {
         CPUHexagonState *thread_env = cpu_env(cs);
         total += thread_env->t_cycle_count;
@@ -154,11 +154,15 @@ uint32_t hexagon_get_sys_pcycle_count_low(CPUHexagonState *env)
     return (uint32_t)(hexagon_get_sys_pcycle_count(env));
 }

+/*
+ * Every function in this family takes the BQL itself, so the guard below
+ * holds it across the read-modify-write.  Nested guards are no-ops.
+ */
 void hexagon_set_sys_pcycle_count_high(CPUHexagonState *env, uint32_t val)
 {
     uint64_t old;

-    g_assert(bql_locked());
+    BQL_LOCK_GUARD();
     old = hexagon_get_sys_pcycle_count(env);
     old = deposit64(old, 32, 32, val);
     hexagon_set_sys_pcycle_count(env, old);
@@ -168,7 +172,7 @@ void hexagon_set_sys_pcycle_count_low(CPUHexagonState *env, uint32_t val)
 {
     uint64_t old;

-    g_assert(bql_locked());
+    BQL_LOCK_GUARD();
     old = hexagon_get_sys_pcycle_count(env);
     old = deposit64(old, 0, 32, val);
     hexagon_set_sys_pcycle_count(env, old);
@@ -181,7 +185,7 @@ void hexagon_set_sys_pcycle_count(CPUHexagonState *env, uint64_t val)
     int num_threads;
     int64_t delta, per_thread, remainder;

-    g_assert(bql_locked());
+    BQL_LOCK_GUARD();
     total = hexagon_get_sys_pcycle_count(env);

     /* Count active threads */