Hi, I''m working with Xen 3.2 and having a hard time understanding what''s going on in this piece of code used to do ref and type counting. int get_page_type(struct page_info *page, unsigned long type) { ... else if ( unlikely((x & PGT_count_mask) == 0) ) { struct domain *d = page_get_owner(page); /* Never allow a shadowed frame to go from type count 0 to 1 */ if ( d && shadow_mode_enabled(d) ) shadow_remove_all_shadows(d->vcpu[0], _mfn(page_to_mfn(page))); Does this mean that every time a page goes from read-only to writable, the shadow PTE mapping that page is destroyed and recreated? In particular, if I wanted to restore writable access to a page during log-dirty mode (such as what occurs when a fault is taken and that page is then marked dirty and RW is not revoked in _sh_propagate()), will the shadow always be destroyed and then recreated?>From what I understand, shadow_remove_all_shadows() will remove allshadows of the gmfn, which should be a guest PT. Basically, it''ll remove all shadows inserted in the shadow_hash table for that gmfn. It IS NOT removing shadow PTEs mapping that gmfn. Is this a correct understanding? I don''t understand how get_page_type() would know in the code that is there how the given page is actually a guest PT? -- Mike _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
>From: Mike Sun >Sent: Monday, January 05, 2009 11:18 AM > >Hi, > >I''m working with Xen 3.2 and having a hard time understanding what''s >going on in this piece of code used to do ref and type counting. > >int get_page_type(struct page_info *page, unsigned long type) >{ > ... > else if ( unlikely((x & PGT_count_mask) == 0) ) > { > struct domain *d = page_get_owner(page); > > /* Never allow a shadowed frame to go from type >count 0 to 1 */ > if ( d && shadow_mode_enabled(d) ) > shadow_remove_all_shadows(d->vcpu[0], >_mfn(page_to_mfn(page))); > >Does this mean that every time a page goes from read-only to writable, >the shadow PTE mapping that page is destroyed and recreated? In >particular, if I wanted to restore writable access to a page during >log-dirty mode (such as what occurs when a fault is taken and that >page is then marked dirty and RW is not revoked in _sh_propagate()), >will the shadow always be destroyed and then recreated? > >>From what I understand, shadow_remove_all_shadows() will remove all >shadows of the gmfn, which should be a guest PT. Basically, it''ll >remove all shadows inserted in the shadow_hash table for that gmfn. >It IS NOT removing shadow PTEs mapping that gmfn. Is this a correct >understanding? I don''t understand how get_page_type() would know in >the code that is there how the given page is actually a guest PT? >guest page table has a flag PGC_page_table if shadowed, which is checked within shadow_remove_all_shadows. That means, for most write-type page fault in log dirty mode, it''s just a nop if faulting va is a memory page. In latest Xen, type check is moved outside with a new exception on oos l1: if ( d && shadow_mode_enabled(d) && (page->count_info & PGC_page_table) && !((page->shadow_flags & (1u<<29)) && type == PGT_writable_page) ) shadow_remove_all_shadows(d->vcpu[0], _mfn(page_to_mfn(page))); Thanks, Kevin _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hi, At 22:18 -0500 on 04 Jan (1231107492), Mike Sun wrote:> Does this mean that every time a page goes from read-only to writable, > the shadow PTE mapping that page is destroyed and recreated?No - I mentioned this in another thread, but just for the archives: this means that every time a page goes from read-only to writable, all shadows of that page must be destroyed (since it''s not safe to let the guest write directly to a shadowed page).> >From what I understand, shadow_remove_all_shadows() will remove all > shadows of the gmfn, which should be a guest PT. Basically, it''ll > remove all shadows inserted in the shadow_hash table for that gmfn. > It IS NOT removing shadow PTEs mapping that gmfn. Is this a correct > understanding?Yes.> I don''t understand how get_page_type() would know in > the code that is there how the given page is actually a guest PT?It doesn''t, but shadow_remove_all_shadows() does. As Kevin points out, in later Xens, this test is modified to check both that the page is shadowed and also that it''s not out of sync before calling out (since being out of sync is now the one exception to the rule that writeable pages must not be shadowed). Cheers, Tim. -- Tim Deegan <Tim.Deegan@citrix.com> 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