Commit dcaadc26fd for qemu.org

commit dcaadc26fda20e920e05828f488fe5b10f00a3de
Author: Bibo Mao <maobibo@loongson.cn>
Date:   Thu Oct 29 16:56:54 2026 +0800

    target/loongarch: Check CPU msgint feature with cpu_has_msgint()

    There are two ways to check the CPU msgint feature. One is to call
    cpu_has_msgint(); the other is to check CPULoongArchState::msgint, which
    has type OnOffAuto. A problem arises if msgint is set to ON_OFF_AUTO_AUTO
    in KVM mode: QEMU checks the host feature and sets its actual value in
    cpucfg1, which is read by cpu_has_msgint(). However, the msgint field
    remains ON_OFF_AUTO_AUTO.

    Therefore, in KVM mode cpu_has_msgint() is more accurate than checking
    the OnOffAuto-typed msgint field.

    A problem occurs when booting a VM with the max CPU type on an LA464 host
    that does not support msgint. cpu_has_msgint() returns false, but the
    msgint field remains ON_OFF_AUTO_AUTO, so the expression
    cpu->msgint != ON_OFF_AUTO_OFF evaluates to true.

    Signed-off-by: Bibo Mao <maobibo@loongson.cn>
    Reviewed-by: Xianglai Li <lixianglai@loongson.cn>

diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 33bd89be89..c67dad095a 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -901,12 +901,12 @@ static void virt_check_dmsi(MachineState *machine)

     cpu = LOONGARCH_CPU(first_cpu);
     if (lvms->dmsi == ON_OFF_AUTO_AUTO) {
-        if (cpu->msgint != ON_OFF_AUTO_OFF) {
+        if (cpu_has_msgint(&cpu->env)) {
             lvms->misc_feature = BIT(IOCSRF_DMSI);
         }
     }

-    if (lvms->dmsi == ON_OFF_AUTO_ON && cpu->msgint == ON_OFF_AUTO_OFF) {
+    if (lvms->dmsi == ON_OFF_AUTO_ON && !cpu_has_msgint(&cpu->env)) {
         error_report("Fail to enable dmsi , cpu msgint is off "
                      "pleass add cpu feature mesgint=on.");
         exit(EXIT_FAILURE);
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index dd70beca18..1f3022265a 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -232,7 +232,9 @@ static void loongarch_set_lasx(Object *obj, bool value, Error **errp)

 static bool loongarch_get_msgint(Object *obj, Error **errp)
 {
-    return LOONGARCH_CPU(obj)->msgint != ON_OFF_AUTO_OFF;
+    LoongArchCPU *cpu = LOONGARCH_CPU(obj);
+
+    return cpu_has_msgint(&cpu->env);
 }

 static void loongarch_set_msgint(Object *obj, bool value, Error **errp)