From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: How KVM sync guest page table with corresponding shadow page table? Date: Tue, 14 Aug 2012 17:23:01 +0800 Message-ID: <502A18F5.1050609@linux.vnet.ibm.com> References: <20120814035457.GB57133@cs.nctu.edu.tw> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org To: =?UTF-8?B?IumZs+mfi+S7uyAoV2VpLVJlbiBDaGVuKSI=?= Return-path: Received: from e28smtp09.in.ibm.com ([122.248.162.9]:41838 "EHLO e28smtp09.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752013Ab2HNJXI (ORCPT ); Tue, 14 Aug 2012 05:23:08 -0400 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 14 Aug 2012 14:53:05 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7E9N3Fs35061822 for ; Tue, 14 Aug 2012 14:53:03 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7EEqbXM008664 for ; Tue, 14 Aug 2012 20:22:38 +0530 In-Reply-To: <20120814035457.GB57133@cs.nctu.edu.tw> Sender: kvm-owner@vger.kernel.org List-ID: On 08/14/2012 11:54 AM, =E9=99=B3=E9=9F=8B=E4=BB=BB (Wei-Ren Chen) wrot= e: > Hi all, >=20 > If guest modify its guest page table entry, KVM should trap that ev= ent, > emulate what guest trying to do, and sync with the corresponding shad= ow > page table entry. Is my understanding correct? If so, does KVM use > something like mprotect to make guest page table read-only, or there = is > another way?=20 It is controlled by shadow page table, guest-page-tables are write-prot= ected on shadow pages (the W bit on PTE is cleared). There has a special case, called unsync shadow page, if the page only u= sed as guest page structure on the lowest level (level =3D 1), we allow it = to be writable, it will be sync-ed when the guest flush the tlb (e.g: CR3 rel= oad, invlpg...) because according to x86 TLB rules, it needs to flush tlb to= apply the change. > Besides, how KVM know what guest try to write into the > guest page table entry? In the normal case, guest writes its page table will generate #PF since= the page is write-protected as we mention above. =46or the special case (unsync shadow page), we can happily write its p= age table without #PF.