From: Avi Kivity Subject: [PATCH] KVM: Fix mov to/from control register emulation, with r8-r15 as gpr Date: Thu, 30 Nov 2006 10:56:38 -0000 Message-ID: <20061130105638.7EADB25017B@cleopatra.q> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: akpm-3NddpPZAyC0@public.gmane.org, mingo-X9Un+BFzKDI@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Return-path: To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org Use the standrd modrm decoder instead of special casing these instructions. This fixes mov %rX, %crY with X >= 8 or Y >= 8. The fix only applies to AMD SVM, as Intel vmx decodes the instruction for us. It cures the FC5 installer crashing when loading the xor module. Signed-off-by: Avi Kivity Index: linux-2.6/drivers/kvm/x86_emulate.c =================================================================== --- linux-2.6.orig/drivers/kvm/x86_emulate.c +++ linux-2.6/drivers/kvm/x86_emulate.c @@ -155,7 +155,8 @@ static u8 twobyte_table[256] = { /* 0x10 - 0x1F */ 0, 0, 0, 0, 0, 0, 0, 0, ImplicitOps | ModRM, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x2F */ - ImplicitOps, ModRM, ImplicitOps, ModRM, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ModRM | ImplicitOps, ModRM, ModRM | ImplicitOps, ModRM, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x47 */ @@ -1295,17 +1296,14 @@ twobyte_special_insn: emulate_clts(ctxt->vcpu); break; case 0x20: /* mov cr, reg */ - b = insn_fetch(u8, 1, _eip); - if ((b & 0xc0) != 0xc0) + if (modrm_mod != 3) goto cannot_emulate; - _regs[b & 7] = realmode_get_cr(ctxt->vcpu, (b >> 3) & 7); + _regs[modrm_rm] = realmode_get_cr(ctxt->vcpu, modrm_reg); break; case 0x22: /* mov reg, cr */ - b = insn_fetch(u8, 1, _eip); - if ((b & 0xc0) != 0xc0) + if (modrm_mod != 3) goto cannot_emulate; - realmode_set_cr(ctxt->vcpu, (b >> 3) & 7, _regs[b & 7] & -1u, - &_eflags); + realmode_set_cr(ctxt->vcpu, modrm_reg, modrm_val, &_eflags); break; case 0xc7: /* Grp9 (cmpxchg8b) */ #if defined(__i386__) ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV