From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takuya Yoshikawa Subject: Re: [PATCH v2 1/8] KVM: Fix load_guest_segment_descriptor() to inject page fault Date: Fri, 12 Feb 2010 09:19:08 +0900 Message-ID: <4B749E7C.9030305@oss.ntt.co.jp> References: <20100210104541.e0f1fdd1.yoshikawa.takuya@oss.ntt.co.jp> <20100210105034.21644f5b.yoshikawa.takuya@oss.ntt.co.jp> <4B72DE06.3020909@redhat.com> <20100210164311.GC2995@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Avi Kivity , mtosatti@redhat.com, kvm@vger.kernel.org To: Gleb Natapov Return-path: Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:46711 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757340Ab0BLARA (ORCPT ); Thu, 11 Feb 2010 19:17:00 -0500 In-Reply-To: <20100210164311.GC2995@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Gleb Natapov wrote: > On Wed, Feb 10, 2010 at 06:25:42PM +0200, Avi Kivity wrote: >> On 02/10/2010 03:50 AM, Takuya Yoshikawa wrote: >>> This patch injects page fault when reading descriptor in >>> load_guest_segment_descriptor() fails with FAULT. >>> >>> Effects of this injection: This function is used by >>> kvm_load_segment_descriptor() which is necessary for the >>> following instructions. >>> - mov seg,r/m16 >>> - jmp far >>> - pop ?s >>> This patch makes it possible to emulate the page faults >>> generated by these instructions. But be sure that unless >>> we change the kvm_load_segment_descriptor()'s ret value >>> propagation this patch has no effect. >>> >>> >>> @@ -4655,6 +4655,7 @@ static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, >>> { >>> struct descriptor_table dtable; >>> u16 index = selector>> 3; >>> + int ret; >>> >>> get_segment_descriptor_dtable(vcpu, selector,&dtable); >>> >>> @@ -4662,7 +4663,11 @@ static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, >>> kvm_queue_exception_e(vcpu, GP_VECTOR, selector& 0xfffc); >>> return X86EMUL_PROPAGATE_FAULT; >>> } >>> - return kvm_read_guest_virt(dtable.base + index*8, seg_desc, sizeof(*seg_desc), vcpu); >>> + ret = kvm_read_guest_virt(dtable.base + index*8, seg_desc, sizeof(*seg_desc), vcpu); >>> + if (ret == X86EMUL_PROPAGATE_FAULT) >>> + kvm_inject_page_fault(vcpu, dtable.base + index*8, 0); >>> + >>> + return ret; >>> } >> If the descriptor table is not aligned, and a descriptor spans two >> pages, then we might need to inject a page fault at some other >> address. >> >> Also, the injection should be done in kvm_read_guest_virt() to avoid >> duplicating code. >> > This function is used from inside emulator and I hope one day we will > make emulator independent of KVM, so it shouldn't inject event directly, > but rather return them as a result of emulation. Also this function is > used in kvm_report_emulation_failure() may be not the best place to > inject #PF. Agree. Actually I tried to find how to, at which layer, inject page faults, but could not find any good way in the current situation. > >> These instructions however are only emulated in big real mode. >> Where did you encounter the need to inject page faults during their >> emulation? >> >> -- >> error compiling committee.c: too many arguments to function >> >> -- >> To unsubscribe from this list: send the line "unsubscribe kvm" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html > > -- > Gleb.