Skip to contentSkip to conversation

Hexagon: fix lock, priv bugs

PATCH Superseded Brian Cain 3 participants 19 messages Oct 9 – Oct 14 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

cover Hexagon: fix lock, priv bugs

Testing with h2 and linux has uncovered some bugs in the way the locks are implemented and privileged instructions.

Note that this will be rebased to make adjustments when the *next_pc removals
land. See https://lore.kernel.org/qemu-devel/[email protected]/

Brian Cain (6):
target/hexagon: check privilege mode for system instructions target/hexagon: wake K0 and TLB lock waiters target/hexagon: fix stale PC on k0lock wait resume target/hexagon: halt on tlblock when the TLB lock is contended target/hexagon: set a started thread's enable bit when start retires tests/functional/hexagon: add MiniVM, lock tests

 target/hexagon/cpu.h                      |  1 +
 target/hexagon/translate.h                |  1 +
 target/hexagon/cpu.c                      |  2 ++
 target/hexagon/cpu_helper.c               |  6 ++++
 target/hexagon/hex_interrupts.c           |  8 +++--
 target/hexagon/hex_mmu.c                  |  7 ++++
 target/hexagon/op_helper.c                |  3 ++
 target/hexagon/translate.c                | 15 ++++++++
 target/hexagon/gen_tcg_funcs.py           | 16 +++++----
 tests/functional/hexagon/meson.build      |  1 +
 tests/functional/hexagon/test_minivm.py   | 43 +++++++++++++++++++++++
 tests/functional/hexagon/test_systests.py |  3 ++
 12 files changed, 98 insertions(+), 8 deletions(-)
 create mode 100755 tests/functional/hexagon/test_minivm.py
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/6 target/hexagon: check privilege mode for system instructions

Fixes 9831d3cab168 ("target/hexagon: Add privilege check, use tag_ignore()")
---
 target/hexagon/cpu.h            |  1 +
 target/hexagon/translate.h      |  1 +
 target/hexagon/cpu.c            |  2 ++
 target/hexagon/translate.c      | 15 +++++++++++++++
 target/hexagon/gen_tcg_funcs.py | 16 ++++++++++------
 5 files changed, 29 insertions(+), 6 deletions(-)
target/hexagon/cpu.h +1 -0
index df4c0182247..2a5514d512a 100644
@@ -229,6 +229,7 @@ FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1)
 FIELD(TB_FLAGS, MMU_INDEX, 1, 3)
 FIELD(TB_FLAGS, PCYCLE_ENABLED, 4, 1)
 FIELD(TB_FLAGS, HVX_COPROC_ENABLED, 5, 1)
+FIELD(TB_FLAGS, CPU_MODE, 6, 2)
 
 G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,
                                             uint32_t exception,
target/hexagon/translate.h +1 -0
index e17261761b2..aad296485d0 100644
@@ -45,6 +45,7 @@ typedef struct DisasContext {
     DECLARE_BITMAP(gpr_uncond, TOTAL_PER_THREAD_REGS);
     bool implicit_usr_write;
 #ifndef CONFIG_USER_ONLY
+    uint32_t cpu_mode;
     int greg_log[GREG_WRITES_MAX];
     int greg_log_idx;
     DECLARE_BITMAP(gregs_written, NUM_GREGS);
target/hexagon/cpu.c +2 -0
index 1f7d8a8df70..89b16a0d713 100644
@@ -353,6 +353,8 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs)
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, HVX_COPROC_ENABLED,
                            cpu->hvx_ctx[0] &&
                            GET_SSR_FIELD(SSR_XE, env->t_sreg[HEX_SREG_SSR]));
+    hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, CPU_MODE,
+                           get_cpu_mode(env));
 #else
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, MMU_INDEX, MMU_USER_IDX);
 #endif
target/hexagon/translate.c +15 -0
index 827859e052c..35f1e47b7a7 100644
@@ -1280,6 +1280,20 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
                                       HEX_CAUSE_REG_WRITE_CONFLICT);
             return;
         }
+#ifndef CONFIG_USER_ONLY
+        if (check_for_attrib(&ctx->pkt, A_PRIV) &&
+            ctx->cpu_mode != HEX_CPU_MODE_MONITOR) {
+            hex_gen_exception_end_tb(ctx, HEX_CAUSE_PRIV_USER_NO_SINSN);
+            ctx->base.pc_next += ctx->pkt.encod_pkt_size_in_bytes;
+            return;
+        }
+        if (check_for_attrib(&ctx->pkt, A_GUEST) &&
+            ctx->cpu_mode == HEX_CPU_MODE_USER) {
+            hex_gen_exception_end_tb(ctx, HEX_CAUSE_PRIV_USER_NO_GINSN);
+            ctx->base.pc_next += ctx->pkt.encod_pkt_size_in_bytes;
+            return;
+        }
+#endif
         gen_start_packet(ctx);
         for (i = 0; i < ctx->pkt.num_insns; i++) {
             ctx->insn = &ctx->pkt.insn[i];
@@ -1314,6 +1328,7 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase,
     ctx->hvx_coproc_enabled =
         FIELD_EX32(hex_flags, TB_FLAGS, HVX_COPROC_ENABLED);
     ctx->hvx_check_emitted = false;
+    ctx->cpu_mode = FIELD_EX32(hex_flags, TB_FLAGS, CPU_MODE);
 #endif
 }
 
