Skip to contentSkip to conversation

x86/kvm/emulate.c: simplify NOP (opcode 0x90) check

PATCH In review Denys Vlasenko 2 participants 2 messages Jul 4, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/kvm/emulate.c: simplify NOP (opcode 0x90) check

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

CC Paolo Bonzini <[email protected]>
CC Avi Kivity <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Avi Kivity <[email protected]>
---
 arch/x86/kvm/emulate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/emulate.c +6 -1
index 2bc1e81..2dc48a1 100644
@@ -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 */
Signature · 1 line
1.8.1.4
#1 lore raw

Please send kvm patches to [email protected] too.

Quoted 2 lines · Denys Vlasenko

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.

Quoted 33 lines
CC Paolo Bonzini <[email protected]>
CC Avi Kivity <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Avi Kivity <[email protected]>
---
 arch/x86/kvm/emulate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/emulate.c +6 -1
index 2bc1e81..2dc48a1 100644
@@ -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 */
Signature · 1 line
1.8.1.4

--
Gleb.