An exception that carries an error code must retain it across migration.
Otherwise the destination reinjects it with error_code 0, which can make
the guest panic. Do not suppress this required state for old machine
types; an incompatible destination should abort migration instead.
The chance of stopping a vCPU while an exception is pending or injected
is extremely low, so the cpu/error_code subsection should rarely be
needed.
It is currently emitted much more often because KVM does not clear
has_error_code and error_code after completing exception injection.
Require a valid exception_nr before sending the subsection. This filters
stale KVM state while preserving the error code for a real exception.
Fixes: 1b80f1009d ("target/i386: add compat for migrating error code")
Cc: [email protected]
Reported-by: Yuxuan Li <[email protected]>
Signed-off-by: Yanfei Xu <[email protected]>
---
hw/i386/pc.c | 1 -
target/i386/cpu.c | 1 -
target/i386/cpu.h | 1 -
target/i386/machine.c | 2 +-
4 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index e9e4fc262b..1cfe1a50f7 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -85,7 +85,6 @@ const size_t pc_compat_10_2_len =
G_N_ELEMENTS(pc_compat_10_2);
GlobalProperty pc_compat_10_1[] = {
{ "mch", "extended-tseg-mbytes", "16" },
- { TYPE_X86_CPU, "x-migrate-error-code", "false" },
};
const size_t pc_compat_10_1_len = G_N_ELEMENTS(pc_compat_10_1);
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index e5ffb10d15..6f295d5325 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -10819,7 +10819,6 @@ static const Property x86_cpu_properties[] = {
DEFINE_PROP_BOOL("tcg-cpuid", X86CPU, expose_tcg, true),
DEFINE_PROP_BOOL("x-migrate-smi-count", X86CPU, migrate_smi_count,
true),
- DEFINE_PROP_BOOL("x-migrate-error-code", X86CPU, migrate_error_code, true),
/*
* lecacy_cache defaults to true unless the CPU model provides its
* own cache information (see x86_cpu_load_def()).
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 641f3ee5c2..2fdc610539 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2379,7 +2379,6 @@ struct ArchCPU {
bool expose_tcg;
bool migratable;
bool migrate_smi_count;
- bool migrate_error_code;
uint32_t apic_id;
/* Enables publishing of TSC increment and Local APIC bus frequencies to
diff --git a/target/i386/machine.c b/target/i386/machine.c
index 8d69d7e25e..b5c6b127c9 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -466,7 +466,7 @@ static bool cpu_errcode_needed(void *opaque)
{
X86CPU *cpu = opaque;
- return cpu->env.has_error_code != 0 && cpu->migrate_error_code;
+ return cpu->env.exception_nr != -1 && cpu->env.has_error_code != 0;
}
static const VMStateDescription vmstate_error_code = {
--
2.20.1