Back to home page

LXR

 
 

    


0001 /*
0002  *  mm/pgtable-generic.c
0003  *
0004  *  Generic pgtable methods declared in asm-generic/pgtable.h
0005  *
0006  *  Copyright (C) 2010  Linus Torvalds
0007  */
0008 
0009 #include <linux/pagemap.h>
0010 #include <asm/tlb.h>
0011 #include <asm-generic/pgtable.h>
0012 
0013 /*
0014  * If a p?d_bad entry is found while walking page tables, report
0015  * the error, before resetting entry to p?d_none.  Usually (but
0016  * very seldom) called out from the p?d_none_or_clear_bad macros.
0017  */
0018 
0019 void pgd_clear_bad(pgd_t *pgd)
0020 {
0021     pgd_ERROR(*pgd);
0022     pgd_clear(pgd);
0023 }
0024 
0025 void pud_clear_bad(pud_t *pud)
0026 {
0027     pud_ERROR(*pud);
0028     pud_clear(pud);
0029 }
0030 
0031 void pmd_clear_bad(pmd_t *pmd)
0032 {
0033     pmd_ERROR(*pmd);
0034     pmd_clear(pmd);
0035 }
0036 
0037 #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
0038 /*
0039  * Only sets the access flags (dirty, accessed), as well as write 
0040  * permission. Furthermore, we know it always gets set to a "more
0041  * permissive" setting, which allows most architectures to optimize
0042  * this. We return whether the PTE actually changed, which in turn
0043  * instructs the caller to do things like update__mmu_cache.  This
0044  * used to be done in the caller, but sparc needs minor faults to
0045  * force that call on sun4c so we changed this macro slightly
0046  */
0047 int ptep_set_access_flags(struct vm_area_struct *vma,
0048               unsigned long address, pte_t *ptep,
0049               pte_t entry, int dirty)
0050 {
0051     int changed = !pte_same(*ptep, entry);
0052     if (changed) {
0053         set_pte_at(vma->vm_mm, address, ptep, entry);
0054         flush_tlb_fix_spurious_fault(vma, address);
0055     }
0056     return changed;
0057 }
0058 #endif
0059 
0060 #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
0061 int ptep_clear_flush_young(struct vm_area_struct *vma,
0062                unsigned long address, pte_t *ptep)
0063 {
0064     int young;
0065     young = ptep_test_and_clear_young(vma, address, ptep);
0066     if (young)
0067         flush_tlb_page(vma, address);
0068     return young;
0069 }
0070 #endif
0071 
0072 #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
0073 pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long address,
0074                pte_t *ptep)
0075 {
0076     struct mm_struct *mm = (vma)->vm_mm;
0077     pte_t pte;
0078     pte = ptep_get_and_clear(mm, address, ptep);
0079     if (pte_accessible(mm, pte))
0080         flush_tlb_page(vma, address);
0081     return pte;
0082 }
0083 #endif
0084 
0085 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
0086 
0087 #ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
0088 int pmdp_set_access_flags(struct vm_area_struct *vma,
0089               unsigned long address, pmd_t *pmdp,
0090               pmd_t entry, int dirty)
0091 {
0092     int changed = !pmd_same(*pmdp, entry);
0093     VM_BUG_ON(address & ~HPAGE_PMD_MASK);
0094     if (changed) {
0095         set_pmd_at(vma->vm_mm, address, pmdp, entry);
0096         flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
0097     }
0098     return changed;
0099 }
0100 #endif
0101 
0102 #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
0103 int pmdp_clear_flush_young(struct vm_area_struct *vma,
0104                unsigned long address, pmd_t *pmdp)
0105 {
0106     int young;
0107     VM_BUG_ON(address & ~HPAGE_PMD_MASK);
0108     young = pmdp_test_and_clear_young(vma, address, pmdp);
0109     if (young)
0110         flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
0111     return young;
0112 }
0113 #endif
0114 
0115 #ifndef __HAVE_ARCH_PMDP_HUGE_CLEAR_FLUSH
0116 pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma, unsigned long address,
0117                 pmd_t *pmdp)
0118 {
0119     pmd_t pmd;
0120     VM_BUG_ON(address & ~HPAGE_PMD_MASK);
0121     VM_BUG_ON(!pmd_trans_huge(*pmdp) && !pmd_devmap(*pmdp));
0122     pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);
0123     flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
0124     return pmd;
0125 }
0126 #endif
0127 
0128 #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT
0129 void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
0130                 pgtable_t pgtable)
0131 {
0132     assert_spin_locked(pmd_lockptr(mm, pmdp));
0133 
0134     /* FIFO */
0135     if (!pmd_huge_pte(mm, pmdp))
0136         INIT_LIST_HEAD(&pgtable->lru);
0137     else
0138         list_add(&pgtable->lru, &pmd_huge_pte(mm, pmdp)->lru);
0139     pmd_huge_pte(mm, pmdp) = pgtable;
0140 }
0141 #endif
0142 
0143 #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
0144 /* no "address" argument so destroys page coloring of some arch */
0145 pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
0146 {
0147     pgtable_t pgtable;
0148 
0149     assert_spin_locked(pmd_lockptr(mm, pmdp));
0150 
0151     /* FIFO */
0152     pgtable = pmd_huge_pte(mm, pmdp);
0153     pmd_huge_pte(mm, pmdp) = list_first_entry_or_null(&pgtable->lru,
0154                               struct page, lru);
0155     if (pmd_huge_pte(mm, pmdp))
0156         list_del(&pgtable->lru);
0157     return pgtable;
0158 }
0159 #endif
0160 
0161 #ifndef __HAVE_ARCH_PMDP_INVALIDATE
0162 void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
0163              pmd_t *pmdp)
0164 {
0165     pmd_t entry = *pmdp;
0166     set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
0167     flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
0168 }
0169 #endif
0170 
0171 #ifndef pmdp_collapse_flush
0172 pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address,
0173               pmd_t *pmdp)
0174 {
0175     /*
0176      * pmd and hugepage pte format are same. So we could
0177      * use the same function.
0178      */
0179     pmd_t pmd;
0180 
0181     VM_BUG_ON(address & ~HPAGE_PMD_MASK);
0182     VM_BUG_ON(pmd_trans_huge(*pmdp));
0183     pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);
0184 
0185     /* collapse entails shooting down ptes not pmd */
0186     flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
0187     return pmd;
0188 }
0189 #endif
0190 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */