From: Avi Kivity <avi@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
kvm@vger.kernel.org,
Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Subject: Re: [RFC] KVM: x86: emulate movdqa
Date: Sun, 08 Jan 2012 18:41:04 +0200 [thread overview]
Message-ID: <4F09C720.3090006@redhat.com> (raw)
In-Reply-To: <CAJSP0QV21UEJ2FJoj-VXQvUicyGAAUYQ-0a+H1S1ueLsWiLQ2Q@mail.gmail.com>
On 01/08/2012 06:21 PM, Stefan Hajnoczi wrote:
> On Sun, Jan 8, 2012 at 10:32 AM, Avi Kivity <avi@redhat.com> wrote:
> > On 01/07/2012 12:26 PM, Stefan Hajnoczi wrote:
> >>
> >> movdqa %xmm0,(%rdi)
> >>
> >> This patch adds movdqa to the emulator but does not implement #GP when
> >> the memory operand is unaligned to 16 bytes. I'm not sure whether
> >> alignment checking can be implemented as an opcode .flag or if it needs
> >> to be done in em_movdqa().
> >
> > It should actually be automatic when the Sse flag is present, since it's
> > the norm for almost all SSE instructions. There should be a .flag to
> > override it for movdqu.
>
> When writing a kvm-unit-test for movdqa I found that alignment
> checking happens before the page fault (makes sense). That means
> misalignment is detected by the CPU while still in guest mode. The
> emulator never sees the instruction because #GP is raised and handled
> in the guest.
Right. The way to test this is to change the instruction while the vcpu
is processing it, see for example x86/svm.c's
corrupt_cr3_intercept_bypass().
> I also didn't see other instances of alignment checking in the
> emulator (e.g. eflags AC). I guess the same situation applies there.
Yes.
> Can you think of a case where we need to perform alignment checking in
> the emulator?
The case that x86/svm.c is checking for is a security issue.
Guests don't normally turn eflags.AC on, so I don't expect issues
there. I also don't see issues with SSE alignment, especially as AVX
removes it (for VEX encoded instructions). However, it's good to stick
to the spec, there are always surprise issues when you don't.
>
> >> A more fundamental question: why do we have to emulate this guest
> >> userspace SSE instruction in the first place? This host machine lacks
> >> EPT but can't we service the page fault and then retry execution inside
> >> the guest?
> >
> > Not when the target is mmio - there is no possible mapping. With your
> > patch, is there a kvm_mmio trace right after the movdqa emulation?
>
> You are right. These instructions are accessing the VGA area at 0xa0000.
> >
> > Need the Mov flag too (I see it's missing for movdqu as well); otherwise
> > the emulator will RMW the destination.
>
> The Mov is already given by the GP() group prefix.
>
Ah. Not sure it was a good idea. The whole trend towards em_foo() is
motivated by the idea of having everything about an instruction in one
place, and this doesn't help there. On the other hand, I can see many
SSE instructions repeating this pattern. We'll just have to see how it
evolves.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2012-01-08 16:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-07 10:26 [RFC] KVM: x86: emulate movdqa Stefan Hajnoczi
2012-01-08 10:32 ` Avi Kivity
2012-01-08 16:21 ` Stefan Hajnoczi
2012-01-08 16:36 ` Gleb Natapov
2012-01-08 16:41 ` Avi Kivity [this message]
2012-01-09 8:52 ` Takuya Yoshikawa
2012-01-09 10:02 ` Avi Kivity
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=4F09C720.3090006@redhat.com \
--to=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=stefanha@gmail.com \
--cc=stefanha@linux.vnet.ibm.com \
--cc=yoshikawa.takuya@oss.ntt.co.jp \
/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;
as well as URLs for NNTP newsgroup(s).