Skip to contentSkip to conversation

kvmvapic: patch_instruction fix

PATCH In review Pavel Dovgalyuk 2 participants 2 messages Oct 30, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvmvapic: patch_instruction fix

When QEMU works in icount mode cpu_restore_state function performs two actions:
restoring the program counter and updating icount to the correct value. kvmvapic's patch_instruction function is called by cpu_report_tpr_access function which also invokes cpu_restore_state. It results to calling cpu_restore_state twice - in cpu_report_tpr_access and in patch_instruction. When icount is disabled second call is safe. But when icount is enabled, cpu_restore_state modifies instructions counter twice, which leads to incorrect behavior. This patch removes useless cpu_restore_state call from kvmvapic.

---
 hw/i386/kvmvapic.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
hw/i386/kvmvapic.c +0 -1
index f9da050..28547a7 100644
@@ -405,7 +405,6 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
     }
 
     if (!kvm_enabled()) {
-        cpu_restore_state(cs, cs->mem_io_pc);
         cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
                              &current_flags);
     }
#1 lore raw
Quoted 20 lines · Pavel Dovgalyuk

When QEMU works in icount mode cpu_restore_state function performs two actions:
restoring the program counter and updating icount to the correct value. kvmvapic's patch_instruction function is called by cpu_report_tpr_access function which also invokes cpu_restore_state. It results to calling cpu_restore_state twice - in cpu_report_tpr_access and in patch_instruction. When icount is disabled second call is safe. But when icount is enabled, cpu_restore_state modifies instructions counter twice, which leads to incorrect behavior. This patch removes useless cpu_restore_state call from kvmvapic.

---
 hw/i386/kvmvapic.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
hw/i386/kvmvapic.c +0 -0
index f9da050..28547a7 100644

hw/i386/kvmvapic.c static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip) · line 410

Quoted 7 lines
hw/i386/kvmvapic.c +0 -1
@@ -405,7 +405,6 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
     }
 
     if (!kvm_enabled()) {
-        cpu_restore_state(cs, cs->mem_io_pc);
         cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
                              &current_flags);
     }

Thanks, applying.

Paolo