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-locking.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>
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
)
105 page
= pmd_page(*dir
);
107 pgtable_remove_rmap(page
);
108 pte_free_tlb(tlb
, page
);
111 static inline void free_one_pgd(struct mmu_gather
*tlb
, pgd_t
* dir
)
123 pmd
= pmd_offset(dir
, 0);
125 for (j
= 0; j
< PTRS_PER_PMD
; j
++)
126 free_one_pmd(tlb
, pmd
+j
);
127 pmd_free_tlb(tlb
, pmd
);
131 * This function clears all user-level page tables of a process - this
132 * is needed by execve(), so that old pages aren't in the way.
134 * Must be called with pagetable lock held.
136 void clear_page_tables(struct mmu_gather
*tlb
, unsigned long first
, int nr
)
138 pgd_t
* page_dir
= tlb
->mm
->pgd
;
142 free_one_pgd(tlb
, page_dir
);
147 pte_t
* pte_alloc_map(struct mm_struct
*mm
, pmd_t
*pmd
, unsigned long address
)
149 if (!pmd_present(*pmd
)) {
152 spin_unlock(&mm
->page_table_lock
);
153 new = pte_alloc_one(mm
, address
);
154 spin_lock(&mm
->page_table_lock
);
159 * Because we dropped the lock, we should re-check the
160 * entry, as somebody else could have populated it..
162 if (pmd_present(*pmd
)) {
166 pgtable_add_rmap(new, mm
, address
);
167 pmd_populate(mm
, pmd
, new);
170 return pte_offset_map(pmd
, address
);
173 pte_t
* pte_alloc_kernel(struct mm_struct
*mm
, pmd_t
*pmd
, unsigned long address
)
175 if (!pmd_present(*pmd
)) {
178 spin_unlock(&mm
->page_table_lock
);
179 new = pte_alloc_one_kernel(mm
, address
);
180 spin_lock(&mm
->page_table_lock
);
185 * Because we dropped the lock, we should re-check the
186 * entry, as somebody else could have populated it..
188 if (pmd_present(*pmd
)) {
189 pte_free_kernel(new);
192 pgtable_add_rmap(virt_to_page(new), mm
, address
);
193 pmd_populate_kernel(mm
, pmd
, new);
196 return pte_offset_kernel(pmd
, address
);
198 #define PTE_TABLE_MASK ((PTRS_PER_PTE-1) * sizeof(pte_t))
199 #define PMD_TABLE_MASK ((PTRS_PER_PMD-1) * sizeof(pmd_t))
202 * copy one vm_area from one task to the other. Assumes the page tables
203 * already present in the new task to be cleared in the whole range
204 * covered by this vma.
206 * 08Jan98 Merged into one routine from several inline routines to reduce
207 * variable count and make things faster. -jj
209 * dst->page_table_lock is held on entry and exit,
210 * but may be dropped within pmd_alloc() and pte_alloc_map().
212 int copy_page_range(struct mm_struct
*dst
, struct mm_struct
*src
,
213 struct vm_area_struct
*vma
)
215 pgd_t
* src_pgd
, * dst_pgd
;
216 unsigned long address
= vma
->vm_start
;
217 unsigned long end
= vma
->vm_end
;
219 struct pte_chain
*pte_chain
= NULL
;
221 if (is_vm_hugetlb_page(vma
))
222 return copy_hugetlb_page_range(dst
, src
, vma
);
224 pte_chain
= pte_chain_alloc(GFP_ATOMIC
);
226 spin_unlock(&dst
->page_table_lock
);
227 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
228 spin_lock(&dst
->page_table_lock
);
233 cow
= (vma
->vm_flags
& (VM_SHARED
| VM_MAYWRITE
)) == VM_MAYWRITE
;
234 src_pgd
= pgd_offset(src
, address
)-1;
235 dst_pgd
= pgd_offset(dst
, address
)-1;
238 pmd_t
* src_pmd
, * dst_pmd
;
240 src_pgd
++; dst_pgd
++;
244 if (pgd_none(*src_pgd
))
245 goto skip_copy_pmd_range
;
246 if (pgd_bad(*src_pgd
)) {
249 skip_copy_pmd_range
: address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
250 if (!address
|| (address
>= end
))
255 src_pmd
= pmd_offset(src_pgd
, address
);
256 dst_pmd
= pmd_alloc(dst
, dst_pgd
, address
);
261 pte_t
* src_pte
, * dst_pte
;
265 if (pmd_none(*src_pmd
))
266 goto skip_copy_pte_range
;
267 if (pmd_bad(*src_pmd
)) {
271 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
274 goto cont_copy_pmd_range
;
277 dst_pte
= pte_alloc_map(dst
, dst_pmd
, address
);
280 spin_lock(&src
->page_table_lock
);
281 src_pte
= pte_offset_map_nested(src_pmd
, address
);
283 pte_t pte
= *src_pte
;
290 goto cont_copy_pte_range_noset
;
291 /* pte contains position in swap, so copy. */
292 if (!pte_present(pte
)) {
294 swap_duplicate(pte_to_swp_entry(pte
));
295 set_pte(dst_pte
, pte
);
296 goto cont_copy_pte_range_noset
;
299 /* the pte points outside of valid memory, the
300 * mapping is assumed to be good, meaningful
301 * and not mapped via rmap - duplicate the
306 page
= pfn_to_page(pfn
);
308 if (!page
|| PageReserved(page
)) {
309 set_pte(dst_pte
, pte
);
310 goto cont_copy_pte_range_noset
;
314 * If it's a COW mapping, write protect it both
315 * in the parent and the child
318 ptep_set_wrprotect(src_pte
);
323 * If it's a shared mapping, mark it clean in
326 if (vma
->vm_flags
& VM_SHARED
)
327 pte
= pte_mkclean(pte
);
328 pte
= pte_mkold(pte
);
332 set_pte(dst_pte
, pte
);
333 pte_chain
= page_add_rmap(page
, dst_pte
,
336 goto cont_copy_pte_range_noset
;
337 pte_chain
= pte_chain_alloc(GFP_ATOMIC
);
339 goto cont_copy_pte_range_noset
;
342 * pte_chain allocation failed, and we need to
345 pte_unmap_nested(src_pte
);
347 spin_unlock(&src
->page_table_lock
);
348 spin_unlock(&dst
->page_table_lock
);
349 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
350 spin_lock(&dst
->page_table_lock
);
353 spin_lock(&src
->page_table_lock
);
354 dst_pte
= pte_offset_map(dst_pmd
, address
);
355 src_pte
= pte_offset_map_nested(src_pmd
,
357 cont_copy_pte_range_noset
:
358 address
+= PAGE_SIZE
;
359 if (address
>= end
) {
360 pte_unmap_nested(src_pte
);
366 } while ((unsigned long)src_pte
& PTE_TABLE_MASK
);
367 pte_unmap_nested(src_pte
-1);
368 pte_unmap(dst_pte
-1);
369 spin_unlock(&src
->page_table_lock
);
374 } while ((unsigned long)src_pmd
& PMD_TABLE_MASK
);
377 spin_unlock(&src
->page_table_lock
);
379 pte_chain_free(pte_chain
);
382 pte_chain_free(pte_chain
);
387 zap_pte_range(struct mmu_gather
*tlb
, pmd_t
* pmd
,
388 unsigned long address
, unsigned long size
)
390 unsigned long offset
;
400 ptep
= pte_offset_map(pmd
, address
);
401 offset
= address
& ~PMD_MASK
;
402 if (offset
+ size
> PMD_SIZE
)
403 size
= PMD_SIZE
- offset
;
405 for (offset
=0; offset
< size
; ptep
++, offset
+= PAGE_SIZE
) {
409 if (pte_present(pte
)) {
410 unsigned long pfn
= pte_pfn(pte
);
412 pte
= ptep_get_and_clear(ptep
);
413 tlb_remove_tlb_entry(tlb
, ptep
, address
+offset
);
414 if (pfn_valid(pfn
)) {
415 struct page
*page
= pfn_to_page(pfn
);
416 if (!PageReserved(page
)) {
418 set_page_dirty(page
);
419 if (page
->mapping
&& pte_young(pte
) &&
420 !PageSwapCache(page
))
421 mark_page_accessed(page
);
423 page_remove_rmap(page
, ptep
);
424 tlb_remove_page(tlb
, page
);
429 free_swap_and_cache(pte_to_swp_entry(pte
));
437 zap_pmd_range(struct mmu_gather
*tlb
, pgd_t
* dir
,
438 unsigned long address
, unsigned long size
)
450 pmd
= pmd_offset(dir
, address
);
451 end
= address
+ size
;
452 if (end
> ((address
+ PGDIR_SIZE
) & PGDIR_MASK
))
453 end
= ((address
+ PGDIR_SIZE
) & PGDIR_MASK
);
455 zap_pte_range(tlb
, pmd
, address
, end
- address
);
456 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
458 } while (address
< end
);
461 void unmap_page_range(struct mmu_gather
*tlb
, struct vm_area_struct
*vma
,
462 unsigned long address
, unsigned long end
)
466 if (is_vm_hugetlb_page(vma
)) {
467 unmap_hugepage_range(vma
, address
, end
);
471 BUG_ON(address
>= end
);
473 dir
= pgd_offset(vma
->vm_mm
, address
);
474 tlb_start_vma(tlb
, vma
);
476 zap_pmd_range(tlb
, dir
, address
, end
- address
);
477 address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
479 } while (address
&& (address
< end
));
480 tlb_end_vma(tlb
, vma
);
483 /* Dispose of an entire struct mmu_gather per rescheduling point */
484 #if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT)
485 #define ZAP_BLOCK_SIZE (FREE_PTE_NR * PAGE_SIZE)
488 /* For UP, 256 pages at a time gives nice low latency */
489 #if !defined(CONFIG_SMP) && defined(CONFIG_PREEMPT)
490 #define ZAP_BLOCK_SIZE (256 * PAGE_SIZE)
493 /* No preempt: go for the best straight-line efficiency */
494 #if !defined(CONFIG_PREEMPT)
495 #define ZAP_BLOCK_SIZE (~(0UL))
499 * unmap_vmas - unmap a range of memory covered by a list of vma's
500 * @tlbp: address of the caller's struct mmu_gather
501 * @mm: the controlling mm_struct
502 * @vma: the starting vma
503 * @start_addr: virtual address at which to start unmapping
504 * @end_addr: virtual address at which to end unmapping
505 * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
507 * Returns the number of vma's which were covered by the unmapping.
509 * Unmap all pages in the vma list. Called under page_table_lock.
511 * We aim to not hold page_table_lock for too long (for scheduling latency
512 * reasons). So zap pages in ZAP_BLOCK_SIZE bytecounts. This means we need to
513 * return the ending mmu_gather to the caller.
515 * Only addresses between `start' and `end' will be unmapped.
517 * The VMA list must be sorted in ascending virtual address order.
519 * unmap_vmas() assumes that the caller will flush the whole unmapped address
520 * range after unmap_vmas() returns. So the only responsibility here is to
521 * ensure that any thus-far unmapped pages are flushed before unmap_vmas()
522 * drops the lock and schedules.
524 int unmap_vmas(struct mmu_gather
**tlbp
, struct mm_struct
*mm
,
525 struct vm_area_struct
*vma
, unsigned long start_addr
,
526 unsigned long end_addr
, unsigned long *nr_accounted
)
528 unsigned long zap_bytes
= ZAP_BLOCK_SIZE
;
529 unsigned long tlb_start
= 0; /* For tlb_finish_mmu */
530 int tlb_start_valid
= 0;
533 if (vma
) { /* debug. killme. */
534 if (end_addr
<= vma
->vm_start
)
535 printk("%s: end_addr(0x%08lx) <= vm_start(0x%08lx)\n",
536 __FUNCTION__
, end_addr
, vma
->vm_start
);
537 if (start_addr
>= vma
->vm_end
)
538 printk("%s: start_addr(0x%08lx) <= vm_end(0x%08lx)\n",
539 __FUNCTION__
, start_addr
, vma
->vm_end
);
542 for ( ; vma
&& vma
->vm_start
< end_addr
; vma
= vma
->vm_next
) {
546 start
= max(vma
->vm_start
, start_addr
);
547 if (start
>= vma
->vm_end
)
549 end
= min(vma
->vm_end
, end_addr
);
550 if (end
<= vma
->vm_start
)
553 if (vma
->vm_flags
& VM_ACCOUNT
)
554 *nr_accounted
+= (end
- start
) >> PAGE_SHIFT
;
557 while (start
!= end
) {
560 if (is_vm_hugetlb_page(vma
))
563 block
= min(zap_bytes
, end
- start
);
565 if (!tlb_start_valid
) {
570 unmap_page_range(*tlbp
, vma
, start
, start
+ block
);
573 if ((long)zap_bytes
> 0)
575 if (need_resched()) {
576 tlb_finish_mmu(*tlbp
, tlb_start
, start
);
577 cond_resched_lock(&mm
->page_table_lock
);
578 *tlbp
= tlb_gather_mmu(mm
, 0);
581 zap_bytes
= ZAP_BLOCK_SIZE
;
583 if (vma
->vm_next
&& vma
->vm_next
->vm_start
< vma
->vm_end
)
584 printk("%s: VMA list is not sorted correctly!\n",
591 * zap_page_range - remove user pages in a given range
592 * @vma: vm_area_struct holding the applicable pages
593 * @address: starting address of pages to zap
594 * @size: number of bytes to zap
596 void zap_page_range(struct vm_area_struct
*vma
,
597 unsigned long address
, unsigned long size
)
599 struct mm_struct
*mm
= vma
->vm_mm
;
600 struct mmu_gather
*tlb
;
601 unsigned long end
= address
+ size
;
602 unsigned long nr_accounted
= 0;
606 if (is_vm_hugetlb_page(vma
)) {
607 zap_hugepage_range(vma
, address
, size
);
612 spin_lock(&mm
->page_table_lock
);
613 tlb
= tlb_gather_mmu(mm
, 0);
614 unmap_vmas(&tlb
, mm
, vma
, address
, end
, &nr_accounted
);
615 tlb_finish_mmu(tlb
, address
, end
);
616 spin_unlock(&mm
->page_table_lock
);
620 * Do a quick page-table lookup for a single page.
621 * mm->page_table_lock must be held.
624 follow_page(struct mm_struct
*mm
, unsigned long address
, int write
)
630 struct vm_area_struct
*vma
;
632 vma
= hugepage_vma(mm
, address
);
634 return follow_huge_addr(mm
, vma
, address
, write
);
636 pgd
= pgd_offset(mm
, address
);
637 if (pgd_none(*pgd
) || pgd_bad(*pgd
))
640 pmd
= pmd_offset(pgd
, address
);
644 return follow_huge_pmd(mm
, address
, pmd
, write
);
648 ptep
= pte_offset_map(pmd
, address
);
654 if (pte_present(pte
)) {
655 if (write
&& !pte_write(pte
))
657 if (write
&& !pte_dirty(pte
)) {
658 struct page
*page
= pte_page(pte
);
659 if (!PageDirty(page
))
660 set_page_dirty(page
);
663 if (pfn_valid(pfn
)) {
664 struct page
*page
= pfn_to_page(pfn
);
666 mark_page_accessed(page
);
676 * Given a physical address, is there a useful struct page pointing to
677 * it? This may become more complex in the future if we start dealing
678 * with IO-aperture pages for direct-IO.
681 static inline struct page
*get_page_map(struct page
*page
)
683 if (!pfn_valid(page_to_pfn(page
)))
689 int get_user_pages(struct task_struct
*tsk
, struct mm_struct
*mm
,
690 unsigned long start
, int len
, int write
, int force
,
691 struct page
**pages
, struct vm_area_struct
**vmas
)
697 * Require read or write permissions.
698 * If 'force' is set, we only require the "MAY" flags.
700 flags
= write
? (VM_WRITE
| VM_MAYWRITE
) : (VM_READ
| VM_MAYREAD
);
701 flags
&= force
? (VM_MAYREAD
| VM_MAYWRITE
) : (VM_READ
| VM_WRITE
);
705 struct vm_area_struct
* vma
;
707 vma
= find_extend_vma(mm
, start
);
708 if (!vma
&& in_gate_area(tsk
, start
)) {
709 unsigned long pg
= start
& PAGE_MASK
;
710 struct vm_area_struct
*gate_vma
= get_gate_vma(tsk
);
714 if (write
) /* user gate pages are read-only */
715 return i
? : -EFAULT
;
716 pgd
= pgd_offset_k(pg
);
718 return i
? : -EFAULT
;
719 pmd
= pmd_offset(pgd
, pg
);
721 return i
? : -EFAULT
;
722 pte
= pte_offset_kernel(pmd
, pg
);
723 if (!pte
|| !pte_present(*pte
))
724 return i
? : -EFAULT
;
726 pages
[i
] = pte_page(*pte
);
737 if (!vma
|| (pages
&& (vma
->vm_flags
& VM_IO
))
738 || !(flags
& vma
->vm_flags
))
739 return i
? : -EFAULT
;
741 if (is_vm_hugetlb_page(vma
)) {
742 i
= follow_hugetlb_page(mm
, vma
, pages
, vmas
,
746 spin_lock(&mm
->page_table_lock
);
749 while (!(map
= follow_page(mm
, start
, write
))) {
750 spin_unlock(&mm
->page_table_lock
);
751 switch (handle_mm_fault(mm
,vma
,start
,write
)) {
758 case VM_FAULT_SIGBUS
:
759 return i
? i
: -EFAULT
;
761 return i
? i
: -ENOMEM
;
765 spin_lock(&mm
->page_table_lock
);
768 pages
[i
] = get_page_map(map
);
770 spin_unlock(&mm
->page_table_lock
);
772 page_cache_release(pages
[i
]);
776 flush_dcache_page(pages
[i
]);
777 if (!PageReserved(pages
[i
]))
778 page_cache_get(pages
[i
]);
785 } while(len
&& start
< vma
->vm_end
);
786 spin_unlock(&mm
->page_table_lock
);
792 EXPORT_SYMBOL(get_user_pages
);
794 static void zeromap_pte_range(pte_t
* pte
, unsigned long address
,
795 unsigned long size
, pgprot_t prot
)
799 address
&= ~PMD_MASK
;
800 end
= address
+ size
;
804 pte_t zero_pte
= pte_wrprotect(mk_pte(ZERO_PAGE(address
), prot
));
805 BUG_ON(!pte_none(*pte
));
806 set_pte(pte
, zero_pte
);
807 address
+= PAGE_SIZE
;
809 } while (address
&& (address
< end
));
812 static inline int zeromap_pmd_range(struct mm_struct
*mm
, pmd_t
* pmd
, unsigned long address
,
813 unsigned long size
, pgprot_t prot
)
815 unsigned long base
, end
;
817 base
= address
& PGDIR_MASK
;
818 address
&= ~PGDIR_MASK
;
819 end
= address
+ size
;
820 if (end
> PGDIR_SIZE
)
823 pte_t
* pte
= pte_alloc_map(mm
, pmd
, base
+ address
);
826 zeromap_pte_range(pte
, base
+ address
, end
- address
, prot
);
828 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
830 } while (address
&& (address
< end
));
834 int zeromap_page_range(struct vm_area_struct
*vma
, unsigned long address
, unsigned long size
, pgprot_t prot
)
838 unsigned long beg
= address
;
839 unsigned long end
= address
+ size
;
840 struct mm_struct
*mm
= vma
->vm_mm
;
842 dir
= pgd_offset(mm
, address
);
843 flush_cache_range(vma
, beg
, end
);
847 spin_lock(&mm
->page_table_lock
);
849 pmd_t
*pmd
= pmd_alloc(mm
, dir
, address
);
853 error
= zeromap_pmd_range(mm
, pmd
, address
, end
- address
, prot
);
856 address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
858 } while (address
&& (address
< end
));
860 * Why flush? zeromap_pte_range has a BUG_ON for !pte_none()
862 flush_tlb_range(vma
, beg
, end
);
863 spin_unlock(&mm
->page_table_lock
);
868 * maps a range of physical memory into the requested pages. the old
869 * mappings are removed. any references to nonexistent pages results
870 * in null mappings (currently treated as "copy-on-access")
872 static inline void remap_pte_range(pte_t
* pte
, unsigned long address
, unsigned long size
,
873 unsigned long phys_addr
, pgprot_t prot
)
878 address
&= ~PMD_MASK
;
879 end
= address
+ size
;
882 pfn
= phys_addr
>> PAGE_SHIFT
;
884 BUG_ON(!pte_none(*pte
));
885 if (!pfn_valid(pfn
) || PageReserved(pfn_to_page(pfn
)))
886 set_pte(pte
, pfn_pte(pfn
, prot
));
887 address
+= PAGE_SIZE
;
890 } while (address
&& (address
< end
));
893 static inline int remap_pmd_range(struct mm_struct
*mm
, pmd_t
* pmd
, unsigned long address
, unsigned long size
,
894 unsigned long phys_addr
, pgprot_t prot
)
896 unsigned long base
, end
;
898 base
= address
& PGDIR_MASK
;
899 address
&= ~PGDIR_MASK
;
900 end
= address
+ size
;
901 if (end
> PGDIR_SIZE
)
903 phys_addr
-= address
;
905 pte_t
* pte
= pte_alloc_map(mm
, pmd
, base
+ address
);
908 remap_pte_range(pte
, base
+ address
, end
- address
, address
+ phys_addr
, prot
);
910 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
912 } while (address
&& (address
< end
));
916 /* Note: this is only safe if the mm semaphore is held when called. */
917 int remap_page_range(struct vm_area_struct
*vma
, unsigned long from
, unsigned long phys_addr
, unsigned long size
, pgprot_t prot
)
921 unsigned long beg
= from
;
922 unsigned long end
= from
+ size
;
923 struct mm_struct
*mm
= vma
->vm_mm
;
926 dir
= pgd_offset(mm
, from
);
927 flush_cache_range(vma
, beg
, end
);
931 spin_lock(&mm
->page_table_lock
);
933 pmd_t
*pmd
= pmd_alloc(mm
, dir
, from
);
937 error
= remap_pmd_range(mm
, pmd
, from
, end
- from
, phys_addr
+ from
, prot
);
940 from
= (from
+ PGDIR_SIZE
) & PGDIR_MASK
;
942 } while (from
&& (from
< end
));
944 * Why flush? remap_pte_range has a BUG_ON for !pte_none()
946 flush_tlb_range(vma
, beg
, end
);
947 spin_unlock(&mm
->page_table_lock
);
951 EXPORT_SYMBOL(remap_page_range
);
954 * We hold the mm semaphore for reading and vma->vm_mm->page_table_lock
956 static inline void break_cow(struct vm_area_struct
* vma
, struct page
* new_page
, unsigned long address
,
961 flush_cache_page(vma
, address
);
962 entry
= pte_mkwrite(pte_mkdirty(mk_pte(new_page
, vma
->vm_page_prot
)));
963 ptep_establish(vma
, address
, page_table
, entry
);
964 update_mmu_cache(vma
, address
, entry
);
968 * This routine handles present pages, when users try to write
969 * to a shared page. It is done by copying the page to a new address
970 * and decrementing the shared-page counter for the old page.
972 * Goto-purists beware: the only reason for goto's here is that it results
973 * in better assembly code.. The "default" path will see no jumps at all.
975 * Note that this routine assumes that the protection checks have been
976 * done by the caller (the low-level page fault routine in most cases).
977 * Thus we can safely just mark it writable once we've done any necessary
980 * We also mark the page dirty at this point even though the page will
981 * change only once the write actually happens. This avoids a few races,
982 * and potentially makes it more efficient.
984 * We hold the mm semaphore and the page_table_lock on entry and exit
985 * with the page_table_lock released.
987 static int do_wp_page(struct mm_struct
*mm
, struct vm_area_struct
* vma
,
988 unsigned long address
, pte_t
*page_table
, pmd_t
*pmd
, pte_t pte
)
990 struct page
*old_page
, *new_page
;
991 unsigned long pfn
= pte_pfn(pte
);
992 struct pte_chain
*pte_chain
;
995 if (unlikely(!pfn_valid(pfn
))) {
997 * This should really halt the system so it can be debugged or
998 * at least the kernel stops what it's doing before it corrupts
999 * data, but for the moment just pretend this is OOM.
1001 pte_unmap(page_table
);
1002 printk(KERN_ERR
"do_wp_page: bogus page at address %08lx\n",
1004 spin_unlock(&mm
->page_table_lock
);
1005 return VM_FAULT_OOM
;
1007 old_page
= pfn_to_page(pfn
);
1009 if (!TestSetPageLocked(old_page
)) {
1010 int reuse
= can_share_swap_page(old_page
);
1011 unlock_page(old_page
);
1013 flush_cache_page(vma
, address
);
1014 entry
= pte_mkyoung(pte_mkdirty(pte_mkwrite(pte
)));
1015 ptep_establish(vma
, address
, page_table
, entry
);
1016 update_mmu_cache(vma
, address
, entry
);
1017 pte_unmap(page_table
);
1018 spin_unlock(&mm
->page_table_lock
);
1019 return VM_FAULT_MINOR
;
1022 pte_unmap(page_table
);
1025 * Ok, we need to copy. Oh, well..
1027 page_cache_get(old_page
);
1028 spin_unlock(&mm
->page_table_lock
);
1030 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
1033 new_page
= alloc_page(GFP_HIGHUSER
);
1036 copy_cow_page(old_page
,new_page
,address
);
1039 * Re-check the pte - we dropped the lock
1041 spin_lock(&mm
->page_table_lock
);
1042 page_table
= pte_offset_map(pmd
, address
);
1043 if (pte_same(*page_table
, pte
)) {
1044 if (PageReserved(old_page
))
1046 page_remove_rmap(old_page
, page_table
);
1047 break_cow(vma
, new_page
, address
, page_table
);
1048 pte_chain
= page_add_rmap(new_page
, page_table
, pte_chain
);
1049 lru_cache_add_active(new_page
);
1051 /* Free the old page.. */
1052 new_page
= old_page
;
1054 pte_unmap(page_table
);
1055 page_cache_release(new_page
);
1056 page_cache_release(old_page
);
1057 spin_unlock(&mm
->page_table_lock
);
1058 pte_chain_free(pte_chain
);
1059 return VM_FAULT_MINOR
;
1062 pte_chain_free(pte_chain
);
1064 page_cache_release(old_page
);
1065 return VM_FAULT_OOM
;
1069 * Helper function for invalidate_mmap_range().
1070 * Both hba and hlen are page numbers in PAGE_SIZE units.
1071 * An hlen of zero blows away the entire portion file after hba.
1074 invalidate_mmap_range_list(struct list_head
*head
,
1075 unsigned long const hba
,
1076 unsigned long const hlen
)
1078 struct list_head
*curr
;
1079 unsigned long hea
; /* last page of hole. */
1081 unsigned long vea
; /* last page of corresponding uva hole. */
1082 struct vm_area_struct
*vp
;
1086 hea
= hba
+ hlen
- 1; /* avoid overflow. */
1089 list_for_each(curr
, head
) {
1090 vp
= list_entry(curr
, struct vm_area_struct
, shared
);
1092 vea
= vba
+ ((vp
->vm_end
- vp
->vm_start
) >> PAGE_SHIFT
) - 1;
1093 if (hea
< vba
|| vea
< hba
)
1094 continue; /* Mapping disjoint from hole. */
1095 zba
= (hba
<= vba
) ? vba
: hba
;
1096 zea
= (vea
<= hea
) ? vea
: hea
;
1098 ((zba
- vba
) << PAGE_SHIFT
) + vp
->vm_start
,
1099 (zea
- zba
+ 1) << PAGE_SHIFT
);
1104 * invalidate_mmap_range - invalidate the portion of all mmaps
1105 * in the specified address_space corresponding to the specified
1106 * page range in the underlying file.
1107 * @address_space: the address space containing mmaps to be invalidated.
1108 * @holebegin: byte in first page to invalidate, relative to the start of
1109 * the underlying file. This will be rounded down to a PAGE_SIZE
1110 * boundary. Note that this is different from vmtruncate(), which
1111 * must keep the partial page. In contrast, we must get rid of
1113 * @holelen: size of prospective hole in bytes. This will be rounded
1114 * up to a PAGE_SIZE boundary. A holelen of zero truncates to the
1117 void invalidate_mmap_range(struct address_space
*mapping
,
1118 loff_t
const holebegin
, loff_t
const holelen
)
1120 unsigned long hba
= holebegin
>> PAGE_SHIFT
;
1121 unsigned long hlen
= (holelen
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
1123 /* Check for overflow. */
1124 if (sizeof(holelen
) > sizeof(hlen
)) {
1126 (holebegin
+ holelen
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
1128 if (holeend
& ~(long long)ULONG_MAX
)
1129 hlen
= ULONG_MAX
- hba
+ 1;
1131 down(&mapping
->i_shared_sem
);
1132 /* Protect against page fault */
1133 atomic_inc(&mapping
->truncate_count
);
1134 if (unlikely(!list_empty(&mapping
->i_mmap
)))
1135 invalidate_mmap_range_list(&mapping
->i_mmap
, hba
, hlen
);
1136 if (unlikely(!list_empty(&mapping
->i_mmap_shared
)))
1137 invalidate_mmap_range_list(&mapping
->i_mmap_shared
, hba
, hlen
);
1138 up(&mapping
->i_shared_sem
);
1140 EXPORT_SYMBOL_GPL(invalidate_mmap_range
);
1143 * Handle all mappings that got truncated by a "truncate()"
1146 * NOTE! We have to be ready to update the memory sharing
1147 * between the file and the memory map for a potential last
1148 * incomplete page. Ugly, but necessary.
1150 int vmtruncate(struct inode
* inode
, loff_t offset
)
1152 struct address_space
*mapping
= inode
->i_mapping
;
1153 unsigned long limit
;
1155 if (inode
->i_size
< offset
)
1157 i_size_write(inode
, offset
);
1158 invalidate_mmap_range(mapping
, offset
+ PAGE_SIZE
- 1, 0);
1159 truncate_inode_pages(mapping
, offset
);
1163 limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
1164 if (limit
!= RLIM_INFINITY
&& offset
> limit
)
1166 if (offset
> inode
->i_sb
->s_maxbytes
)
1168 i_size_write(inode
, offset
);
1171 if (inode
->i_op
&& inode
->i_op
->truncate
)
1172 inode
->i_op
->truncate(inode
);
1175 send_sig(SIGXFSZ
, current
, 0);
1180 EXPORT_SYMBOL(vmtruncate
);
1183 * Primitive swap readahead code. We simply read an aligned block of
1184 * (1 << page_cluster) entries in the swap area. This method is chosen
1185 * because it doesn't cost us any seek time. We also make sure to queue
1186 * the 'original' request together with the readahead ones...
1188 void swapin_readahead(swp_entry_t entry
)
1191 struct page
*new_page
;
1192 unsigned long offset
;
1195 * Get the number of handles we should do readahead io to.
1197 num
= valid_swaphandles(entry
, &offset
);
1198 for (i
= 0; i
< num
; offset
++, i
++) {
1199 /* Ok, do the async read-ahead now */
1200 new_page
= read_swap_cache_async(swp_entry(swp_type(entry
),
1204 page_cache_release(new_page
);
1206 lru_add_drain(); /* Push any new pages onto the LRU now */
1210 * We hold the mm semaphore and the page_table_lock on entry and
1211 * should release the pagetable lock on exit..
1213 static int do_swap_page(struct mm_struct
* mm
,
1214 struct vm_area_struct
* vma
, unsigned long address
,
1215 pte_t
*page_table
, pmd_t
*pmd
, pte_t orig_pte
, int write_access
)
1218 swp_entry_t entry
= pte_to_swp_entry(orig_pte
);
1220 int ret
= VM_FAULT_MINOR
;
1221 struct pte_chain
*pte_chain
= NULL
;
1223 pte_unmap(page_table
);
1224 spin_unlock(&mm
->page_table_lock
);
1225 page
= lookup_swap_cache(entry
);
1227 swapin_readahead(entry
);
1228 page
= read_swap_cache_async(entry
);
1231 * Back out if somebody else faulted in this pte while
1232 * we released the page table lock.
1234 spin_lock(&mm
->page_table_lock
);
1235 page_table
= pte_offset_map(pmd
, address
);
1236 if (pte_same(*page_table
, orig_pte
))
1239 ret
= VM_FAULT_MINOR
;
1240 pte_unmap(page_table
);
1241 spin_unlock(&mm
->page_table_lock
);
1245 /* Had to read the page from swap area: Major fault */
1246 ret
= VM_FAULT_MAJOR
;
1247 inc_page_state(pgmajfault
);
1250 mark_page_accessed(page
);
1251 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
1259 * Back out if somebody else faulted in this pte while we
1260 * released the page table lock.
1262 spin_lock(&mm
->page_table_lock
);
1263 page_table
= pte_offset_map(pmd
, address
);
1264 if (!pte_same(*page_table
, orig_pte
)) {
1265 pte_unmap(page_table
);
1266 spin_unlock(&mm
->page_table_lock
);
1268 page_cache_release(page
);
1269 ret
= VM_FAULT_MINOR
;
1273 /* The page isn't present yet, go ahead with the fault. */
1277 remove_exclusive_swap_page(page
);
1280 pte
= mk_pte(page
, vma
->vm_page_prot
);
1281 if (write_access
&& can_share_swap_page(page
))
1282 pte
= pte_mkdirty(pte_mkwrite(pte
));
1285 flush_icache_page(vma
, page
);
1286 set_pte(page_table
, pte
);
1287 pte_chain
= page_add_rmap(page
, page_table
, pte_chain
);
1289 /* No need to invalidate - it was non-present before */
1290 update_mmu_cache(vma
, address
, pte
);
1291 pte_unmap(page_table
);
1292 spin_unlock(&mm
->page_table_lock
);
1294 pte_chain_free(pte_chain
);
1299 * We are called with the MM semaphore and page_table_lock
1300 * spinlock held to protect against concurrent faults in
1301 * multithreaded programs.
1304 do_anonymous_page(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
1305 pte_t
*page_table
, pmd_t
*pmd
, int write_access
,
1309 struct page
* page
= ZERO_PAGE(addr
);
1310 struct pte_chain
*pte_chain
;
1313 pte_chain
= pte_chain_alloc(GFP_ATOMIC
);
1315 pte_unmap(page_table
);
1316 spin_unlock(&mm
->page_table_lock
);
1317 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
1320 spin_lock(&mm
->page_table_lock
);
1321 page_table
= pte_offset_map(pmd
, addr
);
1324 /* Read-only mapping of ZERO_PAGE. */
1325 entry
= pte_wrprotect(mk_pte(ZERO_PAGE(addr
), vma
->vm_page_prot
));
1327 /* ..except if it's a write access */
1329 /* Allocate our own private page. */
1330 pte_unmap(page_table
);
1331 spin_unlock(&mm
->page_table_lock
);
1333 page
= alloc_page(GFP_HIGHUSER
);
1336 clear_user_highpage(page
, addr
);
1338 spin_lock(&mm
->page_table_lock
);
1339 page_table
= pte_offset_map(pmd
, addr
);
1341 if (!pte_none(*page_table
)) {
1342 pte_unmap(page_table
);
1343 page_cache_release(page
);
1344 spin_unlock(&mm
->page_table_lock
);
1345 ret
= VM_FAULT_MINOR
;
1349 entry
= pte_mkwrite(pte_mkdirty(mk_pte(page
, vma
->vm_page_prot
)));
1350 lru_cache_add_active(page
);
1351 mark_page_accessed(page
);
1354 set_pte(page_table
, entry
);
1355 /* ignores ZERO_PAGE */
1356 pte_chain
= page_add_rmap(page
, page_table
, pte_chain
);
1357 pte_unmap(page_table
);
1359 /* No need to invalidate - it was non-present before */
1360 update_mmu_cache(vma
, addr
, entry
);
1361 spin_unlock(&mm
->page_table_lock
);
1362 ret
= VM_FAULT_MINOR
;
1368 pte_chain_free(pte_chain
);
1373 * do_no_page() tries to create a new page mapping. It aggressively
1374 * tries to share with existing pages, but makes a separate copy if
1375 * the "write_access" parameter is true in order to avoid the next
1378 * As this is called only for pages that do not currently exist, we
1379 * do not need to flush old virtual caches or the TLB.
1381 * This is called with the MM semaphore held and the page table
1382 * spinlock held. Exit with the spinlock released.
1385 do_no_page(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
1386 unsigned long address
, int write_access
, pte_t
*page_table
, pmd_t
*pmd
)
1388 struct page
* new_page
;
1389 struct address_space
*mapping
= NULL
;
1391 struct pte_chain
*pte_chain
;
1393 int ret
= VM_FAULT_MINOR
;
1395 if (!vma
->vm_ops
|| !vma
->vm_ops
->nopage
)
1396 return do_anonymous_page(mm
, vma
, page_table
,
1397 pmd
, write_access
, address
);
1398 pte_unmap(page_table
);
1399 spin_unlock(&mm
->page_table_lock
);
1402 mapping
= vma
->vm_file
->f_mapping
;
1403 sequence
= atomic_read(&mapping
->truncate_count
);
1405 smp_rmb(); /* Prevent CPU from reordering lock-free ->nopage() */
1407 new_page
= vma
->vm_ops
->nopage(vma
, address
& PAGE_MASK
, &ret
);
1409 /* no page was available -- either SIGBUS or OOM */
1410 if (new_page
== NOPAGE_SIGBUS
)
1411 return VM_FAULT_SIGBUS
;
1412 if (new_page
== NOPAGE_OOM
)
1413 return VM_FAULT_OOM
;
1415 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
1420 * Should we do an early C-O-W break?
1422 if (write_access
&& !(vma
->vm_flags
& VM_SHARED
)) {
1423 struct page
* page
= alloc_page(GFP_HIGHUSER
);
1426 copy_user_highpage(page
, new_page
, address
);
1427 page_cache_release(new_page
);
1428 lru_cache_add_active(page
);
1432 spin_lock(&mm
->page_table_lock
);
1434 * For a file-backed vma, someone could have truncated or otherwise
1435 * invalidated this page. If invalidate_mmap_range got called,
1436 * retry getting the page.
1439 (unlikely(sequence
!= atomic_read(&mapping
->truncate_count
)))) {
1440 sequence
= atomic_read(&mapping
->truncate_count
);
1441 spin_unlock(&mm
->page_table_lock
);
1442 page_cache_release(new_page
);
1443 pte_chain_free(pte_chain
);
1446 page_table
= pte_offset_map(pmd
, address
);
1449 * This silly early PAGE_DIRTY setting removes a race
1450 * due to the bad i386 page protection. But it's valid
1451 * for other architectures too.
1453 * Note that if write_access is true, we either now have
1454 * an exclusive copy of the page, or this is a shared mapping,
1455 * so we can make it writable and dirty to avoid having to
1456 * handle that later.
1458 /* Only go through if we didn't race with anybody else... */
1459 if (pte_none(*page_table
)) {
1460 if (!PageReserved(new_page
))
1462 flush_icache_page(vma
, new_page
);
1463 entry
= mk_pte(new_page
, vma
->vm_page_prot
);
1465 entry
= pte_mkwrite(pte_mkdirty(entry
));
1466 set_pte(page_table
, entry
);
1467 pte_chain
= page_add_rmap(new_page
, page_table
, pte_chain
);
1468 pte_unmap(page_table
);
1470 /* One of our sibling threads was faster, back out. */
1471 pte_unmap(page_table
);
1472 page_cache_release(new_page
);
1473 spin_unlock(&mm
->page_table_lock
);
1477 /* no need to invalidate: a not-present page shouldn't be cached */
1478 update_mmu_cache(vma
, address
, entry
);
1479 spin_unlock(&mm
->page_table_lock
);
1482 page_cache_release(new_page
);
1485 pte_chain_free(pte_chain
);
1490 * Fault of a previously existing named mapping. Repopulate the pte
1491 * from the encoded file_pte if possible. This enables swappable
1494 static int do_file_page(struct mm_struct
* mm
, struct vm_area_struct
* vma
,
1495 unsigned long address
, int write_access
, pte_t
*pte
, pmd_t
*pmd
)
1497 unsigned long pgoff
;
1500 BUG_ON(!vma
->vm_ops
|| !vma
->vm_ops
->nopage
);
1502 * Fall back to the linear mapping if the fs does not support
1505 if (!vma
->vm_ops
|| !vma
->vm_ops
->populate
||
1506 (write_access
&& !(vma
->vm_flags
& VM_SHARED
))) {
1508 return do_no_page(mm
, vma
, address
, write_access
, pte
, pmd
);
1511 pgoff
= pte_to_pgoff(*pte
);
1514 spin_unlock(&mm
->page_table_lock
);
1516 err
= vma
->vm_ops
->populate(vma
, address
& PAGE_MASK
, PAGE_SIZE
, vma
->vm_page_prot
, pgoff
, 0);
1518 return VM_FAULT_OOM
;
1520 return VM_FAULT_SIGBUS
;
1521 return VM_FAULT_MAJOR
;
1525 * These routines also need to handle stuff like marking pages dirty
1526 * and/or accessed for architectures that don't do it in hardware (most
1527 * RISC architectures). The early dirtying is also good on the i386.
1529 * There is also a hook called "update_mmu_cache()" that architectures
1530 * with external mmu caches can use to update those (ie the Sparc or
1531 * PowerPC hashed page tables that act as extended TLBs).
1533 * Note the "page_table_lock". It is to protect against kswapd removing
1534 * pages from under us. Note that kswapd only ever _removes_ pages, never
1535 * adds them. As such, once we have noticed that the page is not present,
1536 * we can drop the lock early.
1538 * The adding of pages is protected by the MM semaphore (which we hold),
1539 * so we don't need to worry about a page being suddenly been added into
1542 * We enter with the pagetable spinlock held, we are supposed to
1543 * release it when done.
1545 static inline int handle_pte_fault(struct mm_struct
*mm
,
1546 struct vm_area_struct
* vma
, unsigned long address
,
1547 int write_access
, pte_t
*pte
, pmd_t
*pmd
)
1552 if (!pte_present(entry
)) {
1554 * If it truly wasn't present, we know that kswapd
1555 * and the PTE updates will not touch it later. So
1558 if (pte_none(entry
))
1559 return do_no_page(mm
, vma
, address
, write_access
, pte
, pmd
);
1560 if (pte_file(entry
))
1561 return do_file_page(mm
, vma
, address
, write_access
, pte
, pmd
);
1562 return do_swap_page(mm
, vma
, address
, pte
, pmd
, entry
, write_access
);
1566 if (!pte_write(entry
))
1567 return do_wp_page(mm
, vma
, address
, pte
, pmd
, entry
);
1569 entry
= pte_mkdirty(entry
);
1571 entry
= pte_mkyoung(entry
);
1572 ptep_establish(vma
, address
, pte
, entry
);
1573 update_mmu_cache(vma
, address
, entry
);
1575 spin_unlock(&mm
->page_table_lock
);
1576 return VM_FAULT_MINOR
;
1580 * By the time we get here, we already hold the mm semaphore
1582 int handle_mm_fault(struct mm_struct
*mm
, struct vm_area_struct
* vma
,
1583 unsigned long address
, int write_access
)
1588 __set_current_state(TASK_RUNNING
);
1589 pgd
= pgd_offset(mm
, address
);
1591 inc_page_state(pgfault
);
1593 if (is_vm_hugetlb_page(vma
))
1594 return VM_FAULT_SIGBUS
; /* mapping truncation does this. */
1597 * We need the page table lock to synchronize with kswapd
1598 * and the SMP-safe atomic PTE updates.
1600 spin_lock(&mm
->page_table_lock
);
1601 pmd
= pmd_alloc(mm
, pgd
, address
);
1604 pte_t
* pte
= pte_alloc_map(mm
, pmd
, address
);
1606 return handle_pte_fault(mm
, vma
, address
, write_access
, pte
, pmd
);
1608 spin_unlock(&mm
->page_table_lock
);
1609 return VM_FAULT_OOM
;
1613 * Allocate page middle directory.
1615 * We've already handled the fast-path in-line, and we own the
1618 * On a two-level page table, this ends up actually being entirely
1621 pmd_t
*__pmd_alloc(struct mm_struct
*mm
, pgd_t
*pgd
, unsigned long address
)
1625 spin_unlock(&mm
->page_table_lock
);
1626 new = pmd_alloc_one(mm
, address
);
1627 spin_lock(&mm
->page_table_lock
);
1632 * Because we dropped the lock, we should re-check the
1633 * entry, as somebody else could have populated it..
1635 if (pgd_present(*pgd
)) {
1639 pgd_populate(mm
, pgd
, new);
1641 return pmd_offset(pgd
, address
);
1644 int make_pages_present(unsigned long addr
, unsigned long end
)
1646 int ret
, len
, write
;
1647 struct vm_area_struct
* vma
;
1649 vma
= find_vma(current
->mm
, addr
);
1650 write
= (vma
->vm_flags
& VM_WRITE
) != 0;
1653 if (end
> vma
->vm_end
)
1655 len
= (end
+PAGE_SIZE
-1)/PAGE_SIZE
-addr
/PAGE_SIZE
;
1656 ret
= get_user_pages(current
, current
->mm
, addr
,
1657 len
, write
, 0, NULL
, NULL
);
1660 return ret
== len
? 0 : -1;
1664 * Map a vmalloc()-space virtual address to the physical page.
1666 struct page
* vmalloc_to_page(void * vmalloc_addr
)
1668 unsigned long addr
= (unsigned long) vmalloc_addr
;
1669 struct page
*page
= NULL
;
1670 pgd_t
*pgd
= pgd_offset_k(addr
);
1674 if (!pgd_none(*pgd
)) {
1675 pmd
= pmd_offset(pgd
, addr
);
1676 if (!pmd_none(*pmd
)) {
1678 ptep
= pte_offset_map(pmd
, addr
);
1680 if (pte_present(pte
))
1681 page
= pte_page(pte
);
1689 EXPORT_SYMBOL(vmalloc_to_page
);
1691 #if !defined(CONFIG_ARCH_GATE_AREA) && defined(AT_SYSINFO_EHDR)
1692 struct vm_area_struct gate_vma
;
1694 static int __init
gate_vma_init(void)
1696 gate_vma
.vm_mm
= NULL
;
1697 gate_vma
.vm_start
= FIXADDR_USER_START
;
1698 gate_vma
.vm_end
= FIXADDR_USER_END
;
1699 gate_vma
.vm_page_prot
= PAGE_READONLY
;
1700 gate_vma
.vm_flags
= 0;
1703 __initcall(gate_vma_init
);