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>
49 #include <asm/pgalloc.h>
51 #include <asm/uaccess.h>
53 #include <asm/tlbflush.h>
54 #include <asm/pgtable.h>
56 #include <linux/swapops.h>
58 #ifndef CONFIG_DISCONTIGMEM
59 /* use the per-pgdat data instead for discontigmem - mbligh */
60 unsigned long max_mapnr
;
64 unsigned long num_physpages
;
66 struct page
*highmem_start_page
;
69 * We special-case the C-O-W ZERO_PAGE, because it's such
70 * a common occurrence (no need to read the page to know
71 * that it's zero - better for the cache and memory subsystem).
73 static inline void copy_cow_page(struct page
* from
, struct page
* to
, unsigned long address
)
75 if (from
== ZERO_PAGE(address
)) {
76 clear_user_highpage(to
, address
);
79 copy_user_highpage(to
, from
, address
);
83 * Note: this doesn't free the actual pages themselves. That
84 * has been handled earlier when unmapping all the memory regions.
86 static inline void free_one_pmd(struct mmu_gather
*tlb
, pmd_t
* dir
)
97 page
= pmd_page(*dir
);
99 pgtable_remove_rmap(page
);
100 pte_free_tlb(tlb
, page
);
103 static inline void free_one_pgd(struct mmu_gather
*tlb
, pgd_t
* dir
)
115 pmd
= pmd_offset(dir
, 0);
117 for (j
= 0; j
< PTRS_PER_PMD
; j
++)
118 free_one_pmd(tlb
, pmd
+j
);
119 pmd_free_tlb(tlb
, pmd
);
123 * This function clears all user-level page tables of a process - this
124 * is needed by execve(), so that old pages aren't in the way.
126 * Must be called with pagetable lock held.
128 void clear_page_tables(struct mmu_gather
*tlb
, unsigned long first
, int nr
)
130 pgd_t
* page_dir
= tlb
->mm
->pgd
;
134 free_one_pgd(tlb
, page_dir
);
139 pte_t
* pte_alloc_map(struct mm_struct
*mm
, pmd_t
*pmd
, unsigned long address
)
141 if (!pmd_present(*pmd
)) {
144 spin_unlock(&mm
->page_table_lock
);
145 new = pte_alloc_one(mm
, address
);
146 spin_lock(&mm
->page_table_lock
);
151 * Because we dropped the lock, we should re-check the
152 * entry, as somebody else could have populated it..
154 if (pmd_present(*pmd
)) {
158 pgtable_add_rmap(new, mm
, address
);
159 pmd_populate(mm
, pmd
, new);
162 return pte_offset_map(pmd
, address
);
165 pte_t
* pte_alloc_kernel(struct mm_struct
*mm
, pmd_t
*pmd
, unsigned long address
)
167 if (!pmd_present(*pmd
)) {
170 spin_unlock(&mm
->page_table_lock
);
171 new = pte_alloc_one_kernel(mm
, address
);
172 spin_lock(&mm
->page_table_lock
);
177 * Because we dropped the lock, we should re-check the
178 * entry, as somebody else could have populated it..
180 if (pmd_present(*pmd
)) {
181 pte_free_kernel(new);
184 pgtable_add_rmap(virt_to_page(new), mm
, address
);
185 pmd_populate_kernel(mm
, pmd
, new);
188 return pte_offset_kernel(pmd
, address
);
190 #define PTE_TABLE_MASK ((PTRS_PER_PTE-1) * sizeof(pte_t))
191 #define PMD_TABLE_MASK ((PTRS_PER_PMD-1) * sizeof(pmd_t))
194 * copy one vm_area from one task to the other. Assumes the page tables
195 * already present in the new task to be cleared in the whole range
196 * covered by this vma.
198 * 08Jan98 Merged into one routine from several inline routines to reduce
199 * variable count and make things faster. -jj
201 * dst->page_table_lock is held on entry and exit,
202 * but may be dropped within pmd_alloc() and pte_alloc_map().
204 int copy_page_range(struct mm_struct
*dst
, struct mm_struct
*src
,
205 struct vm_area_struct
*vma
)
207 pgd_t
* src_pgd
, * dst_pgd
;
208 unsigned long address
= vma
->vm_start
;
209 unsigned long end
= vma
->vm_end
;
211 struct pte_chain
*pte_chain
= NULL
;
213 if (is_vm_hugetlb_page(vma
))
214 return copy_hugetlb_page_range(dst
, src
, vma
);
216 pte_chain
= pte_chain_alloc(GFP_ATOMIC
);
218 spin_unlock(&dst
->page_table_lock
);
219 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
220 spin_lock(&dst
->page_table_lock
);
225 cow
= (vma
->vm_flags
& (VM_SHARED
| VM_MAYWRITE
)) == VM_MAYWRITE
;
226 src_pgd
= pgd_offset(src
, address
)-1;
227 dst_pgd
= pgd_offset(dst
, address
)-1;
230 pmd_t
* src_pmd
, * dst_pmd
;
232 src_pgd
++; dst_pgd
++;
236 if (pgd_none(*src_pgd
))
237 goto skip_copy_pmd_range
;
238 if (pgd_bad(*src_pgd
)) {
241 skip_copy_pmd_range
: address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
242 if (!address
|| (address
>= end
))
247 src_pmd
= pmd_offset(src_pgd
, address
);
248 dst_pmd
= pmd_alloc(dst
, dst_pgd
, address
);
253 pte_t
* src_pte
, * dst_pte
;
257 if (pmd_none(*src_pmd
))
258 goto skip_copy_pte_range
;
259 if (pmd_bad(*src_pmd
)) {
263 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
266 goto cont_copy_pmd_range
;
269 dst_pte
= pte_alloc_map(dst
, dst_pmd
, address
);
272 spin_lock(&src
->page_table_lock
);
273 src_pte
= pte_offset_map_nested(src_pmd
, address
);
275 pte_t pte
= *src_pte
;
282 goto cont_copy_pte_range_noset
;
283 /* pte contains position in swap, so copy. */
284 if (!pte_present(pte
)) {
286 swap_duplicate(pte_to_swp_entry(pte
));
287 set_pte(dst_pte
, pte
);
288 goto cont_copy_pte_range_noset
;
291 /* the pte points outside of valid memory, the
292 * mapping is assumed to be good, meaningful
293 * and not mapped via rmap - duplicate the
298 page
= pfn_to_page(pfn
);
300 if (!page
|| PageReserved(page
)) {
301 set_pte(dst_pte
, pte
);
302 goto cont_copy_pte_range_noset
;
306 * If it's a COW mapping, write protect it both
307 * in the parent and the child
310 ptep_set_wrprotect(src_pte
);
315 * If it's a shared mapping, mark it clean in
318 if (vma
->vm_flags
& VM_SHARED
)
319 pte
= pte_mkclean(pte
);
320 pte
= pte_mkold(pte
);
324 set_pte(dst_pte
, pte
);
325 pte_chain
= page_add_rmap(page
, dst_pte
,
328 goto cont_copy_pte_range_noset
;
329 pte_chain
= pte_chain_alloc(GFP_ATOMIC
);
331 goto cont_copy_pte_range_noset
;
334 * pte_chain allocation failed, and we need to
337 pte_unmap_nested(src_pte
);
339 spin_unlock(&src
->page_table_lock
);
340 spin_unlock(&dst
->page_table_lock
);
341 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
342 spin_lock(&dst
->page_table_lock
);
345 spin_lock(&src
->page_table_lock
);
346 dst_pte
= pte_offset_map(dst_pmd
, address
);
347 src_pte
= pte_offset_map_nested(src_pmd
,
349 cont_copy_pte_range_noset
:
350 address
+= PAGE_SIZE
;
351 if (address
>= end
) {
352 pte_unmap_nested(src_pte
);
358 } while ((unsigned long)src_pte
& PTE_TABLE_MASK
);
359 pte_unmap_nested(src_pte
-1);
360 pte_unmap(dst_pte
-1);
361 spin_unlock(&src
->page_table_lock
);
366 } while ((unsigned long)src_pmd
& PMD_TABLE_MASK
);
369 spin_unlock(&src
->page_table_lock
);
371 pte_chain_free(pte_chain
);
374 pte_chain_free(pte_chain
);
379 zap_pte_range(struct mmu_gather
*tlb
, pmd_t
* pmd
,
380 unsigned long address
, unsigned long size
)
382 unsigned long offset
;
392 ptep
= pte_offset_map(pmd
, address
);
393 offset
= address
& ~PMD_MASK
;
394 if (offset
+ size
> PMD_SIZE
)
395 size
= PMD_SIZE
- offset
;
397 for (offset
=0; offset
< size
; ptep
++, offset
+= PAGE_SIZE
) {
401 if (pte_present(pte
)) {
402 unsigned long pfn
= pte_pfn(pte
);
404 pte
= ptep_get_and_clear(ptep
);
405 tlb_remove_tlb_entry(tlb
, ptep
, address
+offset
);
406 if (pfn_valid(pfn
)) {
407 struct page
*page
= pfn_to_page(pfn
);
408 if (!PageReserved(page
)) {
410 set_page_dirty(page
);
411 if (page
->mapping
&& pte_young(pte
) &&
412 !PageSwapCache(page
))
413 mark_page_accessed(page
);
415 page_remove_rmap(page
, ptep
);
416 tlb_remove_page(tlb
, page
);
421 free_swap_and_cache(pte_to_swp_entry(pte
));
429 zap_pmd_range(struct mmu_gather
*tlb
, pgd_t
* dir
,
430 unsigned long address
, unsigned long size
)
442 pmd
= pmd_offset(dir
, address
);
443 end
= address
+ size
;
444 if (end
> ((address
+ PGDIR_SIZE
) & PGDIR_MASK
))
445 end
= ((address
+ PGDIR_SIZE
) & PGDIR_MASK
);
447 zap_pte_range(tlb
, pmd
, address
, end
- address
);
448 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
450 } while (address
< end
);
453 void unmap_page_range(struct mmu_gather
*tlb
, struct vm_area_struct
*vma
,
454 unsigned long address
, unsigned long end
)
458 if (is_vm_hugetlb_page(vma
)) {
459 unmap_hugepage_range(vma
, address
, end
);
463 BUG_ON(address
>= end
);
465 dir
= pgd_offset(vma
->vm_mm
, address
);
466 tlb_start_vma(tlb
, vma
);
468 zap_pmd_range(tlb
, dir
, address
, end
- address
);
469 address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
471 } while (address
&& (address
< end
));
472 tlb_end_vma(tlb
, vma
);
475 /* Dispose of an entire struct mmu_gather per rescheduling point */
476 #if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT)
477 #define ZAP_BLOCK_SIZE (FREE_PTE_NR * PAGE_SIZE)
480 /* For UP, 256 pages at a time gives nice low latency */
481 #if !defined(CONFIG_SMP) && defined(CONFIG_PREEMPT)
482 #define ZAP_BLOCK_SIZE (256 * PAGE_SIZE)
485 /* No preempt: go for the best straight-line efficiency */
486 #if !defined(CONFIG_PREEMPT)
487 #define ZAP_BLOCK_SIZE (~(0UL))
491 * unmap_vmas - unmap a range of memory covered by a list of vma's
492 * @tlbp: address of the caller's struct mmu_gather
493 * @mm: the controlling mm_struct
494 * @vma: the starting vma
495 * @start_addr: virtual address at which to start unmapping
496 * @end_addr: virtual address at which to end unmapping
497 * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
499 * Returns the number of vma's which were covered by the unmapping.
501 * Unmap all pages in the vma list. Called under page_table_lock.
503 * We aim to not hold page_table_lock for too long (for scheduling latency
504 * reasons). So zap pages in ZAP_BLOCK_SIZE bytecounts. This means we need to
505 * return the ending mmu_gather to the caller.
507 * Only addresses between `start' and `end' will be unmapped.
509 * The VMA list must be sorted in ascending virtual address order.
511 * unmap_vmas() assumes that the caller will flush the whole unmapped address
512 * range after unmap_vmas() returns. So the only responsibility here is to
513 * ensure that any thus-far unmapped pages are flushed before unmap_vmas()
514 * drops the lock and schedules.
516 int unmap_vmas(struct mmu_gather
**tlbp
, struct mm_struct
*mm
,
517 struct vm_area_struct
*vma
, unsigned long start_addr
,
518 unsigned long end_addr
, unsigned long *nr_accounted
)
520 unsigned long zap_bytes
= ZAP_BLOCK_SIZE
;
521 unsigned long tlb_start
; /* For tlb_finish_mmu */
522 int tlb_start_valid
= 0;
525 if (vma
) { /* debug. killme. */
526 if (end_addr
<= vma
->vm_start
)
527 printk("%s: end_addr(0x%08lx) <= vm_start(0x%08lx)\n",
528 __FUNCTION__
, end_addr
, vma
->vm_start
);
529 if (start_addr
>= vma
->vm_end
)
530 printk("%s: start_addr(0x%08lx) <= vm_end(0x%08lx)\n",
531 __FUNCTION__
, start_addr
, vma
->vm_end
);
534 for ( ; vma
&& vma
->vm_start
< end_addr
; vma
= vma
->vm_next
) {
538 start
= max(vma
->vm_start
, start_addr
);
539 if (start
>= vma
->vm_end
)
541 end
= min(vma
->vm_end
, end_addr
);
542 if (end
<= vma
->vm_start
)
545 if (vma
->vm_flags
& VM_ACCOUNT
)
546 *nr_accounted
+= (end
- start
) >> PAGE_SHIFT
;
549 while (start
!= end
) {
552 if (is_vm_hugetlb_page(vma
))
555 block
= min(zap_bytes
, end
- start
);
557 if (!tlb_start_valid
) {
562 unmap_page_range(*tlbp
, vma
, start
, start
+ block
);
565 if ((long)zap_bytes
> 0)
567 if (need_resched()) {
568 tlb_finish_mmu(*tlbp
, tlb_start
, start
);
569 cond_resched_lock(&mm
->page_table_lock
);
570 *tlbp
= tlb_gather_mmu(mm
, 0);
573 zap_bytes
= ZAP_BLOCK_SIZE
;
575 if (vma
->vm_next
&& vma
->vm_next
->vm_start
< vma
->vm_end
)
576 printk("%s: VMA list is not sorted correctly!\n",
583 * zap_page_range - remove user pages in a given range
584 * @vma: vm_area_struct holding the applicable pages
585 * @address: starting address of pages to zap
586 * @size: number of bytes to zap
588 void zap_page_range(struct vm_area_struct
*vma
,
589 unsigned long address
, unsigned long size
)
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;
598 if (is_vm_hugetlb_page(vma
)) {
599 zap_hugepage_range(vma
, address
, size
);
604 spin_lock(&mm
->page_table_lock
);
605 tlb
= tlb_gather_mmu(mm
, 0);
606 unmap_vmas(&tlb
, mm
, vma
, address
, end
, &nr_accounted
);
607 tlb_finish_mmu(tlb
, address
, end
);
608 spin_unlock(&mm
->page_table_lock
);
612 * Do a quick page-table lookup for a single page.
613 * mm->page_table_lock must be held.
616 follow_page(struct mm_struct
*mm
, unsigned long address
, int write
)
622 struct vm_area_struct
*vma
;
624 vma
= hugepage_vma(mm
, address
);
626 return follow_huge_addr(mm
, vma
, address
, write
);
628 pgd
= pgd_offset(mm
, address
);
629 if (pgd_none(*pgd
) || pgd_bad(*pgd
))
632 pmd
= pmd_offset(pgd
, address
);
636 return follow_huge_pmd(mm
, address
, pmd
, write
);
640 ptep
= pte_offset_map(pmd
, address
);
646 if (pte_present(pte
)) {
647 if (!write
|| (pte_write(pte
) && pte_dirty(pte
))) {
649 if (pfn_valid(pfn
)) {
650 struct page
*page
= pfn_to_page(pfn
);
652 mark_page_accessed(page
);
663 * Given a physical address, is there a useful struct page pointing to
664 * it? This may become more complex in the future if we start dealing
665 * with IO-aperture pages for direct-IO.
668 static inline struct page
*get_page_map(struct page
*page
)
670 if (!pfn_valid(page_to_pfn(page
)))
676 int get_user_pages(struct task_struct
*tsk
, struct mm_struct
*mm
,
677 unsigned long start
, int len
, int write
, int force
,
678 struct page
**pages
, struct vm_area_struct
**vmas
)
684 * Require read or write permissions.
685 * If 'force' is set, we only require the "MAY" flags.
687 flags
= write
? (VM_WRITE
| VM_MAYWRITE
) : (VM_READ
| VM_MAYREAD
);
688 flags
&= force
? (VM_MAYREAD
| VM_MAYWRITE
) : (VM_READ
| VM_WRITE
);
692 struct vm_area_struct
* vma
;
694 vma
= find_extend_vma(mm
, start
);
696 #ifdef FIXADDR_USER_START
698 start
>= FIXADDR_USER_START
&& start
< FIXADDR_USER_END
) {
699 static struct vm_area_struct fixmap_vma
= {
700 /* Catch users - if there are any valid
701 ones, we can make this be "&init_mm" or
704 .vm_start
= FIXADDR_USER_START
,
705 .vm_end
= FIXADDR_USER_END
,
706 .vm_page_prot
= PAGE_READONLY
,
707 .vm_flags
= VM_READ
| VM_EXEC
,
709 unsigned long pg
= start
& PAGE_MASK
;
713 if (write
) /* user fixmap pages are read-only */
714 return i
? : -EFAULT
;
715 pgd
= pgd_offset_k(pg
);
717 return i
? : -EFAULT
;
718 pmd
= pmd_offset(pgd
, pg
);
720 return i
? : -EFAULT
;
721 pte
= pte_offset_kernel(pmd
, pg
);
722 if (!pte
|| !pte_present(*pte
))
723 return i
? : -EFAULT
;
725 pages
[i
] = pte_page(*pte
);
729 vmas
[i
] = &fixmap_vma
;
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 static void zeromap_pte_range(pte_t
* pte
, unsigned long address
,
793 unsigned long size
, pgprot_t prot
)
797 address
&= ~PMD_MASK
;
798 end
= address
+ size
;
802 pte_t zero_pte
= pte_wrprotect(mk_pte(ZERO_PAGE(address
), prot
));
803 BUG_ON(!pte_none(*pte
));
804 set_pte(pte
, zero_pte
);
805 address
+= PAGE_SIZE
;
807 } while (address
&& (address
< end
));
810 static inline int zeromap_pmd_range(struct mm_struct
*mm
, pmd_t
* pmd
, unsigned long address
,
811 unsigned long size
, pgprot_t prot
)
813 unsigned long base
, end
;
815 base
= address
& PGDIR_MASK
;
816 address
&= ~PGDIR_MASK
;
817 end
= address
+ size
;
818 if (end
> PGDIR_SIZE
)
821 pte_t
* pte
= pte_alloc_map(mm
, pmd
, base
+ address
);
824 zeromap_pte_range(pte
, base
+ address
, end
- address
, prot
);
826 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
828 } while (address
&& (address
< end
));
832 int zeromap_page_range(struct vm_area_struct
*vma
, unsigned long address
, unsigned long size
, pgprot_t prot
)
836 unsigned long beg
= address
;
837 unsigned long end
= address
+ size
;
838 struct mm_struct
*mm
= vma
->vm_mm
;
840 dir
= pgd_offset(mm
, address
);
841 flush_cache_range(vma
, beg
, end
);
845 spin_lock(&mm
->page_table_lock
);
847 pmd_t
*pmd
= pmd_alloc(mm
, dir
, address
);
851 error
= zeromap_pmd_range(mm
, pmd
, address
, end
- address
, prot
);
854 address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
856 } while (address
&& (address
< end
));
857 flush_tlb_range(vma
, beg
, end
);
858 spin_unlock(&mm
->page_table_lock
);
863 * maps a range of physical memory into the requested pages. the old
864 * mappings are removed. any references to nonexistent pages results
865 * in null mappings (currently treated as "copy-on-access")
867 static inline void remap_pte_range(pte_t
* pte
, unsigned long address
, unsigned long size
,
868 unsigned long phys_addr
, pgprot_t prot
)
873 address
&= ~PMD_MASK
;
874 end
= address
+ size
;
877 pfn
= phys_addr
>> PAGE_SHIFT
;
879 BUG_ON(!pte_none(*pte
));
880 if (!pfn_valid(pfn
) || PageReserved(pfn_to_page(pfn
)))
881 set_pte(pte
, pfn_pte(pfn
, prot
));
882 address
+= PAGE_SIZE
;
885 } while (address
&& (address
< end
));
888 static inline int remap_pmd_range(struct mm_struct
*mm
, pmd_t
* pmd
, unsigned long address
, unsigned long size
,
889 unsigned long phys_addr
, pgprot_t prot
)
891 unsigned long base
, end
;
893 base
= address
& PGDIR_MASK
;
894 address
&= ~PGDIR_MASK
;
895 end
= address
+ size
;
896 if (end
> PGDIR_SIZE
)
898 phys_addr
-= address
;
900 pte_t
* pte
= pte_alloc_map(mm
, pmd
, base
+ address
);
903 remap_pte_range(pte
, base
+ address
, end
- address
, address
+ phys_addr
, prot
);
905 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
907 } while (address
&& (address
< end
));
911 /* Note: this is only safe if the mm semaphore is held when called. */
912 int remap_page_range(struct vm_area_struct
*vma
, unsigned long from
, unsigned long phys_addr
, unsigned long size
, pgprot_t prot
)
916 unsigned long beg
= from
;
917 unsigned long end
= from
+ size
;
918 struct mm_struct
*mm
= vma
->vm_mm
;
921 dir
= pgd_offset(mm
, from
);
922 flush_cache_range(vma
, beg
, end
);
926 spin_lock(&mm
->page_table_lock
);
928 pmd_t
*pmd
= pmd_alloc(mm
, dir
, from
);
932 error
= remap_pmd_range(mm
, pmd
, from
, end
- from
, phys_addr
+ from
, prot
);
935 from
= (from
+ PGDIR_SIZE
) & PGDIR_MASK
;
937 } while (from
&& (from
< end
));
938 flush_tlb_range(vma
, beg
, end
);
939 spin_unlock(&mm
->page_table_lock
);
944 * Establish a new mapping:
945 * - flush the old one
946 * - update the page tables
947 * - inform the TLB about the new one
949 * We hold the mm semaphore for reading and vma->vm_mm->page_table_lock
951 static inline void establish_pte(struct vm_area_struct
* vma
, unsigned long address
, pte_t
*page_table
, pte_t entry
)
953 set_pte(page_table
, entry
);
954 flush_tlb_page(vma
, address
);
955 update_mmu_cache(vma
, address
, entry
);
959 * We hold the mm semaphore for reading and vma->vm_mm->page_table_lock
961 static inline void break_cow(struct vm_area_struct
* vma
, struct page
* new_page
, unsigned long address
,
964 flush_cache_page(vma
, address
);
965 establish_pte(vma
, address
, page_table
, pte_mkwrite(pte_mkdirty(mk_pte(new_page
, vma
->vm_page_prot
))));
969 * This routine handles present pages, when users try to write
970 * to a shared page. It is done by copying the page to a new address
971 * and decrementing the shared-page counter for the old page.
973 * Goto-purists beware: the only reason for goto's here is that it results
974 * in better assembly code.. The "default" path will see no jumps at all.
976 * Note that this routine assumes that the protection checks have been
977 * done by the caller (the low-level page fault routine in most cases).
978 * Thus we can safely just mark it writable once we've done any necessary
981 * We also mark the page dirty at this point even though the page will
982 * change only once the write actually happens. This avoids a few races,
983 * and potentially makes it more efficient.
985 * We hold the mm semaphore and the page_table_lock on entry and exit
986 * with the page_table_lock released.
988 static int do_wp_page(struct mm_struct
*mm
, struct vm_area_struct
* vma
,
989 unsigned long address
, pte_t
*page_table
, pmd_t
*pmd
, pte_t pte
)
991 struct page
*old_page
, *new_page
;
992 unsigned long pfn
= pte_pfn(pte
);
993 struct pte_chain
*pte_chain
= NULL
;
996 if (unlikely(!pfn_valid(pfn
))) {
998 * This should really halt the system so it can be debugged or
999 * at least the kernel stops what it's doing before it corrupts
1000 * data, but for the moment just pretend this is OOM.
1002 pte_unmap(page_table
);
1003 printk(KERN_ERR
"do_wp_page: bogus page at address %08lx\n",
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 establish_pte(vma
, address
, page_table
,
1015 pte_mkyoung(pte_mkdirty(pte_mkwrite(pte
))));
1016 pte_unmap(page_table
);
1017 ret
= VM_FAULT_MINOR
;
1021 pte_unmap(page_table
);
1024 * Ok, we need to copy. Oh, well..
1026 page_cache_get(old_page
);
1027 spin_unlock(&mm
->page_table_lock
);
1029 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
1032 new_page
= alloc_page(GFP_HIGHUSER
);
1035 copy_cow_page(old_page
,new_page
,address
);
1038 * Re-check the pte - we dropped the lock
1040 spin_lock(&mm
->page_table_lock
);
1041 page_table
= pte_offset_map(pmd
, address
);
1042 if (pte_same(*page_table
, pte
)) {
1043 if (PageReserved(old_page
))
1045 page_remove_rmap(old_page
, page_table
);
1046 break_cow(vma
, new_page
, address
, page_table
);
1047 pte_chain
= page_add_rmap(new_page
, page_table
, pte_chain
);
1048 lru_cache_add_active(new_page
);
1050 /* Free the old page.. */
1051 new_page
= old_page
;
1053 pte_unmap(page_table
);
1054 page_cache_release(new_page
);
1055 page_cache_release(old_page
);
1056 ret
= VM_FAULT_MINOR
;
1060 page_cache_release(old_page
);
1064 spin_unlock(&mm
->page_table_lock
);
1065 pte_chain_free(pte_chain
);
1070 * Helper function for invalidate_mmap_range().
1071 * Both hba and hlen are page numbers in PAGE_SIZE units.
1072 * An hlen of zero blows away the entire portion file after hba.
1075 invalidate_mmap_range_list(struct list_head
*head
,
1076 unsigned long const hba
,
1077 unsigned long const hlen
)
1079 struct list_head
*curr
;
1080 unsigned long hea
; /* last page of hole. */
1082 unsigned long vea
; /* last page of corresponding uva hole. */
1083 struct vm_area_struct
*vp
;
1087 hea
= hba
+ hlen
- 1; /* avoid overflow. */
1090 list_for_each(curr
, head
) {
1091 vp
= list_entry(curr
, struct vm_area_struct
, shared
);
1093 vea
= vba
+ ((vp
->vm_end
- vp
->vm_start
) >> PAGE_SHIFT
) - 1;
1094 if (hea
< vba
|| vea
< hba
)
1095 continue; /* Mapping disjoint from hole. */
1096 zba
= (hba
<= vba
) ? vba
: hba
;
1097 zea
= (vea
<= hea
) ? vea
: hea
;
1099 ((zba
- vba
) << PAGE_SHIFT
) + vp
->vm_start
,
1100 (zea
- zba
+ 1) << PAGE_SHIFT
);
1105 * invalidate_mmap_range - invalidate the portion of all mmaps
1106 * in the specified address_space corresponding to the specified
1107 * page range in the underlying file.
1108 * @address_space: the address space containing mmaps to be invalidated.
1109 * @holebegin: byte in first page to invalidate, relative to the start of
1110 * the underlying file. This will be rounded down to a PAGE_SIZE
1111 * boundary. Note that this is different from vmtruncate(), which
1112 * must keep the partial page. In contrast, we must get rid of
1114 * @holelen: size of prospective hole in bytes. This will be rounded
1115 * up to a PAGE_SIZE boundary. A holelen of zero truncates to the
1118 void invalidate_mmap_range(struct address_space
*mapping
,
1119 loff_t
const holebegin
, loff_t
const holelen
)
1121 unsigned long hba
= holebegin
>> PAGE_SHIFT
;
1122 unsigned long hlen
= (holelen
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
1124 /* Check for overflow. */
1125 if (sizeof(holelen
) > sizeof(hlen
)) {
1127 (holebegin
+ holelen
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
1129 if (holeend
& ~(long long)ULONG_MAX
)
1130 hlen
= ULONG_MAX
- hba
+ 1;
1132 down(&mapping
->i_shared_sem
);
1133 /* Protect against page fault */
1134 atomic_inc(&mapping
->truncate_count
);
1135 if (unlikely(!list_empty(&mapping
->i_mmap
)))
1136 invalidate_mmap_range_list(&mapping
->i_mmap
, hba
, hlen
);
1137 if (unlikely(!list_empty(&mapping
->i_mmap_shared
)))
1138 invalidate_mmap_range_list(&mapping
->i_mmap_shared
, hba
, hlen
);
1139 up(&mapping
->i_shared_sem
);
1141 EXPORT_SYMBOL_GPL(invalidate_mmap_range
);
1144 * Handle all mappings that got truncated by a "truncate()"
1147 * NOTE! We have to be ready to update the memory sharing
1148 * between the file and the memory map for a potential last
1149 * incomplete page. Ugly, but necessary.
1151 int vmtruncate(struct inode
* inode
, loff_t offset
)
1153 struct address_space
*mapping
= inode
->i_mapping
;
1154 unsigned long limit
;
1156 if (inode
->i_size
< offset
)
1158 i_size_write(inode
, offset
);
1159 invalidate_mmap_range(mapping
, offset
+ PAGE_SIZE
- 1, 0);
1160 truncate_inode_pages(mapping
, offset
);
1164 limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
1165 if (limit
!= RLIM_INFINITY
&& offset
> limit
)
1167 if (offset
> inode
->i_sb
->s_maxbytes
)
1169 i_size_write(inode
, offset
);
1172 if (inode
->i_op
&& inode
->i_op
->truncate
)
1173 inode
->i_op
->truncate(inode
);
1176 send_sig(SIGXFSZ
, current
, 0);
1182 * Primitive swap readahead code. We simply read an aligned block of
1183 * (1 << page_cluster) entries in the swap area. This method is chosen
1184 * because it doesn't cost us any seek time. We also make sure to queue
1185 * the 'original' request together with the readahead ones...
1187 void swapin_readahead(swp_entry_t entry
)
1190 struct page
*new_page
;
1191 unsigned long offset
;
1194 * Get the number of handles we should do readahead io to.
1196 num
= valid_swaphandles(entry
, &offset
);
1197 for (i
= 0; i
< num
; offset
++, i
++) {
1198 /* Ok, do the async read-ahead now */
1199 new_page
= read_swap_cache_async(swp_entry(swp_type(entry
),
1203 page_cache_release(new_page
);
1205 lru_add_drain(); /* Push any new pages onto the LRU now */
1209 * We hold the mm semaphore and the page_table_lock on entry and
1210 * should release the pagetable lock on exit..
1212 static int do_swap_page(struct mm_struct
* mm
,
1213 struct vm_area_struct
* vma
, unsigned long address
,
1214 pte_t
*page_table
, pmd_t
*pmd
, pte_t orig_pte
, int write_access
)
1217 swp_entry_t entry
= pte_to_swp_entry(orig_pte
);
1219 int ret
= VM_FAULT_MINOR
;
1220 struct pte_chain
*pte_chain
= NULL
;
1222 pte_unmap(page_table
);
1223 spin_unlock(&mm
->page_table_lock
);
1224 page
= lookup_swap_cache(entry
);
1226 swapin_readahead(entry
);
1227 page
= read_swap_cache_async(entry
);
1230 * Back out if somebody else faulted in this pte while
1231 * we released the page table lock.
1233 spin_lock(&mm
->page_table_lock
);
1234 page_table
= pte_offset_map(pmd
, address
);
1235 if (pte_same(*page_table
, orig_pte
))
1238 ret
= VM_FAULT_MINOR
;
1239 pte_unmap(page_table
);
1240 spin_unlock(&mm
->page_table_lock
);
1244 /* Had to read the page from swap area: Major fault */
1245 ret
= VM_FAULT_MAJOR
;
1246 inc_page_state(pgmajfault
);
1249 mark_page_accessed(page
);
1250 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
1258 * Back out if somebody else faulted in this pte while we
1259 * released the page table lock.
1261 spin_lock(&mm
->page_table_lock
);
1262 page_table
= pte_offset_map(pmd
, address
);
1263 if (!pte_same(*page_table
, orig_pte
)) {
1264 pte_unmap(page_table
);
1265 spin_unlock(&mm
->page_table_lock
);
1267 page_cache_release(page
);
1268 ret
= VM_FAULT_MINOR
;
1272 /* The page isn't present yet, go ahead with the fault. */
1276 remove_exclusive_swap_page(page
);
1279 pte
= mk_pte(page
, vma
->vm_page_prot
);
1280 if (write_access
&& can_share_swap_page(page
))
1281 pte
= pte_mkdirty(pte_mkwrite(pte
));
1284 flush_icache_page(vma
, page
);
1285 set_pte(page_table
, pte
);
1286 pte_chain
= page_add_rmap(page
, page_table
, pte_chain
);
1288 /* No need to invalidate - it was non-present before */
1289 update_mmu_cache(vma
, address
, pte
);
1290 pte_unmap(page_table
);
1291 spin_unlock(&mm
->page_table_lock
);
1293 pte_chain_free(pte_chain
);
1298 * We are called with the MM semaphore and page_table_lock
1299 * spinlock held to protect against concurrent faults in
1300 * multithreaded programs.
1303 do_anonymous_page(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
1304 pte_t
*page_table
, pmd_t
*pmd
, int write_access
,
1308 struct page
* page
= ZERO_PAGE(addr
);
1309 struct pte_chain
*pte_chain
;
1312 pte_chain
= pte_chain_alloc(GFP_ATOMIC
);
1314 pte_unmap(page_table
);
1315 spin_unlock(&mm
->page_table_lock
);
1316 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
1319 spin_lock(&mm
->page_table_lock
);
1320 page_table
= pte_offset_map(pmd
, addr
);
1323 /* Read-only mapping of ZERO_PAGE. */
1324 entry
= pte_wrprotect(mk_pte(ZERO_PAGE(addr
), vma
->vm_page_prot
));
1326 /* ..except if it's a write access */
1328 /* Allocate our own private page. */
1329 pte_unmap(page_table
);
1330 spin_unlock(&mm
->page_table_lock
);
1332 page
= alloc_page(GFP_HIGHUSER
);
1335 clear_user_highpage(page
, addr
);
1337 spin_lock(&mm
->page_table_lock
);
1338 page_table
= pte_offset_map(pmd
, addr
);
1340 if (!pte_none(*page_table
)) {
1341 pte_unmap(page_table
);
1342 page_cache_release(page
);
1343 spin_unlock(&mm
->page_table_lock
);
1344 ret
= VM_FAULT_MINOR
;
1348 entry
= pte_mkwrite(pte_mkdirty(mk_pte(page
, vma
->vm_page_prot
)));
1349 lru_cache_add_active(page
);
1350 mark_page_accessed(page
);
1353 set_pte(page_table
, entry
);
1354 /* ignores ZERO_PAGE */
1355 pte_chain
= page_add_rmap(page
, page_table
, pte_chain
);
1356 pte_unmap(page_table
);
1358 /* No need to invalidate - it was non-present before */
1359 update_mmu_cache(vma
, addr
, entry
);
1360 spin_unlock(&mm
->page_table_lock
);
1361 ret
= VM_FAULT_MINOR
;
1367 pte_chain_free(pte_chain
);
1372 * do_no_page() tries to create a new page mapping. It aggressively
1373 * tries to share with existing pages, but makes a separate copy if
1374 * the "write_access" parameter is true in order to avoid the next
1377 * As this is called only for pages that do not currently exist, we
1378 * do not need to flush old virtual caches or the TLB.
1380 * This is called with the MM semaphore held and the page table
1381 * spinlock held. Exit with the spinlock released.
1384 do_no_page(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
1385 unsigned long address
, int write_access
, pte_t
*page_table
, pmd_t
*pmd
)
1387 struct page
* new_page
;
1388 struct address_space
*mapping
= NULL
;
1390 struct pte_chain
*pte_chain
;
1394 if (!vma
->vm_ops
|| !vma
->vm_ops
->nopage
)
1395 return do_anonymous_page(mm
, vma
, page_table
,
1396 pmd
, write_access
, address
);
1397 pte_unmap(page_table
);
1398 spin_unlock(&mm
->page_table_lock
);
1401 mapping
= vma
->vm_file
->f_dentry
->d_inode
->i_mapping
;
1402 sequence
= atomic_read(&mapping
->truncate_count
);
1404 smp_rmb(); /* Prevent CPU from reordering lock-free ->nopage() */
1406 new_page
= vma
->vm_ops
->nopage(vma
, address
& PAGE_MASK
, 0);
1408 /* no page was available -- either SIGBUS or OOM */
1409 if (new_page
== NOPAGE_SIGBUS
)
1410 return VM_FAULT_SIGBUS
;
1411 if (new_page
== NOPAGE_OOM
)
1412 return VM_FAULT_OOM
;
1414 pte_chain
= pte_chain_alloc(GFP_KERNEL
);
1419 * Should we do an early C-O-W break?
1421 if (write_access
&& !(vma
->vm_flags
& VM_SHARED
)) {
1422 struct page
* page
= alloc_page(GFP_HIGHUSER
);
1424 page_cache_release(new_page
);
1427 copy_user_highpage(page
, new_page
, address
);
1428 page_cache_release(new_page
);
1429 lru_cache_add_active(page
);
1433 spin_lock(&mm
->page_table_lock
);
1435 * For a file-backed vma, someone could have truncated or otherwise
1436 * invalidated this page. If invalidate_mmap_range got called,
1437 * retry getting the page.
1440 (unlikely(sequence
!= atomic_read(&mapping
->truncate_count
)))) {
1441 sequence
= atomic_read(&mapping
->truncate_count
);
1442 spin_unlock(&mm
->page_table_lock
);
1443 page_cache_release(new_page
);
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
);
1474 ret
= VM_FAULT_MINOR
;
1478 /* no need to invalidate: a not-present page shouldn't be cached */
1479 update_mmu_cache(vma
, address
, entry
);
1480 spin_unlock(&mm
->page_table_lock
);
1481 ret
= VM_FAULT_MAJOR
;
1486 pte_chain_free(pte_chain
);
1491 * Fault of a previously existing named mapping. Repopulate the pte
1492 * from the encoded file_pte if possible. This enables swappable
1495 static int do_file_page(struct mm_struct
* mm
, struct vm_area_struct
* vma
,
1496 unsigned long address
, int write_access
, pte_t
*pte
, pmd_t
*pmd
)
1498 unsigned long pgoff
;
1501 BUG_ON(!vma
->vm_ops
|| !vma
->vm_ops
->nopage
);
1503 * Fall back to the linear mapping if the fs does not support
1506 if (!vma
->vm_ops
|| !vma
->vm_ops
->populate
||
1507 (write_access
&& !(vma
->vm_flags
& VM_SHARED
))) {
1509 return do_no_page(mm
, vma
, address
, write_access
, pte
, pmd
);
1512 pgoff
= pte_to_pgoff(*pte
);
1515 spin_unlock(&mm
->page_table_lock
);
1517 err
= vma
->vm_ops
->populate(vma
, address
& PAGE_MASK
, PAGE_SIZE
, vma
->vm_page_prot
, pgoff
, 0);
1519 return VM_FAULT_OOM
;
1521 return VM_FAULT_SIGBUS
;
1522 return VM_FAULT_MAJOR
;
1526 * These routines also need to handle stuff like marking pages dirty
1527 * and/or accessed for architectures that don't do it in hardware (most
1528 * RISC architectures). The early dirtying is also good on the i386.
1530 * There is also a hook called "update_mmu_cache()" that architectures
1531 * with external mmu caches can use to update those (ie the Sparc or
1532 * PowerPC hashed page tables that act as extended TLBs).
1534 * Note the "page_table_lock". It is to protect against kswapd removing
1535 * pages from under us. Note that kswapd only ever _removes_ pages, never
1536 * adds them. As such, once we have noticed that the page is not present,
1537 * we can drop the lock early.
1539 * The adding of pages is protected by the MM semaphore (which we hold),
1540 * so we don't need to worry about a page being suddenly been added into
1543 * We enter with the pagetable spinlock held, we are supposed to
1544 * release it when done.
1546 static inline int handle_pte_fault(struct mm_struct
*mm
,
1547 struct vm_area_struct
* vma
, unsigned long address
,
1548 int write_access
, pte_t
*pte
, pmd_t
*pmd
)
1553 if (!pte_present(entry
)) {
1555 * If it truly wasn't present, we know that kswapd
1556 * and the PTE updates will not touch it later. So
1559 if (pte_none(entry
))
1560 return do_no_page(mm
, vma
, address
, write_access
, pte
, pmd
);
1561 if (pte_file(entry
))
1562 return do_file_page(mm
, vma
, address
, write_access
, pte
, pmd
);
1563 return do_swap_page(mm
, vma
, address
, pte
, pmd
, entry
, write_access
);
1567 if (!pte_write(entry
))
1568 return do_wp_page(mm
, vma
, address
, pte
, pmd
, entry
);
1570 entry
= pte_mkdirty(entry
);
1572 entry
= pte_mkyoung(entry
);
1573 establish_pte(vma
, address
, pte
, 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
);