lkml.org 
[lkml]   [2009]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] deal with interrupt shadow state for emulated instruction
> Hmm, if the guest runs an infinite emulated 'mov ss', it will keep  
> toggling the MOV_SS bit, but STI will remain set, so we'll never allow
> an interrupt into the guest kernel.
We have no choice but returning both flags, since svm does not differentiate
between them.

But see below for an alternative path that makes it a non-issue.

>
>> diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
>> index d2664fc..797d41f 100644
>> --- a/arch/x86/kvm/x86_emulate.c
>> +++ b/arch/x86/kvm/x86_emulate.c
>> @@ -1618,6 +1618,16 @@ special_insn:
>> int err;
>> sel = c->src.val;
>> + if (c->modrm_reg == VCPU_SREG_SS) {
>> + u32 int_shadow =
>> + kvm_x86_ops->get_interrupt_shadow(ctxt->vcpu);
>> + /* See sti emulation for an explanation of this */
>> + if ((int_shadow & X86_SHADOW_INT_MOV_SS))
>> + ctxt->interruptibility &= ~X86_SHADOW_INT_MOV_SS;
>> + else
>> + ctxt->interruptibility |= X86_SHADOW_INT_MOV_SS;
>> + }
>>
>
> ^=
=p \o/

After re-reading this, masking the flags in here makes no sense.

I am moving to an approach in which I do

if (!(int_shadow & X86_SHADOW_INT_MOV_SS))
ctxt->interruptibility = X86_SHADOW_INT_MOV_SS;

Since if the next instruction is an sti, it is certainly not an sti; sti instruction
(the current is mov ss, after all). So we should mask it anyway. This also solves
nicely the problem you raised at svm.c.
>
>> @@ -1846,10 +1856,23 @@ special_insn:
>> ctxt->eflags &= ~X86_EFLAGS_IF;
>> c->dst.type = OP_NONE; /* Disable writeback. */
>> break;
>> - case 0xfb: /* sti */
>> + case 0xfb: { /* sti */
>> + u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(ctxt->vcpu);
>> + /*
>> + * 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
>> + */
>> + if ((int_shadow & X86_SHADOW_INT_STI))
>> + ctxt->interruptibility &= ~X86_SHADOW_INT_STI;
>> + else
>> + ctxt->interruptibility |= X86_SHADOW_INT_STI;
>>
>
> ^=
ditto



\
 
 \ /
  Last update: 2009-05-05 15:55    [W:0.049 / U:0.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site