ia64/xen-unstable

changeset 14251:1359e04a8fb3

linux/x86-64: allow kernel init memory to be freed.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kfraser@localhost.localdomain
date Mon Mar 05 13:27:51 2007 +0000 (2007-03-05)
parents 43b0be37736b
children c371b6b26753
files linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c	Mon Mar 05 13:18:28 2007 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c	Mon Mar 05 13:27:51 2007 +0000
     1.3 @@ -102,14 +102,11 @@ static void __meminit early_make_page_re
     1.4  		BUG();
     1.5  }
     1.6  
     1.7 -void make_page_readonly(void *va, unsigned int feature)
     1.8 +static void __make_page_readonly(void *va)
     1.9  {
    1.10  	pgd_t *pgd; pud_t *pud; pmd_t *pmd; pte_t pte, *ptep;
    1.11  	unsigned long addr = (unsigned long) va;
    1.12  
    1.13 -	if (xen_feature(feature))
    1.14 -		return;
    1.15 -
    1.16  	pgd = pgd_offset_k(addr);
    1.17  	pud = pud_offset(pgd, addr);
    1.18  	pmd = pmd_offset(pud, addr);
    1.19 @@ -120,17 +117,14 @@ void make_page_readonly(void *va, unsign
    1.20  		xen_l1_entry_update(ptep, pte); /* fallback */
    1.21  
    1.22  	if ((addr >= VMALLOC_START) && (addr < VMALLOC_END))
    1.23 -		make_page_readonly(__va(pte_pfn(pte) << PAGE_SHIFT), feature);
    1.24 +		__make_page_readonly(__va(pte_pfn(pte) << PAGE_SHIFT));
    1.25  }
    1.26  
    1.27 -void make_page_writable(void *va, unsigned int feature)
    1.28 +static void __make_page_writable(void *va)
    1.29  {
    1.30  	pgd_t *pgd; pud_t *pud; pmd_t *pmd; pte_t pte, *ptep;
    1.31  	unsigned long addr = (unsigned long) va;
    1.32  
    1.33 -	if (xen_feature(feature))
    1.34 -		return;
    1.35 -
    1.36  	pgd = pgd_offset_k(addr);
    1.37  	pud = pud_offset(pgd, addr);
    1.38  	pmd = pmd_offset(pud, addr);
    1.39 @@ -141,7 +135,19 @@ void make_page_writable(void *va, unsign
    1.40  		xen_l1_entry_update(ptep, pte); /* fallback */
    1.41  
    1.42  	if ((addr >= VMALLOC_START) && (addr < VMALLOC_END))
    1.43 -		make_page_writable(__va(pte_pfn(pte) << PAGE_SHIFT), feature);
    1.44 +		__make_page_writable(__va(pte_pfn(pte) << PAGE_SHIFT));
    1.45 +}
    1.46 +
    1.47 +void make_page_readonly(void *va, unsigned int feature)
    1.48 +{
    1.49 +	if (!xen_feature(feature))
    1.50 +		__make_page_readonly(va);
    1.51 +}
    1.52 +
    1.53 +void make_page_writable(void *va, unsigned int feature)
    1.54 +{
    1.55 +	if (!xen_feature(feature))
    1.56 +		__make_page_writable(va);
    1.57  }
    1.58  
    1.59  void make_pages_readonly(void *va, unsigned nr, unsigned int feature)
    1.60 @@ -150,7 +156,7 @@ void make_pages_readonly(void *va, unsig
    1.61  		return;
    1.62  
    1.63  	while (nr-- != 0) {
    1.64 -		make_page_readonly(va, feature);
    1.65 +		__make_page_readonly(va);
    1.66  		va = (void*)((unsigned long)va + PAGE_SIZE);
    1.67  	}
    1.68  }
    1.69 @@ -161,7 +167,7 @@ void make_pages_writable(void *va, unsig
    1.70  		return;
    1.71  
    1.72  	while (nr-- != 0) {
    1.73 -		make_page_writable(va, feature);
    1.74 +		__make_page_writable(va);
    1.75  		va = (void*)((unsigned long)va + PAGE_SIZE);
    1.76  	}
    1.77  }
    1.78 @@ -1028,11 +1034,6 @@ void __init mem_init(void)
    1.79  
    1.80  void free_init_pages(char *what, unsigned long begin, unsigned long end)
    1.81  {
    1.82 -#ifdef __DO_LATER__
    1.83 -	/*
    1.84 -	 * Some pages can be pinned, but some are not. Unpinning such pages 
    1.85 -	 * triggers BUG(). 
    1.86 -	 */
    1.87  	unsigned long addr;
    1.88  
    1.89  	if (begin >= end)
    1.90 @@ -1044,25 +1045,27 @@ void free_init_pages(char *what, unsigne
    1.91  		init_page_count(virt_to_page(addr));
    1.92  		memset((void *)(addr & ~(PAGE_SIZE-1)),
    1.93  		       POISON_FREE_INITMEM, PAGE_SIZE); 
    1.94 -		make_page_writable(
    1.95 -			__va(__pa(addr)), XENFEAT_writable_page_tables);
    1.96 -		/*
    1.97 -		 * Make pages from __PAGE_OFFSET address as well
    1.98 -		 */
    1.99 -		make_page_writable(
   1.100 -			(void *)addr, XENFEAT_writable_page_tables);
   1.101 +		if (addr >= __START_KERNEL_map) {
   1.102 +			/* make_readonly() reports all kernel addresses. */
   1.103 +			__make_page_writable(__va(__pa(addr)));
   1.104 +			if (HYPERVISOR_update_va_mapping(addr, __pte(0), 0)) {
   1.105 +				pgd_t *pgd = pgd_offset_k(addr);
   1.106 +				pud_t *pud = pud_offset(pgd, addr);
   1.107 +				pmd_t *pmd = pmd_offset(pud, addr);
   1.108 +				pte_t *pte = pte_offset_kernel(pmd, addr);
   1.109 +
   1.110 +				xen_l1_entry_update(pte, __pte(0)); /* fallback */
   1.111 +			}
   1.112 +		}
   1.113  		free_page(addr);
   1.114  		totalram_pages++;
   1.115  	}
   1.116 -#endif
   1.117  }
   1.118  
   1.119  void free_initmem(void)
   1.120  {
   1.121 -#ifdef __DO_LATER__
   1.122  	memset(__initdata_begin, POISON_FREE_INITDATA,
   1.123  		__initdata_end - __initdata_begin);
   1.124 -#endif
   1.125  	free_init_pages("unused kernel memory",
   1.126  			(unsigned long)(&__init_begin),
   1.127  			(unsigned long)(&__init_end));