From: Glauber Costa <glommer@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] deal with interrupt shadow state for emulated instruction
Date: Tue, 5 May 2009 10:57:06 -0300 [thread overview]
Message-ID: <20090505135706.GA26401@poweredge.glommer> (raw)
In-Reply-To: <49F99095.7060503@redhat.com>
> 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
next prev parent reply other threads:[~2009-05-05 13:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-28 14:30 [PATCH] deal with interrupt shadow state for emulated instruction Glauber Costa
2009-04-30 11:50 ` Avi Kivity
2009-05-05 13:57 ` Glauber Costa [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-05-05 18:40 Glauber Costa
2009-05-06 8:03 ` Gleb Natapov
2009-05-06 10:51 ` Avi Kivity
2009-05-08 5:25 ` Glauber Costa
2009-05-08 7:18 ` Gleb Natapov
2009-05-08 13:02 ` Glauber Costa
2009-04-13 20:06 Glauber Costa
2009-04-14 9:07 ` Gleb Natapov
2009-04-14 9:34 ` Avi Kivity
2009-04-14 16:07 ` H. Peter Anvin
2009-04-14 16:14 ` Avi Kivity
2009-04-14 16:25 ` H. Peter Anvin
2009-04-16 9:18 ` Avi Kivity
2009-04-16 22:40 ` H. Peter Anvin
2009-04-19 8:26 ` Avi Kivity
2009-04-14 17:31 ` Alan Cox
2009-04-14 17:32 ` H. Peter Anvin
2009-04-08 21:42 Glauber Costa
2009-04-11 16:37 ` Avi Kivity
2009-04-11 21:15 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090505135706.GA26401@poweredge.glommer \
--to=glommer@redhat.com \
--cc=avi@redhat.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox