mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
x86: Implement SMEP and SMAP
This patch implements Supervisor Mode Execution Prevention (SMEP) and Supervisor Mode Access Prevention (SMAP) for x86. The purpose of the patch, obviously, is to help kernel developers debug the support for those features. A fair bit of the code relates to the handling of CPUID features. The CPUID code probably would get greatly simplified if all the feature bit words were unified into a single vector object, but in the interest of producing a minimal patch for SMEP/SMAP, and because I had very limited time for this project, I followed the existing style. [ v2: don't change the definition of the qemu64 CPU shorthand, since that breaks loading old snapshots. Per Anthony Liguori this can be fixed once the CPU feature set is snapshot. Change the coding style slightly to conform to checkpatch.pl. ] Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
4a19e505df
commit
a9321a4d49
6 changed files with 207 additions and 49 deletions
|
@ -107,6 +107,7 @@ typedef struct DisasContext {
|
|||
int cpuid_ext_features;
|
||||
int cpuid_ext2_features;
|
||||
int cpuid_ext3_features;
|
||||
int cpuid_7_0_ebx_features;
|
||||
} DisasContext;
|
||||
|
||||
static void gen_eob(DisasContext *s);
|
||||
|
@ -6556,7 +6557,7 @@ static target_ulong disas_insn(DisasContext *s, target_ulong pc_start)
|
|||
}
|
||||
gen_pop_update(s);
|
||||
s->cc_op = CC_OP_EFLAGS;
|
||||
/* abort translation because TF flag may change */
|
||||
/* abort translation because TF/AC flag may change */
|
||||
gen_jmp_im(s->pc - s->cs_base);
|
||||
gen_eob(s);
|
||||
}
|
||||
|
@ -7206,6 +7207,24 @@ static target_ulong disas_insn(DisasContext *s, target_ulong pc_start)
|
|||
gen_helper_mwait(cpu_env, tcg_const_i32(s->pc - pc_start));
|
||||
gen_eob(s);
|
||||
break;
|
||||
case 2: /* clac */
|
||||
if (!(s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_SMAP) ||
|
||||
s->cpl != 0) {
|
||||
goto illegal_op;
|
||||
}
|
||||
gen_helper_clac(cpu_env);
|
||||
gen_jmp_im(s->pc - s->cs_base);
|
||||
gen_eob(s);
|
||||
break;
|
||||
case 3: /* stac */
|
||||
if (!(s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_SMAP) ||
|
||||
s->cpl != 0) {
|
||||
goto illegal_op;
|
||||
}
|
||||
gen_helper_stac(cpu_env);
|
||||
gen_jmp_im(s->pc - s->cs_base);
|
||||
gen_eob(s);
|
||||
break;
|
||||
default:
|
||||
goto illegal_op;
|
||||
}
|
||||
|
@ -7901,15 +7920,13 @@ static inline void gen_intermediate_code_internal(CPUX86State *env,
|
|||
/* select memory access functions */
|
||||
dc->mem_index = 0;
|
||||
if (flags & HF_SOFTMMU_MASK) {
|
||||
if (dc->cpl == 3)
|
||||
dc->mem_index = 2 * 4;
|
||||
else
|
||||
dc->mem_index = 1 * 4;
|
||||
dc->mem_index = (cpu_mmu_index(env) + 1) << 2;
|
||||
}
|
||||
dc->cpuid_features = env->cpuid_features;
|
||||
dc->cpuid_ext_features = env->cpuid_ext_features;
|
||||
dc->cpuid_ext2_features = env->cpuid_ext2_features;
|
||||
dc->cpuid_ext3_features = env->cpuid_ext3_features;
|
||||
dc->cpuid_7_0_ebx_features = env->cpuid_7_0_ebx_features;
|
||||
#ifdef TARGET_X86_64
|
||||
dc->lma = (flags >> HF_LMA_SHIFT) & 1;
|
||||
dc->code64 = (flags >> HF_CS64_SHIFT) & 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue