ia64/linux-2.6.18-xen.hg

annotate mm/mincore.c @ 452:c7ed6fe5dca0

kexec: dont initialise regions in reserve_memory()

There is no need to initialise efi_memmap_res and boot_param_res in
reserve_memory() for the initial xen domain as it is done in
machine_kexec_setup_resources() using values from the kexec hypercall.

Signed-off-by: Simon Horman <horms@verge.net.au>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 28 10:55:18 2008 +0000 (2008-02-28)
parents 3e8752eb6d9c
children
rev   line source
ian@0 1 /*
ian@0 2 * linux/mm/mincore.c
ian@0 3 *
ian@240 4 * Copyright (C) 1994-2006 Linus Torvalds
ian@0 5 */
ian@0 6
ian@0 7 /*
ian@0 8 * The mincore() system call.
ian@0 9 */
ian@0 10 #include <linux/slab.h>
ian@0 11 #include <linux/pagemap.h>
ian@0 12 #include <linux/mm.h>
ian@0 13 #include <linux/mman.h>
ian@0 14 #include <linux/syscalls.h>
ian@0 15
ian@0 16 #include <asm/uaccess.h>
ian@0 17 #include <asm/pgtable.h>
ian@0 18
ian@0 19 /*
ian@0 20 * Later we can get more picky about what "in core" means precisely.
ian@0 21 * For now, simply check to see if the page is in the page cache,
ian@0 22 * and is up to date; i.e. that no page-in operation would be required
ian@0 23 * at this time if an application were to map and access this page.
ian@0 24 */
ian@0 25 static unsigned char mincore_page(struct vm_area_struct * vma,
ian@0 26 unsigned long pgoff)
ian@0 27 {
ian@0 28 unsigned char present = 0;
ian@0 29 struct address_space * as = vma->vm_file->f_mapping;
ian@0 30 struct page * page;
ian@0 31
ian@0 32 page = find_get_page(as, pgoff);
ian@0 33 if (page) {
ian@0 34 present = PageUptodate(page);
ian@0 35 page_cache_release(page);
ian@0 36 }
ian@0 37
ian@0 38 return present;
ian@0 39 }
ian@0 40
ian@240 41 /*
ian@240 42 * Do a chunk of "sys_mincore()". We've already checked
ian@240 43 * all the arguments, we hold the mmap semaphore: we should
ian@240 44 * just return the amount of info we're asked for.
ian@240 45 */
ian@240 46 static long do_mincore(unsigned long addr, unsigned char *vec, unsigned long pages)
ian@0 47 {
ian@240 48 unsigned long i, nr, pgoff;
ian@240 49 struct vm_area_struct *vma = find_vma(current->mm, addr);
ian@0 50
ian@240 51 /*
ian@240 52 * find_vma() didn't find anything above us, or we're
ian@240 53 * in an unmapped hole in the address space: ENOMEM.
ian@240 54 */
ian@240 55 if (!vma || addr < vma->vm_start)
ian@240 56 return -ENOMEM;
ian@0 57
ian@240 58 /*
ian@240 59 * Ok, got it. But check whether it's a segment we support
ian@240 60 * mincore() on. Right now, we don't do any anonymous mappings.
ian@240 61 *
ian@240 62 * FIXME: This is just stupid. And returning ENOMEM is
ian@240 63 * stupid too. We should just look at the page tables. But
ian@240 64 * this is what we've traditionally done, so we'll just
ian@240 65 * continue doing it.
ian@240 66 */
ian@240 67 if (!vma->vm_file)
ian@240 68 return -ENOMEM;
ian@0 69
ian@240 70 /*
ian@240 71 * Calculate how many pages there are left in the vma, and
ian@240 72 * what the pgoff is for our address.
ian@240 73 */
ian@240 74 nr = (vma->vm_end - addr) >> PAGE_SHIFT;
ian@240 75 if (nr > pages)
ian@240 76 nr = pages;
ian@0 77
ian@240 78 pgoff = (addr - vma->vm_start) >> PAGE_SHIFT;
ian@240 79 pgoff += vma->vm_pgoff;
ian@0 80
ian@240 81 /* And then we just fill the sucker in.. */
ian@240 82 for (i = 0 ; i < nr; i++, pgoff++)
ian@240 83 vec[i] = mincore_page(vma, pgoff);
ian@240 84
ian@240 85 return nr;
ian@0 86 }
ian@0 87
ian@0 88 /*
ian@0 89 * The mincore(2) system call.
ian@0 90 *
ian@0 91 * mincore() returns the memory residency status of the pages in the
ian@0 92 * current process's address space specified by [addr, addr + len).
ian@0 93 * The status is returned in a vector of bytes. The least significant
ian@0 94 * bit of each byte is 1 if the referenced page is in memory, otherwise
ian@0 95 * it is zero.
ian@0 96 *
ian@0 97 * Because the status of a page can change after mincore() checks it
ian@0 98 * but before it returns to the application, the returned vector may
ian@0 99 * contain stale information. Only locked pages are guaranteed to
ian@0 100 * remain in memory.
ian@0 101 *
ian@0 102 * return values:
ian@0 103 * zero - success
ian@0 104 * -EFAULT - vec points to an illegal address
ian@0 105 * -EINVAL - addr is not a multiple of PAGE_CACHE_SIZE
ian@0 106 * -ENOMEM - Addresses in the range [addr, addr + len] are
ian@0 107 * invalid for the address space of this process, or
ian@0 108 * specify one or more pages which are not currently
ian@0 109 * mapped
ian@0 110 * -EAGAIN - A kernel resource was temporarily unavailable.
ian@0 111 */
ian@0 112 asmlinkage long sys_mincore(unsigned long start, size_t len,
ian@0 113 unsigned char __user * vec)
ian@0 114 {
ian@240 115 long retval;
ian@240 116 unsigned long pages;
ian@240 117 unsigned char *tmp;
ian@0 118
ian@240 119 /* Check the start address: needs to be page-aligned.. */
ian@0 120 if (start & ~PAGE_CACHE_MASK)
ian@240 121 return -EINVAL;
ian@0 122
ian@240 123 /* ..and we need to be passed a valid user-space range */
ian@240 124 if (!access_ok(VERIFY_READ, (void __user *) start, len))
ian@240 125 return -ENOMEM;
ian@0 126
ian@240 127 /* This also avoids any overflows on PAGE_CACHE_ALIGN */
ian@240 128 pages = len >> PAGE_SHIFT;
ian@240 129 pages += (len & ~PAGE_MASK) != 0;
ian@0 130
ian@240 131 if (!access_ok(VERIFY_WRITE, vec, pages))
ian@240 132 return -EFAULT;
ian@0 133
ian@240 134 tmp = (void *) __get_free_page(GFP_USER);
ian@240 135 if (!tmp)
ian@240 136 return -EAGAIN;
ian@0 137
ian@240 138 retval = 0;
ian@240 139 while (pages) {
ian@240 140 /*
ian@240 141 * Do at most PAGE_SIZE entries per iteration, due to
ian@240 142 * the temporary buffer size.
ian@240 143 */
ian@240 144 down_read(&current->mm->mmap_sem);
ian@240 145 retval = do_mincore(start, tmp, min(pages, PAGE_SIZE));
ian@240 146 up_read(&current->mm->mmap_sem);
ian@0 147
ian@240 148 if (retval <= 0)
ian@240 149 break;
ian@240 150 if (copy_to_user(vec, tmp, retval)) {
ian@240 151 retval = -EFAULT;
ian@240 152 break;
ian@240 153 }
ian@240 154 pages -= retval;
ian@240 155 vec += retval;
ian@240 156 start += retval << PAGE_SHIFT;
ian@240 157 retval = 0;
ian@0 158 }
ian@240 159 free_page((unsigned long) tmp);
ian@240 160 return retval;
ian@0 161 }