x86/mm: Allocate log-dirty bitmaps from shadow/HAP memory
PATCH 1/1 x86/mm: Allocate log-dirty bitmaps from shadow/HAP memory
x86/mm: Allocate log-dirty bitmaps from shadow/HAP memory.
Move the p2m alloc and free functions back into the per-domain paging assistance structure and allow them to be called from the log-dirty code. This makes it less likely that log-dirty code will run out of memory populating the log-dirty bitmap.
Signed-off-by Tim Deegan <[email protected]>
xen/arch/x86/mm/hap/hap.c +26 -10
@@ -276,12 +276,16 @@ static void hap_free(struct domain *d, mpage_list_add_tail (pg, &d->arch.paging.hap.freelist); } -static struct page_info *hap_alloc_p2m_page (struct p2m_domain *p2m) +static struct page_info *hap_alloc_p2m_page (struct domain *d) { -struct domain *d = p2m->domain;struct page_info *pg; +int do_locking; -hap_lock (d); +/* This is called both from the p2m code (which never holds the +* hap lock) and the log-dirty code (which sometimes does). */ + do_locking = !hap_locked_by_me (d); +if ( do_locking ) +hap_lock (d); pg =hap_alloc (d);#if CONFIG_PAGING_LEVELS ==3
@@ -312,14 +316,21 @@ static struct page_info *hap_alloc_p2m_p pg->count_info |=1 ; } -hap_unlock (d); +if ( do_locking ) +hap_unlock (d);return pg; } -static void hap_free_p2m_page (struct p2m_domain *p2m,struct page_info *pg) +static void hap_free_p2m_page (struct domain *d,struct page_info *pg) { -struct domain *d = p2m->domain; -hap_lock (d); +int do_locking; + +/* This is called both from the p2m code (which never holds the +* hap lock) and the log-dirty code (which sometimes does). */ + do_locking = !hap_locked_by_me (d); +if ( do_locking ) +hap_lock (d); +ASSERT (page_get_owner (pg) == d);/* Should have just the one ref we gave it in alloc_p2m_page() */ if ( (pg->count_info & PGC_count_mask) !=1 )
@@ -333,7 +344,9 @@ static void hap_free_p2m_page(struct p2m d->arch.paging.hap.total_pages++;hap_free (d,page_to_mfn (pg));ASSERT (d->arch.paging.hap.p2m_pages >=0 ); -hap_unlock (d); + +if ( do_locking ) +hap_unlock (d); }/* Return the size of the pool, rounded up to the nearest MB */
@@ -597,11 +610,14 @@ int hap_enable(struct domain *d, u32 mod } } +/* Allow p2m and log-dirty code to borrow our memory */ + d->arch.paging.alloc_page = hap_alloc_p2m_page; + d->arch.paging.free_page = hap_free_p2m_page; +/* allocate P2m table */ if ( mode & PG_translate ) { - rv =p2m_alloc_table (p2m_get_hostp2m (d), - hap_alloc_p2m_page, hap_free_p2m_page); + rv =p2m_alloc_table (p2m_get_hostp2m (d));if ( rv !=0 ) goto out; }
xen/arch/x86/mm/hap/p2m-ept.c +3 -1
@@ -125,6 +125,8 @@ static int ept_set_middle_entry(struct p/* free ept sub tree behind an entry */ void ept_free_entry (struct p2m_domain *p2m,ept_entry_t *ept_entry,int level) { +struct domain *d = p2m->domain; +/* End if the entry is a leaf entry. */ if ( level ==0 || !is_epte_present (ept_entry) ||is_epte_superpage (ept_entry) )
@@ -138,7 +140,7 @@ void ept_free_entry(struct p2m_domain *punmap_domain_page (epte); } - p2m->free_page (p2m,mfn_to_page (ept_entry->mfn)); + d->arch.paging.free_page (d,mfn_to_page (ept_entry->mfn)); } static int ept_split_super_page(struct p2m_domain *p2m, ept_entry_t *ept_entry,
xen/arch/x86/mm/p2m.c +6 -13
@@ -142,8 +142,9 @@ p2m_alloc_ptp(struct p2m_domain *p2m, unstruct page_info *pg;ASSERT (p2m); -ASSERT (p2m->alloc_page); - pg = p2m->alloc_page (p2m); +ASSERT (p2m->domain); +ASSERT (p2m->domain->arch.paging.alloc_page); + pg = p2m->domain->arch.paging.alloc_page (p2m->domain);if (pg ==NULL )return NULL ;
@@ -167,7 +168,6 @@ p2m_next_level(struct p2m_domain *p2m, ml1_pgentry_t new_entry;void *next;int i; -ASSERT (p2m->alloc_page);if ( !(p2m_entry =p2m_find_entry (*table, gfn_remainder, gfn, shift, max)) )
@@ -1792,14 +1792,9 @@ int set_p2m_entry(struct p2m_domain *p2m// The structure of the p2m table is that of a pagetable for xen (i.e. it is // controlled by CONFIG_PAGING_LEVELS). // -// The alloc_page and free_page functions will be used to get memory to -// build the p2m, and to release it again at the end of day. -// // Returns 0 for success or -errno. // -int p2m_alloc_table (struct p2m_domain *p2m, -struct page_info * (*alloc_page)(struct p2m_domain *p2m), -void (*free_page)(struct p2m_domain *p2m,struct page_info *pg)) +int p2m_alloc_table (struct p2m_domain *p2m) {mfn_t mfn =_mfn (INVALID_MFN );struct page_info *page, *p2m_top;
@@ -1817,9 +1812,6 @@ int p2m_alloc_table(struct p2m_domain *pP2M_PRINTK ("allocating p2m table\n" ); - p2m->alloc_page = alloc_page; - p2m->free_page = free_page; - p2m_top = p2m_alloc_ptp(p2m, #if CONFIG_PAGING_LEVELS == 4 PGT_l4_page_table
@@ -1882,6 +1874,7 @@ void p2m_teardown(struct p2m_domain *p2m* We know we don't have any extra mappings to these pages */ {struct page_info *pg; +struct domain *d = p2m->domain;#ifdef __x86_64__unsigned long gfn;p2m_type_t t;
@@ -1902,7 +1895,7 @@ void p2m_teardown(struct p2m_domain *p2m p2m->phys_table =pagetable_null ();while ( (pg =page_list_remove_head (&p2m->pages)) ) - p2m->free_page (p2m, pg); + d->arch.paging.free_page (d, pg);p2m_unlock (p2m); }
xen/arch/x86/mm/paging.c +21 -62
164 lines not on this page · raw message
xen/arch/x86/mm/shadow/common.c +35 -14
119 lines not on this page · raw message
xen/arch/x86/mm/shadow/private.h +4 -2
@@ -584,7 +584,6 @@ sh_mfn_is_dirty(struct domain *d, mfn_tint rv;ASSERT (shadow_mode_log_dirty (d)); -ASSERT (mfn_valid (d->arch.paging.log_dirty.top));/* We /really/ mean PFN here, even for non-translated guests. */ pfn =get_gpfn_from_mfn (mfn_x (gmfn));
@@ -602,7 +601,10 @@ sh_mfn_is_dirty(struct domain *d, mfn_t*/ return 1 ; - l4 =map_domain_page (mfn_x (d->arch.paging.log_dirty.top)); + l4 =paging_map_log_dirty_bitmap (d); +if ( !l4 ) +return 0 ; + mfn = l4[L4_LOGDIRTY_IDX (pfn)];unmap_domain_page (l4);if ( !mfn_valid (mfn) )
xen/include/asm-x86/domain.h +4 -0
@@ -201,6 +201,10 @@ struct paging_domain {struct hap_domain hap;/* log dirty support */ struct log_dirty_domain log_dirty; +/* alloc/free pages from the pool for paging-assistance structures +* (used by p2m and log-dirty code for their tries) */ +struct page_info * (*alloc_page)(struct domain *d); +void (*free_page)(struct domain *d,struct page_info *pg); };struct paging_vcpu {
xen/include/asm-x86/p2m.h +1 -10
@@ -179,10 +179,6 @@ struct p2m_domain {/* Pages used to construct the p2m */ struct page_list_head pages; -/* Functions to call to get or free pages for the p2m */ -struct page_info * (*alloc_page )(struct p2m_domain *p2m); -void (*free_page )(struct p2m_domain *p2m, -struct page_info *pg); int (*set_entry )(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, unsigned int page_order,
@@ -390,13 +386,8 @@ int p2m_init(struct domain *d);/* Allocate a new p2m table for a domain. * -* The alloc_page and free_page functions will be used to get memory to -* build the p2m, and to release it again at the end of day. -* * Returns 0 for success or -errno. */ -int p2m_alloc_table (struct p2m_domain *p2m, -struct page_info * (*alloc_page)(struct p2m_domain *p2m), -void (*free_page)(struct p2m_domain *p2m,struct page_info *pg)); +int p2m_alloc_table (struct p2m_domain *p2m);/* Return all the p2m resources to Xen. */ void p2m_teardown (struct p2m_domain *p2m);
xen/include/asm-x86/paging.h +2 -2
@@ -134,8 +134,8 @@ struct paging_mode {/***************************************************************************** * Log dirty code */ -/* allocate log dirty bitmap resource for recording dirty pages */ -int paging_alloc_log_dirty_bitmap (struct domain *d); +/* get the top of the log-dirty bitmap trie, allocating if necessary */ +mfn_t *paging_map_log_dirty_bitmap (struct domain *d);/* free log dirty bitmap resource */ void paging_free_log_dirty_bitmap (struct domain *d);