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>
52 #include <asm/uaccess.h>
54 #include <asm/tlbflush.h>
55 #include <asm/pgtable.h>
57 #include <linux/swapops.h>
58 #include <linux/elf.h>
60 #ifndef CONFIG_DISCONTIGMEM
61 /* use the per-pgdat data instead for discontigmem - mbligh */
62 unsigned long max_mapnr;
65 EXPORT_SYMBOL(max_mapnr);
66 EXPORT_SYMBOL(mem_map);
69 unsigned long num_physpages;
71 struct page *highmem_start_page;
73 EXPORT_SYMBOL(num_physpages);
74 EXPORT_SYMBOL(highmem_start_page);
75 EXPORT_SYMBOL(high_memory);
78 * We special-case the C-O-W ZERO_PAGE, because it's such
79 * a common occurrence (no need to read the page to know
80 * that it's zero - better for the cache and memory subsystem).
82 static inline void copy_cow_page(struct page * from, struct page * to, unsigned long address)
84 if (from == ZERO_PAGE(address)) {
85 clear_user_highpage(to, address);
88 copy_user_highpage(to, from, address);
92 * Note: this doesn't free the actual pages themselves. That
93 * has been handled earlier when unmapping all the memory regions.
95 static inline void free_one_pmd(struct mmu_gather *tlb, pmd_t * dir)
106 page = pmd_page(*dir);
108 pgtable_remove_rmap(page);
109 pte_free_tlb(tlb, page);
112 static inline void free_one_pgd(struct mmu_gather *tlb, pgd_t * dir)
124 pmd = pmd_offset(dir, 0);
126 for (j = 0; j < PTRS_PER_PMD ; j++)
127 free_one_pmd(tlb, pmd+j);
128 pmd_free_tlb(tlb, pmd);
132 * This function clears all user-level page tables of a process - this
133 * is needed by execve(), so that old pages aren't in the way.
135 * Must be called with pagetable lock held.
137 void clear_page_tables(struct mmu_gather *tlb, unsigned long first, int nr)
139 pgd_t * page_dir = tlb->mm->pgd;
143 free_one_pgd(tlb, page_dir);
148 pte_t fastcall * pte_alloc_map(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
150 if (!pmd_present(*pmd)) {
153 spin_unlock(&mm->page_table_lock);
154 new = pte_alloc_one(mm, address);
155 spin_lock(&mm->page_table_lock);
160 * Because we dropped the lock, we should re-check the
161 * entry, as somebody else could have populated it..
163 if (pmd_present(*pmd)) {
167 pgtable_add_rmap(new, mm, address);
168 pmd_populate(mm, pmd, new);
171 return pte_offset_map(pmd, address);
174 pte_t fastcall * pte_alloc_kernel(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
176 if (!pmd_present(*pmd)) {
179 spin_unlock(&mm->page_table_lock);
180 new = pte_alloc_one_kernel(mm, address);
181 spin_lock(&mm->page_table_lock);
186 * Because we dropped the lock, we should re-check the
187 * entry, as somebody else could have populated it..
189 if (pmd_present(*pmd)) {
190 pte_free_kernel(new);
193 pgtable_add_rmap(virt_to_page(new), mm, address);
194 pmd_populate_kernel(mm, pmd, new);
197 return pte_offset_kernel(pmd, address);
199 #define PTE_TABLE_MASK ((PTRS_PER_PTE-1) * sizeof(pte_t))
200 #define PMD_TABLE_MASK ((PTRS_PER_PMD-1) * sizeof(pmd_t))
203 * copy one vm_area from one task to the other. Assumes the page tables
204 * already present in the new task to be cleared in the whole range
205 * covered by this vma.
207 * 08Jan98 Merged into one routine from several inline routines to reduce
208 * variable count and make things faster. -jj
210 * dst->page_table_lock is held on entry and exit,
211 * but may be dropped within pmd_alloc() and pte_alloc_map().
213 int copy_page_range(struct mm_struct *dst, struct mm_struct *src,
214 struct vm_area_struct *vma)
216 pgd_t * src_pgd, * dst_pgd;
217 unsigned long address = vma->vm_start;
218 unsigned long end = vma->vm_end;
220 struct pte_chain *pte_chain = NULL;
222 if (is_vm_hugetlb_page(vma))
223 return copy_hugetlb_page_range(dst, src, vma);
225 pte_chain = pte_chain_alloc(GFP_ATOMIC | __GFP_NOWARN);
227 spin_unlock(&dst->page_table_lock);
228 pte_chain = pte_chain_alloc(GFP_KERNEL);
229 spin_lock(&dst->page_table_lock);
234 cow = (vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
235 src_pgd = pgd_offset(src, address)-1;
236 dst_pgd = pgd_offset(dst, address)-1;
239 pmd_t * src_pmd, * dst_pmd;
241 src_pgd++; dst_pgd++;
245 if (pgd_none(*src_pgd))
246 goto skip_copy_pmd_range;
247 if (pgd_bad(*src_pgd)) {
250 skip_copy_pmd_range: address = (address + PGDIR_SIZE) & PGDIR_MASK;
251 if (!address || (address >= end))
256 src_pmd = pmd_offset(src_pgd, address);
257 dst_pmd = pmd_alloc(dst, dst_pgd, address);
262 pte_t * src_pte, * dst_pte;
266 if (pmd_none(*src_pmd))
267 goto skip_copy_pte_range;
268 if (pmd_bad(*src_pmd)) {
272 address = (address + PMD_SIZE) & PMD_MASK;
275 goto cont_copy_pmd_range;
278 dst_pte = pte_alloc_map(dst, dst_pmd, address);
281 spin_lock(&src->page_table_lock);
282 src_pte = pte_offset_map_nested(src_pmd, address);
284 pte_t pte = *src_pte;
288 if (!vx_rsspages_avail(dst, 1)) {
289 spin_unlock(&src->page_table_lock);
295 goto cont_copy_pte_range_noset;
296 /* pte contains position in swap, so copy. */
297 if (!pte_present(pte)) {
299 swap_duplicate(pte_to_swp_entry(pte));
300 set_pte(dst_pte, pte);
301 goto cont_copy_pte_range_noset;
304 /* the pte points outside of valid memory, the
305 * mapping is assumed to be good, meaningful
306 * and not mapped via rmap - duplicate the
311 page = pfn_to_page(pfn);
313 if (!page || PageReserved(page)) {
314 set_pte(dst_pte, pte);
315 goto cont_copy_pte_range_noset;
319 * If it's a COW mapping, write protect it both
320 * in the parent and the child
323 ptep_set_wrprotect(src_pte);
328 * If it's a shared mapping, mark it clean in
331 if (vma->vm_flags & VM_SHARED)
332 pte = pte_mkclean(pte);
333 pte = pte_mkold(pte);
336 vx_rsspages_inc(dst);
338 set_pte(dst_pte, pte);
339 pte_chain = page_add_rmap(page, dst_pte,
342 goto cont_copy_pte_range_noset;
343 pte_chain = pte_chain_alloc(GFP_ATOMIC | __GFP_NOWARN);
345 goto cont_copy_pte_range_noset;
348 * pte_chain allocation failed, and we need to
351 pte_unmap_nested(src_pte);
353 spin_unlock(&src->page_table_lock);
354 spin_unlock(&dst->page_table_lock);
355 pte_chain = pte_chain_alloc(GFP_KERNEL);
356 spin_lock(&dst->page_table_lock);
359 spin_lock(&src->page_table_lock);
360 dst_pte = pte_offset_map(dst_pmd, address);
361 src_pte = pte_offset_map_nested(src_pmd,
363 cont_copy_pte_range_noset:
364 address += PAGE_SIZE;
365 if (address >= end) {
366 pte_unmap_nested(src_pte);
372 } while ((unsigned long)src_pte & PTE_TABLE_MASK);
373 pte_unmap_nested(src_pte-1);
374 pte_unmap(dst_pte-1);
375 spin_unlock(&src->page_table_lock);
380 } while ((unsigned long)src_pmd & PMD_TABLE_MASK);
383 spin_unlock(&src->page_table_lock);
385 pte_chain_free(pte_chain);
388 pte_chain_free(pte_chain);
392 static void zap_pte_range(struct mmu_gather *tlb,
393 pmd_t *pmd, unsigned long address,
394 unsigned long size, struct zap_details *details)
396 unsigned long offset;
406 ptep = pte_offset_map(pmd, address);
407 offset = address & ~PMD_MASK;
408 if (offset + size > PMD_SIZE)
409 size = PMD_SIZE - offset;
411 for (offset=0; offset < size; ptep++, offset += PAGE_SIZE) {
415 if (pte_present(pte)) {
416 struct page *page = NULL;
417 unsigned long pfn = pte_pfn(pte);
418 if (pfn_valid(pfn)) {
419 page = pfn_to_page(pfn);
420 if (PageReserved(page))
423 if (unlikely(details) && page) {
425 * unmap_shared_mapping_pages() wants to
426 * invalidate cache without truncating:
427 * unmap shared but keep private pages.
429 if (details->check_mapping &&
430 details->check_mapping != page->mapping)
433 * Each page->index must be checked when
434 * invalidating or truncating nonlinear.
436 if (details->nonlinear_vma &&
437 (page->index < details->first_index ||
438 page->index > details->last_index))
441 pte = ptep_get_and_clear(ptep);
442 tlb_remove_tlb_entry(tlb, ptep, address+offset);
445 if (unlikely(details) && details->nonlinear_vma
446 && linear_page_index(details->nonlinear_vma,
447 address+offset) != page->index)
448 set_pte(ptep, pgoff_to_pte(page->index));
450 set_page_dirty(page);
451 if (pte_young(pte) && page_mapping(page))
452 mark_page_accessed(page);
454 page_remove_rmap(page, ptep);
455 tlb_remove_page(tlb, page);
459 * If details->check_mapping, we leave swap entries;
460 * if details->nonlinear_vma, we leave file entries.
462 if (unlikely(details))
465 free_swap_and_cache(pte_to_swp_entry(pte));
471 static void zap_pmd_range(struct mmu_gather *tlb,
472 pgd_t * dir, unsigned long address,
473 unsigned long size, struct zap_details *details)
485 pmd = pmd_offset(dir, address);
486 end = address + size;
487 if (end > ((address + PGDIR_SIZE) & PGDIR_MASK))
488 end = ((address + PGDIR_SIZE) & PGDIR_MASK);
490 zap_pte_range(tlb, pmd, address, end - address, details);
491 address = (address + PMD_SIZE) & PMD_MASK;
493 } while (address < end);
496 static void unmap_page_range(struct mmu_gather *tlb,
497 struct vm_area_struct *vma, unsigned long address,
498 unsigned long end, struct zap_details *details)
502 BUG_ON(address >= end);
503 dir = pgd_offset(vma->vm_mm, address);
504 tlb_start_vma(tlb, vma);
506 zap_pmd_range(tlb, dir, address, end - address, details);
507 address = (address + PGDIR_SIZE) & PGDIR_MASK;
509 } while (address && (address < end));
510 tlb_end_vma(tlb, vma);
513 /* Dispose of an entire struct mmu_gather per rescheduling point */
514 #if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT)
515 #define ZAP_BLOCK_SIZE (FREE_PTE_NR * PAGE_SIZE)
518 /* For UP, 256 pages at a time gives nice low latency */
519 #if !defined(CONFIG_SMP) && defined(CONFIG_PREEMPT)
520 #define ZAP_BLOCK_SIZE (256 * PAGE_SIZE)
523 /* No preempt: go for improved straight-line efficiency */
524 #if !defined(CONFIG_PREEMPT)
525 #define ZAP_BLOCK_SIZE (1024 * PAGE_SIZE)
529 * unmap_vmas - unmap a range of memory covered by a list of vma's
530 * @tlbp: address of the caller's struct mmu_gather
531 * @mm: the controlling mm_struct
532 * @vma: the starting vma
533 * @start_addr: virtual address at which to start unmapping
534 * @end_addr: virtual address at which to end unmapping
535 * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
536 * @details: details of nonlinear truncation or shared cache invalidation
538 * Returns the number of vma's which were covered by the unmapping.
540 * Unmap all pages in the vma list. Called under page_table_lock.
542 * We aim to not hold page_table_lock for too long (for scheduling latency
543 * reasons). So zap pages in ZAP_BLOCK_SIZE bytecounts. This means we need to
544 * return the ending mmu_gather to the caller.
546 * Only addresses between `start' and `end' will be unmapped.
548 * The VMA list must be sorted in ascending virtual address order.
550 * unmap_vmas() assumes that the caller will flush the whole unmapped address
551 * range after unmap_vmas() returns. So the only responsibility here is to
552 * ensure that any thus-far unmapped pages are flushed before unmap_vmas()
553 * drops the lock and schedules.
555 int unmap_vmas(struct mmu_gather **tlbp, struct mm_struct *mm,
556 struct vm_area_struct *vma, unsigned long start_addr,
557 unsigned long end_addr, unsigned long *nr_accounted,
558 struct zap_details *details)
560 unsigned long zap_bytes = ZAP_BLOCK_SIZE;
561 unsigned long tlb_start = 0; /* For tlb_finish_mmu */
562 int tlb_start_valid = 0;
565 for ( ; vma && vma->vm_start < end_addr; vma = vma->vm_next) {
569 start = max(vma->vm_start, start_addr);
570 if (start >= vma->vm_end)
572 end = min(vma->vm_end, end_addr);
573 if (end <= vma->vm_start)
576 if (vma->vm_flags & VM_ACCOUNT)
577 *nr_accounted += (end - start) >> PAGE_SHIFT;
580 while (start != end) {
583 if (!tlb_start_valid) {
588 if (is_vm_hugetlb_page(vma)) {
590 unmap_hugepage_range(vma, start, end);
592 block = min(zap_bytes, end - start);
593 unmap_page_range(*tlbp, vma, start,
594 start + block, details);
599 if ((long)zap_bytes > 0)
601 if (need_resched()) {
602 int fullmm = tlb_is_full_mm(*tlbp);
603 tlb_finish_mmu(*tlbp, tlb_start, start);
604 cond_resched_lock(&mm->page_table_lock);
605 *tlbp = tlb_gather_mmu(mm, fullmm);
608 zap_bytes = ZAP_BLOCK_SIZE;
615 * zap_page_range - remove user pages in a given range
616 * @vma: vm_area_struct holding the applicable pages
617 * @address: starting address of pages to zap
618 * @size: number of bytes to zap
619 * @details: details of nonlinear truncation or shared cache invalidation
621 void zap_page_range(struct vm_area_struct *vma, unsigned long address,
622 unsigned long size, struct zap_details *details)
624 struct mm_struct *mm = vma->vm_mm;
625 struct mmu_gather *tlb;
626 unsigned long end = address + size;
627 unsigned long nr_accounted = 0;
631 if (is_vm_hugetlb_page(vma)) {
632 zap_hugepage_range(vma, address, size);
637 spin_lock(&mm->page_table_lock);
638 tlb = tlb_gather_mmu(mm, 0);
639 unmap_vmas(&tlb, mm, vma, address, end, &nr_accounted, details);
640 tlb_finish_mmu(tlb, address, end);
641 spin_unlock(&mm->page_table_lock);
645 * Do a quick page-table lookup for a single page.
646 * mm->page_table_lock must be held.
649 follow_page(struct mm_struct *mm, unsigned long address, int write)
657 page = follow_huge_addr(mm, address, write);
661 pgd = pgd_offset(mm, address);
662 if (pgd_none(*pgd) || pgd_bad(*pgd))
665 pmd = pmd_offset(pgd, address);
669 return follow_huge_pmd(mm, address, pmd, write);
673 ptep = pte_offset_map(pmd, address);
679 if (pte_present(pte)) {
680 if (write && !pte_write(pte))
682 if (write && !pte_dirty(pte)) {
683 struct page *page = pte_page(pte);
684 if (!PageDirty(page))
685 set_page_dirty(page);
688 if (pfn_valid(pfn)) {
689 struct page *page = pfn_to_page(pfn);
691 mark_page_accessed(page);
701 * Given a physical address, is there a useful struct page pointing to
702 * it? This may become more complex in the future if we start dealing
703 * with IO-aperture pages for direct-IO.
706 static inline struct page *get_page_map(struct page *page)
708 if (!pfn_valid(page_to_pfn(page)))
715 untouched_anonymous_page(struct mm_struct* mm, struct vm_area_struct *vma,
716 unsigned long address)
721 /* Check if the vma is for an anonymous mapping. */
722 if (vma->vm_ops && vma->vm_ops->nopage)
725 /* Check if page directory entry exists. */
726 pgd = pgd_offset(mm, address);
727 if (pgd_none(*pgd) || pgd_bad(*pgd))
730 /* Check if page middle directory entry exists. */
731 pmd = pmd_offset(pgd, address);
732 if (pmd_none(*pmd) || pmd_bad(*pmd))
735 /* There is a pte slot for 'address' in 'mm'. */
740 int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
741 unsigned long start, int len, int write, int force,
742 struct page **pages, struct vm_area_struct **vmas)
748 * Require read or write permissions.
749 * If 'force' is set, we only require the "MAY" flags.
751 flags = write ? (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD);
752 flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
756 struct vm_area_struct * vma;
758 vma = find_extend_vma(mm, start);
759 if (!vma && in_gate_area(tsk, start)) {
760 unsigned long pg = start & PAGE_MASK;
761 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
765 if (write) /* user gate pages are read-only */
766 return i ? : -EFAULT;
767 pgd = pgd_offset_k(pg);
769 return i ? : -EFAULT;
770 pmd = pmd_offset(pgd, pg);
772 return i ? : -EFAULT;
773 pte = pte_offset_kernel(pmd, pg);
774 if (!pte || !pte_present(*pte))
775 return i ? : -EFAULT;
777 pages[i] = pte_page(*pte);
788 if (!vma || (pages && (vma->vm_flags & VM_IO))
789 || !(flags & vma->vm_flags))
790 return i ? : -EFAULT;
792 if (is_vm_hugetlb_page(vma)) {
793 i = follow_hugetlb_page(mm, vma, pages, vmas,
797 spin_lock(&mm->page_table_lock);
800 int lookup_write = write;
801 while (!(map = follow_page(mm, start, lookup_write))) {
803 * Shortcut for anonymous pages. We don't want
804 * to force the creation of pages tables for
805 * insanly big anonymously mapped areas that
806 * nobody touched so far. This is important
807 * for doing a core dump for these mappings.
810 untouched_anonymous_page(mm,vma,start)) {
811 map = ZERO_PAGE(start);
814 spin_unlock(&mm->page_table_lock);
815 switch (handle_mm_fault(mm,vma,start,write)) {
822 case VM_FAULT_SIGBUS:
823 return i ? i : -EFAULT;
825 return i ? i : -ENOMEM;
830 * Now that we have performed a write fault
831 * and surely no longer have a shared page we
832 * shouldn't write, we shouldn't ignore an
833 * unwritable page in the page table if
834 * we are forcing write access.
836 lookup_write = write && !force;
837 spin_lock(&mm->page_table_lock);
840 pages[i] = get_page_map(map);
842 spin_unlock(&mm->page_table_lock);
844 page_cache_release(pages[i]);
848 flush_dcache_page(pages[i]);
849 if (!PageReserved(pages[i]))
850 page_cache_get(pages[i]);
857 } while(len && start < vma->vm_end);
858 spin_unlock(&mm->page_table_lock);
864 EXPORT_SYMBOL(get_user_pages);
866 static void zeromap_pte_range(pte_t * pte, unsigned long address,
867 unsigned long size, pgprot_t prot)
871 address &= ~PMD_MASK;
872 end = address + size;
876 pte_t zero_pte = pte_wrprotect(mk_pte(ZERO_PAGE(address), prot));
877 BUG_ON(!pte_none(*pte));
878 set_pte(pte, zero_pte);
879 address += PAGE_SIZE;
881 } while (address && (address < end));
884 static inline int zeromap_pmd_range(struct mm_struct *mm, pmd_t * pmd, unsigned long address,
885 unsigned long size, pgprot_t prot)
887 unsigned long base, end;
889 base = address & PGDIR_MASK;
890 address &= ~PGDIR_MASK;
891 end = address + size;
892 if (end > PGDIR_SIZE)
895 pte_t * pte = pte_alloc_map(mm, pmd, base + address);
898 zeromap_pte_range(pte, base + address, end - address, prot);
900 address = (address + PMD_SIZE) & PMD_MASK;
902 } while (address && (address < end));
906 int zeromap_page_range(struct vm_area_struct *vma, unsigned long address, unsigned long size, pgprot_t prot)
910 unsigned long beg = address;
911 unsigned long end = address + size;
912 struct mm_struct *mm = vma->vm_mm;
914 dir = pgd_offset(mm, address);
915 flush_cache_range(vma, beg, end);
919 spin_lock(&mm->page_table_lock);
921 pmd_t *pmd = pmd_alloc(mm, dir, address);
925 error = zeromap_pmd_range(mm, pmd, address, end - address, prot);
928 address = (address + PGDIR_SIZE) & PGDIR_MASK;
930 } while (address && (address < end));
932 * Why flush? zeromap_pte_range has a BUG_ON for !pte_none()
934 flush_tlb_range(vma, beg, end);
935 spin_unlock(&mm->page_table_lock);
940 * maps a range of physical memory into the requested pages. the old
941 * mappings are removed. any references to nonexistent pages results
942 * in null mappings (currently treated as "copy-on-access")
944 static inline void remap_pte_range(pte_t * pte, unsigned long address, unsigned long size,
945 unsigned long phys_addr, pgprot_t prot)
950 address &= ~PMD_MASK;
951 end = address + size;
954 pfn = phys_addr >> PAGE_SHIFT;
956 BUG_ON(!pte_none(*pte));
957 if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
958 set_pte(pte, pfn_pte(pfn, prot));
959 address += PAGE_SIZE;
962 } while (address && (address < end));
965 static inline int remap_pmd_range(struct mm_struct *mm, pmd_t * pmd, unsigned long address, unsigned long size,
966 unsigned long phys_addr, pgprot_t prot)
968 unsigned long base, end;
970 base = address & PGDIR_MASK;
971 address &= ~PGDIR_MASK;
972 end = address + size;
973 if (end > PGDIR_SIZE)
975 phys_addr -= address;
977 pte_t * pte = pte_alloc_map(mm, pmd, base + address);
980 remap_pte_range(pte, base + address, end - address, address + phys_addr, prot);
982 address = (address + PMD_SIZE) & PMD_MASK;
984 } while (address && (address < end));
988 /* Note: this is only safe if the mm semaphore is held when called. */
989 int remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long phys_addr, unsigned long size, pgprot_t prot)
993 unsigned long beg = from;
994 unsigned long end = from + size;
995 struct mm_struct *mm = vma->vm_mm;
998 dir = pgd_offset(mm, from);
999 flush_cache_range(vma, beg, end);
1003 spin_lock(&mm->page_table_lock);
1005 pmd_t *pmd = pmd_alloc(mm, dir, from);
1009 error = remap_pmd_range(mm, pmd, from, end - from, phys_addr + from, prot);
1012 from = (from + PGDIR_SIZE) & PGDIR_MASK;
1014 } while (from && (from < end));
1016 * Why flush? remap_pte_range has a BUG_ON for !pte_none()
1018 flush_tlb_range(vma, beg, end);
1019 spin_unlock(&mm->page_table_lock);
1023 EXPORT_SYMBOL(remap_page_range);
1026 * Do pte_mkwrite, but only if the vma says VM_WRITE. We do this when
1027 * servicing faults for write access. In the normal case, do always want
1028 * pte_mkwrite. But get_user_pages can cause write faults for mappings
1029 * that do not have writing enabled, when used by access_process_vm.
1031 static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
1033 if (likely(vma->vm_flags & VM_WRITE))
1034 pte = pte_mkwrite(pte);
1039 * We hold the mm semaphore for reading and vma->vm_mm->page_table_lock
1041 static inline void break_cow(struct vm_area_struct * vma, struct page * new_page, unsigned long address,
1046 flush_cache_page(vma, address);
1047 entry = maybe_mkwrite(pte_mkdirty(mk_pte(new_page, vma->vm_page_prot)),
1049 ptep_establish(vma, address, page_table, entry);
1050 update_mmu_cache(vma, address, entry);
1054 * This routine handles present pages, when users try to write
1055 * to a shared page. It is done by copying the page to a new address
1056 * and decrementing the shared-page counter for the old page.
1058 * Goto-purists beware: the only reason for goto's here is that it results
1059 * in better assembly code.. The "default" path will see no jumps at all.
1061 * Note that this routine assumes that the protection checks have been
1062 * done by the caller (the low-level page fault routine in most cases).
1063 * Thus we can safely just mark it writable once we've done any necessary
1066 * We also mark the page dirty at this point even though the page will
1067 * change only once the write actually happens. This avoids a few races,
1068 * and potentially makes it more efficient.
1070 * We hold the mm semaphore and the page_table_lock on entry and exit
1071 * with the page_table_lock released.
1073 static int do_wp_page(struct mm_struct *mm, struct vm_area_struct * vma,
1074 unsigned long address, pte_t *page_table, pmd_t *pmd, pte_t pte)
1076 struct page *old_page, *new_page;
1077 unsigned long pfn = pte_pfn(pte);
1078 struct pte_chain *pte_chain;
1081 if (unlikely(!pfn_valid(pfn))) {
1083 * This should really halt the system so it can be debugged or
1084 * at least the kernel stops what it's doing before it corrupts
1085 * data, but for the moment just pretend this is OOM.
1087 pte_unmap(page_table);
1088 printk(KERN_ERR "do_wp_page: bogus page at address %08lx\n",
1090 spin_unlock(&mm->page_table_lock);
1091 return VM_FAULT_OOM;
1093 old_page = pfn_to_page(pfn);
1095 if (!TestSetPageLocked(old_page)) {
1096 int reuse = can_share_swap_page(old_page);
1097 unlock_page(old_page);
1099 flush_cache_page(vma, address);
1100 entry = maybe_mkwrite(pte_mkyoung(pte_mkdirty(pte)),
1102 ptep_establish(vma, address, page_table, entry);
1103 update_mmu_cache(vma, address, entry);
1104 pte_unmap(page_table);
1105 spin_unlock(&mm->page_table_lock);
1106 return VM_FAULT_MINOR;
1109 pte_unmap(page_table);
1112 * Ok, we need to copy. Oh, well..
1114 page_cache_get(old_page);
1115 spin_unlock(&mm->page_table_lock);
1117 pte_chain = pte_chain_alloc(GFP_KERNEL);
1120 new_page = alloc_page(GFP_HIGHUSER);
1123 copy_cow_page(old_page,new_page,address);
1126 * Re-check the pte - we dropped the lock
1128 spin_lock(&mm->page_table_lock);
1129 page_table = pte_offset_map(pmd, address);
1130 if (pte_same(*page_table, pte)) {
1131 if (PageReserved(old_page))
1133 vx_rsspages_inc(mm);
1134 page_remove_rmap(old_page, page_table);
1135 break_cow(vma, new_page, address, page_table);
1136 pte_chain = page_add_rmap(new_page, page_table, pte_chain);
1137 lru_cache_add_active(new_page);
1139 /* Free the old page.. */
1140 new_page = old_page;
1142 pte_unmap(page_table);
1143 page_cache_release(new_page);
1144 page_cache_release(old_page);
1145 spin_unlock(&mm->page_table_lock);
1146 pte_chain_free(pte_chain);
1147 return VM_FAULT_MINOR;
1150 pte_chain_free(pte_chain);
1152 page_cache_release(old_page);
1153 return VM_FAULT_OOM;
1157 * Helper function for unmap_mapping_range().
1159 static void unmap_mapping_range_list(struct list_head *head,
1160 struct zap_details *details)
1162 struct vm_area_struct *vma;
1163 pgoff_t vba, vea, zba, zea;
1165 list_for_each_entry(vma, head, shared) {
1166 if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
1167 details->nonlinear_vma = vma;
1168 zap_page_range(vma, vma->vm_start,
1169 vma->vm_end - vma->vm_start, details);
1170 details->nonlinear_vma = NULL;
1173 vba = vma->vm_pgoff;
1174 vea = vba + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) - 1;
1175 /* Assume for now that PAGE_CACHE_SHIFT == PAGE_SHIFT */
1176 if (vba > details->last_index || vea < details->first_index)
1177 continue; /* Mapping disjoint from hole. */
1178 zba = details->first_index;
1181 zea = details->last_index;
1185 ((zba - vba) << PAGE_SHIFT) + vma->vm_start,
1186 (zea - zba + 1) << PAGE_SHIFT,
1187 details->check_mapping? details: NULL);
1192 * unmap_mapping_range - unmap the portion of all mmaps
1193 * in the specified address_space corresponding to the specified
1194 * page range in the underlying file.
1195 * @address_space: the address space containing mmaps to be unmapped.
1196 * @holebegin: byte in first page to unmap, relative to the start of
1197 * the underlying file. This will be rounded down to a PAGE_SIZE
1198 * boundary. Note that this is different from vmtruncate(), which
1199 * must keep the partial page. In contrast, we must get rid of
1201 * @holelen: size of prospective hole in bytes. This will be rounded
1202 * up to a PAGE_SIZE boundary. A holelen of zero truncates to the
1204 * @even_cows: 1 when truncating a file, unmap even private COWed pages;
1205 * but 0 when invalidating pagecache, don't throw away private data.
1207 void unmap_mapping_range(struct address_space *mapping,
1208 loff_t const holebegin, loff_t const holelen, int even_cows)
1210 struct zap_details details;
1211 pgoff_t hba = holebegin >> PAGE_SHIFT;
1212 pgoff_t hlen = (holelen + PAGE_SIZE - 1) >> PAGE_SHIFT;
1214 /* Check for overflow. */
1215 if (sizeof(holelen) > sizeof(hlen)) {
1217 (holebegin + holelen + PAGE_SIZE - 1) >> PAGE_SHIFT;
1218 if (holeend & ~(long long)ULONG_MAX)
1219 hlen = ULONG_MAX - hba + 1;
1222 details.check_mapping = even_cows? NULL: mapping;
1223 details.nonlinear_vma = NULL;
1224 details.first_index = hba;
1225 details.last_index = hba + hlen - 1;
1226 if (details.last_index < details.first_index)
1227 details.last_index = ULONG_MAX;
1229 down(&mapping->i_shared_sem);
1230 /* Protect against page fault */
1231 atomic_inc(&mapping->truncate_count);
1232 if (unlikely(!list_empty(&mapping->i_mmap)))
1233 unmap_mapping_range_list(&mapping->i_mmap, &details);
1235 /* Don't waste time to check mapping on fully shared vmas */
1236 details.check_mapping = NULL;
1238 if (unlikely(!list_empty(&mapping->i_mmap_shared)))
1239 unmap_mapping_range_list(&mapping->i_mmap_shared, &details);
1240 up(&mapping->i_shared_sem);
1242 EXPORT_SYMBOL(unmap_mapping_range);
1245 * Handle all mappings that got truncated by a "truncate()"
1248 * NOTE! We have to be ready to update the memory sharing
1249 * between the file and the memory map for a potential last
1250 * incomplete page. Ugly, but necessary.
1252 int vmtruncate(struct inode * inode, loff_t offset)
1254 struct address_space *mapping = inode->i_mapping;
1255 unsigned long limit;
1257 if (inode->i_size < offset)
1259 i_size_write(inode, offset);
1260 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
1261 truncate_inode_pages(mapping, offset);
1265 limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
1266 if (limit != RLIM_INFINITY && offset > limit)
1268 if (offset > inode->i_sb->s_maxbytes)
1270 i_size_write(inode, offset);
1273 if (inode->i_op && inode->i_op->truncate)
1274 inode->i_op->truncate(inode);
1277 send_sig(SIGXFSZ, current, 0);
1282 EXPORT_SYMBOL(vmtruncate);
1285 * Primitive swap readahead code. We simply read an aligned block of
1286 * (1 << page_cluster) entries in the swap area. This method is chosen
1287 * because it doesn't cost us any seek time. We also make sure to queue
1288 * the 'original' request together with the readahead ones...
1290 void swapin_readahead(swp_entry_t entry)
1293 struct page *new_page;
1294 unsigned long offset;
1297 * Get the number of handles we should do readahead io to.
1299 num = valid_swaphandles(entry, &offset);
1300 for (i = 0; i < num; offset++, i++) {
1301 /* Ok, do the async read-ahead now */
1302 new_page = read_swap_cache_async(swp_entry(swp_type(entry),
1306 page_cache_release(new_page);
1308 lru_add_drain(); /* Push any new pages onto the LRU now */
1312 * We hold the mm semaphore and the page_table_lock on entry and
1313 * should release the pagetable lock on exit..
1315 static int do_swap_page(struct mm_struct * mm,
1316 struct vm_area_struct * vma, unsigned long address,
1317 pte_t *page_table, pmd_t *pmd, pte_t orig_pte, int write_access)
1320 swp_entry_t entry = pte_to_swp_entry(orig_pte);
1322 int ret = VM_FAULT_MINOR;
1323 struct pte_chain *pte_chain = NULL;
1325 pte_unmap(page_table);
1326 spin_unlock(&mm->page_table_lock);
1327 page = lookup_swap_cache(entry);
1329 swapin_readahead(entry);
1330 page = read_swap_cache_async(entry);
1333 * Back out if somebody else faulted in this pte while
1334 * we released the page table lock.
1336 spin_lock(&mm->page_table_lock);
1337 page_table = pte_offset_map(pmd, address);
1338 if (pte_same(*page_table, orig_pte))
1341 ret = VM_FAULT_MINOR;
1342 pte_unmap(page_table);
1343 spin_unlock(&mm->page_table_lock);
1347 /* Had to read the page from swap area: Major fault */
1348 ret = VM_FAULT_MAJOR;
1349 inc_page_state(pgmajfault);
1352 if (!vx_rsspages_avail(mm, 1)) {
1356 mark_page_accessed(page);
1357 pte_chain = pte_chain_alloc(GFP_KERNEL);
1365 * Back out if somebody else faulted in this pte while we
1366 * released the page table lock.
1368 spin_lock(&mm->page_table_lock);
1369 page_table = pte_offset_map(pmd, address);
1370 if (!pte_same(*page_table, orig_pte)) {
1371 pte_unmap(page_table);
1372 spin_unlock(&mm->page_table_lock);
1374 page_cache_release(page);
1375 ret = VM_FAULT_MINOR;
1379 /* The page isn't present yet, go ahead with the fault. */
1383 remove_exclusive_swap_page(page);
1386 vx_rsspages_inc(mm);
1387 pte = mk_pte(page, vma->vm_page_prot);
1388 if (write_access && can_share_swap_page(page))
1389 pte = maybe_mkwrite(pte_mkdirty(pte), vma);
1392 flush_icache_page(vma, page);
1393 set_pte(page_table, pte);
1394 pte_chain = page_add_rmap(page, page_table, pte_chain);
1396 /* No need to invalidate - it was non-present before */
1397 update_mmu_cache(vma, address, pte);
1398 pte_unmap(page_table);
1399 spin_unlock(&mm->page_table_lock);
1401 pte_chain_free(pte_chain);
1406 * We are called with the MM semaphore and page_table_lock
1407 * spinlock held to protect against concurrent faults in
1408 * multithreaded programs.
1411 do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
1412 pte_t *page_table, pmd_t *pmd, int write_access,
1416 struct page * page = ZERO_PAGE(addr);
1417 struct pte_chain *pte_chain;
1420 if (!vx_rsspages_avail(mm, 1)) {
1421 spin_unlock(&mm->page_table_lock);
1422 return VM_FAULT_OOM;
1425 pte_chain = pte_chain_alloc(GFP_ATOMIC | __GFP_NOWARN);
1427 pte_unmap(page_table);
1428 spin_unlock(&mm->page_table_lock);
1429 pte_chain = pte_chain_alloc(GFP_KERNEL);
1432 spin_lock(&mm->page_table_lock);
1433 page_table = pte_offset_map(pmd, addr);
1436 /* Read-only mapping of ZERO_PAGE. */
1437 entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
1439 /* ..except if it's a write access */
1441 /* Allocate our own private page. */
1442 pte_unmap(page_table);
1443 spin_unlock(&mm->page_table_lock);
1445 page = alloc_page(GFP_HIGHUSER);
1448 clear_user_highpage(page, addr);
1450 spin_lock(&mm->page_table_lock);
1451 page_table = pte_offset_map(pmd, addr);
1453 if (!pte_none(*page_table)) {
1454 pte_unmap(page_table);
1455 page_cache_release(page);
1456 spin_unlock(&mm->page_table_lock);
1457 ret = VM_FAULT_MINOR;
1461 vx_rsspages_inc(mm);
1462 entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
1463 vma->vm_page_prot)),
1465 lru_cache_add_active(page);
1466 mark_page_accessed(page);
1469 set_pte(page_table, entry);
1470 /* ignores ZERO_PAGE */
1471 pte_chain = page_add_rmap(page, page_table, pte_chain);
1472 pte_unmap(page_table);
1474 /* No need to invalidate - it was non-present before */
1475 update_mmu_cache(vma, addr, entry);
1476 spin_unlock(&mm->page_table_lock);
1477 ret = VM_FAULT_MINOR;
1483 pte_chain_free(pte_chain);
1488 * do_no_page() tries to create a new page mapping. It aggressively
1489 * tries to share with existing pages, but makes a separate copy if
1490 * the "write_access" parameter is true in order to avoid the next
1493 * As this is called only for pages that do not currently exist, we
1494 * do not need to flush old virtual caches or the TLB.
1496 * This is called with the MM semaphore held and the page table
1497 * spinlock held. Exit with the spinlock released.
1500 do_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
1501 unsigned long address, int write_access, pte_t *page_table, pmd_t *pmd)
1503 struct page * new_page;
1504 struct address_space *mapping = NULL;
1506 struct pte_chain *pte_chain;
1508 int ret = VM_FAULT_MINOR;
1510 if (!vma->vm_ops || !vma->vm_ops->nopage)
1511 return do_anonymous_page(mm, vma, page_table,
1512 pmd, write_access, address);
1513 pte_unmap(page_table);
1514 spin_unlock(&mm->page_table_lock);
1517 mapping = vma->vm_file->f_mapping;
1518 sequence = atomic_read(&mapping->truncate_count);
1520 smp_rmb(); /* Prevent CPU from reordering lock-free ->nopage() */
1522 new_page = vma->vm_ops->nopage(vma, address & PAGE_MASK, &ret);
1524 /* no page was available -- either SIGBUS or OOM */
1525 if (new_page == NOPAGE_SIGBUS)
1526 return VM_FAULT_SIGBUS;
1527 if (new_page == NOPAGE_OOM)
1528 return VM_FAULT_OOM;
1529 if (!vx_rsspages_avail(mm, 1))
1530 return VM_FAULT_OOM;
1532 pte_chain = pte_chain_alloc(GFP_KERNEL);
1537 * Should we do an early C-O-W break?
1539 if (write_access && !(vma->vm_flags & VM_SHARED)) {
1540 struct page * page = alloc_page(GFP_HIGHUSER);
1543 copy_user_highpage(page, new_page, address);
1544 page_cache_release(new_page);
1545 lru_cache_add_active(page);
1549 spin_lock(&mm->page_table_lock);
1551 * For a file-backed vma, someone could have truncated or otherwise
1552 * invalidated this page. If unmap_mapping_range got called,
1553 * retry getting the page.
1556 (unlikely(sequence != atomic_read(&mapping->truncate_count)))) {
1557 sequence = atomic_read(&mapping->truncate_count);
1558 spin_unlock(&mm->page_table_lock);
1559 page_cache_release(new_page);
1560 pte_chain_free(pte_chain);
1563 page_table = pte_offset_map(pmd, address);
1566 * This silly early PAGE_DIRTY setting removes a race
1567 * due to the bad i386 page protection. But it's valid
1568 * for other architectures too.
1570 * Note that if write_access is true, we either now have
1571 * an exclusive copy of the page, or this is a shared mapping,
1572 * so we can make it writable and dirty to avoid having to
1573 * handle that later.
1575 /* Only go through if we didn't race with anybody else... */
1576 if (pte_none(*page_table)) {
1577 if (!PageReserved(new_page))
1579 vx_rsspages_inc(mm);
1580 flush_icache_page(vma, new_page);
1581 entry = mk_pte(new_page, vma->vm_page_prot);
1583 entry = maybe_mkwrite(pte_mkdirty(entry), vma);
1584 set_pte(page_table, entry);
1585 pte_chain = page_add_rmap(new_page, page_table, pte_chain);
1586 pte_unmap(page_table);
1588 /* One of our sibling threads was faster, back out. */
1589 pte_unmap(page_table);
1590 page_cache_release(new_page);
1591 spin_unlock(&mm->page_table_lock);
1595 /* no need to invalidate: a not-present page shouldn't be cached */
1596 update_mmu_cache(vma, address, entry);
1597 spin_unlock(&mm->page_table_lock);
1600 page_cache_release(new_page);
1603 pte_chain_free(pte_chain);
1608 * Fault of a previously existing named mapping. Repopulate the pte
1609 * from the encoded file_pte if possible. This enables swappable
1612 static int do_file_page(struct mm_struct * mm, struct vm_area_struct * vma,
1613 unsigned long address, int write_access, pte_t *pte, pmd_t *pmd)
1615 unsigned long pgoff;
1618 BUG_ON(!vma->vm_ops || !vma->vm_ops->nopage);
1620 * Fall back to the linear mapping if the fs does not support
1623 if (!vma->vm_ops || !vma->vm_ops->populate ||
1624 (write_access && !(vma->vm_flags & VM_SHARED))) {
1626 return do_no_page(mm, vma, address, write_access, pte, pmd);
1629 pgoff = pte_to_pgoff(*pte);
1632 spin_unlock(&mm->page_table_lock);
1634 err = vma->vm_ops->populate(vma, address & PAGE_MASK, PAGE_SIZE, vma->vm_page_prot, pgoff, 0);
1636 return VM_FAULT_OOM;
1638 return VM_FAULT_SIGBUS;
1639 return VM_FAULT_MAJOR;
1643 * These routines also need to handle stuff like marking pages dirty
1644 * and/or accessed for architectures that don't do it in hardware (most
1645 * RISC architectures). The early dirtying is also good on the i386.
1647 * There is also a hook called "update_mmu_cache()" that architectures
1648 * with external mmu caches can use to update those (ie the Sparc or
1649 * PowerPC hashed page tables that act as extended TLBs).
1651 * Note the "page_table_lock". It is to protect against kswapd removing
1652 * pages from under us. Note that kswapd only ever _removes_ pages, never
1653 * adds them. As such, once we have noticed that the page is not present,
1654 * we can drop the lock early.
1656 * The adding of pages is protected by the MM semaphore (which we hold),
1657 * so we don't need to worry about a page being suddenly been added into
1660 * We enter with the pagetable spinlock held, we are supposed to
1661 * release it when done.
1663 static inline int handle_pte_fault(struct mm_struct *mm,
1664 struct vm_area_struct * vma, unsigned long address,
1665 int write_access, pte_t *pte, pmd_t *pmd)
1670 if (!pte_present(entry)) {
1672 * If it truly wasn't present, we know that kswapd
1673 * and the PTE updates will not touch it later. So
1676 if (pte_none(entry))
1677 return do_no_page(mm, vma, address, write_access, pte, pmd);
1678 if (pte_file(entry))
1679 return do_file_page(mm, vma, address, write_access, pte, pmd);
1680 return do_swap_page(mm, vma, address, pte, pmd, entry, write_access);
1684 if (!pte_write(entry))
1685 return do_wp_page(mm, vma, address, pte, pmd, entry);
1687 entry = pte_mkdirty(entry);
1689 entry = pte_mkyoung(entry);
1690 ptep_establish(vma, address, pte, entry);
1691 update_mmu_cache(vma, address, entry);
1693 spin_unlock(&mm->page_table_lock);
1694 return VM_FAULT_MINOR;
1698 * By the time we get here, we already hold the mm semaphore
1700 int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct * vma,
1701 unsigned long address, int write_access)
1706 __set_current_state(TASK_RUNNING);
1707 pgd = pgd_offset(mm, address);
1709 inc_page_state(pgfault);
1711 if (is_vm_hugetlb_page(vma))
1712 return VM_FAULT_SIGBUS; /* mapping truncation does this. */
1715 * We need the page table lock to synchronize with kswapd
1716 * and the SMP-safe atomic PTE updates.
1718 spin_lock(&mm->page_table_lock);
1719 pmd = pmd_alloc(mm, pgd, address);
1722 pte_t * pte = pte_alloc_map(mm, pmd, address);
1724 return handle_pte_fault(mm, vma, address, write_access, pte, pmd);
1726 spin_unlock(&mm->page_table_lock);
1727 return VM_FAULT_OOM;
1731 * Allocate page middle directory.
1733 * We've already handled the fast-path in-line, and we own the
1736 * On a two-level page table, this ends up actually being entirely
1739 pmd_t fastcall *__pmd_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
1743 spin_unlock(&mm->page_table_lock);
1744 new = pmd_alloc_one(mm, address);
1745 spin_lock(&mm->page_table_lock);
1750 * Because we dropped the lock, we should re-check the
1751 * entry, as somebody else could have populated it..
1753 if (pgd_present(*pgd)) {
1757 pgd_populate(mm, pgd, new);
1759 return pmd_offset(pgd, address);
1762 int make_pages_present(unsigned long addr, unsigned long end)
1764 int ret, len, write;
1765 struct vm_area_struct * vma;
1767 vma = find_vma(current->mm, addr);
1768 write = (vma->vm_flags & VM_WRITE) != 0;
1771 if (end > vma->vm_end)
1773 len = (end+PAGE_SIZE-1)/PAGE_SIZE-addr/PAGE_SIZE;
1774 ret = get_user_pages(current, current->mm, addr,
1775 len, write, 0, NULL, NULL);
1778 return ret == len ? 0 : -1;
1782 * Map a vmalloc()-space virtual address to the physical page.
1784 struct page * vmalloc_to_page(void * vmalloc_addr)
1786 unsigned long addr = (unsigned long) vmalloc_addr;
1787 struct page *page = NULL;
1788 pgd_t *pgd = pgd_offset_k(addr);
1792 if (!pgd_none(*pgd)) {
1793 pmd = pmd_offset(pgd, addr);
1794 if (!pmd_none(*pmd)) {
1796 ptep = pte_offset_map(pmd, addr);
1798 if (pte_present(pte))
1799 page = pte_page(pte);
1807 EXPORT_SYMBOL(vmalloc_to_page);
1809 #if !defined(CONFIG_ARCH_GATE_AREA)
1811 #if defined(AT_SYSINFO_EHDR)
1812 struct vm_area_struct gate_vma;
1814 static int __init gate_vma_init(void)
1816 gate_vma.vm_mm = NULL;
1817 gate_vma.vm_start = FIXADDR_USER_START;
1818 gate_vma.vm_end = FIXADDR_USER_END;
1819 gate_vma.vm_page_prot = PAGE_READONLY;
1820 gate_vma.vm_flags = 0;
1823 __initcall(gate_vma_init);
1826 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
1828 #ifdef AT_SYSINFO_EHDR
1835 int in_gate_area(struct task_struct *task, unsigned long addr)
1837 #ifdef AT_SYSINFO_EHDR
1838 if ((addr >= FIXADDR_USER_START) && (addr < FIXADDR_USER_END))