From ad3b9c5faa13cca130e56e8dbcd0febf8d2ba961 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Mon, 18 Apr 2011 10:01:06 +0100 Subject: [PATCH] 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 Signed-off-by: Keir Fraser --- xen/arch/x86/hvm/svm/svm.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index fe0a62559f..18acd562a0 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -1130,6 +1130,23 @@ static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs) __update_guest_eip(regs, inst_len); } +static void svm_vmexit_do_cr_access( + struct vmcb_struct *vmcb, struct cpu_user_regs *regs) +{ + int gp, cr, dir, rc; + + cr = vmcb->exitcode - VMEXIT_CR0_READ; + dir = (cr > 15); + cr &= 0xf; + gp = vmcb->exitinfo1 & 0xf; + + rc = dir ? hvm_mov_to_cr(cr, gp) : hvm_mov_from_cr(cr, gp); + + ASSERT(cpu_has_svm_nrips); + if ( rc == X86EMUL_OKAY ) + __update_guest_eip(regs, vmcb->nextrip - vmcb->rip); +} + static void svm_dr_access(struct vcpu *v, struct cpu_user_regs *regs) { HVMTRACE_0D(DR_WRITE); @@ -1898,11 +1915,19 @@ asmlinkage void svm_vmexit_handler(struct cpu_user_regs *regs) int dir = (vmcb->exitinfo1 & 1) ? IOREQ_READ : IOREQ_WRITE; if ( handle_pio(port, bytes, dir) ) __update_guest_eip(regs, vmcb->exitinfo2 - vmcb->rip); - break; } - /* fallthrough to emulation if a string instruction */ + else 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 ( cpu_has_svm_decode && (vmcb->exitinfo1 & (1ULL << 63)) ) + svm_vmexit_do_cr_access(vmcb, regs); + else if ( !handle_mmio() ) + hvm_inject_exception(TRAP_gp_fault, 0, 0); + break; + case VMEXIT_INVLPG: if ( !handle_mmio() ) hvm_inject_exception(TRAP_gp_fault, 0, 0); -- 2.39.5