Commit 4e6099e048 for qemu.org

commit 4e6099e048f467c9319e9efd0ca1345d5c20957f
Author: Bibo Mao <maobibo@loongson.cn>
Date:   Wed Oct 28 11:24:56 2026 +0800

    target/loongarch: Replace sys_state with vm_level

    Int type vm_level is more meaningful than pointer type sys_state,
    and it is easy to get current mode from value of vm_level.

    Here replace sys_state with vm_level, and use vm_level directly.

    Signed-off-by: Bibo Mao <maobibo@loongson.cn>
    Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 5cc2370da2..277fc4f475 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -429,7 +429,7 @@ typedef struct CPUArchState {
     /* Fields up to this point are cleared by a CPU reset */
     struct {} end_reset_fields;

-    CPUSysState sys_states[1];
+    CPUSysState sys_states[VM_LEVELS];
     uint32_t cpucfg[21];
     uint32_t pv_features;
     uint64_t vendor_id;
@@ -440,7 +440,7 @@ typedef struct CPUArchState {
     AddressSpace *address_space_iocsr;
     uint32_t mp_state;
 #endif
-    CPUSysState *sys_state;
+    int vm_level;
     unsigned int irq_nr;
 } CPULoongArchState;

@@ -510,12 +510,14 @@ struct LoongArchCPUClass {

 static inline CPUSysState *env_sys(CPULoongArchState *env)
 {
-    return env->sys_state;
+    return &env->sys_states[env->vm_level];
 }

 static inline void set_sys(CPULoongArchState *env, int vm_level)
 {
-    env->sys_state = &env->sys_states[vm_level];
+    if (vm_level >= 0 && vm_level <  VM_LEVELS) {
+        env->vm_level = vm_level;
+    }
 }

 static inline CPUTimerState *env_timer(CPULoongArchState *env)