* [PATCH v2] x86/emul: Implement the STAC and CLAC instructions
@ 2016-12-12 17:39 Andrew Cooper
2016-12-13 8:22 ` Jan Beulich
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Cooper @ 2016-12-12 17:39 UTC (permalink / raw)
To: Xen-devel; +Cc: Andrew Cooper, Jan Beulich
Note that unlike most privilege restricted instructions, STAC and CLAC are
documented to raise #UD rather than #GP[0], and indeed do so.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
v2:
* Exclude the use of legacy prefixes. Their exclusion is undocumented but
consistent with observed behaviour and the other Grp7 instructions.
* Drop the %cr4 check. Introduce a CPUID check instead.
---
xen/arch/x86/x86_emulate/x86_emulate.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c
index fe055cf..dfb6f47 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -433,6 +433,7 @@ typedef union {
#define CR4_OSXMMEXCPT (1<<10)
#define CR4_UMIP (1<<11)
#define CR4_OSXSAVE (1<<18)
+#define CR4_SMAP (1<<21)
/* EFLAGS bit definitions. */
#define EFLG_ID (1<<21)
@@ -1295,6 +1296,7 @@ static bool vcpu_has(
#define vcpu_has_bmi1() vcpu_has( 7, EBX, 3, ctxt, ops)
#define vcpu_has_hle() vcpu_has( 7, EBX, 4, ctxt, ops)
#define vcpu_has_rtm() vcpu_has( 7, EBX, 11, ctxt, ops)
+#define vcpu_has_smap() vcpu_has( 7, EBX, 20, ctxt, ops)
#define vcpu_must_have(feat) \
generate_exception_if(!vcpu_has_##feat(), EXC_UD)
@@ -4354,6 +4356,18 @@ x86_emulate(
switch( modrm )
{
+ case 0xca: /* clac */
+ case 0xcb: /* stac */
+ vcpu_must_have(smap);
+ generate_exception_if(
+ lock_prefix || vex.pfx ||
+ (_regs.eflags & EFLG_VM) || !mode_ring0(), EXC_UD);
+
+ _regs.eflags &= ~EFLG_AC;
+ if ( modrm == 0xcb )
+ _regs.eflags |= EFLG_AC;
+ goto no_writeback;
+
#ifdef __XEN__
case 0xd1: /* xsetbv */
{
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] x86/emul: Implement the STAC and CLAC instructions
2016-12-12 17:39 [PATCH v2] x86/emul: Implement the STAC and CLAC instructions Andrew Cooper
@ 2016-12-13 8:22 ` Jan Beulich
0 siblings, 0 replies; 2+ messages in thread
From: Jan Beulich @ 2016-12-13 8:22 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Xen-devel
>>> On 12.12.16 at 18:39, <andrew.cooper3@citrix.com> wrote:
> --- a/xen/arch/x86/x86_emulate/x86_emulate.c
> +++ b/xen/arch/x86/x86_emulate/x86_emulate.c
> @@ -433,6 +433,7 @@ typedef union {
> #define CR4_OSXMMEXCPT (1<<10)
> #define CR4_UMIP (1<<11)
> #define CR4_OSXSAVE (1<<18)
> +#define CR4_SMAP (1<<21)
I don't think this is needed anymore?
> @@ -4354,6 +4356,18 @@ x86_emulate(
>
> switch( modrm )
> {
> + case 0xca: /* clac */
> + case 0xcb: /* stac */
> + vcpu_must_have(smap);
> + generate_exception_if(
> + lock_prefix || vex.pfx ||
> + (_regs.eflags & EFLG_VM) || !mode_ring0(), EXC_UD);
mode_ring0() already excludes EFLAGS.VM being set. Also please
use more conventional indentation here (no need to break the line
before the first argument). With all of these taken care of
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-12-13 8:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-12 17:39 [PATCH v2] x86/emul: Implement the STAC and CLAC instructions Andrew Cooper
2016-12-13 8:22 ` Jan Beulich
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).