From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 5/5] kvm/svm: copy instruction bytes from VMCB Date: Mon, 13 Dec 2010 14:24:13 +0200 Message-ID: <4D06106D.8030007@redhat.com> References: <1291989088-1380-1-git-send-email-andre.przywara@amd.com> <1291989088-1380-6-git-send-email-andre.przywara@amd.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: mtosatti@redhat.com, kvm@vger.kernel.org To: Andre Przywara Return-path: Received: from mx1.redhat.com ([209.132.183.28]:35396 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753571Ab0LMMYS (ORCPT ); Mon, 13 Dec 2010 07:24:18 -0500 In-Reply-To: <1291989088-1380-6-git-send-email-andre.przywara@amd.com> Sender: kvm-owner@vger.kernel.org List-ID: On 12/10/2010 03:51 PM, Andre Przywara wrote: > In case of a nested page fault or an intercepted #PF newer SVM > implementations provide a copy of the faulting instruction bytes > in the VMCB. > Use these bytes to feed the instruction emulator and avoid the costly > guest instruction fetch in this case. > > > > +static int svm_prefetch_instruction(struct kvm_vcpu *vcpu) > +{ > + struct vcpu_svm *svm = to_svm(vcpu); > + uint8_t len; > + struct fetch_cache *fetch; > + > + len = svm->vmcb->control.insn_len& 0x0F; > + if (len == 0) > + return 1; > + > + fetch =&svm->vcpu.arch.emulate_ctxt.decode.fetch; > + fetch->start = kvm_rip_read(&svm->vcpu); > + fetch->end = fetch->start + len; > + memcpy(fetch->data, svm->vmcb->control.insn_bytes, len); > + > + return 0; > +} This reaching in into the emulator internals from svm code is not very good. It also assumes ->prefetch_instruction() is called immediately after an exit; this isn't true in vmx and at least was considered for svm (emulating multiple instructions during the nsvm vmexit sequence). Alternatives are: - add the insn data to emulate_instruction() and friends (my first suggestion) - adding x86_decode_insn_init(), which initializes the decode cache, and x86_decode_insn_prefill_cache(), called only if we have the insn data Another one: teach kvm_fetch_guest_virt() to check if addr/bytes intersects with csbase+rip/len; if so, use that instead of doing the page table dance. -- error compiling committee.c: too many arguments to function