From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: [PATCH v2 02/12] KVM: x86: tag the instructions which are used to write page table Date: Wed, 03 Aug 2011 17:24:28 +0800 Message-ID: <4E3913CC.7010907@cn.fujitsu.com> References: <4E37DA49.1040000@cn.fujitsu.com> <4E37DA73.7010908@cn.fujitsu.com> <4E37EB8E.6080207@redhat.com> <4E38E477.2000208@cn.fujitsu.com> <4E39021F.8070508@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Marcelo Tosatti , LKML , KVM To: Avi Kivity Return-path: Received: from cn.fujitsu.com ([222.73.24.84]:59268 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752629Ab1HCJWg convert rfc822-to-8bit (ORCPT ); Wed, 3 Aug 2011 05:22:36 -0400 In-Reply-To: <4E39021F.8070508@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Hi Avi, On 08/03/2011 04:09 PM, Avi Kivity wrote: > On 08/03/2011 09:02 AM, Xiao Guangrong wrote: >> > Note we don't need to actually emulate, just decode, since page_f= ault can tell us whether a write failed due to page tables or mmio. >> > >> >> This is a interesting feature. If it happens, i will just drop the s= hadow pages >> and retry these instructions directly. >=20 > Note it's a little dangerous. If the guest uses a non-page-table mod= ifying instruction on the PDE that points to the instruction, then we w= ill unmap the instruction and go to an infinite loop. >=20 Yes, it is. > Maybe it's better to emulate if we can't find a fix for that. >=20 > One way would be to emulate every 20 instructions; this breaks us out= of the loop but reduces costly emulations to 5%. >=20 After much thought about this, may be this optimization is not good sin= ce: - it is little complex - this optimization is only applied to the instruction emulation caused= by #PF - it does not improve too much: if we emulate the instruction, we need to do: - decode instruction - emulate it - zap shadow pages And do this, it can return to the guest, the guest can run the next i= nstruction if we retry the instruction, we need to do: - decode instruction - zap shadow pages then return to the guest and retry the instruction, however, we will = get page fault again(since the mapping is still read-only), so we will get another V= M-exit and need to do: # trigger page fault - handle the page fault and change the mapping to writable - retry the instruction until now, the guest can run the next instruction So, i do not think the new way is better, your opinion=EF=BC=9F =20 =20