i386: hvf: Reset IRQ inhibition after moving RIP
PATCH 1/1 i386: hvf: Reset IRQ inhibition after moving RIP
The sequence of instructions exposes an issue:
sti
hlt
Interrupts cannot be delivered to hvf after hlt instruction cpu because HF_INHIBIT_IRQ_MASK is set just before hlt is handled and never reset after moving instruction pointer beyond hlt.
So, after hvf_vcpu_exec() returns, CPU thread gets locked up forever in qemu_wait_io_event() (cpu_thread_is_idle() evaluates inhibition flag and considers the CPU idle if the flag is set).
--- target/i386/hvf/vmx.h | 3 +++ 1 file changed, 3 insertions(+)
target/i386/hvf/vmx.h +3 -0
@@ -167,6 +167,8 @@ static inline void macvm_set_cr4(hv_vcpuid_t vcpu, uint64_t cr4)static inline void macvm_set_rip (CPUState *cpu,uint64_t rip) { +X86CPU *x86_cpu =X86_CPU (cpu); +CPUX86State *env = &x86_cpu->env;uint64_t val;/* BUG, should take considering overlap.. */
@@ -176,6 +178,7 @@ static inline void macvm_set_rip(CPUState *cpu, uint64_t rip) val =rvmcs (cpu->hvf_fd,VMCS_GUEST_INTERRUPTIBILITY );if (val & (VMCS_INTERRUPTIBILITY_STI_BLOCKING |VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING )) { + env->hflags &= ~HF_INHIBIT_IRQ_MASK ;wvmcs (cpu->hvf_fd,VMCS_GUEST_INTERRUPTIBILITY , val & ~(VMCS_INTERRUPTIBILITY_STI_BLOCKING |VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING ));
Signature · 1 line
2.24.1
Paolo Bonzini
AppliedQuoted 33 lines · Roman Bolshakov
The sequence of instructions exposes an issue:
sti
hltInterrupts cannot be delivered to hvf after hlt instruction cpu because
HF_INHIBIT_IRQ_MASKis set just before hlt is handled and never reset after moving instruction pointer beyond hlt.So, after
hvf_vcpu_exec()returns, CPU thread gets locked up forever inqemu_wait_io_event()(cpu_thread_is_idle()evaluates inhibition flag and considers the CPU idle if the flag is set).Cc Cameron Esfahani <[email protected]>Signed-off-by Roman Bolshakov <[email protected]>--- target/i386/hvf/vmx.h | 3 +++ 1 file changed, 3 insertions(+)target/i386/hvf/vmx.h +2
-0@@ -167,6 +167,8 @@ static inline void macvm_set_cr4(hv_vcpuid_t vcpu, uint64_t cr4)static inline void macvm_set_rip (CPUState *cpu,uint64_t rip) { +X86CPU *x86_cpu =X86_CPU (cpu); +CPUX86State *env = &x86_cpu->env;uint64_t val;/* BUG, should take considering overlap.. */
target/i386/hvf/vmx.h static inline void macvm_set_rip(CPUState *cpu, uint64_t rip) · line 184
Quoted 7 lines
target/i386/hvf/vmx.h +1
-0@@ -176,6 +178,7 @@ static inline void macvm_set_rip(CPUState *cpu, uint64_t rip) val =rvmcs (cpu->hvf_fd,VMCS_GUEST_INTERRUPTIBILITY );if (val & (VMCS_INTERRUPTIBILITY_STI_BLOCKING |VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING )) { + env->hflags &= ~HF_INHIBIT_IRQ_MASK ;wvmcs (cpu->hvf_fd,VMCS_GUEST_INTERRUPTIBILITY , val & ~(VMCS_INTERRUPTIBILITY_STI_BLOCKING |VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING ));
Queued, thanks!
Paolo
LGTM.
Cameron Esfahani
[email protected]
"There are times in the life of a nation when the only place a decent man can find himself is in prison."
Quoted 45 lines · Roman Bolshakov
The sequence of instructions exposes an issue:
sti
hltInterrupts cannot be delivered to hvf after hlt instruction cpu because
HF_INHIBIT_IRQ_MASKis set just before hlt is handled and never reset after moving instruction pointer beyond hlt.So, after
hvf_vcpu_exec()returns, CPU thread gets locked up forever inqemu_wait_io_event()(cpu_thread_is_idle()evaluates inhibition flag and considers the CPU idle if the flag is set).Cc Cameron Esfahani <[email protected]>Signed-off-by Roman Bolshakov <[email protected]>---
target/i386/hvf/vmx.h| 3 +++1 file changed, 3 insertions(+)target/i386/hvf/vmx.h +3
-0@@ -167,6 +167,8 @@ static inline void macvm_set_cr4(hv_vcpuid_t vcpu, uint64_t cr4)static inline void macvm_set_rip (CPUState *cpu,uint64_t rip) { +X86CPU *x86_cpu =X86_CPU (cpu); +CPUX86State *env = &x86_cpu->env;uint64_t val;/* BUG, should take considering overlap.. */ @@ -176,6 +178,7 @@ static inline void macvm_set_rip(CPUState *cpu, uint64_t rip) val =rvmcs (cpu->hvf_fd,VMCS_GUEST_INTERRUPTIBILITY );if (val & (VMCS_INTERRUPTIBILITY_STI_BLOCKING |VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING )) { + env->hflags &= ~HF_INHIBIT_IRQ_MASK ;wvmcs (cpu->hvf_fd,VMCS_GUEST_INTERRUPTIBILITY , val & ~(VMCS_INTERRUPTIBILITY_STI_BLOCKING |VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING ));Signature · 1 line
2.24.1