Re: [PATCH] deal with interrupt shadow state for emulated instruction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux