Reviewed-by:  Xianglai Li <[email protected]>

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 <[email protected]>
---
  hw/loongarch/virt.c    | 4 ++--
  target/loongarch/cpu.c | 4 +++-
  2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 9c5371af9d..1aa9e5dbd5 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -910,12 +910,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)


Reply via email to