target/hexagon/gen_tcg_funcs.py +10 -6
index 2592acf21eb..f793ceb9dc9 100755
@@ -58,16 +58,20 @@ def gen_tcg_func(f, tag, regs, imms):
 
     f.write("    Insn *insn G_GNUC_UNUSED = ctx->insn;\n")
 
-    if "A_PRIV" in hex_common.attribdict[tag]:
+    if (
+        "A_PRIV" in hex_common.attribdict[tag]
+        or "A_GUEST" in hex_common.attribdict[tag]
+    ):
         f.write(dedent("""\
 #ifdef CONFIG_USER_ONLY
-    hex_gen_exception_end_tb(ctx, HEX_CAUSE_PRIV_USER_NO_SINSN);
-#else
 """))
-    if "A_GUEST" in hex_common.attribdict[tag]:
+        if "A_PRIV" in hex_common.attribdict[tag]:
+            f.write("    hex_gen_exception_end_tb(ctx, "
+                    "HEX_CAUSE_PRIV_USER_NO_SINSN);\n")
+        else:
+            f.write("    hex_gen_exception_end_tb(ctx, "
+                    "HEX_CAUSE_PRIV_USER_NO_GINSN);\n")
         f.write(dedent("""\
-#ifdef CONFIG_USER_ONLY
-    hex_gen_exception_end_tb(ctx, HEX_CAUSE_PRIV_USER_NO_GINSN);
 #else
 """))
     if hex_common.need_ea(tag):
Signature · 1 line
2.34.1
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] target/hexagon: check privilege mode for system instructions

Quoted 10 lines · Brian Cain
Fixes 9831d3cab168 ("target/hexagon: Add privilege check, use tag_ignore()")
---
 target/hexagon/cpu.h            |  1 +
 target/hexagon/translate.h      |  1 +
 target/hexagon/cpu.c            |  2 ++
 target/hexagon/translate.c      | 15 +++++++++++++++
 target/hexagon/gen_tcg_funcs.py | 16 ++++++++++------
 5 files changed, 29 insertions(+), 6 deletions(-)
author
#3 lore raw

PATCH 2/6 target/hexagon: wake K0 and TLB lock waiters

In reply to Brian Cain

Wake the selected K0 or TLB lock waiter when ownership passes. Update its interrupt state and kick the vCPU.

---
 target/hexagon/cpu_helper.c     | 2 ++
 target/hexagon/hex_interrupts.c | 8 ++++++--
 target/hexagon/hex_mmu.c        | 3 +++
 target/hexagon/op_helper.c      | 2 ++
 4 files changed, 13 insertions(+), 2 deletions(-)
target/hexagon/cpu_helper.c +2 -0
index cf0762ff05f..0cc8ec890da 100644
@@ -460,6 +460,7 @@ static uint32_t set_enable_mask(CPUHexagonState *env)
     thread_enabled_mask = GET_FIELD(MODECTL_E, modectl);
     thread_enabled_mask |= 0x1 << env->threadId;
     SET_SYSTEM_FIELD(env, HEX_SREG_MODECTL, MODECTL_E, thread_enabled_mask);
+    hex_interrupt_update(env);
     return thread_enabled_mask;
 }
 
@@ -480,6 +481,7 @@ static uint32_t clear_enable_mask(CPUHexagonState *env)
     thread_enabled_mask = GET_FIELD(MODECTL_E, modectl);
     thread_enabled_mask &= ~(0x1 << env->threadId);
     SET_SYSTEM_FIELD(env, HEX_SREG_MODECTL, MODECTL_E, thread_enabled_mask);
+    hex_interrupt_update(env);
     return thread_enabled_mask;
 }
 static void do_start_thread(CPUState *cs, run_on_cpu_data tbd)
target/hexagon/hex_interrupts.c +6 -2
index 0b714b73831..01fe1896203 100644
@@ -240,8 +240,10 @@ static bool hex_is_qualified_for_int(CPUHexagonState *env, int int_num)
     bool ssr_ie = get_ssr_ie(env);
     bool ssr_ex = get_ssr_ex(env);
     bool imask = get_imask_bit(env, int_num);
+    bool lock_pending = env->k0_lock_state != HEX_LOCK_UNLOCKED ||
+                        env->tlb_lock_state != HEX_LOCK_UNLOCKED;
 
-    return syscfg_gie && !iad && ssr_ie && !ssr_ex && !imask;
+    return syscfg_gie && !iad && ssr_ie && !ssr_ex && !imask && !lock_pending;
 }
 
 static void clear_pending_locks(CPUHexagonState *env)
