4 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
8 * demand-loading started 01.12.91 - seems it is high on the list of
9 * things wanted, and it should be easy to implement. - Linus
13 * Ok, demand-loading was easy, shared pages a little bit tricker. Shared
14 * pages started 02.12.91, seems to work. - Linus.
16 * Tested sharing by executing about 30 /bin/sh: under the old kernel it
17 * would have taken more than the 6M I have free, but it worked well as
20 * Also corrected some "invalidate()"s - I wasn't doing enough of them.
24 * Real VM (paging to/from disk) started 18.12.91. Much more work and
25 * thought has to go into this. Oh, well..
26 * 19.12.91 - works, somewhat. Sometimes I get faults, don't know why.
27 * Found it. Everything seems to work now.
28 * 20.12.91 - Ok, making the swap-device changeable like the root.
32 * 05.04.94 - Multi-page memory management added for v1.1.
33 * Idea by Alex Bligh (alex@cconcepts.co.uk)
35 * 16.07.99 - Support of BIGMEM added by Gerhard Wichert, Siemens AG
36 * (Gerhard.Wichert@pdb.siemens.de)
39 #include <linux/kernel_stat.h>
41 #include <linux/hugetlb.h>
42 #include <linux/mman.h>
43 #include <linux/swap.h>
44 #include <linux/highmem.h>
45 #include <linux/pagemap.h>
46 #include <linux/rmap.h>
47 #include <linux/module.h>
48 #include <linux/init.h>
50 #include <asm/pgalloc.h>
51 #include <asm/uaccess.h>
53 #include <asm/tlbflush.h>
54 #include <asm/pgtable.h>
56 #include <linux/swapops.h>
57 #include <linux/elf.h>
59 #ifndef CONFIG_DISCONTIGMEM
60 /* use the per-pgdat data instead for discontigmem - mbligh */
61 unsigned long max_mapnr;
64 EXPORT_SYMBOL(max_mapnr);
65 EXPORT_SYMBOL(mem_map);
68 unsigned long num_physpages;
70 struct page *highmem_start_page;
72 EXPORT_SYMBOL(num_physpages);
73 EXPORT_SYMBOL(highmem_start_page);
74 EXPORT_SYMBOL(high_memory);
77 * We special-case the C-O-W ZERO_PAGE, because it's such
78 * a common occurrence (no need to read the page to know
79 * that it's zero - better for the cache and memory subsystem).
81 static inline void copy_cow_page(struct page * from, struct page * to, unsigned long address)
83 if (from == ZERO_PAGE(address)) {
84 clear_user_highpage(to, address);
87 copy_user_highpage(to, from, address);
91 * Note: this doesn't free the actual pages themselves. That
92 * has been handled earlier when unmapping all the memory regions.
94 static inline void free_one_pmd(struct mmu_gather *tlb, pmd_t * dir)
100 if (unlikely(pmd_bad(*dir))) {
105 page = pmd_page(*dir);
107 dec_page_state(nr_page_table_pages);
108 pte_free_tlb(tlb, page);
111 static inline void free_one_pgd(struct mmu_gather *tlb, pgd_t * dir,
119 if (unlikely(pgd_bad(*dir))) {
124 pmd = pmd_offset(dir, 0);
126 for (j = 0; j < PTRS_PER_PMD ; j++) {
127 if (pgd_idx * PGDIR_SIZE + j * PMD_SIZE >= TASK_SIZE)
129 free_one_pmd(tlb, pmd+j);
131 pmd_free_tlb(tlb, pmd);
135 * This function clears all user-level page tables of a process - this
136 * is needed by execve(), so that old pages aren't in the way.
138 * Must be called with pagetable lock held.
140 void clear_page_tables(struct mmu_gather *tlb, unsigned long first, int nr)
142 pgd_t * page_dir = tlb->mm->pgd;
147 free_one_pgd(tlb, page_dir, pgd_idx);
153 pte_t fastcall * pte_alloc_map(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
155 if (!pmd_present(*pmd)) {
158 spin_unlock(&mm->page_table_lock);
159 new = pte_alloc_one(mm, address);
160 spin_lock(&mm->page_table_lock);
165 * Because we dropped the lock, we should re-check the
166 * entry, as somebody else could have populated it..
168 if (pmd_present(*pmd)) {
172 inc_page_state(nr_page_table_pages);
173 pmd_populate(mm, pmd, new);
176 return pte_offset_map(pmd, address);
179 pte_t fastcall * pte_alloc_kernel(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
181 if (!pmd_present(*pmd)) {
184 spin_unlock(&mm->page_table_lock);
185 new = pte_alloc_one_kernel(mm, address);
186 spin_lock(&mm->page_table_lock);
191 * Because we dropped the lock, we should re-check the
192 * entry, as somebody else could have populated it..
194 if (pmd_present(*pmd)) {
195 pte_free_kernel(new);
198 pmd_populate_kernel(mm, pmd, new);
201 return pte_offset_kernel(pmd, address);
203 #define PTE_TABLE_MASK ((PTRS_PER_PTE-1) * sizeof(pte_t))
204 #define PMD_TABLE_MASK ((PTRS_PER_PMD-1) * sizeof(pmd_t))
207 * copy one vm_area from one task to the other. Assumes the page tables
208 * already present in the new task to be cleared in the whole range
209 * covered by this vma.
211 * 08Jan98 Merged into one routine from several inline routines to reduce
212 * variable count and make things faster. -jj
214 * dst->page_table_lock is held on entry and exit,
215 * but may be dropped within pmd_alloc() and pte_alloc_map().
217 int copy_page_range(struct mm_struct *dst, struct mm_struct *src,
218 struct vm_area_struct *vma)
220 pgd_t * src_pgd, * dst_pgd;
221 unsigned long address = vma->vm_start;
222 unsigned long end = vma->vm_end;
225 if (is_vm_hugetlb_page(vma))
226 return copy_hugetlb_page_range(dst, src, vma);
228 cow = (vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
229 src_pgd = pgd_offset(src, address)-1;
230 dst_pgd = pgd_offset(dst, address)-1;
233 pmd_t * src_pmd, * dst_pmd;
235 src_pgd++; dst_pgd++;
239 if (pgd_none(*src_pgd))
240 goto skip_copy_pmd_range;
241 if (unlikely(pgd_bad(*src_pgd))) {
244 skip_copy_pmd_range: address = (address + PGDIR_SIZE) & PGDIR_MASK;
245 if (!address || (address >= end))
250 src_pmd = pmd_offset(src_pgd, address);
251 dst_pmd = pmd_alloc(dst, dst_pgd, address);
256 pte_t * src_pte, * dst_pte;
260 if (pmd_none(*src_pmd))
261 goto skip_copy_pte_range;
262 if (unlikely(pmd_bad(*src_pmd))) {
266 address = (address + PMD_SIZE) & PMD_MASK;
269 goto cont_copy_pmd_range;
272 dst_pte = pte_alloc_map(dst, dst_pmd, address);
275 spin_lock(&src->page_table_lock);
276 src_pte = pte_offset_map_nested(src_pmd, address);
278 pte_t pte = *src_pte;
285 goto cont_copy_pte_range_noset;
286 /* pte contains position in swap, so copy. */
287 if (!pte_present(pte)) {
289 swap_duplicate(pte_to_swp_entry(pte));
290 set_pte(dst_pte, pte);
291 goto cont_copy_pte_range_noset;
294 /* the pte points outside of valid memory, the
295 * mapping is assumed to be good, meaningful
296 * and not mapped via rmap - duplicate the
301 page = pfn_to_page(pfn);
303 if (!page || PageReserved(page)) {
304 set_pte(dst_pte, pte);
305 goto cont_copy_pte_range_noset;
309 * If it's a COW mapping, write protect it both
310 * in the parent and the child
313 ptep_set_wrprotect(src_pte);
318 * If it's a shared mapping, mark it clean in
321 if (vma->vm_flags & VM_SHARED)
322 pte = pte_mkclean(pte);
323 pte = pte_mkold(pte);
326 set_pte(dst_pte, pte);
328 cont_copy_pte_range_noset:
329 address += PAGE_SIZE;
330 if (address >= end) {
331 pte_unmap_nested(src_pte);
337 } while ((unsigned long)src_pte & PTE_TABLE_MASK);
338 pte_unmap_nested(src_pte-1);
339 pte_unmap(dst_pte-1);
340 spin_unlock(&src->page_table_lock);
341 cond_resched_lock(&dst->page_table_lock);
345 } while ((unsigned long)src_pmd & PMD_TABLE_MASK);
348 spin_unlock(&src->page_table_lock);
355 static void zap_pte_range(struct mmu_gather *tlb,
356 pmd_t *pmd, unsigned long address,
357 unsigned long size, struct zap_details *details)
359 unsigned long offset;
364 if (unlikely(pmd_bad(*pmd))) {
369 ptep = pte_offset_map(pmd, address);
370 offset = address & ~PMD_MASK;
371 if (offset + size > PMD_SIZE)
372 size = PMD_SIZE - offset;
374 if (details && !details->check_mapping && !details->nonlinear_vma)
376 for (offset=0; offset < size; ptep++, offset += PAGE_SIZE) {
380 if (pte_present(pte)) {
381 struct page *page = NULL;
382 unsigned long pfn = pte_pfn(pte);
383 if (pfn_valid(pfn)) {
384 page = pfn_to_page(pfn);
385 if (PageReserved(page))
388 if (unlikely(details) && page) {
390 * unmap_shared_mapping_pages() wants to
391 * invalidate cache without truncating:
392 * unmap shared but keep private pages.
394 if (details->check_mapping &&
395 details->check_mapping != page->mapping)
398 * Each page->index must be checked when
399 * invalidating or truncating nonlinear.
401 if (details->nonlinear_vma &&
402 (page->index < details->first_index ||
403 page->index > details->last_index))
406 pte = ptep_get_and_clear(ptep);
407 tlb_remove_tlb_entry(tlb, ptep, address+offset);
410 if (unlikely(details) && details->nonlinear_vma
411 && linear_page_index(details->nonlinear_vma,
412 address+offset) != page->index)
413 set_pte(ptep, pgoff_to_pte(page->index));
415 set_page_dirty(page);
416 if (pte_young(pte) && page_mapping(page))
417 mark_page_accessed(page);
419 page_remove_rmap(page);
420 tlb_remove_page(tlb, page);
424 * If details->check_mapping, we leave swap entries;
425 * if details->nonlinear_vma, we leave file entries.
427 if (unlikely(details))
430 free_swap_and_cache(pte_to_swp_entry(pte));
436 static void zap_pmd_range(struct mmu_gather *tlb,
437 pgd_t * dir, unsigned long address,
438 unsigned long size, struct zap_details *details)
441 unsigned long end, pgd_boundary;
445 if (unlikely(pgd_bad(*dir))) {
450 pmd = pmd_offset(dir, address);
451 end = address + size;
452 pgd_boundary = ((address + PGDIR_SIZE) & PGDIR_MASK);
453 if (pgd_boundary && (end > pgd_boundary))
456 zap_pte_range(tlb, pmd, address, end - address, details);
457 address = (address + PMD_SIZE) & PMD_MASK;
459 } while (address && (address < end));
462 static void unmap_page_range(struct mmu_gather *tlb,
463 struct vm_area_struct *vma, unsigned long address,
464 unsigned long end, struct zap_details *details)
468 BUG_ON(address >= end);
469 dir = pgd_offset(vma->vm_mm, address);
470 tlb_start_vma(tlb, vma);
472 zap_pmd_range(tlb, dir, address, end - address, details);
473 address = (address + PGDIR_SIZE) & PGDIR_MASK;
475 } while (address && (address < end));
476 tlb_end_vma(tlb, vma);
479 /* Dispose of an entire struct mmu_gather per rescheduling point */
480 #if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT)
481 #define ZAP_BLOCK_SIZE (FREE_PTE_NR * PAGE_SIZE)
484 /* For UP, 256 pages at a time gives nice low latency */
485 #if !defined(CONFIG_SMP) && defined(CONFIG_PREEMPT)
486 #define ZAP_BLOCK_SIZE (256 * PAGE_SIZE)
489 /* No preempt: go for improved straight-line efficiency */
490 #if !defined(CONFIG_PREEMPT)
491 #define ZAP_BLOCK_SIZE (1024 * PAGE_SIZE)
495 * unmap_vmas - unmap a range of memory covered by a list of vma's
496 * @tlbp: address of the caller's struct mmu_gather
497 * @mm: the controlling mm_struct
498 * @vma: the starting vma
499 * @start_addr: virtual address at which to start unmapping
500 * @end_addr: virtual address at which to end unmapping
501 * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
502 * @details: details of nonlinear truncation or shared cache invalidation
504 * Returns the number of vma's which were covered by the unmapping.
506 * Unmap all pages in the vma list. Called under page_table_lock.
508 * We aim to not hold page_table_lock for too long (for scheduling latency
509 * reasons). So zap pages in ZAP_BLOCK_SIZE bytecounts. This means we need to
510 * return the ending mmu_gather to the caller.
512 * Only addresses between `start' and `end' will be unmapped.
514 * The VMA list must be sorted in ascending virtual address order.
516 * unmap_vmas() assumes that the caller will flush the whole unmapped address
517 * range after unmap_vmas() returns. So the only responsibility here is to
518 * ensure that any thus-far unmapped pages are flushed before unmap_vmas()
519 * drops the lock and schedules.
521 int unmap_vmas(struct mmu_gather **tlbp, struct mm_struct *mm,
522 struct vm_area_struct *vma, unsigned long start_addr,
523 unsigned long end_addr, unsigned long *nr_accounted,
524 struct zap_details *details)
526 unsigned long zap_bytes = ZAP_BLOCK_SIZE;
527 unsigned long tlb_start = 0; /* For tlb_finish_mmu */
528 int tlb_start_valid = 0;
530 int atomic = details && details->atomic;
532 for ( ; vma && vma->vm_start < end_addr; vma = vma->vm_next) {
536 start = max(vma->vm_start, start_addr);
537 if (start >= vma->vm_end)
539 end = min(vma->vm_end, end_addr);
540 if (end <= vma->vm_start)
543 if (vma->vm_flags & VM_ACCOUNT)
544 *nr_accounted += (end - start) >> PAGE_SHIFT;
547 while (start != end) {
550 if (!tlb_start_valid) {
555 if (is_vm_hugetlb_page(vma)) {
557 unmap_hugepage_range(vma, start, end);
559 block = min(zap_bytes, end - start);
560 unmap_page_range(*tlbp, vma, start,
561 start + block, details);
566 if ((long)zap_bytes > 0)
568 if (!atomic && need_resched()) {
569 int fullmm = tlb_is_full_mm(*tlbp);
570 tlb_finish_mmu(*tlbp, tlb_start, start);
571 cond_resched_lock(&mm->page_table_lock);
572 *tlbp = tlb_gather_mmu(mm, fullmm);
575 zap_bytes = ZAP_BLOCK_SIZE;
582 * zap_page_range - remove user pages in a given range
583 * @vma: vm_area_struct holding the applicable pages
584 * @address: starting address of pages to zap
585 * @size: number of bytes to zap
586 * @details: details of nonlinear truncation or shared cache invalidation
588 void zap_page_range(struct vm_area_struct *vma, unsigned long address,
589 unsigned long size, struct zap_details *details)
591 struct mm_struct *mm = vma->vm_mm;
592 struct mmu_gather *tlb;
593 unsigned long end = address + size;
594 unsigned long nr_accounted = 0;
596 if (is_vm_hugetlb_page(vma)) {
597 zap_hugepage_range(vma, address, size);
602 spin_lock(&mm->page_table_lock);
603 tlb = tlb_gather_mmu(mm, 0);
604 unmap_vmas(&tlb, mm, vma, address, end, &nr_accounted, details);
605 tlb_finish_mmu(tlb, address, end);
606 spin_unlock(&mm->page_table_lock);
610 * Do a quick page-table lookup for a single page.
611 * mm->page_table_lock must be held.
614 follow_page(struct mm_struct *mm, unsigned long address, int write)
622 page = follow_huge_addr(mm, address, write);
626 pgd = pgd_offset(mm, address);
627 if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
630 pmd = pmd_offset(pgd, address);
634 return follow_huge_pmd(mm, address, pmd, write);
635 if (unlikely(pmd_bad(*pmd)))
638 ptep = pte_offset_map(pmd, address);
644 if (pte_present(pte)) {
645 if (write && !pte_write(pte))
648 if (pfn_valid(pfn)) {
649 page = pfn_to_page(pfn);
650 if (write && !pte_dirty(pte) && !PageDirty(page))
651 set_page_dirty(page);
652 mark_page_accessed(page);
662 follow_page_pfn(struct mm_struct *mm, unsigned long address, int write,
663 unsigned long *pfn_ptr)
672 page = follow_huge_addr(mm, address, write);
676 pgd = pgd_offset(mm, address);
677 if (pgd_none(*pgd) || pgd_bad(*pgd))
680 pmd = pmd_offset(pgd, address);
684 return follow_huge_pmd(mm, address, pmd, write);
688 ptep = pte_offset_map(pmd, address);
694 if (pte_present(pte)) {
695 if (write && !pte_write(pte))
697 if (write && !pte_dirty(pte)) {
698 struct page *page = pte_page(pte);
699 if (!PageDirty(page))
700 set_page_dirty(page);
703 if (pfn_valid(pfn)) {
704 struct page *page = pfn_to_page(pfn);
706 mark_page_accessed(page);
720 * Given a physical address, is there a useful struct page pointing to
721 * it? This may become more complex in the future if we start dealing
722 * with IO-aperture pages for direct-IO.
725 static inline struct page *get_page_map(struct page *page)
727 if (!pfn_valid(page_to_pfn(page)))
733 #ifndef CONFIG_X86_4G
735 untouched_anonymous_page(struct mm_struct* mm, struct vm_area_struct *vma,
736 unsigned long address)
741 /* Check if the vma is for an anonymous mapping. */
742 if (vma->vm_ops && vma->vm_ops->nopage)
745 /* Check if page directory entry exists. */
746 pgd = pgd_offset(mm, address);
747 if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
750 /* Check if page middle directory entry exists. */
751 pmd = pmd_offset(pgd, address);
752 if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
755 /* There is a pte slot for 'address' in 'mm'. */
761 int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
762 unsigned long start, int len, int write, int force,
763 struct page **pages, struct vm_area_struct **vmas)
769 * Require read or write permissions.
770 * If 'force' is set, we only require the "MAY" flags.
772 flags = write ? (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD);
773 flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
777 struct vm_area_struct * vma;
779 vma = find_extend_vma(mm, start);
780 if (!vma && in_gate_area(tsk, start)) {
781 unsigned long pg = start & PAGE_MASK;
782 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
786 if (write) /* user gate pages are read-only */
787 return i ? : -EFAULT;
788 pgd = pgd_offset_k(pg);
790 return i ? : -EFAULT;
791 pmd = pmd_offset(pgd, pg);
793 return i ? : -EFAULT;
794 pte = pte_offset_kernel(pmd, pg);
795 if (!pte || !pte_present(*pte))
796 return i ? : -EFAULT;
798 pages[i] = pte_page(*pte);
809 if (!vma || (pages && (vma->vm_flags & VM_IO))
810 || !(flags & vma->vm_flags))
811 return i ? : -EFAULT;
813 if (is_vm_hugetlb_page(vma)) {
814 i = follow_hugetlb_page(mm, vma, pages, vmas,
818 spin_lock(&mm->page_table_lock);
821 int lookup_write = write;
822 while (!(map = follow_page(mm, start, lookup_write))) {
824 * Shortcut for anonymous pages. We don't want
825 * to force the creation of pages tables for
826 * insanly big anonymously mapped areas that
827 * nobody touched so far. This is important
828 * for doing a core dump for these mappings.
830 * disable this for 4:4 - it prevents
831 * follow_page() from ever seeing these pages.
833 * (The 'fix' is dubious anyway, there's
834 * nothing that this code avoids which couldnt
835 * be triggered from userspace anyway.)
837 #ifndef CONFIG_X86_4G
839 untouched_anonymous_page(mm,vma,start)) {
840 map = ZERO_PAGE(start);
844 spin_unlock(&mm->page_table_lock);
845 switch (handle_mm_fault(mm,vma,start,write)) {
852 case VM_FAULT_SIGBUS:
853 return i ? i : -EFAULT;
855 return i ? i : -ENOMEM;
860 * Now that we have performed a write fault
861 * and surely no longer have a shared page we
862 * shouldn't write, we shouldn't ignore an
863 * unwritable page in the page table if
864 * we are forcing write access.
866 lookup_write = write && !force;
867 spin_lock(&mm->page_table_lock);
870 pages[i] = get_page_map(map);
872 spin_unlock(&mm->page_table_lock);
874 page_cache_release(pages[i]);
878 flush_dcache_page(pages[i]);
879 if (!PageReserved(pages[i]))
880 page_cache_get(pages[i]);
887 } while(len && start < vma->vm_end);
888 spin_unlock(&mm->page_table_lock);
894 EXPORT_SYMBOL(get_user_pages);
896 static void zeromap_pte_range(pte_t * pte, unsigned long address,
897 unsigned long size, pgprot_t prot)
901 address &= ~PMD_MASK;
902 end = address + size;
906 pte_t zero_pte = pte_wrprotect(mk_pte(ZERO_PAGE(address), prot));
907 BUG_ON(!pte_none(*pte));
908 set_pte(pte, zero_pte);
909 address += PAGE_SIZE;
911 } while (address && (address < end));
914 static inline int zeromap_pmd_range(struct mm_struct *mm, pmd_t * pmd, unsigned long address,
915 unsigned long size, pgprot_t prot)
917 unsigned long base, end;
919 base = address & PGDIR_MASK;
920 address &= ~PGDIR_MASK;
921 end = address + size;
922 if (end > PGDIR_SIZE)
925 pte_t * pte = pte_alloc_map(mm, pmd, base + address);
928 zeromap_pte_range(pte, base + address, end - address, prot);
930 address = (address + PMD_SIZE) & PMD_MASK;
932 } while (address && (address < end));
936 int zeromap_page_range(struct vm_area_struct *vma, unsigned long address, unsigned long size, pgprot_t prot)
940 unsigned long beg = address;
941 unsigned long end = address + size;
942 struct mm_struct *mm = vma->vm_mm;
944 dir = pgd_offset(mm, address);
945 flush_cache_range(vma, beg, end);
949 spin_lock(&mm->page_table_lock);
951 pmd_t *pmd = pmd_alloc(mm, dir, address);
955 error = zeromap_pmd_range(mm, pmd, address, end - address, prot);
958 address = (address + PGDIR_SIZE) & PGDIR_MASK;
960 } while (address && (address < end));
962 * Why flush? zeromap_pte_range has a BUG_ON for !pte_none()
964 flush_tlb_range(vma, beg, end);
965 spin_unlock(&mm->page_table_lock);
970 * maps a range of physical memory into the requested pages. the old
971 * mappings are removed. any references to nonexistent pages results
972 * in null mappings (currently treated as "copy-on-access")
974 static inline void remap_pte_range(pte_t * pte, unsigned long address, unsigned long size,
975 unsigned long phys_addr, pgprot_t prot)
980 address &= ~PMD_MASK;
981 end = address + size;
984 pfn = phys_addr >> PAGE_SHIFT;
986 BUG_ON(!pte_none(*pte));
987 if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
988 set_pte(pte, pfn_pte(pfn, prot));
989 address += PAGE_SIZE;
992 } while (address && (address < end));
995 static inline int remap_pmd_range(struct mm_struct *mm, pmd_t * pmd, unsigned long address, unsigned long size,
996 unsigned long phys_addr, pgprot_t prot)
998 unsigned long base, end;
1000 base = address & PGDIR_MASK;
1001 address &= ~PGDIR_MASK;
1002 end = address + size;
1003 if (end > PGDIR_SIZE)
1005 phys_addr -= address;
1007 pte_t * pte = pte_alloc_map(mm, pmd, base + address);
1010 remap_pte_range(pte, base + address, end - address, address + phys_addr, prot);
1012 address = (address + PMD_SIZE) & PMD_MASK;
1014 } while (address && (address < end));
1018 /* Note: this is only safe if the mm semaphore is held when called. */
1019 int remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long phys_addr, unsigned long size, pgprot_t prot)
1023 unsigned long beg = from;
1024 unsigned long end = from + size;
1025 struct mm_struct *mm = vma->vm_mm;
1028 dir = pgd_offset(mm, from);
1029 flush_cache_range(vma, beg, end);
1033 spin_lock(&mm->page_table_lock);
1035 pmd_t *pmd = pmd_alloc(mm, dir, from);
1039 error = remap_pmd_range(mm, pmd, from, end - from, phys_addr + from, prot);
1042 from = (from + PGDIR_SIZE) & PGDIR_MASK;
1044 } while (from && (from < end));
1046 * Why flush? remap_pte_range has a BUG_ON for !pte_none()
1048 flush_tlb_range(vma, beg, end);
1049 spin_unlock(&mm->page_table_lock);
1053 EXPORT_SYMBOL(remap_page_range);
1056 * Do pte_mkwrite, but only if the vma says VM_WRITE. We do this when
1057 * servicing faults for write access. In the normal case, do always want
1058 * pte_mkwrite. But get_user_pages can cause write faults for mappings
1059 * that do not have writing enabled, when used by access_process_vm.
1061 static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
1063 if (likely(vma->vm_flags & VM_WRITE))
1064 pte = pte_mkwrite(pte);
1069 * We hold the mm semaphore for reading and vma->vm_mm->page_table_lock
1071 static inline void break_cow(struct vm_area_struct * vma, struct page * new_page, unsigned long address,
1076 flush_cache_page(vma, address);
1077 entry = maybe_mkwrite(pte_mkdirty(mk_pte(new_page, vma->vm_page_prot)),
1079 ptep_establish(vma, address, page_table, entry);
1080 update_mmu_cache(vma, address, entry);
1084 * This routine handles present pages, when users try to write
1085 * to a shared page. It is done by copying the page to a new address
1086 * and decrementing the shared-page counter for the old page.
1088 * Goto-purists beware: the only reason for goto's here is that it results
1089 * in better assembly code.. The "default" path will see no jumps at all.
1091 * Note that this routine assumes that the protection checks have been
1092 * done by the caller (the low-level page fault routine in most cases).
1093 * Thus we can safely just mark it writable once we've done any necessary
1096 * We also mark the page dirty at this point even though the page will
1097 * change only once the write actually happens. This avoids a few races,
1098 * and potentially makes it more efficient.
1100 * We hold the mm semaphore and the page_table_lock on entry and exit
1101 * with the page_table_lock released.
1103 static int do_wp_page(struct mm_struct *mm, struct vm_area_struct * vma,
1104 unsigned long address, pte_t *page_table, pmd_t *pmd, pte_t pte)
1106 struct page *old_page, *new_page;
1107 unsigned long pfn = pte_pfn(pte);
1110 if (unlikely(!pfn_valid(pfn))) {
1112 * This should really halt the system so it can be debugged or
1113 * at least the kernel stops what it's doing before it corrupts
1114 * data, but for the moment just pretend this is OOM.
1116 pte_unmap(page_table);
1117 printk(KERN_ERR "do_wp_page: bogus page at address %08lx\n",
1119 spin_unlock(&mm->page_table_lock);
1120 return VM_FAULT_OOM;
1122 old_page = pfn_to_page(pfn);
1124 if (!TestSetPageLocked(old_page)) {
1125 int reuse = can_share_swap_page(old_page);
1126 unlock_page(old_page);
1128 flush_cache_page(vma, address);
1129 entry = maybe_mkwrite(pte_mkyoung(pte_mkdirty(pte)),
1131 ptep_set_access_flags(vma, address, page_table, entry, 1);
1132 update_mmu_cache(vma, address, entry);
1133 pte_unmap(page_table);
1134 spin_unlock(&mm->page_table_lock);
1135 return VM_FAULT_MINOR;
1138 pte_unmap(page_table);
1141 * Ok, we need to copy. Oh, well..
1143 page_cache_get(old_page);
1144 spin_unlock(&mm->page_table_lock);
1146 if (unlikely(anon_vma_prepare(vma)))
1148 new_page = alloc_page_vma(GFP_HIGHUSER, vma, address);
1151 copy_cow_page(old_page,new_page,address);
1154 * Re-check the pte - we dropped the lock
1156 spin_lock(&mm->page_table_lock);
1157 page_table = pte_offset_map(pmd, address);
1158 if (likely(pte_same(*page_table, pte))) {
1159 if (PageReserved(old_page))
1162 page_remove_rmap(old_page);
1163 break_cow(vma, new_page, address, page_table);
1164 lru_cache_add_active(new_page);
1165 page_add_anon_rmap(new_page, vma, address);
1167 /* Free the old page.. */
1168 new_page = old_page;
1170 pte_unmap(page_table);
1171 page_cache_release(new_page);
1172 page_cache_release(old_page);
1173 spin_unlock(&mm->page_table_lock);
1174 return VM_FAULT_MINOR;
1177 page_cache_release(old_page);
1178 return VM_FAULT_OOM;
1182 * Helper function for unmap_mapping_range().
1184 static inline void unmap_mapping_range_list(struct prio_tree_root *root,
1185 struct zap_details *details)
1187 struct vm_area_struct *vma = NULL;
1188 struct prio_tree_iter iter;
1189 pgoff_t vba, vea, zba, zea;
1191 while ((vma = vma_prio_tree_next(vma, root, &iter,
1192 details->first_index, details->last_index)) != NULL) {
1193 vba = vma->vm_pgoff;
1194 vea = vba + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) - 1;
1195 /* Assume for now that PAGE_CACHE_SHIFT == PAGE_SHIFT */
1196 zba = details->first_index;
1199 zea = details->last_index;
1203 ((zba - vba) << PAGE_SHIFT) + vma->vm_start,
1204 (zea - zba + 1) << PAGE_SHIFT, details);
1209 * unmap_mapping_range - unmap the portion of all mmaps
1210 * in the specified address_space corresponding to the specified
1211 * page range in the underlying file.
1212 * @address_space: the address space containing mmaps to be unmapped.
1213 * @holebegin: byte in first page to unmap, relative to the start of
1214 * the underlying file. This will be rounded down to a PAGE_SIZE
1215 * boundary. Note that this is different from vmtruncate(), which
1216 * must keep the partial page. In contrast, we must get rid of
1218 * @holelen: size of prospective hole in bytes. This will be rounded
1219 * up to a PAGE_SIZE boundary. A holelen of zero truncates to the
1221 * @even_cows: 1 when truncating a file, unmap even private COWed pages;
1222 * but 0 when invalidating pagecache, don't throw away private data.
1224 void unmap_mapping_range(struct address_space *mapping,
1225 loff_t const holebegin, loff_t const holelen, int even_cows)
1227 struct zap_details details;
1228 pgoff_t hba = holebegin >> PAGE_SHIFT;
1229 pgoff_t hlen = (holelen + PAGE_SIZE - 1) >> PAGE_SHIFT;
1231 /* Check for overflow. */
1232 if (sizeof(holelen) > sizeof(hlen)) {
1234 (holebegin + holelen + PAGE_SIZE - 1) >> PAGE_SHIFT;
1235 if (holeend & ~(long long)ULONG_MAX)
1236 hlen = ULONG_MAX - hba + 1;
1239 details.check_mapping = even_cows? NULL: mapping;
1240 details.nonlinear_vma = NULL;
1241 details.first_index = hba;
1242 details.last_index = hba + hlen - 1;
1243 details.atomic = 1; /* A spinlock is held */
1244 if (details.last_index < details.first_index)
1245 details.last_index = ULONG_MAX;
1247 spin_lock(&mapping->i_mmap_lock);
1248 /* Protect against page fault */
1249 atomic_inc(&mapping->truncate_count);
1251 if (unlikely(!prio_tree_empty(&mapping->i_mmap)))
1252 unmap_mapping_range_list(&mapping->i_mmap, &details);
1255 * In nonlinear VMAs there is no correspondence between virtual address
1256 * offset and file offset. So we must perform an exhaustive search
1257 * across *all* the pages in each nonlinear VMA, not just the pages
1258 * whose virtual address lies outside the file truncation point.
1260 if (unlikely(!list_empty(&mapping->i_mmap_nonlinear))) {
1261 struct vm_area_struct *vma;
1262 list_for_each_entry(vma, &mapping->i_mmap_nonlinear,
1263 shared.vm_set.list) {
1264 details.nonlinear_vma = vma;
1265 zap_page_range(vma, vma->vm_start,
1266 vma->vm_end - vma->vm_start, &details);
1269 spin_unlock(&mapping->i_mmap_lock);
1271 EXPORT_SYMBOL(unmap_mapping_range);
1274 * Handle all mappings that got truncated by a "truncate()"
1277 * NOTE! We have to be ready to update the memory sharing
1278 * between the file and the memory map for a potential last
1279 * incomplete page. Ugly, but necessary.
1281 int vmtruncate(struct inode * inode, loff_t offset)
1283 struct address_space *mapping = inode->i_mapping;
1284 unsigned long limit;
1286 if (inode->i_size < offset)
1288 i_size_write(inode, offset);
1289 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
1290 truncate_inode_pages(mapping, offset);
1294 limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
1295 if (limit != RLIM_INFINITY && offset > limit)
1297 if (offset > inode->i_sb->s_maxbytes)
1299 i_size_write(inode, offset);
1302 if (inode->i_op && inode->i_op->truncate)
1303 inode->i_op->truncate(inode);
1306 send_sig(SIGXFSZ, current, 0);
1311 EXPORT_SYMBOL(vmtruncate);
1314 * Primitive swap readahead code. We simply read an aligned block of
1315 * (1 << page_cluster) entries in the swap area. This method is chosen
1316 * because it doesn't cost us any seek time. We also make sure to queue
1317 * the 'original' request together with the readahead ones...
1319 * This has been extended to use the NUMA policies from the mm triggering
1322 * Caller must hold down_read on the vma->vm_mm if vma is not NULL.
1324 void swapin_readahead(swp_entry_t entry, unsigned long addr,struct vm_area_struct *vma)
1327 struct vm_area_struct *next_vma = vma ? vma->vm_next : NULL;
1330 struct page *new_page;
1331 unsigned long offset;
1334 * Get the number of handles we should do readahead io to.
1336 num = valid_swaphandles(entry, &offset);
1337 for (i = 0; i < num; offset++, i++) {
1338 /* Ok, do the async read-ahead now */
1339 new_page = read_swap_cache_async(swp_entry(swp_type(entry),
1340 offset), vma, addr);
1343 page_cache_release(new_page);
1346 * Find the next applicable VMA for the NUMA policy.
1352 if (addr >= vma->vm_end) {
1354 next_vma = vma ? vma->vm_next : NULL;
1356 if (vma && addr < vma->vm_start)
1359 if (next_vma && addr >= next_vma->vm_start) {
1361 next_vma = vma->vm_next;
1366 lru_add_drain(); /* Push any new pages onto the LRU now */
1370 * We hold the mm semaphore and the page_table_lock on entry and
1371 * should release the pagetable lock on exit..
1373 static int do_swap_page(struct mm_struct * mm,
1374 struct vm_area_struct * vma, unsigned long address,
1375 pte_t *page_table, pmd_t *pmd, pte_t orig_pte, int write_access)
1378 swp_entry_t entry = pte_to_swp_entry(orig_pte);
1380 int ret = VM_FAULT_MINOR;
1382 pte_unmap(page_table);
1383 spin_unlock(&mm->page_table_lock);
1384 page = lookup_swap_cache(entry);
1386 swapin_readahead(entry, address, vma);
1387 page = read_swap_cache_async(entry, vma, address);
1390 * Back out if somebody else faulted in this pte while
1391 * we released the page table lock.
1393 spin_lock(&mm->page_table_lock);
1394 page_table = pte_offset_map(pmd, address);
1395 if (likely(pte_same(*page_table, orig_pte)))
1398 ret = VM_FAULT_MINOR;
1399 pte_unmap(page_table);
1400 spin_unlock(&mm->page_table_lock);
1404 /* Had to read the page from swap area: Major fault */
1405 ret = VM_FAULT_MAJOR;
1406 inc_page_state(pgmajfault);
1409 mark_page_accessed(page);
1413 * Back out if somebody else faulted in this pte while we
1414 * released the page table lock.
1416 spin_lock(&mm->page_table_lock);
1417 page_table = pte_offset_map(pmd, address);
1418 if (unlikely(!pte_same(*page_table, orig_pte))) {
1419 pte_unmap(page_table);
1420 spin_unlock(&mm->page_table_lock);
1422 page_cache_release(page);
1423 ret = VM_FAULT_MINOR;
1427 /* The page isn't present yet, go ahead with the fault. */
1431 remove_exclusive_swap_page(page);
1434 pte = mk_pte(page, vma->vm_page_prot);
1435 if (write_access && can_share_swap_page(page)) {
1436 pte = maybe_mkwrite(pte_mkdirty(pte), vma);
1441 flush_icache_page(vma, page);
1442 set_pte(page_table, pte);
1443 page_add_anon_rmap(page, vma, address);
1446 if (do_wp_page(mm, vma, address,
1447 page_table, pmd, pte) == VM_FAULT_OOM)
1452 /* No need to invalidate - it was non-present before */
1453 update_mmu_cache(vma, address, pte);
1454 pte_unmap(page_table);
1455 spin_unlock(&mm->page_table_lock);
1461 * We are called with the MM semaphore and page_table_lock
1462 * spinlock held to protect against concurrent faults in
1463 * multithreaded programs.
1466 do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
1467 pte_t *page_table, pmd_t *pmd, int write_access,
1471 struct page * page = ZERO_PAGE(addr);
1473 /* Read-only mapping of ZERO_PAGE. */
1474 entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
1476 /* ..except if it's a write access */
1478 /* Allocate our own private page. */
1479 pte_unmap(page_table);
1480 spin_unlock(&mm->page_table_lock);
1482 if (unlikely(anon_vma_prepare(vma)))
1484 page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
1487 clear_user_highpage(page, addr);
1489 spin_lock(&mm->page_table_lock);
1490 page_table = pte_offset_map(pmd, addr);
1492 if (!pte_none(*page_table)) {
1493 pte_unmap(page_table);
1494 page_cache_release(page);
1495 spin_unlock(&mm->page_table_lock);
1499 entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
1500 vma->vm_page_prot)),
1502 lru_cache_add_active(page);
1503 mark_page_accessed(page);
1504 page_add_anon_rmap(page, vma, addr);
1507 set_pte(page_table, entry);
1508 pte_unmap(page_table);
1510 /* No need to invalidate - it was non-present before */
1511 update_mmu_cache(vma, addr, entry);
1512 spin_unlock(&mm->page_table_lock);
1514 return VM_FAULT_MINOR;
1516 return VM_FAULT_OOM;
1520 * do_no_page() tries to create a new page mapping. It aggressively
1521 * tries to share with existing pages, but makes a separate copy if
1522 * the "write_access" parameter is true in order to avoid the next
1525 * As this is called only for pages that do not currently exist, we
1526 * do not need to flush old virtual caches or the TLB.
1528 * This is called with the MM semaphore held and the page table
1529 * spinlock held. Exit with the spinlock released.
1532 do_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
1533 unsigned long address, int write_access, pte_t *page_table, pmd_t *pmd)
1535 struct page * new_page;
1536 struct address_space *mapping = NULL;
1539 int ret = VM_FAULT_MINOR;
1542 if (!vma->vm_ops || !vma->vm_ops->nopage)
1543 return do_anonymous_page(mm, vma, page_table,
1544 pmd, write_access, address);
1545 pte_unmap(page_table);
1546 spin_unlock(&mm->page_table_lock);
1549 mapping = vma->vm_file->f_mapping;
1550 sequence = atomic_read(&mapping->truncate_count);
1552 smp_rmb(); /* Prevent CPU from reordering lock-free ->nopage() */
1554 new_page = vma->vm_ops->nopage(vma, address & PAGE_MASK, &ret);
1556 /* no page was available -- either SIGBUS or OOM */
1557 if (new_page == NOPAGE_SIGBUS)
1558 return VM_FAULT_SIGBUS;
1559 if (new_page == NOPAGE_OOM)
1560 return VM_FAULT_OOM;
1563 * Should we do an early C-O-W break?
1565 if (write_access && !(vma->vm_flags & VM_SHARED)) {
1568 if (unlikely(anon_vma_prepare(vma)))
1570 page = alloc_page_vma(GFP_HIGHUSER, vma, address);
1573 copy_user_highpage(page, new_page, address);
1574 page_cache_release(new_page);
1579 spin_lock(&mm->page_table_lock);
1581 * For a file-backed vma, someone could have truncated or otherwise
1582 * invalidated this page. If unmap_mapping_range got called,
1583 * retry getting the page.
1586 (unlikely(sequence != atomic_read(&mapping->truncate_count)))) {
1587 sequence = atomic_read(&mapping->truncate_count);
1588 spin_unlock(&mm->page_table_lock);
1589 page_cache_release(new_page);
1592 page_table = pte_offset_map(pmd, address);
1595 * This silly early PAGE_DIRTY setting removes a race
1596 * due to the bad i386 page protection. But it's valid
1597 * for other architectures too.
1599 * Note that if write_access is true, we either now have
1600 * an exclusive copy of the page, or this is a shared mapping,
1601 * so we can make it writable and dirty to avoid having to
1602 * handle that later.
1604 /* Only go through if we didn't race with anybody else... */
1605 if (pte_none(*page_table)) {
1606 if (!PageReserved(new_page))
1608 flush_icache_page(vma, new_page);
1609 entry = mk_pte(new_page, vma->vm_page_prot);
1611 entry = maybe_mkwrite(pte_mkdirty(entry), vma);
1612 set_pte(page_table, entry);
1614 lru_cache_add_active(new_page);
1615 page_add_anon_rmap(new_page, vma, address);
1617 page_add_file_rmap(new_page);
1618 pte_unmap(page_table);
1620 /* One of our sibling threads was faster, back out. */
1621 pte_unmap(page_table);
1622 page_cache_release(new_page);
1623 spin_unlock(&mm->page_table_lock);
1627 /* no need to invalidate: a not-present page shouldn't be cached */
1628 update_mmu_cache(vma, address, entry);
1629 spin_unlock(&mm->page_table_lock);
1633 page_cache_release(new_page);
1639 * Fault of a previously existing named mapping. Repopulate the pte
1640 * from the encoded file_pte if possible. This enables swappable
1643 static int do_file_page(struct mm_struct * mm, struct vm_area_struct * vma,
1644 unsigned long address, int write_access, pte_t *pte, pmd_t *pmd)
1646 unsigned long pgoff;
1649 BUG_ON(!vma->vm_ops || !vma->vm_ops->nopage);
1651 * Fall back to the linear mapping if the fs does not support
1654 if (!vma->vm_ops || !vma->vm_ops->populate ||
1655 (write_access && !(vma->vm_flags & VM_SHARED))) {
1657 return do_no_page(mm, vma, address, write_access, pte, pmd);
1660 pgoff = pte_to_pgoff(*pte);
1663 spin_unlock(&mm->page_table_lock);
1665 err = vma->vm_ops->populate(vma, address & PAGE_MASK, PAGE_SIZE, vma->vm_page_prot, pgoff, 0);
1667 return VM_FAULT_OOM;
1669 return VM_FAULT_SIGBUS;
1670 return VM_FAULT_MAJOR;
1674 * These routines also need to handle stuff like marking pages dirty
1675 * and/or accessed for architectures that don't do it in hardware (most
1676 * RISC architectures). The early dirtying is also good on the i386.
1678 * There is also a hook called "update_mmu_cache()" that architectures
1679 * with external mmu caches can use to update those (ie the Sparc or
1680 * PowerPC hashed page tables that act as extended TLBs).
1682 * Note the "page_table_lock". It is to protect against kswapd removing
1683 * pages from under us. Note that kswapd only ever _removes_ pages, never
1684 * adds them. As such, once we have noticed that the page is not present,
1685 * we can drop the lock early.
1687 * The adding of pages is protected by the MM semaphore (which we hold),
1688 * so we don't need to worry about a page being suddenly been added into
1691 * We enter with the pagetable spinlock held, we are supposed to
1692 * release it when done.
1694 static inline int handle_pte_fault(struct mm_struct *mm,
1695 struct vm_area_struct * vma, unsigned long address,
1696 int write_access, pte_t *pte, pmd_t *pmd)
1701 if (!pte_present(entry)) {
1703 * If it truly wasn't present, we know that kswapd
1704 * and the PTE updates will not touch it later. So
1707 if (pte_none(entry))
1708 return do_no_page(mm, vma, address, write_access, pte, pmd);
1709 if (pte_file(entry))
1710 return do_file_page(mm, vma, address, write_access, pte, pmd);
1711 return do_swap_page(mm, vma, address, pte, pmd, entry, write_access);
1715 if (!pte_write(entry))
1716 return do_wp_page(mm, vma, address, pte, pmd, entry);
1718 entry = pte_mkdirty(entry);
1720 entry = pte_mkyoung(entry);
1721 ptep_set_access_flags(vma, address, pte, entry, write_access);
1722 update_mmu_cache(vma, address, entry);
1724 spin_unlock(&mm->page_table_lock);
1725 return VM_FAULT_MINOR;
1729 * By the time we get here, we already hold the mm semaphore
1731 int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct * vma,
1732 unsigned long address, int write_access)
1737 __set_current_state(TASK_RUNNING);
1738 pgd = pgd_offset(mm, address);
1740 inc_page_state(pgfault);
1742 if (is_vm_hugetlb_page(vma))
1743 return VM_FAULT_SIGBUS; /* mapping truncation does this. */
1746 * We need the page table lock to synchronize with kswapd
1747 * and the SMP-safe atomic PTE updates.
1749 spin_lock(&mm->page_table_lock);
1750 pmd = pmd_alloc(mm, pgd, address);
1753 pte_t * pte = pte_alloc_map(mm, pmd, address);
1755 return handle_pte_fault(mm, vma, address, write_access, pte, pmd);
1757 spin_unlock(&mm->page_table_lock);
1758 return VM_FAULT_OOM;
1762 * Allocate page middle directory.
1764 * We've already handled the fast-path in-line, and we own the
1767 * On a two-level page table, this ends up actually being entirely
1770 pmd_t fastcall *__pmd_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
1774 spin_unlock(&mm->page_table_lock);
1775 new = pmd_alloc_one(mm, address);
1776 spin_lock(&mm->page_table_lock);
1781 * Because we dropped the lock, we should re-check the
1782 * entry, as somebody else could have populated it..
1784 if (pgd_present(*pgd)) {
1788 pgd_populate(mm, pgd, new);
1790 return pmd_offset(pgd, address);
1793 int make_pages_present(unsigned long addr, unsigned long end)
1795 int ret, len, write;
1796 struct vm_area_struct * vma;
1798 vma = find_vma(current->mm, addr);
1799 write = (vma->vm_flags & VM_WRITE) != 0;
1802 if (end > vma->vm_end)
1804 len = (end+PAGE_SIZE-1)/PAGE_SIZE-addr/PAGE_SIZE;
1805 ret = get_user_pages(current, current->mm, addr,
1806 len, write, 0, NULL, NULL);
1809 return ret == len ? 0 : -1;
1813 * Map a vmalloc()-space virtual address to the physical page.
1815 struct page * vmalloc_to_page(void * vmalloc_addr)
1817 unsigned long addr = (unsigned long) vmalloc_addr;
1818 struct page *page = NULL;
1819 pgd_t *pgd = pgd_offset_k(addr);
1823 if (!pgd_none(*pgd)) {
1824 pmd = pmd_offset(pgd, addr);
1825 if (!pmd_none(*pmd)) {
1827 ptep = pte_offset_map(pmd, addr);
1829 if (pte_present(pte))
1830 page = pte_page(pte);
1838 EXPORT_SYMBOL(vmalloc_to_page);
1840 #if !defined(CONFIG_ARCH_GATE_AREA)
1842 #if defined(AT_SYSINFO_EHDR)
1843 struct vm_area_struct gate_vma;
1845 static int __init gate_vma_init(void)
1847 gate_vma.vm_mm = NULL;
1848 gate_vma.vm_start = FIXADDR_USER_START;
1849 gate_vma.vm_end = FIXADDR_USER_END;
1850 gate_vma.vm_page_prot = PAGE_READONLY;
1851 gate_vma.vm_flags = 0;
1854 __initcall(gate_vma_init);
1857 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
1859 #ifdef AT_SYSINFO_EHDR
1866 int in_gate_area(struct task_struct *task, unsigned long addr)
1868 #ifdef AT_SYSINFO_EHDR
1869 if ((addr >= FIXADDR_USER_START) && (addr < FIXADDR_USER_END))