target-i386: tcg: Handle clflushopt/clwb/pcommit instructions
cover target-i386: tcg: Handle clflushopt/clwb/pcommit instructions
This series makes TCG accept the clwb instruction, and make it check the right CPUID bits when handling clflushopt and pcommit.
Tested using the kvm-unit-test patch I sent earlier today:
Subject: [kvm-unit-test RFC] x86: Memory instructions test case
Message-Id: <[email protected]>
Eduardo Habkost (2):
target-i386: tcg: Accept clwb instruction
target-i386: tcg: Check right CPUID bits for clflushopt/pcommit
target-i386/translate.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 target-i386: tcg: Accept clwb instruction
Accept the clwb instruction (66 0F AE /6) if its corresponding feature flag is enabled on CPUID[7].
--- target-i386/translate.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
target-i386/translate.c +12 -1
@@ -7716,10 +7716,21 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, }break ;case 5 :/* lfence */ -case 6 :/* mfence */ if ((modrm &0xc7 ) !=0xc0 || !(s->cpuid_features &CPUID_SSE2 )) goto illegal_op;break ; +case 6 :/* mfence/clwb */ +if (s->prefix &PREFIX_DATA ) { +/* clwb */ +if (!(s->cpuid_7_0_ebx_features &CPUID_7_0_EBX_CLWB )) + goto illegal_op; +gen_lea_modrm (env, s, modrm); + }else { +/* mfence */ +if ((modrm &0xc7 ) !=0xc0 || !(s->cpuid_features &CPUID_SSE2 )) + goto illegal_op; + } +break ;case 7 :/* sfence / clflush */ if ((modrm &0xc7 ) ==0xc0 ) {/* sfence */
Signature · 1 line
2.1.0
Re: [PATCH 1/2] target-i386: tcg: Accept clwb instruction
Quoted 16 lines · Eduardo Habkost
Accept the clwb instruction (66 0F AE /6) if its corresponding feature flag is enabled on CPUID[7].
Signed-off-by Eduardo Habkost <[email protected]>--- target-i386/translate.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)target-i386/translate.c +0
-0@@ -7716,10 +7716,21 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, }break ;case 5 :/* lfence */
target-i386/translate.c static target_ulong disas_insn(CPUX86State *env, DisasContext *s, · line 7727
Quoted 10 lines
target-i386/translate.c +6
-1-case 6 :/* mfence */ if ((modrm &0xc7 ) !=0xc0 || !(s->cpuid_features &CPUID_SSE2 )) goto illegal_op;break ; +case 6 :/* mfence/clwb */ +if (s->prefix &PREFIX_DATA ) { +/* clwb */ +if (!(s->cpuid_7_0_ebx_features &CPUID_7_0_EBX_CLWB )) + goto illegal_op; +gen_lea_modrm (env, s, modrm);
You should use gen_nop_modrm here, since we're not going to do anything with the address. Otherwise,
r~
Re: [PATCH 1/2] target-i386: tcg: Accept clwb instruction
Quoted 31 lines · Richard Henderson
Quoted 16 lines · Eduardo Habkost
Accept the clwb instruction (66 0F AE /6) if its corresponding feature flag is enabled on CPUID[7].
Signed-off-by Eduardo Habkost <[email protected]>--- target-i386/translate.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)target-i386/translate.c +0
-0@@ -7716,10 +7716,21 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, }break ;case 5 :/* lfence */ target-i386/translate.c static target_ulong disas_insn(CPUX86State *env, DisasContext *s, · line 7727
Quoted 10 lines
target-i386/translate.c +6
-1-case 6 :/* mfence */ if ((modrm &0xc7 ) !=0xc0 || !(s->cpuid_features &CPUID_SSE2 )) goto illegal_op;break ; +case 6 :/* mfence/clwb */ +if (s->prefix &PREFIX_DATA ) { +/* clwb */ +if (!(s->cpuid_7_0_ebx_features &CPUID_7_0_EBX_CLWB )) + goto illegal_op; +gen_lea_modrm (env, s, modrm);You should use
gen_nop_modrmhere, since we're not going to do anything with the address. Otherwise,
Quoted 1 line
Reviewed-by Richard Henderson <[email protected]>
Thanks! BTW, clflush uses gen_lea_modrm() too, does it do anything with the address somewhere else?
Signature · 1 line
Eduardo
Re: [PATCH 1/2] target-i386: tcg: Accept clwb instruction
Quoted 2 lines · Eduardo Habkost
Thanks! BTW, clflush uses
gen_lea_modrm()too, does it do anything with the address somewhere else?
Nope. It probably pre-dates the introduction of gen_nop_modrm.
r~
PATCH 2/2 target-i386: tcg: Check right CPUID bits for clflushopt/pcommit
In reply to Eduardo HabkostDetect the clflushopt and pcommit instructions and check their corresponding feature flags, instead of checking CPUID_SSE and CPUID_CLFLUSH.
--- target-i386/translate.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
target-i386/translate.c +20 -8
@@ -7731,16 +7731,28 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, goto illegal_op; }break ; -case 7 :/* sfence / clflush */ +case 7 :/* sfence / clflush / clflushopt / pcommit */ if ((modrm &0xc7 ) ==0xc0 ) { -/* sfence */ -/* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */ -if (!(s->cpuid_features &CPUID_SSE )) - goto illegal_op; +if (s->prefix &PREFIX_DATA ) { +/* pcommit */ +if (!(s->cpuid_7_0_ebx_features &CPUID_7_0_EBX_PCOMMIT )) + goto illegal_op; + }else { +/* sfence */ +/* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */ +if (!(s->cpuid_features &CPUID_SSE )) + goto illegal_op; + } }else { -/* clflush */ -if (!(s->cpuid_features &CPUID_CLFLUSH )) - goto illegal_op; +if (s->prefix &PREFIX_DATA ) { +/* clflushopt */ +if (!(s->cpuid_7_0_ebx_features &CPUID_7_0_EBX_CLFLUSHOPT )) + goto illegal_op; + }else { +/* clflush */ +if (!(s->cpuid_features &CPUID_CLFLUSH )) + goto illegal_op; + }gen_lea_modrm (env, s, modrm); }break ;
Signature · 1 line
2.1.0
Re: [PATCH 2/2] target-i386: tcg: Check right CPUID bits for clflushopt/pcommit
Quoted 8 lines · Eduardo Habkost
Detect the clflushopt and pcommit instructions and check their corresponding feature flags, instead of checking
CPUID_SSEandCPUID_CLFLUSH.Signed-off-by Eduardo Habkost <[email protected]>--- target-i386/translate.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
r~