@@ -257,7 +259,9 @@ static void clear_pending_locks(CPUHexagonState *env)
 
 static bool should_not_exec(CPUHexagonState *env)
 {
-    return (get_exe_mode(env) == HEX_EXE_MODE_WAIT);
+    return get_exe_mode(env) == HEX_EXE_MODE_WAIT ||
+           env->k0_lock_state == HEX_LOCK_WAITING ||
+           env->tlb_lock_state == HEX_LOCK_WAITING;
 }
 
 static void restore_state(CPUHexagonState *env, bool int_accepted)
target/hexagon/hex_mmu.c +3 -0
index d6ee7c40798..bdcfa057c21 100644
@@ -19,6 +19,7 @@
 #include "sys_macros.h"
 #include "hw/hexagon/hexagon_tlb.h"
 #include "hw/hexagon/hexagon_globalreg.h"
+#include "hex_interrupts.h"
 
 static inline void hex_log_tlbw(uint32_t index, uint64_t entry)
 {
@@ -271,6 +272,8 @@ void hex_tlb_unlock(CPUHexagonState *env)
         unlock_thread->tlb_lock_state = HEX_LOCK_QUEUED;
         SET_SYSCFG_FIELD(unlock_thread, SYSCFG_TLBLOCK, 1);
         cpu_interrupt(cs, CPU_INTERRUPT_TLB_UNLOCK);
+        hex_interrupt_update(unlock_thread);
+        qemu_cpu_kick(cs);
     }
 
     if (qemu_loglevel_mask(CPU_LOG_MMU)) {
target/hexagon/op_helper.c +2 -0
index 4f00ca773f3..6784efddc9f 100644
@@ -1395,6 +1395,8 @@ static void hex_k0_unlock(CPUHexagonState *env)
         unlock_thread->k0_lock_state = HEX_LOCK_QUEUED;
         SET_SYSCFG_FIELD(unlock_thread, SYSCFG_K0LOCK, 1);
         cpu_interrupt(cs, CPU_INTERRUPT_K0_UNLOCK);
+        hex_interrupt_update(unlock_thread);
+        qemu_cpu_kick(cs);
     }
 
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] target/hexagon: wake K0 and TLB lock waiters

Quoted 11 lines · Brian Cain

Wake the selected K0 or TLB lock waiter when ownership passes. Update its interrupt state and kick the vCPU.

---
 target/hexagon/cpu_helper.c     | 2 ++
 target/hexagon/hex_interrupts.c | 8 ++++++--
 target/hexagon/hex_mmu.c        | 3 +++
 target/hexagon/op_helper.c      | 2 ++
 4 files changed, 13 insertions(+), 2 deletions(-)
author
#5 lore raw

PATCH 3/6 target/hexagon: fix stale PC on k0lock wait resume

In reply to Brian Cain

Set PC to the k0lock instruction before halting a contended thread. A stale PC can skip the acquired lock or resume at unrelated guest code.

---
 target/hexagon/op_helper.c | 1 +
 1 file changed, 1 insertion(+)
target/hexagon/op_helper.c +1 -0
index 6784efddc9f..56cf601ef1d 100644
@@ -1314,6 +1314,7 @@ static void hex_k0_lock(CPUHexagonState *env)
             return;
         }
         env->k0_lock_state = HEX_LOCK_WAITING;
+        env->gpr[HEX_REG_PC] = env->next_PC - 4;
         cpu_interrupt(cs, CPU_INTERRUPT_HALT);
         cpu_loop_exit(cs);
     } else {
Signature · 1 line
2.34.1
Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] target/hexagon: fix stale PC on k0lock wait resume

Quoted 8 lines · Brian Cain

Set PC to the k0lock instruction before halting a contended thread. A stale PC can skip the acquired lock or resume at unrelated guest code.

---
 target/hexagon/op_helper.c | 1 +
 1 file changed, 1 insertion(+)
author
#7 lore raw

PATCH 4/6 target/hexagon: halt on tlblock when the TLB lock is contended

In reply to Brian Cain

Set PC to the tlblock instruction and leave the CPU loop when the lock is contended. This retries tlblock after ownership is passed and prevents execution without the lock.

---
 target/hexagon/hex_mmu.c | 4 ++++
 1 file changed, 4 insertions(+)
target/hexagon/hex_mmu.c +4 -0
index bdcfa057c21..b9fab949d0f 100644
@@ -12,6 +12,7 @@
 #include "system/cpus.h"
 #include "internal.h"
 #include "exec/cpu-interrupt.h"
+#include "accel/tcg/cpu-loop.h"
 #include "cpu_helper.h"
 #include "exec/cputlb.h"
 #include "hex_mmu.h"
