Commit 08964c565b2fe49e338ffbe4907adcc19647ef16
Committed by
Linus Torvalds
1 parent
c56004901f
Exists in
master
and in
4 other branches
[PATCH] uml: merge duplicated page table code
There is a lot of code which is duplicated between the 2 and 3 level implementation, with the only difference that the 3-level implementation is a bit more generalized (instead of accessing directly pte_t.pte, it uses the appropriate access macros). So this code is joined together. As obvious, a "core code nice cleanup" is not a "stability-friendly patch" so usual care applies. Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Jeff Dike <jdike@addtoit.com> Cc: Paolo Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Showing 3 changed files with 46 additions and 63 deletions Side-by-side Diff
include/asm-um/pgtable-2level.h
| ... | ... | @@ -35,35 +35,8 @@ |
| 35 | 35 | static inline int pgd_newpage(pgd_t pgd) { return 0; } |
| 36 | 36 | static inline void pgd_mkuptodate(pgd_t pgd) { } |
| 37 | 37 | |
| 38 | -#define pte_present(x) (pte_val(x) & (_PAGE_PRESENT | _PAGE_PROTNONE)) | |
| 39 | - | |
| 40 | -static inline pte_t pte_mknewprot(pte_t pte) | |
| 41 | -{ | |
| 42 | - pte_val(pte) |= _PAGE_NEWPROT; | |
| 43 | - return(pte); | |
| 44 | -} | |
| 45 | - | |
| 46 | -static inline pte_t pte_mknewpage(pte_t pte) | |
| 47 | -{ | |
| 48 | - pte_val(pte) |= _PAGE_NEWPAGE; | |
| 49 | - return(pte); | |
| 50 | -} | |
| 51 | - | |
| 52 | -static inline void set_pte(pte_t *pteptr, pte_t pteval) | |
| 53 | -{ | |
| 54 | - /* If it's a swap entry, it needs to be marked _PAGE_NEWPAGE so | |
| 55 | - * fix_range knows to unmap it. _PAGE_NEWPROT is specific to | |
| 56 | - * mapped pages. | |
| 57 | - */ | |
| 58 | - *pteptr = pte_mknewpage(pteval); | |
| 59 | - if(pte_present(*pteptr)) *pteptr = pte_mknewprot(*pteptr); | |
| 60 | -} | |
| 61 | -#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) | |
| 62 | - | |
| 63 | 38 | #define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval)) |
| 64 | 39 | |
| 65 | -#define pte_page(x) pfn_to_page(pte_pfn(x)) | |
| 66 | -#define pte_none(x) !(pte_val(x) & ~_PAGE_NEWPAGE) | |
| 67 | 40 | #define pte_pfn(x) phys_to_pfn(pte_val(x)) |
| 68 | 41 | #define pfn_pte(pfn, prot) __pte(pfn_to_phys(pfn) | pgprot_val(prot)) |
| 69 | 42 | #define pfn_pmd(pfn, prot) __pmd(pfn_to_phys(pfn) | pgprot_val(prot)) |
include/asm-um/pgtable-3level.h
| ... | ... | @@ -57,35 +57,6 @@ |
| 57 | 57 | |
| 58 | 58 | static inline void pgd_mkuptodate(pgd_t pgd) { pgd_val(pgd) &= ~_PAGE_NEWPAGE; } |
| 59 | 59 | |
| 60 | - | |
| 61 | -#define pte_present(x) pte_get_bits(x, (_PAGE_PRESENT | _PAGE_PROTNONE)) | |
| 62 | - | |
| 63 | -static inline pte_t pte_mknewprot(pte_t pte) | |
| 64 | -{ | |
| 65 | - pte_set_bits(pte, _PAGE_NEWPROT); | |
| 66 | - return(pte); | |
| 67 | -} | |
| 68 | - | |
| 69 | -static inline pte_t pte_mknewpage(pte_t pte) | |
| 70 | -{ | |
| 71 | - pte_set_bits(pte, _PAGE_NEWPAGE); | |
| 72 | - return(pte); | |
| 73 | -} | |
| 74 | - | |
| 75 | -static inline void set_pte(pte_t *pteptr, pte_t pteval) | |
| 76 | -{ | |
| 77 | - pte_copy(*pteptr, pteval); | |
| 78 | - | |
| 79 | - /* If it's a swap entry, it needs to be marked _PAGE_NEWPAGE so | |
| 80 | - * fix_range knows to unmap it. _PAGE_NEWPROT is specific to | |
| 81 | - * mapped pages. | |
| 82 | - */ | |
| 83 | - | |
| 84 | - *pteptr = pte_mknewpage(*pteptr); | |
| 85 | - if(pte_present(*pteptr)) *pteptr = pte_mknewprot(*pteptr); | |
| 86 | -} | |
| 87 | -#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) | |
| 88 | - | |
| 89 | 60 | #define set_pmd(pmdptr, pmdval) set_64bit((phys_t *) (pmdptr), pmd_val(pmdval)) |
| 90 | 61 | |
| 91 | 62 | static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) |
| ... | ... | @@ -112,13 +83,6 @@ |
| 112 | 83 | /* Find an entry in the second-level page table.. */ |
| 113 | 84 | #define pmd_offset(pud, address) ((pmd_t *) pud_page(*(pud)) + \ |
| 114 | 85 | pmd_index(address)) |
| 115 | - | |
| 116 | -#define pte_page(x) pfn_to_page(pte_pfn(x)) | |
| 117 | - | |
| 118 | -static inline int pte_none(pte_t pte) | |
| 119 | -{ | |
| 120 | - return pte_is_zero(pte); | |
| 121 | -} | |
| 122 | 86 | |
| 123 | 87 | static inline unsigned long pte_pfn(pte_t pte) |
| 124 | 88 | { |
include/asm-um/pgtable.h
| ... | ... | @@ -153,11 +153,25 @@ |
| 153 | 153 | |
| 154 | 154 | #define pmd_page(pmd) phys_to_page(pmd_val(pmd) & PAGE_MASK) |
| 155 | 155 | |
| 156 | +#define pte_page(x) pfn_to_page(pte_pfn(x)) | |
| 156 | 157 | #define pte_address(x) (__va(pte_val(x) & PAGE_MASK)) |
| 157 | 158 | #define mk_phys(a, r) ((a) + (((unsigned long) r) << REGION_SHIFT)) |
| 158 | 159 | #define phys_addr(p) ((p) & ~REGION_MASK) |
| 159 | 160 | |
| 161 | +#define pte_present(x) pte_get_bits(x, (_PAGE_PRESENT | _PAGE_PROTNONE)) | |
| 162 | + | |
| 160 | 163 | /* |
| 164 | + * ================================= | |
| 165 | + * Flags checking section. | |
| 166 | + * ================================= | |
| 167 | + */ | |
| 168 | + | |
| 169 | +static inline int pte_none(pte_t pte) | |
| 170 | +{ | |
| 171 | + return pte_is_zero(pte); | |
| 172 | +} | |
| 173 | + | |
| 174 | +/* | |
| 161 | 175 | * The following only work if pte_present() is true. |
| 162 | 176 | * Undefined behaviour if not.. |
| 163 | 177 | */ |
| ... | ... | @@ -212,6 +226,18 @@ |
| 212 | 226 | return(pte_present(pte) && (pte_get_bits(pte, _PAGE_NEWPROT))); |
| 213 | 227 | } |
| 214 | 228 | |
| 229 | +/* | |
| 230 | + * ================================= | |
| 231 | + * Flags setting section. | |
| 232 | + * ================================= | |
| 233 | + */ | |
| 234 | + | |
| 235 | +static inline pte_t pte_mknewprot(pte_t pte) | |
| 236 | +{ | |
| 237 | + pte_set_bits(pte, _PAGE_NEWPROT); | |
| 238 | + return(pte); | |
| 239 | +} | |
| 240 | + | |
| 215 | 241 | static inline pte_t pte_rdprotect(pte_t pte) |
| 216 | 242 | { |
| 217 | 243 | pte_clear_bits(pte, _PAGE_USER); |
| ... | ... | @@ -279,6 +305,26 @@ |
| 279 | 305 | pte_clear_bits(pte, _PAGE_NEWPROT); |
| 280 | 306 | return(pte); |
| 281 | 307 | } |
| 308 | + | |
| 309 | +static inline pte_t pte_mknewpage(pte_t pte) | |
| 310 | +{ | |
| 311 | + pte_set_bits(pte, _PAGE_NEWPAGE); | |
| 312 | + return(pte); | |
| 313 | +} | |
| 314 | + | |
| 315 | +static inline void set_pte(pte_t *pteptr, pte_t pteval) | |
| 316 | +{ | |
| 317 | + pte_copy(*pteptr, pteval); | |
| 318 | + | |
| 319 | + /* If it's a swap entry, it needs to be marked _PAGE_NEWPAGE so | |
| 320 | + * fix_range knows to unmap it. _PAGE_NEWPROT is specific to | |
| 321 | + * mapped pages. | |
| 322 | + */ | |
| 323 | + | |
| 324 | + *pteptr = pte_mknewpage(*pteptr); | |
| 325 | + if(pte_present(*pteptr)) *pteptr = pte_mknewprot(*pteptr); | |
| 326 | +} | |
| 327 | +#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) | |
| 282 | 328 | |
| 283 | 329 | extern phys_t page_to_phys(struct page *page); |
| 284 | 330 |