All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] tcg/i386: 'nop' instruction with 'lock' prefix is illegal
@ 2017-05-13 15:58 Pranith Kumar
  2017-05-14 21:12 ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Pranith Kumar @ 2017-05-13 15:58 UTC (permalink / raw)
  To: Paolo Bonzini, Richard Henderson, Eduardo Habkost,
	open list:All patches CC here

The instruction "lock nopl (%rax)" should raise an exception. However,
we don't do that since we do not check for lock prefix for nop
instructions. The following patch adds this check and makes the
behavior similar to hardware.

Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
---
 target/i386/translate.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/target/i386/translate.c b/target/i386/translate.c
index 1d1372fb43..76f4ccd3b4 100644
--- a/target/i386/translate.c
+++ b/target/i386/translate.c
@@ -7881,6 +7881,9 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
         gen_nop_modrm(env, s, modrm);
         break;
     case 0x119: case 0x11c ... 0x11f: /* nop (multi byte) */
+        if (prefixes & PREFIX_LOCK) {
+            goto illegal_op;
+        }
         modrm = cpu_ldub_code(env, s->pc++);
         gen_nop_modrm(env, s, modrm);
         break;
-- 
2.13.0

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

* Re: [Qemu-devel] [PATCH] tcg/i386: 'nop' instruction with 'lock' prefix is illegal
  2017-05-13 15:58 [Qemu-devel] [PATCH] tcg/i386: 'nop' instruction with 'lock' prefix is illegal Pranith Kumar
@ 2017-05-14 21:12 ` Richard Henderson
  2017-05-15 14:58   ` Pranith Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2017-05-14 21:12 UTC (permalink / raw)
  To: Pranith Kumar, Paolo Bonzini, Eduardo Habkost,
	open list:All patches CC here

On 05/13/2017 08:58 AM, Pranith Kumar wrote:
> The instruction "lock nopl (%rax)" should raise an exception. However,
> we don't do that since we do not check for lock prefix for nop
> instructions. The following patch adds this check and makes the
> behavior similar to hardware.
> 
> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
> ---
>   target/i386/translate.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/target/i386/translate.c b/target/i386/translate.c
> index 1d1372fb43..76f4ccd3b4 100644
> --- a/target/i386/translate.c
> +++ b/target/i386/translate.c
> @@ -7881,6 +7881,9 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
>           gen_nop_modrm(env, s, modrm);
>           break;
>       case 0x119: case 0x11c ... 0x11f: /* nop (multi byte) */
> +        if (prefixes & PREFIX_LOCK) {
> +            goto illegal_op;
> +        }
>           modrm = cpu_ldub_code(env, s->pc++);
>           gen_nop_modrm(env, s, modrm);
>           break;
> 
Surely you'd also want to make this change for 0x11a and 0x11b.  Which would 
also simplify that code a bit.

That said, there's *lots* of missing LOCK prefix checks.  What brings this one 
in particular to your attention?


r~

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

* Re: [Qemu-devel] [PATCH] tcg/i386: 'nop' instruction with 'lock' prefix is illegal
  2017-05-14 21:12 ` Richard Henderson
@ 2017-05-15 14:58   ` Pranith Kumar
  0 siblings, 0 replies; 3+ messages in thread
From: Pranith Kumar @ 2017-05-15 14:58 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Paolo Bonzini, Eduardo Habkost, open list:All patches CC here

On Sun, May 14, 2017 at 5:12 PM, Richard Henderson <rth@twiddle.net> wrote:
>>
> Surely you'd also want to make this change for 0x11a and 0x11b.  Which would
> also simplify that code a bit.
>
> That said, there's *lots* of missing LOCK prefix checks.  What brings this
> one in particular to your attention?
>

The motivation for this change is here:
https://github.com/aquynh/capstone/issues/915

Apparently LLVM generates it in certain scenarios when padding with
multi-byte nop (it shouldn't).

>From what I understand, a proper instruction like "lock; <valid inst>"
is converted to "lock; multi-byte nop; <valid inst>" due to code
alignment.

There were bugs reported regarding this:
https://bugs.chromium.org/p/nativeclient/issues/detail?id=3929

I am not sure we want to fix this, but I thought it would be easy
enough to cover this case.

Thanks,
-- 
Pranith

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

end of thread, other threads:[~2017-05-15 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-13 15:58 [Qemu-devel] [PATCH] tcg/i386: 'nop' instruction with 'lock' prefix is illegal Pranith Kumar
2017-05-14 21:12 ` Richard Henderson
2017-05-15 14:58   ` Pranith Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.