@@ -185,11 +186,14 @@ void hex_tlb_lock(CPUHexagonState *env)
             env->next_PC += 4;
             CPUState *cs = env_cpu(env);
             cpu_interrupt(cs, CPU_INTERRUPT_HALT);
+            cpu_loop_exit(cs);
             return;
         }
         env->tlb_lock_state = HEX_LOCK_WAITING;
+        env->gpr[HEX_REG_PC] = env->next_PC - 4;
         CPUState *cs = env_cpu(env);
         cpu_interrupt(cs, CPU_INTERRUPT_HALT);
+        cpu_loop_exit(cs);
     } else {
         env->next_PC += 4;
         env->tlb_lock_count++;
Signature · 1 line
2.34.1
Reviewed-by on v1 4/6
#8 lore raw

Re: [PATCH 4/6] target/hexagon: halt on tlblock when the TLB lock is contended

Quoted 9 lines · Brian Cain

Set PC to the tlblock instruction and leave the CPU loop when the lock is contended. This retries tlblock after ownership is passed and prevents execution without the lock.

---
 target/hexagon/hex_mmu.c | 4 ++++
 1 file changed, 4 insertions(+)
#9 lore raw

Re: [PATCH 4/6] target/hexagon: halt on tlblock when the TLB lock is contended

In reply to Brian Cain
Quoted 22 lines · Brian Cain

Set PC to the tlblock instruction and leave the CPU loop when the lock is contended. This retries tlblock after ownership is passed and prevents execution without the lock.

---
  target/hexagon/hex_mmu.c | 4 ++++
  1 file changed, 4 insertions(+)
target/hexagon/hex_mmu.c +1 -0
index bdcfa057c21..b9fab949d0f 100644
@@ -12,6 +12,7 @@
  #include "system/cpus.h"
  #include "internal.h"
  #include "exec/cpu-interrupt.h"
+#include "accel/tcg/cpu-loop.h"
  #include "cpu_helper.h"
  #include "exec/cputlb.h"
  #include "hex_mmu.h"

target/hexagon/hex_mmu.c void hex_tlb_lock(CPUHexagonState *env) · line 188

Quoted 3 lines
target/hexagon/hex_mmu.c +0 -0
@@ -185,11 +186,14 @@ void hex_tlb_lock(CPUHexagonState *env)
              env->next_PC += 4;
              CPUState *cs = env_cpu(env);
              cpu_interrupt(cs, CPU_INTERRUPT_HALT);

Pre-existing apparently, is CPU_INTERRUPT_HALT appropriate?

     /*
      * External hardware interrupt pending.
      * This is typically used for interrupts from devices.
      */
     #define CPU_INTERRUPT_HARD        0x0002

or is there a better match from "exec/cpu-interrupt.h" definitions?

target/hexagon/hex_mmu.c void hex_tlb_lock(CPUHexagonState *env) · line 189

Quoted 1 line
target/hexagon/hex_mmu.c +1 -0
+            cpu_loop_exit(cs);

This call makes sense otherwise.

Quoted 2 lines
target/hexagon/hex_mmu.c +0 -0
              return;
          }
author
#10 lore raw

Re: [PATCH 4/6] target/hexagon: halt on tlblock when the TLB lock is contended

Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 22 lines · Brian Cain

Set PC to the tlblock instruction and leave the CPU loop when the lock is contended. This retries tlblock after ownership is passed and prevents execution without the lock.

---
  target/hexagon/hex_mmu.c | 4 ++++

  1 file changed, 4 insertions(+)
target/hexagon/hex_mmu.c +1 -0
index bdcfa057c21..b9fab949d0f 100644
@@ -12,6 +12,7 @@
   #include "system/cpus.h"
   #include "internal.h"
   #include "exec/cpu-interrupt.h"
+#include "accel/tcg/cpu-loop.h"
   #include "cpu_helper.h"
   #include "exec/cputlb.h"
   #include "hex_mmu.h"

target/hexagon/hex_mmu.c void hex_tlb_lock(CPUHexagonState *env) · line 188

Quoted 3 lines
target/hexagon/hex_mmu.c +0 -0
@@ -185,11 +186,14 @@ void hex_tlb_lock(CPUHexagonState *env)
               env->next_PC += 4;
               CPUState *cs = env_cpu(env);
               cpu_interrupt(cs, CPU_INTERRUPT_HALT);

Pre-existing apparently, is CPU_INTERRUPT_HALT appropriate?

Quoted 7 lines

     /*
      * External hardware interrupt pending.
      * This is typically used for interrupts from devices. */
     #define CPU_INTERRUPT_HARD        0x0002

or is there a better match from "exec/cpu-interrupt.h" definitions?

I think CPU_INTERRUPT_HALT is appropriate.  _HARD is suitable for an external (maskable) interrupt.  The signal we need here is one that will cause us to stop executing instructions while pending on the lock.

Quoted 8 lines

target/hexagon/hex_mmu.c void hex_tlb_lock(CPUHexagonState *env) · line 189

