ia64/xen-unstable

changeset 14144:9e5e94942045

x86: Clean up {alloc,free}_xen_pagetable() interface to avoid use of
frame_table variable before initialisation. This wasn't a bug, but was
confusing.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Mon Feb 26 16:25:17 2007 +0000 (2007-02-26)
parents 45ddffd595a1
children 0070b18869f7
files xen/arch/x86/mm.c xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_64/mm.c xen/include/asm-x86/page.h
line diff
     1.1 --- a/xen/arch/x86/mm.c	Mon Feb 26 15:50:50 2007 +0000
     1.2 +++ b/xen/arch/x86/mm.c	Mon Feb 26 16:25:17 2007 +0000
     1.3 @@ -3401,7 +3401,7 @@ int map_pages_to_xen(
     1.4              {
     1.5                  local_flush_tlb_pge();
     1.6                  if ( !(l2e_get_flags(ol2e) & _PAGE_PSE) )
     1.7 -                    free_xen_pagetable(l2e_get_page(ol2e));
     1.8 +                    free_xen_pagetable(page_to_virt(l2e_get_page(ol2e)));
     1.9              }
    1.10  
    1.11              virt    += 1UL << L2_PAGETABLE_SHIFT;
    1.12 @@ -3413,14 +3413,14 @@ int map_pages_to_xen(
    1.13              /* Normal page mapping. */
    1.14              if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) )
    1.15              {
    1.16 -                pl1e = page_to_virt(alloc_xen_pagetable());
    1.17 +                pl1e = alloc_xen_pagetable();
    1.18                  clear_page(pl1e);
    1.19                  l2e_write(pl2e, l2e_from_page(virt_to_page(pl1e),
    1.20                                                __PAGE_HYPERVISOR));
    1.21              }
    1.22              else if ( l2e_get_flags(*pl2e) & _PAGE_PSE )
    1.23              {
    1.24 -                pl1e = page_to_virt(alloc_xen_pagetable());
    1.25 +                pl1e = alloc_xen_pagetable();
    1.26                  for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
    1.27                      l1e_write(&pl1e[i],
    1.28                                l1e_from_pfn(l2e_get_pfn(*pl2e) + i,
     2.1 --- a/xen/arch/x86/x86_32/mm.c	Mon Feb 26 15:50:50 2007 +0000
     2.2 +++ b/xen/arch/x86/x86_32/mm.c	Mon Feb 26 16:25:17 2007 +0000
     2.3 @@ -35,26 +35,27 @@ unsigned int PAGE_HYPERVISOR_NOCACHE = _
     2.4  
     2.5  static unsigned long mpt_size;
     2.6  
     2.7 -struct page_info *alloc_xen_pagetable(void)
     2.8 +void *alloc_xen_pagetable(void)
     2.9  {
    2.10      extern int early_boot;
    2.11      extern unsigned long xenheap_phys_start;
    2.12 -    struct page_info *pg;
    2.13 +    unsigned long mfn;
    2.14  
    2.15      if ( !early_boot )
    2.16      {
    2.17          void *v = alloc_xenheap_page();
    2.18 -        return ((v == NULL) ? NULL : virt_to_page(v));
    2.19 +        BUG_ON(v == NULL);
    2.20 +        return v;
    2.21      }
    2.22  
    2.23 -    pg = maddr_to_page(xenheap_phys_start);
    2.24 +    mfn = xenheap_phys_start >> PAGE_SHIFT;
    2.25      xenheap_phys_start += PAGE_SIZE;
    2.26 -    return pg;
    2.27 +    return mfn_to_virt(mfn);
    2.28  }
    2.29  
    2.30 -void free_xen_pagetable(struct page_info *pg)
    2.31 +void free_xen_pagetable(void *v)
    2.32  {
    2.33 -    free_xenheap_page(page_to_virt(pg));
    2.34 +    free_xenheap_page(v);
    2.35  }
    2.36  
    2.37  l2_pgentry_t *virt_to_xen_l2e(unsigned long v)
     3.1 --- a/xen/arch/x86/x86_64/mm.c	Mon Feb 26 15:50:50 2007 +0000
     3.2 +++ b/xen/arch/x86/x86_64/mm.c	Mon Feb 26 16:25:17 2007 +0000
     3.3 @@ -36,22 +36,27 @@
     3.4  unsigned int m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START;
     3.5  #endif
     3.6  
     3.7 -struct page_info *alloc_xen_pagetable(void)
     3.8 +void *alloc_xen_pagetable(void)
     3.9  {
    3.10      extern int early_boot;
    3.11 -    unsigned long pfn;
    3.12 +    unsigned long mfn;
    3.13  
    3.14      if ( !early_boot )
    3.15 -        return alloc_domheap_page(NULL);
    3.16 +    {
    3.17 +        struct page_info *pg = alloc_domheap_page(NULL);
    3.18 +        BUG_ON(pg == NULL);
    3.19 +        return page_to_virt(pg);
    3.20 +    }
    3.21  
    3.22      /* Early pagetables must come from low 1GB of memory. */
    3.23 -    pfn = alloc_boot_low_pages(1, 1); /* 0x0 - 0x40000000 */
    3.24 -    return ((pfn == 0) ? NULL : mfn_to_page(pfn));
    3.25 +    mfn = alloc_boot_low_pages(1, 1); /* 0x0 - 0x40000000 */
    3.26 +    BUG_ON(mfn == 0);
    3.27 +    return mfn_to_virt(mfn);
    3.28  }
    3.29  
    3.30 -void free_xen_pagetable(struct page_info *pg)
    3.31 +void free_xen_pagetable(void *v)
    3.32  {
    3.33 -    free_domheap_page(pg);
    3.34 +    free_domheap_page(virt_to_page(v));
    3.35  }
    3.36  
    3.37  l2_pgentry_t *virt_to_xen_l2e(unsigned long v)
    3.38 @@ -63,7 +68,7 @@ l2_pgentry_t *virt_to_xen_l2e(unsigned l
    3.39      pl4e = &idle_pg_table[l4_table_offset(v)];
    3.40      if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
    3.41      {
    3.42 -        pl3e = page_to_virt(alloc_xen_pagetable());
    3.43 +        pl3e = alloc_xen_pagetable();
    3.44          clear_page(pl3e);
    3.45          l4e_write(pl4e, l4e_from_paddr(__pa(pl3e), __PAGE_HYPERVISOR));
    3.46      }
    3.47 @@ -71,7 +76,7 @@ l2_pgentry_t *virt_to_xen_l2e(unsigned l
    3.48      pl3e = l4e_to_l3e(*pl4e) + l3_table_offset(v);
    3.49      if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) )
    3.50      {
    3.51 -        pl2e = page_to_virt(alloc_xen_pagetable());
    3.52 +        pl2e = alloc_xen_pagetable();
    3.53          clear_page(pl2e);
    3.54          l3e_write(pl3e, l3e_from_paddr(__pa(pl2e), __PAGE_HYPERVISOR));
    3.55      }
     4.1 --- a/xen/include/asm-x86/page.h	Mon Feb 26 15:50:50 2007 +0000
     4.2 +++ b/xen/include/asm-x86/page.h	Mon Feb 26 16:25:17 2007 +0000
     4.3 @@ -363,8 +363,8 @@ static inline int get_order_from_pages(u
     4.4  }
     4.5  
     4.6  /* Allocator functions for Xen pagetables. */
     4.7 -struct page_info *alloc_xen_pagetable(void);
     4.8 -void free_xen_pagetable(struct page_info *pg);
     4.9 +void *alloc_xen_pagetable(void);
    4.10 +void free_xen_pagetable(void *v);
    4.11  l2_pgentry_t *virt_to_xen_l2e(unsigned long v);
    4.12  
    4.13  /* Map machine page range in Xen virtual address space. */