From: Gleb Natapov <gleb@redhat.com>
To: Borislav Petkov <bp@alien8.de>
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: Thu, 11 Apr 2013 17:28:18 +0300 [thread overview]
Message-ID: <20130411142818.GA17919@redhat.com> (raw)
In-Reply-To: <20130411001815.GA17544@pd.tnic>
On Thu, Apr 11, 2013 at 02:18:15AM +0200, Borislav Petkov wrote:
> On Wed, Apr 10, 2013 at 03:16:39PM +0300, Gleb Natapov wrote:
> > Right, the question is how kernel can tell QEMU that the cpuid bit is
> > supported but should not be set unless explicitly asked by an user.
>
> Actually, this seems to work with the patch below based on whether you
> have "+movbe" in the -cpu option or not.
>
The problem is that -cpu host will have it unconditionally and this is
definitely not what we want.
> Anyway, here's the second version with hopefully all comments and
> suggestions addressed.
>
Thanks, will review it later.
> Thanks.
>
> --
> >From 612fc75a732ad16332f270b7c52a68c89e3565ca Mon Sep 17 00:00:00 2001
> From: Borislav Petkov <bp@suse.de>
> Date: Thu, 11 Apr 2013 02:06:30 +0200
> Subject: [PATCH] kvm: Emulate MOVBE
>
> This basically came from the need to be able to boot 32-bit Atom SMP
> guests on an AMD host, i.e. host which doesn't support MOVBE. As a
> matter of fact, qemu has since recently received MOVBE support but we
> cannot share that with kvm emulation and thus we have to do this in the
> host.
>
> We piggyback on the #UD path and emulate the MOVBE functionality. With
> it, an 8-core SMP guest boots in under 6 seconds.
>
> Also, requesting MOVBE emulation needs to happen explicitly to work,
> i.e. qemu -cpu n270,+movbe...
>
> Signed-off-by: Andre Przywara <andre@andrep.de>
> Signed-off-by: Borislav Petkov <bp@suse.de>
> ---
> arch/x86/kvm/cpuid.c | 2 +-
> arch/x86/kvm/emulate.c | 39 +++++++++++++++++++++++++++++++++++++--
> 2 files changed, 38 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index a20ecb5b6cbf..2d44fc4fd855 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -273,7 +273,7 @@ static int do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
> cpuid_mask(&entry->ecx, 4);
> /* we support x2apic emulation even if host does not support
> * it since we emulate x2apic in software */
> - entry->ecx |= F(X2APIC);
> + entry->ecx |= F(X2APIC) | F(MOVBE);
> break;
> /* function 2 entries are STATEFUL. That is, repeated cpuid commands
> * may return different values. This forces us to get_cpu() before
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index a335cc6cde72..9011c7a656ad 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -152,6 +152,7 @@
> #define Avx ((u64)1 << 43) /* Advanced Vector Extensions */
> #define Fastop ((u64)1 << 44) /* Use opcode::u.fastop */
> #define NoWrite ((u64)1 << 45) /* No writeback */
> +#define EmulateOnUD ((u64)1 << 46) /* emulate if unsupported by the host */
>
> #define X2(x...) x, x
> #define X3(x...) X2(x), x
> @@ -3107,6 +3108,30 @@ static int em_mov(struct x86_emulate_ctxt *ctxt)
> return X86EMUL_CONTINUE;
> }
>
> +static int em_movbe(struct x86_emulate_ctxt *ctxt)
> +{
> + switch (ctxt->op_bytes) {
> + case 2:
> + *(u16 *)ctxt->dst.valptr = swab16(*(u16 *)ctxt->src.valptr);
> + break;
> + 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;
> + break;
> + case 8:
> + *(u64 *)ctxt->dst.valptr = swab64(*(u64 *)ctxt->src.valptr);
> + break;
> + default:
> + return X86EMUL_PROPAGATE_FAULT;
> + }
> + return X86EMUL_CONTINUE;
> +}
> +
> static int em_cr_write(struct x86_emulate_ctxt *ctxt)
> {
> if (ctxt->ops->set_cr(ctxt, ctxt->modrm_reg, ctxt->src.val))
> @@ -4033,6 +4058,11 @@ static const struct opcode twobyte_table[256] = {
> N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N
> };
>
> +static const struct opcode threebyte_table[] = {
> + [0xf0] = I(DstReg | SrcMem | ModRM | Mov | EmulateOnUD, em_movbe),
> + [0xf1] = I(DstMem | SrcReg | ModRM | Mov | EmulateOnUD, em_movbe),
> +};
> +
> #undef D
> #undef N
> #undef G
> @@ -4320,6 +4350,9 @@ done_prefixes:
> ctxt->twobyte = 1;
> ctxt->b = insn_fetch(u8, ctxt);
> opcode = twobyte_table[ctxt->b];
> +
> + if (ctxt->b == 0x38)
> + opcode = threebyte_table[insn_fetch(u8, ctxt)];
> }
> ctxt->d = opcode.flags;
>
> @@ -4376,8 +4409,10 @@ done_prefixes:
> if (ctxt->d == 0 || (ctxt->d & Undefined))
> return EMULATION_FAILED;
>
> - if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn)
> - return EMULATION_FAILED;
> + if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn) {
> + if (!(ctxt->d & EmulateOnUD))
> + return EMULATION_FAILED;
> + }
>
> if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack))
> ctxt->op_bytes = 8;
> --
> 1.8.2.135.g7b592fa
>
>
> --
> Regards/Gruss,
> Boris.
>
> Sent from a fat crate under my desk. Formatting is fine.
> --
--
Gleb.
next prev parent reply other threads:[~2013-04-11 14:28 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 [this message]
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
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=20130411142818.GA17919@redhat.com \
--to=gleb@redhat.com \
--cc=andre@andrep.de \
--cc=bp@alien8.de \
--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.