Quoted 2 lines
target/hexagon/hex_mmu.c +1 -0
+            cpu_loop_exit(cs);

This call makes sense otherwise.

Quoted 2 lines
target/hexagon/hex_mmu.c +0 -0
               return;
           }
#11 lore raw

Re: [PATCH 4/6] target/hexagon: halt on tlblock when the TLB lock is contended

Quoted 37 lines · Brian Cain
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 22 lines · Brian Cain

Set PC to the tlblock instruction and leave the CPU loop when the lock is contended. This retries tlblock after ownership is passed and prevents execution without the lock.

---
  target/hexagon/hex_mmu.c | 4 ++++

  1 file changed, 4 insertions(+)
target/hexagon/hex_mmu.c +1 -0
index bdcfa057c21..b9fab949d0f 100644
@@ -12,6 +12,7 @@
   #include "system/cpus.h"
   #include "internal.h"
   #include "exec/cpu-interrupt.h"
+#include "accel/tcg/cpu-loop.h"
   #include "cpu_helper.h"
   #include "exec/cputlb.h"
   #include "hex_mmu.h"

target/hexagon/hex_mmu.c void hex_tlb_lock(CPUHexagonState *env) · line 188

Quoted 3 lines
target/hexagon/hex_mmu.c +0 -0
@@ -185,11 +186,14 @@ void hex_tlb_lock(CPUHexagonState *env)
               env->next_PC += 4;
               CPUState *cs = env_cpu(env);
               cpu_interrupt(cs, CPU_INTERRUPT_HALT);

Pre-existing apparently, is CPU_INTERRUPT_HALT appropriate?

     /*
      * External hardware interrupt pending.
      * This is typically used for interrupts from devices. */
     #define CPU_INTERRUPT_HARD        0x0002

Quoted 3 lines
Quoted 1 line

or is there a better match from "exec/cpu-interrupt.h" definitions?

I think CPU_INTERRUPT_HALT is appropriate.  _HARD is suitable for an external (maskable) interrupt.  The signal we need here is one that will cause us to stop executing instructions while pending on the lock.

OK, we are good then :)

author
#12 lore raw

PATCH 5/6 target/hexagon: set a started thread's enable bit when start retires

In reply to Brian Cain

Set MODECTL.E when start retires rather than when the target thread runs. This makes the thread state visible to software immediately after start.

---
 target/hexagon/cpu_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
