Commit 310b5d30 authored by Glauber Costa's avatar Glauber Costa Committed by Avi Kivity

KVM: Deal with interrupt shadow state for emulated instructions

We currently unblock shadow interrupt state when we skip an instruction,
but failing to do so when we actually emulate one. This blocks interrupts
in key instruction blocks, in particular sti; hlt; sequences

If the instruction emulated is an sti, we have to block shadow interrupts.
The same goes for mov ss. pop ss also needs it, but we don't currently
emulate it.

Without this patch, I cannot boot gpxe option roms at vmx machines.
This is described at https://bugzilla.redhat.com/show_bug.cgi?id=494469Signed-off-by: default avatarGlauber Costa <glommer@redhat.com>
CC: H. Peter Anvin <hpa@zytor.com>
CC: Gleb Natapov <gleb@redhat.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 2809f5d2
...@@ -155,6 +155,9 @@ struct x86_emulate_ctxt { ...@@ -155,6 +155,9 @@ struct x86_emulate_ctxt {
int mode; int mode;
u32 cs_base; u32 cs_base;
/* interruptibility state, as a result of execution of STI or MOV SS */
int interruptibility;
/* decode cache */ /* decode cache */
struct decode_cache decode; struct decode_cache decode;
}; };
......
...@@ -2379,7 +2379,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, ...@@ -2379,7 +2379,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
u16 error_code, u16 error_code,
int emulation_type) int emulation_type)
{ {
int r; int r, shadow_mask;
struct decode_cache *c; struct decode_cache *c;
kvm_clear_exception_queue(vcpu); kvm_clear_exception_queue(vcpu);
...@@ -2433,6 +2433,10 @@ int emulate_instruction(struct kvm_vcpu *vcpu, ...@@ -2433,6 +2433,10 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
} }
r = x86_emulate_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); r = x86_emulate_insn(&vcpu->arch.emulate_ctxt, &emulate_ops);
shadow_mask = vcpu->arch.emulate_ctxt.interruptibility;
if (r == 0)
kvm_x86_ops->set_interrupt_shadow(vcpu, shadow_mask);
if (vcpu->arch.pio.string) if (vcpu->arch.pio.string)
return EMULATE_DO_MMIO; return EMULATE_DO_MMIO;
......
...@@ -1361,6 +1361,20 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt, ...@@ -1361,6 +1361,20 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
return 0; return 0;
} }
void toggle_interruptibility(struct x86_emulate_ctxt *ctxt, u32 mask)
{
u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(ctxt->vcpu, mask);
/*
* an sti; sti; sequence only disable interrupts for the first
* instruction. So, if the last instruction, be it emulated or
* not, left the system with the INT_STI flag enabled, it
* means that the last instruction is an sti. We should not
* leave the flag on in this case. The same goes for mov ss
*/
if (!(int_shadow & mask))
ctxt->interruptibility = mask;
}
int int
x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
{ {
...@@ -1372,6 +1386,8 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) ...@@ -1372,6 +1386,8 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
int io_dir_in; int io_dir_in;
int rc = 0; int rc = 0;
ctxt->interruptibility = 0;
/* Shadow copy of register state. Committed on successful emulation. /* Shadow copy of register state. Committed on successful emulation.
* NOTE: we can copy them from vcpu as x86_decode_insn() doesn't * NOTE: we can copy them from vcpu as x86_decode_insn() doesn't
* modify them. * modify them.
...@@ -1618,6 +1634,9 @@ special_insn: ...@@ -1618,6 +1634,9 @@ special_insn:
int err; int err;
sel = c->src.val; sel = c->src.val;
if (c->modrm_reg == VCPU_SREG_SS)
toggle_interruptibility(ctxt, X86_SHADOW_INT_MOV_SS);
if (c->modrm_reg <= 5) { if (c->modrm_reg <= 5) {
type_bits = (c->modrm_reg == 1) ? 9 : 1; type_bits = (c->modrm_reg == 1) ? 9 : 1;
err = kvm_load_segment_descriptor(ctxt->vcpu, sel, err = kvm_load_segment_descriptor(ctxt->vcpu, sel,
...@@ -1847,6 +1866,7 @@ special_insn: ...@@ -1847,6 +1866,7 @@ special_insn:
c->dst.type = OP_NONE; /* Disable writeback. */ c->dst.type = OP_NONE; /* Disable writeback. */
break; break;
case 0xfb: /* sti */ case 0xfb: /* sti */
toggle_interruptibility(ctxt, X86_SHADOW_INT_STI);
ctxt->eflags |= X86_EFLAGS_IF; ctxt->eflags |= X86_EFLAGS_IF;
c->dst.type = OP_NONE; /* Disable writeback. */ c->dst.type = OP_NONE; /* Disable writeback. */
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment