From: "Jan Beulich" <JBeulich@suse.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>, Keir Fraser <keir@xen.org>
Subject: [PATCH 2/3] x86emul: check host features alongside guest ones where needed
Date: Fri, 11 Mar 2016 10:34:28 -0700 [thread overview]
Message-ID: <56E30FB402000078000DBB8F@prv-mh.provo.novell.com> (raw)
In-Reply-To: <56E30EA102000078000DBB7F@prv-mh.provo.novell.com>
[-- Attachment #1: Type: text/plain, Size: 4296 bytes --]
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -1093,6 +1093,22 @@ static bool_t vcpu_has(
#define vcpu_must_have_cx16() vcpu_must_have(0x00000001, ECX, 13)
#define vcpu_must_have_avx() vcpu_must_have(0x00000001, ECX, 28)
+#ifdef __XEN__
+/*
+ * Note the (subtle?) difference between vcpu_must_have_<feature>() and
+ * vcpu_must_have(<feature>): The former only checks guest feature flags,
+ * while the latter also checks host ones, i.e. is required to be used when
+ * emulation code is using the same instruction class for carrying out the
+ * actual operation).
+ */
+#define host_and_vcpu_must_have(feat) ({ \
+ generate_exception_if(!cpu_has_##feat, EXC_UD, -1); \
+ vcpu_must_have_##feat(); \
+})
+#else
+#define host_and_vcpu_must_have(feat) vcpu_must_have_##feat()
+#endif
+
static int
in_longmode(
struct x86_emulate_ctxt *ctxt,
@@ -3102,7 +3118,7 @@ x86_emulate(
emulate_fpu_insn_memsrc("fildl", src.val);
break;
case 1: /* fisttp m32i */
- vcpu_must_have_sse3();
+ host_and_vcpu_must_have(sse3);
ea.bytes = 4;
dst = ea;
dst.type = OP_MEM;
@@ -3211,7 +3227,7 @@ x86_emulate(
emulate_fpu_insn_memsrc("fldl", src.val);
break;
case 1: /* fisttp m64i */
- vcpu_must_have_sse3();
+ host_and_vcpu_must_have(sse3);
ea.bytes = 8;
dst = ea;
dst.type = OP_MEM;
@@ -3319,7 +3335,7 @@ x86_emulate(
emulate_fpu_insn_memsrc("filds", src.val);
break;
case 1: /* fisttp m16i */
- vcpu_must_have_sse3();
+ host_and_vcpu_must_have(sse3);
ea.bytes = 2;
dst = ea;
dst.type = OP_MEM;
@@ -4115,9 +4131,9 @@ x86_emulate(
if ( vex.opcx == vex_none )
{
if ( vex.pfx & VEX_PREFIX_DOUBLE_MASK )
- vcpu_must_have_sse2();
+ host_and_vcpu_must_have(sse2);
else
- vcpu_must_have_sse();
+ host_and_vcpu_must_have(sse);
ea.bytes = 16;
SET_SSE_PREFIX(buf[0], vex.pfx);
get_fpu(X86EMUL_FPU_xmm, &fic);
@@ -4128,7 +4144,7 @@ x86_emulate(
((vex.reg != 0xf) &&
((ea.type == OP_MEM) ||
!(vex.pfx & VEX_PREFIX_SCALAR_MASK))));
- vcpu_must_have_avx();
+ host_and_vcpu_must_have(avx);
get_fpu(X86EMUL_FPU_ymm, &fic);
ea.bytes = 16 << vex.l;
}
@@ -4361,16 +4377,16 @@ x86_emulate(
{
case vex_66:
case vex_f3:
- vcpu_must_have_sse2();
+ host_and_vcpu_must_have(sse2);
buf[0] = 0x66; /* movdqa */
get_fpu(X86EMUL_FPU_xmm, &fic);
ea.bytes = 16;
break;
case vex_none:
if ( b != 0xe7 )
- vcpu_must_have_mmx();
+ host_and_vcpu_must_have(mmx);
else
- vcpu_must_have_sse();
+ host_and_vcpu_must_have(sse);
get_fpu(X86EMUL_FPU_mmx, &fic);
ea.bytes = 8;
break;
@@ -4382,7 +4398,7 @@ x86_emulate(
{
fail_if((vex.opcx != vex_0f) || (vex.reg != 0xf) ||
((vex.pfx != vex_66) && (vex.pfx != vex_f3)));
- vcpu_must_have_avx();
+ host_and_vcpu_must_have(avx);
get_fpu(X86EMUL_FPU_ymm, &fic);
ea.bytes = 16 << vex.l;
}
@@ -4688,7 +4704,7 @@ x86_emulate(
generate_exception_if((modrm_reg & 7) != 1, EXC_UD, -1);
generate_exception_if(ea.type != OP_MEM, EXC_UD, -1);
if ( op_bytes == 8 )
- vcpu_must_have_cx16();
+ host_and_vcpu_must_have(cx16);
op_bytes *= 2;
/* Get actual old value. */
[-- Attachment #2: x86emul-host-features.patch --]
[-- Type: text/plain, Size: 4358 bytes --]
x86emul: check host features alongside guest ones where needed
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -1093,6 +1093,22 @@ static bool_t vcpu_has(
#define vcpu_must_have_cx16() vcpu_must_have(0x00000001, ECX, 13)
#define vcpu_must_have_avx() vcpu_must_have(0x00000001, ECX, 28)
+#ifdef __XEN__
+/*
+ * Note the (subtle?) difference between vcpu_must_have_<feature>() and
+ * vcpu_must_have(<feature>): The former only checks guest feature flags,
+ * while the latter also checks host ones, i.e. is required to be used when
+ * emulation code is using the same instruction class for carrying out the
+ * actual operation).
+ */
+#define host_and_vcpu_must_have(feat) ({ \
+ generate_exception_if(!cpu_has_##feat, EXC_UD, -1); \
+ vcpu_must_have_##feat(); \
+})
+#else
+#define host_and_vcpu_must_have(feat) vcpu_must_have_##feat()
+#endif
+
static int
in_longmode(
struct x86_emulate_ctxt *ctxt,
@@ -3102,7 +3118,7 @@ x86_emulate(
emulate_fpu_insn_memsrc("fildl", src.val);
break;
case 1: /* fisttp m32i */
- vcpu_must_have_sse3();
+ host_and_vcpu_must_have(sse3);
ea.bytes = 4;
dst = ea;
dst.type = OP_MEM;
@@ -3211,7 +3227,7 @@ x86_emulate(
emulate_fpu_insn_memsrc("fldl", src.val);
break;
case 1: /* fisttp m64i */
- vcpu_must_have_sse3();
+ host_and_vcpu_must_have(sse3);
ea.bytes = 8;
dst = ea;
dst.type = OP_MEM;
@@ -3319,7 +3335,7 @@ x86_emulate(
emulate_fpu_insn_memsrc("filds", src.val);
break;
case 1: /* fisttp m16i */
- vcpu_must_have_sse3();
+ host_and_vcpu_must_have(sse3);
ea.bytes = 2;
dst = ea;
dst.type = OP_MEM;
@@ -4115,9 +4131,9 @@ x86_emulate(
if ( vex.opcx == vex_none )
{
if ( vex.pfx & VEX_PREFIX_DOUBLE_MASK )
- vcpu_must_have_sse2();
+ host_and_vcpu_must_have(sse2);
else
- vcpu_must_have_sse();
+ host_and_vcpu_must_have(sse);
ea.bytes = 16;
SET_SSE_PREFIX(buf[0], vex.pfx);
get_fpu(X86EMUL_FPU_xmm, &fic);
@@ -4128,7 +4144,7 @@ x86_emulate(
((vex.reg != 0xf) &&
((ea.type == OP_MEM) ||
!(vex.pfx & VEX_PREFIX_SCALAR_MASK))));
- vcpu_must_have_avx();
+ host_and_vcpu_must_have(avx);
get_fpu(X86EMUL_FPU_ymm, &fic);
ea.bytes = 16 << vex.l;
}
@@ -4361,16 +4377,16 @@ x86_emulate(
{
case vex_66:
case vex_f3:
- vcpu_must_have_sse2();
+ host_and_vcpu_must_have(sse2);
buf[0] = 0x66; /* movdqa */
get_fpu(X86EMUL_FPU_xmm, &fic);
ea.bytes = 16;
break;
case vex_none:
if ( b != 0xe7 )
- vcpu_must_have_mmx();
+ host_and_vcpu_must_have(mmx);
else
- vcpu_must_have_sse();
+ host_and_vcpu_must_have(sse);
get_fpu(X86EMUL_FPU_mmx, &fic);
ea.bytes = 8;
break;
@@ -4382,7 +4398,7 @@ x86_emulate(
{
fail_if((vex.opcx != vex_0f) || (vex.reg != 0xf) ||
((vex.pfx != vex_66) && (vex.pfx != vex_f3)));
- vcpu_must_have_avx();
+ host_and_vcpu_must_have(avx);
get_fpu(X86EMUL_FPU_ymm, &fic);
ea.bytes = 16 << vex.l;
}
@@ -4688,7 +4704,7 @@ x86_emulate(
generate_exception_if((modrm_reg & 7) != 1, EXC_UD, -1);
generate_exception_if(ea.type != OP_MEM, EXC_UD, -1);
if ( op_bytes == 8 )
- vcpu_must_have_cx16();
+ host_and_vcpu_must_have(cx16);
op_bytes *= 2;
/* Get actual old value. */
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-03-11 17:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-11 17:29 [PATCH 0/3] x86: instruction emulator improvements Jan Beulich
2016-03-11 17:33 ` [PATCH 1/3] x86: rename XMM* features to SSE* Jan Beulich
2016-03-11 17:34 ` Jan Beulich [this message]
2016-03-11 17:41 ` [PATCH 2/3] x86emul: check host features alongside guest ones where needed Andrew Cooper
2016-03-14 8:29 ` Jan Beulich
2016-03-14 8:52 ` Andrew Cooper
2016-03-11 17:35 ` [PATCH 3/3] x86emul: support MOVBE and CRC32 Jan Beulich
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=56E30FB402000078000DBB8F@prv-mh.provo.novell.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=keir@xen.org \
--cc=xen-devel@lists.xenproject.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;
as well as URLs for NNTP newsgroup(s).