All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/kvm/emulate.c: simplify NOP (opcode 0x90) check
@ 2013-07-04 11:27 Denys Vlasenko
  2013-07-04 11:35 ` Gleb Natapov
  0 siblings, 1 reply; 2+ messages in thread
From: Denys Vlasenko @ 2013-07-04 11:27 UTC (permalink / raw)
  To: Gleb Natapov, linux-kernel; +Cc: Denys Vlasenko, Paolo Bonzini, Avi Kivity

We do not need to check for reg == RAX for opcodes 0x91...0x97.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Avi Kivity <avi.kivity@gmail.com>

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Avi Kivity <avi.kivity@gmail.com>
---
 arch/x86/kvm/emulate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 2bc1e81..2dc48a1 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -4544,9 +4544,14 @@ special_insn:
 	case 0x8d: /* lea r16/r32, m */
 		ctxt->dst.val = ctxt->src.addr.mem.ea;
 		break;
-	case 0x90 ... 0x97: /* nop / xchg reg, rax */
+	case 0x90: /* nop / xchg reg, rax */
+		/* Not all opcodes 90 are NOPs, only ones which refer to RAX */
+		/* For example, 49 90 is xchg %rax,%r8 */
+		/* Bare 90 and 40 90 (redundant REX prefix) are nop */
 		if (ctxt->dst.addr.reg == reg_rmw(ctxt, VCPU_REGS_RAX))
 			break;
+		/* Fall through */
+	case 0x91 ... 0x97: /* xchg reg, rax */
 		rc = em_xchg(ctxt);
 		break;
 	case 0x98: /* cbw/cwde/cdqe */
-- 
1.8.1.4

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

* Re: [PATCH v2] x86/kvm/emulate.c: simplify NOP (opcode 0x90) check
  2013-07-04 11:27 [PATCH v2] x86/kvm/emulate.c: simplify NOP (opcode 0x90) check Denys Vlasenko
@ 2013-07-04 11:35 ` Gleb Natapov
  0 siblings, 0 replies; 2+ messages in thread
From: Gleb Natapov @ 2013-07-04 11:35 UTC (permalink / raw)
  To: Denys Vlasenko; +Cc: linux-kernel, Paolo Bonzini, Avi Kivity

Please send kvm patches to kvm@vger.kernel.org too.

On Thu, Jul 04, 2013 at 01:27:00PM +0200, Denys Vlasenko wrote:
> We do not need to check for reg == RAX for opcodes 0x91...0x97.
> 
The is no reason to optimize here. This is not performance sensitive
path, far from it. If not for "clear high bits" behaviour of em_xchg() we
would just call it to emulate nop.

> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Avi Kivity <avi.kivity@gmail.com>
> 
> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Avi Kivity <avi.kivity@gmail.com>
> ---
>  arch/x86/kvm/emulate.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 2bc1e81..2dc48a1 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -4544,9 +4544,14 @@ special_insn:
>  	case 0x8d: /* lea r16/r32, m */
>  		ctxt->dst.val = ctxt->src.addr.mem.ea;
>  		break;
> -	case 0x90 ... 0x97: /* nop / xchg reg, rax */
> +	case 0x90: /* nop / xchg reg, rax */
> +		/* Not all opcodes 90 are NOPs, only ones which refer to RAX */
> +		/* For example, 49 90 is xchg %rax,%r8 */
> +		/* Bare 90 and 40 90 (redundant REX prefix) are nop */
>  		if (ctxt->dst.addr.reg == reg_rmw(ctxt, VCPU_REGS_RAX))
>  			break;
> +		/* Fall through */
> +	case 0x91 ... 0x97: /* xchg reg, rax */
>  		rc = em_xchg(ctxt);
>  		break;
>  	case 0x98: /* cbw/cwde/cdqe */
> -- 
> 1.8.1.4

--
			Gleb.

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

end of thread, other threads:[~2013-07-04 11:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-04 11:27 [PATCH v2] x86/kvm/emulate.c: simplify NOP (opcode 0x90) check Denys Vlasenko
2013-07-04 11:35 ` Gleb Natapov

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.