From: "Wu Bingzheng" Subject: Re:Re:Re: Questions about shadow page table. Date: Wed, 27 May 2009 10:47:58 +0800 (CST) Message-ID: <12737400.124241243392478610.JavaMail.coremail@bj163app62.163.com> References: <3841352.530971243347632779.JavaMail.coremail@bj163app57.163.com> <20090526095459.GA16056@york.uk.xensource.com> <27156115.386171243327618700.JavaMail.coremail@bj163app31.163.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1899755526==" Return-path: In-Reply-To: <3841352.530971243347632779.JavaMail.coremail@bj163app57.163.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Wu Bingzheng Cc: xen-devel , Tim Deegan List-Id: xen-devel@lists.xenproject.org --===============1899755526== Content-Type: multipart/alternative; boundary="----=_Part_33738_12884539.1243392478608" ------=_Part_33738_12884539.1243392478608 Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: quoted-printable Hi, I have another question about Shadow. If a process writes a read-only page in guest OS, how does the page-fault h= andler deal with it? In sh_page_fault() [xen/arch/x86/mm/shadow/multi.c], which part deals with = this case? In the label `emulate` and `not_a_shadow_fault` ? But the point= s where jumps to the label `emulate` seems not to be this case (write reado= nly pages in guest), but seems to emulate accesses to page tables. Thanks, Wu > >At 09:46 +0100 on 26 May (1243331218), Wu Bingzheng wrote: >> Shadow-1. Its method of propagating changes from guest pagetables >> to the shadow pagetables was as follows: >>=20 >> 1. Remove write access to any guest pagetable. >> 2. When a guest attempts to write to the guest pagetable, mark it >> out-of-sync, add the page to the out-of-sync list and give write >> permission. >> 3. On the next page fault or cr3 write, take each page from the >> out-of-sync list and: >> - resync the page: look for changes to the guest pagetable, >> propagate those entries into the shadow pagetable >> - remove write permission, and clear the out-of-sync bit. >>=20 >> My question is that, dose step 2 trap into Xen hypervisor? > >Yes, of course. It's done in the #PF handler.=20 > >> 2. >> I think there are 2 kinds of page fault. 1) normal page fault in guest, >> which should be handled by guest; 2) invoked by guest updating the page >> table, which should be handled by Xen. >>=20 >> So, if there's a page-miss fault in guest, how many times it will trap i= nto Xen? >> First, page miss, trap into Xen. Xen finds out it's the 1st kind fault, >> then it go back to guest to handle it >> Then, in guest, when it updates the page table to fix the page fault, >> it will invoke the 2nd kind fault, which will trap into Xen again. >>=20 >> Am I right? > >Yes; and in some circumstances there can be more than two faults >(e.g. if the guest's new entry hasn't got the Accessed bit set). > >> 3. >> For the user space part, are the attribute bits of the entries >> in Guest page table and Shadow page table the same? > >No; the only guarantee is that the shadow entry won't contain more >access rights than the guest entry. For PTEs that map MMIO space we try >to do the right thing with the caching attributes too. > >Cheers, > >Tim. > >--=20 >Tim Deegan >Principal Software Engineer, Citrix Systems (R&D) Ltd. >[Company #02300071, SL9 0DZ, UK.] > >_______________________________________________ >Xen-devel mailing list >Xen-devel@lists.xensource.com >http://lists.xensource.com/xen-devel =B4=A9=D4=BD=B5=D8=D5=F0=B4=F8 =BC=CD=C4=EE=E3=EB=B4=A8=B5=D8=D5=F0=D2=BB= =D6=DC=C4=EA ------=_Part_33738_12884539.1243392478608 Content-Type: text/html; charset=gbk Content-Transfer-Encoding: quoted-printable Hi,

I have another question about Shadow.If a process writes a read-only page i= n guest OS, how does the page-fault hand= ler deal with it?
In sh_page_fault() [xen/arch/= x86/mm/shadow/multi.c], which part deals with this=  case? In the label `emulate` and `not_a= _shadow_fault` ?  But the points where j= umps to the label `emulate` seems not to=  be this case (write readonly pages in&n= bsp;guest), but seems to emulate accesses to&= nbsp;page tables.

Thanks,
Wu

>
>At 09:4= 6 +0100 on 26 May (1243331218), Wu Bingz= heng wrote:
>> Shadow-1. Its method of&nb= sp;propagating changes from guest pagetables
>>= ; to the shadow pagetables was as follow= s:
>> 
>>   1. Remove write=  access to any guest pagetable.
>> &= nbsp; 2. When a guest attempts to write&= nbsp;to the guest pagetable, mark it
>>&n= bsp;     out-of-sync, add the page&= nbsp;to the out-of-sync list and give write>>      permission.
>> =   3. On the next page fault or = ;cr3 write, take each page from the
>&g= t;      out-of-sync list and:
&g= t;>      - resync the page:=  look for changes to the guest pagetable= ,
>>        propagate = ;those entries into the shadow pagetable
>&g= t;      - remove write permiss= ion, and clear the out-of-sync bit.
>>&nb= sp;
>> My question is that, dose ste= p 2 trap into Xen hypervisor?
>
>Yes,&= nbsp;of course.  It's done in the #PF&nb= sp;handler. 
>
>> 2.
>> I think=  there are 2 kinds of page fault. 1= ) normal page fault in guest,
>> whi= ch should be handled by guest; 2) invoke= d by guest updating the page
>> tabl= e, which should be handled by Xen.
>>= ; 
>> So, if there's a page-miss&nbs= p;fault in guest, how many times it will=  trap into Xen?
>> First, page miss,=  trap into Xen. Xen finds out it's = the 1st kind fault,
>> then it go&nb= sp;back to guest to handle it
>> The= n, in guest, when it updates the page&nb= sp;table to fix the page fault,
>> i= t will invoke the 2nd kind fault, which&= nbsp;will trap into Xen again.
>> 
>= ;> Am I right?
>
>Yes; and in = some circumstances there can be more than&nbs= p;two faults
>(e.g. if the guest's new = entry hasn't got the Accessed bit set).
&g= t;
>> 3.
>> For the user space&n= bsp;part, are the attribute bits of the = entries
>> in Guest page table and S= hadow page table the same?
>
>No; the&= nbsp;only guarantee is that the shadow entry&= nbsp;won't contain more
>access rights than = the guest entry.  For PTEs that map = ;MMIO space we try
>to do the right&nbs= p;thing with the caching attributes too.
>>Cheers,
>
>Tim.
>
>-- 
>Tim D= eegan <Tim.Deegan@citrix.com>
>Principal Software&nbs= p;Engineer, Citrix Systems (R&D) Ltd.
>[Compa= ny #02300071, SL9 0DZ, UK.]
>
>____________= ___________________________________
>Xen-devel mailing list=
>Xen-devel@lists.xensource.com
>http://lists.xensource.com/xen= -devel

=B4=A9=D4=BD=B5=D8=D5=F0=B4=F8 =BC=CD=C4=EE=E3=EB=B4=A8= =B5=D8=D5=F0=D2=BB=D6=DC=C4=EA


=B4=A9=D4=BD=B5=D8=D5=F0=B4=F8 =BC=CD=C4=EE=E3=EB=B4=A8=B5=D8=D5=F0= =D2=BB=D6=DC=C4=EA
------=_Part_33738_12884539.1243392478608-- --===============1899755526== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1899755526==--