pgtable.h
来自「linux 内核源代码」· C头文件 代码 · 共 964 行 · 第 1/2 页
H
964 行
{ unsigned long mask = ~_SEGMENT_ENTRY_ORIGIN & ~_SEGMENT_ENTRY_INV; return (pmd_val(pmd) & mask) != _SEGMENT_ENTRY;}static inline int pte_none(pte_t pte){ return (pte_val(pte) & _PAGE_INVALID) && !(pte_val(pte) & _PAGE_SWT);}static inline int pte_present(pte_t pte){ unsigned long mask = _PAGE_RO | _PAGE_INVALID | _PAGE_SWT | _PAGE_SWX; return (pte_val(pte) & mask) == _PAGE_TYPE_NONE || (!(pte_val(pte) & _PAGE_INVALID) && !(pte_val(pte) & _PAGE_SWT));}static inline int pte_file(pte_t pte){ unsigned long mask = _PAGE_RO | _PAGE_INVALID | _PAGE_SWT; return (pte_val(pte) & mask) == _PAGE_TYPE_FILE;}#define __HAVE_ARCH_PTE_SAME#define pte_same(a,b) (pte_val(a) == pte_val(b))/* * query functions pte_write/pte_dirty/pte_young only work if * pte_present() is true. Undefined behaviour if not.. */static inline int pte_write(pte_t pte){ return (pte_val(pte) & _PAGE_RO) == 0;}static inline int pte_dirty(pte_t pte){ /* A pte is neither clean nor dirty on s/390. The dirty bit * is in the storage key. See page_test_and_clear_dirty for * details. */ return 0;}static inline int pte_young(pte_t pte){ /* A pte is neither young nor old on s/390. The young bit * is in the storage key. See page_test_and_clear_young for * details. */ return 0;}/* * pgd/pmd/pte modification functions */#ifndef __s390x__#define pgd_clear(pgd) do { } while (0)#define pud_clear(pud) do { } while (0)static inline void pmd_clear_kernel(pmd_t * pmdp){ pmd_val(pmdp[0]) = _SEGMENT_ENTRY_EMPTY; pmd_val(pmdp[1]) = _SEGMENT_ENTRY_EMPTY; pmd_val(pmdp[2]) = _SEGMENT_ENTRY_EMPTY; pmd_val(pmdp[3]) = _SEGMENT_ENTRY_EMPTY;}#else /* __s390x__ */#define pgd_clear(pgd) do { } while (0)static inline void pud_clear_kernel(pud_t *pud){ pud_val(*pud) = _REGION3_ENTRY_EMPTY;}static inline void pud_clear(pud_t * pud){ pud_t *shadow = get_shadow_table(pud); pud_clear_kernel(pud); if (shadow) pud_clear_kernel(shadow);}static inline void pmd_clear_kernel(pmd_t * pmdp){ pmd_val(*pmdp) = _SEGMENT_ENTRY_EMPTY; pmd_val1(*pmdp) = _SEGMENT_ENTRY_EMPTY;}#endif /* __s390x__ */static inline void pmd_clear(pmd_t * pmdp){ pmd_t *shadow_pmd = get_shadow_table(pmdp); pmd_clear_kernel(pmdp); if (shadow_pmd) pmd_clear_kernel(shadow_pmd);}static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep){ pte_t *shadow_pte = get_shadow_pte(ptep); pte_val(*ptep) = _PAGE_TYPE_EMPTY; if (shadow_pte) pte_val(*shadow_pte) = _PAGE_TYPE_EMPTY;}/* * The following pte modification functions only work if * pte_present() is true. Undefined behaviour if not.. */static inline pte_t pte_modify(pte_t pte, pgprot_t newprot){ pte_val(pte) &= PAGE_MASK; pte_val(pte) |= pgprot_val(newprot); return pte;}static inline pte_t pte_wrprotect(pte_t pte){ /* Do not clobber _PAGE_TYPE_NONE pages! */ if (!(pte_val(pte) & _PAGE_INVALID)) pte_val(pte) |= _PAGE_RO; return pte;}static inline pte_t pte_mkwrite(pte_t pte){ pte_val(pte) &= ~_PAGE_RO; return pte;}static inline pte_t pte_mkclean(pte_t pte){ /* The only user of pte_mkclean is the fork() code. We must *not* clear the *physical* page dirty bit just because fork() wants to clear the dirty bit in *one* of the page's mappings. So we just do nothing. */ return pte;}static inline pte_t pte_mkdirty(pte_t pte){ /* We do not explicitly set the dirty bit because the * sske instruction is slow. It is faster to let the * next instruction set the dirty bit. */ return pte;}static inline pte_t pte_mkold(pte_t pte){ /* S/390 doesn't keep its dirty/referenced bit in the pte. * There is no point in clearing the real referenced bit. */ return pte;}static inline pte_t pte_mkyoung(pte_t pte){ /* S/390 doesn't keep its dirty/referenced bit in the pte. * There is no point in setting the real referenced bit. */ return pte;}#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNGstatic inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep){ return 0;}#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSHstatic inline int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long address, pte_t *ptep){ /* No need to flush TLB; bits are in storage key */ return 0;}static inline void __ptep_ipte(unsigned long address, pte_t *ptep){ if (!(pte_val(*ptep) & _PAGE_INVALID)) {#ifndef __s390x__ /* S390 has 1mb segments, we are emulating 4MB segments */ pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00);#else /* ipte in zarch mode can do the math */ pte_t *pto = ptep;#endif asm volatile( " ipte %2,%3" : "=m" (*ptep) : "m" (*ptep), "a" (pto), "a" (address)); } pte_val(*ptep) = _PAGE_TYPE_EMPTY;}static inline void ptep_invalidate(unsigned long address, pte_t *ptep){ __ptep_ipte(address, ptep); ptep = get_shadow_pte(ptep); if (ptep) __ptep_ipte(address, ptep);}/* * This is hard to understand. ptep_get_and_clear and ptep_clear_flush * both clear the TLB for the unmapped pte. The reason is that * ptep_get_and_clear is used in common code (e.g. change_pte_range) * to modify an active pte. The sequence is * 1) ptep_get_and_clear * 2) set_pte_at * 3) flush_tlb_range * On s390 the tlb needs to get flushed with the modification of the pte * if the pte is active. The only way how this can be implemented is to * have ptep_get_and_clear do the tlb flush. In exchange flush_tlb_range * is a nop. */#define __HAVE_ARCH_PTEP_GET_AND_CLEAR#define ptep_get_and_clear(__mm, __address, __ptep) \({ \ pte_t __pte = *(__ptep); \ if (atomic_read(&(__mm)->mm_users) > 1 || \ (__mm) != current->active_mm) \ ptep_invalidate(__address, __ptep); \ else \ pte_clear((__mm), (__address), (__ptep)); \ __pte; \})#define __HAVE_ARCH_PTEP_CLEAR_FLUSHstatic inline pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long address, pte_t *ptep){ pte_t pte = *ptep; ptep_invalidate(address, ptep); return pte;}/* * The batched pte unmap code uses ptep_get_and_clear_full to clear the * ptes. Here an optimization is possible. tlb_gather_mmu flushes all * tlbs of an mm if it can guarantee that the ptes of the mm_struct * cannot be accessed while the batched unmap is running. In this case * full==1 and a simple pte_clear is enough. See tlb.h. */#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULLstatic inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, unsigned long addr, pte_t *ptep, int full){ pte_t pte = *ptep; if (full) pte_clear(mm, addr, ptep); else ptep_invalidate(addr, ptep); return pte;}#define __HAVE_ARCH_PTEP_SET_WRPROTECT#define ptep_set_wrprotect(__mm, __addr, __ptep) \({ \ pte_t __pte = *(__ptep); \ if (pte_write(__pte)) { \ if (atomic_read(&(__mm)->mm_users) > 1 || \ (__mm) != current->active_mm) \ ptep_invalidate(__addr, __ptep); \ set_pte_at(__mm, __addr, __ptep, pte_wrprotect(__pte)); \ } \})#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS#define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __dirty) \({ \ int __changed = !pte_same(*(__ptep), __entry); \ if (__changed) { \ ptep_invalidate(__addr, __ptep); \ set_pte_at((__vma)->vm_mm, __addr, __ptep, __entry); \ } \ __changed; \})/* * Test and clear dirty bit in storage key. * We can't clear the changed bit atomically. This is a potential * race against modification of the referenced bit. This function * should therefore only be called if it is not mapped in any * address space. */#define __HAVE_ARCH_PAGE_TEST_DIRTYstatic inline int page_test_dirty(struct page *page){ return (page_get_storage_key(page_to_phys(page)) & _PAGE_CHANGED) != 0;}#define __HAVE_ARCH_PAGE_CLEAR_DIRTYstatic inline void page_clear_dirty(struct page *page){ page_set_storage_key(page_to_phys(page), PAGE_DEFAULT_KEY);}/* * Test and clear referenced bit in storage key. */#define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNGstatic inline int page_test_and_clear_young(struct page *page){ unsigned long physpage = page_to_phys(page); int ccode; asm volatile( " rrbe 0,%1\n" " ipm %0\n" " srl %0,28\n" : "=d" (ccode) : "a" (physpage) : "cc" ); return ccode & 2;}/* * Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to. */static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot){ pte_t __pte; pte_val(__pte) = physpage + pgprot_val(pgprot); return __pte;}static inline pte_t mk_pte(struct page *page, pgprot_t pgprot){ unsigned long physpage = page_to_phys(page); return mk_pte_phys(physpage, pgprot);}#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))#define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1))#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))#define pgd_offset_k(address) pgd_offset(&init_mm, address)#ifndef __s390x__#define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)#define pud_deref(pmd) ({ BUG(); 0UL; })#define pgd_deref(pmd) ({ BUG(); 0UL; })#define pud_offset(pgd, address) ((pud_t *) pgd)#define pmd_offset(pud, address) ((pmd_t *) pud + pmd_index(address))#else /* __s390x__ */#define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)#define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)#define pgd_deref(pgd) ({ BUG(); 0UL; })#define pud_offset(pgd, address) ((pud_t *) pgd)static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address){ pmd_t *pmd = (pmd_t *) pud_deref(*pud); return pmd + pmd_index(address);}#endif /* __s390x__ */#define pfn_pte(pfn,pgprot) mk_pte_phys(__pa((pfn) << PAGE_SHIFT),(pgprot))#define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)#define pte_page(x) pfn_to_page(pte_pfn(x))#define pmd_page(pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)/* Find an entry in the lowest level page table.. */#define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr))#define pte_offset_kernel(pmd, address) pte_offset(pmd,address)#define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)#define pte_offset_map_nested(pmd, address) pte_offset_kernel(pmd, address)#define pte_unmap(pte) do { } while (0)#define pte_unmap_nested(pte) do { } while (0)/* * 31 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. * Bits 0, 20 and bit 23 have to be zero, otherwise an specification * exception will occur instead of a page translation exception. The * specifiation exception has the bad habit not to store necessary * information in the lowcore. * Bit 21 and bit 22 are the page invalid bit and the page protection * bit. We set both to indicate a swapped page. * Bit 30 and 31 are used to distinguish the different page types. For * a swapped page these bits need to be zero. * This leaves the bits 1-19 and bits 24-29 to store type and offset. * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19 * plus 24 for the offset. * 0| offset |0110|o|type |00| * 0 0000000001111111111 2222 2 22222 33 * 0 1234567890123456789 0123 4 56789 01 * * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. * Bits 52 and bit 55 have to be zero, otherwise an specification * exception will occur instead of a page translation exception. The * specifiation exception has the bad habit not to store necessary * information in the lowcore. * Bit 53 and bit 54 are the page invalid bit and the page protection * bit. We set both to indicate a swapped page. * Bit 62 and 63 are used to distinguish the different page types. For * a swapped page these bits need to be zero. * This leaves the bits 0-51 and bits 56-61 to store type and offset. * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51 * plus 56 for the offset. * | offset |0110|o|type |00| * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66 * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23 */#ifndef __s390x__#define __SWP_OFFSET_MASK (~0UL >> 12)#else#define __SWP_OFFSET_MASK (~0UL >> 11)#endifstatic inline pte_t mk_swap_pte(unsigned long type, unsigned long offset){ pte_t pte; offset &= __SWP_OFFSET_MASK; pte_val(pte) = _PAGE_TYPE_SWAP | ((type & 0x1f) << 2) | ((offset & 1UL) << 7) | ((offset & ~1UL) << 11); return pte;}#define __swp_type(entry) (((entry).val >> 2) & 0x1f)#define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1))#define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) })#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })#define __swp_entry_to_pte(x) ((pte_t) { (x).val })#ifndef __s390x__# define PTE_FILE_MAX_BITS 26#else /* __s390x__ */# define PTE_FILE_MAX_BITS 59#endif /* __s390x__ */#define pte_to_pgoff(__pte) \ ((((__pte).pte >> 12) << 7) + (((__pte).pte >> 1) & 0x7f))#define pgoff_to_pte(__off) \ ((pte_t) { ((((__off) & 0x7f) << 1) + (((__off) >> 7) << 12)) \ | _PAGE_TYPE_FILE })#endif /* !__ASSEMBLY__ */#define kern_addr_valid(addr) (1)extern int add_shared_memory(unsigned long start, unsigned long size);extern int remove_shared_memory(unsigned long start, unsigned long size);/* * No page table caches to initialise */#define pgtable_cache_init() do { } while (0)#define __HAVE_ARCH_MEMMAP_INITextern void memmap_init(unsigned long, int, unsigned long, unsigned long);#include <asm-generic/pgtable.h>#endif /* _S390_PAGE_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?