ia64/linux-2.6.18-xen.hg

changeset 554:12e74c1433a6

linux/x86-64: initialization code cleanup

Since init_memory_mapping() installs the pgd entry after populating
all lower level tables, the whole mechanism can be coded to avoid
using xen_l?_entry_update() on pages that aren't page tables
(yet). Also, __set_pte() is a pure duplicate of set_pte() and hence
can go away.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu May 15 15:15:09 2008 +0100 (2008-05-15)
parents c6e36a53cf05
children 8ce60d057d0c
files arch/x86_64/mm/init-xen.c
line diff
     1.1 --- a/arch/x86_64/mm/init-xen.c	Thu May 15 15:14:31 2008 +0100
     1.2 +++ b/arch/x86_64/mm/init-xen.c	Thu May 15 15:15:09 2008 +0100
     1.3 @@ -59,6 +59,8 @@ unsigned int __kernel_page_user;
     1.4  EXPORT_SYMBOL(__kernel_page_user);
     1.5  #endif
     1.6  
     1.7 +int after_bootmem;
     1.8 +
     1.9  extern unsigned long *contiguous_bitmap;
    1.10  
    1.11  static unsigned long dma_reserve __initdata;
    1.12 @@ -83,6 +85,8 @@ static void __meminit early_make_page_re
    1.13  	pte_t pte, *ptep;
    1.14  	unsigned long *page = (unsigned long *) init_level4_pgt;
    1.15  
    1.16 +	BUG_ON(after_bootmem);
    1.17 +
    1.18  	if (xen_feature(feature))
    1.19  		return;
    1.20  
    1.21 @@ -207,7 +211,6 @@ void show_mem(void)
    1.22  	printk(KERN_INFO "%lu pages swap cached\n",cached);
    1.23  }
    1.24  
    1.25 -int after_bootmem;
    1.26  
    1.27  static __init void *spp_getpage(void)
    1.28  { 
    1.29 @@ -373,11 +376,6 @@ static __meminit void *alloc_static_page
    1.30  
    1.31  #define PTE_SIZE PAGE_SIZE
    1.32  
    1.33 -static inline void __set_pte(pte_t *dst, pte_t val)
    1.34 -{
    1.35 -	*dst = val;
    1.36 -}
    1.37 -
    1.38  static inline int make_readonly(unsigned long paddr)
    1.39  {
    1.40  	extern char __vsyscall_0;
    1.41 @@ -446,28 +444,28 @@ phys_pmd_init(pmd_t *pmd, unsigned long 
    1.42  		unsigned long pte_phys;
    1.43  		pte_t *pte, *pte_save;
    1.44  
    1.45 -		if (address >= end) {
    1.46 -			if (!after_bootmem)
    1.47 -				for (; i < PTRS_PER_PMD; i++, pmd++)
    1.48 -					set_pmd(pmd, __pmd(0));
    1.49 +		if (address >= end)
    1.50  			break;
    1.51 -		}
    1.52  		pte = alloc_static_page(&pte_phys);
    1.53  		pte_save = pte;
    1.54  		for (k = 0; k < PTRS_PER_PTE; pte++, k++, address += PTE_SIZE) {
    1.55  			unsigned long pteval = address | _PAGE_NX | _KERNPG_TABLE;
    1.56  
    1.57 -			if ((address >= end) ||
    1.58 -			    ((address >> PAGE_SHIFT) >=
    1.59 -			     xen_start_info->nr_pages))
    1.60 +			if (address >= (after_bootmem
    1.61 +			                ? end
    1.62 +			                : xen_start_info->nr_pages << PAGE_SHIFT))
    1.63  				pteval = 0;
    1.64  			else if (make_readonly(address))
    1.65  				pteval &= ~_PAGE_RW;
    1.66 -			__set_pte(pte, __pte(pteval & __supported_pte_mask));
    1.67 +			set_pte(pte, __pte(pteval & __supported_pte_mask));
    1.68  		}
    1.69 -		pte = pte_save;
    1.70 -		early_make_page_readonly(pte, XENFEAT_writable_page_tables);
    1.71 -		set_pmd(pmd, __pmd(pte_phys | _KERNPG_TABLE));
    1.72 +		if (!after_bootmem) {
    1.73 +			early_make_page_readonly(pte_save, XENFEAT_writable_page_tables);
    1.74 +			*pmd = __pmd(pte_phys | _KERNPG_TABLE);
    1.75 +		} else {
    1.76 +			make_page_readonly(pte_save, XENFEAT_writable_page_tables);
    1.77 +			set_pmd(pmd, __pmd(pte_phys | _KERNPG_TABLE));
    1.78 +		}
    1.79  	}
    1.80  }
    1.81  
    1.82 @@ -504,11 +502,13 @@ static void __meminit phys_pud_init(pud_
    1.83  			break;
    1.84  
    1.85  		pmd = alloc_static_page(&pmd_phys);
    1.86 -		early_make_page_readonly(pmd, XENFEAT_writable_page_tables);
    1.87 +
    1.88  		spin_lock(&init_mm.page_table_lock);
    1.89 -		set_pud(pud, __pud(pmd_phys | _KERNPG_TABLE));
    1.90 +		*pud = __pud(pmd_phys | _KERNPG_TABLE);
    1.91  		phys_pmd_init(pmd, paddr, end);
    1.92  		spin_unlock(&init_mm.page_table_lock);
    1.93 +
    1.94 +		early_make_page_readonly(pmd, XENFEAT_writable_page_tables);
    1.95  	}
    1.96  	__flush_tlb();
    1.97  } 
    1.98 @@ -739,20 +739,18 @@ void __meminit init_memory_mapping(unsig
    1.99  		pgd_t *pgd = pgd_offset_k(start);
   1.100  		pud_t *pud;
   1.101  
   1.102 -		if (after_bootmem) {
   1.103 +		if (after_bootmem)
   1.104  			pud = pud_offset(pgd, start & PGDIR_MASK);
   1.105 -			make_page_readonly(pud, XENFEAT_writable_page_tables);
   1.106 -			pud_phys = __pa(pud);
   1.107 -		} else {
   1.108 +		else
   1.109  			pud = alloc_static_page(&pud_phys);
   1.110 -			early_make_page_readonly(pud, XENFEAT_writable_page_tables);
   1.111 -		}
   1.112  		next = start + PGDIR_SIZE;
   1.113  		if (next > end) 
   1.114  			next = end; 
   1.115  		phys_pud_init(pud, __pa(start), __pa(next));
   1.116 -		if (!after_bootmem)
   1.117 +		if (!after_bootmem) {
   1.118 +			early_make_page_readonly(pud, XENFEAT_writable_page_tables);
   1.119  			set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys));
   1.120 +		}
   1.121  	}
   1.122  
   1.123  	if (!after_bootmem) {