make sure PGC_extra pages are dealt with properly
v4 cover make sure PGC_extra pages are dealt with properly
This series was formerly called "remove one more shared xenheap page:shared_info" but I have dropped the patches actually changing shared_info and just left the PGC_extra clean-up that was previously intertwined.
Paul Durrant (3):
mm: keep PGC_extra pages on a separate list
x86 / ioreq: use a MEMF_no_refcount allocation for server pages...
mm: add 'is_special_page' inline function...
xen/arch/x86/domain.c | 9 +++++++++ xen/arch/x86/domctl.c | 2 +- xen/arch/x86/hvm/ioreq.c | 2 +- xen/arch/x86/mm.c | 13 ++++++------- xen/arch/x86/mm/altp2m.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 3 +-- xen/arch/x86/mm/p2m-pod.c | 12 +++++++----- xen/arch/x86/mm/p2m.c | 4 ++-- xen/arch/x86/mm/shadow/common.c | 13 ++++++++----- xen/arch/x86/mm/shadow/multi.c | 3 ++- xen/arch/x86/tboot.c | 4 ++-- xen/common/domain.c | 1 + xen/common/page_alloc.c | 2 +- xen/include/asm-x86/mm.h | 6 ++---- xen/include/xen/mm.h | 10 +++++++--- xen/include/xen/sched.h | 13 +++++++++++++ 16 files changed, 64 insertions(+), 35 deletions(-)
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 1/3 mm: keep PGC_extra pages on a separate list
This patch adds a new page_list_head into struct domain to hold PGC_extra pages. This avoids them getting confused with 'normal' domheap pages where the domain's page_list is walked.
A new dump loop is also added to dump_pageframe_info() to unconditionally dump the 'extra page list'.
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
v7:
- Cosmetic changes
v6:
- New in v6
--- xen/arch/x86/domain.c | 9 +++++++++ xen/common/domain.c | 1 + xen/common/page_alloc.c | 2 +- xen/include/asm-x86/mm.h | 6 ++---- xen/include/xen/mm.h | 5 ++--- xen/include/xen/sched.h | 13 +++++++++++++ 6 files changed, 28 insertions(+), 8 deletions(-)
xen/arch/x86/domain.c +9 -0
@@ -251,12 +251,21 @@ void dump_pageframe_info(struct domain *d)p2m_pod_dump_data (d);spin_lock (&d->page_alloc_lock); + page_list_for_each ( page, &d->xenpage_list ) {printk (" XenPage %p: caf=%08lx, taf=%" PRtype_info"\n" ,_p (mfn_x (page_to_mfn (page))), page->count_info, page->u.inuse.type_info); } + + page_list_for_each ( page, &d->extra_page_list ) + { +printk (" ExtraPage %p: caf=%08lx, taf=%" PRtype_info"\n" , +_p (mfn_x (page_to_mfn (page))), + page->count_info, page->u.inuse.type_info); + } +spin_unlock (&d->page_alloc_lock); }
xen/common/domain.c +1 -0
@@ -403,6 +403,7 @@ struct domain *domain_create(domid_t domid,spin_lock_init_prof (d, page_alloc_lock);spin_lock_init (&d->hypercall_deadlock_mutex);INIT_PAGE_LIST_HEAD (&d->page_list); +INIT_PAGE_LIST_HEAD (&d->extra_page_list);INIT_PAGE_LIST_HEAD (&d->xenpage_list);spin_lock_init (&d->node_affinity_lock);
xen/common/page_alloc.c +1 -1
@@ -2314,7 +2314,7 @@ int assign_pages(smp_wmb ();/* Domain pointer must be visible before updating refcnt. */ pg[i].count_info = (pg[i].count_info & PGC_extra) | PGC_allocated |1 ; -page_list_add_tail (&pg[i], &d->page_list); +page_list_add_tail (&pg[i],page_to_list (d, &pg[i])); } out:
xen/include/asm-x86/mm.h +2 -4
@@ -629,10 +629,8 @@ typedef struct mm_rwlock {const char *locker_function;/* func that took it */ } mm_rwlock_t; -#define arch_free_heap_page (d, pg) \ - page_list_del2(pg, is_xen_heap_page(pg) ? \ - &(d)->xenpage_list : &(d)->page_list, \ - &(d)->arch.relmem_list) +#define arch_free_heap_page (d, pg) \ + page_list_del2(pg, page_to_list(d, pg), &(d)->arch.relmem_list)extern const char zero_page[];
xen/include/xen/mm.h +2 -3
@@ -583,9 +583,8 @@ static inline unsigned int get_order_from_pages(unsigned long nr_pages)void scrub_one_page (struct page_info *);#ifndef arch_free_heap_page -#define arch_free_heap_page (d, pg) \ - page_list_del(pg, is_xen_heap_page(pg) ? \ - &(d)->xenpage_list : &(d)->page_list) +#define arch_free_heap_page (d, pg) \ + page_list_del(pg, page_to_list(d, pg))#endif int xenmem_add_to_physmap_one(struct domain *d, unsigned int space,
xen/include/xen/sched.h +13 -0
@@ -329,6 +329,7 @@ struct domainspinlock_t page_alloc_lock;/* protects all the following fields */ struct page_list_head page_list;/* linked list */ +struct page_list_head extra_page_list;/* linked list (size extra_pages) */ struct page_list_head xenpage_list;/* linked list (size xenheap_pages) */ /*
@@ -512,6 +513,18 @@ struct domain#endif }; +static inline struct page_list_head *page_to_list ( +struct domain *d,const struct page_info *pg) +{ +if (is_xen_heap_page (pg) ) +return &d->xenpage_list; + +if ( pg->count_info & PGC_extra ) +return &d->extra_page_list; + +return &d->page_list; +} +/* Return number of pages currently posessed by the domain */ static inline unsigned int domain_tot_pages (const struct domain *d) {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 1/3] mm: keep PGC_extra pages on a separate list
Quoted 9 lines · Paul Durrant
This patch adds a new
page_list_headinto struct domain to holdPGC_extrapages. This avoids them getting confused with 'normal' domheap pages where the domain'spage_listis walked.A new dump loop is also added to
dump_pageframe_info()to unconditionally dump the 'extra page list'.Signed-off-by Paul Durrant <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Quoted 139 lines
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>v7:
- Cosmetic changesv6:
- New in v6--- xen/arch/x86/domain.c | 9 +++++++++ xen/common/domain.c | 1 + xen/common/page_alloc.c | 2 +- xen/include/asm-x86/mm.h | 6 ++---- xen/include/xen/mm.h | 5 ++--- xen/include/xen/sched.h | 13 +++++++++++++ 6 files changed, 28 insertions(+), 8 deletions(-)xen/arch/x86/domain.c +9
-0@@ -251,12 +251,21 @@ void dump_pageframe_info(struct domain *d)p2m_pod_dump_data (d);spin_lock (&d->page_alloc_lock); + page_list_for_each ( page, &d->xenpage_list ) {printk (" XenPage %p: caf=%08lx, taf=%" PRtype_info"\n" ,_p (mfn_x (page_to_mfn (page))), page->count_info, page->u.inuse.type_info); } + + page_list_for_each ( page, &d->extra_page_list ) + { +printk (" ExtraPage %p: caf=%08lx, taf=%" PRtype_info"\n" , +_p (mfn_x (page_to_mfn (page))), + page->count_info, page->u.inuse.type_info); + } +spin_unlock (&d->page_alloc_lock); }xen/common/domain.c +1
-0@@ -403,6 +403,7 @@ struct domain *domain_create(domid_t domid,spin_lock_init_prof (d, page_alloc_lock);spin_lock_init (&d->hypercall_deadlock_mutex);INIT_PAGE_LIST_HEAD (&d->page_list); +INIT_PAGE_LIST_HEAD (&d->extra_page_list);INIT_PAGE_LIST_HEAD (&d->xenpage_list);spin_lock_init (&d->node_affinity_lock);xen/common/page_alloc.c +1
-1@@ -2314,7 +2314,7 @@ int assign_pages(smp_wmb ();/* Domain pointer must be visible before updating refcnt. */ pg[i].count_info = (pg[i].count_info & PGC_extra) | PGC_allocated |1 ; -page_list_add_tail (&pg[i], &d->page_list); +page_list_add_tail (&pg[i],page_to_list (d, &pg[i])); } out:xen/include/asm-x86/mm.h +2
-4@@ -629,10 +629,8 @@ typedef struct mm_rwlock {const char *locker_function;/* func that took it */ } mm_rwlock_t; -#define arch_free_heap_page (d, pg) \ - page_list_del2(pg, is_xen_heap_page(pg) ? \ - &(d)->xenpage_list : &(d)->page_list, \ - &(d)->arch.relmem_list) +#define arch_free_heap_page (d, pg) \ + page_list_del2(pg, page_to_list(d, pg), &(d)->arch.relmem_list)extern const char zero_page[];xen/include/xen/mm.h +2
-3@@ -583,9 +583,8 @@ static inline unsigned int get_order_from_pages(unsigned long nr_pages)void scrub_one_page (struct page_info *);#ifndef arch_free_heap_page -#define arch_free_heap_page (d, pg) \ - page_list_del(pg, is_xen_heap_page(pg) ? \ - &(d)->xenpage_list : &(d)->page_list) +#define arch_free_heap_page (d, pg) \ + page_list_del(pg, page_to_list(d, pg))#endif int xenmem_add_to_physmap_one(struct domain *d, unsigned int space,xen/include/xen/sched.h +13
-0@@ -329,6 +329,7 @@ struct domainspinlock_t page_alloc_lock;/* protects all the following fields */ struct page_list_head page_list;/* linked list */ +struct page_list_head extra_page_list;/* linked list (size extra_pages) */ struct page_list_head xenpage_list;/* linked list (size xenheap_pages) */ /* @@ -512,6 +513,18 @@ struct domain#endif }; +static inline struct page_list_head *page_to_list ( +struct domain *d,const struct page_info *pg) +{ +if (is_xen_heap_page (pg) ) +return &d->xenpage_list; + +if ( pg->count_info & PGC_extra ) +return &d->extra_page_list; + +return &d->page_list; +} +/* Return number of pages currently posessed by the domain */ static inline unsigned int domain_tot_pages (const struct domain *d) {
Signature · 1 line
Julien Grall
PATCH v4 2/3 x86 / ioreq: use a MEMF_no_refcount allocation for server pages...
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
... now that it is safe to assign them.
This avoids relying on libxl (or whatever toolstack is in use) setting max_pages up with sufficient 'slop' to allow all necessary ioreq server pages to be allocated.
---
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
v2:
- New in v2
--- xen/arch/x86/hvm/ioreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/ioreq.c +1 -1
@@ -376,7 +376,7 @@ static int hvm_alloc_ioreq_mfn(struct hvm_ioreq_server *s, bool buf)return 0 ; } - page =alloc_domheap_page (s->target,0 ); + page =alloc_domheap_page (s->target, MEMF_no_refcount);if ( !page )return -ENOMEM ;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 3/3 mm: add 'is_special_page' inline function...
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
... to cover xenheap and PGC_extra pages.
PGC_extra pages are intended to hold data structures that are associated with a domain and may be mapped by that domain. They should not be treated as 'normal' guest pages (i.e. RAM or page tables). Hence, in many cases where code currently tests is_xen_heap_page() it should also check for the PGC_extra bit in 'count_info'.
This patch therefore defines is_special_page() to cover both cases and converts tests of is_xen_heap_page() (or open coded tests of PGC_xen_heap) to is_special_page() where the page is assigned to a domain.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
v7:
- Fixed some uses of is_xen_heap_mfn() that I'd missed
- Updated commit comment to point out that only tests on assigned xenheap pages are candidates for conversion
v6:
- Convert open-coded checks of PGC_xen_heap to use is_special_page() where appropriate
v4:
- Use inline function instead of macro
- Add missing conversions from is_xen_heap_page()
v3:
- Delete obsolete comment.
v2:
- New in v2
--- xen/arch/x86/domctl.c | 2 +- xen/arch/x86/mm.c | 13 ++++++------- xen/arch/x86/mm/altp2m.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 3 +-- xen/arch/x86/mm/p2m-pod.c | 12 +++++++----- xen/arch/x86/mm/p2m.c | 4 ++-- xen/arch/x86/mm/shadow/common.c | 13 ++++++++----- xen/arch/x86/mm/shadow/multi.c | 3 ++- xen/arch/x86/tboot.c | 4 ++-- xen/include/xen/mm.h | 5 +++++ 10 files changed, 35 insertions(+), 26 deletions(-)
xen/arch/x86/domctl.c +1 -1
@@ -394,7 +394,7 @@ long arch_do_domctl( page =get_page_from_gfn (d, gfn, &t,P2M_ALLOC );if (unlikely (!page) || -unlikely (is_xen_heap_page (page)) ) +unlikely (is_special_page (page)) ) {if (unlikely (p2m_is_broken (t)) ) type =XEN_DOMCTL_PFINFO_BROKEN ;
xen/arch/x86/mm.c +6 -7
@@ -1014,7 +1014,7 @@ get_page_from_l1e(unsigned long cacheattr =pte_flags_to_cacheattr (l1f);int err; -if (is_xen_heap_page (page) ) +if (is_special_page (page) ) {if ( write )put_page_type (page);
@@ -2447,7 +2447,7 @@ static int cleanup_page_mappings(struct page_info *page) { page->count_info &= ~PGC_cacheattr_mask; -BUG_ON (is_xen_heap_page (page)); +BUG_ON (is_special_page (page)); rc =update_xen_mappings (mfn,0 ); }
@@ -2477,7 +2477,7 @@ static int cleanup_page_mappings(struct page_info *page) rc = rc2; } -if (likely (!is_xen_heap_page (page)) ) +if (likely (!is_special_page (page)) ) {ASSERT ((page->u.inuse.type_info & (PGT_type_mask | PGT_count_mask)) == PGT_writable_page);
@@ -4216,8 +4216,7 @@ int steal_page(if ( !(owner =page_get_owner_and_reference (page)) ) goto fail; -if ( owner != d ||is_xen_heap_page (page) || - (page->count_info & PGC_extra) ) +if ( owner != d ||is_special_page (page) ) goto fail_put;/*
@@ -4580,8 +4579,8 @@ int xenmem_add_to_physmap_one( prev_mfn =get_gfn (d,gfn_x (gpfn), &p2mt);if (mfn_valid (prev_mfn) ) { -if (is_xen_heap_mfn (prev_mfn) ) -/* Xen heap frames are simply unhooked from this phys slot. */ +if (is_special_page (mfn_to_page (prev_mfn)) ) +/* Special pages are simply unhooked from this phys slot. */ rc =guest_physmap_remove_page (d, gpfn, prev_mfn,PAGE_ORDER_4K );else /* Normal domain memory is freed, to avoid leaking memory. */
xen/arch/x86/mm/altp2m.c +1 -1
@@ -77,7 +77,7 @@ int altp2m_vcpu_enable_ve(struct vcpu *v, gfn_t gfn)* pageable() predicate for this, due to it having the same properties * that we want. */ -if ( !p2m_is_pageable (p2mt) ||is_xen_heap_page (pg) ) +if ( !p2m_is_pageable (p2mt) ||is_special_page (pg) ) { rc = -EINVAL ; goto err;
xen/arch/x86/mm/mem_sharing.c +1 -2
@@ -840,9 +840,8 @@ static int nominate_page(struct domain *d, gfn_t gfn,if ( !p2m_is_sharable (p2mt) ) goto out; -/* Skip xen heap pages */ page =mfn_to_page (mfn); -if ( !page ||is_xen_heap_page (page) ) +if ( !page ||is_special_page (page) ) goto out;/* Check if there are mem_access/remapped altp2m entries for this page */
xen/arch/x86/mm/p2m-pod.c +7 -5
@@ -749,8 +749,9 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, gfn_t gfn) n =1UL <<min (cur_order,SUPERPAGE_ORDER +0U );for ( k =0 , page =mfn_to_page (mfn); k < n; ++k, ++page ) -if ( !(page->count_info & PGC_allocated) || - (page->count_info & (PGC_page_table | PGC_xen_heap)) || +if (is_special_page (page) || + !(page->count_info & PGC_allocated) || + (page->count_info & PGC_page_table) || (page->count_info & PGC_count_mask) > max_ref ) goto out; }
@@ -883,11 +884,12 @@ p2m_pod_zero_check(struct p2m_domain *p2m, const gfn_t *gfns, unsigned int count pg =mfn_to_page (mfns[i]);/* -* If this is ram, and not a pagetable or from the xen heap, and +* If this is ram, and not a pagetable or a special page, and * probably not mapped elsewhere, map it; otherwise, skip. */ -if (p2m_is_ram (types[i]) && (pg->count_info & PGC_allocated) && - !(pg->count_info & (PGC_page_table | PGC_xen_heap)) && +if ( !is_special_page (pg) &&p2m_is_ram (types[i]) && + (pg->count_info & PGC_allocated) && + !(pg->count_info & PGC_page_table) && ((pg->count_info & PGC_count_mask) <= max_ref) ) map[i] =map_domain_page (mfns[i]);else
xen/arch/x86/mm/p2m.c +2 -2
@@ -2983,8 +2983,8 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, prev_mfn =get_gfn (tdom, gpfn, &p2mt_prev);if (mfn_valid (prev_mfn) ) { -if (is_xen_heap_mfn (prev_mfn) ) -/* Xen heap frames are simply unhooked from this phys slot */ +if (is_special_page (mfn_to_page (prev_mfn)) ) +/* Special pages are simply unhooked from this phys slot */ rc =guest_physmap_remove_page (tdom,_gfn (gpfn), prev_mfn,0 );else /* Normal domain memory is freed, to avoid leaking memory. */
xen/arch/x86/mm/shadow/common.c +8 -5
@@ -2087,19 +2087,22 @@ static int sh_remove_all_mappings(struct domain *d, mfn_t gmfn, gfn_t gfn)* The qemu helper process has an untyped mapping of this dom's RAM * and the HVM restore program takes another. * Also allow one typed refcount for -* - Xen heap pages, to match share_xen_page_with_guest(), -* - ioreq server pages, to match prepare_ring_for_helper(). +* - special pages, which are explicitly referenced and mapped by +* Xen. +* - ioreq server pages, which may be special pages or normal +* guest pages with an extra reference taken by +* prepare_ring_for_helper(). */ if ( !(shadow_mode_external (d) && (page->count_info & PGC_count_mask) <=3 && ((page->u.inuse.type_info & PGT_count_mask) - == (is_xen_heap_page (page) || + == (is_special_page (page) || (is_hvm_domain (d) &&is_ioreq_server_page (d, page))))) )printk (XENLOG_G_ERR "can't find all mappings of mfn %" PRI_mfn -" (gfn %" PRI_gfn"): c=%lx t=%lx x=%d i=%d\n" , +" (gfn %" PRI_gfn"): c=%lx t=%lx s=%d i=%d\n" ,mfn_x (gmfn),gfn_x (gfn), page->count_info, page->u.inuse.type_info, - !!is_xen_heap_page (page), +is_special_page (page), (is_hvm_domain (d) &&is_ioreq_server_page (d, page))); }
xen/arch/x86/mm/shadow/multi.c +2 -1
@@ -559,7 +559,8 @@ _sh_propagate(struct vcpu *v,* caching attributes in the shadows to match what was asked for. */ if ( (level ==1 ) &&is_hvm_domain (d) && - !is_xen_heap_mfn (target_mfn) ) + (!mfn_valid (target_mfn) || + !is_special_page (mfn_to_page (target_mfn))) ) {int type;
xen/arch/x86/tboot.c +2 -2
@@ -189,7 +189,7 @@ static void update_pagetable_mac(vmac_ctx_t *ctx)if ( !mfn_valid (_mfn (mfn)) )continue ; -if (is_page_in_use (page) && !is_xen_heap_page (page) ) +if (is_page_in_use (page) && !is_special_page (page) ) {if ( page->count_info & PGC_page_table ) {
@@ -289,7 +289,7 @@ static void tboot_gen_xenheap_integrity(const uint8_t key[TB_KEY_SIZE], + 3 * PAGE_SIZE)) )continue ;/* skip tboot and its page tables */ -if (is_page_in_use (page) &&is_xen_heap_page (page) ) +if (is_page_in_use (page) &&is_special_page (page) ) {void *pg;
xen/include/xen/mm.h +5 -0
@@ -285,6 +285,11 @@ extern struct domain *dom_cow;#include <asm/mm.h> +static inline bool is_special_page (const struct page_info *page) +{ +return is_xen_heap_page (page) || (page->count_info & PGC_extra); +} +#ifndef page_list_entrystruct page_list_head {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 3/3] mm: add 'is_special_page' inline function...
Quoted 10 lines · Paul Durrant
From: Paul Durrant <[email protected]>
... to cover xenheap and
PGC_extrapages.
PGC_extrapages are intended to hold data structures that are associated with a domain and may be mapped by that domain. They should not be treated as 'normal' guest pages (i.e. RAM or page tables). Hence, in many cases where code currently testsis_xen_heap_page()it should also check for thePGC_extrabit in 'count_info'.
Quoted 6 lines
This patch therefore defines
is_special_page()to cover both cases and converts tests ofis_xen_heap_page()(or open coded tests ofPGC_xen_heap) tois_special_page()where the page is assigned to a domain.Signed-off-by Paul Durrant <[email protected]>Acked-by Tamas K Lengyel <[email protected]>
The implied ack here is on the assumption that ultimately the per-domain ->xenpage_list will go away altogether, leaving us without the currently resulting mix.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 3/3] mm: add 'is_special_page' inline function...
In reply to Paul DurrantQuoted 10 lines · Paul Durrant
From: Paul Durrant <[email protected]>
... to cover xenheap and
PGC_extrapages.
PGC_extrapages are intended to hold data structures that are associated with a domain and may be mapped by that domain. They should not be treated as 'normal' guest pages (i.e. RAM or page tables). Hence, in many cases where code currently testsis_xen_heap_page()it should also check for thePGC_extrabit in 'count_info'.
Quoted 6 lines
This patch therefore defines
is_special_page()to cover both cases and converts tests ofis_xen_heap_page()(or open coded tests ofPGC_xen_heap) tois_special_page()where the page is assigned to a domain.Signed-off-by Paul Durrant <[email protected]>Acked-by Tamas K Lengyel <[email protected]>
Quoted 268 lines
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>v7:
- Fixed some uses ofis_xen_heap_mfn()that I'd missed
- Updated commit comment to point out that only tests on assigned xenheap pages are candidates for conversionv6:
- Convert open-coded checks ofPGC_xen_heapto useis_special_page()where appropriatev4:
- Use inline function instead of macro
- Add missing conversions fromis_xen_heap_page()v3:
- Delete obsolete comment.v2:
- New in v2--- xen/arch/x86/domctl.c | 2 +- xen/arch/x86/mm.c | 13 ++++++------- xen/arch/x86/mm/altp2m.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 3 +-- xen/arch/x86/mm/p2m-pod.c | 12 +++++++----- xen/arch/x86/mm/p2m.c | 4 ++-- xen/arch/x86/mm/shadow/common.c | 13 ++++++++----- xen/arch/x86/mm/shadow/multi.c | 3 ++- xen/arch/x86/tboot.c | 4 ++-- xen/include/xen/mm.h | 5 +++++ 10 files changed, 35 insertions(+), 26 deletions(-)xen/arch/x86/domctl.c +1
-1@@ -394,7 +394,7 @@ long arch_do_domctl( page =get_page_from_gfn (d, gfn, &t,P2M_ALLOC );if (unlikely (!page) || -unlikely (is_xen_heap_page (page)) ) +unlikely (is_special_page (page)) ) {if (unlikely (p2m_is_broken (t)) ) type =XEN_DOMCTL_PFINFO_BROKEN ;xen/arch/x86/mm.c +6
-7@@ -1014,7 +1014,7 @@ get_page_from_l1e(unsigned long cacheattr =pte_flags_to_cacheattr (l1f);int err; -if (is_xen_heap_page (page) ) +if (is_special_page (page) ) {if ( write )put_page_type (page);@@ -2447,7 +2447,7 @@ static int cleanup_page_mappings(struct page_info *page) { page->count_info &= ~PGC_cacheattr_mask; -BUG_ON (is_xen_heap_page (page)); +BUG_ON (is_special_page (page)); rc =update_xen_mappings (mfn,0 ); }@@ -2477,7 +2477,7 @@ static int cleanup_page_mappings(struct page_info *page) rc = rc2; } -if (likely (!is_xen_heap_page (page)) ) +if (likely (!is_special_page (page)) ) {ASSERT ((page->u.inuse.type_info & (PGT_type_mask | PGT_count_mask)) == PGT_writable_page);@@ -4216,8 +4216,7 @@ int steal_page(if ( !(owner =page_get_owner_and_reference (page)) ) goto fail; -if ( owner != d ||is_xen_heap_page (page) || - (page->count_info & PGC_extra) ) +if ( owner != d ||is_special_page (page) ) goto fail_put;/* @@ -4580,8 +4579,8 @@ int xenmem_add_to_physmap_one( prev_mfn =get_gfn (d,gfn_x (gpfn), &p2mt);if (mfn_valid (prev_mfn) ) { -if (is_xen_heap_mfn (prev_mfn) ) -/* Xen heap frames are simply unhooked from this phys slot. */ +if (is_special_page (mfn_to_page (prev_mfn)) ) +/* Special pages are simply unhooked from this phys slot. */ rc =guest_physmap_remove_page (d, gpfn, prev_mfn,PAGE_ORDER_4K );else /* Normal domain memory is freed, to avoid leaking memory. */ xen/arch/x86/mm/altp2m.c +1
-1@@ -77,7 +77,7 @@ int altp2m_vcpu_enable_ve(struct vcpu *v, gfn_t gfn)* pageable() predicate for this, due to it having the same properties * that we want. */ -if ( !p2m_is_pageable (p2mt) ||is_xen_heap_page (pg) ) +if ( !p2m_is_pageable (p2mt) ||is_special_page (pg) ) { rc = -EINVAL ; goto err;xen/arch/x86/mm/mem_sharing.c +1
-2@@ -840,9 +840,8 @@ static int nominate_page(struct domain *d, gfn_t gfn,if ( !p2m_is_sharable (p2mt) ) goto out; -/* Skip xen heap pages */ page =mfn_to_page (mfn); -if ( !page ||is_xen_heap_page (page) ) +if ( !page ||is_special_page (page) ) goto out;/* Check if there are mem_access/remapped altp2m entries for this page */ xen/arch/x86/mm/p2m-pod.c +7
-5@@ -749,8 +749,9 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, gfn_t gfn) n =1UL <<min (cur_order,SUPERPAGE_ORDER +0U );for ( k =0 , page =mfn_to_page (mfn); k < n; ++k, ++page ) -if ( !(page->count_info & PGC_allocated) || - (page->count_info & (PGC_page_table | PGC_xen_heap)) || +if (is_special_page (page) || + !(page->count_info & PGC_allocated) || + (page->count_info & PGC_page_table) || (page->count_info & PGC_count_mask) > max_ref ) goto out; }@@ -883,11 +884,12 @@ p2m_pod_zero_check(struct p2m_domain *p2m, const gfn_t *gfns, unsigned int count pg =mfn_to_page (mfns[i]);/* -* If this is ram, and not a pagetable or from the xen heap, and +* If this is ram, and not a pagetable or a special page, and * probably not mapped elsewhere, map it; otherwise, skip. */ -if (p2m_is_ram (types[i]) && (pg->count_info & PGC_allocated) && - !(pg->count_info & (PGC_page_table | PGC_xen_heap)) && +if ( !is_special_page (pg) &&p2m_is_ram (types[i]) && + (pg->count_info & PGC_allocated) && + !(pg->count_info & PGC_page_table) && ((pg->count_info & PGC_count_mask) <= max_ref) ) map[i] =map_domain_page (mfns[i]);else xen/arch/x86/mm/p2m.c +2
-2@@ -2983,8 +2983,8 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, prev_mfn =get_gfn (tdom, gpfn, &p2mt_prev);if (mfn_valid (prev_mfn) ) { -if (is_xen_heap_mfn (prev_mfn) ) -/* Xen heap frames are simply unhooked from this phys slot */ +if (is_special_page (mfn_to_page (prev_mfn)) ) +/* Special pages are simply unhooked from this phys slot */ rc =guest_physmap_remove_page (tdom,_gfn (gpfn), prev_mfn,0 );else /* Normal domain memory is freed, to avoid leaking memory. */ xen/arch/x86/mm/shadow/common.c +8
-5@@ -2087,19 +2087,22 @@ static int sh_remove_all_mappings(struct domain *d, mfn_t gmfn, gfn_t gfn)* The qemu helper process has an untyped mapping of this dom's RAM * and the HVM restore program takes another. * Also allow one typed refcount for -* - Xen heap pages, to match share_xen_page_with_guest(), -* - ioreq server pages, to match prepare_ring_for_helper(). +* - special pages, which are explicitly referenced and mapped by +* Xen. +* - ioreq server pages, which may be special pages or normal +* guest pages with an extra reference taken by +* prepare_ring_for_helper(). */ if ( !(shadow_mode_external (d) && (page->count_info & PGC_count_mask) <=3 && ((page->u.inuse.type_info & PGT_count_mask) - == (is_xen_heap_page (page) || + == (is_special_page (page) || (is_hvm_domain (d) &&is_ioreq_server_page (d, page))))) )printk (XENLOG_G_ERR "can't find all mappings of mfn %" PRI_mfn -" (gfn %" PRI_gfn"): c=%lx t=%lx x=%d i=%d\n" , +" (gfn %" PRI_gfn"): c=%lx t=%lx s=%d i=%d\n" ,mfn_x (gmfn),gfn_x (gfn), page->count_info, page->u.inuse.type_info, - !!is_xen_heap_page (page), +is_special_page (page), (is_hvm_domain (d) &&is_ioreq_server_page (d, page))); }xen/arch/x86/mm/shadow/multi.c +2
-1@@ -559,7 +559,8 @@ _sh_propagate(struct vcpu *v,* caching attributes in the shadows to match what was asked for. */ if ( (level ==1 ) &&is_hvm_domain (d) && - !is_xen_heap_mfn (target_mfn) ) + (!mfn_valid (target_mfn) || + !is_special_page (mfn_to_page (target_mfn))) ) {int type;xen/arch/x86/tboot.c +2
-2@@ -189,7 +189,7 @@ static void update_pagetable_mac(vmac_ctx_t *ctx)if ( !mfn_valid (_mfn (mfn)) )continue ; -if (is_page_in_use (page) && !is_xen_heap_page (page) ) +if (is_page_in_use (page) && !is_special_page (page) ) {if ( page->count_info & PGC_page_table ) {@@ -289,7 +289,7 @@ static void tboot_gen_xenheap_integrity(const uint8_t key[TB_KEY_SIZE], + 3 * PAGE_SIZE)) )continue ;/* skip tboot and its page tables */ -if (is_page_in_use (page) &&is_xen_heap_page (page) ) +if (is_page_in_use (page) &&is_special_page (page) ) {void *pg;xen/include/xen/mm.h +5
-0@@ -285,6 +285,11 @@ extern struct domain *dom_cow;#include <asm/mm.h> +static inline bool is_special_page (const struct page_info *page) +{ +return is_xen_heap_page (page) || (page->count_info & PGC_extra); +} +#ifndef page_list_entrystruct page_list_head {
Signature · 1 line
Julien Grall
Quoted 8 lines · Paul Durrant
This series was formerly called "remove one more shared xenheap page:
shared_info" but I have dropped the patches actually changingshared_infoand just left thePGC_extraclean-up that was previously intertwined.Paul Durrant (3):
mm: keepPGC_extrapages on a separate list
x86 / ioreq: use aMEMF_no_refcountallocation for server pages...
mm: add 'is_special_page' inline function...
So I'm confused - I had just replied twice to v6 patch 5/5. This series calls itself v4 and consists of the middle three patches of what v6 was. What's the deal? Is this really v7, and the two patches have been dropped / postponed?
Jan
Quoted 20 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 24 March 2020 09:39
To: Paul Durrant <[email protected]>
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; Tim Deegan <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH v4 0/3] make surePGC_extrapages are dealt with properlyQuoted 8 lines · Paul Durrant
This series was formerly called "remove one more shared xenheap page:
shared_info" but I have dropped the patches actually changingshared_infoand just left thePGC_extraclean-up that was previously intertwined.Paul Durrant (3):
mm: keepPGC_extrapages on a separate list
x86 / ioreq: use aMEMF_no_refcountallocation for server pages...
mm: add 'is_special_page' inline function...
Quoted 4 lines
So I'm confused - I had just replied twice to v6 patch 5/5. This series calls itself v4 and consists of the middle three patches of what v6 was. What's the deal? Is this really v7, and the two patches have been dropped / postponed?
Sorry, I clearly got confused with numbering against one of my other series. Yes, this should be v7.
I wanted to send the patches that clear up use of PGC_extra, separating from the change to shared_info since I'm pressed for time to complete all the other conversions from xenheap pages such that I can send them as a single series.
Paul
Quoted 2 lines
Jan