x86/mm: Override mfn_to_page() and page_to_mfn() to use mfn_t
PATCH 1/2 x86/mm: Override mfn_to_page() and page_to_mfn() to use mfn_t
To avoid breaking the build elsewhere, the l{1..4}e_{from,get}_page() macros are switched to using __mfn_to_page() and __page_to_mfn().
Most changes are wrapping or removing _mfn()/mfn_x() from existing callsites.
However, {alloc,free}_l1_table() are switched to using __map_domain_page(), as their pfn parameters are otherwise unused. get_page() has one pfn->mfn correction in a printk(), and __get_page_type()'s IOMMU handling has its gfn calculation broken out for clarity.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: George Dunlap <[email protected]>
CC: Tim Deegan <[email protected]>
--- xen/arch/x86/mm.c | 151 ++++++++++++++++++++++++--------------------- xen/include/asm-x86/page.h | 16 ++--- 2 files changed, 88 insertions(+), 79 deletions(-)
xen/arch/x86/mm.c +80 -71
@@ -123,6 +123,12 @@#include <asm/io_apic.h> #include <asm/pci.h> +/* Override macros from asm/mm.h to make them work with mfn_t */ +#undef mfn_to_page +#define mfn_to_page (mfn) __mfn_to_page(mfn_x(mfn)) +#undef page_to_mfn +#define page_to_mfn (pg) _mfn(__page_to_mfn(pg)) +/* Mapping of the fixmap space needed early. */ l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_fixmap[L1_PAGETABLE_ENTRIES ];
@@ -282,7 +288,8 @@ void __init arch_init_memory(void)/* First 1MB of RAM is historically marked as I/O. */ for ( i =0 ; i <0x100 ; i++ ) -share_xen_page_with_guest (mfn_to_page (i), dom_io, XENSHARE_writable); +share_xen_page_with_guest (mfn_to_page (_mfn (i)), + dom_io, XENSHARE_writable);/* Any areas not specified as RAM by the e820 map are considered I/O. */ for ( i =0 , pfn =0 ; pfn < max_page; i++ )
@@ -323,7 +330,7 @@ void __init arch_init_memory(void)if ( !mfn_valid (_mfn (pfn)) )continue ;share_xen_page_with_guest ( -mfn_to_page (pfn), dom_io, XENSHARE_writable); +mfn_to_page (_mfn (pfn)), dom_io, XENSHARE_writable); }/* Skip the RAM region. */
@@ -425,7 +432,7 @@ void share_xen_page_with_guest(if (page_get_owner (page) == d )return ; -set_gpfn_from_mfn (page_to_mfn (page),INVALID_M2P_ENTRY ); +set_gpfn_from_mfn (mfn_x (page_to_mfn (page)),INVALID_M2P_ENTRY );spin_lock (&d->page_alloc_lock);
@@ -682,7 +689,8 @@ int map_ldt_shadow_page(unsigned int off)return 0 ; } - nl1e =l1e_from_pfn (page_to_mfn (page),l1e_get_flags (l1e) | _PAGE_RW); + nl1e =l1e_from_pfn (mfn_x (page_to_mfn (page)), +l1e_get_flags (l1e) | _PAGE_RW);spin_lock (&v->arch.pv_vcpu.shadow_ldt_lock);l1e_write (&gdt_ldt_ptes (d, v)[off +16 ], nl1e);
@@ -695,7 +703,7 @@ int map_ldt_shadow_page(unsigned int off)static bool get_page_from_mfn (mfn_t mfn,struct domain *d) { -struct page_info *page =mfn_to_page (mfn_x (mfn)); +struct page_info *page =mfn_to_page (mfn);if (unlikely (!mfn_valid (mfn)) ||unlikely (!get_page (page, d)) ) {
@@ -712,7 +720,7 @@ static int get_page_and_type_from_mfn( mfn_t mfn, unsigned long type, struct domain *d, int partial, int preemptible) { - struct page_info *page = mfn_to_page(mfn_x(mfn)); + struct page_info *page = mfn_to_page(mfn);int rc; if ( likely(partial >= 0) &&
@@ -777,7 +785,7 @@ get_##level##_linear_pagetable( \* Ensure that the mapped frame is an already-validated page table. \ * If so, atomically increment the count (checking for overflow). \ */ \ - page =mfn_to_page (pfn); \ + page =mfn_to_page (_mfn (pfn)); \ y = page->u.inuse.type_info; \ do { \ x = y; \
@@ -804,7 +812,7 @@ bool is_iomem_page(mfn_t mfn)return true;/* Caller must know that it is an iomem page, or a reference is held. */ - page =mfn_to_page (mfn_x (mfn)); + page =mfn_to_page (mfn);ASSERT ((page->count_info & PGC_count_mask) !=0 );return (page_get_owner (page) == dom_io);
@@ -873,7 +881,7 @@ get_page_from_l1e( l1_pgentry_t l1e, struct domain *l1e_owner, struct domain *pg_owner) { unsigned long mfn = l1e_get_pfn(l1e); -struct page_info *page =mfn_to_page (mfn); +struct page_info *page =mfn_to_page (_mfn (mfn));uint32_t l1f =l1e_get_flags (l1e);struct vcpu *curr = current;struct domain *real_pg_owner;
@@ -1219,7 +1227,7 @@ void put_page_from_l1e(l1_pgentry_t l1e, struct domain *l1e_owner)if ( !(l1e_get_flags (l1e) & _PAGE_PRESENT) ||is_iomem_page (_mfn (pfn)) )return ; - page =mfn_to_page (pfn); + page =mfn_to_page (_mfn (pfn)); pg_owner =page_get_owner (page);/*
@@ -1280,7 +1288,7 @@ static int put_page_from_l2e(l2_pgentry_t l2e, unsigned long pfn)if (l2e_get_flags (l2e) & _PAGE_PSE ) { -struct page_info *page =mfn_to_page (l2e_get_pfn (l2e)); +struct page_info *page =mfn_to_page (_mfn (l2e_get_pfn (l2e)));unsigned int i;for ( i =0 ; i < (1u <<PAGETABLE_ORDER ); i++, page++ )
@@ -1308,7 +1316,7 @@ static int put_page_from_l3e(l3_pgentry_t l3e, unsigned long pfn,ASSERT (!(mfn & ((1UL << (L3_PAGETABLE_SHIFT -PAGE_SHIFT )) -1 )));do { -put_data_page (mfn_to_page (mfn), writeable); +put_data_page (mfn_to_page (_mfn (mfn)), writeable); }while ( ++mfn & ((1UL << (L3_PAGETABLE_SHIFT -PAGE_SHIFT )) -1 ) );return 0 ;
@@ -1359,12 +1367,11 @@ static int put_page_from_l4e(l4_pgentry_t l4e, unsigned long pfn,static int alloc_l1_table (struct page_info *page) {struct domain *d =page_get_owner (page); -unsigned long pfn =page_to_mfn (page);l1_pgentry_t *pl1e;unsigned int i;int ret =0 ; - pl1e =map_domain_page (_mfn (pfn)); + pl1e =__map_domain_page (page);for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) {
@@ -1439,7 +1446,7 @@ static int alloc_l2_table(struct page_info *page, unsigned long type, int preemptible) {struct domain *d =page_get_owner (page); -unsigned long pfn =page_to_mfn (page); +unsigned long pfn =mfn_x (page_to_mfn (page));l2_pgentry_t *pl2e;unsigned int i;int rc =0 ;
@@ -1488,7 +1495,7 @@ static int alloc_l2_table(struct page_info *page, unsigned long type,static int alloc_l3_table (struct page_info *page) {struct domain *d =page_get_owner (page); -unsigned long pfn =page_to_mfn (page); +unsigned long pfn =mfn_x (page_to_mfn (page));l3_pgentry_t *pl3e;unsigned int i;int rc =0 , partial = page->partial_pte;
@@ -1609,7 +1616,7 @@ void zap_ro_mpt(unsigned long mfn)static int alloc_l4_table (struct page_info *page) {struct domain *d =page_get_owner (page); -unsigned long pfn =page_to_mfn (page); +unsigned long pfn =mfn_x (page_to_mfn (page));l4_pgentry_t *pl4e =map_domain_page (_mfn (pfn));unsigned int i;int rc =0 , partial = page->partial_pte;
@@ -1668,11 +1675,10 @@ static int alloc_l4_table(struct page_info *page)static void free_l1_table (struct page_info *page) {struct domain *d =page_get_owner (page); -unsigned long pfn =page_to_mfn (page);l1_pgentry_t *pl1e;unsigned int i; - pl1e =map_domain_page (_mfn (pfn)); + pl1e =__map_domain_page (page);for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ )put_page_from_l1e (pl1e[i], d);
@@ -1684,7 +1690,7 @@ static void free_l1_table(struct page_info *page)static int free_l2_table (struct page_info *page,int preemptible) {struct domain *d =page_get_owner (page); -unsigned long pfn =page_to_mfn (page); +unsigned long pfn =mfn_x (page_to_mfn (page));l2_pgentry_t *pl2e;unsigned int i = page->nr_validated_ptes -1 ;int err =0 ;
@@ -1713,7 +1719,7 @@ static int free_l2_table(struct page_info *page, int preemptible)static int free_l3_table (struct page_info *page) {struct domain *d =page_get_owner (page); -unsigned long pfn =page_to_mfn (page); +unsigned long pfn =mfn_x (page_to_mfn (page));l3_pgentry_t *pl3e;int rc =0 , partial = page->partial_pte;unsigned int i = page->nr_validated_ptes - !partial;
@@ -1752,7 +1758,7 @@ static int free_l3_table(struct page_info *page)static int free_l4_table (struct page_info *page) {struct domain *d =page_get_owner (page); -unsigned long pfn =page_to_mfn (page); +unsigned long pfn =mfn_x (page_to_mfn (page));l4_pgentry_t *pl4e =map_domain_page (_mfn (pfn));int rc =0 , partial = page->partial_pte;unsigned int i = page->nr_validated_ptes - !partial;
@@ -1911,7 +1917,7 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, page =get_page_from_gfn (pg_dom,l1e_get_pfn (nl1e),NULL ,P2M_ALLOC );if ( !page )return -EINVAL ; - nl1e =l1e_from_pfn (page_to_mfn (page),l1e_get_flags (nl1e)); + nl1e =l1e_from_pfn (mfn_x (page_to_mfn (page)),l1e_get_flags (nl1e)); }/* Fast path for sufficiently-similar mappings. */
@@ -1970,7 +1976,7 @@ static int mod_l2_entry(l2_pgentry_t *pl2e, {l2_pgentry_t ol2e;struct domain *d = vcpu->domain; -struct page_info *l2pg =mfn_to_page (pfn); +struct page_info *l2pg =mfn_to_page (_mfn (pfn));unsigned long type = l2pg->u.inuse.type_info;int rc =0 ;
@@ -2168,7 +2174,7 @@ static int cleanup_page_cacheattr(struct page_info *page)BUG_ON (is_xen_heap_page (page)); -return update_xen_mappings (page_to_mfn (page),0 ); +return update_xen_mappings (mfn_x (page_to_mfn (page)),0 ); }void put_page (struct page_info *page)
@@ -2188,7 +2194,7 @@ void put_page(struct page_info *page)free_domheap_page (page); else gdprintk(XENLOG_WARNING, - "Leaking mfn %" PRI_pfn "\n", page_to_mfn(page)); + "Leaking mfn %" PRI_mfn "\n", mfn_x(page_to_mfn(page))); } }
@@ -2226,8 +2232,8 @@ int get_page(struct page_info *page, struct domain *domain)if ( !paging_mode_refcounts (domain) && !domain->is_dying )gprintk (XENLOG_INFO , -"Error pfn %lx: rd=%d od=%d caf=%08lx taf=%" PRtype_info"\n" , -page_to_mfn (page), domain->domain_id, +"Error mfn %" PRI_mfn": rd=%d od=%d caf=%08lx taf=%" PRtype_info"\n" , +mfn_x (page_to_mfn (page)), domain->domain_id, owner ? owner->domain_id :DOMID_INVALID , page->count_info - !!owner, page->u.inuse.type_info);
@@ -2267,7 +2273,7 @@ static int alloc_page_type(struct page_info *page, unsigned long type,/* A page table is dirtied when its type count becomes non-zero. */ if (likely (owner !=NULL ) ) -paging_mark_dirty (owner,_mfn (page_to_mfn (page))); +paging_mark_dirty (owner,page_to_mfn (page));switch ( type & PGT_type_mask ) {
@@ -2313,7 +2319,8 @@ static int alloc_page_type(struct page_info *page, unsigned long type,gdprintk (XENLOG_WARNING ,"Error while validating mfn %" PRI_mfn" (pfn %" PRI_pfn") for type %" PRtype_info": caf=%08lx taf=%" PRtype_info"\n" , -page_to_mfn (page),get_gpfn_from_mfn (page_to_mfn (page)), +mfn_x (page_to_mfn (page)), +get_gpfn_from_mfn (mfn_x (page_to_mfn (page))), type, page->count_info, page->u.inuse.type_info);if ( page != current->arch.old_guest_table ) page->u.inuse.type_info =0 ;
@@ -2342,11 +2349,11 @@ int free_page_type(struct page_info *page, unsigned long type,if (likely (owner !=NULL ) &&unlikely (paging_mode_enabled (owner)) ) {/* A page table is dirtied when its type count becomes zero. */ -paging_mark_dirty (owner,_mfn (page_to_mfn (page))); +paging_mark_dirty (owner,page_to_mfn (page));ASSERT (!shadow_mode_refcounts (owner)); - gmfn =mfn_to_gmfn (owner,page_to_mfn (page)); + gmfn =mfn_to_gmfn (owner,mfn_x (page_to_mfn (page)));ASSERT (VALID_M2P (gmfn));/* Page sharing not supported for shadowed domains */ if (!SHARED_M2P (gmfn))
@@ -2378,7 +2385,7 @@ int free_page_type(struct page_info *page, unsigned long type,break ;default :gdprintk (XENLOG_WARNING ,"type %" PRtype_info" mfn %" PRI_mfn"\n" , - type,page_to_mfn (page)); + type,mfn_x (page_to_mfn (page))); rc = -EINVAL ;BUG (); }
@@ -2484,7 +2491,7 @@ static int __get_page_type(struct page_info *page, unsigned long type, {gdprintk (XENLOG_WARNING ,"Type count overflow on mfn %" PRI_mfn"\n" , -page_to_mfn (page)); +mfn_x (page_to_mfn (page)));return -EINVAL ; } else if ( unlikely((x & PGT_count_mask) == 0) )
@@ -2501,7 +2508,7 @@ static int __get_page_type(struct page_info *page, unsigned long type, && (page->count_info & PGC_page_table) && !((page->shadow_flags & (1u<<29)) && type == PGT_writable_page) ) -shadow_remove_all_shadows (d,_mfn (page_to_mfn (page))); +shadow_remove_all_shadows (d,page_to_mfn (page));ASSERT (!(x & PGT_pae_xen_l2));if ( (x & PGT_type_mask) != type )
@@ -2555,8 +2562,8 @@ static int __get_page_type(struct page_info *page, unsigned long type,gdprintk (XENLOG_WARNING ,"Bad type (saw %" PRtype_info" != exp %" PRtype_info") " "for mfn %" PRI_mfn" (pfn %" PRI_pfn")\n" , - x, type,page_to_mfn (page), -get_gpfn_from_mfn (page_to_mfn (page))); + x, type,mfn_x (page_to_mfn (page)), +get_gpfn_from_mfn (mfn_x (page_to_mfn (page))));return -EINVAL ; }else if (unlikely (!(x & PGT_validated)) )
@@ -2590,11 +2597,13 @@ static int __get_page_type(struct page_info *page, unsigned long type,struct domain *d =page_get_owner (page);if ( d &&is_pv_domain (d) &&unlikely (need_iommu (d)) ) { +gfn_t gfn =_gfn (mfn_to_gmfn (d,mfn_x (page_to_mfn (page)))); +if ( (x & PGT_type_mask) == PGT_writable_page ) - iommu_ret =iommu_unmap_page (d,mfn_to_gmfn (d,page_to_mfn (page))); + iommu_ret =iommu_unmap_page (d,gfn_x (gfn));else if ( type == PGT_writable_page ) - iommu_ret =iommu_map_page (d,mfn_to_gmfn (d,page_to_mfn (page)), -page_to_mfn (page), + iommu_ret =iommu_map_page (d,gfn_x (gfn), +mfn_x (page_to_mfn (page)), IOMMUF_readable|IOMMUF_writable); } }
@@ -2682,7 +2691,7 @@ int vcpu_destroy_pagetables(struct vcpu *v)if ( mfn ) { - page =mfn_to_page (mfn); + page =mfn_to_page (_mfn (mfn));if (paging_mode_refcounts (v->domain) )put_page (page);else
@@ -2703,7 +2712,7 @@ int vcpu_destroy_pagetables(struct vcpu *v) mfn =pagetable_get_pfn (v->arch.guest_table_user);if ( mfn ) { - page =mfn_to_page (mfn); + page =mfn_to_page (_mfn (mfn));if (paging_mode_refcounts (v->domain) )put_page (page);else
@@ -2802,7 +2811,7 @@ int new_guest_cr3(unsigned long mfn)if (likely (old_base_mfn !=0 ) ) { -struct page_info *page =mfn_to_page (old_base_mfn); +struct page_info *page =mfn_to_page (_mfn (old_base_mfn));if (paging_mode_refcounts (d) )put_page (page);
@@ -3041,7 +3050,7 @@ long do_mmuext_op(else if ( rc != -ERESTART )gdprintk (XENLOG_WARNING ,"Error %d while pinning mfn %" PRI_mfn"\n" , - rc,page_to_mfn (page)); + rc,mfn_x (page_to_mfn (page)));if ( page != curr->arch.old_guest_table )put_page (page);break ;
@@ -3052,7 +3061,8 @@ long do_mmuext_op( &page->u.inuse.type_info)) ) {gdprintk (XENLOG_WARNING , -"mfn %" PRI_mfn" already pinned\n" ,page_to_mfn (page)); +"mfn %" PRI_mfn" already pinned\n" , +mfn_x (page_to_mfn (page))); rc = -EINVAL ; }
@@ -3060,7 +3070,7 @@ long do_mmuext_op( goto pin_drop;/* A page is dirtied when its pin status is set. */ -paging_mark_dirty (pg_owner,_mfn (page_to_mfn (page))); +paging_mark_dirty (pg_owner,page_to_mfn (page));/* We can race domain destruction (domain_relinquish_resources). */ if (unlikely (pg_owner != currd) )
@@ -3120,7 +3130,7 @@ long do_mmuext_op(put_page (page);/* A page is dirtied when its pin status is cleared. */ -paging_mark_dirty (pg_owner,_mfn (page_to_mfn (page))); +paging_mark_dirty (pg_owner,page_to_mfn (page));break ;case MMUEXT_NEW_BASEPTR :
@@ -3174,7 +3184,7 @@ long do_mmuext_op(if ( old_mfn !=0 ) { - page =mfn_to_page (old_mfn); + page =mfn_to_page (_mfn (old_mfn));switch ( rc =put_page_and_type_preemptible (page) ) {
@@ -3318,9 +3328,9 @@ long do_mmuext_op( }/* A page is dirtied when it's being cleared. */ -paging_mark_dirty (pg_owner,_mfn (page_to_mfn (page))); +paging_mark_dirty (pg_owner,page_to_mfn (page)); -clear_domain_page (_mfn (page_to_mfn (page))); +clear_domain_page (page_to_mfn (page));put_page_and_type (page);break ;
@@ -3365,10 +3375,9 @@ long do_mmuext_op( }/* A page is dirtied when it's being copied to. */ -paging_mark_dirty (pg_owner,_mfn (page_to_mfn (dst_page))); +paging_mark_dirty (pg_owner,page_to_mfn (dst_page)); -copy_domain_page (_mfn (page_to_mfn (dst_page)), -_mfn (page_to_mfn (src_page))); +copy_domain_page (page_to_mfn (dst_page),page_to_mfn (src_page));put_page_and_type (dst_page);put_page (src_page);
@@ -3566,7 +3575,7 @@ long do_mmu_update(break ; } - mfn =page_to_mfn (page); + mfn =mfn_x (page_to_mfn (page));if ( !mfn_eq (_mfn (mfn), map_mfn) ) {
@@ -3694,7 +3703,7 @@ long do_mmu_update(paging_mark_dirty (pg_owner,_mfn (mfn)); -put_page (mfn_to_page (mfn)); +put_page (mfn_to_page (_mfn (mfn)));break ;default :
@@ -3777,7 +3786,7 @@ static int create_grant_pte_mapping(return GNTST_general_error; } - mfn =page_to_mfn (page); + mfn =mfn_x (page_to_mfn (page)); va =map_domain_page (_mfn (mfn)); va = (void *)((unsigned long )va + ((unsigned long )pte_addr & ~PAGE_MASK ));
@@ -3841,7 +3850,7 @@ static int destroy_grant_pte_mapping(return GNTST_general_error; } - mfn =page_to_mfn (page); + mfn =mfn_x (page_to_mfn (page)); va =map_domain_page (_mfn (mfn)); va = (void *)((unsigned long )va + ((unsigned long )addr & ~PAGE_MASK ));
@@ -3916,7 +3925,7 @@ static int create_grant_va_mapping(return GNTST_general_error; } - l1pg =mfn_to_page (gl1mfn); + l1pg =mfn_to_page (_mfn (gl1mfn));if ( !page_lock (l1pg) ) {put_page (l1pg);
@@ -3966,7 +3975,7 @@ static int replace_grant_va_mapping( goto out; } - l1pg =mfn_to_page (gl1mfn); + l1pg =mfn_to_page (_mfn (gl1mfn));if ( !page_lock (l1pg) ) { rc = GNTST_general_error;
@@ -4135,7 +4144,7 @@ int replace_grant_host_mapping(return GNTST_general_error; } - l1pg =mfn_to_page (gl1mfn); + l1pg =mfn_to_page (_mfn (gl1mfn));if ( !page_lock (l1pg) ) {put_page (l1pg);
@@ -4208,7 +4217,7 @@ int donate_page(spin_unlock (&d->page_alloc_lock);gdprintk (XENLOG_WARNING ,"Bad donate mfn %" PRI_mfn" to d%d (owner d%d) caf=%08lx taf=%" PRtype_info"\n" , -page_to_mfn (page), d->domain_id, +mfn_x (page_to_mfn (page)), d->domain_id, owner ? owner->domain_id :DOMID_INVALID , page->count_info, page->u.inuse.type_info);return -EINVAL ;
@@ -4274,7 +4283,7 @@ int steal_page(spin_unlock (&d->page_alloc_lock);gdprintk (XENLOG_WARNING ,"Bad steal mfn %" PRI_mfn" from d%d (owner d%d) caf=%08lx taf=%" PRtype_info"\n" , -page_to_mfn (page), d->domain_id, +mfn_x (page_to_mfn (page)), d->domain_id, owner ? owner->domain_id :DOMID_INVALID , page->count_info, page->u.inuse.type_info);return -EINVAL ;
@@ -4303,7 +4312,7 @@ static int __do_update_va_mapping(if (unlikely (!pl1e || !get_page_from_mfn (_mfn (gl1mfn), d)) ) goto out; - gl1pg =mfn_to_page (gl1mfn); + gl1pg =mfn_to_page (_mfn (gl1mfn));if ( !page_lock (gl1pg) ) {put_page (gl1pg);
@@ -4413,7 +4422,7 @@ void destroy_gdt(struct vcpu *v) { pfn =l1e_get_pfn (pl1e[i]);if ( (l1e_get_flags (pl1e[i]) & _PAGE_PRESENT) && pfn != zero_pfn ) -put_page_and_type (mfn_to_page (pfn)); +put_page_and_type (mfn_to_page (_mfn (pfn)));l1e_write (&pl1e[i],l1e_from_pfn (zero_pfn, __PAGE_HYPERVISOR_RO)); v->arch.pv_vcpu.gdt_frames[i] =0 ; }
@@ -4445,7 +4454,7 @@ long set_gdt(struct vcpu *v,put_page (page); goto fail; } - frames[i] =page_to_mfn (page); + frames[i] =mfn_x (page_to_mfn (page)); }/* Tear down the old GDT. */
@@ -4465,7 +4474,7 @@ long set_gdt(struct vcpu *v, fail:while ( i-- >0 ) { -put_page_and_type (mfn_to_page (frames[i])); +put_page_and_type (mfn_to_page (_mfn (frames[i]))); }return -EINVAL ; }
@@ -4520,7 +4529,7 @@ long do_update_descriptor(u64 pa, u64 desc)put_page (page);return -EINVAL ; } - mfn =page_to_mfn (page); + mfn =mfn_x (page_to_mfn (page));/* Check if the given frame is in use in an unsafe context. */ switch ( page->u.inuse.type_info & PGT_type_mask )
@@ -4675,7 +4684,7 @@ int xenmem_add_to_physmap_one(if ( !get_page_from_mfn (_mfn (idx), d) )break ; mfn = idx; - page =mfn_to_page (mfn); + page =mfn_to_page (_mfn (mfn));break ; }case XENMAPSPACE_gmfn_foreign:
@@ -5044,7 +5053,7 @@ static int ptwr_emulated_update( pte = ptwr_ctxt->pte; mfn =l1e_get_pfn (pte); - page =mfn_to_page (mfn); + page =mfn_to_page (_mfn (mfn));/* We are looking only for read-only mappings of p.t. pages. */ ASSERT ((l1e_get_flags (pte) & (_PAGE_RW|_PAGE_PRESENT)) == _PAGE_PRESENT);
@@ -5371,7 +5380,7 @@ int mmio_ro_do_page_fault(struct vcpu *v, unsigned long addr, mfn =l1e_get_pfn (pte);if (mfn_valid (_mfn (mfn)) ) { -struct page_info *page =mfn_to_page (mfn); +struct page_info *page =mfn_to_page (_mfn (mfn));struct domain *owner =page_get_owner_and_reference (page);if ( owner )
@@ -6212,7 +6221,7 @@ int create_perdomain_mapping(struct domain *d, unsigned long va, pg =alloc_domheap_page (d, MEMF_no_owner);if ( pg ) { -clear_domain_page (_mfn (page_to_mfn (pg))); +clear_domain_page (page_to_mfn (pg));if ( !IS_NIL (ppg) ) *ppg++ = pg; l1tab[l1_table_offset(va)] =
xen/include/asm-x86/page.h +8 -8
@@ -82,10 +82,10 @@ ((paddr_t)(((x).l4 & (PADDR_MASK &PAGE_MASK )))) /* Get pointer to info structure of page mapped by pte (struct page_info *). */ -#define l1e_get_page (x) (mfn_to_page(l1e_get_pfn(x))) -#define l2e_get_page (x) (mfn_to_page(l2e_get_pfn(x))) -#define l3e_get_page (x) (mfn_to_page(l3e_get_pfn(x))) -#define l4e_get_page (x) (mfn_to_page(l4e_get_pfn(x))) +#define l1e_get_page (x) (__mfn_to_page(l1e_get_pfn(x))) +#define l2e_get_page (x) (__mfn_to_page(l2e_get_pfn(x))) +#define l3e_get_page (x) (__mfn_to_page(l3e_get_pfn(x))) +#define l4e_get_page (x) (__mfn_to_page(l4e_get_pfn(x)))/* Get pte access flags (unsigned int). */ #define l1e_get_flags (x) (get_pte_flags((x).l1))
@@ -145,10 +145,10 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)#define l4e_from_intpte (intpte) ((l4_pgentry_t) { (intpte_t)(intpte) })/* Construct a pte from a page pointer and access flags. */ -#define l1e_from_page (page, flags) (l1e_from_pfn(page_to_mfn(page),(flags))) -#define l2e_from_page (page, flags) (l2e_from_pfn(page_to_mfn(page),(flags))) -#define l3e_from_page (page, flags) (l3e_from_pfn(page_to_mfn(page),(flags))) -#define l4e_from_page (page, flags) (l4e_from_pfn(page_to_mfn(page),(flags))) +#define l1e_from_page (page, flags) (l1e_from_pfn(__page_to_mfn(page), (flags))) +#define l2e_from_page (page, flags) (l2e_from_pfn(__page_to_mfn(page), (flags))) +#define l3e_from_page (page, flags) (l3e_from_pfn(__page_to_mfn(page), (flags))) +#define l4e_from_page (page, flags) (l4e_from_pfn(__page_to_mfn(page), (flags)))/* Add extra flags to an existing pte. */ #define l1e_add_flags (x, flags) ((x).l1 |= put_pte_flags(flags))
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/2 x86/smp: Misc cleanup
* Delete trailing whitespace
* Switch to using mfn_t for mfn_to_page()/page_to_mfn()
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/smpboot.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
xen/arch/x86/smpboot.c +19 -13
@@ -4,17 +4,17 @@* This inherits a great deal from Linux's SMP boot code: * (c) 1995 Alan Cox, Building #3 <[email protected]> * (c) 1998, 1999, 2000 Ingo Molnar <[email protected]> -* +* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program; If not, see <http://www.gnu.org/licenses/>. */
@@ -46,6 +46,12 @@#include <mach_wakecpu.h> #include <smpboot_hooks.h> +/* Override macros from asm/mm.h to make them work with mfn_t */ +#undef mfn_to_page +#define mfn_to_page (mfn) __mfn_to_page(mfn_x(mfn)) +#undef page_to_mfn +#define page_to_mfn (pg) _mfn(__page_to_mfn(pg)) +#define setup_trampoline () (bootsym_phys(trampoline_realmode_entry))unsigned long __read_mostly trampoline_phys;
@@ -307,14 +313,14 @@ void start_secondary(void *unused)* Just as during early bootstrap, it is convenient here to disable * spinlock checking while we have IRQs disabled. This allows us to * acquire IRQ-unsafe locks when it would otherwise be disallowed. -* +* * It is safe because the race we are usually trying to avoid involves * a group of CPUs rendezvousing in an IPI handler, where one cannot * join because it is spinning with IRQs disabled waiting to acquire a * lock held by another in the rendezvous group (the lock must be an * IRQ-unsafe lock since the CPU took the IPI after acquiring it, and * hence had IRQs enabled). This is a deadlock scenario. -* +* * However, no CPU can be involved in rendezvous until it is online, * hence no such group can be waiting for this CPU until it is * visible in cpu_online_map. Hence such a deadlock is not possible.
@@ -423,8 +429,8 @@ static int wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)else if (tboot_in_measured_env () ) {/* -* With tboot AP is actually spinning in a mini-guest before -* receiving INIT. Upon receiving INIT ipi, AP need time to VMExit, +* With tboot AP is actually spinning in a mini-guest before +* receiving INIT. Upon receiving INIT ipi, AP need time to VMExit, * update VMCS to tracking SIPIs and VMResume. * * While AP is in root mode handling the INIT the CPU will drop
@@ -596,7 +602,7 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)BUILD_BUG_ON (STUBS_PER_PAGE & (STUBS_PER_PAGE -1 ));if ( *mfn ) - pg =mfn_to_page (*mfn); + pg =mfn_to_page (_mfn (*mfn));else {nodeid_t node =cpu_to_node (cpu);
@@ -610,7 +616,7 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) } stub_va =XEN_VIRT_END - (cpu +1 ) *PAGE_SIZE ; -if (map_pages_to_xen (stub_va,page_to_mfn (pg),1 , +if (map_pages_to_xen (stub_va,mfn_x (page_to_mfn (pg)),1 ,PAGE_HYPERVISOR_RX |MAP_SMALL_PAGES ) ) {if ( !*mfn )
@@ -618,7 +624,7 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) stub_va =0 ; }else if ( !*mfn ) - *mfn =page_to_mfn (pg); + *mfn =mfn_x (page_to_mfn (pg));return stub_va; }
@@ -652,8 +658,8 @@ static void cpu_smpboot_free(unsigned int cpu)if (per_cpu (stubs.addr, cpu) ) { -unsigned long mfn =per_cpu (stubs.mfn, cpu); -unsigned char *stub_page =map_domain_page (_mfn (mfn)); +mfn_t mfn =_mfn (per_cpu (stubs.mfn, cpu)); +unsigned char *stub_page =map_domain_page (mfn);unsigned int i;memset (stub_page +STUB_BUF_CPU_OFFS (cpu),0xcc ,STUB_BUF_SIZE );
@@ -871,7 +877,7 @@ remove_siblinginfo(int cpu)if (cpumask_weight (per_cpu (cpu_sibling_mask, cpu)) ==1 ) cpu_data[sibling].booted_cores--; } - +for_each_cpu (sibling,per_cpu (cpu_sibling_mask, cpu))cpumask_clear_cpu (cpu,per_cpu (cpu_sibling_mask, sibling));cpumask_clear (per_cpu (cpu_sibling_mask, cpu));
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 2/2] x86/smp: Misc cleanup
Quoted 5 lines · Andrew Cooper
* Delete trailing whitespace
* Switch to usingmfn_tfor mfn_to_page()/page_to_mfn()Signed-off-by Andrew Cooper <[email protected]>
[...]
Quoted 1 line
+/* Override macros from
asm/mm.hto make them work withmfn_t*/
Same here.
Otherwise:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 2/2] x86/smp: Misc cleanup
In reply to Andrew CooperQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.08.17 at 12:27, <[email protected]> wrote:
* Delete trailing whitespace
* Switch to usingmfn_tfor mfn_to_page()/page_to_mfn()Signed-off-by Andrew Cooper <[email protected]>
again with Wei's remark addressed.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 28 lines · Andrew Cooper
To avoid breaking the build elsewhere, the l{1..4}e_{from,get}_page() macros are switched to using
__mfn_to_page()and__page_to_mfn().Most changes are wrapping or removing _mfn()/mfn_x() from existing callsites.
However, {alloc,free}_l1_table() are switched to using
__map_domain_page(), as their pfn parameters are otherwise unused.get_page()has onepfn->mfncorrection in aprintk(), and __get_page_type()'s IOMMU handling has its gfn calculation broken out for clarity.No functional change.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: George Dunlap <[email protected]>
CC: Tim Deegan <[email protected]>--- xen/arch/x86/mm.c | 151 ++++++++++++++++++++++++--------------------- xen/include/asm-x86/page.h | 16 ++--- 2 files changed, 88 insertions(+), 79 deletions(-)xen/arch/x86/mm.c +0
-0
xen/arch/x86/mm.c line 126
Quoted 4 lines
xen/arch/x86/mm.c +1
-0@@ -123,6 +123,12 @@#include <asm/io_apic.h> #include <asm/pci.h> +/* Override macros from asm/mm.h to make them work with mfn_t */
They are from asm/page.h.
Otherwise:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.08.17 at 12:27, <[email protected]> wrote:
To avoid breaking the build elsewhere, the l{1..4}e_{from,get}_page() macros are switched to using
__mfn_to_page()and__page_to_mfn().Most changes are wrapping or removing _mfn()/mfn_x() from existing callsites.
Quoted 8 lines
However, {alloc,free}_l1_table() are switched to using
__map_domain_page(), as their pfn parameters are otherwise unused.get_page()has onepfn->mfncorrection in aprintk(), and __get_page_type()'s IOMMU handling has its gfn calculation broken out for clarity.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
with Wei's remark addressed and with one optional further request:
Quoted 19 lines
xen/include/asm-x86/page.h +4
-4@@ -82,10 +82,10 @@ ((paddr_t)(((x).l4 & (PADDR_MASK &PAGE_MASK )))) /* Get pointer to info structure of page mapped by pte (struct page_info *). */ -#define l1e_get_page (x) (mfn_to_page(l1e_get_pfn(x))) -#define l2e_get_page (x) (mfn_to_page(l2e_get_pfn(x))) -#define l3e_get_page (x) (mfn_to_page(l3e_get_pfn(x))) -#define l4e_get_page (x) (mfn_to_page(l4e_get_pfn(x))) +#define l1e_get_page (x) (__mfn_to_page(l1e_get_pfn(x))) +#define l2e_get_page (x) (__mfn_to_page(l2e_get_pfn(x))) +#define l3e_get_page (x) (__mfn_to_page(l3e_get_pfn(x))) +#define l4e_get_page (x) (__mfn_to_page(l4e_get_pfn(x)))/* Get pte access flags (unsigned int). */ #define l1e_get_flags (x) (get_pte_flags((x).l1))@@ -145,10 +145,10 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)#define l4e_from_intpte (intpte) ((l4_pgentry_t) { (intpte_t)(intpte) })
xen/include/asm-x86/page.h static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) · line 151
Quoted 10 lines
xen/include/asm-x86/page.h +4
-4/* Construct a pte from a page pointer and access flags. */ -#define l1e_from_page (page, flags) (l1e_from_pfn(page_to_mfn(page),(flags))) -#define l2e_from_page (page, flags) (l2e_from_pfn(page_to_mfn(page),(flags))) -#define l3e_from_page (page, flags) (l3e_from_pfn(page_to_mfn(page),(flags))) -#define l4e_from_page (page, flags) (l4e_from_pfn(page_to_mfn(page),(flags))) +#define l1e_from_page (page, flags) (l1e_from_pfn(__page_to_mfn(page), (flags))) +#define l2e_from_page (page, flags) (l2e_from_pfn(__page_to_mfn(page), (flags))) +#define l3e_from_page (page, flags) (l3e_from_pfn(__page_to_mfn(page), (flags))) +#define l4e_from_page (page, flags) (l4e_from_pfn(__page_to_mfn(page), (flags)))
Mind at once stripping the pointless outer parentheses from all the macros you modify, and the ones around flags in the latter set?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 37 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.08.17 at 12:27, <[email protected]> wrote:
To avoid breaking the build elsewhere, the l{1..4}e_{from,get}_page() macros are switched to using
__mfn_to_page()and__page_to_mfn().Most changes are wrapping or removing _mfn()/mfn_x() from existing callsites.
Quoted 8 lines
However, {alloc,free}_l1_table() are switched to using
__map_domain_page(), as their pfn parameters are otherwise unused.get_page()has onepfn->mfncorrection in aprintk(), and __get_page_type()'s IOMMU handling has its gfn calculation broken out for clarity.No functional change.
Signed-off-by Andrew Cooper <[email protected]>Acked-by Jan Beulich <[email protected]>with Wei's remark addressed and with one optional further request:
Quoted 20 lines
xen/include/asm-x86/page.h +4
-4@@ -82,10 +82,10 @@ ((paddr_t)(((x).l4 & (PADDR_MASK &PAGE_MASK )))) /* Get pointer to info structure of page mapped by pte (struct page_info *). */ -#define l1e_get_page (x) (mfn_to_page(l1e_get_pfn(x))) -#define l2e_get_page (x) (mfn_to_page(l2e_get_pfn(x))) -#define l3e_get_page (x) (mfn_to_page(l3e_get_pfn(x))) -#define l4e_get_page (x) (mfn_to_page(l4e_get_pfn(x))) +#define l1e_get_page (x) (__mfn_to_page(l1e_get_pfn(x))) +#define l2e_get_page (x) (__mfn_to_page(l2e_get_pfn(x))) +#define l3e_get_page (x) (__mfn_to_page(l3e_get_pfn(x))) +#define l4e_get_page (x) (__mfn_to_page(l4e_get_pfn(x)))/* Get pte access flags (unsigned int). */ #define l1e_get_flags (x) (get_pte_flags((x).l1))@@ -145,10 +145,10 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)#define l4e_from_intpte (intpte) ((l4_pgentry_t) { (intpte_t)(intpte) })
Quoted 12 lines
xen/include/asm-x86/page.h static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) · line 151
Quoted 9 lines
xen/include/asm-x86/page.h +4
-4/* Construct a pte from a page pointer and access flags. */ -#define l1e_from_page (page, flags) (l1e_from_pfn(page_to_mfn(page),(flags))) -#define l2e_from_page (page, flags) (l2e_from_pfn(page_to_mfn(page),(flags))) -#define l3e_from_page (page, flags) (l3e_from_pfn(page_to_mfn(page),(flags))) -#define l4e_from_page (page, flags) (l4e_from_pfn(page_to_mfn(page),(flags))) +#define l1e_from_page (page, flags) (l1e_from_pfn(__page_to_mfn(page), (flags))) +#define l2e_from_page (page, flags) (l2e_from_pfn(__page_to_mfn(page), (flags))) +#define l3e_from_page (page, flags) (l3e_from_pfn(__page_to_mfn(page), (flags))) +#define l4e_from_page (page, flags) (l4e_from_pfn(__page_to_mfn(page), (flags)))Mind at once stripping the pointless outer parentheses from all the macros you modify, and the ones around flags in the latter set?
Will do.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel