qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] target-i386: tcg: Handle clflushopt/clwb/pcommit instructions
@ 2015-11-04 21:24 Eduardo Habkost
  2015-11-04 21:24 ` [Qemu-devel] [PATCH 1/2] target-i386: tcg: Accept clwb instruction Eduardo Habkost
  2015-11-04 21:24 ` [Qemu-devel] [PATCH 2/2] target-i386: tcg: Check right CPUID bits for clflushopt/pcommit Eduardo Habkost
  0 siblings, 2 replies; 7+ messages in thread
From: Eduardo Habkost @ 2015-11-04 21:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Xiao Guangrong, kvm, Richard Henderson

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: <1446672079-8549-1-git-send-email-ehabkost@redhat.com>

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(-)

-- 
2.1.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 1/2] target-i386: tcg: Accept clwb instruction
  2015-11-04 21:24 [Qemu-devel] [PATCH 0/2] target-i386: tcg: Handle clflushopt/clwb/pcommit instructions Eduardo Habkost
@ 2015-11-04 21:24 ` Eduardo Habkost
  2015-11-06 11:04   ` Richard Henderson
  2015-11-04 21:24 ` [Qemu-devel] [PATCH 2/2] target-i386: tcg: Check right CPUID bits for clflushopt/pcommit Eduardo Habkost
  1 sibling, 1 reply; 7+ messages in thread
From: Eduardo Habkost @ 2015-11-04 21:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Xiao Guangrong, kvm, Richard Henderson

Accept the clwb instruction (66 0F AE /6) if its corresponding feature
flag is enabled on CPUID[7].

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/translate.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index b400d24..bac1685 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -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 */
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/2] target-i386: tcg: Check right CPUID bits for clflushopt/pcommit
  2015-11-04 21:24 [Qemu-devel] [PATCH 0/2] target-i386: tcg: Handle clflushopt/clwb/pcommit instructions Eduardo Habkost
  2015-11-04 21:24 ` [Qemu-devel] [PATCH 1/2] target-i386: tcg: Accept clwb instruction Eduardo Habkost
@ 2015-11-04 21:24 ` Eduardo Habkost
  2015-11-06 11:07   ` Richard Henderson
  1 sibling, 1 reply; 7+ messages in thread
From: Eduardo Habkost @ 2015-11-04 21:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Xiao Guangrong, kvm, Richard Henderson

Detect the clflushopt and pcommit instructions and check their
corresponding feature flags, instead of checking CPUID_SSE and
CPUID_CLFLUSH.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/translate.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index bac1685..a938967 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -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;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target-i386: tcg: Accept clwb instruction
  2015-11-04 21:24 ` [Qemu-devel] [PATCH 1/2] target-i386: tcg: Accept clwb instruction Eduardo Habkost
@ 2015-11-06 11:04   ` Richard Henderson
  2015-11-06 13:59     ` Eduardo Habkost
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2015-11-06 11:04 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel; +Cc: Paolo Bonzini, Xiao Guangrong, kvm

On 11/04/2015 10:24 PM, Eduardo Habkost wrote:
> Accept the clwb instruction (66 0F AE /6) if its corresponding feature
> flag is enabled on CPUID[7].
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>   target-i386/translate.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/target-i386/translate.c b/target-i386/translate.c
> index b400d24..bac1685 100644
> --- a/target-i386/translate.c
> +++ b/target-i386/translate.c
> @@ -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);

You should use gen_nop_modrm here, since we're not going to do anything with 
the address.  Otherwise,

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] target-i386: tcg: Check right CPUID bits for clflushopt/pcommit
  2015-11-04 21:24 ` [Qemu-devel] [PATCH 2/2] target-i386: tcg: Check right CPUID bits for clflushopt/pcommit Eduardo Habkost
@ 2015-11-06 11:07   ` Richard Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2015-11-06 11:07 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel; +Cc: Paolo Bonzini, Xiao Guangrong, kvm

On 11/04/2015 10:24 PM, Eduardo Habkost wrote:
> Detect the clflushopt and pcommit instructions and check their
> corresponding feature flags, instead of checking CPUID_SSE and
> CPUID_CLFLUSH.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>   target-i386/translate.c | 28 ++++++++++++++++++++--------
>   1 file changed, 20 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target-i386: tcg: Accept clwb instruction
  2015-11-06 11:04   ` Richard Henderson
@ 2015-11-06 13:59     ` Eduardo Habkost
  2015-11-06 14:13       ` Richard Henderson
  0 siblings, 1 reply; 7+ messages in thread
From: Eduardo Habkost @ 2015-11-06 13:59 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Paolo Bonzini, Xiao Guangrong, qemu-devel, kvm

On Fri, Nov 06, 2015 at 12:04:56PM +0100, Richard Henderson wrote:
> On 11/04/2015 10:24 PM, Eduardo Habkost wrote:
> >Accept the clwb instruction (66 0F AE /6) if its corresponding feature
> >flag is enabled on CPUID[7].
> >
> >Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> >---
> >  target-i386/translate.c | 13 ++++++++++++-
> >  1 file changed, 12 insertions(+), 1 deletion(-)
> >
> >diff --git a/target-i386/translate.c b/target-i386/translate.c
> >index b400d24..bac1685 100644
> >--- a/target-i386/translate.c
> >+++ b/target-i386/translate.c
> >@@ -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);
> 
> You should use gen_nop_modrm here, since we're not going to do anything with
> the address.  Otherwise,
> 
> Reviewed-by: Richard Henderson <rth@twiddle.net>

Thanks! BTW, clflush uses gen_lea_modrm() too, does it do anything with
the address somewhere else?

-- 
Eduardo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target-i386: tcg: Accept clwb instruction
  2015-11-06 13:59     ` Eduardo Habkost
@ 2015-11-06 14:13       ` Richard Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2015-11-06 14:13 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Paolo Bonzini, Xiao Guangrong, qemu-devel, kvm

On 11/06/2015 02:59 PM, Eduardo Habkost wrote:
> 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~

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-11-06 14:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-04 21:24 [Qemu-devel] [PATCH 0/2] target-i386: tcg: Handle clflushopt/clwb/pcommit instructions Eduardo Habkost
2015-11-04 21:24 ` [Qemu-devel] [PATCH 1/2] target-i386: tcg: Accept clwb instruction Eduardo Habkost
2015-11-06 11:04   ` Richard Henderson
2015-11-06 13:59     ` Eduardo Habkost
2015-11-06 14:13       ` Richard Henderson
2015-11-04 21:24 ` [Qemu-devel] [PATCH 2/2] target-i386: tcg: Check right CPUID bits for clflushopt/pcommit Eduardo Habkost
2015-11-06 11:07   ` Richard Henderson

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).