From: Borislav Petkov <bp@alien8.de>
To: Gleb Natapov <gleb@redhat.com>
Cc: "Andre Przywara" <andre@andrep.de>,
kvm@vger.kernel.org, "Jörg Rödel" <joro@8bytes.org>,
"H. Peter Anvin" <hpa@zytor.com>, x86-ml <x86@kernel.org>
Subject: Re: [PATCH -v2] kvm: Emulate MOVBE
Date: Sun, 14 Apr 2013 23:02:18 +0200 [thread overview]
Message-ID: <20130414210218.GF20547@pd.tnic> (raw)
In-Reply-To: <20130414084303.GE17919@redhat.com>
On Sun, Apr 14, 2013 at 11:43:03AM +0300, Gleb Natapov wrote:
> > +#define EmulateOnUD ((u64)1 << 46) /* emulate if unsupported by the host */
> >
> Just rename VendorSpecific to EmulateOnUD. The meaning is the same.
done.
> > +static int em_movbe(struct x86_emulate_ctxt *ctxt)
> > +{
> > + switch (ctxt->op_bytes) {
> > + case 2:
> > + *(u16 *)ctxt->dst.valptr = swab16(*(u16 *)ctxt->src.valptr);
> What's wrong with: ctxt->dst.val = swab16((u16)ctxt->src.val)?
This doesn't work for the 16-bit swab because of the following
functionality of MOVBE:
"When the operand size is 16 bits, the upper word of the destination
register remains unchanged."
Now here's what gcc produces here:
movzwl 112(%rdi), %eax # ctxt_5(D)->src.D.27823.val, tmp83
rolw $8, %ax #, tmp83
movzwl %ax, %eax # tmp83, tmp84
movq %rax, 240(%rdi) # tmp84,
See the zero-extension happening twice (second one should not be needed,
even) and it is actually writing the whole 64-bit value in %rax back
which effectively destroys the upper word?
However, this, a bit uglier version works:
*(u16 *)&ctxt->dst.val = swab16((u16)ctxt->src.val);
movzwl 112(%rdi), %eax # ctxt_5(D)->src.D.27823.val, tmp82
rolw $8, %ax #, tmp82
movw %ax, 240(%rdi) # tmp82, MEM[(u16 *)ctxt_5(D) + 240B]
Whichever version we take, I'll slap a comment explaining why we're
doing it differently for 16-bit.
> > + case 4:
> > + *(u32 *)ctxt->dst.valptr = swab32(*(u32 *)ctxt->src.valptr);
> > +
> > + /*
> > + * clear upper dword for 32-bit operand size in 64-bit mode.
> > + */
> > + if (ctxt->mode == X86EMUL_MODE_PROT64)
> > + *((u32 *)ctxt->dst.valptr + 1) = 0x0;
> It should be clean without this this.
Right, this should probably work because for 32-bit, we don't care
about the zero-extended upper dword and in 64-bit mode we want to do it
anyway.
> > + break;
> > + case 8:
> > + *(u64 *)ctxt->dst.valptr = swab64(*(u64 *)ctxt->src.valptr);
Ditto for this one.
> > +static const struct opcode threebyte_table[] = {
> > + [0xf0] = I(DstReg | SrcMem | ModRM | Mov | EmulateOnUD, em_movbe),
> > + [0xf1] = I(DstMem | SrcReg | ModRM | Mov | EmulateOnUD, em_movbe),
> > +};
> > +
> Populate the whole table explicitly please. You can use X16(N) to make it
> short. The encoding is also wrong since 0F 38 F0/F1 instruction decoding
> depend on a prefix.
... on the absence of a prefix, actually.
> Same opcode is decoded as CRC32 with f2 prefix. We have Prefix
> mechanism for such instructions, but it currently assumes that 66 and
> f2/f3 prefixes are mutually exclusive, but in this case they are not,
> ugh.
Yeah, I'm lazy and wanted to leave the honors to the poor soul who
implements the whole 0F_38h opcode map. :-)
Ok, I probably could do something similar to pfx_vmovntpx with the GP
macro for the F0/F1 opcodes. I'll give it a try when I get a chance
soonish.
> > +
> > + if (ctxt->b == 0x38)
> > + opcode = threebyte_table[insn_fetch(u8, ctxt)];
> ctxt->b = insn_fetch(u8, ctxt);
> opcode = threebyte_table[ctxt->b];
>
> Otherwise OpImplicit type of decoding will not work for three byte
> instructions. Also should rename twobyte into opbytes and set it to 1,
> 2 or 3. I prefer that three byte instruction decoding will be sent as a
> separate patch.
Ok.
Thanks.
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
next prev parent reply other threads:[~2013-04-14 21:02 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-09 23:46 [RFC PATCH] Emulate MOVBE Borislav Petkov
2013-04-10 0:03 ` Borislav Petkov
2013-04-10 0:04 ` H. Peter Anvin
2013-04-10 9:53 ` Borislav Petkov
2013-04-10 9:29 ` Andre Przywara
2013-04-10 10:08 ` Gleb Natapov
2013-04-10 10:17 ` Borislav Petkov
2013-04-10 10:21 ` Gleb Natapov
2013-04-10 10:39 ` Andre Przywara
2013-04-10 12:16 ` Gleb Natapov
2013-04-11 0:18 ` [PATCH -v2] kvm: " Borislav Petkov
2013-04-11 14:28 ` Gleb Natapov
2013-04-11 15:37 ` Borislav Petkov
2013-04-14 7:41 ` Gleb Natapov
2013-04-14 17:32 ` Borislav Petkov
2013-04-14 18:36 ` H. Peter Anvin
2013-04-14 19:09 ` Borislav Petkov
2013-04-14 19:40 ` H. Peter Anvin
2013-04-16 17:42 ` Gleb Natapov
2013-04-17 11:04 ` Borislav Petkov
2013-04-17 13:38 ` Gleb Natapov
2013-04-17 14:02 ` Borislav Petkov
2013-04-18 22:48 ` Borislav Petkov
2013-04-21 9:46 ` Gleb Natapov
2013-04-21 11:30 ` Borislav Petkov
2013-04-21 12:51 ` Gleb Natapov
2013-04-23 23:41 ` Borislav Petkov
2013-04-23 23:50 ` H. Peter Anvin
2013-04-24 8:42 ` Gleb Natapov
2013-04-24 8:47 ` Borislav Petkov
2013-04-14 8:43 ` Gleb Natapov
2013-04-14 21:02 ` Borislav Petkov [this message]
2013-04-16 11:36 ` Paolo Bonzini
2013-04-21 11:46 ` Borislav Petkov
2013-04-21 12:23 ` Borislav Petkov
2013-04-22 8:53 ` Paolo Bonzini
2013-04-22 9:38 ` Borislav Petkov
2013-04-22 9:42 ` Gleb Natapov
2013-04-22 9:52 ` Borislav Petkov
2013-04-22 9:58 ` Gleb Natapov
2013-04-22 13:49 ` Borislav Petkov
2013-04-26 16:08 ` Borislav Petkov
2013-04-16 11:47 ` [RFC PATCH] " Paolo Bonzini
2013-04-16 12:08 ` Borislav Petkov
2013-04-16 12:13 ` H. Peter Anvin
2013-04-16 17:28 ` Gleb Natapov
2013-04-17 10:42 ` Paolo Bonzini
2013-04-17 13:33 ` Gleb Natapov
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=20130414210218.GF20547@pd.tnic \
--to=bp@alien8.de \
--cc=andre@andrep.de \
--cc=gleb@redhat.com \
--cc=hpa@zytor.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.