target/hexagon/cpu_helper.c +4 -0
index 0cc8ec890da..df306fccd6b 100644
@@ -504,6 +504,9 @@ static void do_start_thread(CPUState *cs, run_on_cpu_data tbd)
 void hexagon_start_threads(CPUHexagonState *current_env, uint32_t mask)
 {
     CPUState *cs;
+
+    BQL_LOCK_GUARD();
+
     CPU_FOREACH(cs) {
         CPUHexagonState *env = cpu_env(cs);
         if (!(mask & (0x1 << env->threadId))) {
@@ -511,6 +514,7 @@ void hexagon_start_threads(CPUHexagonState *current_env, uint32_t mask)
         }
 
         if (current_env->threadId != env->threadId) {
+            set_enable_mask(env);
             async_safe_run_on_cpu(cs, do_start_thread, RUN_ON_CPU_NULL);
         }
     }
Signature · 1 line
2.34.1
Reviewed-by on v1 5/6
#13 lore raw

Re: [PATCH 5/6] target/hexagon: set a started thread's enable bit when start retires

Quoted 8 lines · Brian Cain

Set MODECTL.E when start retires rather than when the target thread runs. This makes the thread state visible to software immediately after start.

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

PATCH 6/6 tests/functional/hexagon: add MiniVM, lock tests

In reply to Brian Cain

Add the lock_verify test case to verify the k0/tlblock behavior, add the minivm tests to cover start() and more.

---
 tests/functional/hexagon/meson.build      |  1 +
 tests/functional/hexagon/test_minivm.py   | 43 +++++++++++++++++++++++
 tests/functional/hexagon/test_systests.py |  3 ++
 3 files changed, 47 insertions(+)
 create mode 100755 tests/functional/hexagon/test_minivm.py
tests/functional/hexagon/meson.build +1 -0
index 44053e64676..e182bc98a06 100644
@@ -3,6 +3,7 @@
 tests_hexagon_system_thorough = [
   'arch_tests',
   'systests',
+  'minivm',
 ]
 
 test_hexagon_timeouts = {
tests/functional/hexagon/test_minivm.py new file +43 -0

43 lines not on this page · raw message

tests/functional/hexagon/test_systests.py +3 -0
index c8137a71713..67043488657 100755
@@ -105,5 +105,8 @@ def test_hvx_multi(self):
     def test_standalone_vec(self):
         self.run_exit_zero("standalone_vec")
 
+    def test_lock_verify(self):
+        self.run_exit_zero("lock_verify")
+
 if __name__ == "__main__":
     QemuSystemTest.main()
Signature · 1 line
2.34.1
Reviewed-by on v1 6/6
#15 lore raw

Re: [PATCH 6/6] tests/functional/hexagon: add MiniVM, lock tests

Quoted 60 lines · Brian Cain

Add the lock_verify test case to verify the k0/tlblock behavior, add the minivm tests to cover start() and more.

---
 tests/functional/hexagon/meson.build      |  1 +
 tests/functional/hexagon/test_minivm.py   | 43 +++++++++++++++++++++++
 tests/functional/hexagon/test_systests.py |  3 ++
 3 files changed, 47 insertions(+)
 create mode 100755 tests/functional/hexagon/test_minivm.py
tests/functional/hexagon/meson.build +1 -0
index 44053e64676..e182bc98a06 100644
@@ -3,6 +3,7 @@
 tests_hexagon_system_thorough = [
   'arch_tests',
   'systests',
+  'minivm',
 ]
 
 test_hexagon_timeouts = {
tests/functional/hexagon/test_minivm.py new file +31 -0
new file mode 100755
index 00000000000..a70edbcc987
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+#
+# Copyright(c) 2024-2025 Qualcomm Innovation Center, Inc. All Rights Reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from qemu_test import QemuSystemTest, Asset, skipBigDataTest
+
+class MiniVMTest(QemuSystemTest):
+    '''
+    minivm is a Hexagon hypervisor that implements the Hexagon VM
+    specification.  These test cases boot minivm and then load test cases
+    to the address specified by MiniVMTest.GUEST_ENTRY and
+    execute a minvm-guest program to exercise minivm virtualization
+    features.
+    '''
+    timeout = 180
+    GUEST_ENTRY = 0xc0000000
+    REPO = 'https://artifacts.codelinaro.org/artifactory'
+    ASSET_TARBALL = \
+        Asset(f'{REPO}/codelinaro-toolchain-for-hexagon/'
+               '19.1.5/hexagon_minivm_2024_Dec_15.tar.gz',
+        'd7920b5ff14bed5a10b23ada7d4eb927ede08635281f25067e0d5711feee2c2a')
+
+    @skipBigDataTest()
+    def test_minivm(self):
+        self.set_machine('sim')
+        self.archive_extract(self.ASSET_TARBALL)
+        rootfs_path = self.scratch_file('hexagon-unknown-linux-musl-rootfs')
+        kernel_path = f'{rootfs_path}/boot/minivm'
+

tests/functional/hexagon/test_minivm.py line 41

Quoted 10 lines
tests/functional/hexagon/test_minivm.py new file +10 -0
+        for test_case in ('test_mmu', 'test_interrupts', 'test_processors'):
+            with self.subTest(test_case=test_case):
+                vm = self.get_vm(name=test_case)
+                vm.add_args('-kernel', kernel_path, '-device',
+                            f'loader,addr={hex(self.GUEST_ENTRY)},'
+                            f'file={rootfs_path}/boot/{test_case}')
+                vm.launch()
+                vm.wait()
+                self.assertEqual(vm.exitcode(), 0)
+

In case we decide to extend that with many other sub testcases, it could be useful to define real sub tests. Just a suggestion though, it's not necessary for the only 3 tests we have at the moment.

Regards,
Pierrick

author
#16 lore raw

Re: [PATCH 6/6] tests/functional/hexagon: add MiniVM, lock tests

Quoted 66 lines · Pierrick Bouvier
Quoted 65 lines · Brian Cain

Add the lock_verify test case to verify the k0/tlblock behavior, add the minivm tests to cover start() and more.

---
  tests/functional/hexagon/meson.build      |  1 +
  tests/functional/hexagon/test_minivm.py   | 43 +++++++++++++++++++++++
  tests/functional/hexagon/test_systests.py |  3 ++
  3 files changed, 47 insertions(+)

create mode 100755 tests/functional/hexagon/test_minivm.py

tests/functional/hexagon/meson.build +1 -0
index 44053e64676..e182bc98a06 100644
@@ -3,6 +3,7 @@
  tests_hexagon_system_thorough = [
    'arch_tests',
    'systests',
+  'minivm',
  ]
 
  test_hexagon_timeouts = {
tests/functional/hexagon/test_minivm.py new file +36 -0
new file mode 100755
index 00000000000..a70edbcc987
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+#
+# Copyright(c) 2024-2025 Qualcomm Innovation Center, Inc. All Rights Reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from qemu_test import QemuSystemTest, Asset, skipBigDataTest
+
+class MiniVMTest(QemuSystemTest):
+    '''
+    minivm is a Hexagon hypervisor that implements the Hexagon VM
+    specification.  These test cases boot minivm and then load test cases
+    to the address specified by MiniVMTest.GUEST_ENTRY and
+    execute a minvm-guest program to exercise minivm virtualization
+    features.
+    '''
+    timeout = 180
+    GUEST_ENTRY = 0xc0000000
+    REPO = 'https://artifacts.codelinaro.org/artifactory'
+    ASSET_TARBALL = \
+        Asset(f'{REPO}/codelinaro-toolchain-for-hexagon/'
+               '19.1.5/hexagon_minivm_2024_Dec_15.tar.gz',
+        'd7920b5ff14bed5a10b23ada7d4eb927ede08635281f25067e0d5711feee2c2a')
+
+    @skipBigDataTest()
+    def test_minivm(self):
+        self.set_machine('sim')
+        self.archive_extract(self.ASSET_TARBALL)
+        rootfs_path = self.scratch_file('hexagon-unknown-linux-musl-rootfs')
+        kernel_path = f'{rootfs_path}/boot/minivm'
+
+        for test_case in ('test_mmu', 'test_interrupts', 'test_processors'):
+            with self.subTest(test_case=test_case):
+                vm = self.get_vm(name=test_case)
+                vm.add_args('-kernel', kernel_path, '-device',
+                            f'loader,addr={hex(self.GUEST_ENTRY)},'
Quoted 8 lines

tests/functional/hexagon/test_minivm.py line 41

Quoted 5 lines
tests/functional/hexagon/test_minivm.py new file +5 -0
+                            f'file={rootfs_path}/boot/{test_case}')
+                vm.launch()
+                vm.wait()
+                self.assertEqual(vm.exitcode(), 0)
+

In case we decide to extend that with many other sub testcases, it could be useful to define real sub tests. Just a suggestion though, it's not necessary for the only 3 tests we have at the moment.

OBTW confession time - the subTest() was merely hackery because the tarball includes a large-ish filesystem.  It was a sparse file before archive+compression but effectively now it's dense.  I just did this to avoid the time spent extracting for each test.  The extraction time dominates the test duration.

So maybe there's a better approach to consider w/o subTest()?

Quoted 4 lines

Regards,
Pierrick

#17 lore raw

Re: [PATCH 6/6] tests/functional/hexagon: add MiniVM, lock tests

Quoted 83 lines · Brian Cain
Quoted 72 lines · Pierrick Bouvier
Quoted 71 lines · Brian Cain

Add the lock_verify test case to verify the k0/tlblock behavior, add the minivm tests to cover start() and more.

---
  tests/functional/hexagon/meson.build      |  1 + tests/functional/hexagon/test_minivm.py   | 43 +++++++++++++++++++++++ tests/functional/hexagon/test_systests.py |  3 ++

  3 files changed, 47 insertions(+)

  create mode 100755 tests/functional/hexagon/test_minivm.py

tests/functional/ renamed from tests/functional/hexagon/meson.build +0 -0

hexagon/meson.build
index 44053e64676..e182bc98a06 100644

tests/functional/hexagon/meson.build +0 -0
@@ -3,6 +3,7 @@

  tests_hexagon_system_thorough = [
    'arch_tests',
    'systests',
+  'minivm',
  ]
    test_hexagon_timeouts = {

tests/ renamed from tests/functional/hexagon/test_minivm.py +0 -0

functional/hexagon/test_minivm.py
new file mode 100755
index 00000000000..a70edbcc987

tests/functional/hexagon/test_minivm.py new file +3 -0
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+#
+# Copyright(c) 2024-2025 Qualcomm Innovation Center, Inc. All Rights

Reserved.

tests/functional/hexagon/test_minivm.py new file +9 -0
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from qemu_test import QemuSystemTest, Asset, skipBigDataTest
+
+class MiniVMTest(QemuSystemTest):
+    '''
+    minivm is a Hexagon hypervisor that implements the Hexagon VM
+    specification.  These test cases boot minivm and then load test

cases
+    to the address specified by MiniVMTest.GUEST_ENTRY and +    execute a minvm-guest program to exercise minivm virtualization +    features.
+    '''
+    timeout = 180
+    GUEST_ENTRY = 0xc0000000
+    REPO = 'https://artifacts.codelinaro.org/artifactory' +    ASSET_TARBALL = \
+        Asset(f'{REPO}/codelinaro-toolchain-for-hexagon/' +               '19.1.5/hexagon_minivm_2024_Dec_15.tar.gz', + 'd7920b5ff14bed5a10b23ada7d4eb927ede08635281f25067e0d5711feee2c2a') +
+    @skipBigDataTest()
+    def test_minivm(self):
+        self.set_machine('sim')
+        self.archive_extract(self.ASSET_TARBALL)
+        rootfs_path = self.scratch_file('hexagon-unknown-linux-musl- rootfs')
+        kernel_path = f'{rootfs_path}/boot/minivm'
+
+        for test_case in ('test_mmu', 'test_interrupts', 'test_processors'):
+            with self.subTest(test_case=test_case):
+                vm = self.get_vm(name=test_case)
+                vm.add_args('-kernel', kernel_path, '-device', +                            f'loader,addr={hex(self.GUEST_ENTRY)},'

Quoted 8 lines
Quoted 5 lines

+                            f'file={rootfs_path}/boot/{test_case}') +                vm.launch()
+                vm.wait()
+                self.assertEqual(vm.exitcode(), 0)
+

In case we decide to extend that with many other sub testcases, it could be useful to define real sub tests. Just a suggestion though, it's not necessary for the only 3 tests we have at the moment.

Quoted 8 lines

OBTW confession time - the subTest() was merely hackery because the tarball includes a large-ish filesystem.  It was a sparse file before archive+compression but effectively now it's dense.  I just did this to avoid the time spent extracting for each test.  The extraction time dominates the test duration.

So maybe there's a better approach to consider w/o subTest()?

After checking it's indeed a bit slow.
Would that be possible to reduce test_mmu (culprit, 2.5GB) image size to something under 100MB?

Beyond time, it would save disk space also.

Regards,
Pierrick

author
#18 lore raw

Re: [PATCH 6/6] tests/functional/hexagon: add MiniVM, lock tests

Quoted 88 lines · Pierrick Bouvier
Quoted 87 lines · Brian Cain
Quoted 72 lines · Pierrick Bouvier
Quoted 71 lines · Brian Cain

Add the lock_verify test case to verify the k0/tlblock behavior, add the minivm tests to cover start() and more.

---
   tests/functional/hexagon/meson.build      |  1 +
   tests/functional/hexagon/test_minivm.py   | 43 +++++++++++++++++++++++
   tests/functional/hexagon/test_systests.py |  3 ++
   3 files changed, 47 insertions(+)

  create mode 100755 tests/functional/hexagon/test_minivm.py

tests/functional/ renamed from tests/functional/hexagon/meson.build +0 -0

hexagon/meson.build
index 44053e64676..e182bc98a06 100644

tests/functional/hexagon/meson.build +1 -0
@@ -3,6 +3,7 @@
   tests_hexagon_system_thorough = [
     'arch_tests',
     'systests',
+  'minivm',
   ]
     test_hexagon_timeouts = {
tests/ renamed from tests/functional/hexagon/test_minivm.py +0 -0

functional/hexagon/test_minivm.py
new file mode 100755
index 00000000000..a70edbcc987

tests/functional/hexagon/test_minivm.py new file +3 -0
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+#
+# Copyright(c) 2024-2025 Qualcomm Innovation Center, Inc. All Rights

Reserved.

tests/functional/hexagon/test_minivm.py new file +9 -0
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from qemu_test import QemuSystemTest, Asset, skipBigDataTest
+
+class MiniVMTest(QemuSystemTest):
+    '''
+    minivm is a Hexagon hypervisor that implements the Hexagon VM
+    specification.  These test cases boot minivm and then load test

cases
+    to the address specified by MiniVMTest.GUEST_ENTRY and +    execute a minvm-guest program to exercise minivm virtualization +    features.
+    '''
+    timeout = 180
+    GUEST_ENTRY = 0xc0000000
+    REPO = 'https://artifacts.codelinaro.org/artifactory' +    ASSET_TARBALL = \
+        Asset(f'{REPO}/codelinaro-toolchain-for-hexagon/' +               '19.1.5/hexagon_minivm_2024_Dec_15.tar.gz', + 'd7920b5ff14bed5a10b23ada7d4eb927ede08635281f25067e0d5711feee2c2a') +
+    @skipBigDataTest()
+    def test_minivm(self):
+        self.set_machine('sim')
+        self.archive_extract(self.ASSET_TARBALL)
+        rootfs_path = self.scratch_file('hexagon-unknown-linux-musl- rootfs')
+        kernel_path = f'{rootfs_path}/boot/minivm'
+
+        for test_case in ('test_mmu', 'test_interrupts', 'test_processors'):
+            with self.subTest(test_case=test_case):
+                vm = self.get_vm(name=test_case)
+                vm.add_args('-kernel', kernel_path, '-device', +                            f'loader,addr={hex(self.GUEST_ENTRY)},'

Quoted 8 lines
Quoted 5 lines

+                            f'file={rootfs_path}/boot/{test_case}') +                vm.launch()
+                vm.wait()
+                self.assertEqual(vm.exitcode(), 0)
+

In case we decide to extend that with many other sub testcases, it could be useful to define real sub tests. Just a suggestion though, it's not necessary for the only 3 tests we have at the moment.

OBTW confession time - the subTest() was merely hackery because the tarball includes a large-ish filesystem.  It was a sparse file before archive+compression but effectively now it's dense.  I just did this to avoid the time spent extracting for each test.  The extraction time dominates the test duration.

Quoted 7 lines
Quoted 2 lines

So maybe there's a better approach to consider w/o subTest()?

After checking it's indeed a bit slow.
Would that be possible to reduce test_mmu (culprit, 2.5GB) image size to something under 100MB?

Beyond time, it would save disk space also.

Ok - I'll see about that.

Quoted 3 lines

Regards,
Pierrick