Skip to content

Commit

Permalink
target/i386: Assert !SVME for user-only
Browse files Browse the repository at this point in the history
Most of the VMM instructions are already disabled for user-only,
by being usable only from ring 0.

The spec is intentionally loose for VMMCALL, allowing the VMM to
define syscalls for user-only.  However, we're not emulating any
VMM, so VMMCALL can just raise #UD unconditionally.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20210514151342.384376-31-richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed May 19, 2021
1 parent 9f55e5a commit 5d22388
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions target/i386/tcg/translate.c
Expand Up @@ -138,10 +138,12 @@ typedef struct DisasContext {
#define PE(S) true
#define CPL(S) 3
#define IOPL(S) 0
#define SVME(S) false
#else
#define PE(S) (((S)->flags & HF_PE_MASK) != 0)
#define CPL(S) ((S)->cpl)
#define IOPL(S) ((S)->iopl)
#define SVME(S) (((S)->flags & HF_SVME_MASK) != 0)
#endif
#if defined(CONFIG_USER_ONLY) && defined(TARGET_X86_64)
#define VM86(S) false
Expand Down Expand Up @@ -7495,7 +7497,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
break;

case 0xd8: /* VMRUN */
if (!(s->flags & HF_SVME_MASK) || !PE(s)) {
if (!SVME(s) || !PE(s)) {
goto illegal_op;
}
if (!check_cpl0(s)) {
Expand All @@ -7510,7 +7512,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
break;

case 0xd9: /* VMMCALL */
if (!(s->flags & HF_SVME_MASK)) {
if (!SVME(s)) {
goto illegal_op;
}
gen_update_cc_op(s);
Expand All @@ -7519,7 +7521,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
break;

case 0xda: /* VMLOAD */
if (!(s->flags & HF_SVME_MASK) || !PE(s)) {
if (!SVME(s) || !PE(s)) {
goto illegal_op;
}
if (!check_cpl0(s)) {
Expand All @@ -7531,7 +7533,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
break;

case 0xdb: /* VMSAVE */
if (!(s->flags & HF_SVME_MASK) || !PE(s)) {
if (!SVME(s) || !PE(s)) {
goto illegal_op;
}
if (!check_cpl0(s)) {
Expand All @@ -7543,8 +7545,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
break;

case 0xdc: /* STGI */
if ((!(s->flags & HF_SVME_MASK)
&& !(s->cpuid_ext3_features & CPUID_EXT3_SKINIT))
if ((!SVME(s) && !(s->cpuid_ext3_features & CPUID_EXT3_SKINIT))
|| !PE(s)) {
goto illegal_op;
}
Expand All @@ -7558,7 +7559,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
break;

case 0xdd: /* CLGI */
if (!(s->flags & HF_SVME_MASK) || !PE(s)) {
if (!SVME(s) || !PE(s)) {
goto illegal_op;
}
if (!check_cpl0(s)) {
Expand All @@ -7570,8 +7571,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
break;

case 0xde: /* SKINIT */
if ((!(s->flags & HF_SVME_MASK)
&& !(s->cpuid_ext3_features & CPUID_EXT3_SKINIT))
if ((!SVME(s) && !(s->cpuid_ext3_features & CPUID_EXT3_SKINIT))
|| !PE(s)) {
goto illegal_op;
}
Expand All @@ -7581,7 +7581,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
break;

case 0xdf: /* INVLPGA */
if (!(s->flags & HF_SVME_MASK) || !PE(s)) {
if (!SVME(s) || !PE(s)) {
goto illegal_op;
}
if (!check_cpl0(s)) {
Expand Down Expand Up @@ -8516,6 +8516,7 @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu)
g_assert(SS32(dc) == ((flags & HF_SS32_MASK) != 0));
g_assert(LMA(dc) == ((flags & HF_LMA_MASK) != 0));
g_assert(ADDSEG(dc) == ((flags & HF_ADDSEG_MASK) != 0));
g_assert(SVME(dc) == ((flags & HF_SVME_MASK) != 0));

dc->cc_op = CC_OP_DYNAMIC;
dc->cc_op_dirty = false;
Expand Down

0 comments on commit 5d22388

Please sign in to comment.