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>
This commit is contained in:
Bibo Mao committed 2026-11-05 14:50:32 +08:00
1 parent 38b6e00387
commit dcaadc26fd
2 files changed
+5 -3

No files matched your search

+2 -2
View File
@@ -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);
+3 -1
View File
@@ -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)