commit 11fcadf1400313770480d6d5c4edcc1472c77b0c Author: Andre Przywara Date: Sun Jul 25 15:07:35 2010 +0200 svm: implement CR access part of DecodeAssist Newer SVM implementations (Bulldozer) now give the used general purpose register on a MOV-CR intercept explictly. This avoids fetching and decoding the instruction from guest's memory and speeds up some Windows guest, which exercise CR8 quite often. Signed-off-by: Andre Przywara diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 861c2c7..c406bd3 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -1130,6 +1130,25 @@ static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs) __update_guest_eip(regs, inst_len); } +static int svm_vmexit_do_cr_access(struct vmcb_struct *vmcb, + struct cpu_user_regs *regs) +{ + int gp, cr, dir; + + cr = vmcb->exitcode - VMEXIT_CR0_READ; + dir = (cr > 15); + cr = cr % 16; + gp = vmcb->exitinfo1 & 0x0F; + + if (dir) + hvm_mov_to_cr(gp, cr, regs); + else + hvm_mov_from_cr(cr, gp, regs); + + __update_guest_eip(regs, vmcb->nextrip - vmcb->rip); + return 0; +} + static void svm_dr_access(struct vcpu *v, struct cpu_user_regs *regs) { HVMTRACE_0D(DR_WRITE); @@ -1906,9 +1925,18 @@ asmlinkage void svm_vmexit_handler(struct cpu_user_regs *regs) __update_guest_eip(regs, vmcb->exitinfo2 - vmcb->rip); break; } - /* fallthrough to emulation if a string instruction */ + if ( !handle_mmio() ) + hvm_inject_exception(TRAP_gp_fault, 0, 0); + break; + case VMEXIT_CR0_READ ... VMEXIT_CR15_READ: case VMEXIT_CR0_WRITE ... VMEXIT_CR15_WRITE: + if ((vmcb->exitinfo1 & (1ULL << 63) && + svm_vmexit_do_cr_access(vmcb, regs)) || + !handle_mmio() ) + hvm_inject_exception(TRAP_gp_fault, 0, 0); + break; + case VMEXIT_INVLPG: case VMEXIT_INVLPGA: if ( !handle_mmio() )