If cpu->env.has_error_code is true, backwards migration of a VM from
a QEMU binary with commit 27535e9cca to a QEMU binary without commit
27535e9cca will fail:

> kvm: error while loading state for instance 0x0 of device 'cpu'

This happens even if error_code == 0. Fix it by only sending the
error code if it is actually set.

Cc: [email protected]
Fixes: 27535e9cca ("target/i386: Add support for save/load of exception error 
code")
Signed-off-by: Fiona Ebner <[email protected]>
---
 target/i386/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/i386/machine.c b/target/i386/machine.c
index c913961281..b47b14d819 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;
+    return cpu->env.has_error_code != 0 && cpu->env.error_code != 0;
 }
 
 static const VMStateDescription vmstate_error_code = {
-- 
2.47.3



Reply via email to